programmatically compile a procedure without a .pro extension [message #85662] |
Sat, 24 August 2013 18:10  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
Does anyone know if there is a way to programmatically compile a procedure that does not have a .pro extension? For example, if I have a file named a1.bak containing the following 4 lines:
pro a1
print,'Inside procedure a1'
return
end
then the user can successfully compile this using
IDL> .run a1.bak
But the tools to programmatically compile a file don't work in this case, i.e.
IDL> resolve_routine,'a1.bak'
or
IDL> file_compile,'a1.bak'
where file_compile is from Craig Markwardt's library
http://www.physics.wisc.edu/~craigm/idl/down/file_compile.pr o
It is reasonable to ask why I would not simply use a .pro extension. But the answer is fairly complicated so I don't (yet) want to distract from the straightforward question above. Thanks, --Wayne
|
|
|
Re: programmatically compile a procedure without a .pro extension [message #85663 is a reply to message #85662] |
Sun, 25 August 2013 05:10   |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
If you don't want to get a .pro file by renaming (or making a copy of)
the .bak file, you can do something like the following. The routine
below creates a temporary .pro file and includes the files with other
extensions by use of the @ include file character:
pro compile,filenames
;
tempfile='compile_temp'
openw,lun,/get_lun,tempfile+'.pro'
printf,lun,'@'+filenames,form='(a)'
free_lun,lun
;
catch,error
if ~error then resolve_routine,tempfile
catch,/cancel
;
end
The catch statement suppresses an error message from the compiler,
that there is no compile_temp routine.
Note that you can specify the filenames by a string array, if you want
to compile more than one file.
Cheers, Heinz
|
|
|
Re: programmatically compile a procedure without a .pro extension [message #85667 is a reply to message #85663] |
Sun, 25 August 2013 20:23  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
Heinz,
Thanks. That is an elegant use of CATCH.
I still have mild trepidation about requiring an arbitrary user to have write access to a disk. But I've never had any problem using IDL_TMPDIR as a scratch writeable directory, so I should probably
stop worrying. --Wayne
On Sunday, August 25, 2013 8:10:37 AM UTC-4, Heinz Stege wrote:
> If you don't want to get a .pro file by renaming (or making a copy of)
>
> the .bak file, you can do something like the following. The routine
>
> below creates a temporary .pro file and includes the files with other
>
> extensions by use of the @ include file character:
>
>
>
> pro compile,filenames
>
> ;
>
> tempfile='compile_temp'
>
> openw,lun,/get_lun,tempfile+'.pro'
>
> printf,lun,'@'+filenames,form='(a)'
>
> free_lun,lun
>
> ;
>
> catch,error
>
> if ~error then resolve_routine,tempfile
>
> catch,/cancel
>
> ;
>
> end
>
>
>
> The catch statement suppresses an error message from the compiler,
>
> that there is no compile_temp routine.
>
>
>
> Note that you can specify the filenames by a string array, if you want
>
> to compile more than one file.
>
>
>
> Cheers, Heinz
|
|
|