|
From: Ethan M. <merritt@u.washington.edu> - 2006-03-09 17:50:46
|
On Thursday 09 March 2006 09:03 am, Hans-Bernhard Br=C3=B6ker wrote: > What's the point of asking a question like "if fileexists", when > there's nothing useful that could be done with the answer, that we > can't already do later on, when a command actually tries to read it?=20 I am in 100% agreement with you. The discussion of Petr's xxx_exist() functions was a spin-off that was probably a total waste of time. My preferred method of dealing with this issue is to handle missing/empty files cleanly during the plotting process. That is relatively straightforward for 2D plotting from ascii files, and I have already posted a patch that does so. The code for binary files is a mess, and the 3D code is very different from the 2D code. So far I do not see an easy way to modify these code paths to handle missing files. Should I go ahead and apply the patch for 2D code, which is after all a major category of use? If inspiration (or code clean-up) strikes for the 3D/binary case we can deal with that later. For the present it would remain a known limitation that 2D plots can handle missing files cleanly, but 3D plots cannot. =2D-=20 Ethan A Merritt Biomolecular Structure Center University of Washington, Seattle WA |
|
From: Petr M. <mi...@ph...> - 2006-03-09 20:33:40
|
>> What's the point of asking a question like "if fileexists", when >> there's nothing useful that could be done with the answer, that we > I simply don't believe that either of these functions does something that > gnuplot has to do, or even *can* do meaningfully. The fileexist() is a long time on my done list, I needed that several times, so finally decided to commit it. Some applications: number of fit files, availability of extracted experimental data files. This function is a good candidate for the group of string-related functions for the "strings" patch which has become part of gnuplot recently. Based on the discussion: it is fully sufficient to have fileexist() for testing whether the given file exist. Nothing more (no pipes, no loadpaths). Thus I still wish to commit it (unless there is really still big big opposition). > My preferred method of dealing with this issue is to handle > missing/empty files cleanly during the plotting process. Gnuplot support files with palettes as well. > Should I go ahead and apply the patch for 2D code, > which is after all a major category of use? Yes. >> Trimmed from lines 1240-1280 of datafile.c: >> ========================================================================= >> /* filename cannot be static array! */ >> gp_expand_tilde(&df_filename); > This line makes sense only for regular files and thus it should be moved > to just above the "stat" function. And this change should be committed too. --- PM |
|
From: Daniel J S. <dan...@ie...> - 2006-03-10 00:18:05
|
Ethan Merritt wrote:
> On Thursday 09 March 2006 09:03 am, Hans-Bernhard Br=C3=B6ker wrote:
>=20
>>What's the point of asking a question like "if fileexists", when
>>there's nothing useful that could be done with the answer, that we
>>can't already do later on, when a command actually tries to read it?=20
I have to agree with Hans, too, Petr. If I understand, the idea is to mo=
nitor if a data file changes, then replot it. Or is it something else? =
I guess I'm looking for a bigger context of this. It just seems like som=
ething better dealt with using a little utility or daemon that monitors t=
he file then simply reissues the gnuplot command through a pipe.
At the same time, I'm wondering why gnuplot should plot something if any =
of its specified input files are not present. Shouldn't there be an erro=
r? =20
Now, Ethan raised an issue in one of our discussions about some method fo=
r conditionally checking the functionality of gnuplot so that the demos d=
on't fail if something isn't compiled inside gnuplot, rather they are sim=
ply skipped using proper adjustment of, say, all.dem. If that method exi=
sted, might it be possible to use that kind of thing for checking file ex=
istence of a file?
>=20
>=20
> I am in 100% agreement with you.
> The discussion of Petr's xxx_exist() functions was a spin-off
> that was probably a total waste of time.
>=20
> My preferred method of dealing with this issue is to handle
> missing/empty files cleanly during the plotting process.
> That is relatively straightforward for 2D plotting from ascii
> files, and I have already posted a patch that does so.
>=20
> The code for binary files is a mess, and the 3D code
> is very different from the 2D code. So far I do not see an
> easy way to modify these code paths to handle missing files.
This seems to be a clear case where any code for checking the existence o=
f a file should be at a higher level than binary/ascii/3D/2D. Are you sp=
eaking about the options part of binary? Or at a lower level of input on=
ce the options string has been processed?
> Should I go ahead and apply the patch for 2D code,
> which is after all a major category of use?
>=20
> If inspiration (or code clean-up) strikes for the 3D/binary
> case we can deal with that later. For the present it would
> remain a known limitation that 2D plots can handle missing
> files cleanly, but 3D plots cannot.
Could it be written generic? A little routine that can be called by the =
options handling no matter if it is 2D, 3D, ascii or binary? (We're talk=
ing at the options, level, right?)
I can probably help out with short patches on say, regarding what came up=
the other day (below), but I'd prefer some unification eventually.
Dan
*****
An alternative might be to move just this chunk of code:
#ifdef HAVE_SYS_STAT_H
struct stat statbuf;
if ((stat(df_filename, &statbuf) > -1) &&
!S_ISREG(statbuf.st_mode) && !S_ISFIFO(statbuf.st_mode)) {
os_error(name_token, "\"%s\" is not a regular file or pipe",
df_filename);
}
#endif /* HAVE_SYS_STAT_H */
which I think sort of checks the existence of the file without really ope=
ning it. And replace it with
#ifdef HAVE_SYS_STAT_H
struct stat statbuf;
if ((stat(df_filename, &statbuf) > -1) &&
!S_ISREG(statbuf.st_mode) && !S_ISFIFO(statbuf.st_mode)) {
os_error(name_token, "\"%s\" is not a regular file or pipe",
df_filename);
}
#else
if (<open fails>)
error("Can't open data file "xxx"");
else
close_file();
#endif /* HAVE_SYS_STAT_H */
Would that kind of thing work? That would mean if there is no "stat()" t=
hen the file would be opened and closed for checking existence (also chec=
k for emptiness?), then after options are checked opened again for readin=
g.
Or would you prefer opening and keeping track of the file pointer and doi=
ng a "close" before each instance of "error()"?=20
|
|
From: Ethan M. <merritt@u.washington.edu> - 2006-03-09 22:55:44
|
> > Based on the discussion: it is fully sufficient to have fileexist() > for testing whether the given file exist. Nothing more (no pipes, no > loadpaths). I did not conclude that from the discussion I saw. I think if you have such a thing at all, it must handle pipes and loadpaths. Otherwise what is the point of testing? But I also agree with Hans-Bernhard that such a specialized yet system-dependent function does not belong in gnuplot at all. It is sufficient to use whatever system-dependent shell command matches your use. I gave several examples already. > > My preferred method of dealing with this issue is to handle > > missing/empty files cleanly during the plotting process. > > Gnuplot support files with palettes as well. Sorry, I am not understanding you there. Are you complaining that my missing-files patch doesn't handle PM3D or other 3D plot modes? I'd welcome your help in untangling the code in plot3d.c/graph3d.c so that missing files can be skipped cleanly. -- Ethan A Merritt Biomolecular Structure Center University of Washington, Seattle WA |
|
From: Petr M. <mi...@ph...> - 2006-03-10 07:03:52
|
> It is sufficient to use whatever system-dependent shell command
> matches your use. I gave several examples already.
No examples has been presented until now, but I've just constructed it this
way:
fileexist(name)=\
system(sprintf("bash -c \"if [ -a %s ]; then echo 1; else echo 0; fi\"", name))
print fileexist('a')
print fileexist('aa')
Any better solution?
(There could be one with "REXX support" patch going into gnuplot...)
---
PM
|
|
From: Ethan A M. <merritt@u.washington.edu> - 2006-03-10 07:29:17
|
On Thursday 09 March 2006 11:03 pm, Petr Mikulik wrote:
>
> No examples has been presented until now, but I've just constructed it this
> way:
>
> fileexist(name)=\
> system(sprintf("bash -c \"if [ -a %s ]; then echo 1; else echo 0; fi\"", name))
>
> print fileexist('a')
> print fileexist('aa')
>
> Any better solution?
Didn't we start this whole discussion thread with comparisons of
"find" vs. "test" and their use to check file existence or updates?
ierr = system("test -e 'a'")
if (ERRNO) print "No such file"
ierr = system("test 'a' -nt 'b'")
if (!ERRNO) print "a is newer than b"
Maybe that was another thread....
--
Ethan A Merritt
Biomolecular Structure Center
University of Washington, Seattle 98195-7742
|
|
From: Petr M. <mi...@ph...> - 2006-03-10 07:56:21
|
>> fileexist(name)=\
>> system(sprintf("bash -c \"if [ -a %s ]; then echo 1; else echo 0; fi\"", name))
>>
>> print fileexist('a')
>> print fileexist('aa')
>
> ierr = system("test -e 'a'")
> if (ERRNO) print "No such file"
How to make a function of it? I cannot figure it out:
fileexist(name)=((system("test -e 'ab'")!="!!!") && !ERRNO)
print fileexist('anything')
Unfortunately, neither works under wgnuplot_pipes.
> Didn't we start this whole discussion thread with comparisons of
> "find" vs. "test" and their use to check file existence or updates?
Then I have probably haven't figure it out how to write it in a portable
way.
---
PM
|