DPlot Forum Index DPlot
http://www.dplot.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DPlot PowerBasicConsoleCompiler Example

 
Post new topic   Reply to topic    DPlot Forum Index -> Basic
View previous topic :: View next topic  
Author Message
Bercic



Joined: 17 May 2004
Posts: 27
Location: Slovenia

PostPosted: Mon May 17, 2004 7:56 am    Post subject: DPlot PowerBasicConsoleCompiler Example Reply with quote

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.

Code:
'
'
' 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:
'
' 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                 
Back to top
View user's profile Send private message
Peter Simmonds



Joined: 12 Mar 2005
Posts: 18
Location: Edinburgh, Scotland

PostPosted: Sun Mar 13, 2005 6:03 am    Post subject: Reply with quote

Bercic, thanks very much for translating the Fortran example of the 4 graph plots to PBCC. I was really struggling with the program interface to DPlot Jr until I saw this post, and probably wouldn't have been able to get started without it.

As a suggestion for David Hyde, maybe a PBCC example should be distributed with the DPlot Jr download, because the language is so different from the supplied PBWin examples. I'm sure there are a lot of PBCC programmers who would appreciate the package, given the lack of graphics in PBCC, and the widespread use of PBCC as a simple to use compiler in scientific areas.

Peter
Back to top
View user's profile Send private message
Peter Simmonds



Joined: 12 Mar 2005
Posts: 18
Location: Edinburgh, Scotland

PostPosted: Sun Oct 29, 2006 6:20 am    Post subject: 3D Scatter plot Reply with quote

Coming back to the programme after a bit if a break, I thought I would try to plot a 3D scatter graph, calling the DLL through the DPLOT_Plot function.

I noticed that the equate %DATA_3DS was missing from the INC file supplied with DPlot Jnr for PowerBasic, although I did find the equivalent in the C respource file, where apparently it equals 7.

I modified the PB INC file to include this new equate, but attempts to call the DPLOT_Plot function with dp.DataFormat = 7 always fail. Only lower values, as supplied by the example program seem to work.

Is there any reason why it is not possible to create a 3D scatter graph? Are other modifications to the INC file or the PBC example required?

Thanks for any help

Peter
Back to top
View user's profile Send private message
DPlotAdmin
Site Admin


Joined: 24 Jun 2003
Posts: 2310
Location: Vicksburg, Mississippi

PostPosted: Sun Oct 29, 2006 9:12 am    Post subject: Reply with quote

No, that should do it. You might want to try

DPlot_SetErrorMethod(2)

to see if any interesting error messages pop up. Other than that, I'd suggest taking a look at the C example ctest.c to make sure you're passing your 3D data as expected.
_________________
Visualize Your Data
support@dplot.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Peter Simmonds



Joined: 12 Mar 2005
Posts: 18
Location: Edinburgh, Scotland

PostPosted: Tue Oct 31, 2006 6:17 am    Post subject: Reply with quote

Thanks. I've been having real problems with getting the 3D scatter graphs to work, mainly, I'm sure, because of my own ignorance and stupidity. Below is the section of the PBCC program used for the scatter plot (modified from the 3D contour plot example provided previously).

Code:

     RESET dp
     seed = 1
     FOR a = 1 TO 100
         Node(a).x = INT((a - 1) / 10) + 1
         Node(a).y = ((a - 1) MOD 10) + 1
         Node(a).z = INT(RND * 10) + 1
     NEXT

     dp.Version     = %DPLOT_DDE_VERSION
     dp.hwnd        = 0
     dp.DataFormat  = %DATA_3DS
     dp.MaxCurves   = 1
     dp.MaxPoints   = 100
     dp.NumCurves   = 1
     dp.NP(1)       = 100
     dp.symboltype(1)= 261
     dp.ScaleCode   = %SCALE_LINEARX_LINEARY
     dp.Title(1)    = "Data sent to DPLOT via DPLOTLIB.DLL"
     dp.Title(2)    = "z is random"
     dp.Title(3)    = ""
     dp.XAxis       = "x"
     dp.YAxis       = "y"

     dp_cmd = "[Caption(xx)][TickInterval(1,1,1,1)][Contour3D(0)]" & _
                     "[ContourColorScheme(0)][ContourLevels(21,0,10)]" & _
                     "[SymbolSize(-1,10)][FontPoints(1,10)]" & _
                     "[FontPoints(6,10)]" & CHR$(0)

     ret = DPLOT_Plot(dp,dummy(1),Node(1),dp_cmd)
     PRINT "DPlot answer :    ";ret


