- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello there
Can the subscripts of an array be discontinuous?
For example, how can I define a rank-one array (I) containing the elements I(5), I(6), I(21) and I(22).
Regards
Hamid
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I([5,6,21,22])
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I([5,6,21,22])
Thank you for this. Do you mean using something like the following program?
INTEGER I(4)
I = (/5,6,21,22/)
I(5)=50; I(6)=60; I(21)=210; I(22)=220
PRINT*, I(5), I(6), I(21), I(22)
END
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I([5,6,21,22])
Thank you for this. Do you mean using something like the following program?
INTEGER I(4)
I = (/5,6,21,22/)
I(5)=50; I(6)=60; I(21)=210; I(22)=220
PRINT*, I(5), I(6), I(21), I(22)
END
Something should be wrong. He program works with more subscripts, e.g. I(7), I(8), I(23) and I(24).
INTEGER I(4)
I = (/5,6,21,22/)
I(5)=50; I(6)=60; I(21)=210; I(22)=220
I(7)=70; I(8)=80; I(23)=230; I(24)=240
PRINT*, I(5), I(6), I(21), I(22)
PRINT*, I(7), I(8), I(23), I(24)
END
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What I meant was something more like this:
[plain]INTEGER I(25) I(5)=50; I(6)=60; I(21)=210; I(22)=220 I(7)=70; I(8)=80; I(23)=230; I(24)=240 PRINT*, I([5,6,21,22]) PRINT*, I([7,8,23,24]) END[/plain]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What I meant was something more like this:
[plain]INTEGER I(25) I(5)=50; I(6)=60; I(21)=210; I(22)=220 I(7)=70; I(8)=80; I(23)=230; I(24)=240 PRINT*, I([5,6,21,22]) PRINT*, I([7,8,23,24]) END[/plain]
Many thanks. But you defined a 25-element array. I wanted to have elements as less as possible, which would be an 8-element array for the above example (or 4-element for the first example).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So the best solution seems to be defining an array with elements from the minimum to the maximum values. As I need dynamic variables, the program in post 4 will be:
INTEGER, ALLOCATABLE :: I(:)
M = 5; N = 24
ALLOCATE (I(M:N))
I(5)=50; I(6)=60 ; I(21)=210; I(22)=220
I(7)=70; I(8)=80 ; I(23)=230; I(24)=240
PRINT*, I(5), I(6), I(21), I(22)
PRINT*, I(7), I(8), I(23), I(24)
END
Thanks very much
Hamid

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