Before I begin, I must preface by stating that I am a novice when it comes to FORTRAN. I am maintaining a legacy piece of code from 1978. It's purpose is to read in some data values from a file, process the values, and then output the processed values to another text file.
Given the following FORTRAN code:
INTEGER NM,STUBS,I,J,K
PARAMETER (NM=67,STUBS=43)
INTEGER*4 MDS(STUBS,NM)
CALL OPEN$A(A$RDWR,'/home/test/data.txt', MAXPATHLEN,1)
CALL OPEN$A(A$WRIT,'out',11,2)
DO 90 I=1,2
READ(1,82) STUB
!-- data processing --!
WRITE(2,80) STUB,(MDS(I,J),J=1,24)
90 CONTINUE
80 FORMAT(/1X,A24,25I5)
82 FORMAT(1X,A24,25F5,1)
My question is in regards to the WRITE()
statement.
I understand that (2,80)
refers to the file output stream opened and pointing to the file 'out'
and referenced by the numeral 2. I understand that 80 refers to the format statement referenced by label 80.
STUB
is used to store the values read from file input 1. These values are what is processed, and saved into MDS(I,J)
in the !-- data processing --!
section that I have omitted.
Am I correct in assuming that (MDS(I,J),J=1,24)
will write 24 integer values to the output file? In other words, looping from 1 to 24?
The WRITE statement writes data from the list to a file.
The read and write statements respectively are used for reading from and writing into a file respectively. Most of the specifiers have already been discussed in the above table. The END = s specifier is a statement label where the program jumps, when it reaches end-of-file.
What is the difference between a PRINT and a WRITE? A print always outputs to the "default device" generally the terminal screen. A write sends things to a numbered unit that may be the screen, a disk file, or sometimes a printer (see OPEN statement for connecting unit number to a file).
Yes, you are correct. The syntax (MDS(I,J), J=1,24)
is an "implied DO-loop" and is commonly used in situations like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With