| 1 | #!<TCSH_PATH> -fxv | 
| 2 | # | 
| 3 | #$Id: mkmod.sh,v 1.6 2004/02/20 16:21:41 cnh Exp $ | 
| 4 | #$Name:  $ | 
| 5 | # | 
| 6 | # Script to create modules for an MITgcm production code instance | 
| 7 | # Run this script after the CPP stage of the standard genmake2 | 
| 8 | # build | 
| 9 | # | 
| 10 | # Script does following | 
| 11 | # Selects a set of "module" files with the .f suffix. | 
| 12 | # The set of module files includes all the source files except | 
| 13 | # main.f and a small number of runtime library files. | 
| 14 | # The module file set is then placed within a module of a given name. | 
| 15 | # A single argument to the script is used to create a module prefix | 
| 16 | # allowing the same source tree to be used for multiple modules with | 
| 17 | # differing names and dirrent sized static data objects. | 
| 18 | # | 
| 19 | # | 
| 20 | # Set module prefix | 
| 21 | if ( $# == 1 ) then | 
| 22 | set mpref_s = ( $1 ) | 
| 23 | else | 
| 24 | set mpref_s = ( atm ) | 
| 25 | endif | 
| 26 | set mpref_l = ( mitgcm_org_${mpref_s} ) | 
| 27 |  | 
| 28 | # Set output directory - this is the directory where the compile and link | 
| 29 | #                        objects that other builds (ESMF drivers etc..) use | 
| 30 | set outdir = ( mmout ) | 
| 31 |  | 
| 32 | # Get the genmake generated Makefile to create the .f files | 
| 33 | echo "Creating small f files" | 
| 34 | make small_f | 
| 35 |  | 
| 36 | echo "Building list of .f files" | 
| 37 | ls -1 *.f > flist | 
| 38 | cp flist flist1 | 
| 39 | set mitgcmrtl   = ( mdsio_byteswapr4.f mdsio_byteswapr8.f fool_the_compiler.f ) | 
| 40 | set excludelist = ( main.f ${mitgcmrtl} ) | 
| 41 | foreach f ( $excludelist ) | 
| 42 | cat flist1 | grep -v "^$f" > flist2 | 
| 43 | cp flist2   flist1 | 
| 44 | end | 
| 45 | cp flist1 flist | 
| 46 | set flist = (`cat flist`) | 
| 47 |  | 
| 48 | echo "Joining .f into ${mpref_s}_mod.F" | 
| 49 | \rm ${mpref_l}_mod.Ftmp ${mpref_l}_mod.F | 
| 50 | foreach f ( $flist ) | 
| 51 | cat $f >> ${mpref_l}_mod.Ftmp | 
| 52 | echo -n "." | 
| 53 | end | 
| 54 | echo " " | 
| 55 |  | 
| 56 | echo "Removing comments and blank lines" | 
| 57 | cat ${mpref_l}_mod.Ftmp | grep -v '^ *$' | grep -v '^[a-zA-Z]' > ${mpref_l}_mod2.Ftmp | 
| 58 |  | 
| 59 | echo "Creating top lines for module source" | 
| 60 | cat <<EOF > ${mpref_l}_mod.Ftmp | 
| 61 | MODULE ${mpref_l} | 
| 62 | USE ESMF_MOD | 
| 63 | PRIVATE | 
| 64 | PUBLIC DRIVER_INIT | 
| 65 | PUBLIC DRIVER_RUN | 
| 66 | PUBLIC GET_DOMAIN_SIZE | 
| 67 | CONTAINS | 
| 68 | EOF | 
| 69 |  | 
| 70 | echo "Putting END SUBROUTINE at end of subroutines" | 
| 71 | cat ${mpref_l}_mod2.Ftmp | awk -f print_sub.awk  > ${mpref_l}_mod3.Ftmp | 
| 72 | cat ${mpref_l}_mod3.Ftmp >> ${mpref_l}_mod.Ftmp | 
| 73 |  | 
| 74 | # Remove EXTERNAL refs for functions (some compilers say it is an error | 
| 75 | # to have EXTERNAL on these if they are in a module ) | 
| 76 | echo "Removing EXTERNAL refs for functions that are within the module" | 
| 77 | set extDel = ( DIFFERENT_MULTIPLE IFNBLNK ILNBLNK TIMER_INDEX \ | 
| 78 | IO_ERRCOUNT MDS_RECLEN PORT_RAND SBO_RHO NLATBND \ | 
| 79 | EXF_BULKQSAT EXF_BULKCDN EXF_BULKRHN) | 
| 80 | foreach e ( $extDel ) | 
| 81 | cat ${mpref_l}_mod.Ftmp | grep -iv "      EXTERNAL *${e}" > f1.Ftmp | 
| 82 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 83 | end | 
| 84 |  | 
| 85 | # Remove type declaarations for functions (some compilers say it is an error | 
| 86 | # to have TYPE in a routine for these if they are in a module ) | 
| 87 | echo "Removing type declarations for functions that are within the module" | 
| 88 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *LOGICAL *DIFFERENT_MULTIPLE' \ | 
| 89 | > f1.Ftmp | 
| 90 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 91 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *INTEGER *ILNBLNK' > f1.Ftmp | 
| 92 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 93 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *INTEGER *IFNBLNK' > f1.Ftmp | 
| 94 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 95 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *INTEGER *TIMER_INDEX' > f1.Ftmp | 
| 96 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 97 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *INTEGER *IO_ERRCOUNT' > f1.Ftmp | 
| 98 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 99 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *INTEGER *MDS_RECLEN' > f1.Ftmp | 
| 100 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 101 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *INTEGER *NLATBND' > f1.Ftmp | 
| 102 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 103 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *REAL\*8 *PORT_RAND' > f1.Ftmp | 
| 104 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 105 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *REAL\*8 *SBO_RHO' > f1.Ftmp | 
| 106 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 107 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *REAL\*8 *EXF_BULKQSAT' > f1.Ftmp | 
| 108 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 109 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *REAL\*8 *EXF_BULKCDN' > f1.Ftmp | 
| 110 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 111 | cat ${mpref_l}_mod.Ftmp | grep -iv '      *REAL\*8 *EXF_BULKRHN' > f1.Ftmp | 
| 112 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 113 |  | 
| 114 | # | 
| 115 | echo "Putting END FUNCTION at end of functions" | 
| 116 | cat ${mpref_l}_mod2.Ftmp | awk -f print_func.awk > ${mpref_l}_mod4.Ftmp | 
| 117 | cat ${mpref_l}_mod4.Ftmp >> ${mpref_l}_mod.Ftmp | 
| 118 |  | 
| 119 | # | 
| 120 | echo "Write the end of the module" | 
| 121 | cat ${mpref_l}_mod2.Ftmp | awk -f print_func.awk > ${mpref_l}_mod4.Ftmp | 
| 122 | cat <<EOF >> ${mpref_l}_mod.Ftmp | 
| 123 | END MODULE ${mpref_l} | 
| 124 | EOF | 
| 125 |  | 
| 126 | # Change all the common block names in the module to use the module prefix | 
| 127 | cat ${mpref_l}_mod.Ftmp | sed s'z\( *COMMON[^/]*\)/\(.*\)/\([^/]*\)z      COMMON/C_'${mpref_s}'_\2/\3z' > f1.Ftmp | 
| 128 | cp f1.Ftmp ${mpref_l}_mod.Ftmp | 
| 129 |  | 
| 130 | echo "Compiling code" | 
| 131 | source ${BUILDROOT}/mytools/comp_profile.${COMP_PROF} | 
| 132 |  | 
| 133 | set compinc  = ( ${compinc} -I${BUILDROOT}/esmf_top ) | 
| 134 |  | 
| 135 |  | 
| 136 | # Create output directory | 
| 137 | mkdir mmout | 
| 138 |  | 
| 139 | # Create runtime library archive | 
| 140 | set mitgcmrtlo = ( ) | 
| 141 | foreach f ( $mitgcmrtl ) | 
| 142 | echo " " | $comp $compopts -c ${f} | 
| 143 | set mitgcmrtlo = ( $mitgcmrtlo ${f:r}.o ) | 
| 144 | end | 
| 145 | cc -q64 -c tim.c | 
| 146 | set mitgcmrtlo = ( $mitgcmrtlo tim.o ) | 
| 147 | \rm mmout/libmitgcmrtl.a | 
| 148 | ${arcommand} ${aropts} mmout/libmitgcmrtl.a $mitgcmrtlo | 
| 149 | #ranlib mmout/libmitgcmrtl.a | 
| 150 |  | 
| 151 | # Create component library archive | 
| 152 | mv ${mpref_l}_mod.Ftmp ${mpref_l}_mod.F | 
| 153 | source ${BUILDROOT}/mytools/scommand | 
| 154 | mv foo.F ${mpref_l}_mod.F | 
| 155 | echo " " | $comp $compopts -c ${mpref_l}_mod.F ${complibs} ${compinc} | 
| 156 | mv ${mpref_l}_mod.F ${mpref_l}_mod.Ftmp | 
| 157 | ./template_comp.sh ${mpref_s} | 
| 158 | cc -q64 -c component_${mpref_s}_context.c | 
| 159 | \rm mmout/lib${mpref_l}.a | 
| 160 | ${arcommand} ${aropts} mmout/lib${mpref_l}.a ${mpref_l}_mod.o component_${mpref_s}_context.o | 
| 161 | #ranlib mmout/lib${mpref_l}.a | 
| 162 | cp ${mpref_l}.mod mmout | 
| 163 | \rm *mod |