Note that there are some explanatory texts on larger screens.

plurals
  1. POReading a known number of variable from a file when one of the variables are missing in input file
    primarykey
    data
    text
    <p>I already checked similar posting. The solution is given by M. S. B. here <a href="https://stackoverflow.com/questions/7314216/reading-data-file-in-fortran-with-known-number-of-lines-but-unknown-number-of-en/7315185">Reading data file in Fortran with known number of lines but unknown number of entries in each line</a></p> <p>So, the problem I am having is that from text file I am trying to read inputs. In one line there is supposed to be 3 variables. But sometimes the input file may have 2 variables. In that case I need to make the last variable zero. I tried using READ statement with IOSTAT but if there is only two values it goes to the next line and reads the next available value. I need to make it stop in the 1st line after reading 2 values when there is no 3rd value.</p> <p>I found one way to do that is to have a comment/other than the type I am trying to read (in this case I am reading float while a comment is a char) which makes a IOSTAT>0 and I can use that as a check. But if in some cases I may not have that comment. I want to make sure it works even than. </p> <p>Part of the code </p> <pre><code> read(15,*) x read(15,*,IOSTAT=ioerr) y,z,w if (ioerr.gt.0) then write(*,*)'No value was found' w=0.0; goto 409 elseif (ioerr.eq.0) then write(*,*)'Value found', w endif 409 read(15,*) a,b read(15,*) c,d </code></pre> <p>INPUT FILE is of the form</p> <pre><code> -1.000 abcd 12.460 28.000 8.00 efg 5.000 5.000 hijk 20.000 21.000 lmno </code></pre> <p>I need to make it work even when there is no "8.00 efg"</p> <p>for this case</p> <pre><code> -1.000 abcd 12.460 28.000 5.000 5.000 hijk 20.000 21.000 lmno </code></pre> <p>I can not use the string method suggested by MSB. Is there any other way? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload