Question:

In FORTRAN 77, my program reads blanks as numbers...?

by  |  earlier

0 LIKES UnLike

For my postgraduate dissertation, I needed to process large amounts of meteorological data quickly, and since the university has a Unix system with FORTRAN, I decided to write a program in FORTRAN to do it.

In my program, I have 108 text files with my data in. A typical line from one of these files is:

1997 12 31 23:59, 9820, DCNN, 24, 1, NCM, 1585, 1011, 0, , , , , 0, 0, 0, 0, , , 1, 0, 0, 0, 1, 1, 1, 1, ,

My read command is this:

read(1,*,err=888)iyear,imon,iday,time,id...

& recst,sund,conc,lsnow,snowd,fsnow,snowda...

The variables I'm interested in are the ones with 'snow' in their names, as these correspond to the different snow measurements, as my data is from the MIDAS Land Surface stations observation (UK) data set. The variables after are not needed, so are not included in the read command.

My program checks the 'fsnow' (fresh snow) variable amount and if it is greater than or equal to 1 for that (weather) station on that day, it labels it as a 'day of snow'.

The program works fine for all years up to 1997, in that it only defines a day as a snow day if that 'column' contains a value. But in years 1997 onwards, if it reads a blank, it occasionally decides that the blank is actually a number. I've checked the original data and where my program has read values such as 1,2,4 and 7, there are blanks.

First of all, if anyone out there knows why it's deciding to read numbers from nowhere, then it would be useful to know.

Secondly I've read about read statements with formats. Previously I have used format statements for write commands but was unaware that they might be used for read commands. I have heard mention of 'BZ', which will apparently read blanks as zeros.

Sorry for the long description, I've tried to keep it as simple as possible. Thanks.

 Tags:

   Report

2 ANSWERS


  1. Jeff_in_Dallas makes a very good point: I would insert a PRINT statement directly after that read to verify that what was read in is actually what was in the text file.  


  2. Without seeing the code and data files I can't say for sure.  But this type of thing is usually something simple, such as the program is not reading the same line you think it is.  Or the data file has some feature that you haven't accounted for and therefore the variable is not in the position that you expect.

    Use very verbose output that shows extra details about what is actually being read.

    Good luck.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.