Week 4 Questions


Fortran

What happens if a DO WHILE statement doesn't stop running?

Very good question! Sometimes you aren't careful enough with your logical expression in the DO WHILE line, or with other options to exit the loop, and this does happen. On most Unix computers, you will be sitting around half of forever waiting for the program to be killed. If you believe that it has been running too long, hold the Control key and hit the "c". If you don't see an obvious error, turn on dbx, set a breakpoint on the next statement after the DO WHILE, and watch the evolution of variables that contribute to you logical test that keeps the loop running. When you see what is wrong, type "quit" at the dbx prompt, to end the session.

When is it better to use a DO WHILE instead of an IF statement.

Avoid the use of IF statements combined with GOTO to repeatedly loop over the same block of code. This is a job for DO WHILE or simple DO statements. IF statements are for simple decisions to do one thing or another (or another...) then to move on to other code.

What is a SELECT CASE statement?

It is really just another (often more convenient form) of an IF, THEN, ELSE. For the lecture notes example:

select case (i) default case cond = 0 case (1:5) cond=condUO2(temp) case (7) cond=condZr(temp) end select You could also write:

if (i.ge.1.and.i.le.5) then cond=condUO2(temp) else if (i.eq.7) then cond=condZr(temp) else cond = 0 endif

Can you use <, >, = in your CASE statements?

Yes as part of logical expressions, but the CASE becomes more complex than using IF, THEN, ELSE. For example I can do the following:

select case (i>1) case (.true.) print *, 'i>1' case (.false.) print *, 'i<= 1' end select Is the DEFAULT CASE widely used in programming? What type of programs?

Fortran 90 is too new for any of its new constructs to be "widely used". However, DEFAULT CASE is a variation of the simple ELSE statement. ELSE is very widely used. IF, THEN, ELSE IF, ELSE Anytime, you have a simple logical decision to do one thing (IF, THEN), or another(ELSE IF), and a totally different thing to do if your simple tests fail (ELSE). One fairly universal use of this logic, is in subroutines for processing input. A given user response is compared to a series of accepted responses and appropriate action is taken in each case. An ELSE (or DEFAULT CASE) takes care of sending an error message when the user provides unrecognized input. You will discover many more ways to use this in Fortran or another language as you continue to program.

How does the compiler know how to use the "i" in "go to (100,200,400,600 ) i". In general the GOTO statement is confusing.

Whenever a "go to" is followed by a set of integers in parentheses, the compiler only knows of one thing to do with the "i". The compiler actually converts this structure to a bunch of machine code IF branch statements. The effect of this is that if "i" has a value 2, then the computer branches to execute the statement with label 200. If "i" has a value 3, then the computer branches to execute the statement with label 400. If "i" has a value greater than the number of integers (labels references) within the parentheses, then the next statement after the "go to (100,200,400,600) i".

All a GOTO does is to change the flow of the program. When a GOTO is reached, it generally tells the CPU to execute an instruction somewhere in memory other than the next location after the GOTO. Look at an example with GOTOs or write one of your own, and watch it execute with dbx, using the "step" command to see each statement as it is executed.

Does the computer compile everything between END statements separately.

Yes. Every time it hits an END statement, it compiles everything since the last END (or the beginning if no previous ENDs). The separate compilations are stuck together at the very end by a process called linking.

.I'm still unclear about dbx. Could you or Willie hold a help session just for dbx?

The regular office hours and help sessions are not heavily attended. Stop by then or schedule another time with me to run through some dbx sessions.

How do you get rid of the dbx prompt when you're finished using it? Also, how do I get it to run properly? I tried it on hw3.f and it gave me some trouble.

To get rid of the dbx prompt type "quit". Most programs let you out with either "quit", "end", or "exit". When all else fails try holding down the Control key and hitting C or Z. Control Z just suspends you job, and you may get a message about "Stopped Jobs" when you try to exit from Unix. In this case Unix lets you out, and destroys the stopped job, if you type "exit" a second time.

To get dbx running properly, try keeping a printed copy of the dbx lecture next to you to remind you of key instructions. It would probably also be useful if you run through a few sample dbx sessions with either Willie or me (see above).

.I'm still unclear about dbx. Could you or Willie hold a help session just for dbx?

The regular office hours and help sessions are not heavily attended. Stop by then or schedule another time with me to run through some dbx sessions.

Can you explain exactly what dbx will do for me?

