Silverfrost Forums

Welcome to our forums

Poor Fortran ...

20 Jan 2024 1:16 #30980

From the day 1 of my encounter with Fortran i was missing the following functionality: it recognizes its variables by name in the initial settings file (you name it):

Program ABC
Real : A=0, B=0, C=0
Integer :: i=0, j=0, k=0

LOAD 'Variables.dat'
print*, A, B, C, i, j, k

END

File Variables.dat contains (or not contains) in any order any variable without any formatting

i  =  1
k = 3
B = 222.
C =333
j              =2

A=111.

The result of execution of the code

111., 222., 333., i, 2, 3

May be it exists and i just missed it for 40 years?

20 Jan 2024 1:39 #30981

Dan, have you looked at the venerable NAMELIST feature of old Fortran?

With the program

Program ABC
Real :: A=0, B=0, C=0
Integer :: i=0, j=0, k=0
Namelist /AtoK/A,B,C, i,j,k

Open(10,file='Variables.dat',status='old')
Rewind(10)
read (10, NML = AtoK)
print*, A, B, C, i, j, k

END

and the data file Variables.dat containing

 &ATOK
 i=1
 j=2
 k=3
 A=111.
 B=222.
 C=333
 /

you have almost got what you wished for.

21 Jan 2024 12:19 #30983

Thanks mecej4, i think this is not bad too.

Though would be good to have also the 'default' version without declaring namelist (with default namelist to assume ALL variables in the scope of the program where you LOAD variables can be potentially loaded), writing its name inside the dat file and adding slash at the end which people will always forget to do. Because in current approach we still need to remember these rules. And what i see in MATLAB for example is that they broke all the rules and made everything ultimately simple. But I do not know if this is realistically doable

BTW, curious, why you put REWIND there? 😃

21 Jan 2024 2:00 #30984

Often, when testing new code, it happens that you write a file (with namelist output in this case) REWIND, and try reading back what was just written.

Did you ever spend time rewinding a 1/2 inch tape drive on an old computer?

21 Jan 2024 8:57 #30985

Experience like with rewinding older tapes happens to me 10 times a day RIGHT NOW with just the usual reading files despite all the modern hardware. Because the files are of gigantic size 0.25-1 TB total. Despite after multiple discussions on this forum the reading speeds now are top notch like PCIe allows, further even minimal sorting of that data on single core is a bottleneck and takes ages. Will need to implement multi-threaded parallel read/sorting with FTN95.

Please login to reply.