- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
whats the best way to concatenate one dimensional arrays?
real*8 omega(200).omega1(50),omega2(50),omega3(50),omega4(50)
I initially optimistically just tried
omega=omega1+omega2+omega3+omega4
not quite sure what that actually does, but not what i was wanting.
Ended up just with :-
omega(1:50) = omega1
omega(51:100) = omega2
omega(101:150) = omega3
omega(151:200) = omega4
but there must be a more elegant way - particularly if the array sizes are variables
thanks
real*8 omega(200).omega1(50),omega2(50),omega3(50),omega4(50)
I initially optimistically just tried
omega=omega1+omega2+omega3+omega4
not quite sure what that actually does, but not what i was wanting.
Ended up just with :-
omega(1:50) = omega1
omega(51:100) = omega2
omega(101:150) = omega3
omega(151:200) = omega4
but there must be a more elegant way - particularly if the array sizes are variables
thanks
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Nigel Thomas
whats the best way to concatenate one dimensional arrays?
real*8 omega(200).omega1(50),omega2(50),omega3(50),omega4(50)
I initially optimistically just tried
omega=omega1+omega2+omega3+omega4
not quite sure what that actually does, but not what i was wanting.
Ended up just with :-
omega(1:50) = omega1
omega(51:100) = omega2
omega(101:150) = omega3
omega(151:200) = omega4
but there must be a more elegant way - particularly if the array sizes are variables
thanks
real*8 omega(200).omega1(50),omega2(50),omega3(50),omega4(50)
I initially optimistically just tried
omega=omega1+omega2+omega3+omega4
not quite sure what that actually does, but not what i was wanting.
Ended up just with :-
omega(1:50) = omega1
omega(51:100) = omega2
omega(101:150) = omega3
omega(151:200) = omega4
but there must be a more elegant way - particularly if the array sizes are variables
thanks
omega=omega1+omega2+omega3+omega4
should be diagnosed as an error, if all checks are enabled. The expression on the right adds the arrays element by element, but the size doesn't match the destination.
The array section assignments, for whose simplicity you appear to be apologizing, look just fine. You could easily extend to variable sizes with the SIZE operator, for example.
No doubt, you could define your own "elegant" operators, which might approach the "best" way in your opinion to make it difficult for others to understand.
As pointed out below,
(/ omega1, omega2, omega3, omega4 /) ! f90 notation
[ omega1, omega2, omega3, omega4 ] ! f2003 alternative
would accomplish it, possible with weaker performance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Nigel Thomas
whats the best way to concatenate one dimensional arrays?
real*8 omega(200).omega1(50),omega2(50),omega3(50),omega4(50)
I initially optimistically just tried
omega=omega1+omega2+omega3+omega4
not quite sure what that actually does, but not what i was wanting.
Ended up just with :-
omega(1:50) = omega1
omega(51:100) = omega2
omega(101:150) = omega3
omega(151:200) = omega4
but there must be a more elegant way - particularly if the array sizes are variables
thanks
real*8 omega(200).omega1(50),omega2(50),omega3(50),omega4(50)
I initially optimistically just tried
omega=omega1+omega2+omega3+omega4
not quite sure what that actually does, but not what i was wanting.
Ended up just with :-
omega(1:50) = omega1
omega(51:100) = omega2
omega(101:150) = omega3
omega(151:200) = omega4
but there must be a more elegant way - particularly if the array sizes are variables
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
what about
omega = [omega1,omega2,omega3,omega4] ?
Henning
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - henning_woehler
what about
omega = [omega1,omega2,omega3,omega4] ?
Henning
Works great, exactly what i was looking for. Similar to matlab syntax actually.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The square bracket syntax for an array constructor is new in Fortran 2003, though Intel Fortran has supported it for a very long time. The use of an array constructor to build a new array out of other arrays is in Fortran 90.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page