Sie sind auf Seite 1von 3

Using Compaq Visual Fortran

The Compaq Visual Fortran development environment has many similarities to the Microsoft Visual C++ development environment. The three main areas used when writing a program are the workspace, the project and the source file. A workspace is simply a container to easily organize projects. A project is a container to hold any number of source files. Typically, all the source files in a project are interrelated, often to produce a single executable program file. The hierarchy of areas, listed from highest to lowest, is the workspace, then the project and finally the source file. You can build many different kinds of projects with Visual Fortran. For our purposes only one, the console application, is of interest. A Fortran console application (.exe) is a character-based program that does not require screen graphics output. It looks similar to a program running on a UNIX workstation or a terminal connected to a mainframe computer. Fortran console projects operate in a single window, and let you interact with your program through normal read and write commands. Console applications are better suited to problems that require pure numerical processing rather than graphical output or a graphical user interface. This type of application is also more portable to other platforms than other types of application. Creating a Workspace 1. Once the Visual Fortran program has been started, choose the New option from the File dropdown menu at the top of the screen. 2. A new dialog box will appear. Choose the Workspaces tab. 3. Type a name for your workspace in the Workspace Name: edit box, for example, ece3331fort might be a good choice. 4. Pick a location to save using the browse button (a small button with an ellipses on it). The directory must exist before you can choose it. Visual Studio will create a directory within the directory you choose, and it will be assigned a name identical to your workspace name. 5. Click OK to create the workspace. Creating a Project 1. To create a project within your workspace, choose New from the File dropdown menu. A dialog box will appear. 2. Make sure you are on the Project tab. This should be the default tab when the dialog box appears. 3. Select Fortran Console Application from the list. 4. Type a name for your project in the Project Name: edit box, for example, cp6 might be a good choice. 5. Pick a location to save using the browse button (a small button with an ellipses on it). The directory must exist before you can choose it. Visual Studio will create a directory within the directory you choose, and it will be assigned a name identical to your project name. For example, you could choose the ece3331fort workspace created above. Using this kind of directory structure is a good way to organize several projects within a single workspace. 6. When the next dialog appears, make sure to choose An empty project and click Finish. 7. Click OK for the next dialog box. 8. On the left side of the Visual Fortran application pane, choose the File View tab. Notice that your newly created project is nested within the workspace. Notice that the words cp6 files are in bold letters. This means that this is the current project, and any source files created will be added to this project.

Creating Source Files 1. From the Project dropdown menu, choose Add to Project and then New in the pop-out menu. A dialog box will appear. 2. Make sure the Files tab is chosen. This should be the default when the dialog box opens. 3. If you are creating a Fortran 77 program, select Fortran Fixed Format Source File in the list. If you are creating a Fortran 90/95 program, select Fortran Free Format Source File in the list. 4. Type the name of your source file in the File name: edit box, for example cp6 might be a good choice. You do not need to type an extension. Visual Fortran will assign a .for extension to Fortran 77 files and a .f90 extension to Fortran 90/95 files. If you change this, Visual Fortran will have a problem when it tries to compile the file. The compiler must know whether the source file is fixed format or free format. 5. You probably do not need to choose the location to save this file. The current projects directory will be listed in the Location: edit box. 6. Click OK and the source file will be created and opened. You can now type your source code. Compiling the Source Code Visual Fortran allows you to compile either a single source file or the entire project, assuming there are many files in a particular project (this will not be the case for ECE 3331). 1. To compile only one source file, highlight the file from the Source Files list in the left hand pane of the Visual Fortran application window. From the Build dropdown menu, choose Compile filename.ext, where filename.ext will be the source file that you have highlighted. Any errors in the source file will be listed at the bottom of the screen. 2. To compile the entire project, choose Build from the dropdown menu and then choose Build project.exe, where project.exe is the project you wish to compile. This command will compile all source files within the project, link their respective object files and create an executable file assuming there are no errors. 3. If errors arise during compilation of the source code, they will be listed in the Build window at the bottom of the Visual Fortran application window. Simply double-click on the error message, and the line of code that contains the error will be highlighted. Debugging the Source Code One of the nice features of Compaq Visual Fortran is the debugging environment. It is intuitive to follow and easy to learn. 1. The debugger can only be employed when an executable file is made. If the source code does not compile, the debugger will not be available. 2. To force the debugger to pause execution of the program prior to reaching its end, breakpoints must be set within the program. A breakpoint is a location in a process where execution is stopped to allow the developer to examine the process's code, variables, and register values, and, as necessary, make changes, continue execution, or terminate execution. 3. To set a breakpoint at a source-code line, do the following: In a source window, move the insertion point to the line where you want the program to break. Choose the Insert/Remove Breakpoint toolbar button or press F9. A red dot appears in the left margin, indicating that the breakpoint is set. Note. If you want to set a breakpoint on a source statement extending across two or more lines, you must set the breakpoint on the last line of the statement. 4. To set a breakpoint at the beginning of a function (or subroutine), do the following: In the Find box on the Standard toolbar type the function (or subroutine) name. Click the Insert/Remove Breakpoint toolbar button or press F9.

5.

6.

7. 8.

9.

While in debug mode a red dot appears in your source code in the left margin at the beginning of the function (or subroutine), indicating that the breakpoint is set. To set a breakpoint at the return point of a function (or subroutine), do the following: Start debugging, and pause the debugger in break mode (program is waiting for user input after completing a debugging command). On the View menu, click Debug Windows, then click Call Stack. In the Call Stack window, move the insertion point to the function (or subroutine) where you want the program to break. Click the Insert/Remove Breakpoint toolbar button or press F9. While in debug mode a red dot appears in the left margin of your source code, indicating that the breakpoint is set. To set a breakpoint at a label, do the following: In the Find box on the Standard toolbar type the name of the label. Click the Insert/Remove Breakpoint toolbar button or press F9. While in debug mode a red dot appears in your source code, in the left margin at the line containing the label, indicating that the breakpoint is set. To initiate the debugger, choose Build from the dropdown menu, then pick Start Debug and then select Go. Pressing F5 will also start the debugger. The program will then stop at the first breakpoint it encounters. At this point, there are several options for working through the program. To continue to the next breakpoint, press F5. To step into the next statement, press F11. To step over the next statement, press F10. To step out of a loop or subprogram, press shift+F11. To execute to the current cursor position, press ctrl+F10. Note: all of the above commands are available on the debugging toolbar. This toolbar becomes active as soon as the debug session is initiated. It is possible, during the debug session, to view the value of most variables. This is not possible if the variable is being held in a register. To view the variables in the current subprogram, press the Locals tab at the bottom of the application window. To view a particular variable, the variable name can be entered on one line of the watch window, and its current value will be displayed.

Das könnte Ihnen auch gefallen