Fortran Fortran Module w/ user defined type

AI Thread Summary
In Fortran, user-defined types cannot be initialized directly in a module like intrinsic types; instead, they require a subroutine for initialization. This leads to the necessity of calling the subroutine from the main program to set the values. The 'SAVE' keyword allows for retaining variable values, but it also permits modification by any program using the module. The 'PARAMETER' keyword cannot be applied to user-defined types for initialization, raising the question of how to make these variables read-only. Currently, there are no alternative methods presented for achieving read-only status for user-defined module variables.
hotvette
Homework Helper
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:
Technology news 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?
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Back
Top