bash - 从带有变量的 bash 运行 IDL 程序

标签 bash idl-programming-language

我用 IDL 编写了一个程序来根据命令行参数生成散点图。我可以像这样直接在终端中成功调用程序:

idl -e "scatterplot_1_2d_file.pro" $infile $outfile $title $xtitle $ytitle $xmin $xmax $ymin $ymax $timescale

其中 $* 指的是输入的一些字符串文字。问题是,我认为我可以只输入那一行,用变量名代替文字,放入 bash 脚本中,然后生成一个百万散点图,而我在休息。不幸的是,如果我那样做,我会得到错误:

idl: -e option cannot be specified with batch files

所以我的下一次尝试是尝试将这些命令写入一个 IDL 批处理文件,然后我会运行它。

那个尝试看起来像这样:

#!/bin/bash

indir=/path/to/indir/
outdir=/path/to/outdir/

files=`ls $indir`
batchfile=/path/to/tempbatchfile.pro

echo .r "/path/to/scatterplot_1_2d_file.pro" >> $batchfile

for file in $files
  do
  name=${file%\.*}
  echo scatterplot_1_2d_file $indir$name.txt $outdir$name.jpg $name "Gauge Precipitation (mm)" "NMQ Precipitation (mm)" "*" "*" "*" "*" 2 >> $batchfile
done #done file                                                                                                                                                                                                

echo exit >> $batchfile

idl <<EOF                                                                                                                                                                                                      
@/path/to/scatterplot_1_2d_file                                                                                                                                                                  
EOF                                                                                                                                                                                                            

rm $batchfile

我不知道脚本生成的大部分错误是否相关,所以我只发布开始,如果您需要,我会稍后发布其余部分:

[foo]$ bash script_thing.sh
IDL Version 6.3 (linux x86 m32). (c) 2006, Research Systems, Inc.
Installation number: 91418.
Licensed for personal use by XXXXXXXXX only.
All other use is strictly prohibited.


PRO scatterplot_1_2d_file
                         ^
% Programs can't be compiled from single statement mode.
  At: /path/to/scatterplot_1_2d_file.pro, Line 1
% Attempt to subscript ARGS with <INT      (       1)> is out of range.
% Execution halted at: $MAIN$          
% Attempt to subscript ARGS with <INT      (       2)> is out of range.
% Execution halted at: $MAIN$          
% Attempt to subscript ARGS with <INT      (       3)> is out of range.
% Execution halted at: $MAIN$          
% Attempt to subscript ARGS with <INT      (       4)> is out of range.
% Execution halted at: $MAIN$          
% Attempt to subscript ARGS with <INT      (       5)> is out of range.
% Execution halted at: $MAIN$          
% Attempt to subscript ARGS with <INT      (       6)> is out of range.
% Execution halted at: $MAIN$          
% Attempt to subscript ARGS with <INT      (       7)> is out of range.
% Execution halted at: $MAIN$          
% Attempt to subscript ARGS with <INT      (       8)> is out of range.
% Execution halted at: $MAIN$          
% Attempt to subscript ARGS with <INT      (       9)> is out of range.
% Execution halted at: $MAIN$          

我不知道我是否只是想做一些无法完成的事情,但它看起来并不像这样。有什么建议吗?

最佳答案

有两种方法可以解决此问题:使用 COMMAND_LINE_ARGS 或构造有效的 IDL 例程调用。此例程同时使用:

pro test, other_args
  compile_opt strictarr

  args = command_line_args(count=nargs)

  help, nargs
  if (nargs gt 0L) then print, args

  help, other_args
  if (n_elements(other_args) gt 0L) then print, other_args
end

通过以下两种方式之一从命令行调用它:

Desktop$ idl -e "test" -args $MODE
IDL Version 8.2, Mac OS X (darwin x86_64 m64). (c) 2012, Exelis Visual Information Solutions, Inc.
Installation number: 216855.
Licensed for use by: Tech-X Corporation

% Compiled module: TEST.
NARGS           LONG      =            1
test
OTHER_ARGS      UNDEFINED = <Undefined>
Desktop$ idl -e "test, '$MODE'"
IDL Version 8.2, Mac OS X (darwin x86_64 m64). (c) 2012, Exelis Visual Information Solutions, Inc.
Installation number: 216855.
Licensed for use by: Tech-X Corporation

% Compiled module: TEST.
NARGS           LONG      =            0
OTHER_ARGS      STRING    = 'test'
test

关于bash - 从带有变量的 bash 运行 IDL 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11162341/

相关文章:

bash - 在 Bash 中的文件夹中的所有文件名中出现一个字符串

python - 此图中使用的字体名称是什么?

variables - 在循环中定义数组名称

python - 在Python中调用IDL脚本

linux - 如何将多行回显到来自 grep 结果的文件中

bash - virtualenv 名称未显示在 zsh 提示符中

linux - 在 AWK 中去除空格

bash - Linux shell - 解析奇怪格式的日期

python - Scipy readav 和 IDL 类型

Python 相当于 IDL 的 stop 和 .reset