Reading input files in FORTRAN
Posted
by lollygagger
on Stack Overflow
See other posts from Stack Overflow
or by lollygagger
Published on 2010-05-11T18:43:46Z
Indexed on
2010/05/11
18:54 UTC
Read the original article
Hit count: 189
fortran
Purpose: Create a program that takes two separate files, opens and reads them, assigns their contents to arrays, do some math with those arrays, create a new array with product numbers, print to a new file. Simple enough right?
My input files have comment characters at the beginning. One trouble is, they are '#' which are comment characters for most plotting programs, but not FORTRAN. What is a simple way to tell the computer not to look at these characters? Since I have no previous FORTRAN experience, I am plowing through this with two test files. Here is what I have so far:
PROGRAM gain
IMPLICIT NONE
REAL, DIMENSION (1:4, 1:8) :: X, Y, Z
OPEN(1, FILE='test.out', &
STATUS='OLD', ACTION='READ') ! opens the first file
READ(1,*), X
OPEN(2, FILE='test2.out', &
STATUS='OLD', ACTION='READ') ! opens the second file
READ(2,*), Y
PRINT*, X, Y
Z = X*Y
! PRINT*, Z
OPEN(3, FILE='test3.out', STATUS='NEW', ACTION='WRITE') !creates a new file
WRITE(3,*), Z
CLOSE(1)
CLOSE(2)
CLOSE(3)
END PROGRAM
PS. Please do not overwhelm me with a bunch of code monkey gobblety gook. I am a total programming novice. I do not understand all the lingo, that is why I came here instead of searching for help in existing websites. Thanks.
© Stack Overflow or respective owner