Week 9 Questions


Fortran

Why do we learn Fortran 90 when we have a Fortran 77 compiler?

The choice of names for the compiler in Hammond was not mine. As I've said before, it is in fact a Fortran 90 compiler. Many of the examples that I've provided, and some of the homework requirements have involved Fortran 90 specific constructs. You are learning Fortran 90 because it makes your job as a programmer easier, particularly with the rich choice of intrinsic functions. Again remember that anything in Fortran 77 is also part of Fortran 90. I am careful to distinguish those features that are unique to Fortran 90 for 2 reasons. First is to save you problems in the unlikely event that you are stuck on a machine with an old Fortran 77 compiler. Second is to allow you to pick up an old Fortran 77 program and wisely add Fortran 90 features where appropriate. This could be worth real dollars to you some day.

When you are shifting characters, won't this also shift and number's you read?

Yes and no. At the stage you see me shifting characters, the "numbers" are still really just strings of characters that have no meaning to the computer as numbers. I can move them around as much as I want as long as I don't disrupt the sequence of characters giving digits, decimal point and exponent. It is only through the process of a READ with a * format or ,"i", "f", "e" or related edit descriptor, that the characters we typed into the file are converted to internal representation of a number (integer or real). In particular, the default format '*' is smart enough to scan a character string, and based on the variable type that you request in the READ, obtain a value if your characters make sense, regardless of leading or trailing blanks.

Can you explain parsing and concatination again?

Parsing is the act of deviding a "sentence" into individual "words". Normally the separation that indicates "word" boundaries is a space or a comma. In computer applications the list of separators may be expanded, or completely different. However, the separators are always defined within the program and used for isolating "words". Once this separation is complete, individual words (or proper sequences) can be tested by the computer for "meaning" that cause the program to assign values to specific variables, or take other more complex actions. You are looking at the very beginning of language recognition.

Concatination is the inverse operation. You will frequently find that you have isolated words or phrases containing information that you want to tack together to form a coherent "sentence". At your stage, you are tempted to say "so what, I can already do that with formats". Usually true, but more awkward. When you get into passing arguments to graphics routines, the direct manipulation of characters becomes even more useful. Suppose I want the flexibilty to display results in either metric or English units. I need to give a plotting subroutine labels for the axes as character strings. I might have a CHARACTER array "varname" containing names for all variables of interest:

varname(1)='Temperature'

varname(2)='Pressure'

etc.

Actually, I probably would set these values in a DATA statement. For the units, I would actually use a doubly dimensioned array, but we aren't there yet, so I'll use two more regular arrays:

metric(1)='K'

metric(2)='Pa'

english(1)='F'

english(2)='psia'

etc.

Depending on user choice in the variable to output, and units to use, I will construct a full label with a concatination line like:

label = varname(i)//'('//metric(i)//')'

As we saw in the example this could result in contents of label with too many spaces:

Pressure (Pa )

(i=2 in this example). The solution to this is to use the "trim" intrinsic function

label = trim(varname(i))//' ('//trim(metric(i))//')'

giving a value in "label" of

Pressure (Pa)

Your plot is properly and cleanly labeled, ready for formal presentation. Why didn't I include the parentheses in the contents of the "metric" and "english" arrays? To use those same arrays for printing numbers like "200 psia".

I am still confused about arrays and character variables.

At this stage, the best thing you can do is make an appointment to talk about these features with me. I need to pin down the source of the confusion, to provide a useful explanation. One other thing that may help you is to decide what you think arrays and character variables are doing, and write some very short programs to see if they behave as you expect.

Where are all or your CHARACTER variables coming from in your examples?

In the charvar.f and charvr90.f examples the vast majority of the CHARACTER strings are coming from the input file. The important thing that you must remember for any computer language is that the contents of a file created with an editor like "vi" or "emacs" are just characters. You can use FORMAT edit descriptors, or "*" default formats to convert the characters to numbers in many cases. However, you have the most flexibility by bringing the contents of the file into your program as characters, and then using appropriate tests within the program to sort out what the characters all mean. You are programming the computer to do the sorts of things you do when you read on this page "Temperature = 300.2".

