Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran Module w/ user defined type

  1. Dec 28, 2011 #1

    hotvette

    User Avatar
    Homework Helper

    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: Dec 28, 2011
  2. jcsd
  3. Dec 30, 2011 #2

    hotvette

    User Avatar
    Homework Helper

    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?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook