News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

plotting in masm 32 bit

Started by markallyn, March 06, 2018, 07:19:16 AM

Previous topic - Next topic

markallyn

Hello all,

I am looking for a plot library that is callable from masm.  If none such exists can someone come up with a relatively straightforward method for running gnuplot or similar from masm?

Regards,
Mark Allyn

jj2007

#1
I made a quick search, and there is a tutorial about the gnuplot dll. Calling a DLL from Masm is easy, the difficult part is understanding their manual, I guess 8)

What exactly do you want to plot? For simple line plots, there is ArrayPlot, see screenshot below (a more elaborate example is here). Here is a very simple application plotting a MySinus() array:

include \masm32\MasmBasic\Res\MbGui.asm
  Dim MySinus() As REAL4        ; prepare an array for being plotted (real4 or real8)
  For_ ct=-400 To 400
        SetFloat MySinus(ct+400)=Sinus(ct)
  Next
Event Paint
  ArrayPlot RgbCol(192, 222, 255)               ; init & set background
  ArrayPlot MySinus(), 0, lines=2               ; draw the array with 2px lines
  ArrayPlot exit, "Playing with Sinus() plots"  ; finish with a title
EndOfCode


See also Graphics demo.

P.S.: I've spent some time now trying to find alternatives; it's a mess. Gnuplot is popular, but it's a commandline tool, no chance to use it for an embedded control. There are others like GeoGebra, DPlot, MathPlotLib, but I haven't seen a simple tool that allows to plot data on a Windows control or DC. If somebody knows a lightweight plotting library that does that, please let us know... Wikipedia has a Free_plotting_software category, maybe it contains a hidden jewel.

jj2007

I found one more in my archives:

GuiParas equ "Bessel functions", x20, y20, w900, h250, bnone
include \masm32\MasmBasic\Res\MbGui.asm
  gsl double gsl_sf_bessel_J0(double x)
  gsl double gsl_sf_bessel_Jn (int n, double x)
  SetGlobals fct:REAL8
  gsl_INIT
  Dim Bessel0() As REAL8
  Dim Bessel1() As REAL8
  Dim Bessel2() As REAL8
  xor ecx, ecx                          ; array index
  For_ fct=-10.0 To 40.0 Step 0.04
        SetFloat Bessel0(ecx)=gsl_sf_bessel_J0(fct)
        SetFloat Bessel1(ecx)=gsl_sf_bessel_Jn(1, fct)
        SetFloat Bessel2(ecx)=gsl_sf_bessel_Jn(-3, fct)
        inc ecx
  Next
Event Paint
  ArrayPlot hWnd, RgbCol(240, 240, 240)        ; init with window (or control) handle and background colour
  ArrayPlot Bessel0(), RgbCol(255, 64, 64)     ; red
  ArrayPlot Bessel1(), RgbCol(64, 255, 64)     ; green
  ArrayPlot Bessel2(), RgbCol(64, 64, 255)     ; blue
  ArrayPlot exit, "             GSL: Regular cylindrical Bessel functions"       ; finish with a title
GuiEnd

markallyn

Good morning, Jochen,

Wow!  The GSL approach with MasmBasic produces exactly the sort of plots I'm interested in.  Unfortunately, I am not fluent in MasmBasic.  But, I will fool around with it.  I have it on my machine.

In your first response I note with interest the link to Gnuplot.  I'll check it out.

Thanks,
Mark

HSE

#4
Hi Mark!

You can see also ObjAsm32\Examples\Demo8. I also make an example, but I don't remeber why it's not uploaded. It's here . Requiere AsmC or Hjwasm with long lines (not .for, etc)
Equations in Assembly: SmplMath

markallyn

hello HSE.

I'm not familiar with objasm, but will investigate. 

I should have mentioned earlier to JJ that the plotting I want to do is to plot the numerical solution of ordinary differential equations.  What that entails is to take an array of doubles that are solution points and plot them.  The plots might make use of colors and different line styles plus axis labels (time, yout) and legends.  Nothing fancy.  JJ shows good examples above.

Regards,
Mark

HSE

