Week 4 Questions


I'm still unclear about the different ways you can set initial values to an array.

For now just worry about the data statement. Think about the way you list the array elements to receive values, and the actual values to be assigned separately. For an array "a" with a dimension of four. You can establish the same initial values with any of the following:

data a/2.,3.,4.,5./ data a(1),a(2),a(3),a(4) / 2.,3.,4.,5./ data (a(j),j=1,4)/2.,3.,4.,5./ The last two can be applied to initialize just part of the array:

data a(2),a(3) / 3.,4./ data (a(j),j=2,3)/3.,4./ The implied DO loop functions the same as it does in WRITE and READ statements. You'll get more practice on implied DOs as the semester rolls on.

Now on to the values. You only have two options here. Either list every value separating each by commas, or when you would have repeated the same number in the full value list, you can take a shortcut with the repeat operator. The following are the same.

data a/3.,3.,3.,5./

data a/3*3.,5./

What are mask statements and what are they used for?

First "mask" is not a formal Fortran statement. In our applications "mask" is an optional argument to a set of intrinsic functions. Think of it as a way of activating IF tests within the function. For example a simple minded Fortran representation for what goes on in a reference to "minval(a(1:n))" is

aminval=1.e38 do i =1,n aminval=min(aminval,a(i)) enddo minval=aminval If instead I include the "mask" argument, for example as "minval(a(1:n),mask=a.gt.0)", then the action in minval could be represented as:

aminval=1.e38 do i =1,n if(a(i).gt.0) aminval=min(aminval,a(i)) enddo minval=aminval

What is the need for functions, when subroutines can do everything?

Convenience in arithmetic expressions. " y = 2*sin(x)+x**2" is easier and closer to our experience in mathematics than

call sin (x,sinval) y=2*sinval+x**2 What does the colon mean when you define an array (e.g. A(:))?

It says that I don't know the actual range of "A". If I knew that the first element in "A" is numbered "1" and the last is numbered "10",then I might write "real A(1:10)", but I don't know the size yet, so I throw out the 1 and the 10, leaving "real A(:)".

What is KIND? What exactly does it do?

A given computer may have several kinds of INTEGER representation (and possibly corresponding arithmetic units). It could store some integers in a single byte, some in 2 bytes, and others in 4 bytes. That machine has 3 KINDs of INTEGER variables. You force the selection of the KIND appropriate to your needs with a statement like:

integer (kind=2) i,j,k or as an abbreviation

integer (2) i,j,k Most machines (but not all) do not use sequential numbers (1,2,3) to label their kinds of integers (or reals), they tend to use numbers for kinds that match the number of bytes used in storing the variable.

How are we supposed to know how much memory we need to allocate?

That information can only come from the input of data to the problem. Your problem as a programmer is to figure the best way to either force the user to directly give you the space requirements, or to deduce the space requirements by counting how much data is provided to the program. Look at the array3a.f and array3b.f examples.

How do you enter length for memory allocation?

It is a second level effect. You specify the length between the parentheses of the array given to allocate. You never have a statement "allocate (a,b,c)". It contains no size information. You must have something like "allocate (a(n),b(1:n),c(m:n))", where m and n are variables that have already been assigned values appropriate to the bounds of the arrays.

How do you know if you are on a machine with 90 or 77?

Simplest answer is to give the compiler a small program containing a Fortran 90 statement. Other options include asking the system manager, typing the compiler name with no arguments ("f77"), or consulting "man". Always remember that the problems only work one direction. If you write a program, using only commands contained in Fortran 77, it will always compile and execute with a Fortran 90 compiler. I have tried to clearly state which statements and structures are unique to Fortran 90. The rest are Fortran 77.

Am I correct that our compiler won't recognize the Fortran 90 commands.

