gnuplot:将数据文件1:1加载到数据块中 [英] gnuplot: load datafile 1:1 into datablock

查看:230
本文介绍了gnuplot:将数据文件1:1加载到数据块中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数据文件原样(或1:1)读入数据块?
我怎么能独立做这个平台?
到目前为止,我的尝试:

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

在Win10,其他Linux和其他MacOS系统上, GPVAL_SYSNAME 的值是什么?
我需要多少个 if 语句来覆盖所有通用系统?
至少在Windows下,控制台窗口正在闪烁。我怎么可能压制呢?

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:


  1. 如果您的数据在非常慢的服务器路径上

  2. 如果数据文件相对较大

  3. 如果您适合并绘制多个文件中的多条曲线

例如:

FILE1 = '\\SlowServer\blah\BigDataFile.dat'
FILE2 = '\\SlowerServer\blah\BiggerDataFile.dat'
FILE3 = '\\SlowestServer\blah\BiggestDataFile.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...>

我的问题:


  1. 每次绘制或拟合 FILE ''时,的内容都会文件一次又一次加载,还是将其保存在内存中?

  2. 如果放大,例如在交互式wxt终端中,我觉得好像文件需要再次加载。是真的吗?

  3. 如果一次又一次加载文件,不是最好的做法是在一开始就一次将文件加载一次到数据块中,然后再使用这些数据块吗? li>
  1. Everytime you plot or fit FILE and '', will the content of FILE be loaded again and again or will it be kept in memory?
  2. 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?
  3. 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.

添加:

(部分答案,但新发行):
对于Windows,Linux和MacOS系统,以下情况似乎可以正常工作。

(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"' }

但是,如果我想从外部gnuplot调用此构造程序 FileToDatablock.gpp 可重现导致Win7 / 64下的gnuplot崩溃(没有机会测试Linux或MacOS)。

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

调用此过程的文件:

### 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?

推荐答案

可以将文件读入数据块,只要您知道输入数据格式。例如,您有一个文件 MyFile1 ,其中有3列数字要读取到数据块 MyBlock1 中,然后进行绘图三种方式:

It is possible to read a file into a datablock, provided you know the input data format. For example, you have a file MyFile1 with numbers in 3 columns which you want to read into datablock MyBlock1, then plot in 3 ways:

set table $MyBlock1
   plot "MyFile1" using 1:2:3 with table
unset table
plot $MyBlock1 using 1:2 with points
plot $MyBlock1 using 2:3 with points
plot $MyBlock1 using 1:3 with lines

这样可以避免多次读取文件,并且应该可以在任何平台上使用。而不是这样做,我想将文件从慢速文件系统复制到本地文件系统会更简单。

This avoids reading the file several times, and should presumably work on any platform. Rather than doing this, I imagine it would be simpler to just copy your files from your slow filesystem to a local filesystem.

这篇关于gnuplot:将数据文件1:1加载到数据块中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