Recent

Author Topic: TAplot procedure  (Read 5915 times)

bds

  • New member
  • *
  • Posts: 8
TAplot procedure
« on: June 03, 2015, 03:02:49 am »
I'm new to Lazarus but am an old turbo pascal hack.   I've gone through the plot demos and understand somewhat how to make plots with taplot.   But I'm missing an essential piece of info:

I'm writing a data analysis routine in pascal and am used to doing data analysis "the old way" -- LLS and NLLS fitting, FFT, numerical derivatives etc are each done in separate procedures which output an array of values.   Often one wants to plot the results of the fit or ? so one then calls a procedure -- I'll name it "do_plot" and passes to do_plot a record containing the x-axis and y-axis arrays to plot, axis and plot titles, flag for linear or log plot, flag for single plot vs over-plot of multiple data sets etc.   Such a procedure is useful when the analysis involves dozens or even 100's of plots without re-compiling the program.

The demos I've seen look a bit cumbersome for what I'm trying to do.  I'm sure many have written procedures like this but I'm looking for a demo with a plot procedure or the start of such a routine.   Can you point to some example of such a thing?

wp

  • Hero Member
  • *****
  • Posts: 5737
Re: TAplot procedure
« Reply #1 on: June 03, 2015, 06:29:44 am »
The problem with your request is that there are simply too many possibilities. The "do_plot" procedure would have a LOT of parameters.

Did you look at the tutorials? They give you step-by-step instructions of how to use the basic features: http://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Getting_started (plus many more - you find them with the link "Tutorials" at the bottom of the page).
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 5737
Re: TAplot procedure
« Reply #2 on: June 03, 2015, 04:50:37 pm »
I am enclosing a little demo which implements a Plot() procedure to which you pass arrays with the x and y values, as well as some parameters how to design the series. The code creates a line, cubic spline, b-spline or fit series for the data according to the parameters. There is another procedure, PrepareChart(), which is called when the first plot is added and which does basic things like axis labels, chart title, legend setup, colors etc. Both procedure are rather self-contained and you can use them in your own projects, they only need a chart added to a form. Of course, it is only a quick and dirty demo. Feel free to extend it if something is missing.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

jwdietrich

  • Hero Member
  • *****
  • Posts: 1011
    • formatio reticularis
Re: TAplot procedure
« Reply #3 on: June 03, 2015, 10:44:12 pm »
I am enclosing a little demo which implements a Plot() procedure to which you pass arrays with the x and y values, as well as some parameters how to design the series.

Thanks, this is excellent.  :)
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.2 | FPC 3.0.4 | PPC, Intel, ARM | macOS, Windows, Linux

bds

  • New member
  • *
  • Posts: 8
Re: TAplot procedure
« Reply #4 on: June 04, 2015, 01:20:23 am »
Excellent!!   Thanks so much!!

bds

  • New member
  • *
  • Posts: 8
Re: TAplot procedure
« Reply #5 on: June 04, 2015, 07:21:37 am »
After spending the day going through TAPlot demos and tutorials I have to say pascal without objects and classes is a beautiful tool -- students and other users can quickly understand even relatively complex code.  Once one is forced to go through class libraries to understand what is being done or to make modifications then 2 day jobs turn into 2 month jobs and the advantages of simplicity ease of use are lost....

Am I the only one that thinks that in the struggle for portability we've thrown out the baby with the bath water, so to speak?

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: TAplot procedure
« Reply #6 on: June 04, 2015, 08:27:30 am »
After spending the day going through TAPlot demos and tutorials I have to say pascal without objects and classes is a beautiful tool -- students and other users can quickly understand even relatively complex code.  Once one is forced to go through class libraries to understand what is being done or to make modifications then 2 day jobs turn into 2 month jobs and the advantages of simplicity ease of use are lost....

Am I the only one that thinks that in the struggle for portability we've thrown out the baby with the bath water, so to speak?
sorry you have to be a bit more precise than that. I do understand that some times it is frustrating to have to learn a new framework just to do be able to do the simplest of things and on top of that some open source frameworks are designed by amateurs or with no  design at all making them needlessly complicated or even unfit for the job outside a very narrow use case but other than that the speed and easy of use you get for the most of the cases is extra ordinary. I could say the same thing about rdbms and record based files for example, then again I have to know your frustration dealing with TAchart frameowrk before I can make any semi intelligent comment and even then I do not trust my intelligence very much.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

bds

  • New member
  • *
  • Posts: 8
Re: TAplot procedure
« Reply #7 on: June 04, 2015, 08:32:17 pm »
My frustration stems from the fact that there are 2 classes of users.   I'll call them "real programmers" and "scientist or engineer hacks".   I fall into the 2nd category (likely there are more classes but I simplify to make my point).   The real programmers have developed and use all these fancy widgets to make beautiful GUI programs.   There are scientists that use these tools as well but they are working on multi-month or multi-year analysis/simulation routines and can afford the overhead of coming up to speed with the graphics object and class libraries.  Many of us small-time "hack scientist" types want to run Numerical Recipes (you maybe remember this old book of pascal routines)-type numerical data analysis routines and are fine with console-based user interfaces generated with writeln and readln statements.  We often need to try something new and the datasets are large so can't easily do what we need to do with canned programs.   We understand the language and the algorithms we want to code and run.   But our focus is on solving a scientific problem and so don't have a lot of time to spend coming up to speed on the graphics aspect of the problem.  We want to generate a quick-and-dirty program that can easily be understood and modified by our students and co-workers.   This is the beauty of Pascal w/o classes. 

 So my big obstacle (and beef) is we only need the graphics to plot (or chart) our data.   Since we keep our code simple with simple procedures and functions, we need a procedure I call pretty_good_chart.   Something that can be easily made by a TAChart expert but takes a nubie a number or days or weeks to develop.  It will remain somewhat of a black box to us hack scientist types but that's not a problem since it's not something we'd like to change.  It would be nice if it had some of the beautiful features I find in some of the demos (like being able to expand a section of the plot by pointing at it with a mouse).   But it wouldn't have to.   It just needs to be simple to call (with some clear instructions) and hides inside it all the objects and classes that we really don't need to know about. 

