Load a package inside a script
Gabriel wrote on Apr 16, 2009
Hi,
well, that's my question: can I load a package from within a procedure script?
I'm working with certain tasks that are in the 'daophot' package, and I need to use tasks inside the 'photcal' package. Is there a way to change packages 'on the fly' or do I need to close the script and start another one inside the other package?
Thanks!
well, that's my question: can I load a package from within a procedure script?
I'm working with certain tasks that are in the 'daophot' package, and I need to use tasks inside the 'photcal' package. Is there a way to change packages 'on the fly' or do I need to close the script and start another one inside the other package?
Thanks!
Mike Fitzpatrick wrote on Apr 16, 2009
Scripts can indeed load packages. Typically you would use the defpac() function to see whether the package is already loaded, e.g.
if (defpac("ptools") == no) {
print ("Loading PTOOLS package")
prools
}
Gabriel wrote on Apr 16, 2009
Well, I've tried that already but I get an error. It seems to work on a non-procedure script, but when I try to do it inside a procedure script I get an error. Here's an example of what I do:
-access 'daophot' package
-run script
-at a certain point in the script I write: photcal
-then I try to run the 'mkconfig' task
but I get an 'mkconfig' task not found error.
Again, this DOES seem to work on a non-procedure script, but should it also work on a procedure script?
-access 'daophot' package
-run script
-at a certain point in the script I write: photcal
-then I try to run the 'mkconfig' task
but I get an 'mkconfig' task not found error.
Again, this DOES seem to work on a non-procedure script, but should it also work on a procedure script?
Mike Fitzpatrick wrote on Apr 16, 2009
Post the script, or at least the relevant bits. It should work either way, but note that procedure scripts should be declared as tasks, non-procedure scripts are usually run by redirection.
Gabriel wrote on Apr 16, 2009
This is a simplified script that shows what I'm trying to do:
procedure script1 ()
real dummy
begin
photcal
mkcatalog.review = no
mkcatalog.verify = no
mkcatalog.edit = no
mkcatalog ("landolt.cat")
end
The only way this will work is if I'm already inside 'photcal' when I run it. Any other way I get a 'mkcatalog' task not found error or a 'photcal' task not found error. The script is defined in my loginuser.cl like this:
task casleored2 = /home/iraf/noao/casleored/script1.cl
procedure script1 ()
real dummy
begin
photcal
mkcatalog.review = no
mkcatalog.verify = no
mkcatalog.edit = no
mkcatalog ("landolt.cat")
end
The only way this will work is if I'm already inside 'photcal' when I run it. Any other way I get a 'mkcatalog' task not found error or a 'photcal' task not found error. The script is defined in my loginuser.cl like this:
task casleored2 = /home/iraf/noao/casleored/script1.cl
Mike Fitzpatrick wrote on Apr 16, 2009
Looks like I got it backwards: defpac() is typically used to determine when a package is NOT loaded so you can print an error and quit, loading the package won't work because of the way the package loading works internally. It DOES work in things like package.cl scripts, #!cl scripts and stuff like the login.cl because these are executed using the redirection.
-Mike
-Mike
Gabriel wrote on Apr 16, 2009
What do you mean by:
Do you mean that it does work on NON-procedure scripts but it does not on procedure scripts (like I thought :( )?
Thanks Mike.
fitz
It DOES work in things like package.cl scripts, #!cl scripts and stuff like the login.cl because these are executed using the redirection.
Do you mean that it does work on NON-procedure scripts but it does not on procedure scripts (like I thought :( )?
Thanks Mike.
Last post on Apr 16, 2009