-2

I wanted to open two files in Fortran, but get the following error message:

Fortran Runtime Error: End of line

infile_T contains years from 1970 to 2100 and temperature values for these years. Infile_CO2 contains years for the same time period and CO2-values. I only want to load in the years and temperature values from 1970 to 1998.

Here is my code:

integer j,p, Jahre_CO2
character*20 infile_T, infile_CO2

parameter(infile_T='temp2m.obs',
     1          infile_CO2='yco2.sze',
     1          anfja=0,             
     1          endja=29,             
     1          nt=endja-anfja+1)

real T_beob(anfja:endja),Jahre_T, CO2_beob(anfja:endja)

  open(11,file=infile_T)
  do ja=anfja,endja
    read(11,*) Jahre_T,T_beob(ja)
  enddo
  close(11)
  print *,Jahre_T

  open(12, file=infile_CO2)
  do p=anfja,endja
    read(12,*) Jahre_CO2,CO2_beob(p)
  enddo
  close(12)

  write(6,*) 'Daten eingelesen !',T_beob
Ian Bush
  • 6,996
  • 1
  • 21
  • 27
  • 1
    The error is telling you that you are trying to read values from a line, but that the end of the line has already been reached. What format are your files in? – veryreverie Aug 28 '22 at 12:23
  • 2
    I'm afraid with what you have told us it is all but impossible to answer. Examples of the files you are trying to read are needed, and a *complete* code would be very useful as well. – Ian Bush Aug 28 '22 at 12:25
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 28 '22 at 23:30
  • You may be reading one more line. You want the data from 1970 to 1998. So there is 1998-1970+1=29 years of data to read . I suppose each row represents data from a year. So you want the 29 first rows. But you are reading the first 30. We can't guess what's wrong unless we know the format of the data whithin the file. Open your file with any editor to check its format. The format of the data should not be confidential, maybe the data. – L Maxime Aug 30 '22 at 07:24

1 Answers1

0

Make sure your files contain all the data you expect them to contain. If your files contain 130 lines and you're only reading in 30, you shouldn't receive an end of file error.

Check the format of the data. Usually 'years' (Jahre) are integers ; so you have Jahre_CO2 as integer, but Jahre_T as real -- double check this.

rosenbe2
  • 19
  • 1