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

Home » Public Forums » archive » Command line arguments
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Command line arguments [message #42537] Fri, 11 February 2005 12:27 Go to next message
Mr. No Address is currently offline  Mr. No Address
Messages: 11
Registered: February 2005
Junior Member
Way back in the day I posted a very similar question. Someone gave me a
solution using environment variables that has worked fine all this time,
but now I'm updating things and I'm seeking a cleaner solution. Here we
go...

I have a Perl program that I compile and run an IDL program from. I'm
now looping through several hundred times and it seems wasteful to
compile the IDL program every loop.

# The relevant Perl code...
$ENV{"file"}="$filepath";
open(IDL, "|/usr/local/bin/idl") || die "Can't open IDL: $!";
print IDL ".Compile mentor \n";
print IDL "mentor \n";
close IDL;

# The relevant IDL code...
PRO mentor
file=GETENV('file')

I would like to compile the program once outside the loop and then pass
the file using an argument instead grabbing the file from an environment
variable. Can I do something like this?

print IDL "mentor, $filepath\n";

I found a link with google that describes what I want to do. Judging
from the errors I'm getting I'd say I'm close, but as with most
programming errors, close still doesn't work. If this can be done, I'm
guessing I need to add something to my IDL code. I hope the link below
works. If not, google "passing args idl" select groups and select the
fourth link down "IDL batch mode: Command line args?"

http://groups-beta.google.com/group/comp.lang.idl-pvwave/bro wse_thread/thread/47c013740c2cc376/627e5899522d54e8?q=passin g+args+idl&_done=%2Fgroups%3Fq%3Dpassing+args+idl%26hl%3 Den%26lr%3D%26tab%3Dng%26ie%3DUTF-8%26sa%3DN%26&_doneTit le=Back+to+Search&&d#627e5899522d54e8
Re: Command line arguments [message #42729 is a reply to message #42537] Mon, 21 February 2005 12:20 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
JD Smith writes:

> You'd be surprised how many people I know compile their routines by
> hand, not once, but *twice*, just for good measure. This is what a
> lifetime of IRAF can do to a person.

Oh, I'm pretty much incapable of being surprised about
things like this. This is one of the reasons I have to
attend that 12-step program for cynics on Tuesday nights. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: command line arguments [message #62628 is a reply to message #42537] Mon, 29 September 2008 19:21 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
xiao writes:

> On Sep 29, 2:13 pm, David Fanning <n...@dfanning.com> wrote:
>> xiao writes:
>>> Seems it still does not working...
>>
>> Try hard-coding the file name in your program. Does
>> it work then? :-)
>>
>> Cheers,
>>
>> David
>> --
>> David Fanning, Ph.D.
>> Coyote's Guide to IDL Programming (www.dfanning.com)
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> YES, it works. thank you ~~~every one :)

Problem solved. ;-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: command line arguments [message #62629 is a reply to message #42537] Mon, 29 September 2008 19:10 Go to previous message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Sep 29, 2:13 pm, David Fanning <n...@dfanning.com> wrote:
> xiao writes:
>> Seems it still does not working...
>
> Try hard-coding the file name in your program. Does
> it work then? :-)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Coyote's Guide to IDL Programming (www.dfanning.com)
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

YES, it works. thank you ~~~every one :)
Re: command line arguments [message #62630 is a reply to message #42537] Mon, 29 September 2008 12:13 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
xiao writes:

> Seems it still does not working...

Try hard-coding the file name in your program. Does
it work then? :-)

Cheers,

