Creating (scientific) plots via gnuplot

User projects written in or related to FreeBASIC.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Creating (scientific) plots via gnuplot

Post by jj2007 »

@dodicat: Thanks, I got your program running after a while using WinFBE, but it fails on the DisLin examples. Same crappy error list as above. All my other stuff works just fine - for example, this Windows template:

Code: Select all

#Include "windows.bi"
Dim Shared as Handle hEdit
Function WndProc(hWnd As HWND, msg As  UINT, wParam As WPARAM, lParam As LPARAM) As LRESULT
  Dim As RECT rc
  Dim As PAINTSTRUCT ps
  Dim As HANDLE PtDC
  Select Case msg
  Case WM_CREATE
	hEdit=CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "Hello, I am an edit control",_
	WS_CHILD Or WS_VISIBLE or ES_MULTILINE, 0, 0, 100, 100, hWnd, 100, 0, 0)
  Case WM_PAINT
	PtDC=BeginPaint(hWnd, @ps)
	TextOut(PtDC, 3, 3, "TextOut in the WM_PAINT handler", 31)
	EndPaint(hWnd, @ps)
  Case WM_KEYDOWN
  	if wParam=VK_ESCAPE then SendMessage(hWnd, WM_CLOSE, 0, 0)
  Case WM_SIZE
	GetClientRect(hWnd, @rc)
	MoveWindow(hEdit, 3, 23, rc.right-6, rc.bottom-26, 0)
  Case WM_DESTROY
      PostQuitMessage(0)
  End Select
  return DefWindowProc(hwnd, msg, wParam, lParam)
End Function

Function WinMain(hInstance As HINSTANCE, hPrevInstance As HINSTANCE, lpCmdLine As LPSTR, nShowCmd As Integer) As Integer
   Dim As WNDCLASSEX wc
   Dim As MSG msg
   Dim As string classname="FbGui"
   wc.cbSize = sizeof(WNDCLASSEX)
   wc.hbrBackground = COLOR_BTNFACE+1
   wc.hCursor = LoadCursor(0, IDC_ARROW)
   wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION)
   wc.hIconSm = wc.hIcon
   wc.hInstance = hInstance
   wc.lpfnWndProc = @WndProc
   wc.lpszClassName = StrPtr(classname)
   wc.style = CS_HREDRAW Or CS_VREDRAW
   RegisterClassEx(@wc)

   if CreateWindowEx(0, wc.lpszClassName, "Hello World",_
	WS_OVERLAPPEDWINDOW Or WS_VISIBLE, (GetSystemMetrics(SM_CXSCREEN) / 2) - 150,_
	(GetSystemMetrics(SM_CYSCREEN) / 2) - 150, 300, 300, 0, 0, hInstance, 0)=0 then
		    MessageBox(0, "Creating hMain failed miserably", 0, MB_OK)
		    return 0
   End If

   While GetMessage(@msg, 0, 0, 0)
      TranslateMessage(@msg)
      DispatchMessage(@msg)
   Wend

   return msg.wParam
End Function
WinMain(GetModuleHandle(NULL), NULL, COMMAND(), SW_NORMAL)
Btw I found out a strange behaviour of WinFBE: If you open an existing source, e.g. the window template above, then paste another code, e.g. your example, then press F5 to compile it, then close the window, it will overwrite the old source without any warning. Really dangerous.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Creating (scientific) plots via gnuplot

Post by srvaldez »

in dislin.bi inclib probably was including the wrong or missing lib
btw, this thread has gone way off topic, one reason I have not participated, even this post is off topic.
Last edited by srvaldez on May 21, 2019 1:56, edited 2 times in total.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Creating (scientific) plots via gnuplot

Post by jj2007 »

Trial and error and a sleepless night are the solution to all problems, hooray!
Dodicat's original version (error 132: Too many errors, exiting):

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()
Some minor changes applied (compiles and runs just fine):

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}

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

Dislin.name("Current [A]","x")
Dislin.name("Voltage [V]","y")

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

Dislin.titlin("Voltage over Current",2)

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

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

Dislin.color("fore")
Dislin.height(60)
Dislin.title()

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

Dislin.disfin()
So it was basically a namespace problem. Plus, it didn't like name_ (with understroke). Now the interesting question is why dodicat's code compiles and runs fine on dodicat's computer ;-)
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Creating (scientific) plots via gnuplot

Post by aurelVZAB »

hey JJ
i am wondering why not work on your computer?
i use FB 1.05.0-win32 with jose CSED_FB.
Well this dislin is not bad but is not what i show in the post above .
look screenshot
Image
Last edited by aurelVZAB on May 21, 2019 9:18, edited 3 times in total.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Creating (scientific) plots via gnuplot

Post by dodicat »

jj2007
with your code
If I put

namespace dislin
#INCLUDE "dislin.bi"
end namespace

and put the underscores back on name and color

your code runs fine.

So what is going on with this namespace and underscore issue?


Your windows template also works with a couple of warnings.
Passing scalar as pointer, at parameter 10 of CREATEWINDOWEX()
and
Suspicious pointer assignment.

For freebasic I use the simplest of ides (fbide)
And I would use the quickrunner to test optimizing in gcc because fbide will not accept uppercase on the command flags (-O3)
But I did also test running some dislin examples straight from the dislin folder with WinFBE and found no hiccups.

Win 10 32 bit fbc 1.06.0 for the dislin examples.


aurielVZAB
what is jose CSED_FB ?
I cannot see your screenshot, only an icon saying image.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Creating (scientific) plots via gnuplot

Post by aurelVZAB »

what is jose CSED_FB ?
I cannot see your screenshot, only an icon saying image.
It is well known Jose Roca CSED editor for FB
It is simple and good !i like it...

