- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 6
21 20
8 9
18 17
11 12
15 14
I defined an array:
Link Copied
- 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
Hi,
Thank you for your reply. Just as you say, the number of data in every line is unknown, so...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I using the read statement as follows,
read(1,*)data
it will always turn to the next line, can I read several number in a line with several read statement? Just as
read(1,*)(data(i),i=1,n)
But I don't know the value of n, how should I do?
Thanks,
Zhanghong Tang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1) Read each record as a character string
CHARACTER(500)
READ(1,*) STRING
2)Get the string's length
LENGTH=LEN_TRIM(STRING)
2) count the spaces in the string: this is one less than the number of integer data items
ISTART=1
DO J=1,25
ISPACE=INDEX( STRING(ISTART:LENGTH), ' ')
IF(ISPACE.EQ.0) EXIT
ISTART=ISPACE+1
ENDDO
3) Use in internal read, selecting to read in this number+1 items
READ(STRING(1:LENGTH),*) (DATA(I),I=1,NUMBER)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following code assumes that ther will be at elast one number in a record.
1) Read each record as a character string
CHARACTER(500)
INTEGER(4) I, NUMBER, ISTART, ISPACE
READ(1,*) STRING
2)Get the string's length
LENGTH=LEN_TRIM(STRING)
2) count the spaces in the string: this is one less than the number of integer data items
ISTART=1
NUMBER=0
DO J=1,25'
! EXIT IF SPACE NOT FOUND FROM 'ISTART' TO THE END
ISPACE=INDEX( STRING(ISTART:LENGTH), ' ')
IF(ISPACE.EQ.0) EXIT
ISTART=ISPACE+1
NUMBER=NUMBER+1
ENDDO
NUMBER=NUMBER+1
3) Use in internal read, selecting to read in this number+1 items
READ(STRING(1:LENGTH),*) (DATA(I),I=1,NUMBER)
I have not tested it, but it can be made to work.
- 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
I forgot to include a line of code
STRING = ADJUSTL(ADJUSTR(" "))
(or similar) to initialise the STRING variable to all blanks BEFORE each READ, otherwise it will contain stuff from a previous READ which will screw things up eventually, if the next record is shorter than the last.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Even simpler STRING = " " will do
Les

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