2012-06-22 64 views
5

我已經在IDL中編寫了一個程序,用於根據命令行參數生成散點圖。我成功地可以直接調用程序的終端是這樣的:使用變量從bash運行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$   

我不知道,如果我只是試圖做一些事情不能做,但它似乎並不喜歡它。有什麼建議?

+1

你必須修復所有[報價](HTTP:// mywiki。 wooledge.org/Quotes)錯誤,並且糾正[文件名的處理](http://mywiki.wooledge.org/ParsingLs),然後才能給出具體的建議。如果您在此之後卡住,請發佈新錯誤。 – ormaaj

回答

5

有兩種方法可以解決這個問題:使用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 
4

我不知道IDL,但這裏是爲您的bash腳本修復那些可能幫助:

#!/bin/bash 

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

# (commented out) files=`ls $indir` # no, just no 
batchfile=/path/to/tempbatchfile.pro 

echo ".r /path/to/scatterplot_1_2d_file.pro" > "$batchfile" # overwrite the file on the first write, put everything inside the quotes 

for file in "$indir/"* 
    do 
    name=${file%\.*} 
    echo "scatterplot_1_2d_file $indir$name.txt $outdir$name.jpg $name Gauge Precipitation (mm) NMQ Precipitation (mm) * * * * 2" # quote the whole thing once, it's simpler and echo doesn't do anything differently 
done >> "$batchfile" # do all the output from the loop 
echo exit >> "$batchfile" 

# *** where does idl learn the location of "$batchfile"? *** 
idl <<EOF                                                  
@/path/to/scatterplot_1_2d_file                                         
EOF                                                    

rm "$batchfile" 

要解決您的命令行版本,使用引用:

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

始終引用變量時,他們擴大。