Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why gnuplot cannot read my datafile?

12,137 views
Skip to first unread message

Uglyduckling

unread,
May 7, 2006, 8:40:28 PM5/7/06
to
Hi all,

My datafile is a .txt file named test, which has only two columns of
data. I try to load it using open button, but gnuplot cannot read it
and error always appears like the following:

gnuplot> 1.0000 13.5939
^
"C:\Documents ...\test.dat", line 1: invalid command


:( What's my problem? I appreciate any advice from you guys.

Yingying

Daniel Moeller

unread,
May 8, 2006, 5:33:57 AM5/8/06
to

Ist this the first line in your data file? Did you start with # X Y ?

Daniel Möller

Wilfried Hennings

unread,
May 8, 2006, 6:32:58 AM5/8/06
to
"Uglyduckling" <yyin...@hotmail.com> wrote:

How did you create your data file?
Make sure that you save the file as ANSI, not Unicode nor UTF-8.


--
email me: change "nospam" to "w.hennings"
Wilfried Hennings c./o.
Forschungszentrum (Research Center) Juelich GmbH, MUT
<http://www.fz-juelich.de/mut/mut_home>
All opinions mentioned are strictly my own, not my employer's.

Helmut Haefner

unread,
May 8, 2006, 7:12:07 AM5/8/06
to
Uglyduckling wrote:

> Hi all,
>
> My datafile is a .txt file named test, which has only two columns of
> data. I try to load it using open button, but gnuplot cannot read it

^^^^^^^^^^^^^^^^^^^^^^^^^
is this equivalent to the command?

load "<input-file>"

then of course this means that you try to open a datafile but using it like
a file with commands and settings for gnuplot.

instead you should try the commandline

plot "<datafile>"

plus more options you want to use.

Greetings Helmut


Uglyduckling

unread,
May 8, 2006, 10:22:13 AM5/8/06
to
I think a line starting with # is just comment. It should not be the
problem. And I tried to add "# X Y" as my datafile's 1st line, it
doesn't work either.

Uglyduckling

unread,
May 8, 2006, 10:28:33 AM5/8/06
to
How to make a datafile? I think that's my problem. For now I just
simply creat a .txt file using notepad. Is that ANSI code? I have no
idea.
How to save as ANSI?

Uglyduckling

unread,
May 8, 2006, 10:41:10 AM5/8/06
to
Actually, I tried to use the plot command, but what I got is this:
gnuplot>plot "C:\Documents and ...\test"
^
can't read data file "C:\Documents and ...\test"
or
gnuplot>plot "C:\Documents and ...\test.dat"
^
can't read data file "C:\Documents and ...\test.dat"

My datafile has no suffix. But I found that when I try to open it,
gnuplot always failed, but it added .dat to my datafile.


Wilfried Hennings

unread,
May 8, 2006, 11:07:30 AM5/8/06
to
"Uglyduckling" <yyin...@hotmail.com> wrote:

The Windows 98 version of Notepad always saves as ANSI.
The Windows XP version of Notepad saves as Unicode by default. To save
as ANSI, choose File - Save as - Coding: ANSI.
I'm not sure about the Windows 2000 version.

Wilfried Hennings

unread,
May 8, 2006, 11:17:02 AM5/8/06
to
"Uglyduckling" <yyin...@hotmail.com> wrote:

If it has NO suffix, give the filename without suffix.
If it HAS a suffix, include it.

The problem with your "plot" command is that gnuplot interprets the
backslashes in a special way. So your plot command should either be with
double backslashes

gnuplot>plot "C:\\Documents and ...\\test"

or with forward slashes

gnuplot>plot "C:/Documents and .../test"

Hans-Bernhard Broeker

unread,
May 8, 2006, 11:38:00 AM5/8/06
to
Wilfried Hennings <nos...@fz-juelich.de> wrote:

> backslashes in a special way. So your plot command should either be with
> double backslashes

> gnuplot>plot "C:\\Documents and ...\\test"

> or with forward slashes

> gnuplot>plot "C:/Documents and .../test"

Or single quotes:

gnuplot>plot 'C:\Documents and ...\test'

--
Hans-Bernhard Broeker (bro...@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Hans-Bernhard Broeker

unread,
May 8, 2006, 11:40:06 AM5/8/06
to
Uglyduckling <yyin...@hotmail.com> wrote:

> My datafile has no suffix.

Odds are that's not actually true. Beware of Microsoft's
breathtakingly stupid "innovation" not show the actual suffix by
default, and notepad's equally silly habit of putting an extra ".txt"
suffix on every file you save without an extension (or one it doesn't
recognize).

> But I found that when I try to open it, gnuplot always failed, but
> it added .dat to my datafile.

No, it didn't add anything.

Uglyduckling

unread,
May 8, 2006, 12:00:15 PM5/8/06
to
Hi,

I tried to save my file as ANSI and change backslash to forwardslash
for the plot command, but neither of them could help.

You know what, if I put some commands into my .txt file, gnuplot works
well, but not for data.

Yingying

Dan Luecking

unread,
May 8, 2006, 4:25:16 PM5/8/06
to
On 8 May 2006 07:41:10 -0700, "Uglyduckling" <yyin...@hotmail.com>
wrote:

>Actually, I tried to use the plot command, but what I got is this:
>gnuplot>plot "C:\Documents and ...\test"
> ^
> can't read data file "C:\Documents and ...\test"
>or

If you save a file in Notepad it may add the extension .txt. If that
extension has been associated to Notepad, the Windows default is to
not display that extension in folder windows.

In WinXP: Try opening the folder containing the data file, then choose
the Tools menu and Folder Options. Select the View tab and scroll down
to the box "Hide extensions for know file types". If it is checked,
uncheck it. Then click OK. Then you can see the full name of your
file.

If you don't want to go through all that (or if you don't have Windows
XP), try test.txt as your data file name. It might just work.


Dan
To reply by email, change LookInSig to luecking

*** Posted via a free Usenet account from http://www.teranews.com ***

Wilfried Hennings

unread,
May 10, 2006, 5:13:41 AM5/10/06
to
"Uglyduckling" <yyin...@hotmail.com> wrote:

If gnuplot executes commands in the .txt file but doesn't plot data, you
seem to mix up the "open" and the "plot" command.
"Open" opens a file in which gnuplot expects commands. This file can
also contain data, but only after the appropriate command. See
documentation.
Nevertheless, if you want to have a separate file containing only data,
put the necessary commands in a file test.plt, including a command
plot 'test.txt' (plus other required plot options)
then create a separate file test.txt containing your data.

You can choose file names and extensions as you like, as long as you
correctly tell them to gnuplot. If you use the menu command "open",
gnuplot expects a file extension .dat .

As Hans-Bernhard Broeker wrote, be aware that Windows hides some
extensions. I recommend you open explorer, choose Extras - Folder
options - View and uncheck "Hide extensions for known file types". (The
names of the options may be different in your version of Windows, that's
just my translation from my German Windows.)

Uglyduckling

unread,
May 10, 2006, 4:34:01 PM5/10/06
to
Let me finish our dicussion.

Actually, I find out that. To plot a datafile there are two ways.

1. Using open buttion to load it first. You may see a warning like: ...
line # : invalid command. It seems that gnuplot expect commands, not
data. But that's ok. Still you can plot it. Now the dirctory info to
your datafile is not needed. Just a command: plot "test.txt" or plot
'test.txt', both of them are ok.

2. Plot it directly. You have to tell gnuplot the directoy. This time
the command is: plot 'D:\...\test.txt'. Notice that plot
"D:\...\test.txt" doesn't work!

Finally, thank you all!

Hans-Bernhard Broeker

unread,
May 11, 2006, 5:50:13 AM5/11/06
to
Uglyduckling <yyin...@hotmail.com> wrote:

> 1. Using open buttion to load it first. You may see a warning like: ...
> line # : invalid command. It seems that gnuplot expect commands, not
> data. But that's ok.

Actually, no really. Loading that file is a rather spectacularly
circuituous way of changing the working directory of gnuplot to the
one the data file is in.

> 2. Plot it directly. You have to tell gnuplot the directoy. This time
> the command is: plot 'D:\...\test.txt'. Notice that plot
> "D:\...\test.txt" doesn't work!

It would, if you doubled the backslashes, or used forward slashes
in their place. I.e. all of the following will work:

plot "d:\\some\\place\\data.txt"
plot "d:/some/place/data.txt"
plot 'd:\some\place\data.txt'
plot 'd:/some/place/data.txt'
and
cd 'd:/some/place'
plot 'data.txt'

Dr Engelbert Buxbaum

unread,
May 12, 2006, 12:11:43 AM5/12/06
to
Uglyduckling wrote:

> Hi all,
>
> My datafile is a .txt file named test, which has only two columns of
> data. I try to load it using open button, but gnuplot cannot read it
> and error always appears like the following:
>
> gnuplot> 1.0000 13.5939
> ^
> "C:\Documents ...\test.dat", line 1: invalid command

That is Gnuplots delicate way of telling you that it does not know what
to do with your data; you have to supply appropriate instructions. You
can doe that on the command line of the Gnuplot window, or you can write
a little script (by convention with the ending .plt, but that is not
required), which in the most simple case needs only a single line:

plot "test.txt" with lines

This will create a 2D-plot with the data in the first column used for
the x-axis, and the second column for y. The plot will be scaled
automatically. The data points will be connected by straight line
segments. Use "points" instead of "lines" to have the data points marked
by symbols, or "linespoints" to have both.

Your Gnuplot installation directory (most likely "program files/gnuplot"
if you are on Wintel) should contain a Demo subdirectory with examples
what wonderful things Gnuplot can do for you, if you bother to learn its
scripting language. Note that the command files in this case have the
ending .dem, not .plt

0 new messages