TweetFollow Us on Twitter

Volume Number:9
Issue Number:6
Column Tag:Jörg's Folder

Plotting Packages for Fortran

Inspecting TSI Graphics and SuperPlot

By Jörg Langowski, MacTech Magazine Regular Contributing Author

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Sorry to say for you C++ and Forth lovers, my desk recently gets swamped with goodies from both main players in the Macintosh Fortran game. Absoft has just sent a big parcel with version 3.2 of MacFortran II. Now, the deadline is again approaching in giant leaps, and I have no time to review it for this column; but I promise you a detailed overview in the next one. Here I’ll only mention that Absoft Fortran’s Macintosh run time environment - one of the main shortcomings of previous versions - has finally been improved. Apple Events are supported, as is publish/subscribe, you can use multiple windows, change fonts, change menus, etc. Just from looking at the manual it seems that they offer as many possibilities as LS Fortran, if not more. First tests with the Linpack benchmark indicate that the speed it still about the same (on my old MacII), which means the usual 20-30% faster than LS Fortran (I guess the compiler that makes my MacII turn as fast as a Cray still has to be invented). So stay tuned for a review.

TSI Graphics

Unless you are content with interfacing your Fortran output to a spreadsheet (you saw in the last column how that goes), you might have struggled with writing your own code for graphing the results of a Fortran program. If you have done that, you know how much time you can waste reinventing the wheel. Because there are good plotting libraries around, and one of them is TSI Graphics (Techno-Sciences Inc., 10001 Derekwood Lane, Suite 204, Lanham, MD 20706; phone (301) 577-6000). Language Systems is promoting this package, which works with their Fortran and contains some very powerful tools.

TSI Graphics does several things that are quite tedious to implement if you do it on your own. First of all, it creates one or several - automatically updated - graphics windows. Each window can contain several plot regions in which to display your data. The beautiful thing is that plots created using the TSI plotting routines are automatically adjusted to fit into the active plot area, so you don’t have to worry about setting the length of an axis, the rectangle of a frame, etc. If you have written code that plots correctly in a certain region, the plot will still have the same aspect when you resize the plot area.

The types of plots that are possible are line, bar, pie, X-Y, contour, and 3D mesh surface plots. You can add error bars to plots, create cumulative plots from groups of data, of course use linear or logarithmic scales, set the ranges of the plot axes automatically, label the plot with text in the font, size and style you want, print the plot or save it to a file, and plot in any color (using your own color tables). In fact, you have most of the functions available that a good data graphing program will give you, including the possibility to offset slices of a pie chart to emphasize them. I found one important feature missing - you cannot draw dashed or dotted lines, or change the line thickness. For the rest of us who does not have color printers available, this would be a very important addition - the only way you can distinguish line plots on a black-and-white printer so far is by adding symbols to data points. Adding different line styles to version 2.0 is strongly suggested.

Let us now see how TSI graphics does its work. For the example program, I have chosen the contour plot and the 3D mesh plot, both things you wouldn’t wish you had to write your own code for. We create a 2-dimensional data array and display it both ways in one window, using two different plot areas. The function we plot is

z = 10.0 * exp (-r/5.) * sin(r/2.) *  cos(2.*atan2(x,y))

where r is the distance from the origin x=0, y=0. The output of the program (see listing) is shown in Figure 1.

Fig. 1: Output of the plot program

How is TSI Graphics used? The example shows that you first call a setup routine, InitGraphicsPackage(), set the size of the output window, and then, after creating the data, call the actual plotting routine DrawInNewWindow. This last routine takes one parameter, a pointer to a subroutine that does the drawing. All this happens in the main Fortran program; as you know if you are familiar with the LS Fortran environment, the main program is often used only for setup purposes. After the main program has exited, the run time environment lets you call subroutines to do the actual work by connecting them to menu items. TSI Graphics works closely connected to this LS Fortran run time environment and hooks itself into the main event loop (at least I think so, I haven’t analyzed the code), so that update events to the graphics window are intercepted and the drawing subroutine is called, even after the main program has exited.

This gives you the advantage that you can easily write very modular code. You define your graphics window(s) with the associated drawing routines and your menus with the routines that do the calculation in the main program, and then exit to the run time environment. Then you can initiate your calculations from the menus, change the data that is to be plotted, and have the graphics window automatically update itself (assuming you have written the plotting subroutine so that it takes into account the changed data correctly). Even if you resize the graphics window, all plot areas will be recalculated to fit into the new window.

