I am trying to compile someone else’s FORTRAN code using gfortran 4.4.6. The original coder used something like Compaq FORTRAN.
The code in question is supposed to read a filename like ‘foo.txt’ and create a new file called ‘foo_c.txt’:
file_label_end = SCAN(filename, '.') - 1
WRITE (output_filename,5) filename
5 FORMAT (A<file_label_end>, '_c.txt' )
gfortran complains about the opening angle bracket of the character specifier. That is, rather than “A3” he has “A<(a variable with value 3)>”. I cannot find any information about interpolating format widths from variables… Is this possible? If not, what’s the best way to fix this?
Update:
This seems to be working (compiling):
file_label_end = SCAN(par_filename, '.', .TRUE. ) + 1
output_filename = par_filename(1:file_label_end) // '_c.par'
but I later have a similar case:
12 FORMAT (<n-1>F10.5) ... READ(1,12) (cat_parm (blk,j), j = 1,n-1)
which I attempted to fix by creating a format string:
write(fmt12,'(I0,A4)') n-1, 'F10.5' !12 FORMAT (fmt12) 12 FORMAT (fmt=fmt12)
But the “t” in “fmt” gets flagged with an error about “Nonnegative width required in format string”
The use of
<>in Fortran edit descriptors is non-standard, though widely implemented. You certainly can build edit descriptors from variables, the standard way is through an internal write, something like this (omitting declarations):and then
But in your case this is not entirely necessary. You could try this instead
With the ‘a’ edit descriptor omitting a width means that all the characters in the expression will be written. You may want to declare
if you haven’t already done so.