Thank you all! @Arjen @FedericoPerini @Pap @RonShepard @mecej4 @MarDie @FortranFan ! I did not expected to received so many useful tip! Awesome!
There are two steps.
Step 1. Data file preparation. This data file is a csv file.
Step 2. Fortran read in the data file and then do the calculation.
The Step 1.
is done by the user using any software or programming language. Like Excel, Python, R, etc. This preparation of data file does not need to be done in Fortran. It is the user’s responsibility to check their data file and provide the correct data csv file with correct format.
In fact, the data csv file is basically some medical data. There are only two types of columns, numeric columns and character columns. Numeric ones, such as, the blood pressure, or some drug concentration at each time slot like i=1, 2, 3, … etc. Or weight, height, age, etc. Those are definitely non-negative numbers, no need to worry. For character type, they can be the patient ID, race, gender, etc.
For any missing data, the user will either leave a mark at that place, the mark is character dot, eg, “.” Or leave a -99 there. Note that, if it is a valid data like -99, the user must write -99 in float format such as -99.0 you know something like that. So if it is just exactly -99 it just means the data is missing.
The Step 2.
The old F77 code, creates arrays for numeric columns. Such as the real type array AAA
mentioned. It treats the place with “.” or -99 just as -99. Then it do the AAA(i) == -99
comparison. Anyway it just use this sloppy -99 magic number and lucky.
Now for me. In my code, actually, I always read any data as character first. Then depending on the content of the character, I convert them into the correct data type. This can prevent such -99 sloppy issues.
For example, I actually have two arrays,
real, allocatable, :: AAA( : )
logical, allocatable, :: AAA_valid( : )
I read in the data as character, if the character is " . " or “-99”, I set AAA_valid( i) = .false. Else, I set AAA(i) as the number converted from the character. So I do things like
do i=1, 100
if (AAA_valid(i)) then
... ! treat AAA(i) as a number some do calculation.
else
... ! I know AAA(i) is a missing data so I do something else.
endif
enddo
There can be more elegant way, but my way is to create logical arrays like AAA_valid( : ) to help the numeric array AAA( : ).