Fortran Module w/ user defined type

  • Context: Fortran 
  • Thread starter Thread starter hotvette
  • Start date Start date
  • Tags Tags
    Fortran module Type
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 3K views
Messages
1,001
Reaction score
11
I have a bunch of programs that initialize values of variables of a user defined type, so I thought I'd initialize them all in a module and have each program 'use' the module. But, it seems the only way to initialize the variables in a module is to put the initializations in a subroutine within the module and then call the subroutine, say from the MAIN program. Initializing variables of intrinsic type in a module can be done w/o an imbedded subroutine.

Is my understanding correct, and if so, why the difference? Thanks for any comments.
 
Last edited:
on Phys.org
I think I found the explanation. User defined functions can't be used to initialize parameters. But, this brings up a 2nd question. The only way I've figured out how to initialize the values of variables using a user defined function is to use the 'SAVE' keyword in the declaration of the variable and a 'CONTAINED' subroutine to initialize the values. This means any program 'USING' the module can change the value of the variables.

Simply put, is there is any way to have a variable defined in a module be 'read only' by programs that use the module? Can't use the 'PARAMETER' keyword per the above explanation. Is there any other option?