An example of precisely this behavior can be found within one of the
"version" files, which use an auxiliary env.var. to keep a stack of
values, which you "push" and "pop" values with successive loads and
unloads.
E.g.
# for Tcl script use only
set version 3.2.5
if [ expr [ module-info mode load ] || [ module-info mode display ] ] {
# get rid of old version
module unload null
module unload modules
setenv MODULE_VERSION 3.2.5
}
# version stack
prepend-path MODULE_VERSION_STACK 3.2.5
if [ module-info mode remove ] {
unsetenv MODULE_VERSION [lindex [split $env(MODULE_VERSION_STACK) : ] 0 ]
}
if [ expr [ module-info mode load ] || [ module-info mode display ] ] {
# bring in new version
module load modules
}
Look in the sources at ./modulefiles/version.in .
R.K.
On Tue, Jan 19, 2010 at 6:27 AM, David Boger <da...@ps...> wrote:
> Hi,
>
> I've been getting a lot of use out of the modules package lately but
> have been struggling to do something and am wondering whether it is
> possible. I'd like to set an environment variable only under certain
> conditions when the module is loaded, and then have the original
> condition returned when the module is unloaded. Possibilities are to
> set the variable if it is not already set, or to change its value (under
> certain conditions) if it is already set. Upon unload, it should go back
> to its original value or back to undefined; e.g.
>
>
>> if { [info exists env(MPI_BUFFER_SIZE) ] } {
>> if { $env(MPI_BUFFER_SIZE) < $minBufferSize } {
>> setenv MPI_BUFFER_SIZE $minBufferSize
>> }
>> } else {
>> setenv MPI_BUFFER_SIZE $minBufferSize
>> }
>>
>
> I think that this captures the correct "load" behavior, but the
> original state is not returned at "unload" (modules version 3.2.7)
>
> Thanks,
> David
>
>
>
|