You missed a statement that I made early in class. The compiler name "f77" has been maintained by most vendors to help hard core programmers with preprogrammed fingers. To my knowledge, all CAC and ECSEL supported IBM RS6000 workstations (or Power PC's) are running a Fortran 90 compiler. Yes you may be force to program on some computers in the next few years having a basic Fortran 77 compiler. However, I am giving all the Fortran 77, that you need to do any job. If you see any lack of clarity in my Web notes about what is new Fortran 90, please let me know so that I can clean it up.

Could you go over exactly what DMIN means?

Actually you are dealing with DMIN1 and DMIN0 functions that are analogs to AMIN1 and AMIN0 functions. The "D" says that you are returning a DOUBLE PRECISION value, and for real arguments (DMIN1), they are DOUBLE PRECISION. The best bet continues to be the generic MIN function, which will sort out the needed types.

Why does a program with an OPEN statement but no CLOSE statement still compile?

Two reasons. First a CLOSE is not mandatory. The STOP statement quietly looks around for all open units and closes them properly. Secondly, OPEN is a peculiar statement that has effects beyond subprogram boundaries. I can OPEN unit 11 connecting it to a file with the name "input.data" in any subroutine I want. Any other subroutine (function, or portion of the main program) executed after that OPEN will know to direct the results of any WRITE(11,... statements, to the file "input.data".

I'm sort of confused about how you use a specific value out of an array. What do you call up?

The source of your confusion is probably the similarity in syntax between a function reference and an array reference. To use a value in an array, you just include the postition index of that value. If I want to multiply the 3rd element of array "A" by the 4th element of array "B", and put the result in the 2nd element of array "C", I write:

C(2)=A(3)*B(4) The number between the parentheses is just a position indicator. What's more it doesn't have to be a number as above, it can be an INTEGER variable containing a value. For example I would get the same result as above with:

k=2 j=3 i=4 C(k)=A(j)*B(i)

General Computing

What step do we go through to FTP the better version of Telnet so we can cut and paste with the mouse on a remote terminal session?

If you have the standard CACTWIN package, fire-up FTP and select the item labeled "CAC More Windows Clients", view the file named "ewan.txt", then select and move the file "ewan1052.zip". If you are on a different FTP package, open the machine "ftp.cac.psu.edu", login with the ID "anonymous" and give your E-mail address as a password. Type "cd /pub/access/unsupported/windows", then if no fancy interface exists, type

get ewan.txt bin get ewan1052.zip How much will we need to know about "pipelining" for the next exam?

Recognize, a one or two sentence definition when you see one. Recognize a DO loop that feeds a pipeline (each pass through the loop is independent of results from any other pass), and one that doesn't (dependency on a previous pass through the loop).

Class Procedures

Are we going to be working in groups for the rest of the semester?


Is it really necessary to work in groups?

Yes, and no. I will not accept individual results for a group assignment. At some point everyone in the group will have to agree on one program to submit, based on comparison of results, and which one best responds to specific design requests in the homework statement. It is permissible for each group member to work on an early version of the program. This works as long as individual programs are generated within a few days after the assignment is made, and anyone hitting a brick wall pauses to discuss it with other group members, rather than spending many hours tracing a minor oversight.

From my seat, on the right above the board there is a red light which flashes all the time. Is it a motion detector or what?

Yes it is. Try getting to the classroom really early some day, and walk in while it is dark. The lights come on automatically.

Will our grades be posted on the Web at all?

No, but I will try to put them on a restricted News group.

Do we change as we get older and work together, or do we always try to go around group work? Maybe we just don't want to work at all.

We don't change as much as some people think, we just develop behavior patterns that let us slide by, including working better with others (or avoiding them completely). You hit the nail on the head with the last statement. My observation is that most of us are driven by a pair of conflicting hardwired desires: 1) the need for accomplishment (creation, discovery); and 2) the desire to avoid as much work as possible. Depending on the relative levels of your interpersonal and technical skills, this can drive you to work in groups or work alone. There is another hardwired driver that eventually comes into play here. The desire not to starve (self preservation). Given the work requirements for earning a living in science and engineering, learning to work with others will probably be a big plus on this one.

When is our group homework due? Are we usually going to have a few weeks to do it?

Due dates will always be posted on the Web. Usually you will have 2 weeks to complete the homework. Also, usually it will not be the kind of problem that you can get running in one night.