Anda di halaman 1dari 6

FORTRAN 95

Introduction Fortran programs can be developed, edited, compiled and run from a simple development environment called Plato which is a source code editor that integrates with several compilers and other development tools to provide a single application development environment. Plato is an example of an Integrated Development Environment (IDE). Within Plato you can: Write and compile your program Pinpoint compile-time errors Link/build your program Run your program Debug your program Manage a program as a project consisting of one or many source files and libraries. Starting Plato To start Plato, choose Development Environment from the Programming/F95 option of the Public menu on the Windows taskbar:

The Plato window appears like this:

The File menu allows you to create files, open existing files, save, close and print files. It also has a listing of recently edited files.

Fortran 95

The Edit menu has all the normal editor functions for writing and editing your programs The Project menu contains options for compiling, linking and running programs and building projects. The Options menu allows you to customise certain features of Plato's appearance and operation. The Window menu controls the appearance and position of multiple windows. The Help menu offers on-line assistance in using Plato. Many of the menu options have keyboard shortcuts displayed alongside the option itself. The Toolbar Many of the actions available in the menus can also be activated by clicking on the appropriate button in the Toolbar. Positioning the mouse cursor over a button will display the action of the button. This group of buttons will open, save and print program files. These are editing buttons to cut, copy and paste text. The two buttons on the right allow you to undo the last action and to search for text. Use these buttons to compile, link and build files and projects. This button will start the Debugger to help you with errors in your program. These buttons display the Error window and Project window. The toolbar also has a pulldown list box containing the files that are at present open or part of an open project. You can switch between windows by selecting a filename from this list box. Below the Toolbar is a blank area, the editor, in which you can type the code of your program and at the bottom of the Plato window is an information bar where progress messages and line an character numbers will be displayed. Writing A Program To create a Fortran source file, choose New from the File menu, or use the appropriate button on the toolbar. Make sure the cursor is positioned at the top left of the editor window and type in the code, for example: PROGRAM FIRST PRINT*,'My first program STOP END

Fortran 95

The Plato window will now look like this:

Saving The Source File

Before compiling the program, it must be saved to a file. To do this: Choose Save As from the File menu. Select a directory to save it in. Enter the name first.f95 Make sure you give the file an appropriate extension for the compiler you want to use. By default Plato uses the following conventions: .for .f .f77 .f90 .f95 Salford FTN77 Salford FTN95

It is a good idea to make the filename the same as that of the program. Compiling, Building And Running Having written a program, the next step is to compile and link (or build) it. Compiling is a process by which a human readable program is translated into a form, which the computer can understand. The translated program is automatically saved as a binary or object file. To compile the program choose Compile File from the Tools menu or click on the Compile File button in the toolbar. An information window will display the progress of the compilation and if successful, with no errors will show the following:

Fortran 95

The building procedure is required to build an executable file from one or more object files and built-in libraries of subroutines and functions. To build the program, choose Build File from the Project menu or click on the Build File button in the toolbar. If the program has been compiled and built successfully, it is ready to run. To run the program, choose Run from the Project menu or click on the Execute button in the toolbar. The output will appear in a new DOS window. One Step Execution By default, Plato is set up so that the compile, build and run stages can be done automatically by just choosing Run from the Project menu or clicking on the Execute button. Plato will compile and link only when necessary, that is when your source has changed since the last build, saving you time. Any errors in syntax of your code will prevent compilation. If the compiler detects errors it will display a message in an information window. Click on the Details button in the this window to see a list of each error or warning, one per line showing the name of the source file, the appropriate line number and the error/warning message. When the error is selected in the Error & Warning window the appropriate line will be highlighted in the Edit Window, making it easy to pinpoint exactly where the error occurred. Run-time Errors It is possible that, for some reason, your program fails and that you obtain an error message. This is referred to as a 'run- time error' and usually involves errors in the logic or organisation of your program. For example, you may have attempted to divide by zero or assigned a value to an incompatible variable type. If you are lucky, an error message will indicate what is wrong and you will then be able to correct the program using the editor, save it, re-compile and run it again. Editing More Than One File You can work on more than one program by opening further edit windows. Each time you select New from the File menu a new edit window is created. You can see a list of open files using the drop down menu to the right in the toolbar. Although you may start writing a new program in a new window, the number of windows open will quickly increase if you do so. To avoid this, when you have finished work on a program, and have saved it to disc, you can close a window by choosing Close from the File menu. If your program or application consists of more than one file you will need to create a project to manage it. Projects A Plato project is a file with the extension .prj that contains information about the application you are creating. The information includes: A list of source files A list of object and library files to be linked to the compiled source (this is known as building) Compilation options Other optional settings

Compiler Errors

Fortran 95

Projects provide a convenient way to build an application and all its components. Creating A New Project To create a new project and add your source files to it, follow these steps: Choose New from the Project menu to open an empty Project Window. Give the project a suitable name. Click on the COMPILE section of the Project Files tree and use the Add button to navigate your folders and select the source file(s) that are part of this application. You can select more than one file at a time. Now click on the LINK section of the Project Files tree and use the Add button to navigate your folders and select the objects and libraries that are part of this application. Again, you can select more than one file at a time. Note that you do not need to add entries for objects that are built from source that is listed in the COMPILE section as Plato will make sure that those files are linked. The source file(s) you have selected will now be displayed in the Project Files tree under the heading COMPILE and any object or libraries to be linked will be displayed under the heading LINK:

To specify compiler options for a particular file, select the file then click the Options button. Double click on a file in the Application tree to open it for editing. You can return to the project window from the Project Menu. To save the project at any time use the Save Project button. Compiling And Building A Project Compiling a project is similar to compiling single files, you can use the toolbar to Compile, Build and Rebuild your projects. When a project is built, all the files in the application tree are processed and any files that do not have an up to date object file are compiled. To start the Windows Debugger to debug your application, click the Debugger toolbar button. If necessary Plato will automatically compile and link your application with the /DEBUG option enabled.

Using The Debugger

Fortran 95

A dialogue will appear offering a command line to use with the debugger. The command line must start with sdbg (or wsdbg) and be followed by the path and filename of your application. Optionally this can be followed by /P and then any arguments required by your application. Using Checkmate Checkmate allows you to check the correctness of code dynamically at run-time. By applying Checkmate to your code you can trap most programming errors automatically. To enable Checkmate with a single file: Select File Options from the File menu. Select the option Checkmate enabled Rebuild your application To enable Checkmate for a whole project: Open the Project Window and select the Options tab In the 'Global Compiler Options' box type the option /UNDEF Rebuild your application Writing C Programs Leaving Plato Appendix You can also write, compile, link and run C and C++ programs in Plato. Save your source file with a .c or .cpp extension. To leave Plato, select Quit from the File menu. Keyboard Shortcuts Standard Windows Ctrl+N Ctrl+O Ctrl+S Ctrl+P Ctrl+Z Ctrl+X Shift+Del Ctrl+C Ctrl+Ins Ctrl+V Shift+Ins Ctrl+A Ctrl+F Ctrl+H Ctrl+G F1 Shift+F1 Compiling F2 Creates a new edit window Opens a file Saves the current file Prints a file Undo Cut Cut Copy Copy Paste Paste Select All Find Find and Replace Go To Line Help Topics Keyword Help Save

Fortran 95