# Fortran 90 help reading from file

• Fortran
Hi All

I'm completely new to Fortran 90 and I have to create a program that opens a formatted data file and reads in certain values into my program's variables. The variables are represented in the first six rows with ncols, nrows, xllcorner, yllcorner, cellsize and NODATA being the variable's labels. The format of the data file looks like this but the content of the variables will change depending on data file:

ncols 5
nrows 4
xllcorner 2000
yllcorner 3000
cellsize 10
NODATA -9999
6 7 8 9 10
7 8 9 10 11
8 9 10 11 12
9 10 11 12 13

Ncols, nrows will always be integers but the other variables are most likely going to be double precision numbers.

So far I have programmed the code that opens the file (the file is supposed to be called DEM.in):

integer :: st

if (st>0) then
print*,'Error opening file. File load status:', st
stop
else
print*, 'File openend correctly'
end if

Can anyone help me or indicate me into the right direction on how I can program the code that will read in the values in my data file (5, 4, 2000, 3000, 10, -9999) and write them into my program's variables (ncols, nrows, xllcorner, yllcorner, cellsize, NODATA)? Any help is greatly appreciated; remember I'm a novice with Fortran so labelling any code will be extremely useful.

Thanks very much guys

Jospaghetti

minger
As long as your variables are defined correctly, then you can just do an unformatted read which will read in the variables correctly.
Code:
PROGRAM
IMPLICIT NONE
INTEGER :: ncols,nrows
REAL(kind=8) :: xllcorner,yllcorner
OPEN(11,file='file.x',form='formatted')
END PROGRAM