You cannot see screenshot ..well then something is disabled in your browser?
Yes ..what a crap Vivaldi(chrome) not show image , but K-Meleon (gecko) show.
So Firefox should show too..
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Creating (scientific) plots via gnuplot

Post by dodicat »

I cannot see the screenshot on Chrome or Firefox or Internet explorer.
My microsoft edge is not working, but it no great loss.
I tried my other machine with Linux Firefox, but there is no screenshot.
I think it is just one of those days to try the lottery.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Creating (scientific) plots via gnuplot

Post by jj2007 »

dodicat wrote:jj2007
with your code
If I put

namespace dislin
#INCLUDE "dislin.bi"
end namespace

and put the underscores back on name and color

your code runs fine.

So what is going on with this namespace and underscore issue?
I have no idea. Fact is that
- it compiles and runs fine with the Dislin.metafl ("cons") etc syntax, and without underscores for color and name
- it doesn't compile with the namespace thing you mention above: with or without Dislin., you get the full error list as above

Besides, given that you didn't include namespace in your original post, I guess that it compiled on your machine without that addition, right?

The plot itself looks fine, although the font looks a bit odd, and the window is not sizeable.Image
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Creating (scientific) plots via gnuplot

Post by dodicat »

jj2007
My origional code runs without any namespace.
I suppose it is a nice idea to put #include "dislin.bi" within a namespace and pluck out only the functions needed.
Regarding the scaling of the graph, looks like you can
axslen(2200-500,1200)
To shorten the x domain a little.
The font heights can be changed anywhere it seems.
Here are some of the fonts for windows

Code: Select all

namespace dislin
#INCLUDE "dislin.bi"
end namespace

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}


dislin.page (2970,2100) 'default
Dislin.metafl ("cons")
Dislin.disini()
Dislin.pagera()

'dislin.disalf
'dislin.simplx
'dislin.duplx
'dislin.triplx
dislin.gothic
'dislin.helve
'dislin.helves
'Dislin.serif
'dislin.complx

Dislin.axspos(450,1700)
Dislin.axslen(2200-500,1200)

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

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

Dislin.titlin("Voltage over Current",2)

var ic=Dislin.intrgb(0.95,0.95,0.95)
Dislin.axsbgd(ic)
Dislin.height(40) '
Dislin.graf(100.,200.,100.,10.,0.,300.,0.,50.)
Dislin.setrgb(0.7,0.7,0.7)
Dislin.grid(1,1)

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

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

Dislin.disfin() 
But I think the Gothic fonts were invented before electricity.

some info for dislin:
https://www2.mps.mpg.de/dislin/kap6.html#CHACOD
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Creating (scientific) plots via gnuplot

Post by aurelVZAB »

My microsoft edge is not working
hmm then i suspect something is wrong with your windows 10
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Creating (scientific) plots via gnuplot

Post by jj2007 »

dodicat wrote:My origional code runs without any namespace.
Quite mysterious indeed. Here only the version with Dislin.xxx but without namespace works.
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Creating (scientific) plots via gnuplot

Post by marpon »

@ aurelVZAB
in fact CSED_FB is an adaptation I have done for freebasic (with José Roca acceptance)

Happy to see you are still using my csed_fb adaptation, may we discuss in the related topic?
viewtopic.php?f=8&t=20731&p=260974#p260974
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Creating (scientific) plots via gnuplot

Post by marpon »

jj2007 wrote:
dodicat wrote:My origional code runs without any namespace.
Quite mysterious indeed. Here only the version with Dislin.xxx but without namespace works.
in fact it is not mysterious at all, you simply do not have the same configuration...

the old dislin.bi did not used namespace , it declared only the sub/functions and sometimes with alias for color , name ... to avoid duplicates

with the last evolutions for freebasic they used namespace to isolate the functions , it is good because they have a lot
and the risk of duplication is hight.

no mystery here...


I used dislin for some time now and was also interrested on avoiding the dll
i made a special dislin.bi and used the static lib included on the mingw package (32 or 64) they are providing

obviously the executable grew a lot but not need to share the dll, interresting if you want to distribute your exe
the difference in size for curves.bas around 27k to 555k depending on the fb version
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Creating (scientific) plots via gnuplot

Post by aurelVZAB »

Happy to see you are still using my csed_fb adaptation, may we discuss in the related topic?
hi marpoon
i don't know who made it ..ok
;)
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Creating (scientific) plots via gnuplot

Post by marpon »

to use the dislin static lib
download the package for c/c++ 32 or 64 mingw version
you will find 4 static libs
take the dismg.a or dismg_d.a (double version)

i renamed it libdislin32.a ( or libdislin64.a)
put it in the lib folder of your compiler 32 in 32 version 64 in 64 version

take the dislin.bi you got from the last freebasic package 32 or 64 they are differents
rename it to dislin32_stat.bi or dislin64_stat.bi
modify it like that

Code: Select all

#INCLIB "dislin32"    'the static library   replace the existing inclib  or "dislin64"

#ifdef __FB_WIN32__
	#inclib "gdi32"
	#inclib "winmm"
	#inclib "user32"
#elseif defined(__FB_LINUX__)
	#libpath "/usr/X11R6/lib"
	#inclib "X11"
	#inclib "Xext"
	#inclib "Xpm"
	#inclib "Xrandr"
	#inclib "Xrender"
	#inclib "pthread" '/
#endif
#include "gl\gl.bi"
and put the modified files on the inc folder of your compiler 32 or 64

after you can decide to use dll or static just by changing in the source code
#INCLUDE "dislin.bi"
by
#INCLUDE "dislin32_stat.bi" ' or "dislin64_stat.bi"

i only tested it with windows... and worked very well
Post Reply