- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
I am a F90 newbie and need advice on the following problem. I am converting an old program from F77 to F90. In this program a number of time-dependent differential equations are solved for different but coupled geometries (so-called linked runs) by looping through all geometries during each time step. In the F77 version, all the variables and constants for all runs are stored in one large array, and the variables for the current run are accessed via a COMMON-block. To read/write all variables for each run the following type of coding is used:
How do I do this without the COMMON-block in Fortran 90 and without having to list all the variables in the subroutine "store" (there are quite a few of them)? I'm trying to move the code away from F77 by using modules for global variables, but I haven't figured out a way to do the above in a "nice" way. Since the code is used for research users may modify the code and add global variables, so I don't want the person in question having to make changes in lots of files and subroutines. Preferably, the user will only have to add a declaration in one module and then change an integer in the same or one other module which somehow indicates the number of variables. I thought about some kind of array of integer pointers that would simply be looped through in the "store" routine, but it seems every pointer has to be declared to the size of the target. Wouldn't this require changes in the "store" routine for every added global variable?
Thanks for any hints,
Olof
I am a F90 newbie and need advice on the following problem. I am converting an old program from F77 to F90. In this program a number of time-dependent differential equations are solved for different but coupled geometries (so-called linked runs) by looping through all geometries during each time step. In the F77 version, all the variables and constants for all runs are stored in one large array, and the variables for the current run are accessed via a COMMON-block. To read/write all variables for each run the following type of coding is used:
C main program real store_vars(12,3) integer irun real a,b,c(10) common /variables/a,b,c do irun=1,3 C Read variables for current run from storage array. call store(irun,'R',store_vars) C Do stuff with a,b and c... C Write variables for current run to storage array. call store(irun,'W',store_vars) enddo end subroutine store(irun,action,store_vars) integer irun character action real store_vars(12,3),run_vars(12) common /variables/run_vars if (action.eq.'W') C Write to storage array. do i=1,12 store_vars(i,irun)=run_vars(i) enddo else C Read from storage array. do i=1,12 run_vars(i)=store_vars(i,irun) enddo endif return end
How do I do this without the COMMON-block in Fortran 90 and without having to list all the variables in the subroutine "store" (there are quite a few of them)? I'm trying to move the code away from F77 by using modules for global variables, but I haven't figured out a way to do the above in a "nice" way. Since the code is used for research users may modify the code and add global variables, so I don't want the person in question having to make changes in lots of files and subroutines. Preferably, the user will only have to add a declaration in one module and then change an integer in the same or one other module which somehow indicates the number of variables. I thought about some kind of array of integer pointers that would simply be looped through in the "store" routine, but it seems every pointer has to be declared to the size of the target. Wouldn't this require changes in the "store" routine for every added global variable?
Thanks for any hints,
Olof
Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page