How can I read a datafile as-is (or 1:1) into a datablock? And how could I do this platform independently? My attempt so far:
### load datafile "as is" into datablock for different platforms
FILE = 'Test.dat'
if (GPVAL_SYSNAME[:7] eq "Windows") { # "Windows_NT-6.1" is shown on a Win7 system
load "< echo $Data ^<^<EOD & type ".FILE
}
if (GPVAL_SYSNAME eq "Linux") { # that's shown on a Raspberry
load '< echo "$Data << EOD" & cat '.FILE
}
if (GPVAL_SYSNAME eq "Darwin") { # this was shown on a MacOS Sierra 10.12.6
# how to load a datafile into datablock under MacOS?
}
print $Data
### end of code
What is the value of GPVAL_SYSNAME
on a Win10, other Linux, and other MacOS systems?
How many if
statements would I need to cover all common systems?
At least under Windows the console window is flashing. How could I possibly surpress this?
My thoughts behind reading data into a dataset are the following:
- if you have data on a very(!) slow server path
- if you have relatively large datafiles
- if you fit and plot multiple curves from several files
For example something like:
FILE1 = '\SlowServerlahBigDataFile.dat'
FILE2 = '\SlowerServerlahBiggerDataFile.dat'
FILE3 = '\SlowestServerlahBiggestDataFile.dat'
fit f(x) FILE1 u 1:2 via a,c,d,e
fit g(x) FILE2 u 2:3 via f,g,h,i
fit h(x) FILE3 u 2:3 via j,k,l,m
plot FILE1 u 1:2:3 w l,
'' u (function($1)):(function($2)):3 with <whatever>,
FILE2 u 4:5:6 w l,
'' u 1:2:3 w l,
FILE3 u 7:8:9 w l,
'' u 1:2:3 w l ,
<and more...>
My questions:
- Everytime you plot or fit
FILE
and''
, will the content ofFILE
be loaded again and again or will it be kept in memory? - If you zoom in, e.g. in an interactive wxt terminal, it looks to me as if the files need to be loaded again. Is this true?
- If the files are loaded again and again, wouldn't it be best practice to load files once into datablocks once at the beginning and then work with these datablocks?
Any explanations, limitations, pros & cons and comments are appreciated.
Addition:
(partial answer, but with new issue): For the systems Windows,Linux and MacOS the following seems to work fine. Linux and MacOS are apparently identical.
if (GPVAL_SYSNAME[:7] eq "Windows") { load '< echo $Data ^<^<EOD & type "Test.dat"' }
if (GPVAL_SYSNAME eq "Linux" ) { load '< echo "$Data << EOD" & cat "Test.dat"' }
if (GPVAL_SYSNAME eq "Darwin") { load '< echo "$Data << EOD" & cat "Test.dat"' }
However, if I want to call this construct from an external gnuplot procedure "FileToDatablock.gpp"
it reproduceably crashes gnuplot under Win7/64 (haven't had a chance to test Linux or MacOS).
"FileToDatablock.gpp"
### Load datafile "as is" 1:1 into datablock for different platforms
# ARG1 = input filename
# ARG2 = output datablock
# usage example: call "FileToDatablock.gpp" "Test.dat" "$Data"
if (ARGC<1) { ARG1 = "Test.dat" }
if (ARGC<2) { ARG2 = "$Data" }
if (GPVAL_SYSNAME[:7] eq "Windows") { load '< echo '.ARG2.' ^<^<EOD & type "'.ARG1.'"' }
if (GPVAL_SYSNAME eq "Linux" ) { load '< echo "'.ARG2.' << EOD" & cat "'.ARG1.'"' }
if (GPVAL_SYSNAME eq "Darwin") { load '< echo "'.ARG2.' << EOD" & cat "'.ARG1.'"' }
### end of code
And the file which calls this procedure:
### load datafile 1:1 into datablock
reset session
# this works fine under Win7/64
FILE = "Test.dat"
DATA = "$Data"
load '< echo '.DATA.' ^<^<EOD & type "'.FILE.'"'
print $Data
# this crashes gnuplot under Win7/64
call "tbFileToDatablock.gpp" "Test.dat" "$Data"
print $Data
### end of code
What's wrong with this? Can anybody explain why and how to solve this issue?
Question&Answers:os