Look at the example again: all drawing is done through the routine CreatePlot, which receives its parameters through a common block (you can’t pass subroutines with parameters as arguments to other subroutines in Fortran). The first part of the drawing routine creates the 3D mesh plot. Two plotting areas are defined in the window: the two calls to SetPercentPlotRegion define the left and right halves of the window as plotting areas 1 and 2. The coordinates of the areas are given in percent of the total window height and width. We then set the plotting area to 1 (the left half), and inset the plot by 10% from each side of the area (the call to SetPlotRatio). The rectangle to be displayed in the mesh plot goes from -10 to +10 in both x and y directions (the call to Set3DViewingRect), and we look at this rectangle from a certain point in space (the call to Set3DEyePosition). After these setup calls, we are ready to call MeshPlot, which gives us the complicated plot that you see in the left half of the figure, and label it with some text.

The contour plot is then created by the second half of the program. We set the new plotting area, define the x and y scaling (both from -15 to 15), and draw axes on all four sides of the plot. Then we call ContourPlot and are done! You see the result in the right half of the figure. Quite impressive, and I challenge you to write such a routine yourself, you’ll spend a lot of time on it.


Another philosophy for displaying data is followed by a plotting package that is compatible with both Language Systems and Absoft Fortran: SuperPlot. It is available through SuperSoft, 498 E Robin Rd., Orem, UT 84057, (801) 225-4356. SuperPlot is at an intermediate position between choosing a separate graphing program like Excel for displaying the Fortran data, and an integrated plotting library like TSI Graphics. When you link the SuperPlot routines into your Fortran application, the program behaves as if you had a complete 2D plotting application embedded within your program. When you invoke SuperPlot it replaces the application’s menu bar with one of its own and, once the plot has been drawn, it allows you to edit, save or print the graph, change the axis scaling, line size and styles, add arrows or text, etc. You have to select “Quit to application” from SuperPlot’s menu bar to return control to the FORTRAN program. Multiple calls to SuperPlot can be made from a single program and up to 10 sets of data may be overlaid on the same graph.

In my opinion, SuperPlot is not so much for writing Fortran programs for general distribution (except if you write a general-purpose graphing program, in which case SuperPlot has already done most of the job), but for the research/engineering type user who has to display data from a program and wants to do so without having to save the data first, open a graphics program, read the data in, create the graph etc. If you write a program in which a graphics window is an integral part of the application and the graphics output needs to be updated without user intervention, you need TSI Graphics. Also, the contour and 3D mesh plot options are very powerful and not available in SuperPlot. On the other hand, for creating nicely-looking black and white graphs, SuperPlot is much superior (of course it can do color, too), allowing you to do dashed lines of varying thickness and easily change the plot style without having to recompile the Fortran program.

Next month - a review of Absoft Fortran (as promised), and more.

Example: Window with double plot area, containing a contour and a 3D mesh 

      Program JLDemo
      External CreatePlot
      INTEGER maxContourX, maxContourY
      REAL XYZdata(31,31)
      integer contourColors(128)
      Common /theData/ XYZdata, contourcolors 

!Initialize TSI Graphics
      Call InitGraphicsPackage()

!Create data and load into XYZdata array
      CALL createData(XYZdata)

!Change Output window 
   Call SetOutputGraphWindowSize (20,20,600,300)
!Create a graphics window and hook up our subroutine
      Call DrawInNewWindow(CreatePlot)

!Move the FORTRAN text window off-screen
      Call MoveOutWindow(10,800,200,900)

!Exit and let the FORTRAN menus take over
      Subroutine CreatePlot
   include ''
      INTEGER i
      REAL XYZdata(31,31)
      integer contourColors(128)
      Common /theData/ XYZdata, contourcolors 

!Set the contour colors
      DO i = 1, 128
        contourColors(i) = mod(i, 7)
      END DO

!Define two plot windows for the contour plot 
!and the 3D plot
      CALL SetPercentPlotRegion(1, 0.02,0.05, 0.48,0.95)
      CALL SetPercentPlotRegion(2, 0.52,0.05, 0.97,0.95)

!3D mesh plot
      CALL ChangePlotRegion(1)
      CALL SetPlotRatio(1, 0.1, 0.1, 0.1, 0.1)

!Set the size of the viewing rectangle
      Call Set3DViewingRect(-10.0,-10.0,10.0,10.0)

!Set the view point location
      Call Set3DEyePosition(15.0, 7.5, -10.0)

!Create the plot using a blue outline and yellow fill
      Call SetColor(blue)
      Call MeshPlot(XYZdata, 31, 31, -15., -15., 
 1.0, 1.0, yellow)

