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

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

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


Revision 1.5 - (hide annotations) (download) (as text)
Mon Feb 16 18:57:53 2004 UTC (21 years, 5 months ago) by cnh
Branch: MAIN
Changes since 1.4: +0 -0 lines
File MIME type: application/x-sh
Base files needed for simple component build

1 cnh 1.1 #!/usr/local/bin/tcsh -f
2     #
3 cnh 1.4 #$Id: mkmod.sh,v 1.3 2004/02/16 15:39:22 cnh Exp $
4 cnh 1.2 #$Name: $
5 cnh 1.1 #
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 cnh 1.3 # 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 cnh 1.1 #
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 cnh 1.3 # Set output directory - this is the directory where the compile and link objects
29     # that other builds (ESMF drivers etc..) use
30 cnh 1.1 set outdir = ( mmout )
31    
32 cnh 1.3 # Get the genmake generated Makefile to create the .f files
33 cnh 1.1 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 cnh 1.3 echo "Creating top lines for module source"
60 cnh 1.1 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 cnh 1.3
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 cnh 1.1 cat ${mpref_l}_mod3.Ftmp >> ${mpref_l}_mod.Ftmp
73    
74 cnh 1.3 # Remove EXTERNAL refs for functions (some compilers say it is an error to have EXTERNAL )
75     # ( on these if they are in a module )
76 cnh 1.1 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 cnh 1.3 # Remove type declaarations for functions (some compilers say it is an error to have TYPE in )
86     # (a routine for these if they are in a module )
87 cnh 1.1 echo "Removing type declarations for functions that are within the module"
88     cat ${mpref_l}_mod.Ftmp | grep -iv ' *LOGICAL *DIFFERENT_MULTIPLE' > f1.Ftmp
89     cp f1.Ftmp ${mpref_l}_mod.Ftmp
90     cat ${mpref_l}_mod.Ftmp | grep -iv ' *INTEGER *ILNBLNK' > f1.Ftmp
91     cp f1.Ftmp ${mpref_l}_mod.Ftmp
92     cat ${mpref_l}_mod.Ftmp | grep -iv ' *INTEGER *IFNBLNK' > f1.Ftmp
93     cp f1.Ftmp ${mpref_l}_mod.Ftmp
94     cat ${mpref_l}_mod.Ftmp | grep -iv ' *INTEGER *TIMER_INDEX' > f1.Ftmp
95     cp f1.Ftmp ${mpref_l}_mod.Ftmp
96     cat ${mpref_l}_mod.Ftmp | grep -iv ' *INTEGER *IO_ERRCOUNT' > f1.Ftmp
97     cp f1.Ftmp ${mpref_l}_mod.Ftmp
98     cat ${mpref_l}_mod.Ftmp | grep -iv ' *INTEGER *MDS_RECLEN' > f1.Ftmp
99     cp f1.Ftmp ${mpref_l}_mod.Ftmp
100     cat ${mpref_l}_mod.Ftmp | grep -iv ' *INTEGER *NLATBND' > f1.Ftmp
101     cp f1.Ftmp ${mpref_l}_mod.Ftmp
102     cat ${mpref_l}_mod.Ftmp | grep -iv ' *REAL\*8 *PORT_RAND' > f1.Ftmp
103     cp f1.Ftmp ${mpref_l}_mod.Ftmp
104     cat ${mpref_l}_mod.Ftmp | grep -iv ' *REAL\*8 *SBO_RHO' > f1.Ftmp
105     cp f1.Ftmp ${mpref_l}_mod.Ftmp
106     cat ${mpref_l}_mod.Ftmp | grep -iv ' *REAL\*8 *EXF_BULKQSAT' > f1.Ftmp
107     cp f1.Ftmp ${mpref_l}_mod.Ftmp
108     cat ${mpref_l}_mod.Ftmp | grep -iv ' *REAL\*8 *EXF_BULKCDN' > f1.Ftmp
109     cp f1.Ftmp ${mpref_l}_mod.Ftmp
110     cat ${mpref_l}_mod.Ftmp | grep -iv ' *REAL\*8 *EXF_BULKRHN' > f1.Ftmp
111     cp f1.Ftmp ${mpref_l}_mod.Ftmp
112    
113     echo "Putting END FUNCTION at end of functions"
114     cat ${mpref_l}_mod2.Ftmp | awk -f print_func.awk > ${mpref_l}_mod4.Ftmp
115     cat ${mpref_l}_mod4.Ftmp >> ${mpref_l}_mod.Ftmp
116    
117 cnh 1.3 echo "Write the end of the module"
118     cat ${mpref_l}_mod2.Ftmp | awk -f print_func.awk > ${mpref_l}_mod4.Ftmp
119 cnh 1.1 cat <<EOF >> ${mpref_l}_mod.Ftmp
120     END MODULE ${mpref_l}
121     EOF
122 cnh 1.3
123     # Change all the common block names in the module to use the module prefix
124 cnh 1.1 # cat ${mpref_l}_mod.Ftmp | sed s'z\( *COMMON *[^/]*/ *\)\([^ ]*\)\( */.*\)z\1COMPOCEAN_\2\3z' >f1.Ftmp
125     cat ${mpref_l}_mod.Ftmp | sed s'z\( *COMMON[^/]*\)/\(.*\)/\([^/]*\)z COMMON/C_'${mpref_s}'_\2/\3z' > f1.Ftmp
126     cp f1.Ftmp ${mpref_l}_mod.Ftmp
127    
128     echo "Compiling code"
129     set comp = /s/local/1/cnh/usr/local/pkg/lammpi/lam-7.0.3/lahey/bin/mpif77
130     set compopts = ( --dbl -O0 --fix --lst --xref --wide -I/s/local/1/cnh/usr/local/src/ESMF_1_0_4_withlam/esmf/mod/modO/Linux.lahey.32.default )
131     set complibs = ( -L/s/local/1/cnh/usr/local/src/ESMF_1_0_4_withlam/esmf/lib/libO/Linux.lahey.32.default -lesmf )
132    
133     set comp = /usr/local/pkg/mpi/mpi-1.2.4..8a-gm-1.5/pgi/bin/mpif90
134     set compopts = ( -r8 -Mfixed -Mextend -byteswapio )
135     set complibs = ( )
136    
137     set comp = /usr/local/pkg/mpi/mpich-1.2.5..10/lahey/bin/mpif90
138     set compopts = ( --dbl --o2 --fix --lst --xref --wide --tp4 )
139     #set compopts = ( --dbl --o0 --fix --lst --xref --wide --sav )
140     set complibs = ( -L/usr/local/pkg/ESMF/ESMF_1_0_4/mpich-1.2.5..10/lahey/lib/libO/Linux.lahey.32.default -lesmf )
141     set compinc = ( -I/usr/local/pkg/ESMF/ESMF_1_0_4/mpich-1.2.5..10/lahey/mod/modO/Linux.lahey.32.default )
142     set compinc = ( ${compinc} -I${BUILDROOT}/esmf_top )
143    
144     #set comp = xlf95
145     #set compopts = ( -qfixed=132 -O3 -qarch=pwr4 -qtune=pwr4 -qcache=auto -qmaxmem=-1 -bmaxdata:0x80000000 -q64 )
146     #set compopts = ( --dbl --o0 --fix --lst --xref --wide --sav )
147     #set complibs = ( -L/fs/cgd/data0/erik/esmf/lib/libO/AIX.default.64.default -lesmf )
148     #set compinc = ( -I/fs/cgd/data0/erik/esmf/mod/modO/AIX.default.64.default )
149    
150    
151 cnh 1.2 source ${BUILDROOT}/mytools/comp_profile.${COMP_PROF}
152 cnh 1.1
153     set compinc = ( ${compinc} -I${BUILDROOT}/esmf_top )
154    
155    
156     # Create output directory
157     mkdir mmout
158    
159     # Create runtime library archive
160     set mitgcmrtlo = ( )
161     foreach f ( $mitgcmrtl )
162     echo " " | $comp $compopts -c ${f}
163     set mitgcmrtlo = ( $mitgcmrtlo ${f:r}.o )
164     end
165     cc -q64 -c tim.c
166     set mitgcmrtlo = ( $mitgcmrtlo tim.o )
167     \rm mmout/libmitgcmrtl.a
168     ar -X64 -s -rc mmout/libmitgcmrtl.a $mitgcmrtlo
169     #ranlib mmout/libmitgcmrtl.a
170    
171     # Create component library archive
172     mv ${mpref_l}_mod.Ftmp ${mpref_l}_mod.F
173 cnh 1.2 source ${BUILDROOT}/mytools/scommand
174 cnh 1.1 mv foo.F ${mpref_l}_mod.F
175     echo " " | $comp $compopts -c ${mpref_l}_mod.F ${complibs} ${compinc}
176     mv ${mpref_l}_mod.F ${mpref_l}_mod.Ftmp
177     ./template_comp.sh ${mpref_s}
178     cc -q64 -c component_${mpref_s}_context.c
179     \rm mmout/lib${mpref_l}.a
180     ar -X64 -s -rc mmout/lib${mpref_l}.a ${mpref_l}_mod.o component_${mpref_s}_context.o
181     #ranlib mmout/lib${mpref_l}.a
182     cp ${mpref_l}.mod mmout
183     \rm *mod
184    
185     # Lahey compiler command line
186     # /usr/local/pkg/lammpi/lam-7.0.3/lahey/bin/mpif77 --dbl -O0 --fix --lst --xref --wide -I/s/local/1/cnh/usr/local/src/ESMF_1_0_4_withlam/esmf/mod/modO/Linux.lahey.32.default main.F90 ${mpref_l}_mod.o mdsio_byteswapr4.o mdsio_byteswapr8.o fool_the_compiler.o tim.o -L/home/cnh/src/ESMF_1_0_4_withlam/esmf/lib/libO/Linux.lahey.32.default -lesmf
187     # To run
188     # /s/local/1/cnh/usr/local/pkg/lammpi/lam-7.0.3/lahey/bin/mpirun -np 4 -t -v ../build/a.out
189     # To start lam daemon
190     # /s/local/1/cnh/usr/local/pkg/lammpi/lam-7.0.3/lahey/bin/lamboot -c /s/local/1/cnh/usr/local/pkg/lammpi/lam-7.0.3/lahey/etc/lam-conf.lamd -v -d
191     # NB - for starting daemon you need "lamd" in your search path

  ViewVC Help
Powered by ViewVC 1.1.22