Plotting the Results

F

Freddy

Hi guys,

I have a quick question,

I have a program that generates numerical output (as most of the
programs), the program is written in C language, and currently I use
the "DOS interface to show the output when it is being generated.

is there a "short" and "non-complicated" code which plots the data
automatically instead of showing the numbers.

the plots don't have to be something very fancy...but instead of
on-line monitoring of the numbers, the output can plot them in "real
time" (as they are being generated)..

I am also trying to stay away from Visual C++ codes...just sticking to
C as much as possible...

I appreaciate your help

Thanks
Freddy
 
S

S.Tobias

Freddy said:
I have a program that generates numerical output (as most of the
programs), the program is written in C language, and currently I use
the "DOS interface to show the output when it is being generated.
is there a "short" and "non-complicated" code which plots the data
automatically instead of showing the numbers.

You won't get much help from standard C. If it's scientific
data, then IMHO it's best to keep output in files and
use another application to do the graphics.
the plots don't have to be something very fancy...but instead of
on-line monitoring of the numbers, the output can plot them in "real
time" (as they are being generated)..
I am also trying to stay away from Visual C++ codes...just sticking to
C as much as possible...

You have to look for a library (Sourceforge?) or program it yourself.
Or call an external program via system() function (it depends, of course,
on the program if you can display the plots real-time); or maybe
you could "cooperate" somehow with an external program. All this
is outside the interests of this group; try comp.programming.

One portable method that comes to my mind is to make ascii graphics
(like GNUplot does in dumb terminal mode) and allow them to
scroll up. Depends on what fanciness level you want to have.
 
C

CBFalconer

Freddy said:
I have a program that generates numerical output (as most of the
programs), the program is written in C language, and currently I use
the "DOS interface to show the output when it is being generated.

is there a "short" and "non-complicated" code which plots the data
automatically instead of showing the numbers.

the plots don't have to be something very fancy...but instead of
on-line monitoring of the numbers, the output can plot them in "real
time" (as they are being generated)..

I am also trying to stay away from Visual C++ codes...just sticking
to C as much as possible...

This may give you some ideas.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double pi;

/* ------------------- */

void pause(void)
{
/* fool around with the timers here if needed */
} /* pause */

/* ------------------- */

void plot(int angle)
{
double sine;
int isin;

sine = sin(pi * angle / 180);
isin = 30 * sine + 35.5;

printf("%4d %*c\n", angle, isin, '*');
} /* plot */

/* ------------------- */

int main(int argc, char *argv[])
{
int angle;

pi = 4 * atan(1.0);
for (angle = 0; angle < 3600; angle += 10) {
plot(angle);
pause();
}
return 0;
} /* main */
 
F

Freddy

how can I create the ascii graphics...these graphics should be more
than enough...

any help?

Freddy
 
S

S.Tobias

Freddy said:
how can I create the ascii graphics...these graphics should be more
than enough...

Probably yourself. Or use Gnuplot to do it for you.

In Gnuplot it looks like this:


gnuplot> set term dumb
Terminal type set to 'dumb'
Options are 'feed 79 24'
gnuplot> plot sin(x)


1 ++----------------**---------------+----**-----------+--------**-----++
+ *+ * + * * + sin(x) ****** +
0.8 ++ * * * * * * ++
| * * * * * * |
0.6 ++ * * * * * * ++
* * * * * * * |
0.4 +* * * * * * * ++
|* * * * * * * |
0.2 +* * * * * * * ++
| * * * * * * * |
0 ++* * * * * * *++
| * * * * * * *|
-0.2 ++ * * * * * * *+
| * * * * * * *|
-0.4 ++ * * * * * * *+
| * * * * * * *
-0.6 ++ * * * * * * ++
| * * * * * * |
-0.8 ++ * * * * * * ++
+ * * + * * + * * +
-1 ++-----**---------+----------**----+---------------**+---------------++
-10 -5 0 5 10

gnuplot>
 
M

Malcolm

Freddy said:
is there a "short" and "non-complicated" code which plots the data
automatically instead of showing the numbers.

the plots don't have to be something very fancy...but instead of
on-line monitoring of the numbers, the output can plot them in "real
time" (as they are being generated)..

I am also trying to stay away from Visual C++ codes...just sticking to
C as much as possible...
No. There is no simple way of generating graphical data beyond ASCII art.

The easiest and most portable way is to output the file in an image format.
Unfortunately the two most useful formats, GIF and JPEG, are by no means
simple.
The other route is to use a platform-specific library for interactive
graphcs. It is normally not too difficult to get a window up on screen and
write a few strings of text and a scatter diagram or line graph to it.
However normally the code has to be set up in a special way which has big
implications for your program. It might be necessary to structure the flow
control around function pointers that are called when the mouse and keyboard
is pressed, for example.
 
?

=?iso-8859-1?q?C=E9dric_LEMAIRE?=

The easiest and most portable way is to
output the file in an image format.
Unfortunately the two most useful formats, GIF
and JPEG, are by no means simple.

The TGA format is very simple: a small header and 24 bits RGB for each
pixel. Recognized by drawing tools.
 
J

Jean-Claude Arbaut

You can try an external plotting program, like gnuplot. You can even
use gnuplot within a C program if you can use pipes (not under DOS
I think). If you must use DOS, you can easily program a small plotting
library in VGA or VESA mode. If you use TC, a VGA library is
integrated, but only in 16 colors. If you need 256 colors, VGA mode 13h
is very easy (but low res: 320x200). VESA modes are relatively easy to use,
and allow 24 bits RGB. IMO, you should really consider gnuplot
(gnuplot.sf.net).


Le 12/06/2005 16:16, dans
(e-mail address removed), « Freddy »
 
J

Jean-Claude Arbaut

And I forgot, you can write your plot in a file.
There are fairly easy file formats: BMP, TGA, PSD, SGI(RGB), and TIFF.
They all have a small header and (almost) raw image data.
If you need documentation, www.wotsit.org is the first place to look.


Le 12/06/2005 16:16, dans
(e-mail address removed), « Freddy »
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top