Fortran

Guide To Learn

How do I create numbered file names such as out_01.txt, out_02.txt etc.?

A: Use an “internal write” to create the file names, for example

write (file_name,"('out_',i2.2,'.txt')") i

A: A neater way to do this would be:

i=<file number>
WRITE(file_name, fmt = '(A4,I0,A4)')'out_',i,'.txt'

This way the formatting is clear and you are writing the correct string to the variable. I assume you wanted an integer as the number. ‘I’ format statement requires an Integer length, or zero in some cases. You are probably thinking of F where the decimal point denotes the number of decimals to consider.

How do I create numbered file names such as out_01.txt, out_02.txt etc.?

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top