Fortran77 Source Maintainence Example

This example showcases several concepts. First, it uses extract to include a license with varying parameters in all source files. Second, it demonstrates how differing codes that share a lot of codebase can come from one source file. First, let us say you save the following in type.inc:
@TYPE SREAL
   @define pre @S@
   @define type @REAL@
@TYPE DREAL
   @define pre @D@
   @define type @DOUBLE PRECISION@
@TYPE SCPLX
   @define pre @C@
   @define type @COMPLEX@
@TYPE DCPLX
   @define pre @Z@
   @define type @DOUBLE COMPLEX@
@TYPE !

This file can be used by all files to set up type-dependant macros. Now we save the following license template to license.inc:


@ifdef ! ver
   @define ver @3.0Beta@
@endifdef
@ifdef ! author
   @define author @R. Clint Whaley@
@endifdef
@ifdef ! cdate
   @define cdate @1997@
@endifdef
@define nmln @(C) Copyright @(cdate) @(author)@
*
*             Automatically Tuned Linear Algebra Software v@(ver)
*@75c@(nmln)
@ifdef contrib
*
* Code contributers : @(author), @(contrib)
@endifdef
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*   1. Redistributions of source code must retain the above copyright
*      notice, this list of conditions and the following disclaimer.
*   2. Redistributions in binary form must reproduce the above copyright
*      notice, this list of conditions, and the following disclaimer in the
*      documentation and/or other materials provided with the distribution.
*   3. The name of the University, the ATLAS group, or the names of its 
*      contributers may not be used to endorse or promote products derived
*      from this software without specific written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. 
*

We are finally ready to actually write some code. Let us say I have written a simply scal, using some advice from Antoine, and Antoine has submitted a simple copy routine. We could keep these routines in a basefile like this:


@ifdef ! incd
   @define incd @/home/rwhaley/PROJ/tools/exdir@
@endifdef
@define curdate @2001@
@extract -b @(incd)/type.inc type=@(@type)
@skip
@ROUT SCAL
@extract -b @(incd)/license.inc -def cdate "@(curdate)" -def contrib "Antoine Petitet"
       SUBROUTINE @(pre)SCAL(N, ALPHA, X)
*
*      X <- ALPHA * X
*
       INTEGER N
       @(type) ALPHA
       @(type) X(*)

       DO I = 1, N
          X(I) = ALPHA * X(I)
       END DO
       
       RETURN
       END
@ROUT COPY
@extract -b @(incd)/license.inc -def author "Antoine Petitet" -def cdate "@(curdate)"
       SUBROUTINE @(pre)COPY(N, X, Y)
*
*      Y <- X
*
       INTEGER N
       @(type) X(*), Y(*)

       DO I = 1, N
          Y(I) = X(I)
       END DO
       
       RETURN
       END
@ROUT !

Obviously, the first big win is that we don't have to keep 4 copies to handle single and double real and complex. If you want to get a particular routine, you would extract it. For instance, if you issued extract -b blas.base type=dreal rout=scal, you'd get:


*
*             Automatically Tuned Linear Algebra Software v3.0Beta
*                    (C) Copyright 2001 R. Clint Whaley                     
*
* Code contributers : R. Clint Whaley, Antoine Petitet
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*   1. Redistributions of source code must retain the above copyright
*      notice, this list of conditions and the following disclaimer.
*   2. Redistributions in binary form must reproduce the above copyright
*      notice, this list of conditions, and the following disclaimer in the
*      documentation and/or other materials provided with the distribution.
*   3. The name of the University, the ATLAS group, or the names of its 
*      contributers may not be used to endorse or promote products derived
*      from this software without specific written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. 
*
       SUBROUTINE DSCAL(N, ALPHA, X)
*
*      X <- ALPHA * X
*
       INTEGER N
       DOUBLE PRECISION ALPHA
       DOUBLE PRECISION X(*)

       DO I = 1, N
          X(I) = ALPHA * X(I)
       END DO
       
       RETURN
       END

On the other hand, extract -b blas.base type=scplx rout=copy, you'd get:


*
*             Automatically Tuned Linear Algebra Software v3.0Beta
*                    (C) Copyright 2001 Antoine Petitet                     
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*   1. Redistributions of source code must retain the above copyright
*      notice, this list of conditions and the following disclaimer.
*   2. Redistributions in binary form must reproduce the above copyright
*      notice, this list of conditions, and the following disclaimer in the
*      documentation and/or other materials provided with the distribution.
*   3. The name of the University, the ATLAS group, or the names of its 
*      contributers may not be used to endorse or promote products derived
*      from this software without specific written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. 
*
       SUBROUTINE CCOPY(N, X, Y)
*
*      Y <- X
*
       INTEGER N
       COMPLEX X(*), Y(*)

       DO I = 1, N
          Y(I) = X(I)
       END DO
       
       RETURN
       END

Back to example index