Fortran: how can double precision variable read and hold string content from an input file

StackOverflow https://stackoverflow.com/questions/18565591

  •  27-06-2022
  •  | 
  •  

Question

I'm converting a rather large old fix-format code written in Fortran 77 to free-format. Within the code I frequently encounter read statements like

DOUBLE PRECISION :: VARIABLE

read(1,10) VARIABLE

10 format(2A10)

However, what it reads from input file is in fact a line of string. The code runs perfectly fine, but it crashes when one tries to read VARIABLE from a namelist instead of a fixed format input file.

How is this possible in Fortran? Is there any reference where I can find more information about? Any help is greatly appreciated.

Était-ce utile?

La solution

This comes from the days before F77 when doubles and integers were used for storing characters. From the format statement, this is probably from a CDC which could store 10 six bit characters in each word. Double precision was two words so it was two lots of 10 characters. If you change the code to

CHARACTER(LEN=20) VARIABLE
READ(1,10) VARIABLE
10 FORMAT(A20)

It should work. There isn't a lot of information about on CDC compilers. I've never tried using a namelist with one so I can't really comment about it. Try http://bitsavers.trailing-edge.com/pdf/cdc/cyber/cyber_70/chippewa/Chippewa_Fortran-Run_Apr66.pdf

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top