3

I have a dat file insert.dat

The contents are as follows:

1000    0.002322044 0.00291182
5000    0.000103257 0.000458963
10000   2.50E-05    0.000172019
20000   6.18E-06    6.03E-05
40000   2.51E-06    2.65E-05
60000   1.65E-06    1.71E-05
80000   1.21E-06    1.23E-05
100000  1.01E-06    9.97E-06

When I open the gnuplot.exe and type plot insert.dat with lines, I get a proper output but when I write a C# code as follows:

private  void GNUPlot()
{
    string pgm = @"E:\gnuplot\bin\gnuplot.exe";

    Process extPro = new Process();
    extPro.StartInfo.FileName = pgm;
    extPro.StartInfo.UseShellExecute = false;
    extPro.StartInfo.Standardization = true;
    extPro.Start();

    StreamWriter gnupStWr = extPro.StandardInput;
    gnupStWr.WriteLine("plot \"insert.dat\" with lines ");
    gnupStWr.Flush();
}

I get the following warning:

warning: Skipping unreadable file "insert.dat"

When I replace

gnupStWr.WriteLine("plot \"insert.dat\" with lines ");

with

gnupStWr.WriteLine("plot sin(x) ");

I get the required Sin(x) graph output.

insert.dat is in the current directory of gnuplot. I want insert.dat file data to be plotted.

6
  • Have you tried using single quotes around 'insert.dat' instead? Commented Jun 10, 2013 at 7:34
  • write a plot.p script and exec gnuplot plot.p Commented Jun 10, 2013 at 7:47
  • @AndersGustafsson Ya I tried 'insert.dat' too. It is still not working. It is giving the same warning Commented Jun 10, 2013 at 8:15
  • @Exceptyon Pls explain how to write.. Commented Jun 10, 2013 at 8:26
  • 1
    @guddi: I mean, if you execute "gnuplot script.p" from the command line, gnuplot will execute all the lines in script.p. So, I'd say write the script file from c# and simply invoke gnuplot with first argument the script filename... Commented Jun 10, 2013 at 9:34

1 Answer 1

3

The problem seems to be that gnuplot cannot find the requested file. The working directory of the process is not set to the gnuplot directory, but probably to the directory of the application that is calling gnuplot.

EDIT Try to add either of the following lines to your code somewhere before the extPro.Start() command:

extPro.StartInfo.WorkingDirectory = @"E:\gnuplot\bin";

or

Environment.CurrentDirectory = @"E:\gnuplot\bin";

If this is not working, it might be because your application does not have read access to that directory. Try placing your insert.dat file in a directory that with certainty can be accessed by any client application.

BTW, I also do not recognize the Standardization property that you are using? That line should rather read:

extPro.StartInfo.RedirectStandardInput = true;
Sign up to request clarification or add additional context in comments.

2 Comments

@guddi I have updated my answer with some additional information. In particular, are you sure that your application has read access to the gnuplot bin folder? The error message you are receiving is typical for the case when the file cannot be found (or accessed), the plot command by itself seems to be OK.
Thank You :) I got it. Now it is working. I wrote the script in file.gp and gave this file as an argument [link] (social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.