Dplot with HTBasic

Q&A for Visual Basic, Visual Basic .NET, and PowerBasic developers using DPlot
Post Reply
Lolo15
Posts: 3
Joined: Wed Sep 23, 2015 10:07 am
Location: France

Dplot with HTBasic

Post by Lolo15 »

Hi,
I start to try DPLOT with HTbasic software (without the Techsoft Add-Ins)
Unfortunately there are no sample code to download on Dplot.com
So please find my code bellow ...

It’s working well for [XY] and [XYXY] data command :lol:
But not really for the [XYZ] command :cry:
Dplot send me : "Wrong data type"
and
"Error processing this command [XYZ(4,1,2,3,1,20,0,10,2,0,10,20,30)]"

Somebody for help me ?

Regards,
Lolo

!***********************
! HTBASIC/DPLOT SOFTWARE TEST
!***********************
!
CLEAR SCREEN
KEY LABELS OFF
PRINTER IS CRT
DLL UNLOAD ALL
DEG
OPTION BASE 1
!
DIM Disque1$[80]! HTBasic program location
DIM Disque2$[80]! DPLOT DLL location
!
DIM C$[32767]! DPLOT limit --> 1000 Points de Trace
DIM C1$[80]
DIM Title$[80]
!
LONG Retour1 ! DLL Return type Integer/Longbool
REAL Retour2 ! DLL Return type Double
LONG Doc_num ! DDE document index
!
ALLOCATE D1$[80],D2$[80],D3$[80]
!
Npoint=2
ALLOCATE REAL Data_xy1(1:Npoint,1:2)
ALLOCATE REAL Data_xy2(1:Npoint,1:2)
ALLOCATE REAL Data_xyz(1:Npoint,1:Npoint,1:3)
!
!***********************
! Storage Area Definition : HTBasic & DPLOT DLL
!***********************
Disque1$=SYSTEM$("MSI")! Actual HTBasic Program location
!
Bit64: ON ERROR GOTO Bit32
Disque2$="C:\Program Files (x86)"
MASS STORAGE IS Disque2$
OFF ERROR
Bit=64
GOTO Bit
!
Bit32: OFF ERROR
Bit=32
!
Bit: SELECT Bit
CASE 32
Disque2$="C:\Program Files\DPlotJr\dplotlib"
CASE 64
Disque2$="C:\Program Files (x86)\DPlotJr\dplotlib"
END SELECT
!
!***********************
Dll1: ! Load DLL DPLOT : dplotlib
!***********************
DLL UNLOAD ALL
MASS STORAGE IS Disque2$
DISP "---> DPLOT DLL Loading in progress ..."
DLL LOAD "dplotlib"
MASS STORAGE IS Disque1$
DISP
!
!
!***********************
Start: ! HTBasic/DPLOT Start Here
!***********************
GOSUB Version
GOSUB Min_ver
GOSUB Start_dp
!
!-----------------------------------------
! Open DPlot Session
!-----------------------------------------
Doc_num=0
C$="[FileNew()]"
GOSUB Command
!
!-----------------------------------------
! Curve Type Selection
!-----------------------------------------
FOR J=1 TO 8
ON KEY J LABEL "" GOTO Nextj1
Nextj1: NEXT J
ON KEY 1 LABEL "XY curves " GOTO Choice1
ON KEY 2 LABEL "XYXY curve " GOTO Choice2
ON KEY 3 LABEL "XYZ curve " GOTO Choice3
KEY LABELS ON
Wait1: WAIT .1
GOTO Wait1
!
Choice1:Choix=1 ! Courbe XY = pts/pts (Real time application)
GOTO Trace
Choice2:Choix=2 ! Courbe XY = pts>1000
GOTO Trace
Choice3:Choix=3 ! Courbe XYZ
GOTO Trace
!
!
Trace: KEY LABELS OFF
!
!-----------------------------------------
! DPLOT : Back to Front
!-----------------------------------------
C$="[AppHide()]"
GOSUB Command
C$="[AppShow()]"
GOSUB Command
!
SELECT Choix
CASE 1
!
!-----------------------------------------
! 2D curve Definition
!-----------------------------------------
Npoint=500
GOSUB C2d
!
!-----------------------------------------
! Definition Number of Curve & Points
!-----------------------------------------
Maxc=2
Maxp=Npoint*Maxc
C$="[FileArrays("&VAL$(Maxc)&","&VAL$(Maxp)&")]"
GOSUB Command
!
!-----------------------------------------
! Curve Selection & Trace
!-----------------------------------------
Curve=1
C1$="[SelectCurve("&VAL$(Curve)&")]"
GOSUB Xy1
!
!-----------------------------------------
! Curve Selection & Trace [XY]
!-----------------------------------------
Curve=2
C1$="[SelectCurve("&VAL$(Curve)&")]"
GOSUB Xy1
!
CASE 2
!
!-----------------------------------------
! 2D curve Definition
!-----------------------------------------
Npoint=3500
GOSUB C2d
!
!-----------------------------------------
! Definition Number of Curve & Points
!-----------------------------------------
Maxc=1
Maxp=Npoint
C$="[FileArrays("&VAL$(Maxc)&","&VAL$(Maxp)&")]"
GOSUB Command
!
!-----------------------------------------
! Curve Selection & Trace [XYXY]
!-----------------------------------------
Curve=1
C1$="[SelectCurve("&VAL$(Curve)&")]"
GOSUB Xy2
!
CASE 3
!
!-----------------------------------------
! 3D curve Definition
!-----------------------------------------
GOSUB C3d
!
!-----------------------------------------
! Definition Number of Curve & Points
!-----------------------------------------
Maxc=1
Maxp=Npoint
C$="[FileArrays("&VAL$(Maxc)&","&VAL$(Maxp)&")]"
GOSUB Command
!
!-----------------------------------------
! Curve # Selection & Trace [XYZ]
!-----------------------------------------
Curve=1
C1$="[SelectCurve("&VAL$(Curve)&")]"
GOSUB Xyz
!
END SELECT
GOTO Scale
!
!
!-----------------------------------------
Xy1: ! XY Exportation Data to DPLOT
!-----------------------------------------
! C$="[XY(X,Y)]"
!-----------------------------------------
FOR I=1 TO Npoint
SELECT Curve
CASE 1
X=Data_xy1(I,1)
Y=Data_xy1(I,2)
CASE 2
X=Data_xy2(I,1)
Y=Data_xy2(I,2)
CASE ELSE
RETURN
END SELECT
C$=C1$&"[XY("&VAL$(X)&","&VAL$(Y)&")]"
GOSUB Command
NEXT I
RETURN
!
!
!-----------------------------------------
Xy2: ! XYXY Exportation Data to DPLOT
!-----------------------------------------
! C$="[XYXY(N,X1,Y1,X2,Y2,....Xn,Yn)]"
!-----------------------------------------
Nmax=1000 ! DPLOT limitation
Ndebut=0
!
WHILE Nfin<Npoint
!
Ndebut=Ndebut+1
Nfin=Ndebut
Np=Nfin-Ndebut+1
!
WHILE Np<Nmax>=Npoint THEN GOTO Ex_xy2
END WHILE
!
Ex_xy2: D1$="[XYXY("&VAL$(Np)
N1=LEN(D1$)
D3$=")]"
N3=LEN(D3$)
!
N2=32767-(N1+N3)
DEALLOCATE D2$
ALLOCATE D2$[N2]
!
D2$=""
FOR I=Ndebut TO Nfin
X=Data_xy1(I,1)
Y=Data_xy1(I,2)
D2$=D2$&","&VAL$(X)&","&VAL$(Y)
NEXT I
!
C$=C1$&D1$&D2$&D3$
GOSUB Command
!
Ndebut=Nfin
!
END WHILE
PRINT
RETURN
!
!
!-----------------------------------------
Xyz: ! XYZ Exportation Data to DPLOT
!-----------------------------------------
! C$="[XYZ(N,X1,Y1,Z1,X2,Y2,Z2....Xn,Yn,Zn)]"
!-----------------------------------------
Npoint=4
ALLOCATE REAL Valeur(1:Npoint/2,1:Npoint/2,1:3)
!
! -----------
! X/Y | 2 | 20 |
! ----------------
! | 1 | 3 | 0 |
! | 10 | 0 | 30 |
! ----------------
!
Valeur(1,1,1)=1! X point# 1
Valeur(1,1,2)=2! Y
Valeur(1,1,3)=3! Z
!
Valeur(1,2,1)=1! X point# 2
Valeur(1,2,2)=20! Y
Valeur(1,2,3)=0! Z
!
Valeur(2,1,1)=10! X point# 3
Valeur(2,1,2)=2! Y
Valeur(2,1,3)=0! Z
!
Valeur(2,2,1)=10! X point# 4
Valeur(2,2,2)=20! Y
Valeur(2,2,3)=30! Z
!
D1$="[XYZ("&VAL$(Npoint)
D2$=""
!
FOR I=1 TO Npoint/2
FOR J=1 TO Npoint/2
X=Valeur(I,J,1)
Y=Valeur(I,J,2)
Z=Valeur(I,J,3)
D2$=D2$&","&VAL$(X)&","&VAL$(Y)&","&VAL$(Z)
NEXT J
NEXT I
!
D3$=")]"
C$=C1$&D1$&D2$&D3$
C$=D1$&D2$&D3$
GOSUB Command
!
PRINT
RETURN
!
!
!-----------------------------------------
Scale: ! Manual Scale X & Y
!-----------------------------------------
! C$="[ManualScale(xlo,ylo,xhi,yhi,ylo2,yhi2)]"
!-----------------------------------------
Xmin=0
Xmax=10
Xstep=.5
Ymin1=-2! First Axle : Scale Y1
Ymax1=+2
Ystep=.25
Ymin2=0! Second Axle : Scale Y2
Ymax2=0! N/A
Zstep=0! N/A (Curve XY)
!
IF Ymin2<>0 AND Ymax2<>0 THEN
C$="[ManualScale("&VAL$(Xmin)&","&VAL$(Ymin1)&","&VAL$(Xmax)&","&VAL$(Ymax1)&","&VAL$(Ymin2)&","&VAL$(Ymax2)&")]"
ELSE
C$="[ManualScale("&VAL$(Xmin)&","&VAL$(Ymin1)&","&VAL$(Xmax)&","&VAL$(Ymax1)&",,)]"
END IF
GOSUB Command
!
!-----------------------------------------
! Manual Scale Xstep & Ystep
!-----------------------------------------
! C$="[TickInterval(State,dx,dy,dz)]"
!-----------------------------------------
IF Xstep<>0 OR Ystep<>0 THEN State=1
IF Zstep<>0 THEN
C$="[TickInterval("&VAL$(State)&","&VAL$(Xstep)&","&VAL$(Ystep)&","&VAL$(Zstep)&")]"
ELSE
C$="[TickInterval("&VAL$(State)&","&VAL$(Xstep)&","&VAL$(Ystep)&",)]"
END IF
GOSUB Command
!
!-----------------------------------------
! Title 1
!-----------------------------------------
! C$="[Title1("String")]"
!-----------------------------------------
Title$="TEST DPLOT HTBASIC"
C$="[Title1("""
C$=C$&""&Title$&""
C$=C$&""")]"
GOSUB Command
!
!-----------------------------------------
! Xaxis Label
!-----------------------------------------
! C$="[XAxisLabel("String")]"
!-----------------------------------------
Title$="Axe X"
C$="[XAxisLabel("""
C$=C$&""&Title$&""
C$=C$&""")]"
GOSUB Command
!
!-----------------------------------------
! Yaxis Label
!-----------------------------------------
! C$="[YAxisLabel("String")]"
!-----------------------------------------
Title$="Axe Y"
C$="[YAxisLabel("""
C$=C$&""&Title$&""
C$=C$&""")]"
GOSUB Command
!
!
!***********************
! EXIT Menu
!***********************
FOR J=1 TO 8
ON KEY J LABEL "" GOTO Nextj
Nextj: NEXT J
ON KEY 8 LABEL "Suite Exit " GOTO Suite
KEY LABELS ON
Wait: WAIT .1
GOTO Wait
!
Suite: KEY LABELS OFF
C$="[FileClose()]"
GOSUB Command
!
GOSUB Stop_dp
GOTO End
!
!
!***********************
C2d: ! Create Data for 2D curve
!***********************
DEALLOCATE Data_xy1(*)
DEALLOCATE Data_xy2(*)
ALLOCATE REAL Data_xy1(1:Npoint,1:3)! Curve 1
ALLOCATE REAL Data_xy2(1:Npoint,1:3)! Curve 2
!
Xmin=0
Xmax=2*PI
Xstep=Xmax/Npoint
Xi=1
!
RAD
FOR X=Xmin TO Xmax STEP Xstep
Y1=SIN(X)
Y2=ATN(X/2)*(X/5+RND*(.1)+RND*.3-1)
!
Data_xy1(Xi,1)=X! Data
Data_xy1(Xi,2)=Y1! Curve 1
!
Data_xy2(Xi,1)=X! Data
Data_xy2(Xi,2)=Y2! Curve 2
!
IF Xi<Npoint>0
PRINT Retour1
PRINT "WINDOWS handle of the main DPLOT application window"
CASE ELSE
PRINT "(";Retour1;") : DPLOT start"
END SELECT
!
SELECT Hide
CASE 0
PRINT Dplot$&" is Started normaly"
CASE ELSE
PRINT Dplot$&" is invisible to the user"
END SELECT
!
SELECT Was_active
CASE 0
PRINT Dplot$&" Was not already Active"
CASE 1
PRINT Dplot$&" Was already Active"
CASE ELSE
PRINT "Was Active=";Was_active
GOTO End
END SELECT
PRINT
RETURN
!
!
!-------------------------------------
Stop_dp:! STOP DPLOT
!-------------------------------------
! Procedure / VOID=Rien
!-------------------------------------
ON ERROR GOSUB Er_dll
DLL GET "STDCALL VOID DPLOTLIB:DPlot_Stop" AS "Dplot_stop"
OFF ERROR
!
IF Was_active=0 THEN
Dplot_stop
PRINT Dplot$&" stopped ..."
END IF
PRINT
RETURN
!
!
!-------------------------------------
Command:! SEND Command to DPLOT
!-------------------------------------
! Function / INT=LONG
!-------------------------------------
ON ERROR GOSUB Er_dll
DLL GET "STDCALL LONG DPLOTLIB:DPlot_Command" AS "Dplot_command"
OFF ERROR
!
IF Doc_num=0 THEN Index=0
Retour1=FNDplot_command((Doc_num),C$)
!
SELECT Retour1
CASE >0
!PRINT C$&" ---> Success"
!PRINT
IF Index=0 THEN Doc_num=Retour1
CASE 0
PRINT C$&" ---> Error Processing This Command !!!"
PRINT
GOTO End
CASE -1
PRINT C$&" ---> Could Not Find/Excecute DPLOT !!!"
PRINT
GOTO End
CASE -2
PRINT C$&" ---> Could Not Establish a DDE connection with DPLOT !!!"
PRINT
GOTO End
END SELECT
RETURN
!
!
!***********************
Er_dll: ! Verification Chargement DLL
!***********************
SELECT ERRN
CASE 1104 ! Function already loaded
ERROR RETURN
CASE ELSE
PRINT ERRM$,ERRN
PRINT
GOTO End
END SELECT
!
!***********************
End: ! END of PROGRAM
!***********************
PRINT "END OF PROGRAM"
PRINT
LIST DLL
KEY LABELS ON
END[/code][/quote]
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Sorry, but there's no sample code because the entire Graph-XT product including source is proprietary. My demo version expired a long time ago so I won't be much help here. You may get a helpful reply here, but I think you'll have better luck on Techsoft's site (or not, since you aren't using their tools).
Visualize Your Data
support@dplot.com
Lolo15
Posts: 3
Joined: Wed Sep 23, 2015 10:07 am
Location: France

Post by Lolo15 »

Find the bug ! :idea:

When I open the DPLOT session I need to replace :

C$="[FileNew()]" ! for 2D plot
by
C$="[FileNew(3)]" ! for 3D plot [XYZ]

It was too easy in fact :lol:
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Glad you figured it out. Well done. :D
Visualize Your Data
support@dplot.com
Post Reply