Programs for Programmers

Using Intel Fortran and Microsoft Visual Studio

You’ve been using Compaq Visual Fortran with Microsoft’s Developer Studio for years and it all works, so why think about upgrading?:

·   You wish to use new features of the Fortran language like F2003 or F2008 that are not supported in CVF.

·   You wish to create a mixed-language application calling your Fortran code from Visual Basic.

·   Your third-party add-on library is gradually phasing out support for CVF and Developer Studio.

·   The good chaps at Intel support are politely suggesting that you should!

So you’ve taken the plunge and bought the compiler, The good news is with v11.0, you now don’t have to buy Visual Studio separately.  The bad news is that the Visual Studio supplied with the compiler is the ‘Premier Partner’ edition, which basically means that you can only use it with Intel Fortran.  If you are looking at developing mixed-language applications, you still need to purchase the full version with the necessary VB, VC++, C# compiler.

Command Window

If you don’t wish to use the compiler from Visual Studio, you can still build and run your programs in a Command Window, but ensure that you run it from the one supplied with the compiler. (known as Build environment for Fortran applications).  The linker that the compiler uses is part of the Visual Studio package and tracking down its location is not always straightforward, so using the environment ensures that both the Fortran compiler and C++ linker directory are in the path. For example if you use Intel Parallel Studio XE 2015:

C:\Program Files\Intel\Composer XE 2015\bin\ia32                 IFORT.exe
C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN              VS2008

C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN             VS2010
similar for newer versions of Visual Studio (2012, 2013, 2015)

If you get a bunch of strange linker errors, it could be that you still have your old CVF linker in the path and not the new one.  The old linker was found in:

C:\Program Files\Microsoft Visual Studio\VC98\BIN                Dev Studio

and when used, shows the banner

Incremental Linker 6.00

The linker that comes with Visual Studio 2008 is v9.00 and with Visual Studio 2010 is v10.00, and so on.

What’s the difference between a Project and a Solution?

When creating a new project within Visual Studio, you are given a choice between creating a new ‘project’ or a new ‘solution’.  What’s the difference?  A project is a collection of one or more files associated with one particular language, i.e. Fortran.  A solution can contain one or more projects.  Therefore if developing a mixed-language application, the solution may contain one project containing Visual C++ files and one project containing F90 files.  In its simplest case, a single-source file F90 application will be contained in one project with the same name as its parent solution. 

Converting a Project from CVF Developer Studio

If you own a full Visual Studio (not just the shell edition that comes with Intel Fortran), projects can be converted from the old Compaq Visual Fortran Developer Studio (and from previous versions of Visual Studio.NET), but remember to take a backup, because they cannot be read back in to the older IDE’s afterwards!

Compile and Link Options

Of most interest to the Fortran developer is the setting of compiler and linker switches.  These are accessed via ProjectPropertiesFortran and ProjectPropertiesLinker  This is where all the switches are found, grouped in sensible groups with nice names.  If you are more familiar with the old command-line switch names, cycling through each option displays a 2-line description together with the equivalent command-line option at the bottom of the window.  If you still can’t find the right place to set your switch, then it can be placed in the Command Line  - Additional options entry box in its old-style format and all the other command line switches can be viewed here as well.

Building

Building your project is fairly straightforward and similar to the old Developer Studio.  You have a variety of ways of initiating the build, either via menu-pulldowns, the arrow in the toolbar or the simplest way, pressing <f5>.

Debugging

Getting to grips with the debugger can really speed up development time, but there are many features that are always difficult to find in the documentation:

  1. Much of the Visual Studio environment is configurable to each user.  Not just the size and position of the panes but right down to the actual items on the toolbars and in the menu pulldowns!
    For example, if the option ‘Run to Cursor’ has disappeared from the Debug menu it can be reinstated by going to ToolsCustomizeCommands – and selecting Debug in the Categories box.  Then scroll down the list and find ‘Run to Cursor’ and drag it right out of the window up to the Debug menu pulldown and place it where you like in the pulldown list!

     
  2. If you are expecting to see a window containing local variables or call stack for instance and it isn’t displayed, go to DebugWindows and select the required window.

     
  3. Did you know you can also split a source window into two halves so that you can navigate around the source while referring to a fixed position in the same source window.

    visual studio debugging

    Click on the small bar just above the up-arrow and drag it down to create a second pane within the same window

    visual studio debugging

     
  4. Line Numbers - To display line numbers in the source editor; ToolsOptionsText EditorFortran and click on Display Line numbers.

This is just a small taster of the capabilities of Intel Fortran and Visual Studio.  Visit the links below for more resources or contact us at Polyhedron for more specific information.