0

I have a text file where the first few lines are text and the rest of the lines contain data in the form of real numbers. I just require the real numbers array to be stored in a new file. For this, I read the total lines of the file for which output is correct and then trying to read the real numbers from the particular line numbers. I am unable to understand as to how to read this data. Below is a part of file. Also I have many files like these to read.


AptitudeQT paperI:  12233105
Latitude :   30.00  S
Longitude:   46.45  E
Attemptone Time:  2017-03-30-09-03
End Time:  2017-03-30-14-55

        Height(agl):        m
           Pressure:        hPa
        Temperature:        deg C
           Humidity:        %RH
          Uvelocity:        cm/s
          Vvelocity:        cm/s
          WindSpeed:        cm/s
      WindDirection:        deg


---------------------------------------
        10      1008.383            27.655            62.200          -718.801            -45.665           720.250            266.500
        20      1007.175            27.407            62.950          -792.284            -18.481           792.500            268.800
jcerar
  • 467
  • 4
  • 13
meena
  • 1
  • 1
    Welcome, please take the [tour], read [ask] and use tag [tag:fortran] for all Fortran questions. There is no point tagging with some specific old versions of Fortran when your question does not even have any version specific code. You should make some effort to solve the problem yourself and show at least some code you have and the problems you face. We have *many* questions about data file reading here. Why can't you just skip 18 lines and read in the simple array? – Vladimir F Героям слава Feb 10 '20 at 13:57
  • Have you considered using the unix utilities `wc` and `tail`. `wc` will tell you the number of lines in the file. `tail` can be used to print the last XXX number of lines in the file. – evets Feb 10 '20 at 15:11
  • @VladimirF I am new to this platform.I will surely improve my skills of framing a coding related question. I have been able to read the lines of data using fortran code already as mentioned in the question. I am just trying to solve why the data is not being read as real number when i skip the first lines with character present. Thank you :) – meena Feb 14 '20 at 04:28
  • In that case you have to show us your code. Any question wantimg to explain why your code does this or that must include your code. See [mcve]. – Vladimir F Героям слава Feb 14 '20 at 07:13

1 Answers1

0

There are many examples how to skip/read lines like this

But to sum it up, option A is to skip header and read only data:

! Skip first 17 lines
do i = 1, 17
  read (unit,*,IOSTAT=stat) ! Dummy read
  if ( stat /= 0 ) stop "error"
end do 

! Read data
do i = 1, 1000
  read (unit,*,IOSTAT=stat) data(:,i)
  if ( stat /= 0 ) stop "error"
end do 

If you have many files like this, I suggest wrapping this in a subroutine/function.

Option B is to use unix tail utility to discard header (more info here):

tail -n +18 file.txt
jcerar
  • 467
  • 4
  • 13