467,925 Members | 1,859 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,925 developers. It's quick & easy.

Plotting the Results

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

Nov 14 '05 #1
  • viewed: 1425
Share:
8 Replies
Freddy <zf********@gmail.com> wrote:
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.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #2
Freddy wrote:

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 */

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #3
how can I create the ascii graphics...these graphics should be more
than enough...

any help?

Freddy

Nov 14 '05 #4
Freddy <zf********@gmail.com> wrote:
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>
--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #5

"Freddy" <zf********@gmail.com> wrote

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.

Nov 14 '05 #6
> 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.

Nov 14 '05 #7

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
11**********************@g14g2000cwa.googlegroups. com, «*Freddy*»
<zf********@gmail.com> a écrit*:
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


Nov 14 '05 #8
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
11**********************@g14g2000cwa.googlegroups. com, «*Freddy*»
<zf********@gmail.com> a écrit*:
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


Nov 14 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bob Perlman | last post: by
3 posts views Thread by Erik Lechak | last post: by
6 posts views Thread by Gerrit Holl | last post: by
7 posts views Thread by Rolf Wester | last post: by
11 posts views Thread by Chapman | last post: by
1 post views Thread by T. Crane | last post: by
reply views Thread by Helmut Michels | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.