!  Switch to black and label the mesh using 
!18pt Palatino Bold-Italic
      Call SetColor(black)
      Call SetTextStyle('Palatino', 1+2, 0, 12)
      Call LabelGraph(500.0, 900.0, 
 'exp(r/5)sin(r/2)cos(2*phi)', 1, 0)

!Select region for the contour plot
      CALL ChangePlotRegion(2)
      CALL SetPlotRatio(2, 0.1, 0.1, 0.1, 0.1)

!Set plotting range scale 
      CALL SetXYPlottingRange( -15.0, -15.0, 15.0, 15.0)

!Change to black and draw axes
      CALL SetColor(black)

!Manually draw and label the lower pair of axes
      CALL SetXYIntercepts(-15.0,-15.0)
      CALL DrawYAxis(0.5,1)
      CALL LabelYAxis(10, 1)
      CALL DrawXAxis(0.5,1)
      CALL LabelXAxis(10,1)

!Manually draw and label the upper pair of axes
      CALL SetXYIntercepts(15.0,15.0)
      CALL DrawYAxis(0.5,0)
      CALL LabelYAxis(10,0)
      CALL DrawXAxis(0.5,0)
      CALL LabelXAxis(10,0)

!Border the plot area
      CALL BorderPlotRegion(black)
!Plot the data
      CALL ContourPlot(XYZdata,31,31,-15.0,-15.0, 
 1.0,1.0, 1.0,contourColors)


      SUBROUTINE CreateData(XYZdata)
      INTEGER i,j
      REAL x,y,z,r
      REAL XYZdata(31,31)

!The subroutine for creating the data
      DO i = 1, 31
         x = REAL(i-16)
         DO j = 1, 31
             y = REAL(j-16)
  r = sqrt(x*x+y*y)
             z = 10.0 * exp (-r/5.) * sin(r/2.) *  
             XYZdata(i,j) = z
         END DO
      END DO

Apple Inc.
Microsoft Corpora
Google Inc.

MacTech Search:
Community Search:

Software Updates via MacUpdate