If you have a number like 11.5967 and you print it with format f4.1 will it output 11.5 or 11.6?

It rounds up to 11.6

Can you use an INQUIRE statement to find out if "temp.data" is being read?

Yes, the command "inquire (file='temp.data', number=iunum)" returns a value of -1 if the file is not currently connected to a unit number, or the value of the unit number, if the file has been opened. Its up to you to include logic to decide if that unit number is used for READ or WRITE.

What is an ASCII character?

A standards group got together and decided what "characters" would be useful for computers. These include the obvious upper and lower case alphabet, characters to represent numbers (0,1,2,3,4,5,6,7,8,9), and other odds and ends that you see on the keyboard (: , . " ' + = - / \ ~ and others). They also included "control characters". This is what results when you hold the control key and hit a letter key. These characters were all written down, and each given a unique number from 0 to 127. The resulting standard relation between numbers and letters helps computers communicate character information back and forth without converting the underlying binary numbers to nonsense.

Why bother with arrays?

The big reason for arrays is the relative speed of computer memory and computer disk. Yes, I could constantly cycle through the file temp.data as I need to use temperatures for various calculations. However, it is much faster (factors greater than 1000) to read the information into memory once, and use the data from memory whenever needed. The homework problem is deceptively simple. I can come up with useful calculations that would use that temperature (and probably other information like pressure) thousands to millions of times.

The array language structure is nice because one name plus an index: temp(i) covers all of the information that I might need. Without arrays I would be stuck creating variable names temp1, temp2, temp3, ... temp288 to keep things in memory, and would have to go back and add new variable names if I wanted to go to two days worth of data.

What were we trying to do with the program today? What do the Character Variables do?

The example had two purposes. One was to exercise the basic operations and intrinsic functions that we learned for Character variables. It gives you a chance to see what the operations do, but only if you take the time to run the program on your own, and look at both the programming and resulting output. The second purpose was to demonstrate the use of processing character variables in creating a program with more diagnostics. I must read the input first as characters to be able to sort out extra comment lines in the input deck, and labels telling what numbers mean and to which internal variables the numbers should be assigned.

I need more terminology to talk to others about a Fortran program. What other phrases are there than "Tougher than all get-out" and "A fine construct".

Since we're at a University, it's essential that you work the work "paradigm" in there somewhere. How about "optimal paradigm for implementation of the algorithm".

General Computing

What is pipelining and what does it do for us?

Pipelining is feeding a steady (once per clock cycle) stream of numbers to an arithmetic unit. We don't do it directly, but make it easier for the compiler to set up, by using as many Fortran 90 array constructs and array intrinsic functions as possible ( a(1:n)= b(1:n)*c(1:n) or xsum=sum(x(1:n)) )

Class Procedures

How important are all the CHARACTER intrinsic functions for the next test?

Know INDEX and LEN cold. As for the rest, it is important only to remember that Fortran takes care of those tasks for you, but you don't need to memorize function names or argument lists.

Can you help us do hw8.f

Yes. As I said early in class when you hit a dead-end for any reason. Set an appointment with Willie or I to get help finishing the job. This includes selecting the right Fortran structures, and making sense of all those mysterious compiler error messages.

How much on character variables in the next exam?

The exam covers 5 weeks of material, one of which was spent on various aspects of character variables. No more than 20%, no less than 10%.

Will we be using "achar" and "ichar" a lot, during the rest of the semester?

You will have at least one opportunity to use it, but at will be able to avoid it if you chose. You will have to do some general character manipulation in homeworks.

Will you give out copies of Exam 2.

Will try to give copies to the Nuc Eng. receptionist today. Call or E-mail me if I forget.