Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#1322 EOL character handling under Windows different from Linux

5.0
closed-fixed
nobody
5
3 days ago
2014-01-20
John Edwards
No

Try to plot two data files using the following code :

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

void main()
{
  FILE * gnuplotPipe = _popen ("gnuplot -persist", "w");
  FILE * f1 = fopen("1.tmp", "w");
  FILE * f2 = fopen("2.tmp", "w");
  int i;

  for (i = 0; i < 5; i++)
  {
    fprintf (f1, "%lf %lf\n", (float)i, (float)i);
    fprintf (f2, "%lf %lf\n", (float)i, (float)i+1);
  }
  fclose (f1); fclose (f2);

  fprintf (gnuplotPipe, "plot \"1.tmp\" using 1:2 title \"Data set 0\" with lines lc rgb \"purple\", \\\n");
  fprintf (gnuplotPipe, " \"2.tmp\" using 1:2 title \"Data set 1\" with lines lc rgb \"green\"\n");
  fflush (gnuplotPipe);
  getchar ();
  fprintf (gnuplotPipe, "exit\n");
  _pclose (gnuplotPipe);
}

This works fine if I run the plot command in gnuplot from a script or if I use pgnuplot but when I use gnuplot I get the following error message :

gnuplot> plot "1.tmp" using 1:2 title "Data set 0" with lines lc rgb "purple", \
>
gnuplot>  '2.tmp' using 1:2 title "Data set 1" with lines lc rgb "green"
         ^
         invalid command

the following code works fine :

fprintf (gnuplotPipe, "plot \"1.tmp\" using 1:2 title \"Data set 0\" with lines lc rgb \"purple\", \\\r");

Note the \r rather than \n.

Discussion

  • Verified. Seems to be another side effect of the -persist option, which most likely doesn't do what you expect on Windows anyway. If this option is left out, the code works using \n:

    FILE * gnuplotPipe = _popen ("gnuplot", "w");
    
     
  • John Edwards
    John Edwards
    2014-01-21

    Thanks very much, Bastian,
    Much appreciated.
    Cheers,
    John

     
    • labels: Windows --> Windows, persist
    • status: open --> pending-fixed
     
  • In the meantime the initial problem with the line endings seems to have gone away in version 5. Instead, reading from a pipe wasn't done at all when in persist mode of console mode gnuplot. That is now fixed in CVS.

     
  • Ethan Merritt
    Ethan Merritt
    3 days ago

    • status: pending-fixed --> closed-fixed