- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am trying to read a data file with the following line (the quotes denote the start and end of the line) " 0: 56 56 120 /".
I want to ignore the first 3 characters and read the 3 integers (56,56,120) into 3 integer variables i, j, k. However the numbers of blanks between them can vary depending on the input file, eg, some file may have " 0: 56 56 120 /". Is here a simple syntax for doing this?
I tried "read (unt,'(a3,i0,i0,i0)') str, i, j, k" (where str is a character string) and similar variants, but either end up with i=5656120 and j=k=0, or with a read error...
any pointers would be appreciated!
dmitri
I am trying to read a data file with the following line (the quotes denote the start and end of the line) " 0: 56 56 120 /".
I want to ignore the first 3 characters and read the 3 integers (56,56,120) into 3 integer variables i, j, k. However the numbers of blanks between them can vary depending on the input file, eg, some file may have " 0: 56 56 120 /". Is here a simple syntax for doing this?
I tried "read (unt,'(a3,i0,i0,i0)') str, i, j, k" (where str is a character string) and similar variants, but either end up with i=5656120 and j=k=0, or with a read error...
any pointers would be appreciated!
dmitri
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could do it this way:
character(100) record
...
READ (unit,'(A)') record
READ (record(4:),*) i,j,k
Note that if the input data is bad (for example, letters or punctuation), you may not get an error from the list-directed read.
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