Re: moduel VS parameters



yuanliu1@xxxxxxxx wrote:
I got one code from another guy which has forty parameters for each
subroutine call. I do not like it, so I make modules and then
everything is passed through modules.

I assume you mean arguments, rather than parameters?

Now I have a problem. The original subroutine, which is very messy, can
work independant of the other parts as long as I feed it with the right
parameter. In my version of code, I have to use the module everytime.
Since some information are somewhat common to many modules, it is hard
to isolate them. In another words, the modules I used in one subroutine
may contains more information than the subroutine needs.

I know maybe this is something about Object Oriented. But are there
anyway in fortran I can do?

I believe you have just provided a very elegant description of why procedures usually take arguments, rather than receiving everything through modules/COMMON/'global variables.' Forty arguments does sound like a lot, but.....


There are times when it makes sense to pass things through MODULEs. Physical constants are a good example, since they (probably) won't change during any one run, and they would just clutter up the argument list. There are also times when I've had to use MODULEs and/or COMMON in order to keep variables in the right parallelisation scope. But these cases are the exception. As a general rule, if a procedure is supposed to take some data, do some work, and return results... that's the reason procedures take arguments.

Richard
.



Relevant Pages

  • getting rid of common blocks
    ... I was recently given some Fortran code by a collegue of mine. ... end subroutine sub1 ... Since I've never used common blocks in my own code, ... Am i right if i say that I can move all the common variables to ...
    (comp.lang.fortran)
  • Re: fortran mex file and common blocs
    ... i have split the source code of the 4nec2dx into many .f files ... containing each one a subroutine or a function ... starters but "modern" Fortran would USE module variables in place of COMMON. ...
    (comp.soft-sys.matlab)
  • Re: Fortran based MEX w/ COMMON/SAVE
    ... I believe dat (pointer to the array) and the ... SAVE at the begining of each subroutine is a bit unusual to me. ... > to unload it if there isn't a Fortran END or STOP statement. ... interaction w/ Matlab). ...
    (comp.soft-sys.matlab)
  • Re: Help Constructing Fictional Cross-Religious Movement
    ... You know how to do something in Fortran that I ... >don't know how to do despite being pretty familiar with it, COBOL ... > subroutine point ... >was finding a programming problem that seemed reasonably amenable to ...
    (rec.arts.sf.composition)
  • Re: fortran95 error
    ... At a guess you are using a subroutine like: ... declarations I saw nothing that should have given the above error. ... or better yet in a separate COMMON of their own. ... they are all default reals. ...
    (comp.lang.fortran)