wp

  • Hero Member
  • *****
  • Posts: 5737
Re: TAplot procedure
« Reply #8 on: June 04, 2015, 09:58:11 pm »
Quote
It just needs to be simple to call (with some clear instructions) and hides inside it all the objects and classes that we really don't need to know about.
Isn't that what above code is doing? You can even zoom and pan...

But I think your problem is that you are happy with a command line program like in the old Turbo Pascal days which you can debug from begin to end, no event handlers etc. That's fine, but then TAChart is not good for you. It is designed to work inside a gui, and gui means: objects, classes - all the things that you do not want.

In a commandline environment I would use an external graphics program to plot the data. Your words: "we only need the graphics to plot (or chart) our data". Do you know gnuplot? (www.gnuplot.info/) It is extremely powerful and its basics are very simple (but be warned: the learning curve to dig into its depths is as steep as with TAChart...): Just write the data calculated by your command line program to a file and then call gnuplot with the script:

Code: [Select]
plot 'data.txt' using 1:2'
(which means: x values are in the first, y values in the second column of file "data.txt").
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: TAplot procedure
« Reply #9 on: June 04, 2015, 10:28:57 pm »
I see so you are frustrated because you can't afford a multi-day learning period so you can easily do all the things that tachart can offer then again the simplicity of wp solution has added to your frustration?

Well as you can see the community of lazarus/fpc is a most helpful one, wp gave you a solution you can use it as a black box or ask farther questions, if you want something changed ask how it can be changed, we are all here in our free time so we do understand the pressure a project like that can put on you and we do strive to give advice/solutions as fast and as accurate as possible. Don't be afraid to use us, some of us even like the challenge some times. How you do use us is up to you, personally I would like to help you learn and become more interdependent  but just to write the code is good too, providing you are not a student of some kind I don't have any problem using my time to help by writing glue code.

Just take a breath and ease in to gui development in your own pace. In the mean time the community is here to guide and help as needed. Just don't come the last possible minute give your self and us time to respond properly.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

bds

  • New member
  • *
  • Posts: 8
Re: TAplot procedure
« Reply #10 on: June 05, 2015, 02:13:38 am »
You guys are great -- thanks for the help.   Maybe I'm missing something.   Was the project you sent supposed to just run?   I took it as some code that I was supposed to ponder and work on…   If it was supposed to just run then it didn't on my machine: Mac OS 10.6.8 running Lazarus 1.4.   I get this error:

Semaphone init failed (possibly too many concurrent threads).

Press OK to ignore…
Press Cancel to kill…

No matter what I do it hangs the machine.  Either option gives the next time I run the message "The IDE is still building"  But it never stops building.  Everything is total hung.   The only thing I can do is Force quit Lazarus and re-start.  Was this not the expected result?

bds

  • New member
  • *
  • Posts: 8
Re: TAplot procedure
« Reply #11 on: June 05, 2015, 02:16:00 am »
Sorry, I was wrong with the OS -- it's 10.7.5

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: TAplot procedure
« Reply #12 on: June 05, 2015, 02:33:47 am »
Its a complete application as far as I can see it should just run if everything is installed ok on your part. Having zero experience with apple hardware and software I'm afraid I cant help at all with that specific problem. It sounds very fishy though. Try to make sure that on the project options the use application bundle for running and debugging is checked if it is then try to execute it out side the IDE it self and see if that raises the same error. In sort this smell like a debugger issue not an IDE one. In any case if it runs outside the IDE with out problems then you will have to wait for a debugger knowledgeable person to comment on your problem. Sorry but not having access to MAC OS (not even in a VM) is a game stopper for me.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

bds

  • New member
  • *
  • Posts: 8
Re: TAplot procedure
« Reply #13 on: June 05, 2015, 04:05:16 am »
Thanks for the heads up that this should really work.   So I kept trying and trying and after 10+ failed attempts (a number of different failure modes actually…) in finally it works!!!     So thanks so much to you both!!   I'll have to sort out the reason for the problems but onto something more interesting….

I'm now putting together the analysis code I've written with this plot procedure and finding another stumbling block.  I use a number of writeln and readln statements to check things along the way and input parameters and case statement choices.  So I need both graphical form IO and terminal (console) IO.   I'm on a Mac so I do have access to a terminal window and the code runs fine w/o the addition of the graphics.   So now I have the chart I need a proper way to display and obtain IO from the terminal as well.  Hints on how to do this?

wp

  • Hero Member
  • *****
  • Posts: 5737
Re: TAplot procedure
« Reply #14 on: June 05, 2015, 11:10:17 am »
I don't have a Mac, but on Windows you can have WriteLn statements in a gui application if you uncheck "Win32 gui application" in "Config and Target" of the "Project Options" (Sure, the name suggests that this checkbox is only for windows, but who knows...)
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10