【问题标题】:gnuplot: load datafile 1:1 into datablockgnuplot:将数据文件 1:1 加载到数据块中
【发布时间】:2019-02-08 21:03:08
【问题描述】:

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

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

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

我将数据读入数据集的想法如下:

  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'' 时,FILE 的内容会一次又一次地加载还是会一直保存在内存中?
  2. 如果放大,例如在交互式 wxt 终端中,在我看来好像需要再次加载文件。这是真的吗?
  3. 如果文件一次又一次地加载,最好在开始时将文件一次加载到数据块中,然后使用这些数据块?

感谢任何解释、限制、利弊和 cmet。

加法:

(部分答案,但有新问题): 对于 Windows、Linux 和 MacOS 系统,以下似乎工作正常。 Linux 和 MacOS 显然是相同的。

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)。

"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

这有什么问题?谁能解释一下为什么以及如何解决这个问题?

【问题讨论】:

  • 如果您在慢速连接的另一端有多个大数据文件,那么在同一端运行 gnuplot 并仅将输出发送回本地会话可能更有意义。
  • 原则上是的,但是,使用相同的设置,我也在绘制本地数据。然后我需要管理不同位置的两个 gnuplot 安装。除此之外,我想,低传输率是一回事,但响应时间长是另一回事。即使文件很小,缓慢的响应时间也会使从服务器绘制数据变得痛苦。因此,我的问题是,当您的代码中有 FILE'' 时,是否会再次访问和加载文件。他们是吗?因此,我打算通过在开始时仅将文件一次加载到数据块中来缩短此时间。

标签: gnuplot data-files


【解决方案1】:

只要您知道输入数据格式,就可以将文件读入数据块。例如,您有一个文件MyFile1,其中包含 3 列中的数字,您想将其读入数据块MyBlock1,然后以 3 种方式绘制:

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

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

【讨论】:

  • 谢谢!您的建议涵盖了一种特殊情况。但是,我的输入数据格式是可变的。此外,绘制到表格将修改原始格式。因此,我认为load "&lt; echo $Data ^&lt;^&lt;EOD &amp; type ".FILE(或类似的)仍然是 1:1 加载数据的最佳方式。我没有证据,但文件可能会被加载几次。将文件复制到本地系统也不是解决方案,因为我必须在许多 PC 上同步数 GB 的数据。用户应在服务器上绘制最新数据。由于我无法加快服务器时间,我想尽量减少对服务器的访问。
【解决方案2】:

想法是将数据文件按原样(1:1)放入数据块中,包括注释行或空行等。 据我所知,似乎没有简单直接的平台“独立”gnuplot 命令。 在某些情况下,将数据放在数据块中可能是有利的(自 gnuplot 5.0 起可用),因为您可以简单地按索引寻址行(仅自 gnuplot 5.2 起),例如$Data[7],或向前和向后循环数据,对于文件中的数据,您无法轻松做到这一点。

这终于是一个我可以接受的解决方案,它似乎可以在 Windows 和 Linux 上运行(测试 Windows 7 和 10 以及 Ubuntu 18.04.4)。我无法在 MacOS 上进行测试,但我认为该命令与 Linux 相同,并且也适用于 MacOS。我不了解其他操作系统(感谢反馈)。

代码:

### load data file as is 1:1 into datablock
reset session

FileToDatablock(f,d) = GPVAL_SYSNAME[1:7] eq "Windows" ? \
                       sprintf('< echo   %s ^<^<EOD  & type "%s"',d,f) : \
                       sprintf('< echo "\%s   <<EOD" & cat  "%s"',d,f)     # Linux/MacOS

FILE = 'Test.dat'
load FileToDatablock(FILE,'$Data')

print $Data
### end of code

数据文件: (Test.dat)

# This is a test file
1.1    1.2
2.1    2.2
3.1    3.2

# another commented line
4.1    4.2
5.1    5.2
# some empty lines will follow


  6.1    6.2   # some spaces at the beginning
7.1    7.3
# end of datafile

结果:(正如预期的那样,$Data 是 1:1 等于 Test.dat

# This is a test file
1.1    1.2
2.1    2.2
3.1    3.2

# another commented line
4.1    4.2
5.1    5.2
# some empty lines will follow


  6.1    6.2   # some spaces at the beginning
7.1    7.3
# end of datafile

【讨论】:

    猜你喜欢
    • 2017-03-28
    • 2023-01-17
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多