forked from ESCOMP/CAM
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathbuild-namelist
More file actions
executable file
·4776 lines (4175 loc) · 182 KB
/
Copy pathbuild-namelist
File metadata and controls
executable file
·4776 lines (4175 loc) · 182 KB
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
#!/usr/bin/env perl
#-----------------------------------------------------------------------------------------------
#
# build-namelist
#
# This script builds the namelists for the standalone CAM configuration of CCSM4.
# Eventually the system's build will be reworked so that individual components are responsible
# for building their own namelists.
#
# build-namelist is designed to be used in conjuction with configure. By default configure
# produces a config_cache.xml file that contains all information needed at build time to procduce
# a CAM executable. build-namelist reads this file to obtain information it needs to provide
# default values that are consistent with the CAM executable. For example, the grid resolution
# is obtained from the cache file and used to determine appropriate defaults for boundary datasets
# that are resolution dependent.
#
# The simplest use of build-namelist is to execute it from the build directory where configure
# was run. By default it will use the config_cache.xml file that was written by configure to
# determine the build time properties of the executable, and will write the files that contain
# the output namelists in that same directory. But if multiple runs are to made using the
# same executable, successive invocations of build-namelist will overwrite previously generated
# namelist files. So generally the best strategy is to invoke build-namelist from the run
# directory and use the -config option to provide the filepath of the config_cache.xml file.
#
#
# Date Contributor Modification
# -------------------------------------------------------------------------------------------
# 2007-12-31 Brian Eaton Original version
# 2008-02-02 B. Eaton Restore -test functionality.
# 2008-07-01 Sean Santos Added -inputdata functionality.
# 2008-07-09 B. Eaton Provide default values for rad_climate variable which
# specifies the radiatively active constituents.
# 2008-08-26 B. Eaton Add the driver namelist group ccsm_pes to specify the
# task/thread layout for all components.
# 2008-11-14 B. Eaton Extend use_case functionality.
# 2009-09-02 B. Eaton Allow namelist definition, defaults, and use case files
# to come from the user source mod directories.
#--------------------------------------------------------------------------------------------
use strict;
#use warnings;
#use diagnostics;
use Cwd;
use English;
use File::Basename;
use Getopt::Long;
use IO::File;
use FindBin qw($Bin);
use lib "$Bin/perl5lib";
use Build::ChemNamelist qw(set_dep_lists set_aero_modes_info chem_has_species);
#-----------------------------------------------------------------------------------------------
sub usage {
die <<EOF;
SYNOPSIS
build-namelist [options]
OPTIONS
-case "name" Case identifier up to 32 characters
-config "filepath" Read the given configuration cache file to determine the configuration
of the CAM executable. Default: "config_cache.xml".
-csmdata "dir" Root directory of CCSM input data.
Can also be set by using the CSMDATA environment variable.
-dir "directory" Directory where output namelist files for each component will be
written, i.e., atm_in, drv_in, ice_in, lnd_in, rof_in, and ocn_in.
Default: current working directory.
-help [or -h] Print usage to STDOUT.
-ignore_ic_date Ignore the date of the initial condition files
when determining the default.
-ignore_ic_year Ignore just the year part of the date of the initial condition files
when determining the default.
-infile "filepath" Specify a file containing namelists to read values from.
-inputdata "filepath" Writes out a list containing pathnames for required input datasets in
file specified.
-namelist "namelist" Specify namelist settings directly on the commandline by supplying
a string containing FORTRAN namelist syntax, e.g.,
-namelist "&camexp stop_option='ndays' stop_n=10 /"
-ntasks <n> Specify the number of MPI tasks being used by the run. This is used
to set a default decomposition for the FV dycore only (npr_yz).
-runtype "type" Type of simulation (startup, continue, or branch)
-silent [-s] Turns on silent mode - only fatal messages issued.
-test Enable checking that input datasets exist on local filesystem.
-use_case Specify a use case. Default: present day climatology
-verbose [or -v] Turn on verbose echoing of informational messages.
-version Echo the CVS tag name used to check out this CAM distribution.
Note: The precedence for setting the values of namelist variables is (highest to lowest):
1. namelist values set by specific command-line options, i.e., -case,
-runtype
2. values set on the command-line using the -namelist option,
3. values read from the file specified by -infile,
4. values specified by the -use_case option,
5. values from the namelist defaults file.
EOF
}
#-----------------------------------------------------------------------------------------------
# Set the directory that contains the CAM configuration scripts. If the command was
# issued using a relative or absolute path, that path is in $ProgDir. Otherwise assume the
# command was issued from the current working directory.
(my $ProgName = $0) =~ s!(.*)/!!; # name of this script
$ProgName = "CAM $ProgName"; # Since multiple components are now using a build-namelist
# utility add "CAM" qualifier to the name. This helps when
# looking at error output from the whole CCSM system.
my $ProgDir = $1; # name of directory containing this script -- may be a
# relative or absolute path, or null if the script is in
# the user's PATH
my $cwd = getcwd(); # current working directory
my $cfgdir; # absolute pathname of directory that contains this script
if ($ProgDir) {
$cfgdir = absolute_path($ProgDir);
} else {
$cfgdir = $cwd;
}
# CAM root directory.
my $cam_root = absolute_path("$cfgdir/../../..");
my $cfg_cache = "config_cache.xml"; # Default name of configuration cache file
my $outdirname = "."; # Default name of output directory name
#-----------------------------------------------------------------------------------------------
# Save commandline
my $commandline = "$cfgdir/build-namelist @ARGV";
#-----------------------------------------------------------------------------------------------
# Process command-line options.
my %opts = ( config => $cfg_cache,
csmdata => undef,
help => 0,
dir => $outdirname,
silent => 0,
test => 0,
);
GetOptions(
"case=s" => \$opts{'case'},
"config=s" => \$opts{'config'},
"csmdata=s" => \$opts{'csmdata'},
"d|dir=s" => \$opts{'dir'},
"h|help" => \$opts{'help'},
"ignore_ic_date" => \$opts{'ignore_ic_date'},
"ignore_ic_year" => \$opts{'ignore_ic_year'},
"infile=s" => \$opts{'infile'},
"inputdata=s" => \$opts{'inputdata'},
"namelist=s" => \$opts{'namelist'},
"ntasks=s" => \$opts{'ntasks'},
"runtype=s" => \$opts{'runtype'},
"s|silent" => \$opts{'silent'},
"test" => \$opts{'test'},
"uc|use_case=s" => \$opts{'use_case'},
"v|verbose" => \$opts{'verbose'},
"version" => \$opts{'version'},
) or usage();
# Give usage message.
usage() if $opts{'help'};
# Echo version info.
if ($opts{'version'}) {
version($cfgdir);
exit;
}
# Check for unparsed arguments
if (@ARGV) {
print "ERROR: unrecognized arguments: @ARGV\n";
usage();
}
# Define print levels:
# 0 - only issue fatal error messages
# 1 - only informs what files are created (default)
# 2 - verbose
my $print = 1;
if ($opts{'silent'}) { $print = 0; }
if ($opts{'verbose'}) { $print = 2; }
my $eol = "\n";
if ($print>=2) { print "Setting CAM configuration script directory to $cfgdir$eol"; }
if ($print>=2) { print "build-namelist was invoked with the commandline:\n $commandline$eol"; }
# Check that configuration cache file exists.
(-f $opts{'config'}) or die <<"EOF";
** $ProgName - ERROR: Cannot find configuration cache file: \"$opts{'config'}\" **
EOF
if ($print>=2) { print "Using CAM configuration cache file $opts{'config'}$eol"; }
# Check that the CCSM inputdata root directory has been specified.
my $inputdata_rootdir = undef;
if (defined($opts{'csmdata'})) {
$inputdata_rootdir = $opts{'csmdata'};
}
elsif (defined $ENV{'CSMDATA'}) {
$inputdata_rootdir = $ENV{'CSMDATA'};
}
else {
die "$ProgName - ERROR: CCSM inputdata root directory must be specified by either -csmdata argument\n" .
" or by the CSMDATA environment variable. :";
}
if ($print>=2) { print "CCSM inputdata root directory: $inputdata_rootdir$eol"; }
# If the -test option is specified, then the inputdata root directory must be local or nfs mounted.
if ($opts{'test'}) {
(-d $inputdata_rootdir) or die <<"EOF";
** $ProgName - ERROR: CCSM inputdata root is not a directory: \"$inputdata_rootdir\" **
EOF
}
#-----------------------------------------------------------------------------------------------
# Make sure we can find required perl modules, definition, and defaults files.
# Look for them under the directory that contains the configure script.
# The XML::Lite module is required to parse the XML files.
(-f "$cfgdir/perl5lib/XML/Lite.pm") or die <<"EOF";
** $ProgName - ERROR: Cannot find perl module \"XML/Lite.pm\" in directory \"$cfgdir/perl5lib\" **
EOF
# The Build::Config module provides utilities to access the configuration information
# in the config_cache.xml file
(-f "$cfgdir/perl5lib/Build/Config.pm") or die <<"EOF";
** $ProgName - ERROR: Cannot find perl module \"Build/Config.pm\" in directory \"$cfgdir/perl5lib\" **
EOF
# The Build::NamelistDefinition module provides utilities to validate that the output
# namelists are consistent with the namelist definition file
(-f "$cfgdir/perl5lib/Build/NamelistDefinition.pm") or die <<"EOF";
** $ProgName - ERROR: Cannot find perl module \"Build/NamelistDefinition.pm\" in directory \"$cfgdir/perl5lib\" **
EOF
# The Build::NamelistDefaults module provides a utility to obtain default values of namelist
# variables based on finding a best fit with the attributes specified in the defaults file.
(-f "$cfgdir/perl5lib/Build/NamelistDefaults.pm") or die <<"EOF";
** $ProgName - ERROR: Cannot find perl module \"Build/NamelistDefaults.pm\" in directory \"$cfgdir/perl5lib\" **
EOF
# The Build::Namelist module provides utilities to parse input namelists, to query and modify
# namelists, and to write output namelists.
(-f "$cfgdir/perl5lib/Build/Namelist.pm") or die <<"EOF";
** $ProgName - ERROR: Cannot find perl module \"Build/Namelist.pm\" in directory \"$cfgdir/perl5lib\" **
EOF
#-----------------------------------------------------------------------------------------------
# Add $cfgdir/perl5lib to the list of paths that Perl searches for modules
unshift @INC, "$cfgdir/perl5lib";
require XML::Lite;
require Build::Config;
require Build::NamelistDefinition;
require Build::NamelistDefaults;
require Build::Namelist;
#-----------------------------------------------------------------------------------------------
# Create a configuration object from CAM's config_cache.xml file. This object contains
# all the build-time specifications of the CAM executable.
my $cfg = Build::Config->new($opts{'config'});
#-----------------------------------------------------------------------------------------------
# Create a namelist definition object. This object provides a method for verifying that the
# output namelist variables are in the definition file, and are output in the correct
# namelist groups. Requires a namelist definition file...
#
# The namelist definition file contains entries for all namelist variables that
# can be output by build-namelist. The version of the file that is associate with a
# fixed CAM tag is $cfgdir/namelist_files/namelist_definition.xml. To aid developers
# who make use of the source mods directory (via -usr_src arg to configure) we allow
# the definition file to come from one of those directories.
my $nl_definition_file;
my @usr_src_dirs = split ',', $cfg->get('usr_src');
if (@usr_src_dirs) {
foreach my $dir (@usr_src_dirs) {
if (-f "$dir/namelist_definition.xml") {
$nl_definition_file = "$dir/namelist_definition.xml";
last;
}
}
}
if (! defined $nl_definition_file) {
# default location of namelist definition file
$nl_definition_file = "$cfgdir/namelist_files/namelist_definition.xml";
(-f "$nl_definition_file") or die <<"EOF";
** $ProgName - ERROR: Cannot find namelist definition file \"$nl_definition_file\" **
EOF
}
if ($print>=2) { print "Using namelist definition file $nl_definition_file$eol"; }
my $definition = Build::NamelistDefinition->new($nl_definition_file);
#-----------------------------------------------------------------------------------------------
# Create a namelist defaults object. This object provides default values for variables
# contained in the input defaults file. The configuration object provides attribute
# values that are relevent for the CAM executable for which the namelist is being produced.
# These attributes are used along with optional user specified attributes to find the
# best match when looking for default values.
#
# The namelist defaults file contains default values for all required namelist variables.
# Analogously to the definition file, we allow a user modified version of this file to
# be present in one of the usr_src directories.
my $nl_defaults_file;
if (@usr_src_dirs) {
foreach my $dir (@usr_src_dirs) {
if (-f "$dir/namelist_defaults_cam.xml") {
$nl_defaults_file = "$dir/namelist_defaults_cam.xml";
last;
}
}
}
if (! defined $nl_defaults_file) {
# default location of namelist defaults file
$nl_defaults_file = "$cfgdir/namelist_files/namelist_defaults_cam.xml";
(-f "$nl_defaults_file") or die <<"EOF";
** $ProgName - ERROR: Cannot find namelist defaults file \"$nl_defaults_file\" **
EOF
}
if ($print>=2) { print "Using namelist defaults file $nl_defaults_file$eol"; }
my $defaults = Build::NamelistDefaults->new($nl_defaults_file, $cfg);
#-----------------------------------------------------------------------------------------------
# Similarly to the namelist definition and defaults files, the use case file
# may also come from the usr_src directories. Determine the location of the
# use case file.
my $use_case_file;
if (defined $opts{'use_case'}) {
if (@usr_src_dirs) {
foreach my $dir (@usr_src_dirs) {
if (-f "$dir/$opts{'use_case'}.xml") {
$use_case_file = "$dir/$opts{'use_case'}.xml";
last;
}
}
}
if (! defined $use_case_file) {
# default location of namelist use case files
$opts{'use_case_dir'} = "$cfgdir/namelist_files/use_cases";
validate_use_case("commandline", \%opts);
$use_case_file = "$opts{'use_case_dir'}/$opts{'use_case'}.xml";
}
if ($print>=2) { print "Using namelist use case file $use_case_file$eol"; }
}
#-----------------------------------------------------------------------------------------------
# Create an empty namelist object. Add values to it in order of precedence.
my $nl = Build::Namelist->new();
#-----------------------------------------------------------------------------------------------
# Some regular expressions...
# **N.B.** the use of qr// for precompiling regexps isn't supported until perl 5.005.
my $TRUE = "\.true\.";
my $FALSE = "\.false\.";
#-----------------------------------------------------------------------------------------------
# Process the user input in order of precedence. At each point we'll only add new
# values to the namelist and not overwrite previously specified specified values which
# have higher precedence.
# Process the commandline args that provide specific namelist values.
# Case name
if (defined $opts{'case'}) { add_default($nl, 'case_name', 'val'=>$opts{'case'}); }
# Run type
if (defined $opts{'runtype'}) { add_default($nl, 'start_type', 'val'=>$opts{'runtype'}); }
# Process the -namelist arg.
if (defined $opts{'namelist'}) {
# Parse commandline namelist
my $nl_arg = Build::Namelist->new($opts{'namelist'});
# Validate input namelist -- trap exceptions
my $nl_arg_valid;
eval { $nl_arg_valid = $definition->validate($nl_arg); };
if ($@) {
die "$ProgName - ERROR: Invalid namelist variable in commandline arg '-namelist'.\n $@";
}
# Merge input values into namelist. Previously specified values have higher precedence
# and are not overwritten.
$nl->merge_nl($nl_arg_valid);
}
# Process the -infile arg.
if (defined $opts{'infile'}) {
# Parse namelist input from a file
my $nl_infile = Build::Namelist->new($opts{'infile'});
# Validate input namelist -- trap exceptions
my $nl_infile_valid;
eval { $nl_infile_valid = $definition->validate($nl_infile); };
if ($@) {
die "$ProgName - ERROR: Invalid namelist variable in '-infile' $opts{'infile'}.\n $@";
}
# Merge input values into namelist. Previously specified values have higher precedence
# and are not overwritten.
$nl->merge_nl($nl_infile_valid);
}
# Process the -use_case arg.
# Declare global symbol $uc_defaults even if it's not defined, because we check whether it's
# defined before using it in the get_default_value method below.
my $uc_defaults;
if (defined $use_case_file) {
# The use case definition is contained in an xml file with the same format as the defaults file.
# Create a new NamelistDefaults object.
$uc_defaults = Build::NamelistDefaults->new($use_case_file, $cfg);
# Loop over the variables specified in the use case.
# A defaults file may contain information for variables that are not namelist variables.
# Check each name in the defaults file, and add each namelist variable to the namelist.
my @vars = $uc_defaults->get_variable_names();
VAR: foreach my $var (@vars) {
# Query the definition to find which group the variable belongs to. Skip if not found.
my $group = $definition->get_group_name($var);
if ($group) {
# Get the value of $var from the use case defaults
my $val = $uc_defaults->get_value($var);
if (defined $val) {
add_default($nl, $var, 'val'=>$val);
}
# If the use case doesn't provide a default value, then just ignore. This allows the
# use case mechanism to provide defaults for some attributes (e.g. a specific grid), and
# not for others.
}
}
}
#-----------------------------------------------------------------------------------------------
# Add default values for required namelist variables that have not been previously set.
# This is done either by using the namelist default object, or directly with inline logic.
# Are we building namelists for the CESM scripts or for standalone CAM scripts. If
# CESM then only produce namelists for the CAM component. If CAM standalone then produce
# output for the required non-cam components as well.
my $ccsm_build = $cfg->get('ccsm_seq');
my $cam_build = $ccsm_build ? 0 : 1;
if ($print>=2) {
if ($ccsm_build) {
print "Writing namelist files for cesm scripts$eol";
}
elsif ($cam_build) {
print "Writing namelist files for cam standalone scripts$eol";
}
}
# Start with the driver component. These settings are communicated by the driver to
# all subcomponents.
####################################
# namelist group: cime_driver_inst #
####################################
add_default($nl, 'ninst_driver', 'val'=>'1');
######################################
# namelist group: seq_cplflds_inparm #
######################################
add_default($nl, 'flds_co2_dmsa', 'val'=>'.false.');
add_default($nl, 'flds_co2_dmsb', 'val'=>'.false.');
add_default($nl, 'flds_co2a', 'val'=>'.true.');
add_default($nl, 'flds_co2b', 'val'=>'.false.');
add_default($nl, 'flds_co2c', 'val'=>'.false.');
add_default($nl, 'cplflds_custom', 'val'=>'');
############################
# namelist group: cime_pes #
############################
# By default the driver sets all components to use all tasks. This is the
# appropriate default for the standalone CAM configuration.
# By default the driver sets all components to use 1 thread. This should be
# reset either to user specified values, or by default use the OMP_NUM_THREADS
# environment variable to set the thread count for each component.
# Is this an smp build?
my $smp = $cfg->get('smp');
if ($smp) {
# If user has set the specific variables for component threads on the commandline
# those values will be used. If not, the highest precedence will be given the the
# value of the environment variable OMP_NUM_THREADS. That is because the number of
# threads specified on the configure commandline is used to determine an appropriate
# decomposition for the CICE model, but that decomposition may be valid for a range
# of ntask/nthread settings.
# Check for OMP_NUM_THREADS
my $nthreads;
if (defined $ENV{'OMP_NUM_THREADS'}) {
$nthreads = $ENV{'OMP_NUM_THREADS'};
}
if ($nthreads) {
add_default($nl, 'atm_nthreads', 'val'=>$nthreads);
add_default($nl, 'cpl_nthreads', 'val'=>$nthreads);
add_default($nl, 'ocn_nthreads', 'val'=>$nthreads);
}
}
#######################################
# namelist group: seq_infodata_inparm #
#######################################
# Case name
add_default($nl, 'case_name');
# Run type
add_default($nl, 'start_type');
# CIME model version
add_default($nl, 'cime_model', 'val'=>'cesm');
# CESM driver defaults
add_default($nl, 'coldair_outbreak_mod', 'val'=>'.true.');
add_default($nl, 'flux_max_iteration', 'val'=>'5');
add_default($nl, 'gust_fac', 'val'=>'0');
# Spectral Element dycore
my $dyn = $cfg->get('dyn');
if ($dyn =~ /se/) {add_default($nl, 'vect_map', 'val'=>'cart3d');}
# Physics package checks done here since aqua_planet setting is in
# the seq_infodata_inparm group
my $phys_mode_flags = 0;
my $adia_mode = 0;
my $aqua_mode = 0;
my $phys = $cfg->get('phys');
# Aqua planet
my $aqua_mode = $cfg->get('aquaplanet');
my $nl_aqua_flag = $nl->get_value('aqua_planet');
# Consistency check between configuration and namelist variables used for aquaplanet.
if ($aqua_mode and defined $nl_aqua_flag and ($nl_aqua_flag =~ m/$FALSE/io)) {
die "$ProgName - ERROR: Configured CAM for aquaplanet but aqua_planet set to FALSE in the namelist. \n";
}
if (!($aqua_mode) and defined $nl_aqua_flag and ($nl_aqua_flag =~ m/$TRUE/io)) {
die "$ProgName - ERROR: CAM not configured for aquaplanet but aqua_planet set to TRUE in the namelist. \n";
}
if ($aqua_mode) {
add_default($nl, 'aqua_planet', 'val'=>'.true.');
++$phys_mode_flags;
}
# Consistency check for namelist variables used to implement physics modes.
if ($phys eq 'adiabatic') {
$adia_mode = 1;
++$phys_mode_flags;
}
my $ideal_mode = 0;
if ($phys eq 'kessler' or $phys eq 'held_suarez' or $phys eq 'tj2016') {
$ideal_mode = 1;
++$phys_mode_flags;
}
if ($phys_mode_flags > 1) {
die "$ProgName - ERROR: Only one of the variables atm_adiabatic, atm_ideal_phys, and aqua_planet can be set .true. \n";
}
# Set convenience flag to indicate that one of the ideal or adiabatic
# modes is being used.
my $simple_phys = 0;
if ($adia_mode or $ideal_mode) { $simple_phys = 1; }
# Note that the prescribed SSTs
# used by aqua-planet mode are implemented in the cam_aqua component.)
# Single column mode
my $scam = $cfg->get('scam');
if ($scam) {
add_default($nl, 'single_column', 'val'=>'.true.');
add_default($nl, 'scmlat');
add_default($nl, 'scmlon');
}
######################################
# namelist group: seq_timemgr_inparm #
######################################
# Length of simulation
add_default($nl, 'stop_option');
unless (defined $nl->get_value('stop_ymd')) { add_default($nl, 'stop_n'); }
# Restart interval
add_default($nl, 'restart_option');
# Start date
# The following check should be done for CAM standalone builds only.
if ($cam_build) {
# When the user specifies ncdata there is no default for start_ymd since there is
# no way to determine the corresponding date of the ncdata file. So only add
# a default for start_ymd if the user has not specified ncdata.
if (defined $nl->get_value('ncdata')) {
unless (defined $nl->get_value('start_ymd')) {
die "$ProgName - ERROR: It is not allowed to set ncdata without also setting start_ymd. \n";
}
}
else {
add_default($nl, 'start_ymd');
}
}
# Orbit (if not coupled)
# If orbital parameters have not been specified then check for orbit year.
# If orbit year has not been specified, then set a default value.
if ($cam_build) {
if (not defined $nl->get_value('orb_obliq') or
not defined $nl->get_value('orb_eccen') or
not defined $nl->get_value('orb_mvelp') ) {
if (not defined $nl->get_value('orb_iyear')) {
add_default($nl, 'orb_iyear');
}
}
}
add_default($nl, 'cpl_seq_option');
# Coupling interval
# The default is for CAM to couple to the surface components every CAM timestep.
# So start by making sure CAM's dtime is set.
add_default($nl, 'dtime');
my $dtime = $nl->get_value('dtime');
add_default($nl, 'atm_cpl_dt', 'val'=>$dtime);
#-----------------------------------------------------------------------------------------------
# Add defaults for the CAM component
my $chem = $cfg->get('chem');
my $waccm_chem = ($chem =~ "waccm_");
my $waccm_phys = $cfg->get('waccm_phys');
my $carma = $cfg->get('carma');
my $prog_species = $cfg->get('prog_species');
my $prog_ghg1 = ($chem =~ "trop_mozart" or $chem =~ "trop_strat" or $chem =~ "ghg" or $chem =~ "_sc" or $prog_species =~ "GHG");
my $prog_ghg2 = ($chem =~ "ghg" or $chem =~ "_sc" or $prog_species =~ "GHG");
my $ghg_chem = ($chem =~ "ghg" or $chem =~ "_sc");
my $aero_chem = ($chem =~ "aero" or $chem eq 'trop_mozart' or $chem =~ 'trop_strat' or $chem =~ 'tsmlt');
my $chem_rad_passive = ($nl->get_value('chem_rad_passive') =~ /$TRUE/io);
my $ipcc_aircraft_emis = ($nl->get_value('ipcc_aircraft_emis') =~ /$TRUE/io);
my $rad_prog_ocarb = (($prog_species =~ "OC" or $aero_chem) and !($chem_rad_passive));
my $rad_prog_bcarb = (($prog_species =~ "BC" or $aero_chem) and !($chem_rad_passive));
my $rad_prog_sulf = (($prog_species =~ "SO4" or $aero_chem) and !($chem_rad_passive));
my $rad_prog_dust = (($prog_species =~ "DST" or $aero_chem) and !($chem_rad_passive));
my $rad_prog_sslt = (($prog_species =~ "SSLT" or $aero_chem) and !($chem_rad_passive));
my $rad_prog_ozone = (($chem =~ "mozart" or $chem =~ "waccm_ma" or $chem =~ "tsmlt" or $chem =~ "trop_strat" or $chem =~"tropstrat_mam_oslo") and !($chem_rad_passive));
# Check for eruptive volcano emissions. These will be radiatively active by default, but
# only if using BAM and the camrt radiation package
# or if using MAM and the rrtmg package
(my $volcaero_file = $nl->get_value('prescribed_volcaero_file')) =~ s/\s//g; # strip white space
$volcaero_file =~ s/['"]//g; # strip quotes "'
my $rad_volcaero = ($volcaero_file and $volcaero_file ne 'NONE' ) ? 1 : 0;
#################
# CAM namelists #
#################
# Print conservation errors
# Turn this off for PERGRO runs or for WACCM runs
if ($cfg->get('pergro') or ($chem ne 'none')) {
add_default($nl, 'print_energy_errors', 'val'=>'.false.');
}
# Set default for QNEG warnings
add_default($nl, 'print_qneg_warn', 'val'=>'summary');
# Turn on debugging checks
if ($cfg->get('debug')) {
add_default($nl, 'state_debug_checks', 'val'=> '.true.')
}
my $prescribe_aerosols = $TRUE;
if ($simple_phys) {$prescribe_aerosols = $FALSE;}
if( $chem =~ /_oslo/){
$prescribe_aerosols = $FALSE;
print " ==> Using Oslo aerosols: PRESCRIBED AERO = FALSE (not yet implemented) \n"
}
# Chemistry deposition lists
if ( ($chem ne 'none') or ( $prog_species ) ){
my $chem_proc_src = $cfg->get('chem_proc_src');
my $chem_src_dir = $cfg->get('chem_src_dir');
my ( $gas_wetdep_list, $aer_wetdep_list, $aer_sol_facti, $aer_sol_factb, $aer_scav_coef,
$aer_drydep_list, $gas_drydep_list ) =
set_dep_lists( $cfgdir, $chem_proc_src, $chem_src_dir, $nl, $print );
if (length($gas_wetdep_list)>2){
add_default($nl, 'gas_wetdep_method' );
add_default($nl, 'gas_wetdep_list', 'val'=>$gas_wetdep_list );
}
if (length($aer_wetdep_list)>2){
# determine if prescribed aerosols are not needed ...
if ($aer_wetdep_list =~ /so4/i &&
$aer_wetdep_list =~ /dst/i &&
($aer_wetdep_list =~ /bc/i || $aer_wetdep_list =~ /cb/i) &&
($aer_wetdep_list =~ /ncl/i || $aer_wetdep_list =~ /sslt/i)) {
$prescribe_aerosols = $FALSE;
}
add_default($nl, 'aer_wetdep_list', 'val'=>$aer_wetdep_list );
if (!($chem =~ /_mam/)) {
if (!defined $nl->get_value('aer_sol_facti')) {
add_default($nl, 'aer_sol_facti', val=>$aer_sol_facti );
}
if (!defined $nl->get_value('aer_sol_factb')) {
add_default($nl, 'aer_sol_factb', val=>$aer_sol_factb );
}
if (!defined $nl->get_value('aer_scav_coef')) {
add_default($nl, 'aer_scav_coef', val=>$aer_scav_coef );
}
}
}
if (length($gas_drydep_list)>2){
add_default($nl, 'drydep_list', 'val'=>$gas_drydep_list );
add_default($nl, 'depvel_file' );
add_default($nl, 'depvel_lnd_file' );
add_default($nl, 'clim_soilw_file' );
add_default($nl, 'season_wes_file' );
}
if (length($aer_drydep_list)>2){
add_default($nl, 'aer_drydep_list', 'val'=>$aer_drydep_list );
}
}
if ($chem) {
# Dry Deposition -- The responsibility for dry deposition is shared between CAM and CLM.
# The namelist is read by a driver module, seq_drydep_mod, and the information is shared
# between CAM and CLM by use association of that module.
add_default($nl, 'drydep_method');
# drydep_srf_file is only needed for prognostic MAM when the grid is unstructured.
# structured grids can do interpolation on the fly.
if ($chem =~ /_mam/ and $dyn =~ /se/) {
add_default($nl, 'drydep_srf_file');
}
}
# Initial conditions
#
# Most of the attributes that are matched to determine the default initial file are
# build time options that come from the configuration object. But there are also a couple
# of run time options that need to be considered. Set those in the optional hash argument
# to add_default.
my %atts = ();
# The initial date is an attribute in the defaults file which should be matched unless
# the user explicitly requests to ignore the initial date via the -ignore_ic_date option,
# or just ignore the year of the initial date via the -ignore_ic_year option.
my $ic_date = $nl->get_value('start_ymd');
if ($opts{'ignore_ic_date'}) {
# Don't set any attribute for date matching. By putting this option first it
# will take precedence in the case that the user has set both -ignore_ic_date
# and -ignore_ic_year
}
elsif ($opts{'ignore_ic_year'}) {
$atts{'ic_md'} = $ic_date;
}
else {
# if neither option specified then match full date
$atts{'ic_ymd'} = $ic_date;
}
add_default($nl, 'ncdata', %atts);
# analytic ICs
my $analytic_ic = $cfg->get('analytic_ic');
if ($analytic_ic) {
add_default($nl, 'analytic_ic_type');
}
#
# Simulated years: sim_year and sim_year_start
#
# sim_year
# This is used to identify appropriate defaults for climatological or transient
# forcing datasets. If user hasn't specified then default to 2000 (present day climatology).
my $sim_year = '2000';
if (defined $nl->get_value('sim_year')) {
$sim_year = $nl->get_value('sim_year');
# strip quotes to use the value in attribute matching.
$sim_year =~ s/['"]//g; #"'
}
# sim_year_start
# If sim_year is input as a range of years, then select the first year
# to use with some datasets
my $sim_year_start = $sim_year;
if ($sim_year =~ /(\d+)-(\d+)/) {
$sim_year_start = $1;
}
# Topography
add_default($nl, 'use_topo_file');
my $use_topo_file = $nl->get_value('use_topo_file');
if (!defined $use_topo_file or ($use_topo_file =~ m/$TRUE/io)) {
# Add the topo file unless the "do not use" override has been set.
add_default($nl, 'bnd_topo');
}
# Radiation
my $rad_pkg = $cfg->get('rad');
if ($rad_pkg eq 'camrt') {
add_default($nl, 'absems_data');
}
# Solar irradiance
# First check that solar_const and solar_irrad_data_file are not both defined
if (defined $nl->get_value('solar_const') and
defined $nl->get_value('solar_irrad_data_file')) {
die "$ProgName - ERROR: It is not allowed to set both solar_const and solar_irrad_data_file.\n";
}
if ($rad_pkg eq 'rrtmg' or $chem =~ /waccm/) {
if (defined $nl->get_value('solar_const')) {
die "$ProgName - ERROR: Specifying solar_const with RRTMG or WACCM is not allowed.\n"
}
# use solar data file as the default for rrtmg and waccm_ma
add_default($nl, 'solar_irrad_data_file');
add_default($nl, 'solar_htng_spctrl_scl', 'val'=>'.true.');
}
elsif (!$simple_phys) {
if ($chem eq 'none' and !($prog_species =~ /SO4/) ) { # Spectral solar data is needed for photolysis
# this preserves the default cam3 and cam4 configurations which do not have chemistry
unless (defined $nl->get_value('solar_irrad_data_file')) {
add_default($nl, 'solar_const');
}
} else {
# use solar data file as the default for all chem conifigurations
unless (defined $nl->get_value('solar_const')) {
add_default($nl, 'solar_irrad_data_file');
}
}
add_default($nl, 'solar_htng_spctrl_scl', 'val'=>'.false.');
}
# COSP simulator
if ($cfg->get('cosp')) {
add_default($nl, 'docosp', 'val'=>'.true.');
}
# Constituents
# ============
# Carbon cycle constituents
my $co2_cycle = $cfg->get('co2_cycle');
if ($co2_cycle) {
# co2_flag turns on the co2_cycle code in CAM
add_default($nl, 'co2_flag', 'val'=>'.true.');
# Supply a fossil fuel dataset if the co2_cycle is active and it's a
# transient run ...
if ($sim_year =~ /(\d+)-(\d+)/) {
add_default($nl, 'co2_readflux_fuel', 'val'=>'.true.');
# Check whether user has explicitly turned off reading the fossil fuel dataset.
# (user specification has higher precedence than the true value set above)
if ($nl->get_value('co2_readflux_fuel') =~ /$TRUE/io) {
add_default($nl, 'co2flux_fuel_file', 'sim_year'=>$sim_year);
}
add_default($nl, 'co2_readflux_aircraft', 'val'=>'.true.');
# Check whether user has explicitly turned off reading the aircraft CO2 dataset.
# (user specification has higher precedence than the true value set above)
if ($nl->get_value('co2_readflux_aircraft') =~ /$TRUE/io) {
my $rel_filepath = get_default_value('ac_CO2_emis');
my $emisval = quote_string('ac_CO2 -> ' . $rel_filepath);
add_default($nl, 'aircraft_specifier', 'val'=>$emisval);
add_default($nl, 'aircraft_datapath');
add_default($nl, 'aircraft_type');
# This should be the same file as the one in the aircraft_specifier file.
# This is a workaround to get this filepath into the cam.input_data_list file
# to allow the CESM scripts to obtain all required data for a run.
add_default($nl, 'aircraft_co2_file');
}
}
}
# By default the prognostic co2_cycle CO2 will be radiative active, unless the
# the user sets this override variable. This is used below to construct the
# rad_climate variable.
my $co2_cycle_rad_passive = ($nl->get_value('co2_cycle_rad_passive') =~ /$TRUE/io);
# Set number of test tracers requested via -nadv_tt option to configure
my $test_tracer_num = $cfg->get('nadv_tt');
if ($test_tracer_num > 0) {
add_default($nl, 'test_tracer_num', 'val'=>$test_tracer_num);
}
if ($cfg->get('age_of_air_trcs')) { add_default($nl, 'aoa_tracers_flag', 'val'=>'.true.'); }
# If phys option is "cam3" then turn on the CAM3 prescribed ozone and aerosols
if ($phys eq 'cam3' and !$aqua_mode) {
add_default($nl, 'cam3_ozone_data_on', 'val'=>'.true.');
add_default($nl, 'cam3_aero_data_on', 'val'=>'.true.');
}
# Defaults for radiatively active constituents
my $cam3_ozone_data = $FALSE;
my $cam3_aero_data = $FALSE;
my $moz_ozone_data = $FALSE;
if (!$rad_prog_ozone) {
$moz_ozone_data = $TRUE;
}
my $moz_aero_data = $FALSE;
if (!($rad_prog_ocarb) or !($rad_prog_bcarb) or !($rad_prog_sulf) or !($rad_prog_dust) or !($rad_prog_sslt)){
$moz_aero_data = $TRUE;
}
# CAM3 prescribed ozone only by request
if (defined $nl->get_value('cam3_ozone_data_on') and
$nl->get_value('cam3_ozone_data_on') =~ /$TRUE/io) {
add_default($nl, 'bndtvo');
$cam3_ozone_data = $TRUE;
$moz_ozone_data = $FALSE;
}
# CAM3 prescribed aerosols only by request
if (defined $nl->get_value('cam3_aero_data_on') and
$nl->get_value('cam3_aero_data_on') =~ /$TRUE/io) {
# CAM3 aerosol mass climatology dataset (horizontal resolution dependent)
add_default($nl, 'bndtvaer');
$cam3_aero_data = $TRUE;
$moz_aero_data = $FALSE;
}
if ($chem_rad_passive or $aqua_mode) {
add_default($nl, 'atm_dep_flux', 'val'=>'.false.');
}
# The aerosol optics depend on which radiative transfer model is used due to differing
# wavelength bands used.
my $rrtmg = $rad_pkg eq 'rrtmg' ? 1 : 0;
# @aero_names contains the names of the entities (bulk aerosols and modes)
# that are externally mixed in aerosol optics calculation. These entities are all
# associated with a file that contains their physical and optical properties.
my @aero_names = ();
# @aerosources contains a source identifier corresponding to each entity in @aero_names.
# The values are 'A', 'N', or 'M'
my @aerosources = ();
## Start assembling the gas contributions to the rad_climate specifier.
# $radval contains the "list of strings" value (stored as a scalar string with embedded quotes
# and commas) that will be assigned to the namelist variable rad_climate.
my $radval = "'A:Q:H2O'";
if (($chem =~ /waccm_ma/ or $chem =~ /waccm_tsmlt/) and !$chem_rad_passive) {
$radval .= ",'A:O2:O2','A:CO2:CO2'";
}
elsif ($chem =~ /trop_strat/ and !$chem_rad_passive) {
$radval .= ",'N:O2:O2','A:CO2:CO2'";
}