Re: help with module



On Apr 8, 11:32 am, rudra <bnrj.ru...@xxxxxxxxx> wrote:
well, let me explain what i want to do.i have some variables that
should be available to all other prgrams; so i use the module.

The "protected" attribute was a good idea, dont give up too early.
This is natural next step between fortran "parameter"s and and those
of your computation. All you need is an updater routine:

module params

real, protected, public :: speed_of_light = 3.0E8

public :: set_speed_of_light

contains

subroutine set_speed_of_light(c)
implicit none
real, intent(in) :: c

print *,'warning, somebody is trying to change speed of light
to',c
speed_of_light = c
end subroutine set_speed_of_light

end module

And no one is allowed to modify the speed of light
except when explicitly calling set_speed_of_light().

Alexei
.



Relevant Pages

  • Re: Function result differs from same code for subroutine
    ... I dont think I was clear enough... ... Am in the middle of developing this but I happend on this problem as I ... SpecialCellslike the subroutine does, ... its doing my head in. ...
    (microsoft.public.vb.general.discussion)
  • Re: UNIVERSAL::can function failing under heavy load
    ... I dont' see how ... > that would cause this particular problem, but I'd fix it anyway just in ... subroutine so that recursive calls to _deep_copy will be accessing the ... same version of @Deep_copy_stack to prevent infinite recursion in the ...
    (comp.lang.perl.modules)
  • Re: fortran95 error
    ... and I dont really understand what it means since I just started to ... You should tell us details of operating system and compiler version ... At a guess you are using a subroutine like: ... x = subrt ...
    (comp.lang.fortran)
  • Re: fortran95 error
    ... and I dont really understand what it means since I just started to ... You should tell us details of operating system and compiler version ... At a guess you are using a subroutine like: ... x = subrt ...
    (comp.lang.fortran)