On Sat, 30 Sep 2017, Sven Schreiber wrote:
Am 29.09.2017 um 18:56 schrieb Sven Schreiber:
> I think it should be possible to put together a hansl script for
> that. I'll try (soon; everybody is welcome to beat me to it).
I have started an attempt, attached, but: CAUTION, this produces a
crash for me (with the latest Windows snapshot which I've just
downloaded).
The crash doesn't seem to happen every time, but with a freshly
started gretl instance just now it did. When there's no crash,
there seems to happen some weird over-/underflow error in the N
variable (which by construction should actually be an integer).
Thanks for both the idea and the crash report.
The crash was due to a remaining window of vulnerability created by
our acceptance of the "open" command in loops (something that was
was disallowed until relatively recently). I've now closed that
window in git, so your script should now run OK.
However, the task that your script addresses is easier than you make
it, due to the presence of the $datatype accessor. Given an array of
datafile names "fnames", the following will suffice:
<hansl>
string out = ""
loop i=1..nelem(fnames) --quiet
string tempstr = fnames[i]
printf "Opening %s\n", tempstr
catch open @tempstr --preserve --quiet
if $error
printf "Couldn't open %s\n", tempstr
break
endif
if $datatype == 1
# cross section
out ~= sprintf("\"%s\",\"n = %d\"\n", tempstr, $nobs)
elif $datatype == 2
# time series
out ~= sprintf("\"%s\",\"T = %d\"\n", tempstr, $nobs)
elif $datatype == 3
# panel
N = max($obsmajor)
T = max($obsminor)
out ~= sprintf("\"%s\",\"N = %d, T = %d\"\n", tempstr,
N, T)
else
# weird error
printf "Got no recognized data!?"
break
endif
endloop
print out
</hansl>
Note also that you can't use "temp" as a string (filename) in such a
script without generating confusion, since at least one of the
packaged datafiles contains a series named "temp".
Allin