Chapter 6 Using Visual Fortran
This chapter contains the following sections:
- 6.1, What is the Visual Development Environment?
- 6.2, How to Start the Visual Development Environment
- 6.3, Visual Fortran Projects
- 6.4, Visual Development Environment Windows
- 6.5, Getting Online Help
- 6.6, Project Configurations and Settings
- 6.7, How to Build an Existing Visual Fortran Project (Celsius)
- 6.8, How to Edit a Source File
- 6.9, How to Debug a Source File
- 6.10, How to Create a New Project Based on Existing Source Files
- 6.11, Customizing the Visual Development Environment
- 6.12, Using the Text Editor
- 6.13, Using the Source Browser
- 6.14, Using the Resource Editors
- 6.15, Using the Debugger
Note
This chapter provides a brief introduction to the Microsoft visual development environment. For a more comprehensive understanding, you will need to use the Microsoft documentation.
6.1 What is the Visual Development Environment?
The Microsoft visual development environment is a graphical, user-friendly interface allowing you to manipulate your Visual Fortran files.
Note:
You can also use Visual Fortran from the command line. See Section 7.3, Using the Command-Line Interface.
Using the visual development environment, you can:
- Examine your Fortran source code and make changes and additions to it
- Create input data files and modify the input data
- Compile and link your program
- Debug the errors associated with compiling and linking your program
- Debug logic errors in your program
- Examine your program's output files
- Create Fortran programs using dialog boxes, windows, and other graphics to receive data and display results
The visual development environment includes:
- A project manager to let you automate application builds according to your specifications and tools settings (see Section 6.3, Visual Fortran Projects, and Section 6.6, Project Configurations and Settings)
- A text editor (see Section 6.12, Using the Text Editor)
- A source code browse window (see Section 6.13, Using the Source Browser)
- Resource editors (see Section 6.14, Using the Resource Editors)
- A debugger (see Section 6.15, Using the Debugger)
- A linker supporting incremental linking for faster builds following small changes to the source file
- A profiler for determining the execution frequency of various code paths
Because these tools run under Windows 2000, Windows NT 4, Windows Me, Windows 98, and Windows 95, you can use a variety of Windows features to work faster and more efficiently. For example:
- You can select a variable name in an editor window while debugging, drag that name into the Watch window, and drop it there. The debugger then evaluates the variable and displays the result in the Watch window.
- You can select a control from the toolbar in the dialog box editor and drop it onto a dialog box you are creating. You can then size and position the control as required for your application.
The visual development environment includes toolbars that allow you to quickly invoke commands by clicking a button. You can customize the default toolbar to suit your needs, or you can create your own toolbars. To see a brief description of a toolbar button, you can position the mouse pointer over the button for a second or two (without clicking).
6.2 How to Start the Visual Development Environment
- From the Start menu, click Programs.
- Click Compaq Visual Fortran 6 to display the contents of the program folder.
- Click Developer Studio.
The Microsoft visual development environment appears.
To quit Visual Fortran, choose Exit from the File menu.
6.3 Visual Fortran Projects
In Visual Fortran, development is organized into projects consisting of the source files required to build an application. To set up a project, you need to define the project and set options for it. Then, using the source files, you can build the binary executable or library file. The output of building the application becomes part of the project. A project is stored in a project folder on your hard drive.
Every Visual Fortran project must be one of the following project types:
- Fortran Console application.
- Fortran QuickWin application.
- Fortran Standard Graphics application.
- Fortran Windows application.
- Fortran COM Server application. A Fortran COM Server project is a special-purpose project that lets you create COM servers or dual-interface servers using the Fortran COM server wizard. (Available only with the Professional and Enterprise Editions.)
- Fortran Static Library application (file extension .LIB). A static library is a set of routines that can be called from procedures that are loaded into your application at link time.
- Fortran Dynamic-Link Library (DLL) application (file extension .DLL). A DLL is a set of routines that can be called from procedures that are loaded into your application at run time.
Projects are contained in a workspace. A workspace can contain multiple projects. For example, if you have several Fortran applications that do different calculations but are related to the same research application you're working on, you can store all the individual projects in a workspace. A workspace file has the file extension .dsw.
You need to create a separate project for each binary executable or library file to be created. For example, the main Fortran program and a Fortran dynamic-link library could each reside as:
Table 6-1 describes some project types.
Table 6-1 Visual Fortran Main Project Types Project Type Typical Appearance, Programming Complexity, and Location of Online Samples Fortran Console application Appearance: One character-cell terminal window.Complexity: Simple, resembles character-cell applications.Location: As described in Section 6.7, see:
\Microsoft Visual Studio\Common\MSDev98\My Projects\Celsius Fortran Standard Graphics or Fortran QuickWin application Appearance: One window (Standard Graphics) or multiple windows (QuickWin) with graphics such as menus, charts, and icons.Complexity: Simple to moderate, depending on the graphics and user interaction used.Location: See folders such as Qwpiano or Qwpaint in:
\Microsoft Visual Studio\Common\DF98\Samples\Quickwin Fortran Windows application Appearance: Multiple windows using full graphics interface and Win32 API functions.Complexity: Advanced, requires programming expertise for Win32 API.Location: See folders such as Platform or Polydraw in:
\Microsoft Visual Studio\Common\DF98\Samples\Advanced\Win32You can convert a Fortran Console or Fortran Standard Graphics application to a Fortran QuickWin application by creating the Fortran QuickWin project as a new project, setting the same Project settings, and adding files to the Fortran QuickWin project.
For an example of a multiple project, see the SPLINE mixed-language sample program. This sample contains multiple projects in one workspace, including a Fortran dynamic-link library called either by the main Fortran QuickWin program or the main Visual C++ program. See Section 7.1, Using the Sample Programs.
6.4 Visual Development Environment Windows
Figure 6-1 shows an example of the visual development environment.
The left pane contains a FileView tab and may contain a ClassView or ResourceView tab:
- FileView: Shows each project and their files associated with the workspace.
- ClassView: Appears only if Visual C++ is installed. ClassView is used by Visual C++ for mixed-language programming and is not used by Visual Fortran.
- ResourceView: Appears if the workspace uses Resources. (A Resource is binary data added to an application's executable file. Examples are dialog boxes and icons.)
After you open a workspace, the FileView tab shows the files associated with that workspace. In the FileView pane of Figure 6-1, there are two files: calendar.f90 and calnmod.f90.
The file calnmod.f90 defines a Fortran 90 module file (a post-compiled binary file with an extension of .mod) that is used by calendar.f90. Because calendar.f90 is dependent on the calnmod.mod file being present, it is listed under External Dependencies.
In the right pane of Figure 6-1, the file calendar.f90 is shown in the default language-sensitive visual development environment editor, which uses different colors to identify the following:
To edit a file listed on the FileView pane, either double-click its file name or use the Open item in the File menu.
The output pane appears in the bottom of Figure 6-1, showing text displayed from building the project. The output pane has multiple tabs. The output pane Build tab is selected after you open a workspace and compile one or more project files or build the project. To display the output pane, select Output from the View menu.
6.4.1 Floating Windows and Docking Windows
A floating window can be moved and has a title bar. To move a floating window, drag its title bar.
A docking window is docked (attached) along an edge of the visual development environment window and does not have a title bar.
To allow a docking window to float (not be docked) or to allow a floating window to dock along an edge, do one of the following:
To specify which visual development environment windows will be docked windows and which will be floating windows:
- In the Tools menu, select Options.
- Click the Workspace tab.
- In the Docking View list, click the checkbox for each window to be displayed with a docking view. Unchecked boxes indicate floating windows.
To cycle through your floating windows in the visual development environment, hold down the Ctrl key and click Tab.
6.5 Getting Online Help
You might need help while you are working in the visual development environment. To display information about an option in a dialog box, for example, do either of the following:
- Click the ? (Help) button and click the item you want help on.
- Move your pointer to the item you want help on and click F1.
- Section 7.6, Viewing Online Documentation in the HTML Help Viewer
- Chapter 9, Using the HTML Help Viewer
6.6 Project Configurations and Settings
Each project can specify one or more configurations to build from its source files. A configuration specifies such things as the type of application to build, target platform, and the settings to use when building, such as compiler and linker options.
When you create a project, a Debug and a Release configuration are automatically created:
- A Debug configuration contains full symbolic debugging information that can be used by the debugger. Typically, no optimization or minimal optimization is used.
- A Release configuration does not contain any symbolic debugging information. It contains default optimizations, or your selected optimizations if you have overridden the defaults.
Having multiple configurations lets you extend the scope of a project but still maintain a consistent source code base from which to work.
To specify the current configuration, from the Build menu select Set Active Configuration. When you build your project, the currently selected configuration is built.
Within a project, you can create groups or folders that contain related files. FileView displays the folders and files contained in the project as a graph so you can quickly see the relationships among files.
From the Project menu, select Settings to specify settings for the entire project, for certain configurations, or for certain files. For instance, you can specify certain kinds of compiler optimizations for your project in general, but turn them off for certain configurations or certain files.
Once you have specified the files in your project, the configurations that you want your project to build, and the settings for those configurations, you can build the project with the commands on the Build menu.
For more information about projects:
- Open the sample project Celsius. See Section 6.7, How to Build an Existing Visual Fortran Project (Celsius).
- See Building Programs and Libraries in the online Programmer's Guide described in Section 8.2, Documentation Available in HTML Help Viewer Format.
6.7 How to Build an Existing Visual Fortran Project (Celsius)
For information about Visual Fortran projects, see Section 6.3, Visual Fortran Projects.
To open and execute the sample project workspace file, Celsius.dsw:
- Start Developer Studio (see Section 6.2, How to Start the Visual Development Environment).
- From the File menu, choose Open Workspace.
The Open Workspace dialog box appears, displaying the default projects directory. The default installation location for the Celsius project workspace is the folder
\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects.
- In the list of files and directories within the My Projects folder, double-click the Celsius folder.
The files and directories list now displays the Celsius workspace file.
The visual development environment displays the contents of the Celsius project in the FileView pane. You can click the plus sign (+) next to the Celsius folder to see the contents of the project. In this case, there is only one file, CELSIUS.FOR.
The status of the build is displayed in the Build pane at the bottom of the screen.
- From the Build menu, choose Execute Celsius.exe to run the program. A console output window appears, displaying the output from the program.
- If you want to use the debugger for this project, see Section 6.9, How to Debug a Source File.
- When you are done with this project, select Close Workspace from the File menu.
Visual Fortran includes a number of sample projects, most of which include a project workspace file. See Section 7.1, Using the Sample Programs.
6.8 How to Edit a Source File
The text editor allows you to edit your projects.
The following information assumes you have opened the Celsius workspace in the folder \Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects and have built the Celsius project. (See Section 6.7, How to Build an Existing Visual Fortran Project (Celsius).)
To edit the Celsius source file CELSIUS.FOR:
- The contents of the Celsius project are displayed in the FileView pane. Click the plus sign (+) next to the Celsius folder to see the contents. In this case, there is only one file, CELSIUS.FOR. (If you had any INCLUDE files, they would be listed under External Dependencies.)
- Double-click on the CELSIUS.FOR file name in the FileView pane. The text editor window appears, displaying the source contents of CELSIUS.FOR.
Because CELSIUS.FOR is a fixed-form source file, the text editor shows where column 6 is.
- Click on a line you want to edit and enter the corrections. For example, change the DO loop to have a stride different from 10.
To save the edited file, click Save in the File menu.
For more information, see Section 6.12, Using the Text Editor.
6.9 How to Debug a Source File
The debugger allows you to debug your projects.
The following information assumes you have opened the Celsius workspace in the folder \Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects.
From the Build menu, select Set Active Configuration. Select the Debug configuration. Then build the Celsius project. (See Section 6.7, How to Build an Existing Visual Fortran Project (Celsius).)
To debug the Celsius source file CELSIUS.FOR:
- Click the first executable line to set the cursor position. In this case, click on the beginning of the first PRINT statement line.
- Click on the Set/Remove Breakpoint (open hand symbol) button in the Build toolbar, as shown in Figure 6-2.
The red bullet in the left margin of the text editor/debugger window shows where a breakpoint is set.
- In the Build menu, click the Start Debug: Go item, as shown in Figure 6-3.
The debugger is now active. The current position is marked by a yellow arrow at the first executable line (the initial breakpoint).
The Debug menu appears on the Developer Studio title bar in place of the Build menu.
If not displayed previously, the Debug toolbar appears.
- Step through the lines of source code. You can do this with the Debug menu item Step Over (as shown in Figure 6-4) or the Step Over button on the Debug toolbar.
- Repeat the Step Over action (use the Debug toolbar). Follow program execution into the DO loop, and so on until you are at the end of the program. Position the cursor over the variable Celsius to view the current value (called Data Tip), as shown in Figure 6-5.
- If you need to build the program again, click on the Stop debugging item in the Debug menu.
- When you complete working with the project, click the Close Workspace item in the File menu.
Some additional features of the debugger you can try when it is active are shown in Table 6-2:
In the Debug menu, click the Stop Debugging item to stop the debugger.
For more information, see Section 6.15, Using the Debugger.
See also Debugging Fortran Programs in the online Programmer's Guide described in Section 8.2, Documentation Available in HTML Help Viewer Format.
6.10 How to Create a New Project Based on Existing Source Files
To create a new Visual Fortran project based on existing source files:
- Start Developer Studio (see Section 6.2, How to Start the Visual Development Environment).
- From the File menu, select New. A dialog box appears containing the following tabs:
- Select the Projects tab, which displays various project types, as shown in Figure 6-6.
- Enter the project name, for example, Solver. The Location field will automatically show a subdirectory for the project.
- Accept the default location or specify another location. This is the master directory under which projects and workspaces will be created. You can change this to anything you want. If you want it to be where your source files are located now, change it to the name of that directory.
- Click the type of Fortran project to be created, such as Fortran Console Application. If you have any other Visual tools installed, make sure you select a Fortran project type. See Section 6.3, Visual Fortran Projects.
- Turn on the Create new workspace radio button to create a new Workspace. (If you were adding an additional project to the currently open workspace, you would turn on the Add to current workspace radio button.)
- Click OK.
Depending on the project type selected, one or more dialog boxes appear, requesting additional information about the project. For example, one dialog box gives you the option of creating only the project files with no source files (empty project) or a project with a source file that contains a template for that project type.
- If you chose Fortran Console Application as your project type, you'll be asked `What kind of console application do you want to create?'. Select An empty project.
- If you chose a Location different from the actual location of the source files, you can copy the files into the project directory if you want, but this isn't necessary.
If a saved Fortran environment exists for the Fortran project type being created, you can also import that Fortran environment to provide default project settings for the new project. (For more information on saved environments, see Building Programs and Libraries in the online Programmer's Guide described in Section 8.2, Documentation Available in HTML Help Viewer Format.)
- Choose Project, then Add to Project, then Files. If necessary, change Files of type to Fortran files. Browse to where your source files are located and select the files. Select only the compilable source files, not any files included by INCLUDE or USE statements.
- Click OK.
- Click the Build button to build your application. The Build button looks like an open-topped box with two arrows pointing down. You can usually find it somewhere near the left of the large red exclamation point.
You have now built a Debug configuration, without optimization. The executable file and other output files are in the Debug subfolder in your project directory.
To switch to a Release configuration, choose Build, then Set Active Configuration, then Release. Now click Build again. The executable and other output files will be in a Release subfolder in your project directory.
- To run the program without the debugger, click on the Run button (the exclamation point). To run in the debugger, you need to set a breakpoint. See Section 6.9, How to Debug a Source File.
See also Section 6.8, How to Edit a Source File.
6.10.1 How to Add Files to a Project
You can add files to a project by selecting Add To Project from the Project menu.
To add an existing file to a project:
- Select Files from the submenu.
- The Insert Files into Project dialog box appears. Use this dialog box to select the Fortran files to be added to the project. To add more than one file to the project, hold down the Ctrl key as you select each file name.
To add a new file to a project:
- Select New from the submenu.
- The New dialog box appears. Specify the file name and its location.
- Click the type of file (Fortran Fixed Format Source or Fortran Free Format Source).
- Click OK. The editor appears allowing you to enter source code. The file name appears in the FileView pane. For example, you might enter the following short Fortran program and save it as HELLO.F90:
! File HELLO.F90 PROGRAM HELLO_TEST print *, 'hello world' print *, ' ' END PROGRAM HELLO_TESTNow you can build and run the program as described previously for an existing project. See Section 6.7, How to Build an Existing Visual Fortran Project (Celsius).
For more information about projects:
- See Building Programs and Libraries in the online Programmer's Guide described in Section 8.2, Documentation Available in HTML Help Viewer Format.
- See Working With Projects in the online Visual C++ User's Guide (for Visual Fortran) described in Section 8.2, Documentation Available in HTML Help Viewer Format.
6.11 Customizing the Visual Development Environment
There are a number of ways you can customize the visual development environment to suit your preferences:
- You can add and delete buttons from existing toolbars and menus.
- You can change any of the default shortcut keys, add shortcut keys, set multiple shortcut keys for a command, and specify the windows in which any shortcut is active.
- You can add your own tools to the Tools menu.
- You can record keystrokes in a text editor window and then play them back to recreate that sequence of commands.
- In text editor windows, you can display language elements, such as comments or keywords, in the color of your choice. You can also display the text in one window in a specific font.
- You can establish a layout for the windows associated with a particular project workspace. The visual development environment retains that layout of open files and window positions for the next time you start the project workspace.
- When you are debugging an application, you can choose which windows and toolbars to display. The visual development environment retains that selection for all subsequent debugging sessions.
For more information, see The Visual C++ Environment in the online Visual C++ User's Guide (for Visual Fortran) described in Section 8.2, Documentation Available in HTML Help Viewer Format.
6.12 Using the Text Editor
The text editor in the visual development environment is a language-sensitive editor that recognizes source code syntax and makes source files easy to read. For example, when you edit a file with an .F90, .F, .FOR, or .FPP extension, the editor presents statements and keywords in a second color. You can customize the keyword coloring.
To view the current keyboard mappings, click the Help menu item Keyboard Map.
To customize the keyboard shortcuts for the text editor:
- In the Tools menu, choose Customize.
- Click the Keyboard tab.
- Select the type of editor (such as main or text) from the Editor drop-down list.
- Select the category of keyboard shortcuts by using the Category drop-down list. For example, select the appropriate type of operation, such as FileOpen.
For each operation selected, the shortcut key is shown in the Current keys box.
You can deassign a key combination and assign a new key combination.
You can also view the mapping of a key combination by entering that key combination.
To customize the keyboard commands to match a more familiar text editor, such as Brief or Epsilon:
- In the Tools menu, choose Options.
- Click the Compatibility tab.
- Select the editor emulation from the drop-down list.
- Select other options by using the checkboxes.
You can open any file in binary form and work with either the ASCII or the hexadecimal representation. You can even look at programs, object files, and libraries this way.
All Visual Fortran keywords (such as Fortran statements and intrinsic functions) are highlighted in a color different from the surrounding text. If you are using fixed-form source, the columns of your source code have different colors, including the label zone, the continuation column, and anything beyond the fixed-form line length (by default, column 72).
To print the text in the text editor to a color printer:
- Open the file to be printed in the text editor.
- In the File menu, click Print Colorized Fortran.
- In the dialog box, to print to a printer other than your default printer or to change printer options, click Launch Browser. The Fortran source file is displayed in your default browser. In your browser's File menu, click Print and select the printer and options needed.
- Click OK.
For an example of using the text editor, see Section 6.8, How to Edit a Source File.
For more information, see Text Editor in the online Visual C++ User's Guide (for Visual Fortran) described in Section 8.2, Documentation Available in HTML Help Viewer Format.
6.13 Using the Source Browser
As you are developing and debugging your application, you need to see the symbols you are using in a variety of contexts. The source browser in the visual development environment lets you look at symbol usage in the source code and view graphs of calling relationships between functions. Using the source browser makes it easy to maintain, revise, and debug your code.
When you build your application, Visual Fortran can create a browse information file containing information about the symbols in your application. The browse window displays this information and lets you move among instances of the symbols in your source code. For example, you can move to every place in every file where the symbol is used.
To create a browse information file:
- In the Project menu, click Settings.
- Click the Fortran tab.
- Turn on the Generate Source Browser Information checkbox in the General category.
- Click the Browse Info tab.
- Set the Build browse info file option.
Because Fortran is not a case-sensitive language, you should make sure that the source browser is treating symbol names as case-insensitive. After you modify and build your project to generate browse information:
- In the Tools menu, click Source Browser.
- Near the bottom of the Browse window, locate the Case sensitive checkbox. If the check box is checked on, click it to remove the check mark.
- When you are done using the Browse window, click OK.
In the Browse window, you can view graphs of calling relationships among functions. You can easily view all the symbols contained in a given file, display the definition of any symbol in the file along with all its references in your project, and then open the file containing a particular reference by double-clicking the entry in the window.
6.14 Using the Resource Editors
The visual development environment provides resource editors to develop user-interface components such as dialog boxes, menus, and icons for your projects. Dialog editors and menu editors are examples of resource editors.
Visual Fortran supports both modal and modeless dialog boxes. You can use a number of dialog functions to define the dialog boxes and their controls. Among the types of controls supported are ActiveX controls, static text, buttons, edit boxes, group boxes, checkboxes and radio buttons, list and combo boxes, scroll bars, pictures, progress bars, spin controls, sliders, and tab controls.
For example, to build a dialog box, you drop the interface controls onto a blank dialog box in the construction area, save it, and write the code to initialize and use it from your program.
For more information, see the following topics:
- Using Dialogs in the online Programmer's Guide
- Resource Editors in the online Visual C++ User's Guide (for Visual Fortran)
For information about accessing these online manuals, see Section 8.2, Documentation Available in HTML Help Viewer Format.
6.15 Using the Debugger
For an example of using the debugger, see Section 6.9, How to Debug a Source File.
The debugger in the visual development environment helps you check the logic of an executing program and examine or change variables at run time.
After you have corrected all the build errors encountered during compiling and linking, you can use the debugger to correct logic errors. The debugger lets you monitor your program as it runs and stop it at locations or situations of your choosing. For example:
- When you have isolated a problem to a specific part of a program, you can have your application execute until the application reaches a particular line by setting a breakpoint on a line of code. You can set breakpoints by using the Edit menu item Breakpoints or by right-clicking in the left margin of the text editor window.
- When debugging the cause of a message or exception, you can suspend program execution when the program receives a specified message, or when a specific exception occurs.
- If you are interested in the values assigned to a particular variable, you can have the debugger break whenever your application changes the variable's value.
You can request that Visual Fortran start its debugger for any program that fails while running, regardless of whether the program has debug information or whether Visual Fortran was running beforehand. The debugger starts up while the program is still running, allowing you to analyze the program as it runs. With Just-In-Time debugging, it is possible to find and fix the problem in the program and let it continue running.
For more information, see Debugging Fortran Programs in the online Programmer's Guide described in Section 8.2, Documentation Available in HTML Help Viewer Format.