Fortran Compiler Compatability

Q&A for Fortran developers using DPlot

Moderator: DPlotAdmin

Post Reply
milo
Posts: 5
Joined: Tue Mar 09, 2004 2:32 pm

Fortran Compiler Compatability

Post by milo »

I can confirm that the sample source FTEST.FOR will work properly without changes with the latest version of Open Source WATCOM Fortran, namely version 1.2.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Thanks for the confirmation. It has been a while since I looked at Open Source WATCOM... did you see this note in the source:

c 3) This source code will work properly without changes with Open Source WATCOM Fortran 1.0. HOWEVER,
c the supplied import library (DPLOTLIB.LIB) will NOT work with that compiler. To build FTEST with
c Open Source WATCOM Fortran, first delete the import library DPLOTLIB.LIB, then build a new one
c using the WATCOM library tool WLIB.EXE:
c
c wlib dplotlib +dplotlib.dll

... and was this necessary for version 1.2 or not?
Visualize Your Data
support@dplot.com
milo
Posts: 5
Joined: Tue Mar 09, 2004 2:32 pm

Post by milo »

I had taken note of the information you provided in the source. Having built a new library for version 1.1, I simply proceeded to do the same with the release of version 1.2. I did not have any problems in either case.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Thanks for the info.
Visualize Your Data
support@dplot.com
milo
Posts: 5
Joined: Tue Mar 09, 2004 2:32 pm

Post by milo »

Just completed test of a Win32 Fortran 95 program using Salford FTN95 Compiler, Version 4.7.1. Obtained compatability using Salford's external C/C++ routine and DPLOTLIB.DLL. The routine C_EXTERNAL name ['alias'][(desc)][:restype] allows for the case sensitive call to the external name Dplot_Plot.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Thanks... this is weirdly timely, as I just downloaded Salford FORTRAN yesterday and worked a few things out last night. Another user had much earlier sent me example source meant for Salford FORTRAN, but w/o being able to test it I didn't feel comfortable including it in the distribution.

You'll find that C_EXTERNAL isn't quite right. That uses normal C calling conventions (caller responsible for removing arguments from the stack) rather than STDCALL (called function removes arguments from the stack). What you'll get with C_EXTERNAL is everything works right until after you return from calling DPlot_Plot (or whatever) the first time. Subsequent calls may crash your program or may simply produce goofy looking plots.

I'll be including a Salford FORTRAN example in the next release - most likely within the next few days. In the meantime, the correct interface for all existing DPLOTLIB functions is:

Code: Select all

c
c Interface to DPLOTLIB functions
c
      STDCALL DPLOT_3DBORDER 'DPlot_3DBorder' (VAL, VAL, REF): INTEGER*4
      STDCALL DPLOT_ADDDATA 'DPlot_AddData' (VAL, VAL, VAL, VAL,
     &                          REF, REF): INTEGER*4
      STDCALL DPLOT_ADDDATA8 'DPlot_AddData8' (VAL, VAL, VAL, VAL,
     &                          REF, REF): INTEGER*4
      STDCALL DPLOT_COMMAND 'DPlot_Command' (VAL, INSTRING): INTEGER*4
      STDCALL DPLOT_GETBITMAP 'DPlot_GetBitmap' (VAL, VAL, VAL):
     &                          INTEGER*4
      STDCALL DPLOT_GETBITMAPEX 'DPlot_GetBitmapEx'
     &                          (VAL, VAL, VAL, REF): INTEGER*4
      STDCALL DPLOT_GETENHMETAFILE 'DPlot_GetEnhMetaFile'
     &                          (VAL, VAL, VAL): INTEGER*4
      STDCALL DPLOT_GETVERSION 'DPlot_GetVersion' (OUTSTRING): INTEGER*4
      STDCALL DPLOT_PLOT 'DPlot_Plot' (REF, REF, REF, INSTRING):
     &                          INTEGER*4
      STDCALL DPLOT_PLOT8 'DPlot_Plot8' (REF, REF, REF, INSTRING):
     &                          INTEGER*4
      STDCALL DPLOT_PLOT8P 'DPlot_Plot8p' (REF, VAL, VAL, INSTRING):
     &                          INTEGER*4
      STDCALL DPLOT_PLOTBITMAP 'DPlot_PlotBitmap' (REF, REF, REF,
     &                          INSTRING, VAL, VAL): INTEGER*4
      STDCALL DPLOT_PLOTBITMAP8 'DPlot_PlotBitmap8' (REF, REF, REF,
     &                          INSTRING, VAL, VAL): INTEGER*4
      STDCALL DPLOT_PLOTTORECT 'DPlot_PlotToRect' (REF, REF, REF,
     &                          INSTRING, VAL, REF): INTEGER*4
      STDCALL DPLOT_PLOTTORECT8 'DPlot_PlotToRect8' (REF, REF, REF,
     &                          INSTRING, VAL, REF): INTEGER*4
      STDCALL DPLOT_REQUEST 'DPlot_Request' (VAL, INSTRING, OUTSTRING,
     &                          REF): INTEGER*4
      STDCALL DPLOT_SETERRORMETHOD 'DPlot_SetErrorMethod' (VAL)
      STDCALL DPLOT_START 'DPlot_Start' (VAL, REF): INTEGER*4
      STDCALL DPLOT_STOP 'DPlot_Stop'
      STDCALL DPLOT_ZFROMXY 'DPlot_ZFromXY' (VAL, VAL, VAL, REF):
     &                          INTEGER*4
Visualize Your Data
support@dplot.com
milo
Posts: 5
Joined: Tue Mar 09, 2004 2:32 pm

Post by milo »

I take note of what you say, namely:"You'll find that C_EXTERNAL isn't quite right. That uses normal C calling conventions (caller responsible for removing arguments from the stack) rather than STDCALL (called function removes arguments from the stack). What you'll get with C_EXTERNAL is everything works right until after you return from calling DPlot_Plot (or whatever) the first time. Subsequent calls may crash your program or may simply produce goofy looking plots. ". I have not had, however, any problems with repeat calls of the examples that create the 4 sample plots in the Fortran 95 "test" program that I used.

I did have problems with a Fortran 77 code that used an include file and with a DPLOT structure that is created using a common block. The Fortran 95 code uses modules. In any event, will test the sample which you are making available in the current distribution.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

I have not had, however, any problems with repeat calls of the examples that create the 4 sample plots in the Fortran 95 "test" program that I used.
I don't have a good explanation for that, unless it is that there's a compiler switch that self-corrects the stack pointer. In any case STDCALL is definitely the correct convention to use.
Visualize Your Data
support@dplot.com
milo
Posts: 5
Joined: Tue Mar 09, 2004 2:32 pm

Post by milo »

The sample problem you provide with the latest release eliminates the problem that I experienced with the Fortran 77 test case.

I should have added that the Fortran 95 test case sets up the Dplot stucture prior to each call to Dplot_Plot and uses allocatable arrays in each of the four examples for the data generated. Their rank has been specified when they are declared but their bounds, within the case construct, are defined with an allocate statement at the commencement of each "case" and deallocated prior to the end of each "case". In other words, fresh storage is established prior to each call to Dplot_Plot and discarded prior to a subsequent call. As a consequence, the problem, to which you make reference, does not occur in the Fortran 95 test case.
Post Reply