-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile_header.mk
1059 lines (893 loc) · 39.2 KB
/
Makefile_header.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#------------------------------------------------------------------------------
# GEOS-Chem Global Chemical Transport Model #
#------------------------------------------------------------------------------
#BOP
#
# !IROUTINE: Makefile_header.mk
#
# !DESCRIPTION: This sub-makefile defines the variables which specify
# compilation options for the different supported compiler/platform
# combinations. Also, the default makefile compilation rules are specified
# here.
#\\
#\\
# !REMARKS:
# To build the programs, call "make" with the following syntax:
# .
# make -jN TARGET REQUIRED-FLAGS [ OPTIONAL-FLAGS ]
#
# To display a complete list of options, type "make help".
# .
# The following variables are exported to the main-level Makefile:
# .
# Variable Description
# -------- -----------
# F90 Contains the Fortran compilation commands
# FREEFORM Contains the command to force F90 "free format" compilation
# LD Contains the command to link to libraries & make executable
# LINK Contains the commands to link to GEOS-Chem built libraries
# R8 Contains the command to force REAL -> REAL*8
# SHELL Contains the default Unix shell to use when building code
# NCL Contains the default netCDF library link commands
# .
# FFLAGS is a local variable that is not returned to the "outside world",
# but is only used locally. COMPILER, HDF5, and OMP are all input via the
# command line or via environment variables.
# .
# NOTE: We now use SHELL :=/bin/bash as the default Unix shell. This allows
# us to extend the Makefile ifeq statements so that we can test for more than
# one string. The following example is used to ensure that the met field name
# selected by the user is case-insensitive:
#
# # %%%%% GEOS-FP %%%%%
# REGEXP :=(^[Gg][Ee][Oo][Ss][Ff][Pp])|(^[Gg][Ee][Oo][Ss].[Ff][Pp])
# ifeq ($(shell [[ "$(MET)" =~ $(REGEXP) ]] && echo true),true)
# USER_DEFS += -DGEOS_FP
# endif
# .
# The [[ ]] in bash is an evaluation. The above ifeq statement uses regular
# expressions to test if the MET variable matches the string "GEOS" (case-
# insensitive) and either "FP" or "any character and then a FP". This will
# return true (via the "echo true" statement) for combinations like "GEOS-FP",
# "geosfp", "Geos-FP", "GeOs.FP", etc. This is a robust way of evaluating
# the user's input, and will make errors less likely.
#
# !REVISION HISTORY:
# See the Git history with the gitk browser!
#EOP
#------------------------------------------------------------------------------
#BOC
###############################################################################
### ###
### Set the default Unix shell and some error message variables ###
### ###
###############################################################################
# Set default shell to bash, for use with the Makefile conditionals
SHELL :=/bin/bash
# Error message for bad COMPILER input
ERR_CMPLR :="Unknown Fortran compiler! Must be one of ifort, gfortran, or mpifort|mpif90. Check the FC environment variable in your .bashrc or .cshrc file."
# Error message for unknown compiler/OS combintation
ERR_OSCOMP :="Makefile_header.mk not set up for this compiler/OS combination"
# Error message for bad two-way coupled model input (yanyy,6/18/14)
ERR_COUPLECH :="Select a coupled grid for China/SE Asia: COUPLECH=2x25ch, COUPLECH=4x5ch"
ERR_COUPLENA :="Select a coupled grid for North America: COUPLENA=2x25na, COUPLENA=4x5na"
ERR_COUPLEEU :="Select a coupled grid for Europe : COUPLEEU=2x25eu, COUPLEEU=4x5eu"
ERR_COUPLE :="Select a coupled choice: COUPLE=yes"
# Error message for bad GIGC config
ERR_GIGC :="Unable to find the GIGC configuration file. Have you downloaded the GIGC?"
###############################################################################
### ###
### Set C-preprocessor switches representing user options. These are not ###
### specific to any compiler, but are general options for the simulation. ###
### ###
### NOTE: To make the user input more robust, we use regular expression ###
### syntax to match characters in the various Makefile variables. See ###
### this web page for more info: ###
### http://www.tldp.org/LDP/abs/html/x17046.html ###
### ###
###############################################################################
#------------------------------------------------------------------------------
# Compiler settings
#------------------------------------------------------------------------------
# %%%%% OpenMP parallelization (on by default) %%%%%
ifndef OMP
OMP :=yes
endif
# Option to turn off OpenMP for testing
REGEXP :=(^[Nn]|^[Oo])
ifeq ($(shell [[ "$(OMP)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DNO_OMP
endif
# %%%%% Set the HPC variable if we are building for use w/ ESMF/MPI %%%%
ifeq ($(shell [[ "$(MAKECMDGOALS)" =~ "hpc" ]] && echo true),true)
HPC :=yes
export HPC
endif
# %%%%% For HPC, we disable OpenMP and turn on the full vertical grid %%%%%
REGEXP := (^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(HPC)" =~ $(REGEXP) ]] && echo true),true)
IS_HPC :=1
OMP :=no
# PRECISION :=4
else
IS_HPC :=0
endif
# %%%%% Default to 8-byte precision unless specified otherwise %%%%%
ifndef PRECISION
PRECISION :=8
endif
# %%%%% Default to Timers disabled %%%%%
ifndef TIMERS
TIMERS :=0
endif
# %%%%% Turn on traceback (error stack report) by default %%%%%
ifndef TRACEBACK
TRACEBACK :=yes
endif
# %%%%% Set default compiler %%%%%
# %%%%% Test if mpif90/mpifort is selected (for now assume ifort) %%%%%
REGEXP :=(^[Mm][Pp][Ii])
ifeq ($(shell [[ "$(FC)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DLINUX_IFORT
REG_GNU :=(^[Gg][Nn][Uu])
REG_INTEL :=(^[Ii][Ff][Oo][Rr][Tt])
DISCRIM :=$(word 1,$(shell $(FC) --version ) )
ifeq ($(shell [[ "$(DISCRIM)" =~ $(REG_INTEL) ]] && echo true),true)
COMPILER_FAMILY :=Intel
USER_DEFS += -DLINUX_IFORT
else ifeq ($(shell [[ "$(DISCRIM)" =~ $(REG_GNU) ]] && echo true),true)
COMPILER_FAMILY :=GNU
USER_DEFS += -DLINUX_GFORTRAN
else
$(error Could not determine compiler underlying mpifort/mpif90 )
endif
endif
# %%%%% Test if Intel Fortran Compiler is selected %%%%%
REGEXP :=(^[Ii][Ff][Oo][Rr][Tt])
ifeq ($(shell [[ "$(FC)" =~ $(REGEXP) ]] && echo true),true)
# If we are building GCHP, then set the compile command to "mpifort",
# which invokes the MPI magic. Otherwise set it to $(FC). (bmy, 10/17/16)
COMPILER_FAMILY :=Intel
USER_DEFS += -DLINUX_IFORT
endif
# %%%%% Test if GNU Fortran Compiler is selected %%%%%
REGEXP :=(^[Gg][Ff][Oo][Rr][Tt][Rr][Aa][Nn])
ifeq ($(shell [[ "$(FC)" =~ $(REGEXP) ]] && echo true),true)
COMPILER_FAMILY :=GNU
USER_DEFS += -DLINUX_GFORTRAN
endif
# Is this GCHP?
ifeq ($(IS_HPC),1)
COMPILE_CMD :=mpifort
else
COMPILE_CMD :=$(FC)
endif
# %%%%% ERROR CHECK! Make sure our compiler selection is valid! %%%%%
REGEXP :=((-DLINUX_)?IFORT|GFORTRAN)
ifneq ($(shell [[ "$(USER_DEFS)" =~ $(REGEXP) ]] && echo true),true)
$(error $(ERR_CMPLR))
endif
# Once we are sure the compiler is valid, then get the version number
COMPILER_VERSION_LONG :=$(shell $(FC) --version))
COMPILER_VERSION_LONG :=$(sort $(COMPILER_VERSION_LONG))
# For ifort, the 3rd substring of the sorted text is the version number.
# For pgfortran and gfortran, it's the 4th substring.
# NOTE: Future compiler updates may break this algorithm.
REGEXP :=(^[Ii][Ff][Oo][Rr][Tt])
ifeq ($(shell [[ "$(FC)" =~ $(REGEXP) ]] && echo true),true)
COMPILER_VERSION :=$(word 3, $(COMPILER_VERSION_LONG))
else
COMPILER_VERSION :=$(word 4, $(COMPILER_VERSION_LONG))
endif
# Major version number of the compiler
# e.g. for gfortran 8.2.0, this would be "8"
COMPILER_MAJOR_VERSION :=$(word 1,$(subst ., ,$(COMPILER_VERSION)))
#------------------------------------------------------------------------------
# Special flags for enabling experimental or development code
#------------------------------------------------------------------------------
# %%%%% DEVEL: Enable user-added experimental code %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(DEVEL)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DDEVEL
endif
# %%%%% DIAG_DEVEL: Enable experimental code specific to HEMCO %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(DIAG_DEVEL)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DDIAG_DEVEL
BPCH_DIAG :=no
endif
# %%%%% HCO_DEVEL: Enable experimental code specific to HEMCO %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(HCO_DEVEL)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DHCO_DEVEL
endif
# %%%%% HPC_DEVEL: Enable experimental code specific to GCHP %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(HPC_DEVEL)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DHPC_DEVEL
endif
# %%%%% Turn on tendencies computation %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(USE_TEND)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DUSE_TEND
BPCH_DIAG :=no
endif
#------------------------------------------------------------------------------
# GEOS-Chem HP settings
#------------------------------------------------------------------------------
# %%%%% ESMF %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(ESMF)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DESMF_
NO_GRID_NEEDED :=1
endif
# %%%%% EXTERNAL_GRID %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(EXTERNAL_GRID)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXTERNAL_GRID
NO_GRID_NEEDED :=1
endif
# %%%%% EXTERNAL_FORCING %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(EXTERNAL_FORCING)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXTERNAL_FORCING
NO_GRID_NEEDED :=1
endif
#------------------------------------------------------------------------------
# Coupling GEOS-Chem to External Models settings
#------------------------------------------------------------------------------
# %%%%% NO_EXE %%%%%
# Setting NO_EXE=y will inhibit the creation of a final "geos" executable
# and create a "libGeosCore.a" in the lib folder instead.
# Used if you are linking GEOS-Chem routines to be driven by an external model.
# (hplin, 8/23/18)
EXE_NEEDED :=1
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(NO_EXE)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DMODEL_
EXE_NEEDED :=0
endif
#------------------------------------------------------------------------------
# Diagnostic settings
#------------------------------------------------------------------------------
# Turn on bpch diagnostics UNLESS specified otherwis
ifdef BPCH_DIAG
BPCH_DIAG :=yes
endif
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(BPCH_DIAG)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DBPCH_DIAG
endif
# If we are compiling GEOS-Chem "Classic", then also activate all bpch
# timeseries diagnostics. At this point (v11-02) there are some special
# timeseries diagnostics that require local-time binning, which is not
# yet available in the netCDF diagnostic output. This will preserve
# backwards compatibility for the time being. (bmy, 4/11/18)
ifeq ($(IS_HPC),0)
USER_DEFS += -DBPCH_TIMESER
endif
# Turn on bpch code for nested-grid BC's by default
# Needed for both global and nested simulations
USER_DEFS += -DBPCH_TPBC
#------------------------------------------------------------------------------
# KPP settings chemistry solver settings. NOTE: We can't redefine CHEM
# (since it is an environent variable), so define a shadow variable KPP_CHEM.
#------------------------------------------------------------------------------
# Test if the CHEM value is set
IS_CHEM_SET :=0
# %%%%% CHEM=Standard (aka benchmark) %%%%%
REGEXP :=(^[Ss][Tt][Aa][Nn][Dd][Aa][Rr][Dd])
ifeq ($(shell [[ "$(CHEM)" =~ $(REGEXP) ]] && echo true),true)
KPP_CHEM :=Standard
IS_CHEM_SET :=1
endif
# %%%%% Test if CHEM=SOA (same as Tropchem as of v11-02a) %%%%%
REGEXP :=(^[Ss][Oo][Aa])
ifeq ($(shell [[ "$(CHEM)" =~ $(REGEXP) ]] && echo true),true)
KPP_CHEM :=Tropchem
IS_CHEM_SET :=1
endif
# %%%%% Test if CHEM=SOA_SVPOA %%%%%
REGEXP :=(^[Ss][Oo][Aa]_[Ss][Vv][Pp][Oo][Aa])
ifeq ($(shell [[ "$(CHEM)" =~ $(REGEXP) ]] && echo true),true)
KPP_CHEM :=SOA_SVPOA
IS_CHEM_SET :=1
endif
# %%%%% Test if CHEM=Tropchem %%%%%
REGEXP :=(^[Tt][Rr][Oo][Pp][Cc][Hh][Ee][Mm])
ifeq ($(shell [[ "$(CHEM)" =~ $(REGEXP) ]] && echo true),true)
KPP_CHEM :=Tropchem
IS_CHEM_SET :=1
endif
# %%%%% Test if CHEM=NOx_Ox_HC_Aer_Br (former name for Tropchem) %%%%%
REGEXP :=(^[Nn][Oo][Xx]_[Oo][Xx]_[Hh][Cc]_[Aa][Ee][Rr]_[Bb][Rr])
ifeq ($(shell [[ "$(CHEM)" =~ $(REGEXP) ]] && echo true),true)
KPP_CHEM :=Tropchem
IS_CHEM_SET :=1
endif
# %%%%% Test if CHEM=Custom %%%%%
REGEXP :=(^[Cc][Uu][Ss][Tt][Oo][Mm])
ifeq ($(shell [[ "$(CHEM)" =~ $(REGEXP) ]] && echo true),true)
KPP_CHEM :=Custom
IS_CHEM_SET :=1
endif
# %%%%% Default setting %%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# NOTE: For clarify in the future, the default setting should be to not set
# KPP_CHEM or IS_CHEM_SET if the CHEM compiler option is not passed. The default
# option would be reserved for specialty simulations that do not require the KPP
# code to be compiled. (mps, 4/22/16)
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ifeq ($(IS_CHEM_SET),0)
KPP_CHEM :=Standard
IS_CHEM_SET :=1
endif
#------------------------------------------------------------------------------
# RRTMG radiative transfer model settings
#------------------------------------------------------------------------------
# %%%%% RRTMG %%%%%
RRTMG_NEEDED :=0
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(RRTMG)" =~ $(REGEXP) ]] && echo true),true)
RRTMG_NEEDED :=1
USER_DEFS += -DRRTMG
endif
#------------------------------------------------------------------------------
# APM radiative transfer model settings
#------------------------------------------------------------------------------
# %%%%% RRTMG %%%%%
APM_NEEDED :=0
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(APM)" =~ $(REGEXP) ]] && echo true),true)
APM_NEEDED :=1
USER_DEFS += -DAPM
endif
#------------------------------------------------------------------------------
# Coupled grid settings (yanyy,6/18/14)
#------------------------------------------------------------------------------
# %%%%% Couple %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(COUPLE)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXCHANGE
endif
# %%%%% China (CH) and 4x5 %%%%%
REGEXP :=(^4.5[Cc][Hh]|^4\.0.5\.0[Cc][Hh])
ifeq ($(shell [[ "$(COUPLECH)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXCHANGE -DEXCHANGE_4x5_CH
endif
# %%%%% Europe (EU) and 4x5 %%%%%
REGEXP :=(^4.5[Ee][Uu]|^4\.0.5\.0[Ee][Uu])
ifeq ($(shell [[ "$(COUPLEEU)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXCHANGE -DEXCHANGE_4x5_EU
endif
# %%%%% North America (NA) and 4x5 %%%%%
REGEXP :=(^4.5[Nn][Aa]|^4\.0.5\.0[Nn][Aa])
ifeq ($(shell [[ "$(COUPLENA)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXCHANGE -DEXCHANGE_4x5_NA
endif
# %%%%% SE Asia (SE) and 4x5 %%%%%
REGEXP :=(^4.5[Nn][Aa]|^4\.0.5\.0[Nn][Aa])
ifeq ($(shell [[ "$(COUPLESE)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXCHANGE -DEXCHANGE_4x5_SE
endif
# %%%%% China (CH) and 2x2.5 %%%%%
REGEXP :=(^2.25[Cc][Hh]|^2.2\.5[Cc][Hh]|^2\.0.2\.5[Cc][Hh])
ifeq ($(shell [[ "$(COUPLECH)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXCHANGE -DEXCHANGE_2x25_CH
endif
# %%%%% Europe (EU) and 2x2.5 %%%%%
REGEXP :=(^2.25[Ee][Uu]|^2.2\.5[Ee][Uu]|^2\.0.2\.5[Ee][Uu])
ifeq ($(shell [[ "$(COUPLEEU)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXCHANGE -DEXCHANGE_2x25_EU
endif
# %%%%% North America (NA) and 2x2.5 %%%%%
REGEXP :=(^2.25[Nn][Aa]|^2.2\.5[Nn][Aa]|^2\.0.2\.5[Nn][Aa])
ifeq ($(shell [[ "$(COUPLENA)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXCHANGE -DEXCHANGE_2x25_NA
endif
# %%%%% SE Asia (SE) and 2x2.5 %%%%%
REGEXP :=(^2.25[Nn][Aa]|^2.2\.5[Nn][Aa]|^2\.0.2\.5[Nn][Aa])
ifeq ($(shell [[ "$(COUPLESE)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DEXCHANGE -DEXCHANGE_2x25_SE
endif
# %%%%% ERROR CHECK! Make sure our NEST selection is valid! %%%%%
ifdef COUPLE_NEEDED
REGEXP :=((\-DEXCHANGE_)?CH|NA|EU)
ifneq ($(shell [[ "$(USER_DEFS)" =~ $(REGEXP) ]] && echo true),true)
$(error $(ERR_COUPLE))
endif
endif
#------------------------------------------------------------------------------
# Aerosol microphysics settings
#------------------------------------------------------------------------------
# %%%%% TOMAS, 30 bins (default) %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(TOMAS)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DTOMAS
endif
# %%%%% TOMAS, 40 bins %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(TOMAS40)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DTOMAS -DTOMAS40
endif
# %%%%% TOMAS, 15 bins %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(TOMAS15)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DTOMAS -DTOMAS15
endif
# %%%%% TOMAS, 12 bins %%%%%
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(TOMAS12)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DTOMAS -DTOMAS12
endif
#------------------------------------------------------------------------------
# Special chemistry settings
#------------------------------------------------------------------------------
# Activate Global Terrestrial Mercury Model (GTMM) if necessary
GTMM_NEEDED :=0
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(GTMM_Hg)" =~ $(REGEXP) ]] && echo true),true)
GTMM_NEEDED :=1
USER_DEFS += -DGTMM_Hg
endif
#------------------------------------------------------------------------------
# Performance profiling
#------------------------------------------------------------------------------
# Compile with TAU profiler (from ParaTools, Inc)
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(TAU_PROF)" =~ $(REGEXP) ]] && echo true),true)
COMPILE_CMD :=tau_f90.sh
endif
# Compile with GNU profiler (gprof)
IS_GPROF :=0
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(GPROF)" =~ $(REGEXP) ]] && echo true),true)
IS_GPROF :=1
endif
#------------------------------------------------------------------------------
# Add test for mass conservation
#------------------------------------------------------------------------------
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(MASSCONS)" =~ $(REGEXP) ]] && echo true),true)
USER_DEFS += -DMASSCONS
endif
###############################################################################
### ###
### Set linker commands for local and external libraries (incl. netCDF) ###
### ###
###############################################################################
# Test if we have found the nf-config file, which indicates a separate
# netCDF-Fortran build. IS_NF_CONFIG=0 indicates that we found nf-config.
IS_NF_CONFIG :=$(shell test -f $(GC_F_BIN)/nf-config; echo $$?)
# Test for GEOS-Chem-Libraries or onboard netCDF libraries
ifeq ($(shell [[ "$(GC_LIB)" =~ GEOS-Chem-Libraries ]] && echo true),true)
#-----------------------------------------------------------------------
# %%%%% We are using the GEOS-Chem-Libraries package %%%%%
#
# Both netCDF-Fortran and netCDF-C library files are in the same path
#-----------------------------------------------------------------------
# NetCDF include command: 1 library path
NC_INC_CMD := -I$(GC_INCLUDE)
# NetCDF link command: Add a workaround so that $GC_LIB will specify
# the library path. This should prevent any issues caused by building
# the GEOS-Chem-Libraries in one location and moving them to another.
NC_LINK_CMD := $(shell $(GC_BIN)/nf-config --flibs)
NC_LINK_CMD += $(shell $(GC_BIN)/nc-config --libs)
NC_LINK_CMD := $(filter -l%,$(NC_LINK_CMD))
NC_LINK_CMD :=-L$(GC_LIB) $(NC_LINK_CMD)
else
ifeq ($(IS_NF_CONFIG),0)
#-----------------------------------------------------------------------
# %%%%% We are using the onboard netCDF libraries %%%%%
#
# NetCDF-Fortran and NetCDF-C library files are in different paths,
# which is typical of netCDF versions 4.2 and higher.
#-----------------------------------------------------------------------
# NetCDF include command: 2 library paths
NC_INC_CMD := -I$(GC_INCLUDE) -I$(GC_F_INCLUDE)
# NetCDF link command: 2 sets of link commands
NC_LINK_CMD := $(shell $(GC_F_BIN)/nf-config --flibs)
NC_LINK_CMD += $(shell $(GC_BIN)/nc-config --libs)
else
#-----------------------------------------------------------------------
# %%%%% We are using the onboard netCDF libraries %%%%%
#
# NetCDF-Fortran and NetCDF-C library files are in the same path,
# which is typical netCDF versions earlier than 4.2.
#-----------------------------------------------------------------------
# NetCDF include command: 1 library path
NC_INC_CMD := -I$(GC_INCLUDE)
# NetCDF link command: 1 set of link commands
NC_LINK_CMD := $(shell $(GC_BIN)/nc-config --flibs)
endif
endif
# Save for backwards compatibility
NCL := $(NC_LINK_CMD)
#----------------------------
# For GEOS-Chem
#----------------------------
# Base linker command: specify the library directory
LINK :=-L$(LIB)
# Append library for GTMM, if necessary
ifeq ($(GTMM_NEEDED),1)
LINK :=$(LINK) -lHg
endif
# Append library for RRTMG, if necessary
ifeq ($(RRTMG_NEEDED),1)
LINK :=$(LINK) -lrad
endif
# Append library for RRTMG, if necessary
ifeq ($(APM_NEEDED),1)
LINK :=$(LINK) -lApm
endif
# Create linker command to create the GEOS-Chem executable
LINK :=$(LINK) -lIsorropia -lObsPack -lHistory
LINK :=$(LINK) -lHCOI -lHCOX -lHCO
LINK :=$(LINK) -lGeosUtil -lKpp -lHeaders -lNcUtils
LINK :=$(LINK) $(NC_LINK_CMD)
#----------------------------
# For the HEMCO standalone
#----------------------------
# Create linker command to create the HEMCO standalone executable
LINK_HCO :=-L$(LIB) -lHCOI -lHCOX -lHCO -lGeosUtil -lHeaders
LINK_HCO :=$(LINK_HCO) -lNcUtils $(NC_LINK_CMD)
###############################################################################
### ###
### Test if the netCDF library was built with compression enabled ###
### ###
### NOTE: Compressing the netCDF files will make it impossible to compare ###
### them for identical-ness in a unit test or diff test. Therefore, we ###
### have added some extra checks to skip the compression if so desired. ###
### ###
###############################################################################
# Assume we will turn on netCDF compression (if present)
IS_DEFLATE :=1
# Unless NC_NODEFLATE=y
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(NC_NODEFLATE)" =~ $(REGEXP) ]] && echo true),true)
IS_DEFLATE :=0
endif
# Or DEBUG=y. This will make sure unit tests and diff tests aren't affected.
REGEXP := (^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(DEBUG)" =~ $(REGEXP) ]] && echo true),true)
IS_DEFLATE :=0
endif
# Skip netCDF compression unless it's requested (or not a debug run)
ifeq ($(IS_DEFLATE),1)
# Test if the "nf_def_var_deflate" function is defined in netcdf.inc
# Look for netcdf.inc where the netCDF-Fortran library is located
ifdef GC_F_INCLUDE
GREP :=$(strip $(shell grep nf_def_var_deflate $(GC_F_INCLUDE)/netcdf.inc))
else
GREP :=$(strip $(shell grep nf_def_var_deflate $(GC_INCLUDE)/netcdf.inc))
endif
# Look for the second word of the combined search results
WORD :=$(word 2,"$(GREP)")
# If it matches "nf_def_var_deflate", then define Cpp flag NC_HAS_COMPRESSION
ifeq ($(WORD),nf_def_var_deflate)
USER_DEFS += -DNC_HAS_COMPRESSION
endif
endif
###############################################################################
### ###
### HPC Settings: Build & use ESMF & MAPL for Grid-Independent GEOS-Chem ###
### ###
###############################################################################
# If we are building w/ the HPC target, then include GIGC.mk as well
# Determine if we are building with the hpc target
ifeq ($(IS_HPC),1)
ifneq ("$(wildcard $(CURDIR)/../GCHP/GIGC.mk)","")
include $(CURDIR)/../GCHP/GIGC.mk
else
ifneq ("$(wildcard $(CURDIR)/../../GCHP/GIGC.mk)","")
include $(CURDIR)/../../GCHP/GIGC.mk
else
$(error $(ERR_GIGC))
endif
endif
#FFLAGS += -double-size 32 -real-size 32 -r4
endif
###############################################################################
### ###
### Define settings for the GNU FORTRAN COMPILER (aka gfortran) ###
### ###
###############################################################################
ifeq ($(COMPILER_FAMILY),GNU)
# Get the GNU Fortran version
GNU_VERSION :=$(shell $(FC) -dumpversion)
GNU_VERSION :=$(subst .,,$(GNU_VERSION))
NEWER_THAN_447 :=$(shell perl -e "print ($(GNU_VERSION) gt 447)")
IS_GNU_8 :=$(shell perl -e "print ($(GNU_VERSION) ge 800)")
# Base set of compiler flags
FFLAGS :=-cpp -w -std=legacy -fautomatic -fno-align-commons
ifeq ($(IS_HPC),1)
FFLAGS += -fconvert=native
else
FFLAGS += -fconvert=big-endian
endif
FFLAGS += -fno-range-check
# OPTIONAL: Add the GNU Fortran -march option, which compiles for a
# specific computer architecture. This may cause issues on some types
# of CPUs (e.g. Intel), so we have left this as an optional argument.
ifdef M_ARCH
FFLAGS += -march=$(M_ARCH)
endif
# Default optimization level for all routines (-O3)
ifndef OPT
# Options of interest
# -limf Intel math libraries - machine must have them
# -O3 Highest safe optimization level
# -march=native Make the binary machine-specific. If in doubt,
# use a specific architecture, eg...
# -march=corei7-avx Binary uses optimizations for
# Intel Sandy-Bridge Xeon (e.g. E5-2680)
# -mfpmath=sse Use SSE extensions
# -funroll-loops Enable loop unrolling
# -ffast-math Enable fast math optimizations
OPT := -O3 -funroll-loops
#OPT := -O3 -march=corei7-avx -mfpmath=sse -funroll-loops
endif
# Pick compiler options for debug run or regular run
REGEXP := (^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(DEBUG)" =~ $(REGEXP) ]] && echo true),true)
#-fcheck=all would be more comprehensive but would force bounds checking
FFLAGS += -g -gdwarf-2 -gstrict-dwarf -O0
FFLAGS += -Wall -Wextra -Wconversion
FFLAGS += -Warray-temporaries -fcheck-array-temporaries
TRACEBACK :=yes
USER_DEFS += -DDEBUG
else
FFLAGS += $(OPT)
endif
# Prevent any optimizations that would change numerical results
#GFORTRAN_BAD#FFLAGS += -fp-model source
# Turn on OpenMP parallelization
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(OMP)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -fopenmp
endif
# Get Operating System (Linux = Linux; Darwin = MacOSX)
ifndef UNAME
UNAME :=$(shell uname)
endif
# OSX compilation options
ifeq ($(UNAME),Darwin)
# This has not yet been tested
$(error $(ERR_OSCOMP))
# FFLAGS += -Wl,-stack_size,0x2cb410000 # 12 GB of stack space
# ifdef DEBUG
# FFLAGS += -g0 -debug -save-temps -fpic -Wl,-no_pie
# endif
endif
# Add options for medium memory model. This is to prevent G-C from
# running out of memory at hi-res, especially when using netCDF I/O.
ifneq ($(UNAME),Darwin)
#GFORTRAN_BAD#FFLAGS += -mcmodel=medium -shared-intel
FFLAGS += -mcmodel=medium
endif
# Turn on checking for floating-point exceptions
# These are approximately equivalent to -fpe0 -ftrapuv in IFORT
# NOTE: GNU Fortran 4.4.7 does not allow for -finit-real-snan, so
# we will only add this flag for versions newer than 4.4.7
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(FPE)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -ffpe-trap=invalid,zero,overflow
ifeq ($(NEWER_THAN_447),1)
FFLAGS += -finit-real=snan
endif
endif
ifeq ($(shell [[ "$(FPEX)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -ffpe-trap=invalid,zero,overflow
ifeq ($(NEWER_THAN_447),1)
FFLAGS += -finit-real=snan
endif
endif
# Add option for "array out of bounds" checking
REGEXP := (^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(BOUNDS)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -fbounds-check
endif
# Also add traceback option
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(TRACEBACK)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -fbacktrace
ifndef DEBUG
FFLAGS += -g
endif
endif
# Compile for use with the GNU profiler (gprof), if necessary
ifeq ($(IS_GPROF),1)
FFLAGS += -pg
endif
# Add flexible precision declaration
ifeq ($(PRECISION),8)
USER_DEFS += -DUSE_REAL8
endif
# Add timers declaration
ifeq ($(TIMERS),1)
USER_DEFS += -DUSE_TIMERS
endif
# Append the user options in USER_DEFS to FFLAGS
FFLAGS += $(USER_DEFS)
# Include options (i.e. for finding *.h, *.mod files)
INCLUDE :=-J$(MOD) $(NC_INC_CMD)
# Do not append the ESMF/MAPL/FVDYCORE includes for ISORROPIA, because it
# will not compile. ISORROPIA is slated for removal shortly. (bmy, 11/21/14)
INCLUDE_ISO :=$(INCLUDE)
# Append the ESMF/MAPL/FVDYCORE include commands
ifeq ($(HPC),yes)
INCLUDE += $(MAPL_INC) $(ESMF_MOD) $(ESMF_INC) $(FV_INC)
endif
# Set the standard compiler variables
F90 :=$(COMPILE_CMD) $(FFLAGS) $(INCLUDE)
F90ISO :=$(COMPILE_CMD) $(FFLAGS) $(INCLUDE_ISO)
LD :=$(COMPILE_CMD) $(FFLAGS)
FREEFORM := -ffree-form -ffree-line-length-none
R8 := -fdefault-real-8 -fdefault-double-8
endif
###############################################################################
### ###
### Define settings for the INTEL FORTRAN COMPILER (aka ifort) ###
### ###
###############################################################################
ifeq ($(COMPILER_FAMILY),Intel)
# Base set of compiler flags
FFLAGS :=-cpp -w -auto -noalign -convert big_endian
# Default optimization level for all routines (-O2)
ifndef OPT
OPT := -O2
endif
# Pick compiler options for debug run or regular run
REGEXP := (^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(DEBUG)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -g -O0 -check arg_temp_created -debug all
TRACEBACK :=yes
USER_DEFS += -DDEBUG
else
FFLAGS += $(OPT) -vec-report0
endif
# Prevent any optimizations that would change numerical results
FFLAGS += -fp-model source
# Turn on OpenMP parallelization
# NOTE: ifort 18 and higher users -qopenmp instead of -openmp
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(OMP)" =~ $(REGEXP) ]] && echo true),true)
REGEXP :=^1[8-9]|^2|^3|^4|^5|^6|^7|^8|^9
ifeq ($(shell [[ "$(COMPILER_MAJOR_VERSION)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -qopenmp
else
FFLAGS += -openmp
endif
endif
# Get Operating System (Linux = Linux; Darwin = MacOSX)
ifndef UNAME
UNAME :=$(shell uname)
endif
# OSX compilation options
ifeq ($(UNAME),Darwin)
FFLAGS += -Wl,-stack_size,0x2cb410000 # 12 GB of stack space
ifdef DEBUG
FFLAGS += -g0 -debug -save-temps -fpic -Wl,-no_pie
endif
endif
# Add options for medium memory model. This is to prevent G-C from
# running out of memory at hi-res, especially when using netCDF I/O.
ifneq ($(UNAME),Darwin)
FFLAGS += -mcmodel=medium -shared-intel
endif
# Turn on checking for floating-point exceptions
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(FPE)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -fpe0 -ftrapuv
endif
ifeq ($(shell [[ "$(FPEX)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -fpe0 -ftrapuv
endif
# Add special IFORT optimization commands
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(IPO)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -ipo -static
endif
# Add option for "array out of bounds" checking
REGEXP := (^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(BOUNDS)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -check bounds
endif
# Also add traceback option
REGEXP :=(^[Yy]|^[Yy][Ee][Ss])
ifeq ($(shell [[ "$(TRACEBACK)" =~ $(REGEXP) ]] && echo true),true)
FFLAGS += -traceback
endif
# Compile for use with the GNU profiler (gprof), if necessary
ifeq ($(IS_GPROF),1)
FFLAGS += -p
endif
# Add flexible precision declaration
ifeq ($(PRECISION),8)
USER_DEFS += -DUSE_REAL8
endif
# Add timers declaration
ifeq ($(TIMERS),1)
USER_DEFS += -DUSE_TIMERS
endif
# Append the user options in USER_DEFS to FFLAGS
FFLAGS += $(USER_DEFS)
# Include options (i.e. for finding *.h, *.mod files)
INCLUDE :=-module $(MOD) $(NC_INC_CMD)
# Do not append the ESMF/MAPL/FVDYCORE includes for ISORROPIA, because it
# will not compile. ISORROPIA is slated for removal shortly. (bmy, 11/21/14)
INCLUDE_ISO :=$(INCLUDE)
# Append the ESMF/MAPL/FVDYCORE include commands
ifeq ($(IS_HPC),1)
INCLUDE += $(MAPL_INC) $(ESMF_MOD) $(ESMF_INC) $(FV_INC)
endif
# Set the standard compiler variables
F90 :=$(COMPILE_CMD) $(FFLAGS) $(INCLUDE)
F90ISO :=$(COMPILE_CMD) $(FFLAGS) $(INCLUDE_ISO)
LD :=$(COMPILE_CMD) $(FFLAGS)
FREEFORM := -free
#ifneq ($(shell [[ "$(HPC)" =~ $(REGEXP) ]] && echo true),true)
#ifneq ($(HPC),yes)
R8 := -r8
#endif
endif
###############################################################################
### ###
### Specify pattern rules for compiliation ###
### (i.e. tell "make" how to compile files w/ different extensions) ###
### ###
###############################################################################