• Aucun résultat trouvé

processing Multidimensional Arrays--Nested DO statement

Dans le document VS FORTRAN (Page 35-40)

You can include DO statements completely within the range of a DO loop--that is, among the statements within the range that the initial DO statement controls. You can use this FORTRAN feature to initialize multidimensional arrays. The DO statements in the following example show how it's done:

Coding Your Program--Simplified Programming 17

DIMENSION ARRAY2 (4,5) VALU = 0.0

DO 40 ISUB2=l,5,l DO 40 ISUBl=1,4,1

ARRAY2(ISUBl,ISUB2)=VALU VALU=VALU + 1.0

40 CONTINUE

The first DO statement varies the second subscript from its minimum to its maximum value. The second DO statement varies the first subscript from its minimum to its maximum value as the first subscript is set to each of its specified values. When you specify these two DO statements in this order. vour croaram clac~s

ascend; ng values in each array elemQnt -i n se-quence ..

For a four-dimensional table, you'd specify

1. A DO statement controlling references to the fourth subscript.

2 .. Contained statement 3. Contained statement 4. Contained statement

in that DO statement's range would be a second DO controlling referen~es to the third subscript.

in that DO statement's range would be a third DO controlling references to the second subscript.

in that DO statement's range would be a last DO controlling references to the first subscript.

Programming rules for the DO statement are given in the VS FORTRAN Application Programming: language Reference manual.

OBTAINING RESULTS-USING THE WRITE STATEMENT

To print or display the results of your program, use the WRITE statement.

For example, your program develops two values, TZ and V, which it then uses to test how the program plots a curve. At the end of execution, you'll want to save these values. The following example shows how you can do this:

WRITE (UNIT=8) TZ,V

The meaning of each part of this WRITE statement is:

WRITE tells FORTRAN that your program is to output some information, in this case on an external device.

(UNIT:S) specifies that the information produced by the write statement will be sent to the output device identified by this unit number. (The unit number 8 is only an example; check with your system administrator for valid unit numbers you can use with the WRITE statement.)

TZ and V are the data items to be written to the output device.

The WRITE statement sends the data contained in each item listed, and in the order the items are specified.

Reference documentation for the WRITE statement is given in the VS FORTRAN. Application Programming: Language Reference manual.

I

18 VS FORTRAN Application Programming: Guide

0)

to

(0

ENDING YOUR PROGRAM--END STATEMENT

Once your program has completed all the processing you want done, you must tell the VS FORTRAN compiler that there are no further statements to process.

You do this through the END statement, which is an executable statement and which must be the last statement on the last line in your program. For example:

27 END

The statement number (27) on this statement allows you to transfer control to this END statement from various parts of the program.

When the END statement is executed, program execution ;s ended, and control is returned to the system.

Programming rules for the END statement are given in the VS FORTRAN Application Programming: Language Reference manual.

CODING ERRORS TO AVOID

While you're coding your program, be careful not to make these common programming errors:

1. Misspelling FORTRAN words and data names.

2. Omitting required punctuation.

3. Not observing FORTRAN formatting rules.

4. Forgetti ng to ass; gn values to vari abIes and arrays before you use them.

5. Moving data into an item that's too small for it. (This causes truncation.)

6. Branching into DO loops from other areas in the program.

Errors like these can either prevent your program from executing at all or may cause your program to produce ~rroneous output. For many of these errors, you'll get compilation messages explaining what's wrong; for others, you may not get any error messages, because the error won't become evident until you actually execute the program.

You can quite often detect misspellings and uninitialized items by examining the source program map and the cross-reference listing.

Once your program is coded, you use the VS FORTRAN compiler to compile it, that is, to translate it into machine code. This is explained in "Compiling Your Program-Simplified Programming."

Coding Your Program--Simplified Programming 19

COMPILING YOUR PROGRAM--SIMPLIFIED PROGRAMMING

Your VS FORTRAN source program 1s meaningful to you, but it means nothing to the computer, which understands only a language known as machi ne code.

For this reason, you must compile your program. That is, you must request the VS FORTRAN compiler program 'to translate your FORTRAN source statements into an "object module"-a machi ne code

translation of your source program.

ENTERING YOUR SOURCE PROGRAM

Your fir5t step is to enter your source program into the 5Y5t~ffi.

You can, for example, enter the program from a terminal as a CMS or T50 file, or you can key it onto a diskette, or into a punched card decl(.

For the method your organization uses, see your system administrator.

Whatever method your organization uses, you must submit the source program as a file with 80-character records; each record must follow VS FORTRAN formatting rules.

REqUESTING COMPILATION

Once you've entered your source program into the system, you can ask the VS FORTRAN compiler to process it. When you request compilation, the V5 FORTRAN compiler reads and analyzes your source program and translates it into machine code.

You can request compilation along with the other steps needed for program development--link-editing and execution.

For early debugging, however, it's usually better to request a compile-only run. That way, the compiler can find syntax errors in your program that would prevent a successful execution, and you don't waste machine time and computer printout paper.

See "Using VM/370-CMS with VS FORTRAN" for information on compiling programs under CMS.

S~e "Using OS/VS2-TSO with VS FORTRAN" for information on compiling programs under TSO.

REQUESTING COMPILATION ONLY-OS/VS

The easiest way to request compilation under OS/VS is to use the VS FORTRAN cataloged procedure for compilation only.

Use the following job control statements to execute the compile-only procedure:

//jobname JOB

// EXEC FORTVC

//FORT.SYSIN DD

*

(source program)

/*

/ /

where:

jobname

is the name you're giving this compilation-only job.

20 VS FORTRAN Application Programming: Guide

f ' \ )

\ '

~

o

o

o

See the VS FORTRAN Application Programming: System Services Reference Supplement for more information on these job control statements.

REQUESTING COMPILATION ONLY--DOS/VSE

COMPILER OUTPUT

The easiest way to request compilation under DOS/VSE is to use the following job control statements:

I I 1/

1* 1&

JOB jobname EXEC VFORTRAN (source program)

where the source program is on SYSIPT, and:

jobname

is the name you're gi Vi"9 to thi s compi lat ion-only job.

See the VS FORTRAN Application Programming: System Services Reference Supplement for more information on the DOS/VSE JOB statement.

The VS FORTRAN compiler gives you some or all of the following output, depending on the options in effect for your organization:

• The Source Program Listing-as you entered it, but with compiler-generated internal sequence numbers prefixed at the left; the sequence numbers identify the line-numbers referred to in compiler messages.

An object module--a translation of your program in machine code.

• Messages about the results of the compilation.

• Other listings helpful in debugging.

These listings are described fully in "Fixing Compile-Ti~e

Errors-Advanced Programming" and "Fixing Execution-Time

Errors-Advanced Programmi ng" in Part 2; examples of output for each feature are also given there.

If your compilation was completed without error messages, you can proceed to "L i nk-Edi t i ng Your Program--Si mpl i fi ed Programmi ng."

If your compilation caused error messages, you may have to fix up your errors, as described in "Fixing Compile-time

Errors-Simplified Programming."

Compiling Your Program--Simplified Programming 21

Dans le document VS FORTRAN (Page 35-40)