gnuplot parameter interchange

Discussion in 'C++' started by Bernhard Hidding, Jun 25, 2004.

  1. Hello,
    my c++ programm produces a variable number of ASCII files with variable file
    names. These are to be plotted in with gnuplot. I use

    system("gnuplot -persist my_gnuplot_script.gpl");

    to open gnuplot, and "my_gnuplot_script.gpl" contains a list of files to be
    plotted (e.g. plot "array13.dat", "array87.dat",...). However, each time the
    program runs, different files are to be plotted, so I have to change the
    file names in my gnuplot script manually each time. How can I hand over some
    parameters to gnuplot? Or would it be the easiest way to modify my .gpl
    script by my c++ program? If so, how do I do that?
    Thanks in advance,
    Bernhard Hidding

    -------------------------
    SuSE 9.1, g++ compiler
    Bernhard Hidding, Jun 25, 2004
    #1
    1. Advertising

  2. Bernhard Hidding wrote:
    >
    > Hello,
    > my c++ programm produces a variable number of ASCII files with variable file
    > names. These are to be plotted in with gnuplot. I use
    >
    > system("gnuplot -persist my_gnuplot_script.gpl");
    >
    > to open gnuplot, and "my_gnuplot_script.gpl" contains a list of files to be
    > plotted (e.g. plot "array13.dat", "array87.dat",...). However, each time the
    > program runs, different files are to be plotted, so I have to change the
    > file names in my gnuplot script manually each time. How can I hand over some
    > parameters to gnuplot? Or would it be the easiest way to modify my .gpl
    > script by my c++ program? If so, how do I do that?


    What you pass to system() is a string. Of course you can use a string
    variable also. And thus you have every freedom you want to come
    up with that string.

    #include <iostream>
    #include <cstdlib>
    #include <string>

    using namespace std;

    int main()
    {
    std::string CommandLine;
    std::string FileName;

    CommandLine = "gnuplot -persist ";

    cout << "Which file to plot?\n";
    cin >> FileName;

    CommandLine += FileName;

    cout << "Executing command: " << CommandLine << endl;
    system( CommandLine.c_str() );
    }

    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, Jun 25, 2004
    #2
    1. Advertising

  3. Thank you,
    but that is not quite what I intend to do. Maybe I did not make myself clear
    enough.
    In this case it is not enough to be able to chose between different gnuplot
    script files, but to generate a script file on the fly. Each time my program
    runs, a different script file would be needed, because each time new ASCII
    files with different names are being created which shall be plotted. My c++
    program contains all the data that the gnuplot script file would need to
    know. So, is it the easiest way to let my c++ program create the gnuplot
    script file and write it to disk, and call it after that? Or is there a
    convenient way to pass variables over to gnuplot?

    Bernhard
    Bernhard Hidding, Jun 25, 2004
    #3
  4. Bernhard Hidding wrote:
    >
    > Thank you,
    > but that is not quite what I intend to do. Maybe I did not make myself clear
    > enough.
    > In this case it is not enough to be able to chose between different gnuplot
    > script files, but to generate a script file on the fly.


    open script file
    write commands as text to script file
    close script file

    use system() to execute script file

    > Each time my program
    > runs, a different script file would be needed, because each time new ASCII
    > files with different names are being created which shall be plotted. My c++
    > program contains all the data that the gnuplot script file would need to
    > know. So, is it the easiest way to let my c++ program create the gnuplot
    > script file and write it to disk, and call it after that? Or is there a
    > convenient way to pass variables over to gnuplot?


    C++ knows nothing about gnuplot. There may be some way to control gnuplot
    through some interprocess mechanism.

    The simplest thing is .... see above

    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, Jun 25, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alythh

    Gnuplot module

    Alythh, Jul 23, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,893
    Yuchung Cheng
    Jul 28, 2003
  2. WideBoy
    Replies:
    0
    Views:
    470
    WideBoy
    Jan 4, 2006
  3. Sreejith K

    Interchange 2 nibbles of byte

    Sreejith K, Nov 14, 2003, in forum: C++
    Replies:
    4
    Views:
    479
  4. Edward Rutherford

    Type interchange

    Edward Rutherford, Nov 30, 2011, in forum: C Programming
    Replies:
    35
    Views:
    674
    Tim Rentsch
    Jan 25, 2012
  5. Bryan
    Replies:
    1
    Views:
    72
Loading...

Share This Page