Creating (scientific) plots via gnuplot

User projects written in or related to FreeBASIC.
TJF
Posts: 3486
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Creating (scientific) plots via gnuplot

Postby TJF » May 20, 2019 7:55

dodicat wrote:Dislin is an ongoing project.
No need for extensive installations of Cairo e.t.c., just what is in the folder will do.
Yeah, I introduced DISLIN for FreeBASIC in 2011. Later, in 2015, the bindings and the examples found their way to the official distribution. Now they get updated by the maintainers. That doesn't happen often with FreeBASIC bindings. Anybody should help them to update their supported compilers information .

DISLIN is a good solution for the heavy stuff, like the Shaded Contour / Surface Plot in the above link. But using it isn't really fun. The API is a bit outdated, and GooCanvas/Cairo provides much more features to fine style the output. And it's more easy to integrate in WYSIWYG applications.

Regards
TJF
Posts: 3486
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Creating (scientific) plots via gnuplot

Postby TJF » May 20, 2019 9:13

aurelVZAB wrote:It is not 3D than 2D colored ploting.
I already ask(talk with) jj on another forum.
So it is about scientific plots..yes is not with gnuplot.
I think that should be created with any drawing functions if we know proper formulas.
I don't know how complex might be ..
Perhaps a simple X / Y regression analysis may meet your needs?
dodicat
Posts: 5984
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Creating (scientific) plots via gnuplot

Postby dodicat » May 20, 2019 13:22

Thanks TJF.

Here is some dislin code for the original voltage over current display.

Code: Select all

#INCLUDE "dislin.bi"

dim as double current(...) = {120, 125, 122, 119, 134, 138, 141, 159, 162, 178}
dim as double voltage(...) = {250, 210, 180, 155, 140, 125, 110, 100, 90, 80}

metafl ("cons")
disini()
pagera()
complx()
axspos(450,1700)
axslen(2200,1200)

name_("Current [A]","x")
name_("Voltage [V]","y")

labdig(-1,"x")
ticks(5,"x")
ticks(5,"y")

titlin("Voltage over Current",2)

var ic=intrgb(0.95,0.95,0.95)
axsbgd(ic)

graf(100.,200.,100.,10.,0.,300.,0.,50.)
setrgb(0.7,0.7,0.7)
grid(1,1)

color_("fore")
height(60)
title()

color_("blue")
for n as long=0 to 8
    rline(current(n),voltage(n),current(n+1),voltage(n+1))
next

disfin()

 
jj2007
Posts: 1259
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Creating (scientific) plots via gnuplot

Postby jj2007 » May 20, 2019 15:19

dodicat wrote:Here is some dislin code for the original voltage over current display.
I found inc\dislin.bi but the linker is not happy: ld.exe: cannot find -ldismgc

I have also downloaded the MediaFire dislin.zip but there is no readme explaining where the files should end up, relative to fbc.exe.
Carlos Herrera
Posts: 78
Joined: Nov 28, 2011 13:29
Location: Dictatorship

Re: Creating (scientific) plots via gnuplot

Postby Carlos Herrera » May 20, 2019 16:40

jj2007 wrote:
dodicat wrote:Here is some dislin code for the original voltage over current display.
I found inc\dislin.bi but the linker is not happy: ld.exe: cannot find -ldismgc

I have also downloaded the MediaFire dislin.zip but there is no readme explaining where the files should end up, relative to fbc.exe.