Exactly? Probably not. As I've said in class it will let you follow the flow of a sample program and watch values change on all variables so that you will understand how the Fortran (or C) statements are operating. You may not fully appreciate the more important aspect of dbx until you start writing much longer programs than we attempt in this class. An important aspect of any programming effort is generating an independent check on the program's results. What do you do when the independent check and program don't match. With dbx, you can quickly examine the intermediate results within your program, comparing them to intermediate results in your independent check, or simply looking for wacky numbers. This generally isolates the cause of the bad result faster than staring at several hundred lines of code until you see something wrong.

How do you get rid of the dbx prompt when you're finished using it? Also, how do I get it to run properly? I tried it on hw3.f and it gave me some trouble.

To get rid of the dbx prompt type "quit". Most programs let you out with either "quit"

You went over Fortran 90 structures. Is there a Fortran 90 compiler on the Workstations?

Yes there is, but they have cleverly named it f77. This makes us long time programmers more comfortable, but adds to the confusion of new students of the subject.

Unix

I learned that !v gets you back into the file in vi you were working on. Are there any other shortcuts you can tell us.

Actually "!v" executes the last command that started with the letter "v". You can use the same idea to compile the same file again with "!f", assuming that you haven't executed any other commands starting with "f" since the last use of "f77". If you had used the command "find" after the last compile, you could go to a longer abbreviation of "!f7" to redo the compile.

You can create your own shortcuts with the "alias" command, particularly by including "alias" commands in your ".cshrc" file. If you get good enough with Unix, you can also create shortcuts by writing scripts (files containing a series of Unix commands).

General Computing

.How Do I paste between windows.

Basically the same way you copy and paste in a Word Processor. Highlight the portion of one window that you want to copy by holding down the left mouse button while you drag the mouse cursor. If you are connected through Telnet, select the copy item from the Edit menu of your terminal session. If you are using an Xterm do nothing more in that window. In the other window you must have the file, where want to paste, open with an editor (for now vi) and in text insertion mode with the cursor at the position where you want the text. Click on the destination window. If you are connected through Telnet, select the paste item from the Edit menu of your terminal session. If you are using an Xterm click the center button of the mouse. The copied text should appear in the second window.

How exactly do you get two screens?

I assume you are working from a PC. The way to do it is to open two separate Telnet sessions. After you start the first, point at the bottom line of the window with the mouse hold down the left mouse button, and push the bottom up to shrink the window to about half the height of your full computer screen. Point at the title bar at the top of the Telnet window, hold down the left mouse button and push the Telnet window up or down until you can see the Telnet icon again in the Internet Access group. Double click the icon to start the second session, perhaps logging into a different Hammond machine. Repeat the resize operation and move the windows until they are both visible.

Class Procedures

Are the rest of the homeworks going to be in groups?

Most, but not all. The long programs will be in groups, a few short exercises will be individual.

How would we know our grade for each individual homework? Will they be posted somewhere?

I keep a posting on my office door, and will post the grades on the classroom walls from time to time.

What is the purpose of the groups and what will we be doing in them?

You may have discovered by now, that it is possible to spend large amounts of time looking for a relatively minor typo or programming error. The purpose of groups is primarily to force you to cross check each other, and pick up problems sooner. This becomes more important as homeworks get longer. In fact my suggestion is that the initial programming attempt not be done by the entire group. You should develop independent programs individually or in pairs. Compare results, then document one that you know is giving correct answers.

Another purpose for groups is to help you prepare for the type of environment you will face when its time to earn a real salary. Very few jobs involve individual efforts. You need to start adapting to the process of working in groups.

Can you have hours on Monday's

I assume you're looking for something other than my normal 9-10AM in my office. Remind me to poll the class for interest in an organized session. However, remember that I am fairly flexible in scheduling special appointments. You can usually get an appointment for help at other times of the day.

Is there a way to see what we did wrong with our homework, to find out what we did wrong?

Yes, check with Willie. He keeps notes on all grading. We'll start sending mail on all less than perfect work.

How do I print the sample exam's?

When in the Postsript viewer (Ghostview) click on the "File" menu, and click on the "Print" item. If a menu comes up asking for the printer name just hit the Return (Enter) key to take the default (or click on the OK button). This worked at all PC labs last time I checked (December). If there are problems, see me.

Will you provide answers to the Exams?

Thought I had, but just discovered that only Exam2 and the Final have answers highlighted or typed in cross-out mode. Will try to get a patched copy of Exam1 out later this week.