2012-06-22 15 views
5

He escrito un programa en IDL para generar gráficos de dispersión basados ​​en argumentos de línea de comando. Puedo llamar con éxito el programa directamente en el terminal de la siguiente manera:Ejecutando el programa IDL desde bash con variables

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

Donde $ * se refieren a algunas cadenas literales escribió en el problema es, pensé que sería capaz de simplemente escribir esa misma línea, poniendo. en nombres de variables en lugar de los literales, en un script bash, y generar un millón de diagramas de dispersión mientras estoy en pausa. Por desgracia, si lo hago de esa manera, me sale el error:

idl: -e option cannot be specified with batch files

Así que mi siguiente intento fue intentar escribir estos comandos en un archivo por lotes IDL que entonces había corrido.

Ese intento se parece a esto:

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

No sé si la mayor parte de los errores que genera la escritura son relevantes, así que voy a publicar el inicio y voy a publicar el resto más tarde si lo necesita:

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

no sé si estoy tratando de hacer algo que no se puede hacer, pero no lo parece. ¿Algún consejo?

+1

Vas a tener que arreglar todos los [citar] (http: // mywiki. wooledge.org/Quotes) errores, y corrige el [manejo de nombres de archivos] (http://mywiki.wooledge.org/ParsingLs) antes de que podamos dar consejos específicos. Si estás atrapado después de eso, publica el nuevo error. – ormaaj

Respuesta

5

Hay dos maneras de hacerlo: usando COMMAND_LINE_ARGS o construyendo una llamada de rutina IDL válida. Esta rutina utiliza tanto:

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 

de llamadas desde la línea de comandos en cualquiera de las dos formas siguientes:

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

No sé IDL, pero aquí hay correcciones para su script Bash que puedan ayudar a:

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

para fijar su versión de línea de comandos, el uso de cotización:

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

Siempre cotizar variables cuando están expandidas.