Command line arguments [message #42537] |
Fri, 11 February 2005 12:27  |
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 #62628 is a reply to message #42537] |
Mon, 29 September 2008 19:21  |
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  |
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  |
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  |
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  |
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  |
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  |
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  |
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  |
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  |
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
|
|
|