Command file with card system in Fortran90
I. Introduction
Fortran is a general-purpose programming language that is especially used for numeric computation and scientific computing.
In a code, when digital data need to be modified to run multiple simulations, rather than writing data in the "hard" way in the code, modify and recompile
the code at each simulation, the usual method is to go through a command file which is read by the code during execution.
However, the digital data written to the file must be written in the same order and, furthermore, for a large number of variables change, it can sometimes
be difficult to navigate.
Here is a method that is to go from a command file to a card systen that can be modified as well as comments.
II. Example of command file
Here is a sample command file that we wish to establish suppose that our program deals with population data:
#INHABITANT
295012
#CHILDREN
1098
We'd like to organize data in whatever order you want (possibly the number of children before the total population) and possibly add cards that could be
commented with any character (in the following example only the last card INHABITANT not commented on by! will be displayed).
For example:
#CHILDREN
1567
!#INHABITANT
124590
!#INHABITANT
290745
#INHABITANT
104968
III. Function to search the map you want
Here is the function to read the cards and select one that interests us:
FUNCTION SEARCH_CARD(CARD_SEARCHED,INFO)
IMPLICIT NONE
CHARACTER*(*), INTENT(IN) :: CARD_SEARCHED
INTEGER, INTENT(OUT) :: INFO
!! LOCALs !!
CHARACTER*100 :: CARd
REWIND(66)
DO
READ(66,210,ERR=200,END=200) CARD
IF(CARD(1:1).EQ.'#') THEN
CARD = CARTE(2:100)
IF(TRIM(CARD).EQ.TRIM(CARD_SEARCHED)) THEN
INFO=0
RETURN
END IF
END IF
END DO
200 CONTINUE
INFO=-1
210 FORMAT(A100)
RETURN
END FUNCTION SEARCH_CARD
IV. Function to read the CARD you want
The previous function returns INFO =- 1 if the card is not found and INFO = 0 if the CARD is found.
To read the number of inhabitants, for example, simply run the following function:
FUNCTION READ_NUMBER_INHABITANTS (NUMBER_INHABITANTS)
INTEGER, INTENT (OUT):: NUMBER_INHABITANTS
! LOCAL!
CHARACTER * (*):: CARD
INTEGER:: INFO
CARD = 'INHABITANTS'
CALL SEARCH_CARD (MAP, INFO)
IF (INFO.EQ.0) THEN
READ (66, *, ERR = 123, END = 123) NUMBER_INHABITANTS
ELSE
WRITE (*,*) 'map', TRIM (CARD), 'n'' has not been found, you must'
WRITE (*,*) ''include in the batch file. "
STOP
END IF
RETURN
123 CONTINUE
WRITE (*,*) 'Error reading the number of'habitants on the map'
WRITE (*,*) TRIM (MAP), 'file commands. "
STOP
END FUNCTION LIRE_NOMBRE_HABITANTS
Source:
These codings a re based upon the codes written by Francis Collino, CERFACS.
This method is based on Fortran code by Francis Collino, CERFACS.