Go to the dislin page (https://www.mps.mpg.de/dislin/win-64-bit). You will find there the official distribution for Freebasic.
BTW, it was me who told Helmut Michels (dislin author) about the existence of FB.
Carlos
jj2007
Posts: 1259
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Creating (scientific) plots via gnuplot

Postby jj2007 » May 20, 2019 17:05

Carlos Herrera wrote:Go to the dislin page (https://www.mps.mpg.de/dislin/win-64-bit). You will find there the official distribution for Freebasic.
No luck (I hate working with environment variables, but for the sake of testing this I set them...):

Code: Select all

*** compiling TmpFb.bas with -t 2000 -gen gcc -Wc -Ofast -s console (32-bit GCC) ***
*** DisLin: \AllBasics\FreeBasic\lib\DisLin ***
*** The Path: \AllBasics\FreeBasic\;\AllBasics\FreeBasic\lib\DisLin\win ***
gcc version 8.1.0 (2018)
\AllBasics\FreeBasic\bin\win32\ld.exe: cannot find -ldismgc
dodicat
Posts: 5984
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Creating (scientific) plots via gnuplot

Postby dodicat » May 20, 2019 17:35

jj2007
As with freebasic in general, have the dll alongside the .bas code.
So just run the code from within the dislin folder from mediafire.
If you do this then the dislin.bi inside the same folder will be used.
(I think I have included newdislin.bi in some examples, should be dislin.bi, you should change them - sorry)
-ldismgc is not the one for you here.
#inclib "dislnc is written in your downloaded dislin.bi, which calls dislnc.dll in the downloaded folder.
Environment is not touched.
Remember all is 32 bits.

If there is any more fluffing around with this plotting business It would be easier to do it all in fbgfx.
aurelVZAB
Posts: 291
Joined: Jul 02, 2008 14:55
Location: Croatia
Contact:

Re: Creating (scientific) plots via gnuplot

Postby aurelVZAB » May 20, 2019 18:18

hi dodicat,jj,tjf...all

I would like to see this plotting using fbgx better than those external libs.
badidea
Posts: 1581
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Creating (scientific) plots via gnuplot

Postby badidea » May 20, 2019 18:25

dodicat wrote:If there is any more fluffing around with this plotting business It would be easier to do it all in fbgfx.

That would be perfect. But a flexible plotting tool that also creates good looking plots is a lot of work I think.
Some simple plotting routines can be done quickly as I have done in this project:
Image
It plots a charged particle trajectory in a B-field created by a set of coils.
jj2007
Posts: 1259
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Creating (scientific) plots via gnuplot

Postby jj2007 » May 20, 2019 18:58

I followed exactly the instructions and get this:

Code: Select all

gcc version 8.1.0 (2018)
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(6) error 41: Variable not declared, metafl
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(7) error 41: Variable not declared, disini
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(8) error 41: Variable not declared, pagera
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(9) error 41: Variable not declared, complx
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(10) error 41: Variable not declared, axspos
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(11) error 41: Variable not declared, axslen
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(13) error 41: Variable not declared, name_
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(14) error 3: Expected End-of-Line, found 'name_'
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(16) error 41: Variable not declared, labdig
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(17) error 41: Variable not declared, ticks
C:\FreeBasic\lib\DisLin\tmp\TmpFb.bas(17) error 132: Too many errors, exiting

Maybe we should open a dedicated thread "How to write a library installer for FreeBasic on Windows"?
aurelVZAB
Posts: 291
Joined: Jul 02, 2008 14:55
Location: Croatia
Contact:

Re: Creating (scientific) plots via gnuplot

Postby aurelVZAB » May 20, 2019 19:09

JJ
just use mediafire link and download zip pack into FB examples folder
Unzip package.
Then i use Jose Roca CSED-FB version ( i changed SciLexer to 3.7.4.0)
and open examples from new Dslin folder.
then in Csed- compile....wait
Run..wait..
and work on my win7 machine
dodicat
Posts: 5984
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Creating (scientific) plots via gnuplot

Postby dodicat » May 20, 2019 19:48

You can unpack the dislin folder on the desktop.
Put my above snippet into the dislin folder and run it.
Then test the other examples.
No sense in going anywhere near the fb distribution folders unless you want to perhaps keep hold of dislin, then pop the folder somewhere you know, as suggested, perhaps the FB examples folder.
I presume your ide can pick up and run a .bas file from any location.
jj2007
Posts: 1259
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Creating (scientific) plots via gnuplot

Postby jj2007 » May 20, 2019 20:11

Thank you all for your attempts to help me, but I am out. Most of these "additional" packages suffer from the same problems: they require environment variables to be set, specific folders, specific IDEs, no installation instructions, and conflicting advice from people who managed to get them running through hours of trial and error. I have never seen a BASIC dialect that was so confused, sorry...
TJF
Posts: 3486
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Creating (scientific) plots via gnuplot

Postby TJF » May 20, 2019 20:36

Carlos Herrera wrote:BTW, it was me who told Helmut Michels (dislin author) about the existence of FB.
... and you told him about the existence of my bindings/examples. Now Helmut is happy! He ships the source code of translated examples and bindings for a further programming language. But unfortunately he does not ship the original copyright messages. Poor style :-(

aurelVZAB wrote:hi dodicat,jj,tjf...all

I would like to see this plotting using fbgx better than those external libs.
That's why I pointed you to a clean fbgfx solution by
TJF wrote:Perhaps a simple X / Y regression analysis may meet your needs?
Of course, it's up to you to replace the gray scaling by a coloured scaling to meet your needs.

Regards
dodicat
Posts: 5984
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Creating (scientific) plots via gnuplot

Postby dodicat » May 20, 2019 20:46

jj2007
Perhaps your ide!
Here is a windows quickrunner.
Compile to .exe.
click the .exe.
Find your compiler via select compiler.
For the dislin examples get a 32 bit fb compiler.
Open, navigate to the dislin folder and choose an example (say curve.bas)
press compile then run (the compile run is in effect a quick run mode).
You can set some optimisations in the build options.

Code: Select all


'quickrunner.bas
#define WIN_INCLUDEALL
#Include Once "windows.bi"
#Include once "/win/commctrl.bi"
#include "file.bi"
shell "title Compiler output"
'shell "color f0"
Dim Shared As String fbpath,s1,cd,cpy,L,original,content
dim shared as long filechanged,cleanend
cd=Curdir
Declare Function SetWindowTheme Lib "UxTheme.dll" Alias "SetWindowTheme"(As Any Ptr,As zstring Ptr,As zstring Ptr) As Long
Declare Sub getfiles(Byref SomeFile As OpenFileName,msg As String,flag As String)
Declare Sub CreateMessageWindow
Declare Function loadfile(file As String,flag As Long=1) As String
Declare Sub savefile(filename As String,p As String)
Declare Function getclipboard() As String
declare Function CreateToolTip(X As hwnd,msg As String="") As hwnd
' Globals (unavoidable)
Dim Shared As HFONT guiFont
Dim Shared As zString * 255 textMessage=""
textmessage=loadfile("Buildoptions.txt")
Dim As String tmp
savefile(cd+"\Clipboard.txt","")
fbpath=loadfile("CompilerPath.txt",0)

Dim Shared As Long flag
Dim Shared As HWND  MainWindow, MessageWindow,btn,btn2,runbut,compiler
Dim Shared As HWND EditBox, Button,msgon,label,bar2,label2,minilabel,clabel,file,clipboard
Dim Shared As Long trackpos
Dim Shared SomeFile As OpenFileName
Function WndProc(hWnd As HWND, msg As UINT, wParam As WPARAM, lParam As LPARAM) As LRESULT
   
    Select Case hWnd
   
    Case MainWindow 
        Select Case msg
       
        Case WM_PAINT
            Dim As PAINTSTRUCT ps
            BeginPaint(hWnd, @ps)
            FillRect(ps.hdc, @ps.rcPaint, CreateSolidBrush(BGR(100,100,255)))
            EndPaint(hWnd, @ps)
           
        Case WM_CLOSE
            Kill   cd+"/buildoptionsTEMP.exe"
            Kill   cd+"/BuildoptionsTEMP.bas"
            Kill   cd+"/Clipboard.txt"
            if filechanged then
            var answer=messagebox(0,"Has changed,save?",cpy,MB_YESNO)
            if answer=IDYES then:end if
            if answer=IDNO then
               savefile(original,content)
            end if
            end if
            cleanend=1
            PostQuitMessage(NULL)
           
        Case WM_COMMAND
            Select Case lParam 
            Case msgon
                CreateMessageWindow
               
            Case clipboard
                L=getclipboard
                savefile("Clipboard.txt",L)
                cpy="clipboard.txt"
                setwindowtext(file,"File" +Chr(13,10)+cpy)
                Goto label
               
            Case btn 'open
                filechanged=0
                getfiles(SomeFile, "FreeBASIC Files","*.bas")
                s1=*SomeFile.lpstrFile
                cpy=s1
                original=s1
             
                setwindowtext(file,"File" +Chr(13,10)+cpy)
                L=loadfile(s1,3)
                content=L
                label:
                savefile(cd +"/BuildoptionsTEMP.bas",L)
                s1=cd+"/BuildoptionsTEMP.bas"
                ShellExecute (0,"","notepad.exe ",cpy,"",SW_SHOWNORMAL)
               
            Case btn2'compile
                If Len(s1) Then
                    textmessage=loadfile(cd+"\Buildoptions.txt",3)
                    s1=" "+cd+"/BuildoptionsTEMP.bas"
                    s1+=" "+textmessage+" "
                    var tst1=loadfile(cpy,3)
                    var tst2=loadfile(cd +"/BuildoptionsTEMP.bas",3)
                    if tst1<>tst2 then
                        filechanged=1
                       
                        savefile(cd+"/BuildoptionsTEMP.bas",tst1)
                       
                        end if
                 
                    Dim As String tm="Command "+Chr(13,10)+fbpath+Chr(13,10)+s1
                    setwindowtext(clabel,tm)
                 
                    Shell   fbpath+s1
                   
                Else
                    messagebox(0,"No file chosen","",0)
                End If
            Case runbut
               
                Dim As String tm="Command "+Chr(13,10)+cd+"/buildoptionsTEMP.exe"
                setwindowtext(clabel,tm)
               
                If Fileexists (  cd+"/buildoptionsTEMP.exe")  Then
                    ShellExecute (0,"", cd+"/buildoptionsTEMP.exe","","",SW_SHOWNORMAL)
                End If
               
            Case compiler'select a compiler
                getfiles(SomeFile, "Fbc.exe","fbc*.exe")
                s1=*SomeFile.lpstrFile
                if instr(s1," ") then s1=chr(34)+s1+chr(34) '''''''''''''''
       
                savefile(cd+"/CompilerPath.txt",s1)
             
                fbpath=loadfile(cd +"/CompilerPath.txt",3)
             
               
                setwindowtext(label, fbpath)
               
            End Select
           
        End Select
       
    Case MessageWindow 
        Select Case msg
        Case WM_COMMAND
            Select Case lParam 
            Case Button   
                GetWindowText(EditBox, @textMessage, 255)
                flag=0
                savefile(cd+"\buildoptions.txt",textmessage)
                destroywindow(messagewindow)
            End Select
           
        Case WM_CLOSE
            flag=0
        End Select
       
    End Select
   
    Return DefWindowProc(hWnd, msg, wParam, lParam)
End Function


' Create  window class:
Dim As WNDCLASS wcls

With wcls
   
    .style      = CS_HREDRAW Or CS_VREDRAW or CS_DROPSHADOW'
    .lpfnWndProc  = Cast(WNDPROC, @WndProc)
    .hInstance    = GetModuleHandle(NULL)
    .hIcon      = LoadIcon(NULL, IDI_APPLICATION)
    .hCursor      = LoadCursor(NULL, IDC_ARROW)
    .hbrBackground  = GetStockObject(WHITE_BRUSH)
    .lpszMenuName  = NULL
    .lpszClassName  = Strptr("WindowClass")
End With

If RegisterClass(@wcls) = FALSE Then
    MessageBox(NULL, "RegisterClass('WindowClass') FAIL!", "Error!", MB_OK Or MB_ICONERROR)
    End
End If


MainWindow = CreateWindowEx(NULL, "WindowClass", "Flag setter", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 650, 500, NULL, NULL, NULL, NULL)
msgon= CreateWindowEx(NULL, "Button", "Build options", WS_VISIBLE Or WS_CHILD , 10, 40, 90, 24, MainWindow, NULL, NULL, NULL)
btn=CreateWindowEx( 0,"BUTTON","Open", ws_border Or WS_VISIBLE Or WS_CHILD ,150,50,100,30,  MainWindow,0,0,0)
btn2  =createwindowex(0,"BUTTON","Compile"  ,ws_border Or WS_VISIBLE Or WS_CHILD,280,50,120,30,MainWindow,0,0,0)
runbut=createwindowex(0,"BUTTON","Run"  ,ws_border Or WS_VISIBLE Or WS_CHILD,430,50,120,30,MainWindow,0,0,0)
compiler=createwindowex(0,"BUTTON","Select Compiler"  ,ws_border Or WS_VISIBLE Or WS_CHILD,230,150,120,30,MainWindow,0,0,0)
label=createwindowex(0,"STATIC",fbpath , WS_VISIBLE Or WS_CHILD,0,200,600,60,MainWindow,0,0,0)
minilabel=Createwindowex(0,"STATIC","Compiler:"  ,WS_VISIBLE Or WS_CHILD,0,170,100,30,MainWindow,0,0,0)
clabel=createwindowex(0,"STATIC","Command " , WS_VISIBLE Or WS_CHILD,0,280,600,80,MainWindow,0,0,0)
file=createwindowex(0,"STATIC","File" , WS_VISIBLE Or WS_CHILD,0,380,600,60,MainWindow,0,0,0)
clipboard=CreateWindowEx( 0,"BUTTON","Clipboard", ws_border Or WS_VISIBLE Or WS_CHILD ,150,100,100,30,  MainWindow,0,0,0)

SetWindowTheme(mainwindow," "," ")
Sub CreateMessageWindow
    If flag=0 Then
        flag=1
        MessageWindow = CreateWindowEx(NULL, "WindowClass", "Options", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 300, 150, NULL, NULL, NULL, NULL)
        EditBox = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", textmessage, WS_VISIBLE Or WS_CHILD Or WS_HSCROLL  Or ES_AUTOHSCROLL Or ES_MULTILINE, 10, 0, 250, 50, MessageWindow, NULL, NULL, NULL)
        Button = CreateWindowEx(NULL, "Button", "Save", WS_VISIBLE Or WS_CHILD, 10, 70, 200, 24, MessageWindow, NULL, NULL, NULL)
       
        SetWindowTheme(messagewindow," "," ")'  optional
        createtooltip(EditBox,"-gen gcc -Wc -O3")
    End If
End Sub
Sub getfiles(Byref SomeFile As OpenFileName,msg As String,flag As String)
    Dim As zstring * 2048 SELFILE
    Dim As String MYFILTER
    MYFILTER = msg+Chr(0)+flag+Chr(0)
    With SomeFile
        .lStructSize = Sizeof(OpenFileName)
        .hInstance = null
        .lpstrFilter = Strptr(MYFILTER)
        .lpstrFile = @SELFILE
        .nMaxFile = 2048
        .nMaxFileTitle = 0
        .lpstrTitle =@"Open"
    End With
    GetOpenFileName(@SomeFile)
End Sub
Function loadfile(file As String,flag As Long=1) As String
    If flag=1 Then
        If Fileexists("Buildoptions.txt")=0 Then savefile("Buildoptions.txt","")
    End If
    If flag=0 Then
        If Fileexists("CompilerPath.txt")=0 Then savefile("CompilerPath.txt","")
    End If
    Var  f=Freefile
    Open file For Binary Access Read As #f
    Dim As String text
    If Lof(1) > 0 Then
        text = String(Lof(f), 0)
        Get #f, , text
    End If
    Close #f
    Return text
End Function

Sub savefile(filename As String,p As String)
    Dim As Integer n
    n=Freefile
    If Open (filename For Binary Access Write As #n)=0 Then
        Put #n,,p
        Close
    Else
        Print "Unable to save " + filename
    End If
End Sub
Function getclipboard() As String
    If IsClipboardFormatAvailable(CF_TEXT) = 0 Then Return "Error"
    If OpenClipboard(0) = 0 Then Return "Error"
    Function = *Cast(zstring Ptr,GetClipboardData(CF_TEXT))
    CloseClipboard()
End Function

Function CreateToolTip(X As hwnd,msg As String="") As hwnd
    Dim As hwnd  TT= CreateWindowEx(0,"ToolTips_Class32","",64,0,0,0,0,X,0,GetModuleHandle(0),0)
                                                           '64=bubble,0 = rectangle
    SendMessage(TT, TTM_SETMAXTIPWIDTH, 0 , 280)
    SendMessage(TT, TTM_SETDELAYTIME, TTDT_INITIAL ,40)
    SendMessage(TT, TTM_SETDELAYTIME, TTDT_RESHOW  ,60)
    Dim bubble As TOOLINFO
    bubble.cbSize = Len(TOOLINFO)
    bubble.uFlags = TTF_IDISHWND Or TTF_SUBCLASS
    bubble.uId = Cast(Uinteger,X)
    bubble.lpszText = Strptr(msg)
    SendMessage(TT, TTM_ADDTOOL, 0,Cast(LPARAM,@bubble))
    Return TT
End Function

Sub cleanup Destructor
    Kill   cd+"/buildoptionsTEMP.exe"
    Kill   cd+"/BuildoptionsTEMP.bas"
    Kill   cd+"/Clipboard.txt"
End Sub


Dim As MSG uMsg

While GetMessage(@uMsg, NULL, NULL, NULL) <> FALSE
    TranslateMessage(@uMsg)
    DispatchMessage(@uMsg)
Wend


   

(This is a last ditch stand to get you a runner)

Return to “Projects”

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests