DPlot PowerBasicConsoleCompiler Example
Posted: Mon May 17, 2004 7:56 am
I translate Absoft ProFortran DPlot example into PowerBasic ConsoleCompiler. I hope that this will be usefull for PBCC users of DPlot.
I left source fortran code as commented lines.
And the corresponding include file PBCC.INC
I left source fortran code as commented lines.
Code: Select all
'
'
' Translation of Absoft ProFortran DPlot example to PowerBasicConsoleCompiler
' << gorazd.bercic@ki.si >>
'c
'c FTEST - tests DPLOTLIB.DLL WITH Absoft Fortran
'c
'c This program has been tailored FOR Absoft Fortran. Other Fortran compilers may require
'c changes, particularly IN the interface TO DPlot_Plot.
'c
'c Things TO watch FOR WITH other compilers AND general notes:
'c
'c 1) By DEFAULT, most Fortran compilers translate the names OF ALL functions/subroutines TO UPPERCASE.
'c The NAME "DPlot_Plot" IN the DLL is CASE-specific. IN other words you will most likely encounter
'c an "unresolved external" ERROR ON DPLOT_PLOT unless you take steps TO tell the compiler NOT TO
'c fold ALL characters TO uppercase. IF you are certain that you've taken the correct steps in this
'c regard AND continue TO GET linker errors, the problem most likely lies with...
'c
'c 2) DPLOTLIB.LIB - The import library FOR DPLOTLIB.DLL. The Compaq Visual Fortran AND Absoft Fortran
'c demos use the same import library AS the C demo, which was produced AS a byproduct OF compiling
'c DPLOTLIB.DLL by the MSVC compiler. The DPLOTLIB.LIB used by the WATCOM Fortran demo was produced
'c WITH "wlib dplotlib +dplotlib.dll". This import library will almost certainly NOT work WITH other
'c compilers. IF the import library does NOT work correctly, check your compiler's documentation for
'c the method used TO produce import libraries FROM compiled DLL's.
'c
'c 3) The last parameter TO DPlot_Plot is a character STRING containing DPlot commands. This character
'c STRING must be NULL-terminated (ends IN a 0 BYTE). IF you DO NOT terminate this character STRING
'c WITH a char(0), AT best DPlot will report an ERROR IN the command STRING; AT worst DPlot AND/OR
'c this demo will crash. This restriction does NOT apply TO the character STRING members OF the DPlot
'c structure, although adding a terminating char(0) TO those strings will NOT hurt anything.
'c
' change the locations of this two include files !!!
#INCLUDE "d:\PBWIN70\winapi\win32api.inc"
#INCLUDE "d:\Down_4\dplot\dplotlib\pbCC\PBCC.inc"
DECLARE FUNCTION Ran_dom(aa AS LONG) AS SINGLE
TYPE dp_xyz
X AS SINGLE
y AS SINGLE
z AS SINGLE
END TYPE
FUNCTION PBMAIN()
' program ftest
' DEFINT i-n
' DEFDBL a-h, o-z
' implicit NONE
' STDCALL external DPlot_Plot
'*** DIM DPlot_Plot AS LONG
' real*4 Ran_dom
'***
' INTEGER*4 NP, NZ, NX, NY
DIM dp_NP AS LONG
DIM dp_NZ AS LONG
DIM dp_NX AS LONG
DIM dp_NY AS LONG
' parameter (NP=1001, NZ=1000, NX=61, NY=41)
dp_NP=1001: dp_NZ=1000: dp_NX=61: dp_NY=41
DIM dp AS DPLOT
'' record /DPLOT/ DPlot already defined in dplot.inc file
' real*4 xx, yy
DIM xx AS SINGLE
DIM yy AS SINGLE
'' record /XYZ/ Node(NZ) already defined in dplot.inc file
DIM Node(dp_NZ) AS dp_xyz
' real*4 x(NP), y(2*NP)
' real*4 extents(4)
' real*4 z(NX*NY)
' real*4 PI
' real*4 dummy
DIM x(dp_NP) AS SINGLE,y(2*dp_NP) AS SINGLE, extents(4) AS SINGLE, z(dp_NX,dp_NY) AS SINGLE, PI AS SINGLE, dummy(dp_NP) AS SINGLE
' INTEGER O_ption
' INTEGER i, j, k
' INTEGER ret
' INTEGER seed
DIM O_ption AS LONG
DIM i AS LONG, j AS LONG, k AS LONG, ret AS LONG, seed AS LONG
' character cmd*1024
DIM dp_cmd AS ASCIIZ*1024
PI = 4.*ATN(1.0)
100 REM continue
PRINT " Enter 0 to exit "
PRINT " 1 for XY plot example"
PRINT " 2 for contour plot of gridded data"
PRINT " 3 for contour plot of randomly-spaced points"
PRINT " 4 for box-and-whisker example"
' WRITE(*,*) '? '
LINE INPUT " ? ", a$
O_ption=CLNG(VAL(a$))
SELECT CASE O_ption
CASE 1
RESET dp
'c Plot SIN(PI*x) AND COS(PI*x) FROM x = 0 TO 4.
'c IN this CASE we've used DATA_XYYY (one X array for one or more Y arrays).
'c
'c Since the X values are evenly spaced we could also use
'c DATA_DXY - X has only 2 elements, DX AND X0
'c
'c AND you can ALWAYS use
'c DATA_XYXY - Each curve uses its own X array. This is the only
'c OPTION available IF the curves have different X values OR
'c a different number OF points.
FOR i=1 TO dp_NP
x(i) = (4.*i)/(dp_NP-1)
y(i) = SIN(PI*x(i))
y(i+dp_NP)= COS(PI*x(i))
' Node(i).x = (4.*i)/(NP-1)
' Node(i).y = SIN(PI*x(i))
' Node(i+NP).y= COS(PI*x(i))
NEXT
dp.Version= %DPLOT_DDE_VERSION
dp.hwnd = 0
dp.DataFormat = %DATA_XYYY
dp.MaxCurves = 2
dp.MaxPoints = dp_NP
dp.NumCurves = 2
dp.ScaleCode = %SCALE_LINEARX_LINEARY
dp.LegendX = 0.05
dp.LegendY = 0.05
dp.NP(1) = dp_NP
dp.NP(2) = dp_NP
dp.LineType(1) = %LINESTYLE_SOLID
dp.LineType(2) = %LINESTYLE_LONGDASH
dp.Legend(1) = "sin({\sp}x)"
'c {\s is DPlot-speak FOR "use symbol font"
dp.Legend(2) = "cos({\sp}x)"
'*** dp.Legend ="sin({\sp}x)" & space$(40-len("sin({\sp}x)")) & "cos({\sp}x)" +chr$(34)
dp.Title(1) = "Data sent to DPLOT via DPLOTLIB.DLL"
dp.Title(2) = ""
dp.Title(3) = ""
dp.XAxis = "x"
dp.YAxis = "y"
'c
'c The command STRING can be AS complex AS you like, limited TO 32K characters.
'c AS an alternative, IF your program will be producing many similar plots THEN
'c you might prefer TO CREATE a preferences file, edit the file WITH a text
'c editor TO remove unwanted entries, AND use the [GetPreferences("filename")]
'c command. chr$(34)=' " '
'c Note the use OF VAL(LOC()) TO GET around Absoft Fortran's default behavior
'c OF appending character STRING length TO the END OF the argument list. IF
'c you DO NOT DO this, you'll get an unresolved external error when linking.
'c
' "[Caption( "& CHR$(34) & "DPLOTLIB XY Test" & CHR$(34) & ")]" & CHR$(34) & _
' "[Color(1,255,0,0][Color(2,255,255,0]" & _
dp_cmd = "[ManualScale(0,-1.25,4,1.25)]" & _
"[TickInterval(1,0.5,0.25)]" & _
"[Color(1,255,0,0)][Color(2,100,100,30)]" & _
"[Caption(" & CHR$(34) & "DPLOTLIB XY Test" & CHR$(34) & ")]" & _
"[DocMaximize()][ClearEditFlag()]" '& CHR$(0)
ret = DPLOT_Plot(dp,x(1),y(1),dp_cmd)
PRINT "DPlot answer : ";ret
PRINT "Press a key to continue ... "
WAITKEY$
CASE 2
RESET dp
'c
'c Contour plot OF Z values ON a rectangular grid. z = SIN(x)*COS(y)
'c
'c extents are, IN order, xlo, ylo, xhi, yhi
extents(1) = -3.
extents(2) = -2.
extents(3) = 3.
extents(4) = 2.
FOR i=1 TO dp_NX
xx = extents(1) + ((extents(3)-extents(1))*i)/(dp_NX-1)
FOR j=1 TO dp_NY
yy = extents(2) + ((extents(4)-extents(2))*j)/(dp_NY-1)
z((i-1)*dp_NY+j) = SIN(xx)*COS(yy)
NEXT
NEXT
dp.Version = %DPLOT_DDE_VERSION
dp.hwnd = 0
dp.DataFormat = %DATA_3D
'c
'c MaxCurves AND MaxPoints members are used FOR the size OF the grid, IN grid cells
'c
dp.MaxCurves = dp_NX-1
dp.MaxPoints = dp_NY-1
dp.NumCurves = 1
dp.ScaleCode = %SCALE_LINEARX_LINEARY
dp.Title(1) = "Data sent to DPLOT via DPLOTLIB.DLL"
dp.Title(2) = "z = sin(x)*cos(y)"
dp.Title(3) = ""
dp.XAxis = "x"
dp.YAxis = "y"
dp_cmd = "[Caption("& CHR$(34) & "DPLOTLIB Contour Test 1" & CHR$(34) & ")]" & _
"[Contour3D(1)][ContourGrid(1)][ContourAxes(1)]" & _
"[ContourView(30,20)][ContourLevels(20,-1,1)]" & _
"[ContourScales(1,1,1)]" & _
"[FontPoints(1,10)][FontPoints(6,10)]" & _
"[ZAxisLabel(" & CHR$(34) & "z" & CHR$(34) & ")]" &"[DocMaximize()]" ' & CHR$(0)
ret = DPLOT_Plot(dp,extents(1),z(1),dp_cmd)
PRINT "DPlot answer : ";ret
PRINT "Press a key to continue ... "
WAITKEY$
CASE 3
RESET dp
'c
'c Contour plot WITH randomly spaced points
'c
seed = 1
FOR i=1 TO dp_NZ
Node(i).x = -PI + 2*PI*Ran_dom(seed)
Node(i).y = -PI + 2*PI*Ran_dom(seed)
Node(i).z = SIN(Node(i).x)*COS(Node(i).y)
NEXT
dp.Version = %DPLOT_DDE_VERSION
dp.hwnd = 0
dp.DataFormat = %DATA_3DR
dp.MaxCurves = 1
dp.MaxPoints = dp_NZ
dp.NumCurves = 1
dp.ScaleCode = %SCALE_LINEARX_LINEARY
dp.Title(1) = "Data sent to DPLOT via DPLOTLIB.DLL"
dp.Title(2) = "z = sin(x)*cos(y)"
dp.Title(3) = ""
dp.XAxis = "x"
dp.YAxis = "y"
dp_cmd = "[Caption(" & CHR$(34) & "DPLOTLIB Contour Test 2" & CHR$(34) & ")]" & _
"[Contour3D(0)][ContourGrid(0)]" & _
"[ContourLevels(21,-1,1)]" & _
"[FontPoints(1,10)][FontPoints(6,10)]" & _
"[DocMaximize()]" '& chr$(0)
ret = DPLOT_Plot(dp,dummy(1),Node(1),dp_cmd)
PRINT "DPlot answer : ";ret
PRINT "Press a key to continue ... "
WAITKEY$
CASE 4
RESET dp
'c
'c Box-AND-whisker plot - 3 groups
'c
dp.Version = %DPLOT_DDE_VERSION
dp.hwnd = 0
dp.DataFormat = %DATA_1D
dp.MaxCurves = 3
dp.MaxPoints = 50
dp.NumCurves = 3
dp.LegendX = 0.02
dp.LegendY = 0.7
dp.ScaleCode = %SCALE_LINEARX_LINEARY
dp.Title(1) = "Data sent to DPLOT via DPLOTLIB.DLL"
dp.Title(2) = ""
dp.Title(3) = ""
dp.XAxis = ""
dp.YAxis = "Amplitude"
' dp.Legend=""
FOR i=1 TO dp.NumCurves
dp.NP(i) = dp.MaxPoints
' dp.Legend(i) ="Group " & "//" & str$(64+i) & "//" '& chr$(0)
dp.Legend(i) ="Group " & STR$(64+i) '& chr$(0)
NEXT
' dp.Legend=dp.Legend & chr$(0)
'c Generate group DATA, centered around 5.0 WITH progressively larger variations
k = 1
FOR i=1 TO dp.NumCurves
FOR j=1 TO dp.NP(i)
y(k) = 5.0 + (i+1)*(-0.5+Ran_dom(seed))
k = k+1
NEXT
NEXT
dp_cmd = "[Caption(" & CHR$(34) & "DPLOTLIB Box-and-whisker Test" & CHR$(34) & ")]" & _
"[Stat_PlotType(0)][Stat_GroupInfo(15,4)]" & _
"[Stat_BWOptions(1,1,0,1,1.5,2,3)]" & _
"[Stat_GrandMean(3,30)]" & _
"[FontPoints(1,10)][FontPoints(6,10)]" & _
"[DocMaximize()]" '& CHR$(0)
ret = DPLOT_Plot(dp,dummy(1),y(1),dp_cmd)
PRINT "DPlot answer : ";ret
PRINT "Press a key to continue ... "
WAITKEY$
CASE 0
GOTO 9999
END SELECT
GOTO 100
9999 REM continue
END FUNCTION
'c
'c=======================================================================
'c
FUNCTION Ran_dom(iseed AS LONG) AS SINGLE
' implicit NONE
' INTEGER*4 iseed
'dim iseed as LONG
iseed = (iseed*7141+54773) MOD 259200
Ran_dom = CSNG(iseed)/259200.
' RETURN
END FUNCTION
And the corresponding include file PBCC.INC
Code: Select all
'
' DPlot-specific stuff
'
%DPLOT_DDE_VERSION = 3
TYPE DPLOT
Version AS LONG ' version number of this structure
hwnd AS LONG ' handle of client application window
DataFormat AS LONG ' XY pairs, DX and Y, etc. See DATA_ constants
MaxCurves AS LONG ' DataFormat Description
' DATA_XYXY Max. number of curves, <= 20
' DATA_DXY ..
' DATA_XYYY ..
' DATA_3D Number of grid cells in X direction,
' = number of data columns-1
' DATA_3DR not used
' DATA_1D Max. number of groups, <= 20
MaxPoints AS LONG ' DATA_XYXY Max. number of points/curve
' DATA_DXY ..
' DATA_XYYY ..
' DATA_3D Number of grid cells in Y direction,
' = number of data rows-1
' DATA_3DR Number of X,Y,Z triplets
' DATA_1D Max. number of points/group
NumCurves AS LONG ' Actual number of curves/groups, always 1 for
' DATA_3D or DATA_3DR
ScaleCode AS LONG ' scaling code for XY plots (Linear, Log, etc.)
LegendX AS SINGLE ' left coord of legend, expressed as a ratio
' of plot size (0->1) (CAN be negative and/or > 1,
' but exact placement is then a bit hard to predict)
LegendY AS SINGLE ' top coord of legend, again expressed as a ratio
' of plot size
NP(1 TO 100) AS LONG ' actual number of points in each curve/group for
' XY/1D plots; cannot exceed MaxPoints.
LineType(1 TO 100) AS LONG ' line types (see codes below)
SymbolType(1 TO 100) AS LONG ' symbol types (see codes below)
SizeofExtraInfo AS LONG ' Extra information following X,Y data. No need to
' fill in this member for DPLOTLIB calls
Legend (0 TO 100) AS STRING * 80 ' Legend(0->39) is the caption for the legend
' Legend(n*40->n*40+39) is the caption for the n'th curve
LABEL (1 TO 100) AS STRING * 40 ' Strings displayed beside the last data point
' in a curve, 5 characters per curve
Title(1 TO 3) AS STRING *80
' Title1 AS STRING * 80
' Title2 AS STRING * 80
' Title3 AS STRING * 80
XAxis AS STRING * 80 ' X Axis label.
YAxis AS STRING * 80 ' Y Axis label.
END TYPE
TYPE DPLOT_PLOTMETRICS
size AS LONG ' Size of this structure; should be set by the caller
hll AS LONG ' horizontal and
vll AS LONG ' vertical coordinates of the lower left corner of
' the plot, in pixels
hur AS LONG ' horizontal and
vur AS LONG ' vertical coordinates of the upper right corner of
' the plot, in pixels
xlo AS SINGLE ' value of x at the left plot extent
ylo AS SINGLE ' value of y at the bottom plot extent
xhi AS SINGLE ' value of x at the right plot extent
yhi AS SINGLE ' value of z at the top plot extent
END TYPE
DECLARE FUNCTION DPlot_AddData LIB "dplotlib.dll" ALIAS "DPlot_AddData" (BYVAL DocNum AS LONG, BYVAL DataType AS LONG, BYVAL NumPts AS LONG, BYVAL Curve AS LONG, BYREF x AS ANY, BYREF y AS ANY) AS LONG
DECLARE FUNCTION DPlot_Command LIB "dplotlib.dll" ALIAS "DPlot_Command" (BYVAL DocNum AS LONG, BYVAL Command AS STRING) AS LONG
DECLARE FUNCTION DPlot_GetBitmap LIB "dplotlib.dll" ALIAS "DPlot_GetBitmap" (BYVAL DocNum AS LONG, BYVAL cx AS LONG, BYVAL cy AS LONG) AS LONG
DECLARE FUNCTION DPlot_GetBitmapEx LIB "dplotlib.dll" ALIAS "DPlot_GetBitmapEx" (BYVAL DocNum AS LONG, BYVAL cx AS LONG, BYVAL cy AS LONG, BYREF DPM AS DPLOT_PLOTMETRICS) AS LONG
DECLARE FUNCTION DPlot_GetEnhMetaFile LIB "dplotlib.dll" ALIAS "DPlot_GetEnhMetaFile" (BYVAL DocNum AS LONG,BYVAL cx AS SINGLE, BYVAL cy AS SINGLE) AS LONG
DECLARE FUNCTION DPlot_Plot LIB "dplotlib.dll" ALIAS "DPlot_Plot" (BYREF D AS DPLOT, BYREF x AS ANY, BYREF y AS ANY, BYVAL cmds AS STRING) AS LONG
DECLARE FUNCTION DPlot_PlotBitmap LIB "dplotlib.dll" ALIAS "DPlot_PlotBitmap" (BYREF D AS DPLOT, BYREF x AS ANY, BYREF y AS ANY, BYVAL cmds AS STRING, BYVAL cx AS LONG, BYVAL cy AS LONG) AS LONG
DECLARE FUNCTION DPlot_PlotToRect LIB "dplotlib.dll" ALIAS "DPlot_PlotToRect" (BYREF D AS DPLOT, BYREF x AS ANY, BYREF y AS ANY, BYVAL cmds AS STRING, BYVAL hwnd AS LONG, BYREF rc AS RECT) AS LONG
DECLARE FUNCTION DPlot_Request LIB "dplotlib.dll" ALIAS "DPlot_Request" (BYVAL DocNum AS LONG, BYVAL Item AS STRING, BYVAL Value AS STRING, BYREF MaxCount AS LONG) AS LONG
DECLARE SUB DPlot_SetErrorMethod LIB "dplotlib.dll" ALIAS "DPlot_SetErrorMethod" (BYVAL Method AS LONG)
DECLARE FUNCTION DPlot_Start LIB "dplotlib.dll" ALIAS "DPlot_Start" (BYVAL Minimize AS LONG, BYREF WasActive AS LONG) AS LONG
DECLARE SUB DPlot_Stop LIB "dplotlib.dll" ALIAS "DPlot_Stop" ()
' XY Scaling codes:
%SCALE_LINEARX_LINEARY = 1
%SCALE_LINEARX_LOGY = 2
%SCALE_LOGX_LINEARY = 3
%SCALE_LOGX_LOGY = 4
%SCALE_TRIPARTITE = 5
%SCALE_LINEARX_PROBABILITY = 6
%SCALE_GRAINSIZE_DIST = 7
%SCALE_POLAR = 8
%SCALE_BARCHART = 9
%SCALE_LOGX_PROBABILITY = 10
%SCALE_PROBX_LINEARY = 11
%SCALE_PROBX_LOGY = 12
%SCALE_PROBX_PROBY = 13
%SCALE_TRIANGLE_PLOT = 14
' Unit-specific scaling codes ... combine with above values using OR operator
%UNITS_DEFAULT = 0
%UNITS_TRIPARTITE_INCHES = %UNITS_DEFAULT ' Velocity (Y) in inches/sec
%UNITS_TRIPARTITE_FEET = &H100 ' feet/sec
%UNITS_TRIPARTITE_MILLIMETERS = &H200 ' mm/sec
%UNITS_TRIPARTITE_CENTIMETERS = &H300 ' cm/sec
%UNITS_TRIPARTITE_METERS = &H400 ' meters/sec
%UNITS_GRAINSIZE_MILLIMETERS = %UNITS_DEFAULT ' Grain sizes (X) in mm
%UNITS_GRAINSIZE_INCHES = &H100 ' inches
%UNITS_POLAR_RADIANS = %UNITS_DEFAULT ' Rotation (X) in radians
%UNITS_POLAR_DEGREES = &H100 ' degrees
%UNITS_USERDEFINED = &H7F00
' Data organization following DPLOT structure:
%DATA_XYXY = 0 ' One or more sets of X,Y data
%DATA_DXY = 1 ' One or more X,Y curves. Constant spacing in X and same number of points in all curves.
%DATA_XYYY = 2 ' One or more X,Y curves. All curves have the same X values.
%DATA_3D = 3 ' Z values on a rectangular grid
%DATA_3DR = 4 ' Random X,Y,Z values
%DATA_IMAGE = 5 ' Used only by DPlot - there's no way to SEND DPlot an image
%DATA_1D = 6 ' One or more groups of Y values.
' Line styles:
%LINESTYLE_NONE = 0
%LINESTYLE_SOLID = 1
%LINESTYLE_LONGDASH = 2
%LINESTYLE_DOTTED = 3
%LINESTYLE_DASHDOT = 4
%LINESTYLE_DOTDASH = 4
%LINESTYLE_MEDDASH = 5
%LINESTYLE_DASHDOTDOT = 6
' Symbol styles
%SYMBOLSTYLE_NONE = 0
%SYMBOLSTYLE_DOT = 1
%SYMBOLSTYLE_CROSS = 2
%SYMBOLSTYLE_ASTERISK = 3
%SYMBOLSTYLE_X = 4
%SYMBOLSTYLE_SQUARE = 5
%SYMBOLSTYLE_DIAMOND = 6
%SYMBOLSTYLE_TRIANGLE = 7
%SYMBOLSTYLE_OCTAGON = 8
%SYMBOLSTYLE_ITRIANGLE = 9
%SYMBOLSTYLE_HEXAGON = 10
%SYMBOLSTYLE_PENTAGON = 11
%SYMBOLSTYLE_STAR = 12
%SYMBOLSTYLE_FILL = &H100 ' May be combined with other styles