That is my example  :t

    (not too easy, I'm afraid)
Equations in Assembly: SmplMath

jj2007

Quote from: markallyn on March 07, 2018, 01:51:35 AMThe GSL approach with MasmBasic produces exactly the sort of plots I'm interested in.  Unfortunately, I am not fluent in MasmBasic.  But, I will fool around with it.  I have it on my machine.

Hi Mark,

Use the 10 lines proggie in reply #1 as a template, it is a full-fledged Windows application. The syntax is unorthodox but not difficult. There is a lengthy thread on Event-driven programming explaining the logic. Here is another short example:

GuiParas equ "MasmBasic: fast, compact and easy to use", x50, y50, w1200, h666
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste

include \masm32\MasmBasic\Res\MbGui.asm         ; this line replaces include \masm32\include\masm32rt.inc

  ; any startup code - this is indeed the WM_CREATE handler
  Dim MySinus() As REAL4        ; prepare an array for being plotted (real4 or real8)
  For_ ct=-400 To 400
        SetFloat MySinus(ct+400)=Sinus(ct)      ; there are other ways to populate the array
  Next

Event Menu
  MsgBox 0, Str$("You clicked into menu entry #%i", MenuID), "Hello:", MB_OK

Event Paint
  ArrayPlot RgbCol(192, 222, 255)       ; init & set background
  ArrayPlot MySinus(), 0, lines=3, 00100204h   ; draw the array with 3px lines and left top right bottom margins
  ArrayPlot exit, "Playing with Sinus() plots"  ; finish with a title
  GuiTextBox 50.0-70, 40.0, 140, 96, Str$("Painting took %3f ms", GuiMs/1000), bcol RgbCol(160, 255, 192)
EndOfEvents    ; ----- end of event zone ----

MyAlgo proc    ; ----- start of user-defined procs ----
  ret
MyAlgo endp

EndOfCode

markallyn

Good morning/afternoon, Jochen,

After studying your example a bit I realized it could be/should be a template for what I want to accomplish.  By the time that penetrated my thick skull it was too late in the day to do anything about it.   But today is a new day.

One point of clarification regarding gnuplot:  In my gnuplot distro there is no single gnuplot.dll.  There are a bunch of Linux derived .dll's (pango, etc.), but I don't see a gnuplot.dll.  So, what to load to do the job--should I wish to try it in this fashion--is problematic.

Second:  You obviously are fully aware of GSL and have used it.  I have too, but in C applications, never assembler.  I love GSL.  But, I don't see how I would use it.  There is also OCTAVE which has plot routines in it.  I haven't looked into how one might use them, however.

Thanks for taking an interest in this.

Regards,
Mark

LiaoMi

Quote from: markallyn on March 06, 2018, 07:19:16 AM
Hello all,

I am looking for a plot library that is callable from masm.  If none such exists can someone come up with a relatively straightforward method for running gnuplot or similar from masm?

Regards,
Mark Allyn

Hi markallyn,

look at the library - MathGL http://mathgl.sourceforge.net/doc_en/Main.html
Book  ::) - http://downloads.sourceforge.net/mathgl/mathgl-2.4.1.eng.pdf
MathGL utilities with all required DLL files for 32-bit and 64-bit versions of MS Windows http://downloads.sourceforge.net/mathgl/mgl_scripts-2.4.1.win32.7z and http://downloads.sourceforge.net/mathgl/mgl_scripts-2.4.1.win64.7z



Pictures
http://mathgl.sourceforge.net/doc_en/Pictures.html#Pictures



MathGL is ...
a library for making high-quality scientific graphics under Linux and Windows;
a library for the fast data plotting and data processing of large data arrays;
a library for working in window and console modes and for easy embedding into other programs;
a library with large and growing set of graphics.
Now MathGL has more than 35000 lines of code, more than 55 general types of graphics for 1d, 2d and 3d data arrays, including special ones for chemical and statistical graphics. It can export graphics to raster and vector (EPS or SVG) formats. It has Qt, FLTK, OpenGL interfaces and can be used even from console programs. It has functions for data processing and script MGL language for simplification of data plotting. Also it has several types of transparency and smoothed lightning, vector fonts and TeX-like symbol parsing, arbitrary curvilinear coordinate system and many over useful things. It can be used from code written on C++/C/Fortran/Python/Octave and many other languages. Finally it is platform independent and free (under GPL v.2.0 license).


Tutorial: How to compile a glut version of MathGL 2.2 with Visual Studio 2010 on Windows - https://groups.google.com/forum/#!topic/mathgl/t-X9eg-5joU You can transfer to a new build from 2017  :t

I still can not compile a smaller library, cmake gives a nonsense, when the smaller library is compiled, we can convert the headers  :icon_cool: and try in action on examples!

jj2007

Quote from: LiaoMi on March 08, 2018, 04:14:41 AMlook at the library - MathGL http://mathgl.sourceforge.net/doc_en/Main.html

