Week 8 Questions


How do we make sure that all new data is being added to the end of the file "temp.log"?

open (12,file='temp.log', position='APPEND')

How do we get started on the Subroutine for file input on HW8?

Best place to start is the subroutine that determines the array space required for information in the "temp.data". In that routine open the file and include a counting loop like the one in array3a.f , including the final REWIND of the unit attached to "temp.data". Exit the subroutine, allocate the space in the main program, then call a subroutine that does a simple read of the contents of "temp.data", putting the contents of each column into a different array.

Actually everything you need to know about reading the input for this homework is tucked away in array3a.f. The "DO 30 " loop demonstrates the type of READ that you will need to use to load your arrays for processing. I would consider allocating 3 arrays: one for time, say "time" (watch the times at the end of the file, you may want to write code to convert the 00.xxxx stuff following the 23.99961 entry to 24.xxxx ); one array for station number, say "nstation"; and one array to hold the centigrade temperature, say "tc" (you may also want an array to hold the equivalent Fahrenheit temperatures when they are generated). At this point assuming "temp.data" is attached to unit 11, the equivalent loop for your homework should look like:

do 30 i=1,ndat read (11,*) time(i), nstation(i), tc(i) 30 continue Here I assume that "ndat" is the number of lines of data in "temp.data", and that you got that value when deciding how much space to allocate for the arrays.

How do I use MASK to get information for HW8?

One simple example is this. Suppose the INTEGER variable "istat" contains the number of the station for which want information. To obtain the minimum temperature (say "tmin") at that station (using arrays that I defined in the previous question), use the following simple line:

tmin = minval (tc(1:ndat) , mask = nstation.eq.istat) How do you get a FORMAT statement to write the titles in the file you write into?

Take a look at the "1000" FORMAT in format.f . Titles involve, making a decision on exactly where you want them in the line, then constructing a FORMAT with the appropriate mix of spacing (X edit descriptors), and quoted strings. I could put this title anywhere, just by changing the unit number on the WRITE statement.

open (11,file='test.out') write(11,1000) 1000 format(14x,' Pressure',13x,'Temperature',17x,'Density') would put the same title string into file "test.out", that format.f wrote to the screen.

I saw "WRITE(6,2000) in sample programs. Doesn't the '6' have to be opened?

This is very old (and bad) habit on my part. The long tradition in Fortran is that Unit 6 is the default output device (same as using *). Best to just use the *.

What makes the difference when you use different descriptors like i, f, e, p? Could you explain some of these examples like 1p, e9.3, 3x,?

"i" only works if the variable to be output in that position is an INTEGER. "i5" says output an integer in the line allowing 5 spaces to do the job. If the integer is only 2 digits, the first 3 of the 5 spaces are blanks, and the last 2 contain numbers.

"f" only works if the variable is REAL, and puts out a simple decimal number like 1.1, 2.123, etc.

"e" only works if the variable is REAL, and puts out a number in exponential notation like 0.1234e+01, 0.999e-01, etc.

"p" is for use only if you get tired of the leading zero in "e" format. If the variable x contains 1.23400000, then the write:

write(*,1000) x 1000 format(' x = ',1p,e9.3) give a resulting line

x = 1.234e+01 One key item is to get used to synchronizing the use of "i", "f", and "e" with the variables in the WRITE statement. For

write(*,1001) icount, x, y 1001 format ( ' At icount = ', i5, ' x = ', f5.2,5x, 'y = ',1p,e12.3) The "i5" is the first variable descriptor in the FORMAT and tells you how to output the first variable listed after "write(*,1001)" (icount). The "f5.2" is the second variable descriptor in the FORMAT and tells you how to output the second variable after the WRITE (x). The "e12.3" is the third variable descriptor and tells you how to output the third variable being written (y), as modified by the preceding "1P". The "5x" inserts 5 blank spaces between the end of the printed value of "x", and the beginning of the printed string "y ="

Spend some time running format.f and looking at how each combination of WRITE and FORMAT statement produces results on the screen.

Class Procedures

When is the next exam?

Tuesday March 26, 8:15 PM, Same room as last time (64 Willard).

Can we have some extra time on HW8?

Yes, now due Monday, March 18

Computational Solution Methods