comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: IDL batch mode: Command line args?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: IDL batch mode: Command line args? [message #11496 is a reply to message #11482] Wed, 01 April 1998 00:00 Go to previous messageGo to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Mark Elliott wrote:
>
> I'd like to run IDL (from UNIX) in batch mode with a command
> like:
>
> unixprompt> idl batchprog.pro
>
> How can I provide additional arguments to be used by the batch
> program. For example, is there a syntax like:
>
> unixprompt> idl batchprog.pro inputfile.txt
>
> or
>
> unixprompt> idl batchprog.pro 5 3.78 "John Doe" 24.0
>
> If this can be done, how are the additional args obtainable within the
> batch program? I can find no documentation that this is possible.
> Still I can always hope...
>
> Thanks.

Hi Mark,

your question intrigued me, and I came up with a solution involving
a temporary file that is written by a little Unix shell script and
contains the arguments passed to IDL. This is certainly not perfect,
and I haven't spent any time on error checking etc., but it may provide
a start. I must admit that I have never tried to execute IDL in batch
mode before, and my 2-minute primer on this led to the conclusion that
you can only run main prorgrams this way and that you have to provide an
EXIT command in order to leave IDL after your program has terminated. If
this is not true, I'd be happy to learn more!

Now, here is how it works:
the shellscript idlbatch (make sure it's executable):

# Unix shell script to pass arguments into idl
# when running in batch mode
# uses echo to store the command line arguments in a
# temporary file which can be read by batchtest.pro
# Example: idlbatch batchtest 5 8
echo $* > tmpfile
idl $1


Your main program (see batchtest.pro as an example) will have to
read in 'tmpfile' and extract the arguments: the first argument is
the name of the program itself. In batchtest.pro I simply call a
second procedure batchtest2.pro (also attached below), which multiplies
the first two arguments (defaulted by a value of 3). Certainly, there is
lot of room for improvements on the parameter parsing and type
determination - who knows, maybe David is interested ?

Best regards,
Martin.

------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Earth&Planetary Sciences, Harvard University
186 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax : (617)-495-4551

e-mail: mgs@io.harvard.edu
IDL-homepage: http://www-as.harvard.edu/people/staff/mgs/idl/
------------------------------------------------------------ -------



; simple IDL test program to be run in batch mode
; on the Unix xhell type idlbatch batchtest [arguments]

print,"I'm in !"
; read tmpfile produced from the shell script
args = ''
openr,ilun,'tmpfile',/get_lun
readf,ilun,args
free_lun,ilun

; for now we assume all arguments are numeric
; except for first one which is the name of the IDL program
argv = str_sep(args,' ')
argv = float(argv(1:*))
if (n_elements(argv) ge 2) then $
batchtest2,argv(0),argv(1) $
else if(n_elements(argv) ge 1) then $
batchtest2,argv(0) $
else $
batchtest2

exit,/no_confirm,status=0




pro batchtest2,a,b


if (n_elements(a) eq 0) then a=3
if (n_elements(b) eq 0) then b=3

print,'A*B=',a*b

return
end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: FFT transforms for images
Next Topic: How do you sort an array in IDL?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 08:42:51 PDT 2025

Total time taken to generate the page: 0.87803 seconds