Looks interesting. Have you tried it yourself? For example, what would be the equivalent MathGL code to the demo below (exe attached)?

include \masm32\MasmBasic\Res\MbGui.asm
  Dim MySinus() As REAL8        ; prepare an array for being plotted (real4 or real8)
  Dim MyCosinus() As REAL4

  For_ ct=-400 To 400
        SetFloat MySinus(ct+400)=Sinus(ct)      ; fill two
        SetFloat MyCosinus(ct+400)=Cosinus(ct)  ; arrays
  Next

Event Paint
  ArrayPlot RgbCol(200, 255, 255)                      ; init & set background
  ArrayPlot MySinus(), RgbCol(255, 255, 0), lines=3    ; plot the sinus wave in yellow, 3px
  ArrayPlot MyCosinus(), RgbCol(0, 255, 0), lines=5    ; plot the cosinus wave in green, 5px
  ArrayPlot exit, "Sinus & Cosinus demo"               ; finish with a title
EndOfCode


LiaoMi

Hi jj2007,

I'll try as soon as I can compile the project  :icon_confused: Already now you can look at the api, which can be seen from the link "pictures". Here is an example

int sample(mglGraph *gr)
{
  mglData y;  mgls_prepare1d(&y); gr->SetOrigin(0,0,0);
  gr->SubPlot(2,2,0,"");  gr->Title("Plot plot (default)");
  gr->Box();  gr->Plot(y);

  gr->SubPlot(2,2,2,"");  gr->Title("'!' style; 'rgb' palette");
  gr->Box();  gr->Plot(y,"o!rgb");

  gr->SubPlot(2,2,3,"");  gr->Title("just markers");
  gr->Box();  gr->Plot(y," +");

  gr->SubPlot(2,2,1); gr->Title("3d variant");
  gr->Rotate(50,60);  gr->Box();
  mglData yc(30), xc(30), z(30);  z.Modify("2*x-1");
  yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)");
  gr->Plot(xc,yc,z,"rs");
  return 0;
}


the result is


LiaoMi

To exclude Qt and apply the code only with OpenGL, we need to compile a new VS17 project, two libraries can be used:

GLUT 3.7.6 pre-compiled libs (32 and 64): http://www.ece.lsu.edu/xinli/OpenGL/glut-3.7.6-bin-32and64.zip
GLUT 3.7.6 source codes: http://www.ece.lsu.edu/xinli/OpenGL/glut-3.7.6-src-32and64.zip

freeglut 3.0.0 MSVC Package (32 and 64) https://www.transmissionzero.co.uk/files/software/development/GLUT/freeglut-MSVC.zip

markallyn

good afternoon/evening Jochen,

OK.  I downloaded uasm32, then copied your code as jjdraw.asm and ran a little .bat file (makejjdraw.bat).  Got an error in assembly step I don't understand.  Here's a copy of the assembler output:
Quote
UASM v2.46, Feb  1 2018, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

*** MasmBasic version 25.12.2017 ***
** SetProcessUserModeExceptionPolicy
\masm32\MasmBasic\Res\MbGui.asm(2339) : Error A2164: Empty (null) string
repargA(85)[MasmBasic.inc]: Macro called from
  uChr$(1)[MasmBasic.inc]: Macro called from
   \masm32\MasmBasic\Res\MbGui.asm(2339): Included by
    jjdraw.asm(1): Main line code
## MasmBasic GUI build ##
jjdraw.asm: 10 lines, 1 passes, 256 ms, 0 warnings, 1 errors
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file "jjdraw.obj"
Press any key to continue . . .

And here's a copy of the little .bat file:
Quote
@echo off
if exist jjdraw.obk del jjdraw.obj
..\uaSM32.exe /c /coff /Zi jjdraw.asm
..\bin\link.exe /subsystem:console /entry:main /debug /pdb:jjdraw.pdb /machine:X86 jjdraw.obj
pause

Could you suggest a "fix" to rid the code of bugs?

One other thing:  How would I plot an array of floats (output from a numerical integrator) using your nice masmbasic approach?

Regards,
Mark

markallyn

Good afternoon\evening, LiaoMi,

I will have to investigate more thoroughly later.  The drawings are really nice.  From the code you show, it looks like the calling program is in a high-level language similar to R, i.e. object-oriented, with arrows doing the assingments.  If so, there is most definitely a learning curve that is rather steep.  So, given that I wonder what the advantages might be compared to a scripting language like Gnuplot where the curve is quite shallow.

But, I will look more intensively.  Thanks for bringing this to my attention and also for the excellent examples.

Regards,
Mark