/[MITgcm]/MITgcm_contrib/ESMF/mytools/mkmod.sh
ViewVC logotype

Contents of /MITgcm_contrib/ESMF/mytools/mkmod.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.13 - (show annotations) (download) (as text)
Thu Mar 18 22:19:16 2004 UTC (21 years, 4 months ago) by cnh
Branch: MAIN
CVS Tags: adoption_1_0_pre_A, HEAD
Changes since 1.12: +3 -3 lines
File MIME type: application/x-sh
Error occurred while calculating annotation data.
Options for debug building

1 #!<TCSH_PATH> -f
2 #
3 #$Id: mkmod.sh,v 1.12 2004/02/27 17:51:57 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 cat ${mpref_l}_mod.Ftmp | sed s'/C_'${mpref_s}'_MPIPRIV/MPIPRIV/' > f1.Ftmp
130 cp f1.Ftmp ${mpref_l}_mod.Ftmp
131
132
133 echo "Compiling code"
134 source ${BUILDROOT}/mytools/comp_profile.BASE
135 source ${BUILDROOT}/mytools/comp_profile.${COMP_PROF}
136
137 set compinc = ( ${compinc} -I${BUILDROOT}/esmf_top )
138
139
140 # Create output directory
141 mkdir mmout
142
143 # Create runtime library archive
144 set mitgcmrtlo = ( )
145 foreach f ( $mitgcmrtl )
146 echo " " | $comp $compopts_num -c ${f}
147 set mitgcmrtlo = ( $mitgcmrtlo ${f:r}.o )
148 end
149 ${cccommand} ${ccopts} tim.c
150 set mitgcmrtlo = ( $mitgcmrtlo tim.o )
151 \rm mmout/libmitgcmrtl.a
152 ${arcommand} ${aropts} mmout/libmitgcmrtl.a $mitgcmrtlo
153 #ranlib mmout/libmitgcmrtl.a
154
155 # Create component library archive
156 mv ${mpref_l}_mod.Ftmp ${mpref_l}_mod.F
157 source ${BUILDROOT}/mytools/scommand
158 mv foo.F ${mpref_l}_mod.F
159 echo " " | $comp $compopts_num -c ${mpref_l}_mod.F ${complibs} ${compinc}
160 mv ${mpref_l}_mod.F ${mpref_l}_mod.Ftmp
161 ./template_comp.sh ${mpref_s}
162 ${cccommand} ${ccopts} component_${mpref_s}_context.c
163 \rm mmout/lib${mpref_l}.a
164 ${arcommand} ${aropts} mmout/lib${mpref_l}.a ${mpref_l}_mod.o component_${mpref_s}_context.o
165 #ranlib mmout/lib${mpref_l}.a
166 set modname = `echo ${mpref_l} | ${mkmodname}`
167 echo $modname
168 cp ${modname}.mod mmout
169 #\rm *mod

  ViewVC Help
Powered by ViewVC 1.1.22