| Getting Started with WATFOR77 | IBM/DOS Version | Mark H. Solsman | Center for Academic Computing, Documentation Training and Publications | mhs108@psu.edu 11/2/93 I THE PENNSYLVANIA STATE UNIVERSITY Center for Academic Computing GETTING STARTED WITH WATFOR77 on the IBM PC Writeup Revised: December, 1988 * Copyrighted by Chester M. Smith, Jr. GETTING STARTED WITH WATFOR77 ON THE IBM PC In all the screen examples here, what you type is shown in UPPER CASE, but you can enter lower case letters instead (except for the FORTRAN statements in the program). Start the system with the WATFOR77 command at the DOS prompt: +---------------------------------------------------------------------------+ | B>WATFOR77 | +---------------------------------------------------------------------------+ The initial screen will show an empty workspace, like this: +---------------------------------------------------------------------------+ | | | | | WATFOR-77 V3.0 Copyright WATCOM Systems Inc. 1984,1988 | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ The "input" command allows you to enter statements: +---------------------------------------------------------------------------+ | | | | | WATFOR-77 V3.0 Copyright WATCOM Systems Inc. 1984,1988 | | INPUT | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ ENTERING AND SAVING A FILE Now type in the statements shown below. After you've typed the "END" line, press the key to go back to the command line and enter "put test". This command causes the lines in the workspace to be copied to the file TEST.FOR on the default disk (the one corresponding to the prompt characters A>, B> or C>). Note that the system will add the name extension ".FOR" automatically if you don't specify otherwise; "FOR" stands for "Fortran", and implies that the records are Fortran statements with sequence numbers in columns 73-80. +---------------------------------------------------------------------------+ | | | PRINT*,'ENTER VALUE FOR A' | | READ*,A | | X=SQRT(-A)+-A | | PRINT*,X | | STOP | | END | | | | (7,1,50004) WATFOR-77 V3.0 PC/DOS | | PUT TEST | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ NAMING A WORKSPACE Although we've given the SAVED FILE a name (TEST.FOR), we must also give the WORKSPACE a name (the same one) when it contains a program to be run. You do this with the NAME command: +---------------------------------------------------------------------------+ | | | PRINT*,'ENTER A VALUE FOR A' | | READ*,A | | X=SQRT(-A)+-A | | PRINT*,X | | STOP | | END | | | | (7,1,50004) WATFOR-77 V3.0 PC/DOS | | NAME TEST | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ RUNNING A PROGRAM, FIXING A SYNTAX ERROR The "RUN" command is used to compile and run the program in your workspace (note that the NAME you gave it now shows on the screen): +---------------------------------------------------------------------------+ | | | PRINT*,'ENTER A VALUE FOR A' | | READ*,A | | X=SQRT(-A)+-A | | PRINT*,X | | STOP | | END | | | | TEST.for | | RUN | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ The error message says there is a error: +---------------------------------------------------------------------------+ | ***ERR*** SX-02 line 3, column 19, bad sequence of operators | | | +---------------------------------------------------------------------------+ Press the key to go back to the editor. Press , or use the cursor keys, to move up and remove the "+-A" from the third line. You can remove the characters by blanking them with the space bar, or by deleting them with the key. When you are done, return to the command line with the key. Now run it again: +---------------------------------------------------------------------------+ | | | PRINT*,'ENTER A VALUE FOR A' | | READ*,A | | X=SQRT(-A) | | PRINT*,X | | STOP | | END | | | | TEST.for (4,1,49999) WATFOR-77 V3.0 PC/DOS | | RUN | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ Enter the value "4.0" as the number to be used for A. +---------------------------------------------------------------------------+ | 4.0 | +---------------------------------------------------------------------------+ An execution time error results: +---------------------------------------------------------------------------+ | 4.0 | | ***ERR*** LI-03 argument must not be negative | | TraceBack: Executing in MAIN PROGRAM, statement 3 in file TEST.for | | | +---------------------------------------------------------------------------+ USING THE DEBUG OPTION Run the program again with the DEBUG option. The DEBUG option allows some better run-time tracing and debugging tools: +---------------------------------------------------------------------------+ | | | PRINT*,'ENTER A VALUE FOR A' | | READ*,A | | X=SQRT(-A) | | PRINT*,X | | STOP | | END | | | | WATFOR-77 V3.0 Copyright WATCOM Systems Inc. 1984,1988 | | RUN /DEBUG | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ Since this is the first use of DEBUG, the HELP command is useful to see the options it can provide. The TRACE option will give a statement-by-statement symbolic display of statements executed, the GO option will start it, and the QUIT option will get back to the to the editor. +---------------------------------------------------------------------------+ | Debugger entered at MAIN PROGRAM | | 1: PRINT*,ENTER A VALUE FOR A | | DEBUG>HELP | | Display {* | {:}} | | Go {} | | Help | | LOGio { {ON | OFF}} | | Quit | | SET | | STAtus | | STEp {OVER | INTO} | | STOp OFF | Calls | {:} | | SYStem {} | | Trace {OFF | Calls | {:}} | | Unit {} | | Where | | ? {(z|a)} {{,}...} | | | | DEBUG> | +---------------------------------------------------------------------------+ The "GO" and "-4.0" start the program and provide the value to be used for A. +---------------------------------------------------------------------------+ | GO | | -4.0 | +---------------------------------------------------------------------------+ The value for X is displayed: +---------------------------------------------------------------------------+ | GO | | -4.0 | | 2.0000000 | | | +---------------------------------------------------------------------------+ Try it one more time! +---------------------------------------------------------------------------+ | | | PRINT*,'ENTER A VALUE FOR A' | | READ*,A | | X=SQRT(-A) | | PRINT*,X | | STOP | | END | | | | WATFOR-77 V3.0 Copyright WATCOM Systems Inc. 1984,1988 | | RUN /DEBUG | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ USING THE TRACE OPTION IN DEBUG This time, use the TRACE option to see the statements being executed. +---------------------------------------------------------------------------+ | Debugger entered at MAIN PROGRAM | | 1: PRINT*,ENTER A VALUE FOR A | | debug>TRACE | +---------------------------------------------------------------------------+ Use "GO" and the value 4.0 for A this time. +---------------------------------------------------------------------------+ | Debugger entered at MAIN PROGRAM | | 1: PRINT*,ENTER A VALUE FOR A | | DEBUG>TRACE | | DEBUG>GO | | ENTER A VALUE FOR A | | 2: READ*,A | | 4.0 | +---------------------------------------------------------------------------+ Since there's an error, and it's in the value of A, use the SET command to change the value of A to -4.0. +---------------------------------------------------------------------------+ | Debugger entered at MAIN PROGRAM | | 1: PRINT*,ENTER A VALUE FOR A | | DEBUG>TRACE | | DEBUG>GO | | ENTER A VALUE FOR A | | 2: READ*,A | | 4.0 | | 3: X=SQRT(-A) | | *ERR* LI-03 argument must not be negative | | TraceBack: Executing in MAIN PROGRAM, statement 3 in file TEST.for | | 3: X=SQRT(-A) | | debug>SET A -4.0 | +---------------------------------------------------------------------------+ Now the "GO 3" command will continue the execution of the program with the third statement. Note that the program itself has not been changed in any way; if some change were required, you would use the editor to make it and to re-run the program. +---------------------------------------------------------------------------+ | Debugger entered at MAIN PROGRAM | | 1: PRINT*,ENTER A VALUE FOR A | | DEBUG>TRACE | | DEBUG>GO | | ENTER A VALUE FOR A | | 2: READ*,A | | 4.0 | | 3: X=SQRT(-A) | | *ERR* LI-03 argument must not be negative | | TraceBack: Executing in MAIN PROGRAM, statement 3 in file TEST.for | | 3: X=SQRT(-A) | | DEBUG>SET A -4.0 | | DEBUG>GO 3 | | 3: X=SQRT(-A) | | 4: PRINT*,X | | 2.0000000 | | 5: STOP | | | +---------------------------------------------------------------------------+ Be sure to save the program with a PUT command. This time you don't need to type the file name, because you've NAMEd the file already. +---------------------------------------------------------------------------+ | | | PRINT*,'ENTER A VALUE FOR A' | | READ*,A | | X=SQRT(-A) | | PRINT*,X | | STOP | | END | | | | TEST.for (4,1,49999) WATFOR-77 V3.0 PC/DOS | | PUT | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ GETTING A LISTING FILE Run the program again with the NOXTYPE option. This will produce a listing file (automatically named TEST.LST) that will include both a program listing and the execution output. +---------------------------------------------------------------------------+ | | | PRINT*,'ENTER A VALUE FOR A' | | READ*,A | | X=SQRT(-A) | | PRINT*,X | | STOP | | END | | | | TEST.for - Lines transferred = 6 | | RUN /NOXTYPE | | -4.0 | | | +---------------------------------------------------------------------------+ EXITING WATFOR77 Get out of WATFOR77 with the BYE command: +---------------------------------------------------------------------------+ | | | PRINT*,'ENTER A VALUE FOR A' | | READ*,A | | X=SQRT(-A) | | PRINT*,X | | STOP | | END | | | | TEST.for (4,1,49999) WATFOR-77 V3.0 PC/DOS | | BYE | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ PRINTING A LISTING FILE You can use the COPY command to print the listing file TEST.LST on the printer: +---------------------------------------------------------------------------+ | B> | | COPY TEST.LST LPT1: | +---------------------------------------------------------------------------+ Note that the listing file includes the program listing, with internal statement numbers on the left, execution output, and statistics on the compilation and execution of the program: +---------------------------------------------------------------------------+ | WATFOR-77 V3.0 Copyright WATCOM Systems Inc. 1984,1988 88/05/27 11:19:09 | | Options: list,extensions,warnings,terminal,check | | 1 PRINT*,'ENTER A VALUE FOR A' | | 2 READ*,A | | 3 X=SQRT(-A) | | 4 PRINT*,X | | 5 STOP | | 6 END | | ENTER A VALUE FOR A | | 2.0000000 | | Compile time: 00.22 Execution time: 05.99 | | Size of object code: 104 Number of extensions: 0 | | Size of local data area(s); 63 Number of warnings: 0 | | Size of global data area: 0 Number of errors: 0 | | Object/Dynamic bytes free: 246793/45142 Statements Executed: 4 | +---------------------------------------------------------------------------+ READING INPUT FROM A FILE A program can read input from a file, rather than prompt for data from the keyboard. To try this, first create a file with data in it; start by giving the "WATFOR77" command to get a clear workspace, and then the "input" command to enter the lines. Then save the file; you can give it a name like, for example, "TEST.DAT". Our data file here contains three records, each having two values. +---------------------------------------------------------------------------+ | | | 1.0 2.0 | | 3.0 4.0 | | 5.0 6.0 | | | | (7,1,50004) WATFOR-77 V3.0 PC/DOS | | PUT TEST.DAT | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ Now get the program file (use the command "EDIT TEST.FOR"), and replace the first statement by "OPEN(UNIT=5,FILE='TEST.DAT')", which will cause input to be read from the file instead of the keyboard. Also, since we want to read two data values from each of three records, we'll change the program to do that, and just print the values (see the next panel). After the file is revised, save it again with the PUT command, and then RUN the job. Note that you don't have to give the NAME command this time -- the workspace already has the name of the old file you retrieved with the EDIT command. When you give the RUN command, the screen will look like: +---------------------------------------------------------------------------+ | | | OPEN(UNIT=5,FILE='TEST.DAT') | | READ(5,*) A,B | | READ(5,*) C,D | | READ(5,*) E,F | | PRINT*,A,B,C | | PRINT*,D,E,F | | STOP | | END | | | | TEST.for (7,1,50004) WATFOR-77 V3.0 PC/DOS | | RUN | | F1:PgU 2:PgD 3:LU 4:LD 5:LIns 6:LDel 7:Sel/D 8:Cut 9:Sc/Cmd 10:Help | +---------------------------------------------------------------------------+ The results are displayed: +---------------------------------------------------------------------------+ | 1.0000000 2.0000000 3.0000000 | | 4.0000000 5.0000000 6.0000000 | +---------------------------------------------------------------------------+ FOR FURTHER INFORMATION OR ASSISTANCE The Center for Academic Computing (CAC) provides assistance to academic computer users at Penn State. The CAC Help Desk can be reached at (814) 863-2494 or (814) 863-1035. Electronic mail can be sent to HELPDESK@psuvm.psu.edu. COPYRIGHT NOTICE Computer documentation written by staff of the Center for Academic Computing at Penn State University may be used and reproduced freely for non-profit educational purposes. Persons using or adapting CAC documentation should acknowledge the source and inform the CAC by sending a letter or electronic mail to: Documentation, Training, and Publications Center for Academic Computing Penn State University 225 Computer Building University Park, PA 16802 Electronic mail address: DOCREQ@psuvm.psu.edu Phone: (814) 863-6113 FAX: (814) 863-7049