# Week 5 Questions

### Fortran

When you write a number in the form "10." does that mean "10.0"?

Yes. Fortran just needs the decimal to interpret the number as a REAL type. "10.", "10.0", "1.e1", "1.0e1", "1.0e01", "1.0e+1", and "1.0e+01" all are the same number to Fortran.

When naming a DO loop, why did you use "loop1: do" to start the loop, and "end do loop2" to end it?

Because my brain was disconnected from my fingers. The names should be consistent. A loop beginning "loop1: do" should end with "end do loop1." Sorry for any damage on that slip. No test questions on do loop naming.

I don't understand what the 3 arguments in DO loops are or say. For instance "do 100 i=1,10,2"

Best way to do that is to look at what happens to a sample loop. Try the following:

do 100 i=1,10,2 print *, ' In loop i = ',i 100 continue print *, 'After loop i=', i The printed results will be:

In loop i = 2 In loop i = 4 In loop i = 6 In loop i = 8 In loop i = 10 After loop i = 12 Your DO statement said to do the loop the first time with i=2, do the next time with i=2+2=4, do the 3rd time with i=4+2=6, and keep doing the statements in the loop with i incremented by 2 until i >10. When i>10, don't do anything in the loop again and move on to the next statement after the end of the loop.

Is it possible to use the values generated in the middle of a do loop?

Yes, look at the example above. The variables y and dfdx are generated in the middle of the loop, but also "used" in the print statement below the loop.

With the DO loops, if you have "do 100 1,10" and no third number to set the increment, does Fortran automatically make the increment = 1?

Yes. The following example compiles without errors:

do 100 i=1,5 print *, ' In loop i = ',i 100 continue print *, 'After loop i=', i and the printed results will be:

In loop i = 1 In loop i = 2 In loop i = 3 In loop i = 4 In loop i = 5 After loop i = 6

Does it matter if you use DO WHILE or loops like DO 100? Does it make any difference?

You can do any looping task with either form. The difference is in the level of convenience. If you are going to be stepping some INTEGER as the loop proceeds (counting), use the "do 100 i=imin,imax,istep" form. If it is easier to do your conditional tests somewhere in the middle of the loop, go with the do 100 type loops again.

Do IF and DO loops only do comparisons?

They do comparisons and then branch to different instructions based on those comparisons.

Do DO loops only do comparisons for greater than unless otherwise instructed?

A simple DO like "do 200 i=1,10,2" is just looking to see if "i" is greater than 10. However, note that "do 200 i=10,1,-1" will be watching to see if "i" is less than 1.

In my main program, the argument list for a function is "(x,dfdx), and in the function it is "(x,deriv)". What happens if I use the variable "deriv" from the function in the main program? Will it have the same value as dfdx or will it give me an error?

Here's a sample of what I think you're asking

program test implicit none real x,y,dfdx,deriv,f x=10. y=f(x,dfdx) print *, ' x = ',x,' y = ',y, ' dfdx = ', dfdx, 1 ' deriv = ',deriv stop end function f ( x, deriv) implicit none real x,dfdx,deriv,f deriv = 2*x f = x**2 return end If you compile and execute this program you will usually get no compiler error messages a result of:

x = 10.0000 y = 100.000 dfdx = 20.0000 deriv = 0.00000E+00 What has happened is that the variable named "deriv" in the main program is totally unrelated to "deriv" in the function "f". Because no value has been assigned to "derive" in the main program. It simply contains the value of 0.0 that was loaded into it's location in memory when the program was created. By the way, you should not rely on zeros being loaded into variables if you don't tell the computer anything else. The variables "dfdx" in the main program and "deriv" in "f". are related. Because they occupy the same position in the argument list of the function and the reference to the function in the main program, the two names refer to the contents of the same address in computer memory.

What is the difference between an argument and a dummy argument, and how do they interact?

The author of the text and I use different terminology for this feature. In the text the variable names between the parentheses when a subroutine is called or function is referenced

call test1 (x1,x2,x3) y=2*test2(x1,x2,x3) are called actual arguments. I tend to refer to these as arguments of the calling sequence. The text refers to the variable names listed between the parentheses in the FUNCTION or SUBROUTINE statement

function test1 (y1,y2,y3) subroutine test2 (y1,y2,y3) as dummy arguments. I tend to avoid this term from habit. I simply talk about the argument list of the subroutine or argument list of the function where the text uses the term "dummy argument". However, the text follows the terminology used in the formal specification of the Fortran Standard.

