Fortran - String with unknown characters into substrings

Posted by Masoud on Stack Overflow See other posts from Stack Overflow or by Masoud
Published on 2014-06-08T20:31:08Z Indexed on 2014/06/09 3:26 UTC
Read the original article Hit count: 172

Filed under:
|

I am trying to put an input string into sub-string arrays. The number of data in the input file are less than 10 but unknown. The number of spaces between each data is also unclear.

Example:

Asd  B       Cwqe21 Ddsw      Eww

I am quite novice to Fortran, so I do not know which format I should use. My problem is that I do not know the number of data (here I assumed that there are 5), so how can I make the code work? I tried the following which did not work:

CHARACTER (LEN=100), DIMENSION(10) :: string
READ (1,*) (string,I=1,10)

It seems that the error I got was because there was no 6th string to read and put into string(6).

I tried using the "Index" to find the space, but since I do not know how many spaces are in the string, it did not help me.

© Stack Overflow or respective owner

Related posts about fortran

Related posts about fortran90