updated top-level README and version_decl for V4.4.2 (#1795)
[WRF.git] / compile
blob0595d05db192382e5767a0a985d3296f25b45116
1 #!/bin/csh -f
3 setenv START_OF_COMPILE "`date`"
5 cont1:
7 if ( ! -e configure.wrf ) then
8 echo ""
9 echo "You must run the 'configure' script before running the 'compile' script!"
10 echo "Exiting..."
11 echo ""
12 exit 1
13 endif
15 #----------------------------------
16 # identify the commit where the compiled code came from
17 git log >& /dev/null
18 if ($status) then
19 set v='No git found or not a git repository, git commit version not available.'
20 else
21 set v=(git `git log | head -1` `git diff --shortstat`) >& /dev/null
22 endif
23 echo " CHARACTER (LEN=*), PARAMETER :: commit_version = '$v'" > inc/commit_decl
25 #----------------------------------
26 if ( ! $?WRF_KPP ) setenv WRF_KPP 0
27 if ( $WRF_KPP == 1 ) then
28 chem/KPP/compile_wkc
29 endif
31 #---------------------------------
33 set ZAP = .foofoo
34 set arglist=""
35 set prev_was_j = false
36 set count = 0
37 foreach a ( $argv )
38 @ count ++
39 if ( "$a" == "-h" ) then
40 goto hlp
41 else if ( "$a" == "all_wrfvar" || "$a" == "gen_be" ) then
42 set arglist = ( $arglist $a )
43 grep "DA_CORE=1" configure.wrf > /dev/null
44 if ( ! $status ) then
45 # If configuration file has DA_CORE=1, set WRF_DA_CORE to 1
46 setenv WRF_DA_CORE 1
47 else
48 # If the user ran the configure script without the "wrfda" option, "./compile all_wrfvar"
49 # will fail in non-obvious ways, and some executables will be created incorrectly.
50 # Let's just quit right away to avoid the hassle.
51 echo ""
52 echo "To build WRFDA, you must run the 'configure' script with the 'wrfda' option:"
53 echo " ./configure wrfda"
54 echo ""
55 echo "Exiting..."
56 echo ""
57 exit 1
58 endif
59 else if ( "$a" == "em_real" ) then
60 set arglist = ( $arglist $a )
61 set ZAP = ( main/wrf.exe main/real.exe main/ndown.exe main/tc.exe )
62 else if ( `echo $a | cut -c 1-3` == "em_" ) then
63 set arglist = ( $arglist $a )
64 set ZAP = ( main/wrf.exe main/ideal.exe )
65 else if ( "$a" == "io" ) then
66 set arglist = ( $arglist $a )
67 else if ( "$a" == "wrfplus" ) then
68 set arglist = ( $arglist $a )
69 set ZAP = ( main/wrfplus.exe )
70 setenv WRF_EM_CORE 1
71 setenv WRF_PLUS_CORE 1
72 else if ( "$a" == "wrf" ) then
73 set arglist = ( $arglist $a )
74 set ZAP = ( main/wrf.exe )
75 else if ( "$a" == "-j" ) then
76 @ JJ = $count + 1
77 setenv J "-j $argv[$JJ]"
78 set prev_was_j = true
79 else if ( "$prev_was_j" == "true" ) then
80 set prev_was_j = false
81 else if ( "$a" == "emi_conv" ) then
82 set arglist = ( $arglist $a )
83 set ZAP = ( chem/convert_emiss.exe )
84 else
85 echo "This option is not recognized: $a"
86 exit ( 1 )
87 endif
88 end
90 if ( "$arglist" == "" ) then
91 goto hlp
92 else
93 unsetenv A2DCASE
94 setenv A2DCASE `echo $arglist | grep 2d`
95 unsetenv A1DCASE
96 setenv A1DCASE `echo $arglist | grep scm`
98 if ( ! ( $?WRF_EM_CORE || $?WRF_PLUS_CORE ) ) then
99 echo 'Neither WRF_EM_CORE nor WRF_PLUS_CORE'
100 echo ' are explicitly specified in shell environment.... '
101 setenv WRF_EM_CORE 1
102 setenv WRF_COAMPS_CORE 0
103 setenv WRF_EXP_CORE 0
104 setenv WRF_PLUS_CORE 0
105 endif
107 # these settings get passed down through the environment in the
108 # calls to Make
109 if ( ! $?WRF_HYDRO ) then
110 setenv WRF_HYDRO 0
111 setenv LIB_WRF_HYDRO ""
112 else
113 if($WRF_HYDRO == 1) then
114 setenv LIB_WRF_HYDRO "-L../hydro/lib -lHYDRO"
115 else
116 setenv LIB_WRF_HYDRO ""
117 endif
118 endif
120 if ( ! $?WRF_DA_CORE ) setenv WRF_DA_CORE 0
121 if ( ! $?WRF_EM_CORE ) setenv WRF_EM_CORE 0
122 if ( ! $?WRF_COAMPS_CORE ) setenv WRF_COAMPS_CORE 0
123 if ( ! $?WRF_EXP_CORE ) setenv WRF_EXP_CORE 0
124 if ( ! $?WRF_PLUS_CORE ) setenv WRF_PLUS_CORE 0
125 if ( ! $?WRF_CHEM ) setenv WRF_CHEM 0
126 if ( ! $?WRF_DFI_RADAR ) setenv WRF_DFI_RADAR 0
127 if ( ! $?WRF_CONVERT ) then
128 if ( "$arglist" == "convert_em" ) then
129 setenv WRF_CONVERT 1
130 setenv WRF_EM_CORE 0
131 else
132 setenv WRF_CONVERT 0
133 endif
134 endif
136 # temporary - until all vestiges of NMM ifdefs are gone from WRF source
137 setenv WRF_NMM_CORE 0
138 setenv WRF_NMM_NEST 0
139 setenv HWRF 0
141 if ( ! $?DA_ARCHFLAGS ) setenv DA_ARCHFLAGS ""
143 # if ( ( $WRF_CHEM == 1 ) && ( $WRF_DA_CORE == 1 ) ) then
144 # echo " "
145 # echo "WRFDA can not be compiled with WRF_CHEM=1"
146 # echo "unset the WRF_CHEM env variable."
147 # echo " "
148 # exit
149 # endif
151 if ( ( $WRF_DA_CORE == 1 ) && ( ! -d var ) ) then
152 echo " "
153 echo "You need to download and untar the Var code, or"
154 echo "unset the WRF_DA_CORE env variable."
155 echo " "
156 exit
157 endif
159 if ( ( $WRF_CHEM == 1 ) && ( ! -d chem ) ) then
160 echo " "
161 echo "You need to download and untar the chem code, or"
162 echo "unset the WRF_CHEM env variable."
163 echo " "
164 exit
165 endif
167 set overwrite=0
170 if ($WRF_EM_CORE == 0 && ! $WRF_CONVERT == 1 ) then
171 echo "Cannot compile because both EM core is set to 0."
172 exit 2
173 endif
174 if (($WRF_EM_CORE == 1)&&($WRF_DA_CORE == 0 ) &&($WRF_CHEM == 0 )&&($WRF_CONVERT == 0)&&($WRF_PLUS_CORE == 0) ) then
175 if ( ! -f Registry/Registry ) then
176 set overwrite=1
177 else
178 head -2 Registry/Registry | tail -1 | grep EM > /dev/null
179 if ( $status ) then
180 set overwrite=1
181 else
182 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM' | grep -v 'Registry.EM.' | awk '{print $1}'`
183 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
184 if ( $em_time > $rg_time ) set overwrite=1
185 endif
186 endif
187 if ( $overwrite ) then
188 echo copying Registry/Registry.EM to Registry/Registry
189 echo '## WARNING: this file is autogenerated from Registry/Registry.EM. Changes may be lost' > Registry/Registry
190 /bin/cat Registry/Registry.EM >> Registry/Registry
191 endif
192 else if ( ($WRF_EM_CORE == 1)&&($WRF_PLUS_CORE == 1) ) then
193 if ( ! -f Registry/Registry ) then
194 set overwrite=1
195 else
196 head -2 Registry/Registry | tail -1 | grep WRFPLUS > /dev/null
197 if ( $status ) then
198 set overwrite=1
199 else
200 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.tladj' | grep -v 'Registry.tladj.' | awk '{print $1}'`
201 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
202 if ( $em_time > $rg_time ) set overwrite=1
203 endif
204 endif
205 if ( $overwrite ) then
206 echo copying Registry/Registry.tladj to Registry/Registry
207 echo '## WARNING: this file is autogenerated from Registry/Registry.tladj. Changes may be lost' > Registry/Registry
208 /bin/cat Registry/Registry.tladj >> Registry/Registry
209 endif
210 else if (($WRF_EM_CORE == 1)&&($WRF_CHEM == 1 )&&($WRF_DA_CORE == 0)) then
211 if ( ! -f Registry/Registry ) then
212 set overwrite=1
213 else
214 head -2 Registry/Registry | tail -1 | grep EM_CHEM > /dev/null
215 if ( $status ) then
216 set overwrite=1
217 else
218 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM_CHEM' | grep -v 'Registry.EM_CHEM.' | awk '{print $1}'`
219 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
220 if ( $em_time > $rg_time ) set overwrite=1
221 endif
222 endif
223 if ( $overwrite ) then
224 echo copying Registry/Registry.EM_CHEM to Registry/Registry
225 echo '## WARNING: this file is autogenerated from Registry/Registry.EM_CHEM. Changes may be lost' > Registry/Registry
226 /bin/cat Registry/Registry.EM_CHEM >> Registry/Registry
227 endif
228 else if (($WRF_EM_CORE == 1)&&($WRF_DFI_RADAR == 1 )) then
229 if ( ! -f Registry/Registry ) then
230 set overwrite=1
231 endif
232 if ( $overwrite ) then
233 echo copying Registry/Registry.EM to Registry/Registry
234 echo '## WARNING: this file is autogenerated from Registry/Registry.EM. Changes may be lost' > Registry/Registry
235 /bin/cat Registry/Registry.EM >> Registry/Registry
236 endif
237 else if (($WRF_EM_CORE == 0)&&($WRF_CONVERT == 1 )) then
238 if ( ! -f Registry/Registry ) then
239 set overwrite=1
240 else
241 head -2 Registry/Registry | tail -1 | grep EM_CONVERT > /dev/null
242 if ( $status ) then
243 set overwrite=1
244 else
245 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM_CONVERT' | grep -v 'Registry.EM_CONVERT.' | awk '{print $1}'`
246 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
247 if ( $em_time > $rg_time ) set overwrite=1
248 endif
249 endif
250 if ( $overwrite ) then
251 echo copying Registry/Registry.CONVERT to Registry/Registry
252 echo '## WARNING: this file is autogenerated from Registry/Registry.CONVERT. Changes may be lost' > Registry/Registry
253 /bin/cat Registry/Registry.CONVERT >> Registry/Registry
254 endif
255 else if ( $WRF_DA_CORE == 1 ) then
256 if ( ! -f Registry/Registry ) then
257 set overwrite=1
258 else
259 if ( $WRF_CHEM == 1 ) then
260 head -2 Registry/Registry | tail -1 | grep WRFCHEMVAR > /dev/null
261 else
262 head -2 Registry/Registry | tail -1 | grep WRFVAR > /dev/null
263 endif
264 if ( $status ) then
265 set overwrite=1
266 endif
267 endif
268 if ( $overwrite ) then
269 /bin/rm -f Registry/Registry.rconfig
270 /bin/cat Registry/Registry.EM_COMMON | grep '^rconfig' > Registry/Registry.rconfig
271 if ($WRF_CHEM == 1 ) then
272 echo copying Registry/Registry.wrfchemvar to Registry/Registry
273 echo '## WARNING: this file is autogenerated from Registry/Registry.wrfchemvar Registry/Registry.EM_COMMON.var. Changes may be lost' > Registry/Registry
274 /bin/cat Registry/Registry.wrfchemvar >> Registry/Registry
275 else
276 echo copying Registry/Registry.wrfvar to Registry/Registry
277 echo '## WARNING: this file is autogenerated from Registry/Registry.wrfvar Registry/Registry.EM_COMMON.var. Changes may be lost' > Registry/Registry
278 /bin/cat Registry/Registry.wrfvar >> Registry/Registry
279 endif
280 endif
282 set wrfpluspath = ( `grep "^WRFPLUSPATH" configure.wrf | cut -d"=" -f2-` )
283 if ( $wrfpluspath == "" ) then
284 setenv WRFPLUS_INC " "
285 else
286 setenv WRFPLUS_DIR $wrfpluspath
287 setenv WRFPLUS_INC "-I${wrfpluspath}/dyn_em -I${wrfpluspath}/main -I${wrfpluspath}/frame -I${wrfpluspath}/share -I${wrfpluspath}/wrftladj"
288 endif
290 setenv BUFR 1
291 set CRTM = ( `grep "\-DCRTM" configure.wrf | sed -e 's/\\//g' | sed 's/-//g' ` )
292 if ( $CRTM != "" ) then
293 echo " "
294 echo "Will compile with CRTM library"
295 echo " "
296 if ( ! $?BUFR ) then
297 echo " "
298 echo "BUFR library is needed for radiance data ingest."
299 echo "setting BUFR=1"
300 echo " "
301 setenv BUFR 1
302 endif
303 setenv CRTM_CPP "-DCRTM"
304 setenv CRTM_LIB "-L../external/crtm_2.3.0/libsrc -lCRTM"
305 setenv CRTM_SRC "-I../external/crtm_2.3.0/libsrc"
306 #setenv SFC_CRTM `grep '^SFC' configure.wrf | awk '{print $3}' | sed -e 's/\// /g' | awk '{print $NF}'`
307 #setenv ABI_CRTM `grep '^SFC' configure.wrf | sed -n 's/.*\(\-m[0-9]\{2\}\).*/\1/p'`
308 setenv CRTM 1
309 else
310 echo " "
311 echo "Compiling WRFDA without CRTM library"
312 echo " "
313 setenv CRTM_CPP " "
314 setenv CRTM_LIB " "
315 setenv CRTM_SRC " "
316 setenv CRTM 0
317 endif
318 set hdf5path = ( `grep "^HDF5PATH" configure.wrf | cut -d"=" -f2-` )
319 if ( $hdf5path == "" ) then
320 setenv HDF5_INC ""
321 unsetenv HDF5
322 else
323 echo " "
324 echo "Compiling with HDF5 libraries in:"
325 echo $hdf5path
326 echo " "
327 setenv HDF5_INC "-I${hdf5path}/include"
328 setenv HDF5 1
329 endif
330 set RTTOV = ( `grep "^RTTOVPATH" configure.wrf | cut -d"=" -f2-` )
331 if ( $RTTOV == "" ) then
332 setenv RTTOV_LIB " "
333 setenv RTTOV_SRC " "
334 unsetenv RTTOV
335 else
336 if ( $hdf5path == "" ) then
337 echo "As of version 12.1 of RTTOV, WRFDA requires HDF5 in order utilize the RTTOV library."
338 echo "RTTOV emissivity atlas files are now provided only in HDF5 format."
339 echo "Please supply an HDF5 path prior to configure or unset RTTOV."
340 exit 1
341 else
342 echo " "
343 echo "Compiling with RTTOV libraries in:"
344 echo $RTTOV
345 echo " "
346 if ( ! $?BUFR ) then
347 echo " "
348 echo "BUFR library is needed for radiance data ingest."
349 echo "setting BUFR=1"
350 echo " "
351 setenv BUFR 1
352 endif
353 if ( -e ${RTTOV}/lib/librttov12_main.a ) then
354 setenv RTTOV_LIB "-L${hdf5path}/lib -lhdf5hl_fortran -lhdf5_hl -lhdf5_fortran -lhdf5 -L${RTTOV}/lib -lrttov12_coef_io -lrttov12_emis_atlas -lrttov12_main -lrttov12_hdf"
355 else
356 echo "Can not find a compatible RTTOV library! Please ensure that your RTTOV build was successful,"
357 echo "your 'RTTOV' environment variable is set correctly, and you are using a supported version of RTTOV."
358 echo "Current supported version(s): 12.1"
360 exit 1
361 endif
362 setenv RTTOV_SRC "-I${RTTOV}/include -I${RTTOV}/mod"
363 endif
364 endif
366 if ( $?CLOUD_CV ) then
367 setenv CLOUD_CV_CPP "-DCLOUD_CV"
368 else
369 setenv CLOUD_CV_CPP " "
370 endif
371 if ( $?BUFR ) then
372 setenv BUFR_CPP "-DBUFR"
373 setenv BUFR_LIB "-L../external/bufr -lbufr"
374 else
375 setenv BUFR_CPP " "
376 setenv BUFR_LIB " "
377 endif
378 if ( $?WAVELET ) then
379 setenv WAVELET_LIB "../external/wavelet/libWavelet.a ../external/wavelet/lib_wavelet.a"
380 else
381 setenv WAVELET_LIB " "
382 endif
383 if ( $?MADIS ) then
384 setenv MADIS_CPP "-DMADIS"
385 setenv MADIS_STATIC ${MADIS}/static
386 setenv MADIS_LIB "-L${MADIS} -lmadis"
387 else
388 setenv MADIS_CPP " "
389 setenv MADIS_LIB " "
390 endif
391 setenv DA_ARCHFLAGS "${BUFR_CPP} ${MADIS_CPP} -DFFTPACK -DNORESHAPE"
392 endif
394 echo " "
395 echo "============================================================================================== "
396 echo " "
397 cat inc/version_decl | cut -d"'" -f2 | head -1
398 cat inc/commit_decl | cut -d"'" -f2
399 echo " "
400 echo -n "Compiling: "
401 if ( $WRF_DA_CORE ) echo -n "WRF_DA_CORE "
402 if ( $WRF_EM_CORE ) echo -n "WRF_EM_CORE "
403 if ( $WRF_COAMPS_CORE ) echo -n "WRF_COAMPS_CORE "
404 if ( $WRF_EXP_CORE ) echo -n "WRF_EXP_CORE "
405 echo " "
406 env | grep LARGE
407 echo " "
408 uname -a
409 echo " "
410 set comp = ( `grep "^SFC" configure.wrf | cut -d"=" -f2-` )
411 if ( "$comp[1]" == "gfortran" ) then
412 gfortran --version
413 else if ( "$comp[1]" == "pgf90" ) then
414 pgf90 --version
415 else if ( "$comp[1]" == "ifort" ) then
416 ifort -V
417 else
418 echo "Not sure how to figure out the version of this compiler: $comp[1]"
419 endif
420 echo " "
421 echo "============================================================================================== "
422 echo " "
424 if ( ! $?WRF_SRC_ROOT_DIR ) setenv WRF_SRC_ROOT_DIR `pwd`
426 # new dec 2009. check to see if make supports parallel -j option
427 make -j 2 >& /dev/null
428 if ( $status == 0 ) then # Parallel make ok
429 if ( ! $?J ) then # J not defined
430 echo setting parallel make -j 2 # Set default to 2
431 setenv J "-j 2"
432 else
433 # J is defined, check that it is a correctly formed variable
434 set first2chars = `echo $J | cut -c 1-2` # Are 1st two chars are -j?
435 set second_word = `echo $J | cut -d" " -f2` # Is second word a number?
436 if ( "$first2chars" == "-j" ) then
437 if ( ( "$second_word" >= "2" ) && \
438 ( "$second_word" <= "20" ) ) then
439 echo setting parallel make $J
440 else if ( "$second_word" == "1" ) then
441 echo setting serial make $J
442 else
443 echo "badly formed -j option for parallel make: $J"
444 echo "or you set the number of processors above 20 "
445 echo setting parallel make -j 2 # Set default to 2
446 setenv J "-j 2"
447 endif
448 else
449 if ( "$J" == "" ) then # J blank is OK
450 echo setting serial make $J
451 else
452 echo "parallel option for make is -j, you entered: $first2chars"
453 echo setting parallel make -j 2 # Set default to 2
454 setenv J "-j 2"
455 endif
456 endif
457 endif
458 else
459 echo not setting parallel make
460 endif
462 /bin/rm -f $ZAP >& /dev/null
463 make $arglist A2DCASE="$A2DCASE" WRF_SRC_ROOT_DIR="$WRF_SRC_ROOT_DIR"
465 endif
467 exit 0
469 hlp:
471 echo ' '
472 echo 'Usage:'
473 echo ' '
474 echo ' compile [-j n] wrf compile wrf in run dir (NOTE: no real.exe, ndown.exe, or ideal.exe generated)'
475 echo ' '
476 echo ' or choose a test case (see README_test_cases for details) :'
477 foreach d ( `/bin/ls test` )
478 if ( "$d" != "CVS" ) then
479 echo " compile [-j n] $d"
480 endif
482 echo ' '
483 echo ' compile -j n parallel make using n tasks if supported (default 2)'
484 echo ' compile -h help message'