As to interaction, the calling sequence (actual arguments) establishes locations in memory that will be represented by corresponding names in the subprogram argument list (dummy arguments). The calling sequence (actual argument list) is dictating where things will actually be stored in the computer. The subprogram argument list (dummy argument list), is providing a translation to tell you what name is going to be used in the subprogram to symbolically represent the memory locations passed from the calling sequence.

Can you have a function with its own name in the calling sequence?

y= 2.* dist (dist,range) Don't even think about that one. Once you learn to use EXTERNAL and INTRINSIC statements, and perhaps the Fortran 90 RECURSIVE keyword. You might be able to fool a compiler into taking something like this, but I can't predict what it would do, and someone trying to read your code would have serious trouble following your train of thought. If you want to create a recursive function call, learn the proper use of "RECURSIVE FUNCTION" or "RECURSIVE SUBROUTINE" statements. I probably won't have time to cover that in class, but will be happy to give you an example on request.

What exactly does "implicit none" mean?

If you don't say anything about variable types (no REAL or INTEGER statements, and no IMPLICIT NONE), Fortran implicitly assumes that variables beginning with the letters a through h (or A through H) are REAL. It assumes that those beginning with i through n (or I through N) are INTEGER and those beginning with o through z (or O through Z) are REAL. "IMPLICIT NONE" says make no implicit assumptions, and requires that you declare the type for every variable (or function) that you use. This protects you from typos.

### Unix

How would I go about printing a program that I have written?

Easiest way is to move it to a PC with FTP, open it with your favorite Word Processor, and print like any paper. I recommend setting the font to 10 point Courier at the top of the document. If you are in 316 Hammond and want to print a program named "test.f", try the Unix print command:

lpr -Pasci test.f

### General Computing

Important note: While tracing Willie's printer problems in 316 Hammond, I discovered that the laser printer for the workstations has been moved since the beginning of the semester, and is now on the lab side of the temporary partition next to the windows.

How do I cut and paste on a remote terminal. Willie said he'd tell us in class but he must have forgotten. He said there was a way without using the mouse. That was my problem; trying to highlight stuff with the mouse and cutting the statements and pasting them in another file.

I don't know how to pull it off without a mouse on an Xterm, will check with Willie myself. In a Windows PC Telnet session, you are probably in big trouble without using a mouse to select the text for copying. The standard Windows text selection keystrokes are interpreted differently within the Telnet window

Is there a reason why my mouse would not work on a telnet session from my home computer to use with cutting and pasting?

CAC is probably giving you a poorer default Telnet program than they install in their own labs. Use FTP and select the connection option labeled "CAC More Windows Clients". Download and install either ewan1052.zip or uwterm.zip. I like uwterm better, but ewan is probably easier to install.

How can I get a copy of the program Ghostscript?

Fire up Netscape and do a search on "Ghostview". Look at the hits for the search until one gives you an option to download a file with an installation package for your computer.

### Computational Solution Methods

What is a Taylor Series Expansion?

If you know the value of a function, and the value of all of its derivatives at a point, the Taylor Series gives you a way to obtain values of the function near that point without ever having to know the exact form of the function. To get a thorough answer to this question, you should take a look in a calculus book. If you don't have such a book, go to the math library, find the section of the shelves with calculus textbooks, and browse until you find one that makes sense.

How do you use the convergence criteria inside a loop?

Look at the loops in newton2.f

### Class Procedures

Where will our exams be taken?

Mid-Terms in 64 Willard. Final not yet scheduled, but probably in the regular classroom, 64 Willard.

Will we be reviewing Monday?

Yes.

Is everything we need to know in our notes or should we study other things also?

See the Web notes for Monday's review session

Will I have to write a program on the fill in the blank portion of the test or just a portion of it?

Just a portion.

Is the test going to be hard?

Past student answer to that question would probably be "yes".

What are the averages on your tests usually?

Last year is the only data for this class. Averages were mid to high B.

Can we get the answers to the practice exams?

The answers are there but may be hard to see. In True-False look for question numbers that are slightly lighter that the rest of the text to see True statements. For multiple choice look for one letter that is slightly lighter. For fill-in-the-blank, look at the text with a straight horizontal line through it for one possible answer.

Will the DO loop structure be tested heavily on our first exam?

Maximum of 8 out of 100 points on exam.

How much of the exam is dedicated to Subroutines and Functions?

Add up intrinsic functions, knowledge of calling sequences and argument lists, behavior of variable names and labels across program units, and the actual Fortran statements associated with calling (or referencing) subprograms, marking there beginning and ends, and dealing with data types in each. There is enough there to get you in serious trouble if you don't know what is going on.