views:

553

answers:

6

I have a small Win32 console application which is essentially a test harness. I read data in, do some processing on it and currently just output some of the numbers to the console. This isn't a huge problem - I can get an idea of what the data looks like, but it would be much easier to analyse if there was a way of getting that information into a graph for each run of the software.

I've been getting to grips with GNUPlot recently, but can't work out a simple way to get the data sent to it. Has anyone tried this? ..or is there another graphing application I should try?

[Edit] Excel and OO Calc are great tools and I've loaded .csv data into them for graphing data plenty of times myself. I was, however, hoping for a way to dynamically pipe data into a graphing application to avoid having to close/repoen excel and plot a graph each time I want to look at some data.

I think you can pipe data into GNUPlot (which is why I mentioned it) but the details of how to do so are rather scant.

+5  A: 

A simple approach is to wtite the data out as CSV and then import it into a spreadsheet like Excel or OpenOffice to do the graph drawing.

Edit: Following your question, I got interested in GNUPlot myself - this is the simplest description of using it from the command line that I found: http://www.goldb.org/goldblog/CommentView,guid,f378e279-eaa5-4d85-b7d2-0339a7c72864.aspx

anon
I've used similar approaches, but I was hoping for a more dynamic solution to avoid having to load up excel and plot a graph each time.
Jon Cage
You could use a little automation and VBA from your console app to tell Excel what data to read and what to do with it.
anon
That's an interesting idea I'd not considered. I've not written much VBA though and it's been years since I've tried. If you've any links for doing something like that, they'd be very gratefully received!
Jon Cage
Sorry, it's years since I did any automation work too.
anon
PS You might want to ask a second question specifically mentioning GNUPlot and giving the format of your data and the output you want. Don't forget to use the word "programmatically" in the question :-)
anon
Looks like there's already one about piping C++ into gnu plot which I overlooked [http://stackoverflow.com/questions/424455/c-and-gnuplot]
Jon Cage
+3  A: 

Never underestimate the power of Excel and a .csv data dump.

Writing data to a .csv file form C++ is not very difficult and there's lots of articles out there regarding the subject, for example: here, or just google.

Excel can easily load .csv's and then you can just use that to plot whatever graphs you require. THis is particularly useful if you just want a quick visual sanity check of results etc.

xan
Agreed - I do this all the time, but it's not the dynamic solution I was after. I'll revise my question a little...
Jon Cage
A: 

I just found an example of piping data into gnuplot on Cardiff University's website. Not tried it yet, but it looks promising!

[edit] ..and another which includes some notes for windows.

Jon Cage
+1  A: 

You might also want to look into XMGrace which allows you to launch it and drive it dircetly from C/Fortran programs as shown here

Randle Taylor
+1 > Interesting; I'll have a look at that..
Jon Cage
A: 

Excel is completely script-able. Use the macro recorder to figure out the steps. Create the chart in its own sheet. Then save the chart using the GIF filter.

The actual import is something like:

ActiveChart.Export FileName:=something_dot_gif, FilterName:="GIF"

Sanjaya R
+1  A: 

You don't really need to touch VBA to do this

In Excel you can set up a Data Connection to a file, it supports many files type but CSV does work fine.

  • Go to List item
  • Data Tab
  • Click Connections
  • Click Add
  • select the file
  • go to the connection properties - un-tick prompt for file name
  • set the required period.
  • close the connections dialog
  • select the start cell for importing the data - cell 1a on worksheet 2
  • click existing connections
  • select you data connection
  • flip to worksheet1 add your chart and hookup the data.

the chart will now update automatically

this is Excel 2007 - but think older version had this and I think OO can do it to.

Adrian
+1 > This looks like it could work. Commands in excel 2000 are a little different, but I think I see how to drive it. Looks like a nice simple solution which could be reused for future work - fantastic :)
Jon Cage