This is supposed to produce a 10 x 10 x/y grid with random values for z between 1 and 10.

This creates an error when run, with a box appearing saying "Error processing this command" and then lists the dp_cmd string. It does however usually create the 3D scatter graph, but all the commands in the string are ignored, and presumably substitutes default values (eg. a 3D instead of a vertical view, tick intervals of 0.5 instead of 1 etc).

Of concern is that some alterations to the above command string, particularly to the Caption label, can cause return values of -2, and sometimes the dreaded BSOD (blue screen of death) and a complete computer re-boot (not ideal!)

Would it be possible to get a list of the minimally required commands and paramters for the dp variable to run scatter graphs without errors. I just cannot find the information in the documentation for the program or the example files.

Thanks very much for any help

Peter


Sad
Back to top
View user's profile Send private message
DPlotAdmin
Site Admin


Joined: 24 Jun 2003
Posts: 2310
Location: Vicksburg, Mississippi

PostPosted: Tue Oct 31, 2006 8:25 am    Post subject: Reply with quote

The "[Caption(xx)]" is the problem. You unfortunately can't slap variable names into commands as arguments like that. Instead you'll need to do something like:

"[Caption(" & chr$(34) & xx & chr$(34) & ")]"

(or whatever the syntax for string concatenation is in PB... I need coffee.)

I'm not sure if PB will accept this instead, which is a little more clear:

"[Caption("" & xx & "")]"

DPlot is balking at that first command and ignoring all others. From what you described I think changing this is probably your last problem.

As for a BSOD - that's of course not good. In early versions of DPLOTLIB there was a bad problem if a caption was not included, but I was certain I had fixed that. I'll take a thorough look today.
_________________
Visualize Your Data
support@dplot.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Peter Simmonds



Joined: 12 Mar 2005
Posts: 18
Location: Edinburgh, Scotland

PostPosted: Wed Nov 01, 2006 5:27 am    Post subject: Reply with quote

Thanks but no luck so far. The following (correct) command led to an immediate BSOD when added to the previous code:

Code:

[Caption(" & CHR$(34) &  "xx" & CHR$(34) &  ")]

If I leave out the Caption command entirely, I still get a BSOD. It therefore seems that having some kind of formatting error in the first (caption) command prevents the rest of command string rest being processed (producing a less serious zero or -2 return value), and a final graph with all the commands ignored.

Must be something else wrong with the parameters sent to the program. I'm slightly reluctant to carry on experimenting as I don't realy like having complete crashes on my computer!

Peter
Back to top
View user's profile Send private message
DPlotAdmin
Site Admin


Joined: 24 Jun 2003
Posts: 2310
Location: Vicksburg, Mississippi

PostPosted: Wed Nov 01, 2006 9:30 am    Post subject: Reply with quote

Quote:
Must be something else wrong with the parameters sent to the program.


That would have been my guess as well, but it all looks fine. And when I use your parameters in a C program I get a plot (I'll try PB when I have a chance, tonight.) The only things that stand out are:

[Contour3D(0)]

3D scatter plots will always be 3D, so this is ignored. It won't cause a problem, though.

[SymbolSize(-1,10)]

gives you symbols 0.01" tall. For most display adapters that's less than 1 pixel, so no symbols will be drawn. (If you have "Antialias symbols" turned on then you might see a fuzzy black dot, but that's all.) But this shouldn't cause a serious problem either.

What version of DPlot are you using?
_________________
Visualize Your Data
support@dplot.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Peter Simmonds



Joined: 12 Mar 2005
Posts: 18
Location: Edinburgh, Scotland

PostPosted: Thu Nov 02, 2006 7:51 am    Post subject: Reply with quote

I used the version on the website downloaded last week.

Peter
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    DPlot Forum Index -> Basic All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group