Programming Preliminaries

An animated demonstration illustrating the use of an Editor to create a program, and subsequently how to compile and execute the program is available on the Macintosh computers To invoke the demonstration,

You can use either the Macintosh or the Indigo workstations for entering and testing your program. An Indigo workstation must be used for viewing the graphics generated for Project A, whilst a Macintosh must be used for viewing the spectral output from project B.

Programming Procedure on an Indigo workstation.

Log in as described. You will need to use the Edit-a-file application (actually an editor known as asedit) as invoked from the Tools menu item on the screen, to create and to modify your program, and the Console window for compiling and running your program. When you are ready to visualise some data, Explorer should be invoked from the Applications menu item.

Programming Procedure on a Macintosh computer.

Check that not too many other programs are running before starting, otherwise you may have insufficient memory available for the editing session. You can ascertain this by viewing "About this Macintosh" from the Apple menu. Select either the Xargon_server or the Xneon_server items from the Workstations Apple menu item;
Prompts to enter your user id and password will appear twice, once for a window containing the program editor, and once for the console window.
If you subsequently chose to do project A, remember it is NOT possible to run the Explorer window on the Mac. However, any program written and compiled via the Mac using the above procedure will be automatically available to any Indigo workstation.

Differences in Macintosh and Indigo keyboards

On the Indigo, the backspace key will remove a character immediately to the left of the cursor whilst the delete key will delete to the right of the cursor. The four arrow keys will move the cursor in the appropriate direction.

On the Macintosh, only the delete key is available, but confusingly it occupies the same keyboard position as the backspace key on the Indigo! To obtain a backspace effect on the Mac, press the Ctrl and H keys simultaneously.

On Either Machine.

Once in the editor window, a file called called "untitled.f" will be created by the asedit program.

If you want to edit instead an existing file, select open from the file menu of the editor;
An alternative way to edit an existing file (all Fortran files must end in .f) is to type
asedit yourfilename.f in the console window.

At this stage, text can now be typed in from the keyboard. The display at the bottom of the editor indicates both the line and column position of the cursor . Fortran programming statements must appear in column 7 onwards, and must not be wider than column 120. Depending on the workstation screen you are using, you may only be able to see about 50 columns and about 16 lines at a time. To inspect the rest of the file, you will have to use either the vertical or horizontal "scroll bars" as indicated below. The editor window can also be resized by placing the mouse cursor on an edge or on the bottom right hand corner and "dragging" the window to a new size.

The next advisable action is to save your program with a more descriptive file name;

Note particularly to select the entire default entry (untitled.f) and replace it with your own name in the dialog box where the file name is entered. At this point a backup file will also be created called yourfilename.bakup. If you suffer a major disaster during editing, you can always revert to this backup file.

To move or delete a portion of text, select it first with the mouse (using the left mouse button on the Indigo) and then use the Edit menu to manipulate the text;

Cutting text copies it to a "clipboard" ready for pasting elsewhere, whilst clearing selected text removes it entirely. Note that if you make a mistake, the last command can be "undone". Particular occurances of strings in the text can be "searched" for as follows;

At regular intervals, you should save your file to hard disk. Only after this has been done can another program (e.g. the Fortran compiler) access the changes you may have made to it. Likewise, any changes in a listing or data file produced during compilation will not automatically appear in an editor window unless the file is opened again in the editor. You can have several files open in the editor simultaneously, but you need to "open" each. For example, you may have the prog.f file in one window, and the prog.lis file in another. Remember to re-open the file every time it changes (it is not updated automatically). For further help, invoke that menu item as shown above.

On a Macintosh only, you can switch between the editing and console windows by selecting the Window item at the top of the screen.

Printing Program Listings.

On a Macintosh, the contents of a window can be copied to the "clipboard", and from there printed on one of the Deskwriters in Rooms 134 or 170;
On an Indigo, select Print from the File menu of the Editor and select the "lpr" printer.

The complete listing will be printed on a line printer in the Centre for Computing services (level 4, Mech Eng), from whence you will have to collect it. It is a good idea to put your name and department as a comment line in your program, in case the listing gets lost!

Compiling and Executing

Once you have created and saved a file using the editor, you should click on the console window and type e.g. commands of the following type;
ugfor horbs
ugfor ftnmr

Note that everything should be typed in lower case! This will assume that you have previously saved your program with a .f qualifier, as e.g. a file called horbs.f. A file called horbs.lis and an executable called horbs.uxe will be produced if there are no errors, and your program will automatically run and produce a file containing appropriate values. If compiler errors do occur, you should inspect the horbs.lis file using the editor, and using this, correct the errors in the original horbs.f file, moving between the two editor windows to do so. It is most important to note that before you can re-compile this program, you must save the file again to disk in the editor, since the editor and compiler communicate only via the disk. If you have previously compiled your program and successfully produced an executable file, running ugfor again will produce a prompt asking whether you want to run it again, or whether you wish to re-compile your program to incorporate any modifications etc.

