Roadmap to the Visual Fortran Samples
The Visual Fortran kit provides a number of source code sample programs (samples)
that cover a variety of topics. These samples are provided for illustration
purposes only, although they can be freely used as a basis for other programs.
You can copy the samples as needed. Use a text editor to view the samples;
they are not listed as topics in HTML Help viewer.
On the Visual Fortran media CD-ROM, samples are located in folders under
Info\Df\Samples
. If you request that samples
be installed using a Custom installation, the samples are by default installed
in subdirectories under ...\Microsoft Visual Studio\Df98\Samples
.
Visual Fortran samples include the following:
Advanced
Within the Advanced category, there are several other categories of samples. Each category is
described below, and the specific samples within each are described in its section.
Each category is contained within its own subdirectory
of ...\Df98\Samples\Advanced
:
Component Object Model (Advanced\Com
)
The COM samples demonstrate use of the Component Object Model from within Visual Fortran:
- adder: The Adder sample demonstrates a Fortran COM server and
its use by Visual Fortran, Visual C++, and Visual Basic clients. The COM
server implements a very simple "adding machine" object. Each client displays
a dialog box that uses the server. Adder is used as an example in
Creating a COM Server.
- autodice: The autodice sample demonstrates interactions between Fortran and
Excel 97. This program takes 12 numbers and uses Automation to tell Excel 97 to draw a
histogram of the numbers. The EXCEL97A module generated by the Fortran Module Wizard
is used as the interface to EXCEL. You must have Microsoft Excel 97 installed on your
computer in order to successfully run this sample.
- dlines: The dlines sample demonstrates interactions between Fortran and the
Developer Studio. This program converts Debug lines to IFDEF directives
(metacommands). It uses COM to drive Microsoft Developer Studio to edit the source file.
The COM interfaces defined in DSAPP.F90 are taken from:
...\Microsoft Visual Studio\Common\Msdev98\Bin\devshl.dll
The COM interfaces defined in DSTEXT.F90 are taken from:
...\Microsoft Visual Studio\Common\Msdev98\Bin\devedit.pkg
The dlines sample program is invoked with the following command line:
dlines inputsource outputsource debugchar ifdefname
Where: |
Inputsource is the filename of the input source file. Note: The source file
must be fixed form. |
|
outputsource is the filename of the output source file. |
|
debugchar is the the debug character in the source file to replace with IFDEF
directives (metacommands) |
|
ifdefname is the name to use with the IFDEF directives |
This program is useful as a tool to edit PowerStation Fortran files that used something
other than "C" or "D" as the comment character.
- dsbuild: The dsbuild sample demonstrates using Automation to drive Developers
Studio to rebuild a project configuration.
The Automation interfaces defined in
DSAPPA.F90 are taken from:
...\Microsoft Visual Studio\Common\Msdev98\Bin\devshl.dll
The Automation interfaces defined in DSBLDA.F90 are taken from:
...\Microsoft Visual Studio\Common\Msdev98\Bin\devbld.pkg
The dsbuild program is invoked with the following command line:
dsbuild project.dsw configuration
Where: | project.dsw is the file specification of
the project file. |
| configuration is the name of the configuration to rebuild. |
- ErrorInfo: The ErrorInfo sample demonstrates a Fortran COM Server that
supports COM ErrorInfo objects. For information about COM ErrorInfo objects, see
Adding Support for COM ErrorInfo Objects and the
Platform SDK online documentation.
- iweb: The iweb sample uses the COM interfaces in SHDOCVW.DLL to start a Web
Browser and direct the browser to navigate to a specified URL. The iweb program
is invoked with the following command line:
iweb url
Where: url is the URL to display
Any arguments not provided on the command line will be prompted for.
- safearray: The safearray sample demonstrates converting a Fortran two-dimensional
array to a COM SafeArray and reading the data back from the SafeArray.
- variant: The variant sample demonstrates using the VARIANT manipulation routines
in Visual Fortran. VARIANTs are used in COM interfaces.
Direct Fortran 90 Descriptor
Manipulation (Advanced\Descript
)
In other languages, such as C or Pascal, pointers are simple memory addresses with no notion
of how the information is organized at the address pointed to. Fortran 90 pointers differ
dramatically, by not just containing a memory address, but also keeping track of the bounds
and strides of each dimension of an array. To accomplish this, the Fortran 90 compiler uses
something called an Array Descriptor, which stores the details of how the array is organized.
Array Descriptors may also be called Dope Vectors in other implementations.
By manipulating the contents of a descriptor directly, you can perform operations that would
otherwise not be possible in strict Fortran 90. You can associate a Fortran 90 pointer with any
piece of memory, organized in any way desired (so long as it is rectangular in terms of array
bounds). You can also pass Fortran 90 pointers to other languages, such as C, and have the
other language correctly interpolate the descriptor to obtain the information it needs.
Important for mixed-language programming, you can create a Fortran 90 pointer associated
with an array which is accessed in C's row order, rather than Fortran's traditional
column order, allowing the same array to be used with the same subscripts from both C
and Fortran.
The descript workspace has three subprojects. Each creates its own executable, and there are
no dependencies between them:
- cassign: A Fortran 90 pointer is associated with a C array, in row order.
This pointer is then passed back to Fortran, which reads the values written by C
in exactly the same way that C wrote them. This project uses descript.h, which
provides the C prototypes, routines, and structure definitions to the Fortran
90 pointers.
- fassign: A Fortran 90 pointer is associated with a Fortran 90 array, in
row order, and then passed to a C routine which can read the array in natural
C notation.
- cube: Through use of the Bitmap module a Fortran 90 pointer is
created that points to an internal .BMP file, with its special structure (rows
reversed). Once this pointer is setup, the .BMP can be written to directly and
then quickly displayed on a QuickWin child window. This method is used to show
a flicker-free spinning cube.
OpenGL (Advanced\Opengl
)
OpenGL is a protocol for performing advanced 3-dimensional graphics.
Visual Fortran includes Fortran 90 modules and link libraries for using OpenGL from
Fortran. The sample programs included in this section illustrate programs that take
advantage of these facilities.
All OpenGL samples will run under Windows NT, Windows 2000, Windows Me, and Windows 98, but
require the OSR2 release of Windows 95 to run there. Refer to our Frequently Asked Questions at
http://www.compaq.com/fortran/visual/faq.html for more information.
- 3dcube: The 3dcube sample displays a three-dimensional box on a black background.
It uses QuickWin to create the window and draw the shapes using primitive 3D graphics.
- olympic: The olympic sample displays 5 rings on a window that rotate and
move towards each other, ultimately creating the Olympic symbol. It illustrates calls to
the OpenGL libraries, techniques for supporting code on 32- and 64-bit systems, techniques for
reading arguments from the command line, and interface blocks,
among other Fortran 90 concepts. This sample must be compiled with /fpscomp:logicals
due to a difference in the way that Visual Fortran and Microsoft PowerStation Fortran
interpret logical values. It must also be linked against the QuickWin libraries.
- puzzle: The puzzle sample displays a Rubik's Cube, and allows you to try and
solve it. There is currently a problem with the colors in this sample. It uses
Win32 calls to manage the windowing interface. Again, it illustrates techniques for
supporting code on 32- and 64-bit systems.
- simple: The simple sample displays some points, lines, and simple shapes in a
window. It uses QuickWin to manage the windowing interface. It is, as it sounds, a very
simple example, using primitive 2-D graphics. One interesting aspect of it is the use of
color and how to set some of the standard colors.
- wave: The wave sample displays a window with a surface waving. It uses QuickWin
to manage the windowing interface. Beyond the usage of OpenGL, here are many interesting
demonstrations in this sample, including the animation and the trapping of characters typed
while the window has focus. The keys that are trapped are:
- C, which changes the contour of the wave
- [space], which pauses the animation. To resume, hit space again
- S, which changes the shading of the wave
- A, which causes the wave to spin. To stop spinning, hit A again
- L, which changes the color of the wave.
Win32 API Calls (Advanced\Win32
)
Visual Fortran includes Fortran 90 modules and libraries for doing Windows
programming at the Win32 API level. For information on calling Win32 routines from a
Fortran application, see Calling Win32 Routines.
These samples presented here show Win32 API examples of how
this is done:
- angle: The angle sample uses the Windows interface to manage the GUI. It
illustrates a basic Windows program, including the event dispatcher, and the use of pens
and dialog boxes. The angle sample displays a shape consisting of a straight line plus
an arc, and allows the user to input X,Y coordinates, angle of the arc, and radius of the
arc, and then redraws.
- bounce: The bounce sample uses Win32 calls but creates a console application,
rather than a Windows based one. It is a multi-threaded application that creates a new thread
whenever the letter "A" is typed, up to a maximum of 32. Each thread bounces
a happy face of a different color across the screen. All threads are terminated
when the letter "Q" is typed. This particular application requires
that several compatibility switches be set: /fpscomp:logicals,
/fpscomp:ioformat, /fpscomp:general. These are found under the Compatibility entry
on the Fortran tab of the Project Settings dialog box.
- check_sd: The check_sd sample illustrates the use of security descriptors. The
purpose of the sample is to assist people who want to manipulate security descriptors with
sample code that they can start from. This sample, as is, examines the security descriptor
on files, and could be easily modified to check the security descriptor on other objects.
To use this sample,
check_sd
with no arguments checks the security descriptors on
the A: device. check_sd d:\a.fil
will check the d:\a.fil file. In this
case, D: must be formatted with the NTFS file system because only NTFS files have security
descriptors.
- cliptext: The cliptext sample demonstrates copying text to and from the clipboard.
It uses the Windows interface to manage the GUI, and as such, also demonstrates the use of
WinMain and MainWndProc that contains the event dispatcher. It has an "about"
box, located under the File menu item, as there is no Help.
- cmndlg: The cmndlg sample demonstrates the use of common dialog boxes,
including "About", File access dialogs, and error message dialogs.
Each dialog box is demonstrated being used in three different ways: standard,
using a modified template, and using a hook function. Cmndlg displays
"Hello World" in a window, and allows the user to change the text
and colors, etc.
- consolec: The consolec sample demonstrates the use of the SetConsoleTxtAttribute
and GetConsoleScreenBufferInfo APIs to set or get the console text color attributes. This
is a console application that is linked against dfwin.lib. If no arguments are passed to
consolec, it prints out a color sample in a command window. The arguments are FOREGROUND
color and BACKGROUND color, and the valid options are BLACK, BLUE, GREEN, CYAN, RED,
MAGENTA, YELLOW or WHITE. The color argument passed must be in uppercase, or an error
will be output.
- crypto: The crypto sample demonstrates using the Cryptography API to encrypt and
decrypt files.
- cursor: The cursor sample demonstrates how to manipulate a cursor and select a
region. It uses the Windows interface to manage the GUI. The program will either let the
user draw boxes (regions) or will calculate 1027 prime numbers when RETURN is entered.
During that calculation, the cursor is turned into an hourglass.
- drives: The drives sample determines all drives on the system, both local and
remote, and determines their file system type. This is a console application that links
against dfwin.lib.
- event: The event sample demonstrates the basic concepts involved when using
asynchronous I/O. It reads one file asynchronously and writes another synchronously.
This is a console application that links against dfwin.lib and requires two arguments, the
input file and output file. This executable transfers one file to another. Refer to the
readme.txt for information on how to set it up in the Developer Studio.
- exitwin: The exitwin sample demonstrates how to shut down applications. When run,
it will ask whether you want to continue, as it will log you off. Optionally, you can
compile it to reboot the system. This is a Windows application that uses Windows to
manage the GUI.
- floppy: The floppy sample demonstrates how to access a physical floppy disk
using the Win32 API set. It has two major functions:
- It can be used to display the geometry of a disk, floppy -g a:
- It can be used to produce a disk image or to write a disk image to a floppy,
floppy -c a: bootdisk (produces a disk image of a:) or floppy -c bootdisk a: (make a:
identical to bootdisk image).
This is a Fortran Console program that is linked against dfwin.lib.
- generic: The generic sample demonstrates the basic concepts required in building
a Windows application and could be used as a basis for building a first Windows program. The
specific features that generic implements are:
- Custom icon
- Standard Menu Bar
- Standard Help Menu
- Full WinHelp Support
- Keyboard Accelerator Usage
- Version Control Information
- getdev: The getdev sample demonstrates the GetDeviceCaps() API. Also,
in this sample, the main window is a dialog box, and all the interesting code is in
the window procedure for that dialog box. This is different than many of the
other Windows-based samples, which use MainWndProc to handle the events.
- getopenfilename: The getopenfilename sample demonstrates the use of
the API GetOpenFileName(). When run, it brings up a dialog box listing either
text files or Fortran files in the project directory. It also gives you the option
of opening the file read-only.
- getsys: The getsys sample demonstrates the APIs GetSysColor(),
GetSystemDirectory(), GetSystemInfo(), GetSystemMetrics(), GetSystemPaletteEntries(),
and GetSystemTime(). Also, in this sample, the main window is a dialog box, and
all the interesting code is in the window procedure for that dialog box. This is
different than many of the other Windows-based samples, which use MainWndProc to
handle the events.
- inherit: The inherit sample demonstrates inheritance of file handles
from one process to a child process. It also demonstrates the use of anonymous
pipes as stdout and stderr replacements. It contains two projects, child
and inherit. The inherit project creates inherit.exe, which can be run
without the other project. To run inherit, specify two parameters:
- Trace file to write stdout and stderr
- Command to execute
The inherit program is run within QuickWin so that it can be a "console-less"
parent. Otherwise, there are configuration problems when trying to pipe.
To use this sample, first set the current project to child and build it,
then set the current project to inherit and build it. Before you run it,
read the readme.txt file in the project; this will tell you
what changes you need to make to your project configuration in order to run
this sample.
- input: The input sample is a basic Windows application that does very
general processing on mouse button events and keyboard events. It demonstrates
how input messages are received, and what additional information comes with the
message. When run, it displays the current pointer location, whether the right
or left mousebutton was clicked, and outputs a message based on a 5 second timer.
- maskblt: The maskblt sample is intended to demonstrate masked bit block
transfers. It is unclear that it is working correctly, either in its current form,
or as received from Microsoft. However, it does demonstrate basic calls to functions
that support bitmaps and keyboard accelerators used by clipboard functions.
- MDI: The MDI sample demonstrates the multiple document interface. It
creates a simple window that can create child windows within itself. It also can
set the titles on these child windows.
- menu: The menu sample demonstrates the use of popup menus, user defined
menus and menu functions. It is a very simple program that allows you to select items
off a menu, invoke a pop-up menu, and basically do little else, but is a good example
of how to start with menus.
- mltithrd: The mltitrhd sample demonstrates the use of multiple threads. The
main routine, mltithrd.f90, has a brief guide to writing multi-threaded applications at
the top of the file. It uses the multi-document interface to create child windows, and
bounces colored traces through each one.
- output: The output sample demonstrates using TextOut() and DrawText() to
write to a window. It is a very simple sample, outputting text and a few simple
shapes, such as a rectangle, ellipse, and pie-wedge.
- owncombo: The owncombo sample demonstrates the use of functions and
messages for combo boxes and owner-draw control styles. It brings up a window
and lets you play with the different combo box styles.
- paths: The paths sample demonstrates the use of paths and clipping
regions. A path is one or more figures or shapes that are filled,
outlined, or both filled and outlined. Paths are used in various drawing and
painting applications. This sample demonstrates how 6 different types of paths can
be set up. With this release, when the application first runs, the window is too
small for the titles on the paths, and must be manually resized.
- platform: The platform sample demonstrates some very simple menu
choices, and the popup dialog boxes that you can create from them. This sample
displays "menus" that give you information about which platform you
are running on.
- plgdraw: The plgdraw sample demonstrates the PlgBlt() API. The PlgBlt
function performs a bit-block transfer of the bits of color data from the specified
rectangle in the source device context to the specified parallelogram in the
destination device context. The sample displays a rendered version of the contents
of the middle grid in the leftmost grid.
- polydraw: The polydraw sample demonstrates capturing mouse clicks
and movement, and combining that with some keyboard input (the Ctrl or Shift keys).
It is a very simple program that allows the user to draw lines, curves, and move
some points around on the screen.
- process: The process sample demonstrates creating and terminating
processes from within another program. The user interface is very simple, a
dialog box with two buttons "Create" and "Terminate", and window
with the list of created processes.
- registry: The registry sample demonstrates the Registry API. This
sample displays information from the system registry, allowing the user to
traverse the various trees. It is a fairly simple sample, but could be used as
an example.
- select: The select sample demonstrates how to manipulate a cursor and
select a region. This sample has two projects under it:
- Select, which provides a dynamic link library (dll) of routines for
selecting a region
- Demo, which contains an executable program that uses the select library above.
To use this sample, first set select as the current project and build
select.dll, then set demo as the current project to build the executable.
- setinfo: The setinfo sample demonstrates how to set the attributes of a file.
It has a simple interface, allowing the user to enter a filename in an edit field. The
GetInfo button will retrieve information about the file and display it. To set
file information, modify the values in the Time and Date edit fields, and click the
SetInfo button. To set file attributes, set the appropriate check boxes and click on
the SetAttr button.
This sample also demonstrates the use of the GetFileTime() and SetFileTime() API calls.
- sharemem: The sharemem sample demonstrates the use of named shared memory
between two independent processes. There are two projects in this sample, sharemem
and othrproc. These can be built in either order; neither depends on the other.
To use this sample, first start Sharemem, then start Othrproc. (Note, this is best done
outside of Developer Studio.) The visual effect is better if the focus remains with
Othrproc, while the mouse moves with Sharemem. A "shadow" mouse is displayed
on Othrproc with the same coordinates as the mouse on Sharemem.
- startp: The startp sample demonstrates various CreateProcess()
parameters, including starting processes in a given priority class. This is
very similar to the "start" command but with added functionality. It is best
run from outside Developer Studio, but when run from within Developer Studio,
will give usage information in a console window.
- streblt: The streblt sample demonstrates the use of the StretchBlt function.
This Block Transfer function goes beyond a simple BitBlt, giving the option of
stretching or compressing a bitmap to fit a different area in the destination
device context.
- subclass: The subclass sample demonstrates subclassing of standard
windows controls, such as button, edit field, and list box. It allows the user to
create an arbitrary number of child controls on the main window. These controls are
subclassed, and the subclass procedure provides the user a way to move and size the
controls. A menu item switches in and out of "Test Mode". When this is on,
the subclass procedure passes all message through to the standard procedure, and the
controls act just like normal.
- takeown: The takeown sample demonstrates how to give an Administrator
access to a file that has been denied to all. It must be run from an Administrator
account. There is a sample file provided named takeown.txt which
may be used by the sample.
- termproc: The termproc sample demonstrates how to terminate a process,
given its process id. Although this can be built within the Developer Studio, it
is best run from the command line.
- threads: The threads sample demonstrates suspending, resuming, and setting
the priorities of threads. The display shows two threads, red and green, which draw
paths across the window. There are menu items to suspend, resume, and set the priority
of the two threads. Caution, if the priority of one or the other of the threads is set
too high little else will run on the system.
- timers: The timer sample demonstrates the use of the SetTimer() and
KillTimer() APIs. It creates 4 rectangles on its window, each with a different and
inverts the color whenever the timer goes off. This sample demonstrates two timer
mechanisms.
- tls: The tls sample demonstrates multiple threads calling into a
single DLL. It also demonstrates the use of DLLEXPORT to export entry points from a
DLL, rather than using .DEF files. The tls sample has two projects, tlsdll
and tls. The workspace is configured such that the tls project is dependent
on the tlsdll project. If you build tls, it will automatically build tlsdll. When
running, each thread is blocked waiting for the user to click OK in a message box.
The thread may be running in a minimized window.
- virtmem: The virtmem sample demonstrates the use of various virtual
memory APIs. The sample has a main window with menu items that will modify a set
page to have different attributes. In order to write to memory, the page must be
committed and set to read/write access. Attempting to write to a read only page
will cause an access error, "memory cannot be read".
- world: The world sample demonstrates scaling and translating an image
from a metafile with world coordinate transforms. It uses the calls
SetWorldTransform() and PlayEnhMetaFile() to do the linear transformation between
world space and page space, and to play the enhanced metafile. The sample provides a
single sample metafile, sample.emf, although others could be used.
- wxform: The wxform sample demonstrates world transforms. It has three
dialog boxes that display help, track mouse movements, or allow the user to enter
transform information. The different quadrants of the screen have different
properties, as described in the help box. This sample also demonstrates using
messages to communicate between different window procedures.
Dialog Boxes (Dialog)
The Dialog samples demonstrate several of the newer dialog controls available
through Visual Fortran. There is also a sample that demonstrates how to use
modeless dialog boxes. The dialog samples can be found in the
directory ...\Df98\Samples\Dialog
:
- CelsiCon: The CelsiCon sample is a
Fortran Console application that uses a dialog box. It uses an undocumented hook
into the dialog initialization event WM_INITDIALOG. It also sets special
customizations on that dialog box by using Win32 calls. With a simple
modification to the source program, it can also be built as a QuickWin application.
- dllprgrs: The dllprgrs sample demonstrates
using the Visual Fortran Dialog Procedures in a DLL. The public routines in the DLL
can be called to:
- DisplayProgressBox – Display a dialog box containing a progress bar
- SetProgress – Set the current progress bar value
- DestroyProgressBox – Destroy the dialog box
- fxplorer: The fxplorer sample demonstrates
an SDI Fortran Windows application using the Visual Fortran Dialog Procedures.
It uses an Internet Explorer ActiveX control in the main window of the
application. The Internet Explorer control is installed with Internet Explorer.
If Internet Explorer is not installed, this sample will not run.
- mmplayer: The mmplayer sample demonstrates
a dialog-based Fortran Windows application using the Visual Fortran Dialog Procedures.
It uses an ActiveMovie control in the main window of the application. The
ActiveMovie control is installed with Internet Explorer. If Internet Explorer is
not installed, this sample will not run.
- progress: The progress sample program demonstrates
a "dialog-based" Fortran application using the Visual Fortran Dialog
Routines, including the progress bar. The main window of the application is a dialog box.
It contains Start, Stop, and Exit buttons plus a progress bar. The Start button begins
a lengthy operation that is broken into 100 steps. In this simple example, each
step is sleeping for .25 seconds.
- showfont: The showfont sample demonstrates a
"dialog-based" Fortran application using the Visual Fortran Dialog Routines.
The main window of the application is a dialog box. This program demonstrates the use
of a Tab control. The Tab control is used to select the properties of a font. The
font is used to display a sample text string.
- therm: The therm program demonstrates a
"dialog-based" Fortran application using various Visual Fortran Dialog
Routines, including several that are new to CVF V6.0. The main window of the
application is a dialog box. This program uses a Spin control, a Slider control, a
Progress bar control, and Picture controls. It also demonstrates using multiple
modeless dialog boxes.
- whizzy: The whizzy sample demonstrates many of the
controls available with the dialog manager module provided by Visual Fortran. Note
that it is built with the "Logical Values" compatibility switch set.
This is required for correct interaction with the dialog manager routines.
DLL Examples (DLL)
Within Visual Fortran you can create and use dynamically linked libraries (DLLs).
A DLL is loaded at run time by its calling modules (.EXE or .DLL). When a DLL is
loaded, it is mapped into the address space
of the calling process. There are generally two ways to bring in a DLL, either at image
activation time or at run-time. If an image is linked against the import library for a
DLL the code is mapped into the image's address space at image activation time. If the
import library is not available, the DLL needs to be mapped in with Windows API calls.
The following DLL examples can be found in subdirectories
under ...\Df98\Samples\DLL
:
- DLLEXP1: The DLLEXP1 sample demonstrates a workspace that contains
two projects: one that creates a DLL and a second that uses that DLL, linking
against the import library created by the first project. Note that for the
Fortran Console application to run, the DLL
created by the first project must be found somewhere along the PATH.
- DLLEXP2: The DLLEXP2 sample demonstrates how COMMON variables defined
in a DLL can be shared between multiple programs. Two programs are built against the
same DLL. The first program is run, and then PAUSEs. The second program
is run and changes the COMMON variables, and exits. When the first program resumes, it
displays the changed values.
- LoadExp1: The LoadExp1 sample demonstrates how to dynamically map a DLL
without using an import library. It is a workspace with two projects, one the DLL and
the other the executable that uses it.
Exception Handling (ExceptionHandling)
Visual Fortran Version 6.5 introduces some routines to make it easier for the user to control
floating-point exception handling:
- ClearFP: The ClearFP sample
demonstrates CLEARSTATUSFPQQ, a subroutine
to clear the ia32 floating-point status word exception flags.
- Cslexcp2: The Cslexcp2 sample demonstrates exception and
termination handling in a Fortran Console application.
- Cslexcp4: The Cslexcp4 sample demonstrates how to wrap a Fortran
entry point inside a C try/except block to allow testing for exceptions that
might occur in the protected Fortran code.
- GetEptrs: The GetEptrs sample demonstrates how to establish a
signal handler with SIGNALQQ (or the C signal()
function) and use the TRACEBACKQQ
and GETEXCEPTIONPTRSQQ Fortran library
routines to generate a traceback display from the handler.
- Winexcp1: The Winexcp1 sample demonstrates exception handling in
a Fortran Windows application. It was based on the GENERIC sample, with structured
exception handling (SEH) incorporated.
- VBVF1: The VBVF1 sample demonstrates exception handling in a Visual
Basic application that calls a Visual Fortran DLL. This is an ia32-only sample.
ISO Varying Strings (Isovar)
The Isovar samples demonstrate one possible implementation for the
interface to dynamic-length character strings in Fortran 95. The publicly
accessible interface defined by this module is conformant with the auxiliary
standard, ISO/IEC 1539-2: 1999. The Isovar samples are in separate directories
under ...\Df98\Samples\Isovar
and include:
- unittest: The unittest sample contains 80 small functions that test
each of the features of the ISO varying string module. Some of the features tested
are concatenation, assignment, and searching for a substring.
- vocab: The vocab sample uses the ISO varying string module to read
a text file and keep a list of each word found in the file and its frequency.
When the file is completely read, it prints out the word list and the frequency of
each word.
- wrdcnt: The wrdcnt sample uses the ISO varying string module to read
a text file and keep count of how many words are seen. When the file is
completely read, it prints out the total number of words found in the file.
Miscellaneous (Misc)
There are a number of miscellaneous samples that demonstrate some specific aspects of
Visual Fortran or its utilities. The following miscellaneous examples can be found
in separate subdirectories under ...\Df98\Samples\Misc
:
- calcaver: The calcaver sample demonstrates Fortran 90 features,
including an interface block, assumed shape array, and the use of modules.
It does have a Developer Studio workspace associated with it, or can be
built using nmake and the makefile.
- char2: The char2 sample demonstrates the use of the utility fsplit90.
This utility creates separate files for each program unit within a file. Once it
has been split, it is identical to charexmp. Build this sample using nmake.
- charexmp: The charexmp sample does some simple character handling,
generating arrays of the alphabet and outputting them to the screen. It has a
Developer Studio workspace associated with it, or it can be built using nmake.
- console: The console sample demonstrates some of the basic
console-manipulating routines. Console sets the size of the console, clears
the console, and positions the cursor to write a line at the top of the console,
and again at a line further below. A DOS command prompt is an example of a console.
- cvt_lf_unf: The cvt_lf_unf sample converts data files created with
Lahey Fortran to an unformatted binary file. There are two projects within this
sample:
- cvt_lf_unf which builds the conversion utility
- test which uses cvt_lf_unf to convert a data file created
by Lahey Fortran and then read it from CVF.
- fctrl: The fctrl sample is a very simple one, demonstrating recursion.
It is a console application, and computes and displays the factorials of the
integers 1 to 12. 13! is too big for a 32-bit integer. This sample can be built either
from within Developer Studio, or by using the makefile.
- fivt: The fivt sample is a basic Installation Verification program
for Visual Fortran. It compiles and links a program, and then reads the listing
file to make sure the expected version of the compiler was used. It can be
compiled and run from either the command line or the Developer Studio. To run
fivt from the command line, either set FORT5=FIVT.INP, or invoke it as FIVT < FIVT.INP.
To run from Developer Studio, refer to the README.TXT file in that directory.
- forprint: The forprint sample is a console application that uses the
OpenFile and Print dialog boxes to select and print text files, including files
with Fortran carriage control. Forprint preprocesses the file, generating a text
file that can be printed by any printer. This sample can be built either from
within Developer Studio or by using the makefile.
- fppdemo: The fppdemo sample demonstrates the use of the Fortran
Preprocessor, FPP. FPP is a C-like preprocessor, as opposed to the preprocessing
directives that are part of the Fortran 90 standard. It is easiest to build
using the makefile, but there is a Developer Studio workspace for it. This workspace
has 5 projects, one per variation of fpp defines. It illustrates how to pass fpp flags
to the compiler from the Developer Studio; it must be done by hand from within the
Settings dialog box.
- mandel: The mandel sample demonstrates a simple Win32 application with a
C main program calling a Fortran subroutine.
- uopen: The uopen sample demonstrates the use of the USEROPEN keyword
from the OPEN statement. In this particular example, the Fortran file calls
a C program to do the specialized OPEN.
- lcinfo: The lcinfo sample demonstrates the use of NLS routines to support
some natural language extensions. It also demonstrates how the string order is
affected by choice of natural language. The lcinfo sample is a console application
that prints out information about what the different language and currency settings
are on the computer.
Mixed-Language (Mixlang)
Visual Fortran can be called by a number of other languages, including Visual C/C++, Visual
Basic, and MASM (Assembler). Also, it can call other languages, such as C/C++. The
following samples in subdirectories under ...\Df98\Samples\Mixlang
demonstrate some of the calling standards or argument definitions
that must be used to effectively interwork with other languages:
- c_call_f: The C_Call_F sample demonstrates a mixed-language application in
which a C (or C++) main program calls a Fortran subroutine. It is presented in two
different styles; one where the Fortran and C code are built together in the same
project and one where the Fortran code is built separately into a DLL which is then
called from C. This sample also demonstrates how to pass character/string arguments
to Fortran.
- delphi: This ia32-only sample demonstrates various interactions
between Visual Fortran and BorlandTM Delphi. Delphi
must be installed to build and run this sample:
- CallDVF: The CallDVF sample demonstrates calling Fortran from Delphi.
There are examples of an integer function, a REAL function, and a character
function.
- spline: The spline sample demonstrates mixed language programming with
Visual C/C++. Spline is easiest built from within Developer Studio. The project
contains four projects, Console, QuickWin, VC, and spldll. The last
project, spldll, creates the dll file used by the other projects.
The spline sample implements a "best fit curve" algorithm to a set of
coordinates. The coordinates are input by clicking on a window or through a data file.
Each of the first three projects within this workspace create a different program,
using different paradigms:
- Console creates an application that runs in a console window and takes input
from a data file, fsplit.dat
- QuickWin creates an application using the QuickWin interface that takes
input from mouse clicks.
- VC creates an application using Visual C/C++ and the Microsoft Foundation
Classes that takes input from mouse clicks.
This workspace and its projects also demonstrate one method of dealing with
interproject dependencies. It copies the dependent .DLL file to the local
directory before linking and running the project.
- vb: This set of samples demonstrates various interactions between Visual
Fortran and Visual Basic (VB). In all cases, there is an executable that is the
VB program which you can run. There is also the VB Project, as well as the Visual
Fortran project available so you can modify them as you wish:
- arrays: The arrays sample demonstrates how to pass arrays of
strings from VB to CVF
- callback: The callback sample demonstrates how to invoke VB
callback routines passed to a CVF subroutine
- returnstring: The returnstring sample demonstrates how to
call a Fortran character string function from Visual Basic.
- simple: The simple sample shows very basic interactions between
Visual Fortran and VB, passing numbers from one to the other
- typearrays: The typearrays sample demonstrates how to pass an
array of user-defined types from VB to Visual Fortran, including how to
write into some fields of that type from within the Fortran routine.
- MASM: This set of ia32-only samples demonstrates various
interactions between Visual Fortran and MASM, Microsoft's Assembly Language.
MASM must be installed to build these samples:
- simple: The simple sample demonstrates the most simple call from
Fortran to MASM.
- vecprod: The vecprod sample demonstrates how to calculate the
inner product of two vectors in a MASM program. These two vectors were passed
from Fortran to MASM, and the result was passed back to the Fortran main
program.
- allocabl: The allocabl sample is a rewrite of vecprod using
allocatable arrays rather than static ones.
QuickWin (Quickwin)
Visual Fortran provides a library of routines called QuickWin. QuickWin is a
library that lets you build applications with a simplified version of the Windows interface
with Visual Fortran. The QuickWin library provides a rich set of Windows features, but it
does not include the complete Windows Applications Programming Interface (API). If you need
additional capabilities, you must set up a Windows application to call the Win32 API directly
rather than using QuickWin to build your program. The following samples demonstrate how to use
QuickWin, and how to program around some of the strange paradigms of the package.
The following QuickWin examples can be found in subdirectories under ...\Df98\Samples\QuickWin
:
- calendar: The calendar sample is a simple QuickWin
application. It displays a graphical monthly calendar for the current month.
- chaos: The chaos sample is a QuickWin application that demonstrates the
use of menus, dialog boxes for input and output, message boxes for the signaling
of error states, various ways of recovering from error conditions and still keep
the program running, QuickWin graphics routines, multi-threading, and Fortran 90.
There is a document in the CHAOS subdirectory, README.TXT, that describes this program
and its algorithms in more detail.
- cleanwin: This sample illustrates how to use native Windows APIs to
radically change the appearance of a standard QuickWin window.
- conapp: This sample demonstrates a method for creating a console
window from within a QuickWin application. The sample has two parts: a DLL which
creates the console window and performs I/O to or from it, and a QuickWin program
that calls that DLL. To allow the DLL to access the console using units *, 5, and 6,
this sample uses a technique not recommended for any other use. The DLL is linked
against the Fortran dynamic-link libraries, but the QuickWin application is linked
against the Fortran static libraries. Generally this is discouraged, because using
the two different libraries means that the main program and the DLL cannot share I/O
units. In this case, that is the intended outcome.
- dirkeys: This sample demonstrates a mechanism for passing directional
keys from QuickWin to the user's program.
- dirkeys2: This sample illustrates the use of a callback procedure (hook)
using SetWindowsHookEx for keyboard events. It demonstrates how to get around the
limitations of the PASSDIRKEYS routine, specifically how to trap for Insert, Delete,
and Ctrl-C keys.
- dirkeys4: This sample demonstrates the PASSDIRKEYSQQ routine.
The PASSDIRKEYSQQ routine allows easy access to the Insert, Delete, and Ctrl-C keys.
- menudriv: This sample illustrates three programming idioms for use in
QuickWin applications. These are: using the menu to drive various functions;
getting control on EXIT; using the status bar to indicate program progress.
- peekapp: This multi-threaded sample simulates a compute loop with
Peekchar and Getchar to handle input as it comes in character by character.
It is intended to be used within a QuickWin program.
- peekapp3: This multi-threaded sample is similar to peekapp, but
contains a procedure to perform an orderly shutdown on the character-reading thread.
- poker: The poker sample demonstrates the use of QuickWin and some simple
controls on the window. This sample uses QuickWin to manage the windowing interface,
but uses some of the Win32 API calls, and must be linked against dfwin.lib. It should
be mentioned that the file CARDS.F90 takes a longer time to compile than any of the o
ther files that make up the poker sample. Also, before building, you should make sure
you update all dependencies, as there are many.
- postmini: The Postmini graphical postprocessing software can be used
to examine the output of a number of process, device and circuit simulation (TCAD)
programs, as well as import data from ASCII files. This version of PostMini uses
QuickWin for the graphical interface. Other versions are available for
Compaq Tru64 UNIX and OpenVMS Alpha that use other graphical interfaces. Refer
to the README file in the PostMini directory for details on this sample.
- qwpaint: The qwpaint sample demonstrates using mouse callbacks and graphics
routines in a QuickWin application. It has two windows, a "control grid"
window and a "canvas" window. QuickWin's built-in File.Save option can be used
to save the contents of either window as a bitmap (.BMP) file.
- qwpiano: The qwpiano sample demonstrates using mouse callbacks and menu
callbacks in a QuickWin application. It draws a graphical piano keyboard on the
screen that can be played using the mouse. It should be noted that two compatibility
options, "Logical Values" and "Filenames from Command Line" are set
for this sample. The former affects interacting with the QuickWin routines, and the
latter causes a File dialog box to come up in response to an OPEN request.
- Resize: The resize sample demonstrates how to use Win32 API calls from
within a QuickWin application to correctly size the information to be displayed
to a QuickWin window.
- testscrl: The testscrl sample demonstrates how to scroll to the last
line of a window that has scroll bars. It also shows how to make a window without
scroll bars.
Scientific Graphing Utility (SciGraph)
SCIGRAPH is a package of Fortran routines for drawing scientific graphs. Graph types
available include line, bar, XY, and pie graphs. All graphs are fully customizable, including
control over axis, log scales, data points, colors and
shades, error bars, and many other aspects of a scientific graph. All graphs are drawn using
Visual Fortran's QuickWin graphics routines, so they can be easily added to
an already existing QuickWin application.
The SciGraph package can be found in ...\Df98\Samples\SciGraph
:
- scigraph: The SciGraph sample offers a starting scientific graphing package
to support some basic forms of graphs. There are two projects in this sample:
- Scigraph, which creates a library and some .MOD files
- Sgdemo, which creates a program to demonstrate some of the basic forms of graphs
Build the Scigraph project first, followed by Sgdemo. Note that the output area
for the SCIGRAPH.LIB project is included as a path to find .MOD files.
There is a .WRI file in the SCIGRAPH directory that contains basic reference
information on the various SciGraph calls, including a list of error returns
and possible causes.
A known limitation of SciGraph is directly related to the known QuickWin limitation
of 256 colors on the graphics device. This limitation shows itself when trying to
print or save as a bitmap file; only a black screen is printed or saved.
Tutorial
All Tutorial samples are simple programs, and most of them are standalone. Each contains
compilation information at the top of the file, both for command line and from within
Developer Studio. If there are multiple files, this is noted at the top of the program.
All tutorial samples can be found in the directory ...\Df98\Samples\Tutorial
:
- assocn: The assocn sample illustrates the non-associativity of
floating-point addition.
- cycle: The cycle sample illustrates the Fortran 90 statements CYCLE and
EXIT.
- derived: The derived sample demonstrates a derived type structure, type
variables, and assign values.
- dtypearg: The dtypearg sample demonstrates the use of SEQUENCE
to allow passing a derived-type argument.
- dtypecom: The dtypecom sample demonstrates placing derived-type
objects in COMMON blocks.
- dtypemod: The dtypemod sample demonstrates the use of a module to allow
passing a derived-type argument. It also shows WRITE of a derived-type.
- epsilon: The epsilon sample illustrates several calculations of machine
epsilon.
- internal: The internal sample illustrates the use of an internal
subroutine and the CONTAINS statement.
- interval: The interval sample demonstrates the use of rounding control.
This sample must be compiled without optimizations.
- keynames: The keynames sample demonstrates the Fortran concept of using
a type structure and a subroutine defined within a module. This sample also
requires NAME_SSN.F90 to build.
- matherr: The matherr sample demonstrates handling run-time math
exceptions. This sample is not a standalone application, but can be included
in other programs.
- mathtest: The mathtest sample uses matherr above to demonstrate the
response to error conditions on intrinsic math calls. It uses the MATHERRQQ
subroutine in MATHERR.F90.
- mbcomp: The mbcomp sample demonstrates the use of the National
Language Support (NLS) routines.
- namelist: The namelist sample demonstrates the NAMELIST Statement.
- percent: The percent sample demonstrates a user-defined operator,
in this case a unary operator .c. that converts a floating point number to
a "percentage".
- pointer: The pointer sample demonstrates allocating and deallocating
pointers and targets.
- pointer2: The pointer2 sample demonstrates pointing at a pointer and
target, and the use of the ASSOCIATED intrinsic.
- realg: The realg sample demonstrates using coordinate graphics. This
sample uses the QuickWin package to display to the screen.
- recurs: The recurs sample is a very simple demonstration of a
recursive subroutine.
- showfont: The showfont sample uses QuickWin to display a variety of
fonts. This sample demonstrates various calls to QuickWin.
- sigtest: The sigtest sample demonstrates user-defined exception handlers.
It shows how to establish the name of the exception handler as the function to be
invoked if an exception happens.
- sine: The sine sample demonstrates the use of QuickWin to output
sine waves and some simple shapes.
- testget: The testget sample illustrates the use of internal READ to
convert from REAL to CHARACTER. This is best run from outside of Developer Studio,
and can be built simply by df testget.f90.
- threads: The threads sample demonstrates multiple threads with QuickWin.
It is a much simpler program than advanced\win32\bounce, but is not as efficient at run
time.
- unclear: The unclear sample demonstrates the use of generic module procedures.
A generic procedure called "dup" has three instances; one with real arguments,
one with integer arguments, and one with character arguments.
- where: The where sample demonstrates the Fortran 90 constructs
WHERE and ELSEWHERE.