TOC PREV NEXT INDEX

Chapter 6 Using Visual Fortran


This chapter contains the following sections:

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:

The visual development environment includes:

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:

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

To start Visual Fortran:

  1. From the Start menu, click Programs.
  2. Click Compaq Visual Fortran 6 to display the contents of the program folder.
  3. 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:

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\Win32

You 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.

Figure 6-1 Visual Development Environment Window

The left pane contains a FileView tab and may contain a ClassView or ResourceView tab:

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:

  1. In the Tools menu, select Options.
  2. Click the Workspace tab.
  3. 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:

For more information, see:

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:

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:

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:

  1. Start Developer Studio (see Section 6.2, How to Start the Visual Development Environment).
  2. 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.

  1. 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.

  1. Select the Celsius workspace file, Celsius.dsw.
  2. Click the Open button.

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.

  1. From the Build menu, choose Build Celsius.exe.

The status of the build is displayed in the Build pane at the bottom of the screen.

  1. From the Build menu, choose Execute Celsius.exe to run the program. A console output window appears, displaying the output from the program.
  2. If you want to use the debugger for this project, see Section 6.9, How to Debug a Source File.
  3. 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:

  1. 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.)
  2. 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.

  1. 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.

  1. Build the revised program by clicking the Build Celsius.exe menu item in the Build 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:

  1. Click the first executable line to set the cursor position. In this case, click on the beginning of the first PRINT statement line.
  2. Click on the Set/Remove Breakpoint (open hand symbol) button in the Build toolbar, as shown in Figure 6-2.
Figure 6-2 Setting the Initial Breakpoint in the Debugger

The red bullet in the left margin of the text editor/debugger window shows where a breakpoint is set.

  1. In the Build menu, click the Start Debug: Go item, as shown in Figure 6-3.
Figure 6-3 Starting the Debugger

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.

  1. 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.
Figure 6-4 Using Step Over in the Debugger

  1. 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.
Figure 6-5 Viewing the Value of a Variable in the Debugger

  1. If you need to build the program again, click on the Stop debugging item in the Debug menu.
  2. 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:
Table 6-2 Additional Features of the Debugger
To do this:
Do this:
Display the Local Variables window
In the View menu, click the Debug Windows, Variables item. Click the Locals tab.
Display the Watch window
In the View menu, click the Debug Windows, Watch window item.
Display a value in the Watch window
Select a variable name in the text editor window, drag it, and drop it into the Watch window.
Set or clear a breakpoint
Click on the line where the breakpoint is to be set or cleared. Then do either of the following:
- Click on the Set/Remove Breakpoint (open hand symbol) button in the Build toolbar.
- In the Edit menu, click Breakpoints. A dialog box lets you set or clear breakponits, evaluate expressions, and perform other functions.

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:

  1. Start Developer Studio (see Section 6.2, How to Start the Visual Development Environment).
  2. From the File menu, select New. A dialog box appears containing the following tabs:
    • Files
    • Projects
    • Workspaces
    • Other Documents
  3. Select the Projects tab, which displays various project types, as shown in Figure 6-6.
Figure 6-6 New Project Type Dialog Box

You need to:

    1. Enter the project name, for example, Solver. The Location field will automatically show a subdirectory for the project.
    2. 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.
    3. 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.
    4. 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.)
    5. 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.

  1. 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.
  2. 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.)

  1. 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.
  2. Click OK.
  3. 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.

  1. 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:

  1. Select Files from the submenu.
  2. 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:

  1. Select New from the submenu.
  2. The New dialog box appears. Specify the file name and its location.
  3. Click the type of file (Fortran Fixed Format Source or Fortran Free Format Source).
  4. 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_TEST 
    

Now 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:

6.11 Customizing the Visual Development Environment

There are a number of ways you can customize the visual development environment to suit your preferences:

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:

  1. In the Tools menu, choose Customize.
  2. Click the Keyboard tab.
  3. Select the type of editor (such as main or text) from the Editor drop-down list.
  4. 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:

  1. In the Tools menu, choose Options.
  2. Click the Compatibility tab.
  3. Select the editor emulation from the drop-down list.
  4. 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:

  1. Open the file to be printed in the text editor.
  2. In the File menu, click Print Colorized Fortran.
  3. 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.
  4. 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:

  1. In the Project menu, click Settings.
  2. Click the Fortran tab.
  3. Turn on the Generate Source Browser Information checkbox in the General category.
  4. Click the Browse Info tab.
  5. 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:

  1. In the Tools menu, click Source Browser.
  2. 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.
  3. 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:

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:

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.


TOC PREV NEXT INDEX