Format string corresponding to list-directed I/O

I have long wanted this capability too, going back even to f77 days. My main use is for data files that are written in the general form

cfmt
…data list…
cfmt
…data list…

I would like to simply read the format string and then use that format string to read the following data block.

read(nin,’(a)’) cfmt
read(nin,cfmt) …data list…

If the data are written in fixed columns, then a fixed width format is appropriate, especially when the data items are not separated with spaces or commas. Otherwise, list directed input is appropriate, but the above simple approach does not work because there is no cfmt format string that naturally triggers ldio. So instead, the above if-else-endif block is required to select the appropriate read statement. The last I checked, there was no g0/i0/f0 type format that would work either, although I have not kept up with the latest fortran standard revisions, so maybe this had been recently addressed? The annoyance is exacerbated because different combinations of data types require separate if-else-endif blocks, it cannot be localized within a single subroutine.

1 Like