Optional Macintosh Alternative to using asedit

Not for beginners! You may prefer to create and edit your files on the Macintosh directly, rather than using the asedit editor. The best way of doing this is as follows.

From the Apple menu, select the following sequence; Chooser, Appleshare, ch.ethertalk2, AUFS Server Neon, and finally the OK button. . Select the standard login method, then type your Indigo account name and its password; You will have the option of mounting an item corresponding to your unix log-in account (shown as rzepa here). Click on OK, whereupon an icon with your id as its name will appear on the Mac desktop. Next, you might wish to make an alias of the icon with your id as follows. Select the ionc first using a single click, then;

This alias file can then be copied to your own floppy disk, which is taken away when you finish your session. Next time you want to mount your Indigo filebase for use on the Macintosh, insert this floppy disk and double click the alias file. After prompting for your password, the icon with your id should remount ready for use again.

If you double click on this icon to open the folder, the contents of your Indigo directory will be listed.

You can treat this directory as any other Macintosh folder, copying files into or out of this area.

Double click on an existing yourprog.f type file in this area (if your want instead to create a new file, proceed as indicated here on any file in your space, but then following the following instructions.) A dialog box will appear showing all the available programs that are capable of reading this file; . Select BBedit; The editor is quite similar in operation to most word processors, and you should soon get the hang of it. To save the file, select first the file type; and then the save item; . Selecting the file type is quite important, because Macintosh and Unix files have a different "invisible" end-of-line character, which are mutually incompatible.

The above sequence only enables you to edit your files locally. It does NOT enable you to compile and execute your program (for the simple reason that the Macintosh does not have a licensed Fortran compiler to do the job). To compile and run your program, you will still need to log into the Indigo systems as described above.

If you want to save your work with a different name to the one your started with, you will need to select Save As instead; . If you wanted to create a new file instead, select first Close and then New from the File menu item. When saving this new file, you will have to select the Unix File type and Save As, as before.

When you finish working in this manner, be sure to drag-n-drop the icon in the wastebasket, otherwise someone else could come along and delete your files (performing this action only dismounts the server, it does NOT delete your files!).

Finding and Fixing Run-time Errors.

There is a special "debugging" environment available only on the Indigo workstations called CaseVision/Workshop. Currently, we are restricted to two concurrent uses of this program, so it is not possible for everyone to use it simultaneously. For this reason, you should reserve its use for particularly difficult problems which are resisting solution by other means. CaseVision is normally only invoked when your code has compiled sucessfully but is not yielding the correct numerical answers. It should NOT be used to fix compiler errors. To invoke the environment, type the following from a console or shell window;

$cvd yourprogname.uxe

A number of overlapping windows appear. To fully view (and focus the keyboard onto) any individual window, you will have to click the lhs mouse button in its area. The main window contains a listing of your program, which by default it is read only, but you can make it editable (from the source menu item). You can set "traps" for your program by clicking in the left hand colum against a line of code. In the example below, a trap is set on line 33 of the code. When the code is RUN (from the menu) it will stop at that point, whereupon the contents of the other windows will fill with the values of any variables. An array window (partially obscured below) can be used to enter an array name (XARRAY in the case below) and will display the value of the array. The execution view (partially obscured below) is where you type data for your program and any output from the program is produced.

The expression window can be used to evaluate an entire expression to check its numerical correctness. To do this, the expression needs to be entered into the appropriate cell of the window. Whilst you can do this by typing, a less error prone method is to proceed as follows. In the main window, move the mouse cursor to the start of the expression you are interested in, and press the lhs mouse button. Keeping it pressed, move it over to the end of the expression. The "highlited" text will change colour. Now click on the first free Expression cell of the Expression window and press the middle mouse button. The expression should be "pasted" in. Actually, this combined operation works anywhere in the workstation environment, not just here! Finally, a build view enables you to recompile your program within the environment. It is invoked when you select recompile from the source menu item of the main window.

To inspect any data files produced by your program, you can either open them in the editor, or issue the command from the console window;

page horbit.dat

To end paging, type q. Once your calculated data looks reasonable, run the Explorer or Cricketgraph programs.

Project Requirements.

This would normally involve writing about 100 to 150 lines of Fortran code. The deadline for submission of completed projects will be announced during the lectures, but will not be before mid-February. Your final report should include a program listing and hard copy of any graphical output. If you have other suggestions for a programming project, check with Dr Rzepa before starting.
Copyright (c) B. P. Levitt, H. S. Rzepa and ICSTM Chemistry Department, 1994.
Return to Index page