Thread: GNUPLOT: Plotting multiple files.

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    12

    GNUPLOT: Plotting multiple files.

    Hi there,

    I was hoping someone can help me with this. I'll tell you a little about what I'm doing and then what I'm trying to do.

    I've programmed a numerical simulation in C, which outputs a data file on each iteration (time step). On average I could end up with 10's of .dat files, I've used a simple naming convention "data000.dat, data001.dat and so on.

    What I'm trying to do is to get GNUPLOT to create a plot of each of these .dat files . So lets say I have 200 data file, then I want to plot 200 graphs, one for each. The only thing that will change from graph to graph is the data plotted within.

    Do I need to write a script to do this?

    If so, does anyone know of tutorials I can use, or if anyone has any examples of how I can implement this.

    I know what I'm trying to do but I'm afraid I haven't a clue how to do it :-)

    Any help you can give will be much appreciated,

    Wayne.

    P.S. I know my last post was moved for being unclear, I'm going to refresh this page for the next hour so if you've any questions about what I'm trying to do, please don't hesitate to ask.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    This will end up being moved too, since it's not C. GNUPLOT knows how to read script files, so you should just write a file that sets all your parameters and then has a bunch of set output and plot commands. If you want, you can have your C file write out the script file too (when it writes out a data file, have it write the filename to the script file in the proper way).

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you search the forum for "gnuplot", I'm pretty sure you will find at least one thread that discusses various solutions for this particular problem, as it's been discussed before.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    I had a search last week but with no look, I'll try find a gnuplot specific forum. Thanks for your help though.

    All the best,

    Wayne.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    I seen these also last week, I PM'd them to see exactly what they did but to no avail I'm afraid. The thing is that simulations like this go on all over the world but sadly no-one documents how the visualization is done.

    tabstop I liked your idea about just outputing the name of the files into a ready made script from inside the c program.

    Do you know how I would go about inputting text onto a certain position in that script file?

    If not no worries.

    Thanks again.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by waynex View Post
    I seen these also last week, I PM'd them to see exactly what they did but to no avail I'm afraid. The thing is that simulations like this go on all over the world but sadly no-one documents how the visualization is done.

    tabstop I liked your idea about just outputing the name of the files into a ready made script from inside the c program.

    Do you know how I would go about inputting text onto a certain position in that script file?

    If not no worries.

    Thanks again.
    You could have a "template" text file, where you have "magic marker" to say "Here's where the output file goes", etc - for example read a file and search for "*+output+*", then replace that with your output file.

    But I would probably just put all the necessary text into the C source, and then use fprintf() to output the file, and as part of the output, form the output-filename.

    --
    Mats

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I've done similar things as this (assuming gpfile is my FILE* to the script and currfile is the
    filename that I'm currently writing:
    Code:
    fprintf(gpfile, "set terminal gif\n set xr [0,5]\n"); /* whatever your parameters are; done once */
    .
    .
    .
    fprintf(gpfile, "set output '%s.gif'\nplot '%s'\n"), currfile, currfile) /*after processing each file*/
    Usually I don't have an extension in my currfile (it's just data001, for example), so I don't get double-extension filenames, but if you're on a *nix that probably won't matter. (It might not matter on a Windows box either, I don't think I've tried.) Then you can just do "gnuplot gpfile", which might take a while.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GNUPLOT: Plotting multiple files.
    By waynex in forum Tech Board
    Replies: 3
    Last Post: 01-18-2008, 06:58 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. need assistance with multiple files
    By c++.prog.newbie in forum C++ Programming
    Replies: 7
    Last Post: 03-21-2006, 01:44 AM
  4. Windows shell commands - multiple files
    By Magos in forum Tech Board
    Replies: 3
    Last Post: 02-28-2006, 01:56 AM
  5. copy multiple files to a destination file
    By Bones in forum C++ Programming
    Replies: 2
    Last Post: 10-02-2003, 10:47 AM