David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: command line arguments [message #62633 is a reply to message #42537] Mon, 29 September 2008 13:22 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
> filename=command_line_args()
> print,filename
> file='filename'
> OPENR, lun, file, /GET_LUN

do
OPENR, lun, filename, /GET_LUN


> rows = File_Lines(file)
> header = STRARR(14)
> READF, lun, header
> PRINT, header
> Point_Lun, -lun, currentLocation
>
> Or like this?
>
> filename=command_line_args()
> print,filename
> OPENR, lun, 'filename', /GET_LUN
> rows = File_Lines('filename')
> header = STRARR(14)
> READF, lun, header
> PRINT, header
> Point_Lun, -lun, currentLocation
>
>
>
Re: command line arguments [message #62637 is a reply to message #42537] Mon, 29 September 2008 12:36 Go to previous message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
On Sep 29, 2:04 pm, xiao <littledd...@gmail.com> wrote:
> On Sep 29, 1:58 pm, Rick Towler <rick.tow...@nomail.noaa.gov> wrote:
>
>
>
>> Try it by passing the full path, not just the filename.
>
>> -Rick
>
>> xiao wrote:
>>> I did it like this :
>
>>> idl -arg D20051210_220601_P.QC.eol
>
>>> And then
>
>>> IDL> .r upperdata.pro
>>> % Compiled module: $MAIN$.
>>> D20051210_220601_P.QC.eol
>>> % OPENR: Error opening file. Unit: 100, File: filename
>>>   No such file or directory
>
>>> It can print the right name but did not open the file......
>
> Seems it still does not working...

You want to use filename (no quotes). 'filename' is the literal
string. filename is the variable.
Re: command line arguments [message #62638 is a reply to message #42537] Mon, 29 September 2008 12:04 Go to previous message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Sep 29, 1:58 pm, Rick Towler <rick.tow...@nomail.noaa.gov> wrote:
> Try it by passing the full path, not just the filename.
>
> -Rick
>
> xiao wrote:
>> I did it like this :
>
>> idl -arg D20051210_220601_P.QC.eol
>
>> And then
>
>> IDL> .r upperdata.pro
>> % Compiled module: $MAIN$.
>> D20051210_220601_P.QC.eol
>> % OPENR: Error opening file. Unit: 100, File: filename
>>   No such file or directory
>
>> It can print the right name but did not open the file......
>
>

Seems it still does not working...
Re: command line arguments [message #62639 is a reply to message #42537] Mon, 29 September 2008 11:58 Go to previous message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
Try it by passing the full path, not just the filename.

-Rick

xiao wrote:

> I did it like this :
>
> idl -arg D20051210_220601_P.QC.eol
>
> And then
>
> IDL> .r upperdata.pro
> % Compiled module: $MAIN$.
> D20051210_220601_P.QC.eol
> % OPENR: Error opening file. Unit: 100, File: filename
> No such file or directory
>
> It can print the right name but did not open the file......
Re: command line arguments [message #62640 is a reply to message #42537] Mon, 29 September 2008 11:34 Go to previous message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Sep 29, 11:41 am, Spon <christoph.b...@gmail.com> wrote:
> On Sep 29, 5:01 pm, xiao <littledd...@gmail.com> wrote:
>
>
>
>> HI~ guys , is these lines right? Why I cannot open the file based on
>> the following errors. I know the file is there :(   Thank you
>
>> filename=command_line_args()
>> print,filename
>> file='filename'
>> OPENR, lun, file, /GET_LUN
>>   rows = File_Lines(file)
>> header = STRARR(14)
>> READF, lun, header
>>  PRINT, header
>>   Point_Lun, -lun, currentLocation
>
>> Or like this?
>
>> filename=command_line_args()
>> print,filename
>> OPENR, lun, 'filename', /GET_LUN
>>   rows = File_Lines('filename')
>> header = STRARR(14)
>> READF, lun, header
>>  PRINT, header
>>   Point_Lun, -lun, currentLocation
>
> What exactly are the errors you mention you're getting?
>
> Also, what do you get when you type this?
>
> filename=command_line_args(count=count)
> help, filename
> print, transpose(filename)
> print, 'Count:', Count
>
> What are you using the following line for?
>
> file='filename'
>
> If you want to extract the first string from the string array returned
> by the command_line_args() function, I would use
> file = filename[0]
> instead.
>
> Apart from that - as it stands, I would say that yes, these lines are
> probably right in that I can't find an obvious coding error there, but
> it depends on what you're trying to do!
>
> Tell us more :-)
> Chris

It gave me the following stuff

IDL> .r upperdata.pro
% Compiled module: $MAIN$.
FILENAME STRING = Array[1]
D20051210_220601_P.QC.eol
Count: 1
D20051210_220601_P.QC.eol
% OPENR: Error opening file. Unit: 100, File: filename
No such file or directory
Re: command line arguments [message #62641 is a reply to message #42537] Mon, 29 September 2008 11:32 Go to previous message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Sep 29, 11:41 am, Spon <christoph.b...@gmail.com> wrote:
> On Sep 29, 5:01 pm, xiao <littledd...@gmail.com> wrote:
>
>
>
>> HI~ guys , is these lines right? Why I cannot open the file based on
>> the following errors. I know the file is there :(   Thank you
>
>> filename=command_line_args()
>> print,filename
>> file='filename'
>> OPENR, lun, file, /GET_LUN
>>   rows = File_Lines(file)
>> header = STRARR(14)
>> READF, lun, header
>>  PRINT, header
>>   Point_Lun, -lun, currentLocation
>
>> Or like this?
>
>> filename=command_line_args()
>> print,filename
>> OPENR, lun, 'filename', /GET_LUN
>>   rows = File_Lines('filename')
>> header = STRARR(14)
>> READF, lun, header
>>  PRINT, header
>>   Point_Lun, -lun, currentLocation
>
> What exactly are the errors you mention you're getting?
>
> Also, what do you get when you type this?
>
> filename=command_line_args(count=count)
> help, filename
> print, transpose(filename)
> print, 'Count:', Count
>
> What are you using the following line for?
>
> file='filename'
>
> If you want to extract the first string from the string array returned
> by the command_line_args() function, I would use
> file = filename[0]
> instead.
>
> Apart from that - as it stands, I would say that yes, these lines are
> probably right in that I can't find an obvious coding error there, but
> it depends on what you're trying to do!
>
> Tell us more :-)
> Chris

I did it like this :

idl -arg D20051210_220601_P.QC.eol

And then

IDL> .r upperdata.pro
% Compiled module: $MAIN$.
D20051210_220601_P.QC.eol
% OPENR: Error opening file. Unit: 100, File: filename
No such file or directory

It can print the right name but did not open the file......
Re: command line arguments [message #62642 is a reply to message #42537] Mon, 29 September 2008 09:41 Go to previous message
Spon is currently offline  Spon
Messages: 178
Registered: September 2007
Senior Member
On Sep 29, 5:01 pm, xiao <littledd...@gmail.com> wrote:
> HI~ guys , is these lines right? Why I cannot open the file based on
> the following errors. I know the file is there :(   Thank you
>
> filename=command_line_args()
> print,filename
> file='filename'
> OPENR, lun, file, /GET_LUN
>   rows = File_Lines(file)
> header = STRARR(14)
> READF, lun, header
>  PRINT, header
>   Point_Lun, -lun, currentLocation
>
> Or like this?
>
> filename=command_line_args()
> print,filename
> OPENR, lun, 'filename', /GET_LUN
>   rows = File_Lines('filename')
> header = STRARR(14)
> READF, lun, header
>  PRINT, header
>   Point_Lun, -lun, currentLocation

What exactly are the errors you mention you're getting?

Also, what do you get when you type this?

filename=command_line_args(count=count)
help, filename
print, transpose(filename)
print, 'Count:', Count

What are you using the following line for?

file='filename'

If you want to extract the first string from the string array returned
by the command_line_args() function, I would use
file = filename[0]
instead.

Apart from that - as it stands, I would say that yes, these lines are
probably right in that I can't find an obvious coding error there, but
it depends on what you're trying to do!

Tell us more :-)
Chris
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL Workbench Printing Woes
Next Topic: Re: Newbie math trouble

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

Current Time: Wed Oct 08 17:48:25 PDT 2025

Total time taken to generate the page: 0.00735 seconds