r5152 | xinzhang | 2011-09-26 21:04:33 -0700 (Mon, 26 Sep 2011) | 3 lines
[wrffire.git] / wrfv2_fire / compile
blob7e9eb1a5b9024711cc06e6edcd3b6b5b1824021b
1 #!/bin/csh -f
3 setenv START_OF_COMPILE "`date`"
5 cont1:
7 if ( ! -e configure.wrf ) then
8 if ( $1 == "all_wrfvar" ) then
9 ./configure wrfda
10 set dontask
11 else
12 ./configure $1
13 set dontask
14 endif
15 endif
18 #----------------------------------
19 if ( ! $?WRF_KPP ) setenv WRF_KPP 0
20 if ( $WRF_KPP == 1 ) then
21 chem/KPP/compile_wkc
22 endif
24 #---------------------------------
26 if ( ! $?dontask && $?prompt ) then
27 echo "This script assumes you have configured the code already."
28 echo "You only need to configure once."
29 echo "If you wish to reconfigure, type c at the prompt below"
30 echo " "
31 echo "Ready to compile? [ync]"
32 set resp=$<
34 if ( "$resp" == "c" ) then
35 ./configure
36 goto cont1
37 endif
39 if ( "$resp" == "n" ) then
40 exit 2
41 endif
42 endif
44 set arglist=""
45 foreach a ( $argv )
46 if ( "$a" == "-h" ) then
47 goto hlp
48 else
49 if ( "$a" != "-d" ) then
50 set arglist = ( $arglist $a )
51 endif
52 if ( "$a" == "all_wrfvar" ) then
53 grep "DA_CORE=1" configure.wrf > /dev/null
54 if ( ! $status ) then
55 # If configuration file has DA_CORE=1 hardwired, ok to set WRF_DA_CORE to 1
56 setenv WRF_DA_CORE 1
57 endif
58 endif
59 if ( "$a" == "nmm_real" ) then
60 grep "NMM_CORE=1" configure.wrf > /dev/null
61 if ( ! $status ) then
62 # If configuration file has NMM_CORE=1 hardwired, ok to set WRF_NMM_CORE to 1
63 if ( ! $?WRF_NMM_CORE ) setenv WRF_NMM_CORE 1
64 endif
65 endif
66 if ( "$a" == "-j" ) then
67 shift argv
68 setenv J "-j $argv[1]"
69 endif
70 endif
71 end
73 if ( "$arglist" == "" ) then
74 goto hlp
75 else
76 unsetenv A2DCASE
77 setenv A2DCASE `echo $arglist | grep 2d`
79 if ( ! ( $?WRF_EM_CORE || $?WRF_NMM_CORE \
80 || $?WRF_COAMPS_CORE || $?WRF_EXP_CORE )) then
81 echo 'None of WRF_EM_CORE, WRF_NMM_CORE, '
82 # echo ' WRF_COAMPS_CORE, or WRF_EXP_CORE '
83 echo ' specified in shell environment.... '
84 setenv WRF_EM_CORE 1
85 setenv WRF_NMM_CORE 0
86 setenv WRF_COAMPS_CORE 0
87 setenv WRF_EXP_CORE 0
88 endif
90 # these settings get passed down through the environment in the
91 # calls to Make
92 if ( ! $?WRF_DA_CORE ) setenv WRF_DA_CORE 0
93 if ( ! $?WRF_EM_CORE ) setenv WRF_EM_CORE 0
94 if ( ! $?WRF_NMM_CORE ) setenv WRF_NMM_CORE 0
95 if ( ! $?WRF_NMM_NEST ) setenv WRF_NMM_NEST 0
96 if ( ! $?WRF_COAMPS_CORE ) setenv WRF_COAMPS_CORE 0
97 if ( ! $?WRF_EXP_CORE ) setenv WRF_EXP_CORE 0
98 if ( ! $?WRF_CHEM ) setenv WRF_CHEM 0
99 if ( ! $?WRF_DFI_RADAR ) setenv WRF_DFI_RADAR 0
100 if ( ! $?HWRF ) setenv HWRF 0
101 if ( ! $?WRF_CONVERT ) then
102 if ( "$arglist" == "convert_em" ) then
103 setenv WRF_CONVERT 1
104 setenv WRF_EM_CORE 0
105 else
106 setenv WRF_CONVERT 0
107 endif
108 endif
110 if ( ! $?DA_ARCHFLAGS ) setenv DA_ARCHFLAGS ""
112 if ( ( $WRF_DA_CORE == 1 ) && ( ! -d var ) ) then
113 echo " "
114 echo "You need to download and untar the Var code, or"
115 echo "unset the WRF_DA_CORE env variable."
116 echo " "
117 exit
118 endif
120 if ( ( $WRF_CHEM == 1 ) && ( ! -d chem ) ) then
121 echo " "
122 echo "You need to download and untar the chem code, or"
123 echo "unset the WRF_CHEM env variable."
124 echo " "
125 exit
126 endif
128 set overwrite=0
129 if ($WRF_NMM_CORE == 1 && $WRF_DFI_RADAR == 1 ) then
130 echo "radar dfi not yet supported in NMM core, set WRF_DFI_RADAR to 0 "
131 endif
133 if ($WRF_NMM_CORE == 1 && $WRF_CHEM == 1 ) then
134 echo "Chemistry not yet supported in NMM core, set WRF_CHEM to 0 "
135 if ( ! -f Registry/Registry ) then
136 echo Registry file does not exist
137 set overwrite=1
138 else
139 head -2 Registry/Registry | tail -1 | grep NMM_CHEM > /dev/null
140 if ( $status ) then
141 set overwrite=1
142 else
143 set nmm_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.NMM_CHEM' | grep -v 'Registry.NMM_CHEM.' | awk '{print $1}'`
144 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
145 if ( $nmm_time > $rg_time ) set overwrite=1
146 endif
147 endif
148 if ( $overwrite ) then
149 echo copying Registry/Registry.NMM_CHEM to Registry/Registry
150 echo '## WARNING: this file is autogenerated from Registry/Registry.NMM_CHEM. Changes may be lost' > Registry/Registry
151 /bin/cat Registry/Registry.NMM_CHEM >> Registry/Registry
152 endif
153 # exit 2
154 endif
157 if ($WRF_EM_CORE == 1 && $WRF_NMM_CORE == 1 ) then
158 echo "Cannot compile both EM and NMM cores in same executable yet."
159 exit 2
160 endif
161 if ($WRF_EM_CORE == 0 && $WRF_NMM_CORE == 0 && ! $WRF_CONVERT == 1 ) then
162 echo "Cannot compile because both EM and NMM cores are set to 0."
163 exit 2
164 endif
165 if ("$arglist" == 'nmm_real' && $WRF_NMM_CORE == 0) then
166 echo WRF_NMM_CORE must be set to 1 in order to compile nmm_real
167 exit 2
168 endif
169 if (($WRF_EM_CORE == 1)&&($WRF_DA_CORE == 0 ) &&($WRF_CHEM == 0 )&&($WRF_CONVERT == 0)) then
170 if ( ! -f Registry/Registry ) then
171 set overwrite=1
172 else
173 head -2 Registry/Registry | tail -1 | grep EM > /dev/null
174 if ( $status ) then
175 set overwrite=1
176 else
177 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM' | grep -v 'Registry.EM.' | awk '{print $1}'`
178 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
179 if ( $em_time > $rg_time ) set overwrite=1
180 endif
181 endif
182 if ( $overwrite ) then
183 echo copying Registry/Registry.EM to Registry/Registry
184 echo '## WARNING: this file is autogenerated from Registry/Registry.EM. Changes may be lost' > Registry/Registry
185 /bin/cat Registry/Registry.EM >> Registry/Registry
186 endif
187 else if (($WRF_EM_CORE == 1)&&($WRF_CHEM == 1 )) then
188 if ( ! -f Registry/Registry ) then
189 set overwrite=1
190 else
191 head -2 Registry/Registry | tail -1 | grep EM_CHEM > /dev/null
192 if ( $status ) then
193 set overwrite=1
194 else
195 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM_CHEM' | grep -v 'Registry.EM_CHEM.' | awk '{print $1}'`
196 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
197 if ( $em_time > $rg_time ) set overwrite=1
198 endif
199 endif
200 if ( $overwrite ) then
201 echo copying Registry/Registry.EM_CHEM to Registry/Registry
202 echo '## WARNING: this file is autogenerated from Registry/Registry.EM_CHEM. Changes may be lost' > Registry/Registry
203 /bin/cat Registry/Registry.EM_CHEM >> Registry/Registry
204 endif
205 else if (($WRF_EM_CORE == 1)&&($WRF_DFI_RADAR == 1 )) then
206 if ( ! -f Registry/Registry ) then
207 set overwrite=1
208 endif
209 if ( $overwrite ) then
210 echo copying Registry/Registry.EM to Registry/Registry
211 echo '## WARNING: this file is autogenerated from Registry/Registry.EM. Changes may be lost' > Registry/Registry
212 /bin/cat Registry/Registry.EM >> Registry/Registry
213 endif
214 else if (($WRF_EM_CORE == 0)&&($WRF_CONVERT == 1 )) then
215 if ( ! -f Registry/Registry ) then
216 set overwrite=1
217 else
218 head -2 Registry/Registry | tail -1 | grep EM_CONVERT > /dev/null
219 if ( $status ) then
220 set overwrite=1
221 else
222 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM_CONVERT' | grep -v 'Registry.EM_CONVERT.' | awk '{print $1}'`
223 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
224 if ( $em_time > $rg_time ) set overwrite=1
225 endif
226 endif
227 if ( $overwrite ) then
228 echo copying Registry/Registry.CONVERT to Registry/Registry
229 echo '## WARNING: this file is autogenerated from Registry/Registry.CONVERT. Changes may be lost' > Registry/Registry
230 /bin/cat Registry/Registry.CONVERT >> Registry/Registry
231 endif
232 else if ( $WRF_DA_CORE == 1 ) then
233 if ( ! -f Registry/Registry ) then
234 set overwrite=1
235 else
236 head -2 Registry/Registry | tail -1 | grep WRFVAR > /dev/null
237 if ( $status ) then
238 set overwrite=1
239 else
240 set nmm_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.NMM' | grep -v 'Registry.NMM.' | awk '{print $1}'`
241 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
242 if ( $nmm_time > $rg_time ) set overwrite=1
243 endif
244 endif
245 if ( $overwrite ) then
246 echo copying Registry/Registry.wrfvar to Registry/Registry
247 echo '## WARNING: this file is autogenerated from Registry/Registry.wrfvar. Changes may be lost' > Registry/Registry
248 /bin/cat Registry/Registry.wrfvar >> Registry/Registry
249 endif
250 if ( $?CRTM ) then
251 if ( ! $?BUFR ) then
252 echo " "
253 echo "BUFR library will be compiled for radiance data ingest."
254 echo " "
255 setenv BUFR 1
256 endif
257 setenv CRTM_CPP "-DCRTM"
258 setenv CRTM_LIB "-L../external/crtm/libsrc -lCRTM"
259 setenv CRTM_SRC "-I../external/crtm/libsrc"
260 setenv SFC_CRTM `grep '^SFC' configure.wrf | awk '{print $3}' | sed -e 's/\// /g' | awk '{print $NF}'`
261 setenv ABI_CRTM `grep '^SFC' configure.wrf | sed -n 's/.*\(\-m[0-9]\{2\}\).*/\1/p'`
262 else
263 setenv CRTM_CPP " "
264 setenv CRTM_LIB " "
265 setenv CRTM_SRC " "
266 endif
267 if ( $?RTTOV ) then
268 if ( ! $?BUFR ) then
269 echo " "
270 echo "BUFR library is needed for radiance data ingest."
271 echo " "
272 setenv BUFR 1
273 endif
274 setenv RTTOV_CPP "-DRTTOV"
275 setenv RTTOV_LIB "-L${RTTOV}/lib -lrttov10.1.0_coef_io -lrttov10.1.0_emis_atlas -lrttov10.1.0_main"
276 setenv RTTOV_SRC "-I${RTTOV}/include -I${RTTOV}/mod"
277 else
278 setenv RTTOV_CPP " "
279 setenv RTTOV_LIB " "
280 setenv RTTOV_SRC " "
281 endif
282 if ( $?BUFR ) then
283 setenv BUFR_CPP "-DBUFR"
284 setenv BUFR_LIB "-L../external/bufr -lbufr"
285 else
286 setenv BUFR_CPP " "
287 setenv BUFR_LIB " "
288 endif
289 if ( $?WAVELET ) then
290 setenv WAVELET_LIB "../external/wavelet/libWavelet.a ../external/wavelet/lib_wavelet.a"
291 else
292 setenv WAVELET_LIB " "
293 endif
294 if ( $?MADIS ) then
295 setenv MADIS_CPP "-DMADIS"
296 setenv MADIS_STATIC ${MADIS}/static
297 setenv MADIS_LIB "-L${MADIS} -lmadis"
298 else
299 setenv MADIS_CPP " "
300 setenv MADIS_LIB " "
301 endif
302 setenv DA_ARCHFLAGS "${BUFR_CPP} ${MADIS_CPP} -DFFTPACK -DNORESHAPE"
303 endif
304 if (($WRF_NMM_CORE == 1)&&($WRF_CHEM == 0 )) then
305 if ( ! -f Registry/Registry ) then
306 set overwrite=1
307 else
308 head -2 Registry/Registry | tail -1 | grep NMM > /dev/null
309 if ( $status ) then
310 set overwrite=1
311 else
312 set nmm_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.NMM' | grep -v 'Registry.NMM.' | awk '{print $1}'`
313 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
314 if ( $nmm_time > $rg_time ) set overwrite=1
315 endif
316 endif
317 if ( $overwrite ) then
318 if (($WRF_NMM_CORE == 1)&&($WRF_NMM_NEST == 1)) then
319 if ($HWRF == 1) then
320 echo copying Registry/Registry.NMM_HWRF to Registry/Registry
321 echo '## WARNING: this file is autogenerated from Registry/Registry.NMM_HWRF. Changes may be lost' > Registry/Registry
322 /bin/cat Registry/Registry.NMM_HWRF >> Registry/Registry
323 else
324 echo copying Registry/Registry.NMM_NEST to Registry/Registry
325 echo '## WARNING: this file is autogenerated from Registry/Registry.NMM_NEST. Changes may be lost' > Registry/Registry
326 /bin/cat Registry/Registry.NMM_NEST >> Registry/Registry
327 endif
328 else
329 echo copying Registry/Registry.NMM to Registry/Registry
330 echo '## WARNING: this file is autogenerated from Registry/Registry.NMM. Changes may be lost' > Registry/Registry
331 /bin/cat Registry/Registry.NMM >> Registry/Registry
332 endif
333 endif
334 # integrity check for a kludge where a hard coded value in the
335 # registry must match the same value in arch/preamble_new
336 set registryvalue=`grep 'dimspec.* q ' Registry/registry.dimspec | sed -e 's/..*constant=//' -e 's/ ..*$//'`
337 set preamblevalue=`grep 'DNMM_MAX_DIM=.*' arch/preamble_new | sed -e 's/..*-DNMM_MAX_DIM=//' -e 's/ ..*$//'`
338 if ( $registryvalue != $preamblevalue ) then
339 echo "Harded coded value of dimspec q in Registry ($registryvalue) does not"
340 echo "equal the hard coded value of NMM_MAX_DIM in arch/preamble_new ($preamblevalue)"
341 echo "Please fix and try again."
342 exit 2
343 endif
344 endif
346 echo " "
347 echo -n "Compiling: "
348 if ( $WRF_DA_CORE ) echo -n "WRF_DA_CORE "
349 if ( $WRF_EM_CORE ) echo -n "WRF_EM_CORE "
350 if ( $WRF_NMM_CORE ) echo -n "WRF_NMM_CORE "
351 if ( $WRF_COAMPS_CORE ) echo -n "WRF_COAMPS_CORE "
352 if ( $WRF_EXP_CORE ) echo -n "WRF_EXP_CORE "
353 echo "."
354 echo " "
356 if ( ! $?WRF_SRC_ROOT_DIR ) setenv WRF_SRC_ROOT_DIR `pwd`
358 # new dec 2009. check to see if make supports parallel -j option
359 make -j 2 >& /dev/null
360 if ( $status == 0 ) then # Parallel make ok
361 if ( ! $?J ) then # J not defined
362 echo setting parallel make -j 2 # Set default to 2
363 setenv J "-j 2"
364 else
365 # J is defined, check that it is a correctly formed variable
366 set first2chars = `echo $J | cut -c 1-2` # Are 1st two chars are -j?
367 set second_word = `echo $J | cut -d" " -f2` # Is second word a number?
368 if ( "$first2chars" == "-j" ) then
369 if ( ( "$second_word" >= "2" ) && \
370 ( "$second_word" <= "20" ) ) then
371 echo setting parallel make $J
372 else if ( "$second_word" == "1" ) then
373 echo setting serial make $J
374 else
375 echo "badly formed -j option for parallel make: $J"
376 echo "or you set the number of processors above 20 "
377 echo setting parallel make -j 2 # Set default to 2
378 setenv J "-j 2"
379 endif
380 else
381 if ( "$J" == "" ) then # J blank is OK
382 echo setting serial make $J
383 else
384 echo "parallel option for make is -j, you entered: $first2chars"
385 echo setting parallel make -j 2 # Set default to 2
386 setenv J "-j 2"
387 endif
388 endif
389 endif
390 else
391 echo not setting parallel make
392 endif
394 make $arglist A2DCASE="$A2DCASE" WRF_SRC_ROOT_DIR="$WRF_SRC_ROOT_DIR"
396 endif
398 exit 0
400 hlp:
402 echo ' '
403 echo 'Usage:'
404 echo ' '
405 echo ' compile [-d] [-j n] wrf compile wrf in run dir (NOTE: no real.exe, ndown.exe, or ideal.exe generated)'
406 echo ' '
407 echo ' or choose a test case (see README_test_cases for details) :'
408 foreach d ( `/bin/ls test` )
409 if ( "$d" != "CVS" ) then
410 echo " compile $d"
411 endif
413 echo ' '
414 echo ' compile -d compile without optimization and with debugging'
415 echo ' compile -j n parallel make using n tasks if supported (default 2)'
416 echo ' compile -h help message'