2012-06-22 33 views
5

Tôi đã viết một chương trình trong IDL để tạo các ô phân tán dựa trên các đối số dòng lệnh. Tôi thành công có thể gọi chương trình trực tiếp tại nhà ga như thế này:Chạy chương trình IDL từ bash với các biến

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

đâu $ * tham khảo một số xâu gõ vào Vấn đề là, tôi nghĩ rằng tôi muốn có thể chỉ cần gõ dòng rất, đặt. trong các tên biến thay cho các chữ, thành một tập lệnh bash, và tạo ra một triệu ô phân tán trong khi tôi đang nghỉ. Thật không may, nếu tôi làm điều đó theo cách đó, tôi nhận được thông báo lỗi:

idl: -e option cannot be specified with batch files

Vì vậy, nỗ lực tiếp theo của tôi là cố gắng viết những lệnh để một tập tin batch IDL mà tôi thì muốn chạy.

nỗ lực đó trông như thế này:

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

Tôi không biết nếu phần lớn các lỗi mà kịch bản tạo ra có liên quan, vì vậy tôi sẽ chỉ gửi khi bắt đầu và tôi sẽ gửi phần còn lại sau nếu bạn cần:

[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$   

Tôi không biết nếu tôi chỉ đang cố gắng làm điều gì đó không thể làm được, nhưng nó không SEEM thích nó. Lời khuyên nào?

+1

Bạn sẽ phải sửa chữa tất cả các [trích dẫn] (http: // mywiki. wooledge.org/Quotes) lỗi và sửa [xử lý tên tệp] (http://mywiki.wooledge.org/ParsingLs) trước khi chúng tôi có thể đưa ra lời khuyên cụ thể. Nếu bạn bị kẹt sau đó, hãy đăng lỗi mới. – ormaaj

Trả lời

5

Có hai cách để thực hiện việc này: sử dụng COMMAND_LINE_ARGS hoặc xây dựng cuộc gọi định kỳ IDL hợp lệ. thói quen này sử dụng cả hai:

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 

Gọi nó từ dòng lệnh bằng một trong hai cách sau đây:

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

Tôi không biết IDL, nhưng đây là bản sửa lỗi cho kịch bản Bash của bạn có khả năng giúp:

#!/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" 

Để khắc phục phiên bản dòng lệnh của bạn, sử dụng trích dẫn:

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

Luôn các biến báo giá khi chúng được mở rộng.

Các vấn đề liên quan