[comp.lang.fortran] Using RCS with Fortran

fisher@Alliant.COM (Larry Fisher) (11/09/89)

In article <600@caldwr.UUCP> rfinch@caldwr.UUCP (Ralph Finch) writes:
>
>I just started using RCS to maintain our Fortran programs.  What I
>wish to do is print the rcs id info for the main routine and each
>subroutine, from the main program.  

>I have tried various combinations of static and save declarations in a
>vain attempt to get the compiler to accept this.  Is the problem the
>use of the local data statement in each subroutine?  

The problem is that the compiler generates one data area in the .o file
for the entire common block for which you have any data.  If two separate
routines both have a data declaration for the same common block, even
if for different locations, then the linker is left with the task of
deciding what to do.  

Since data areas in the .o file cover the WHOLE common block, there is
no simple way for the loader to combine the two tables into a single
common block image.  The Unix standard format .o files do not lend
themselves to having only parts of data areas defined, as is the problem
in your case.

>How can I easily
>accomplish the goal of printing each subroutine revision from the main
>program?

My thought was to have a standard form of comment in each routine.  The
text in the comment would contain the $Id$ you showed in your example
and would be read by some tool that ended up writing either a data file
(that could be read by the main program) or writing a file that looks
like a BLOCK DATA that defines the array elements for the common block
(which could be compiled and linked with the rest of the program).


-- 
Larry Fisher			Domain:	fisher@alliant.com
Alliant Computer Systems	UUCP:	{mit-eddie|linus}!alliant!fisher
Littleton, MA 01460		Phone:	(508) 486-1449

hirchert@uxe.cso.uiuc.edu (11/10/89)

Richard Maine (maine@elxsi.dfrf.nasa.gov) writes:
>Just put the 5 ids in 5 separate common blocks (perhaps named
>something brilliant like rcs1,rcs2..rcs5) instead of trying to put them
>all in the same one.  Your problem is that you cannot have data statements
>for one common block in multiple subroutines.  The fact that you are
>trying to initialize different parts of the common block in the different
>routines is irrelevant.  This is a very common (no pun intended) limitation
>on many systems, not just the Sun.
>
>Of course, per ANSI standard, data statemnts for variables in common are
>never legal, except in block data, which won't do you much good.  The Sun
>happens to allow a little more here than ANSI demands, but there are
>major compilers that don't allow anything beyond the standard.
>
>So if you care about portability or standards, you will have to try a
>whole different approach (I have no good suggestions off the top of my
>head, though there are bound to be ways - as a last resort you could
>make an entry in each subroutine that is called at program startup,
>which would work, but is really ugly and questionable style - there's
>gota be a better way than that).

How about putting the initialization for common block RCSn in a block data
subprogram named BDATn and putting one block data in with each subroutine?
(This might be as ugly as the entry point suggestion, but it avoids the
run-time overhead of all those calls.)

By the way, note that the name of the variable in common block RCSn can also
be RCSn.  (This is one of the few cases where FORTRAN allows one name to be
used for two different purposes in a single program unit.)


Kurt W. Hirchert     hirchert@ncsa.uiuc.edu
National Center for Supercomputing Applications