ForeverSave 2.1.3 - Universal auto-save...
ForeverSave auto-saves all documents you're working on while simultaneously doing backup versioning in the background. Lost data can be quickly restored at any time. Losing data, caused by... Read more
Voila 3.8.1 - Capture, annotate, organiz...
Voila is a screen-capture, recording, and annotation tool that is a full-featured replacement for Mac's screen-capture and screen-recording capabilities. It has a large and robust set of editing,... Read more
SyncTwoFolders 2.0.6 - Syncs two user-sp...
SyncTwoFolders simply synchronizes two folders. It supports synchronization across mounted network drives and it is a possibility to run a simulation showing in a log what will be done. Please visit... Read more
Duplicate Annihilator 5.1.1 - Find and d...
Duplicate Annihilator takes on the time-consuming task of comparing the images in your iPhoto library using effective algorithms to make sure that no duplicate escapes. Duplicate Annihilator detects... Read more
Cobook 3.0.7 - Intelligent address book....
Cobook Contacts is an intuitive, engaging address book. Solve the problem of contact management with Cobook Contacts and its simple interface and powerful syncing and integration possibilities.... Read more
StatsBar 1.9 - Monitor system processes...
StatsBar gives you a comprehensive and detailed analysis of the following areas of your Mac: CPU usage Memory usage Disk usage Network and bandwidth usage Battery power and health (MacBooks only)... Read more
Cyberduck 4.6 - FTP and SFTP browser. (F...
Cyberduck is a robust FTP/FTP-TLS/SFTP browser for the Mac whose lack of visual clutter and cleverly intuitive features make it easy to use. Support for external editors and system technologies such... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
Evernote 6.0.1 - Create searchable notes...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
calibre 2.11 - Complete e-library manage...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital... Read more

Latest Forum Discussions

See All

RuPaul’s Drag Race: Dragopolis 2.0 is C...
RuPaul’s Drag Race: Dragopolis 2.0 is Coming to iOS December 4th Posted by Jessica Fisher on November 24th, 2014 [ permalink ] So Much Drama | Read more »
The Sandbox EDU Review
The Sandbox EDU Review By Nadia Oxford on November 24th, 2014 Our Rating: :: COME PLAY IN THE SANDBOX AGAINUniversal App - Designed for iPhone and iPad Like its predecessor, The Sandbox EDU offers lots for players to see, do, and... | Read more »
Taichi Panda Hits iOS in December
Taichi Panda Hits iOS in December Posted by Jessica Fisher on November 24th, 2014 [ permalink ] Snail Games has released the first official game play trailer for  | Read more »
Five Apps to Make Your Thanksgiving Plan...
Thanksgiving is nearly upon us! You know what that means? Eating too much turkey, watching the Big Game, and spending time with family (whether you like it or not). Oh, and that scary Black Friday thing, but we won’t talk about that here. For those... | Read more »
Kingdom Rush Origins HD Review
Kingdom Rush Origins HD Review By Jennifer Allen on November 24th, 2014 Our Rating: :: JUST AS GOOD AS BEFOREiPad Only App - Designed for the iPad It’s more of the same again, but that’s really no bad thing at all.   | Read more »
Skylanders, Show Off How You Fight Kaos...
Skylanders, Show Off How You Fight Kaos to Win Cool Prizes Posted by Jessica Fisher on November 24th, 2014 [ permalink ] iPad Only App - Designed for the iPad | Read more »
Mark of the Dragon – Tips, Tricks, and S...
Calling All Dragon Riders: | Read more »
Playdek has Annouced a Delicious Thanksg...
Playdek has Annouced a Delicious Thanksgiving Sale Posted by Jessica Fisher on November 24th, 2014 [ permalink ] Playdek, makers of | Read more »
Pair Solitaire Review
Pair Solitaire Review By Jennifer Allen on November 24th, 2014 Our Rating: :: ADDICTIVE. SO ADDICTIVEUniversal App - Designed for iPhone and iPad Welcome to your new ‘five more minutes, oh no, why is it dark outside’ addiction.   | Read more »
DryGin Studios Release a Free-to-Play Ve...
DryGin Studios Release a Free-to-Play Version of Bio Inc Posted by Ellis Spice on November 24th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »

Price Scanner via

Jumptuit Launches One-Tap Windows 8.1 iTunes...
Jumptuit has launched Windows 8.1 support for One-Tap iTunes Sync. with which Windows 8.1 users can now easily sync their iTunes libraries with Microsoft OneDrive. Jumptuit provides easy access from... Read more
CEA Study Finds More People Recycling Electro...
A new study by the Consumer Electronics Association (CEA) finds that electronics recycling receives the continued and growing support of consumers. According to the CEA,s Recycling and Reuse Study,... Read more
15″ 2.2GHz Retina MacBook Pro on sale for $17...
 B&H Photo has the 2014 15″ 2.2GHz Retina MacBook Pro on sale today for $1749. Shipping is free, and B&H charges NY sales tax only. B&H will also include free copies of Parallels Desktop... Read more
27-inch 3.5GHz 5K iMac in stock today and on...
 B&H Photo has the new 27″ 3.5GHz 5K iMac in stock today and on sale for $2299 including free shipping plus NY sales tax only. Their price is $200 off MSRP, and it’s the lowest price available... Read more
21-inch 1.4GHz iMac on sale for $979, save $1...
B&H Photo has the new 21″ 1.4GHz iMac on sale for $979.99 including free shipping plus NY sales tax only. Their price is $120 off MSRP. B&H will also include free copies of Parallels Desktop... Read more
13-inch 1.4GHz/256GB MacBook Air on sale for...
B&H Photo has lowered their price on the 13″ 1.4GHz/256GB MacBook Air to $1059.99 including free shipping plus NY sales tax only. Their price is $140 off MSRP, and it’s the lowest price for this... Read more
Save up to $400 with Apple refurbished 2014 1...
The Apple Store has restocked Apple Certified Refurbished 2014 15″ Retina MacBook Pros for up to $400 off the cost of new models. An Apple one-year warranty is included with each model, and shipping... Read more
New 13-inch 1.4GHz MacBook Air on sale for $8...
 Adorama has the 2014 13″ 1.4GHz/128GB MacBook Air on sale for $899.99 including free shipping plus NY & NJ tax only. Their price is $100 off MSRP. B&H Photo has the 13″ 1.4GHz/128GB MacBook... Read more
Apple Expected to Reverse Nine-Month Tablet S...
Apple and Samsung combined accounted for 62 percent of the nearly 36 million branded tablets shipped in 3Q 2014, according to early vendor shipment share estimates from market intelligence firm ABI... Read more
Stratos: 30 Percent of US Smartphone Owners t...
Stratos, Inc., creator of the Bluetooth Connected Card Platform, has announced results from its 2014 Holiday Mobile Payments Survey. The consumer survey found that nearly one out of three (30 percent... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Solutions Consultant (ASC)- Retail S...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager, *Apple* Financial Services...
**Job Summary** Apple Financial Services (AFS) offers consumers, businesses and educational institutions ways to finance Apple purchases. We work with national and Read more
*Apple* Store Leader Program - College Gradu...
Job Description: Job Summary As an Apple Store Leader Program agent, you can continue your education as you major in the art of leadership at the Apple Store. You'll Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.