-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-namelist
2741 lines (2356 loc) · 103 KB
/
build-namelist
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 POP configuration
#
# build-namelist uses a config_cache.xml file that current contains the ocean grid information.
# build-namelist reads this file to obtain information it needs to provide
# default values that are consistent with the POP library. For example, the grid resolution
# is obtained from the cache file and used to determine appropriate defaults for namelist input
# that is 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.
#
#
# Date Contributor Modification
# -------------------------------------------------------------------------------------------
# 2012-01-30 Vertenstein Original version
#--------------------------------------------------------------------------------------------
use strict;
use Cwd qw( getcwd abs_path chdir );
use English;
use Getopt::Long;
use IO::File;
no if ($PERL_VERSION ge v5.18.0), 'warnings' => 'experimental::smartmatch';
#-----------------------------------------------------------------------------------------------
sub usage {
die <<EOF;
SYNOPSIS
build-namelist [options]
OPTIONS
-infile "filepath" Specify a file containing namelists to read values from.
-namelist "namelist" Specify namelist settings directly on the commandline by supplying
a string containing FORTRAN namelist syntax, e.g.,
-namelist "&pop_nml dt=1800 /"
-help [or -h] Print usage to STDOUT.
-test Enable checking that input datasets exist on local filesystem.
-verbose Turn on verbose echoing of informational messages.
-caseroot CASEROOT directory variable
-cimeroot CIMEROOT directory variable
-ocn_grid OCN_GRID variable
-cfg_grid Directory containing POP configuration scripts.
If not defined, location is set as \$ProgDir or \$cwd
(Needed to run build-namelist from SourceMods dir)
-inst_string inst_string variable
-ntasks number of ocean tasks
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. (none right now)
2. values set on the command-line using the -namelist option,
3. values read from the file specified by -infile,
4. values from the namelist defaults file - or values specifically set in build-namelist
EOF
}
#-----------------------------------------------------------------------------------------------
# Set the directory that contains the POP 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
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 = abs_path($ProgDir);
} else {
$cfgdir = $cwd;
}
#-----------------------------------------------------------------------------------------------
# Process command-line options.
my %opts = ( help => 0,
test => 0,
verbose => 0,
preview => 0,
caseroot => undef,
cimeroot => undef,
inst_string => undef,
ocn_grid => undef,
cfg_dir => $cfgdir,
ntasks => undef,
);
GetOptions(
"h|help" => \$opts{'help'},
"infile=s" => \$opts{'infile'},
"namelist=s" => \$opts{'namelist'},
"v|verbose" => \$opts{'verbose'},
"caseroot=s" => \$opts{'caseroot'},
"cimeroot=s" => \$opts{'cimeroot'},
"inst_string=s" => \$opts{'inst_string'},
"ocn_grid=s" => \$opts{'ocn_grid'},
"cfg_dir=s" => \$opts{'cfg_dir'},
"preview" => \$opts{'preview'},
"ntasks=s" => \$opts{'ntasks'},
) or usage();
# Give usage message.
usage() if $opts{'help'};
# 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 (currently not used)
# 2 - verbose
my $print = 0;
my $preview = 0;
if ($opts{'verbose'}) { $print = 2; }
if ($opts{'preview'}) { $preview = 1; }
my $eol = "\n";
if ($print>=2) { print "Setting POP configuration script directory to $cfgdir$eol"; }
my $CASEROOT = $opts{'caseroot'};
my $CIMEROOT = $opts{'cimeroot'};
my $OCN_GRID = $opts{'ocn_grid'};
my $inst_string = $opts{'inst_string'};
my $ntasks = $opts{'ntasks'};
$cfgdir = $opts{'cfg_dir'};
# Validate some of the commandline option values.
validate_options("commandline", \%opts);
#-----------------------------------------------------------------------------------------------
# Make sure we can find required perl modules, definition, and defaults files.
# Look for them under the directory that contains the configure script.
# The root directory for the perl5 required utilities
my $perl5lib = "$CIMEROOT/utils/perl5lib";
# The Build::Config module provides utilities to access the configuration information
# in the config_cache.xml file (see below)
(-f "$perl5lib/Build/Config.pm") or die <<"EOF";
** $ProgName - Cannot find perl module \"Build/Config.pm\" in directory \"$perl5lib\" **
EOF
# The Build::NamelistDefinition module provides utilities to validate that the output
# namelists are consistent with the namelist definition file
(-f "$perl5lib/Build/NamelistDefinition.pm") or die <<"EOF";
** $ProgName - Cannot find perl module \"Build/NamelistDefinition.pm\" in directory \"$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 "$perl5lib/Build/NamelistDefaults.pm") or die <<"EOF";
** $ProgName - Cannot find perl module \"Build/NamelistDefaults.pm\" in directory \"$perl5lib\" **
EOF
# The Build::Namelist module provides utilities to parse input namelists, to query and modify
# namelists, and to write output namelists.
(-f "$perl5lib/Build/Namelist.pm") or die <<"EOF";
** $ProgName - Cannot find perl module \"Build/Namelist.pm\" in directory \"$perl5lib\" **
EOF
# 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 POP tag is $cfgdir/namelist_files/namelist_definition.xml. To aid developers
# who make use of the SourceMods/src.pop directory - we allow the definition file
# to come from that directory
my $nl_definition_file;
if (-f "${CASEROOT}/SourceMods/src.pop/namelist_definition_pop.xml") {
$nl_definition_file = "${CASEROOT}/SourceMods/src.pop/namelist_definition_pop.xml";
}
if (! defined $nl_definition_file) {
# default location of namelist definition file
$nl_definition_file = "$cfgdir/namelist_files/namelist_definition_pop.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"; }
# The namelist defaults file contains default values for all required namelist variables.
my $nl_defaults_file;
if (-f "${CASEROOT}/SourceMods/src.pop/namelist_defaults_pop.xml") {
$nl_defaults_file = "${CASEROOT}/SourceMods/src.pop/namelist_defaults_pop.xml";
}
if (! defined $nl_defaults_file) {
$nl_defaults_file = "$cfgdir/namelist_files/namelist_defaults_pop.xml";
(-f "$nl_defaults_file") or die <<"EOF";
** $ProgName - Cannot find namelist defaults file \"$nl_defaults_file\" **
EOF
}
if ($print>=2) { print "Using namelist defaults file $nl_defaults_file$eol"; }
#-----------------------------------------------------------------------------------------------
# Add $perl5lib_dir to the list of paths that Perl searches for modules
unshift @INC, "$perl5lib";
require Build::Config;
require Build::NamelistDefinition;
require Build::NamelistDefaults;
require Build::Namelist;
require Config::SetupTools;
#-----------------------------------------------------------------------------------------------
# Create a configuration object from the POP config_cache.xml file in $CASEROOT/Buildconf/popconf
my $cfg = Build::Config->new('config_cache.xml');
# 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.
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 POP library for which the namelist is being produced.
my $defaults = Build::NamelistDefaults->new($nl_defaults_file, $cfg);
# Create an empty namelist object. Add values to it in order of precedence.
my $nl = Build::Namelist->new();
#-----------------------------------------------------------------------------------------------
# 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.
# 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'});
my $nl_infile_valid = Build::Namelist->new();
# Validate namelist variables (going to do this one variable at a time)
for my $group ($nl_infile->get_group_names()) {
for my $var ($nl_infile->get_variable_names($group)) {
my $var_local; # Name of variable to write to infile
my $nl_check_var = Build::Namelist->new();
my $nl_check_valid;
my $val = $nl_infile->get_variable_value($group, $var);
my @broken = split(/&/,$var);
my $check_grp = 0; # If 1, make sure group found in definitions file
# matches that specified in user_nl_pop
# if variable has ampersand, truncate it unless it is type derived
if ($broken[1]) {
my $nl_check_amp = Build::Namelist->new();
$nl_check_amp->set_variable_value($group, $var, $val);
eval { $definition->validate($nl_check_amp) };
if (not $@) {
# & is required in variable name
$var_local = $var;
} else {
# & should not be in variable name
$var_local = $broken[0];
$check_grp = 1;
}
} else {
$var_local = $var;
}
# Make sure variable is defined in namelist_definition_pop.xml
$nl_check_var->set_variable_value($group, $var_local,$val);
eval { $nl_check_valid = $definition->validate($nl_check_var); };
(not $@) or die <<"EOF";
** ERROR: either $var_local is not a valid POP namelist variable or $var_local = $val is not a valid value; please fix user_nl_pop. Note that $var_local may appear in multiple namelists, in which case you need to specify the correct namelist in user_nl_pop using the format $var_local\&namelist_nml = $val, where \&namelist_nml is the pop_in namelist containing $var_local.**
EOF
# If group was specified in user_nl_pop, make sure it matches
# the group in the definitions file.
my @group_valid = $nl_check_valid->get_group_names();
((not $check_grp) or ($broken[1] eq $group_valid[0])) or die <<"EOF";
** ERROR: $broken[0] is in $group_valid[0], not $broken[1]! Please fix this in user_nl_pop. **
EOF
# Add variable to validated namelist
$nl_infile_valid->set_variable_value($group_valid[0], $var_local, $val);
}
}
# If preview is desired and something has been changed in $nl_infile_valid,
# output everything in $nl_infile_valid
if (($preview == 1) && ($nl_infile_valid->get_group_names)) {
print " - The following values have been set in user_nl_pop:\n";
print_nl_to_screen($nl_infile_valid);
}
# Merge input values into namelist. Previously specified values have higher
# precedence and are not overwritten.
$nl->merge_nl($nl_infile_valid);
}
#-----------------------------------------------------------------------------------------------
# Determine xml variables
my %xmlvars = ();
SetupTools::getxmlvars($CASEROOT, \%xmlvars);
$xmlvars{DIN_LOC_ROOT} = SetupTools::expand_xml_var($xmlvars{DIN_LOC_ROOT}, \%xmlvars);
foreach my $attr (keys %xmlvars) {
$xmlvars{$attr} = SetupTools::expand_xml_var($xmlvars{$attr}, \%xmlvars);
}
my $RUNDIR = "$xmlvars{'RUNDIR'}";
my $SRCROOT = "$xmlvars{'SRCROOT'}";
my $DIN_LOC_ROOT = "$xmlvars{'DIN_LOC_ROOT'}";
my $CASE = "$xmlvars{'CASE'}";
my $CALENDAR = "$xmlvars{'CALENDAR'}";
my $CCSM_CO2_PPMV = "$xmlvars{'CCSM_CO2_PPMV'}";
my $CCSM_BGC = "$xmlvars{'CCSM_BGC'}";
my $NCPL_BASE_PERIOD = "$xmlvars{'NCPL_BASE_PERIOD'}";
my $OCN_NCPL = "$xmlvars{'OCN_NCPL'}";
my $OCN_COUPLING = "$xmlvars{'OCN_COUPLING'}";
my $OCN_ICE_FORCING = "$xmlvars{'OCN_ICE_FORCING'}";
my $OCN_CHL_TYPE = "$xmlvars{'OCN_CHL_TYPE'}";
my $OCN_CO2_TYPE = "$xmlvars{'OCN_CO2_TYPE'}";
my $OCN_TRANSIENT = "$xmlvars{'OCN_TRANSIENT'}";
my @OCN_TRACER_MODULES = split(" ", "$xmlvars{'OCN_TRACER_MODULES'}");
my $OCN_TRACER_MODULES_OPT = "$xmlvars{'OCN_TRACER_MODULES_OPT'}";
my $OCN_TAVG_TRACER_BUDGET = "$xmlvars{'OCN_TAVG_TRACER_BUDGET'}";
my $OCN_TAVG_HIFREQ = "$xmlvars{'OCN_TAVG_HIFREQ'}";
my $OCN_ONEDIM = "$xmlvars{'OCN_ONEDIM'}";
my $POP_DECOMPTYPE = "$xmlvars{'POP_DECOMPTYPE'}";
my $INFO_DBUG = "$xmlvars{'INFO_DBUG'}";
my $RUN_TYPE = "$xmlvars{'RUN_TYPE'}";
my $RUN_STARTDATE = "$xmlvars{'RUN_STARTDATE'}";
my $RUN_REFDATE = "$xmlvars{'RUN_REFDATE'}";
my $CONTINUE_RUN = "$xmlvars{'CONTINUE_RUN'}";
my $DEBUG = "$xmlvars{'DEBUG'}";
my $ICE_NCAT = $xmlvars{'ICE_NCAT'};
my $POP_PASSIVE_TRACER_RESTART_OVERRIDE = "$xmlvars{'POP_PASSIVE_TRACER_RESTART_OVERRIDE'}";
my $DATM_MODE = "$xmlvars{'DATM_MODE'}";
expand_xml_variables_in_namelist($nl, \%xmlvars);
my $output_r = "./${CASE}.pop.r";
my $output_h = "./${CASE}.pop.h";
my $output_d = "./${CASE}.pop.d";
if ($inst_string) {
$output_r = "./${CASE}.pop${inst_string}.r";
$output_h = "./${CASE}.pop${inst_string}.h";
$output_d = "./${CASE}.pop${inst_string}.d";
}
# Environment variables set in pop.buildnml.csh that are not xml variables
my $RESTART_INPUT_TS_FMT = "$ENV{'RESTART_INPUT_TS_FMT'}";
my $LID = $ENV{'LID'};
if ($CONTINUE_RUN eq 'TRUE') {$RUN_TYPE = "continue";}
my $iyear0 = `echo $RUN_STARTDATE | cut -c1-4 | sed -e 's/^0*//'`;
$iyear0 =~ s/\n/ /g; # remove imbedded newline
$iyear0 = $iyear0+0;
my $imonth0 = `echo $RUN_STARTDATE | cut -c6-7 | sed -e 's/^0*//'`;
$imonth0 =~ s/\n/ /g; # remove imbedded newline
$imonth0 = $imonth0+0;
my $iday0 = `echo $RUN_STARTDATE | cut -c9-10 | sed -e 's/^0*//'`;
$iday0 =~ s/\n/ /g; # remove imbedded newline
$iday0 = $iday0+0;
my $ihour0 = 0;
my $iminute0 = 0;
my $isecond0 = 0;
# coupled_freq and coupled_freq_opts depend on
# environment variables NCPL_BASE_PERIOD and OCN_NCPL
# Note that env_run.xml couples OCN_NCPL times per NCPL_BASE_PERIOD
# while POP couples every coupled_freq [in units of coupled_freq_opts]
# Example: OCN_NCPL = 4, NCPL_BASE_PERIOD = day => couple 4 times a day
# coupled_freq = 4, coupled_freq_opts = nday => couple every 4 days
#
# Also need to know coupled_freq and coupled_freq_opts to set start time
# in time_manager_nml
my $coupled_freq;
my $coupled_freq_opt = 'nsecond';
my $sec_per_base_period;
if ($NCPL_BASE_PERIOD eq 'hour') {
$sec_per_base_period = 3600;
} elsif ($NCPL_BASE_PERIOD eq 'day') {
$sec_per_base_period = 3600 * 24;
} elsif ($NCPL_BASE_PERIOD eq 'year') {
if ($CALENDAR eq 'NO_LEAP') {
$sec_per_base_period = 3600 * 24 * 365;
} else {
die "$ProgName: ERROR invalid CALENDAR for NCPL_BASE_PERIOD $NCPL_BASE_PERIOD";
}
} elsif ($NCPL_BASE_PERIOD eq 'decade') {
if ($CALENDAR eq 'NO_LEAP') {
$sec_per_base_period = 3600 * 24 * 365 * 10;
} else {
die "$ProgName: ERROR invalid CALENDAR for NCPL_BASE_PERIOD $NCPL_BASE_PERIOD";
}
} else {
die "$ProgName: ERROR invalid NCPL_BASE_PERIOD $NCPL_BASE_PERIOD";
}
if ($sec_per_base_period < 0) {
die "$ProgName: ERROR integer overflow $sec_per_base_period should be positive";
}
if ($sec_per_base_period % $OCN_NCPL == 0) {
$coupled_freq = $sec_per_base_period/$OCN_NCPL;
} else {
die "$ProgName: Coupling $OCN_NCPL times per $NCPL_BASE_PERIOD is not an integer number of seconds per coupling period";
}
if ($coupled_freq % 3600 == 0) {
$coupled_freq = $coupled_freq / 3600;
$coupled_freq_opt = 'nhour';
# print $sec_per_base_period/$OCN_NCPL," seconds = $coupled_freq hour(s)\n";
if ($coupled_freq % 24 == 0) {
$coupled_freq = $coupled_freq / 24;
$coupled_freq_opt = 'nday';
# print $sec_per_base_period/$OCN_NCPL," seconds = $coupled_freq day(s)\n";
if ($coupled_freq % 365 == 0) {
$coupled_freq = $coupled_freq / 365;
$coupled_freq_opt = 'nyear';
# print $sec_per_base_period/$OCN_NCPL," seconds = $coupled_freq year(s)\n";
}
}
}
# tmp starts with units of seconds, will cycle through minutes, hours, and days
# and increase isecond0, iminute0, ihour0, and iday0 as necessary. Note that at
# this point I don't know how to toggle months, so errors might occur with
# abnormally large coupling frequency.
my $tmp = $sec_per_base_period/$OCN_NCPL;
my $remainder;
# increase seconds
$remainder = $tmp%60;
$isecond0 += $remainder;
# increase minutes
$tmp = ($tmp - $remainder)/60;
$remainder = $tmp%60;
$iminute0 += $remainder;
# increase hours
$tmp = ($tmp - $remainder)/60;
$remainder = $tmp%24;
$ihour0 += $remainder;
# increase days
$tmp = ($tmp - $remainder)/24;
if ($tmp > 0) {
$iday0 += $tmp;
# check to see if need to roll into new month / year
while (not valid_date(\$iday0, \$imonth0, \$iyear0, $CALENDAR)) {}
}
if ($print>=2) {
print "POP build-namelist: ocn_grid is $OCN_GRID \n";
print "POP build-namelist: ocn_tracer_modules are @OCN_TRACER_MODULES \n";
print "Inputdata root directory: $DIN_LOC_ROOT$eol";
}
#-----------------------------------------------------------------------------------------------
# Determine namelist
#-----------------------------------------------------------------------------------------------
##################################
# namelist group: domain_nml #
##################################
add_default($nl, 'nprocs_clinic', 'val'=>"$ntasks");
add_default($nl, 'nprocs_tropic', 'val'=>"$ntasks");
add_default($nl, 'clinic_distribution_type', 'val'=>"$POP_DECOMPTYPE");
add_default($nl, 'tropic_distribution_type', 'val'=>"$POP_DECOMPTYPE");
add_default($nl, 'ew_boundary_type');
add_default($nl, 'ns_boundary_type');
add_default($nl, 'profile_barrier');
##################################
# namelist group: io_nml #
##################################
add_default($nl, 'num_iotasks');
add_default($nl, 'lredirect_stdout');
add_default($nl, 'log_filename', 'val'=>"${RUNDIR}/ocn${inst_string}.log.$LID");
add_default($nl, 'luse_pointer_files');
####################################
# namelist group: time_manager_nml #
####################################
add_default($nl, 'accel_file', 'val'=>"${RUNDIR}/${OCN_GRID}_depth_accel");
add_default($nl, 'runid', 'val'=>"$CASE");
add_default($nl, 'time_mix_opt');
add_default($nl, 'time_mix_freq');
add_default($nl, 'dt_option');
my $time_mix_opt = $nl->get_value('time_mix_opt');
$time_mix_opt =~ s/^\s+//;
$time_mix_opt =~ s/\s+$//;
add_default($nl, 'dt_count','ocn_coupling'=>"$OCN_COUPLING",'ocn_onedim'=>"$OCN_ONEDIM", 'time_mix'=>"$time_mix_opt");
add_default($nl, 'impcor');
add_default($nl, 'laccel');
add_default($nl, 'dtuxcel');
add_default($nl, 'allow_leapyear', 'calendar'=>"$CALENDAR");
add_default($nl, 'iyear0' ,'val'=>$iyear0);
add_default($nl, 'imonth0' ,'val'=>$imonth0);
add_default($nl, 'iday0' ,'val'=>$iday0);
add_default($nl, 'ihour0' ,'val'=>$ihour0);
add_default($nl, 'iminute0','val'=>$iminute0);
add_default($nl, 'isecond0','val'=>$isecond0);
add_default($nl, 'date_separator');
add_default($nl, 'stop_option');
add_default($nl, 'stop_count');
add_default($nl, 'fit_freq', 'val'=>"$OCN_NCPL");
add_default($nl, 'robert_alpha');
add_default($nl, 'robert_nu');
####################################
# namelist group: grid_nml #
####################################
# Note: topography_opt = bathymetry is a nonstandard option that
# requires the user to provide nonstandard files in the users'
# $CASEROOT/SourceMods/src.pop directory
# Currently this is hard-wired to 'file'
# Also, flat_bottom is not set until after pop1d_nml because its
# default value depends on lidentical_columns
my $topography_opt = 'file'; # hard-wired for now
my $bathymetry_file= 'unknown_bathymetry'; #hard-wired for now
add_default($nl, 'vert_grid_file' , 'val'=>"${RUNDIR}/${OCN_GRID}_vert_grid");
add_default($nl, 'region_info_file', 'val'=>"${RUNDIR}/${OCN_GRID}_region_ids");
add_default($nl, 'topography_opt' , 'val'=>"$topography_opt");
add_default($nl, 'bathymetry_file' , 'val'=>"$bathymetry_file");
add_default($nl, 'lremove_points' , 'topograpahy_opt'=>"$topography_opt");
add_default($nl, 'horiz_grid_opt');
add_default($nl, 'horiz_grid_file');
add_default($nl, 'vert_grid_opt' );
add_default($nl, 'topography_file');
add_default($nl, 'topography_outfile', 'val'=>"${output_h}.topography_bathymetry.ieeer8");
add_default($nl, 'kmt_kmin');
add_default($nl, 'partial_bottom_cells');
add_default($nl, 'bottom_cell_file', 'nofail'=>1);
if (not $nl->get_value('bottom_cell_file')) {
add_default($nl, 'bottom_cell_file', 'val'=>'unknown_bottom_cell','noprepend'=>1);
}
add_default($nl, 'n_topo_smooth');
add_default($nl, 'region_mask_file');
add_default($nl, 'sfc_layer_opt', 'ocn_onedim'=>"$OCN_ONEDIM");
add_default($nl, 'l1Ddyn', 'ocn_onedim'=>"$OCN_ONEDIM");
####################################
# namelist group: pop1d_nml #
####################################
my $iden_cols = 'FALSE'; # used for constant Coriolis and flat bottom
my $l1Ddyn = $nl->get_value('l1Ddyn');
if ($l1Ddyn eq '.true.') {
add_default($nl, 'lidentical_columns');
my $lidentical_cols = $nl->get_value('lidentical_columns');
if ($lidentical_cols eq '.true.') {
$iden_cols = 'TRUE';
}
add_default($nl, 'lconst_Coriolis', 'iden_cols'=>"$iden_cols");
add_default($nl, 'lmin_Coriolis', 'ocn_onedim'=>"$OCN_ONEDIM");
add_default($nl, 'Coriolis_min');
add_default($nl, 'Coriolis_val');
add_default($nl, 'global_taux');
add_default($nl, 'global_SHF_coef');
}
# Back to grid_nml
add_default($nl, 'flat_bottom', 'iden_cols'=>"$iden_cols");
####################################
# namelist group: init_ts_nml #
####################################
if ($OCN_ONEDIM eq 'TRUE' && $RUN_TYPE eq 'startup') {
add_default($nl, 'init_ts_option', 'val'=>'internal');
} else {
if ($RUN_TYPE eq 'startup' && $topography_opt eq 'bathymetry') {
add_default($nl, 'init_ts_option' , 'val'=>'PHC');
add_default($nl, 'init_ts_file' , 'val'=>'ts_PHC2_jan_ic_resindpt'); #TODO?
add_default($nl, 'init_ts_file_fmt', 'val'=>'nc');
} else {
add_default($nl, 'init_ts_option' , 'val'=>"ccsm_${RUN_TYPE}");
add_default($nl, 'init_ts_file');
if ($OCN_GRID eq 'tx0.1v3') {
add_default($nl, 'init_ts_file_fmt');
} else {
add_default($nl, 'init_ts_file_fmt', 'val'=>"$RESTART_INPUT_TS_FMT");
}
}
}
add_default($nl, 'init_ts_outfile' , 'val'=>"${output_h}.ts_ic");
add_default($nl, 'init_ts_outfile_fmt');
add_default($nl, 'init_ts_suboption');
add_default($nl, 'init_ts_perturb');
##########################################
# namelist group: diagnostics_nml #
##########################################
add_default($nl, 'diag_transport_file', 'val'=>"${RUNDIR}/${OCN_GRID}_transport_contents");
if ($INFO_DBUG > 1) {
add_default($nl, 'diag_global_freq_opt', 'val'=>'nstep');
add_default($nl, 'diag_cfl_freq_opt' , 'val'=>'nstep');
add_default($nl, 'diag_transp_freq_opt', 'val'=>'nstep');
} else {
add_default($nl, 'diag_global_freq_opt');
add_default($nl, 'diag_cfl_freq_opt');
add_default($nl, 'diag_transp_freq_opt');
}
add_default($nl, 'diag_global_freq');
add_default($nl, 'diag_cfl_freq');
add_default($nl, 'diag_transp_freq');
add_default($nl, 'diag_outfile', 'val'=>"${RUNDIR}/${output_d}d");
add_default($nl, 'diag_transport_outfile','val'=>"${RUNDIR}/${output_d}t");
add_default($nl, 'diag_velocity_outfile', 'val'=>"${RUNDIR}/${output_d}v");
add_default($nl, 'cfl_all_levels');
add_default($nl, 'diag_all_levels');
add_default($nl, 'ldiag_velocity');
##########################################
# namelist group: budget_diagnostics_nml #
##########################################
if ($OCN_TAVG_HIFREQ eq "TRUE" ) {
add_default($nl, 'ldiag_global_tracer_budgets', 'val'=>'.false.');
} else {
add_default($nl, 'ldiag_global_tracer_budgets','ocn_onedim'=>"$OCN_ONEDIM");
}
##########################################
# namelist group: bsf_diagnostics_nml #
##########################################
add_default($nl, 'ldiag_bsf', 'ocn_onedim'=>"$OCN_ONEDIM");
##########################################
# namelist group: restart_nml #
##########################################
add_default($nl, 'restart_freq_opt');
add_default($nl, 'restart_freq');
add_default($nl, 'restart_start_opt');
add_default($nl, 'restart_start');
add_default($nl, 'restart_outfile', 'val'=>"${output_r}");
add_default($nl, 'restart_fmt');
add_default($nl, 'leven_odd_on');
add_default($nl, 'even_odd_freq');
add_default($nl, 'pressure_correction');
##########################################
# namelist group: history_nml #
##########################################
add_default($nl, 'history_contents', 'val'=>"${RUNDIR}/${OCN_GRID}_history_contents");
add_default($nl, 'history_freq_opt');
add_default($nl, 'history_freq');
add_default($nl, 'history_outfile', 'val'=>"${output_h}s");
add_default($nl, 'history_fmt');
##########################################
# namelist group: movie_nml #
##########################################
add_default($nl, 'movie_contents', 'val'=>"${RUNDIR}/${OCN_GRID}_movie_contents");
add_default($nl, 'movie_freq_opt');
add_default($nl, 'movie_freq');
add_default($nl, 'movie_outfile', 'val'=>"${output_h}m");
add_default($nl, 'movie_fmt');
##########################################
# namelist group: solvers #
##########################################
add_default($nl, 'solverChoice');
add_default($nl, 'convergenceCriterion');
add_default($nl, 'maxIterations');
add_default($nl, 'convergenceCheckFreq');
add_default($nl, 'convergenceCheckStart');
add_default($nl, 'preconditionerChoice');
add_default($nl, 'preconditionerFile');
add_default($nl, 'lanczosconvergenceCriterion');
add_default($nl, 'maxLanczosStep');
##########################################
# namelist group: vertical_mix_nml #
##########################################
add_default($nl, 'vmix_choice');
add_default($nl, 'aidif');
add_default($nl, 'implicit_vertical_mix');
add_default($nl, 'convection_type');
add_default($nl, 'nconvad');
add_default($nl, 'convect_diff');
add_default($nl, 'convect_visc');
add_default($nl, 'bottom_drag');
########################################
# namelist group: geoheatflux_nml #
########################################
add_default($nl, 'geoheatflux_choice');
add_default($nl, 'geoheatflux_const');
add_default($nl, 'geoheatflux_depth');
##########################################
# namelist group: vmix_const_nml #
##########################################
add_default($nl, 'const_vvc');
add_default($nl, 'const_vdc');
##########################################
# namelist group: vmix_rich_nml #
##########################################
add_default($nl, 'bckgrnd_vvc');
add_default($nl, 'bckgrnd_vdc');
add_default($nl, 'rich_mix&vmix_rich_nml');
##########################################
# namelist group: tidal_nml #
##########################################
add_default($nl, 'ltidal_all_TC_coefs_eq_1');
add_default($nl, 'ltidal_all_TC_coefs_eq_p33');
add_default($nl, 'ltidal_mixing');
my $ltidal_mixing = $nl->get_value('ltidal_mixing');
$ltidal_mixing =~ s/ //g;
add_default($nl, 'ltidal_max');
add_default($nl, 'ltidal_schmittner_socn');
add_default($nl, 'ltidal_stabc');
add_default($nl, 'ltidal_lunar_cycle');
add_default($nl, 'ltidal_melet_plot');
my $ltidal_melet_plot = $nl->get_value('ltidal_melet_plot');
$ltidal_melet_plot =~ s/ //g;
add_default($nl, 'tidal_energy_choice');
my $tidal_energy_choice = $nl->get_value('tidal_energy_choice');
$tidal_energy_choice =~ s/ //g;
if ($ltidal_mixing eq ".true." ) {
add_default($nl, 'tidal_energy_file', 'tidal_energy_choice'=>"$tidal_energy_choice");
add_default($nl, 'tidal_energy_file_fmt','tidal_energy_choice'=>"$tidal_energy_choice");
}
add_default($nl, 'tidal_eps_n2');
add_default($nl, 'tidal_vars_file_polz', 'nofail'=>1);
if (not $nl->get_value('tidal_vars_file_polz')) {
add_default($nl, 'tidal_vars_file_polz', 'val'=>'unknown_tidal_vars_file_polz','noprepend'=>1);
}
add_default($nl, 'tidal_energy_ts_files(1)');
add_default($nl, 'tidal_energy_ts_files(2)');
add_default($nl, 'tidal_energy_ts_files(3)');
add_default($nl, 'tidal_energy_ts_files(4)');
add_default($nl, 'tidal_energy_ts_file_fmt');
add_default($nl, 'tidal_energy_ts_calendar');
add_default($nl, 'tidal_energy_ts_model_yr_align');
add_default($nl, 'tidal_energy_ts_data_first_year');
add_default($nl, 'tidal_energy_ts_data_first_month');
add_default($nl, 'tidal_energy_ts_data_first_day');
add_default($nl, 'tidal_energy_ts_data_final_year');
add_default($nl, 'tidal_energy_ts_data_final_month');
add_default($nl, 'tidal_energy_ts_data_final_day');
add_default($nl, 'tidal_local_mixing_fraction');
add_default($nl, 'tidal_mixing_method_choice');
my $tidal_mixing_method_choice = $nl->get_value('tidal_mixing_method_choice');
$tidal_mixing_method_choice =~ s/ //g;
add_default($nl, 'tidal_mixing_efficiency');
add_default($nl, 'vertical_decay_scale');
add_default($nl, 'tidal_mix_max');
add_default($nl, 'tidal_diss_lim_TC');
add_default($nl, 'tidal_vars_file_fmt_polz');
add_default($nl, 'tidal_vert_decay_option_schm');
add_default($nl,'ltidal_min_regions');
add_default($nl,'num_tidal_min_regions');
add_default($nl,'tidal_min_values(1)');
add_default($nl,'tidal_min_regions_name(1)');
add_default($nl,'tidal_min_regions_klevels(1)');
add_default($nl,'tidal_TLATmin_regions(1)');
add_default($nl,'tidal_TLATmax_regions(1)');
add_default($nl,'tidal_TLONmin_regions(1)');
add_default($nl,'tidal_TLONmax_regions(1)');
add_default($nl,'tidal_min_values(2)');
add_default($nl,'tidal_min_regions_name(2)');
add_default($nl,'tidal_min_regions_klevels(2)');
add_default($nl,'tidal_TLATmin_regions(2)');
add_default($nl,'tidal_TLATmax_regions(2)');
add_default($nl,'tidal_TLONmin_regions(2)');
add_default($nl,'tidal_TLONmax_regions(2)');
add_default($nl,'tidal_min_values(3)');
add_default($nl,'tidal_min_regions_name(3)');
add_default($nl,'tidal_min_regions_klevels(3)');
add_default($nl,'tidal_TLATmin_regions(3)');
add_default($nl,'tidal_TLATmax_regions(3)');
add_default($nl,'tidal_TLONmin_regions(3)');
add_default($nl,'tidal_TLONmax_regions(3)');
##########################################
# namelist group: vmix_kpp_nml #
##########################################
add_default($nl, 'lcvmix', 'ocn_onedim'=>"$OCN_ONEDIM");
add_default($nl, 'rich_mix&vmix_kpp_nml');
# grid dependent value of lhoriz_varying_background set in
# namelist_defaults_pop.xml and value of ltidal-mixing is
# obtained from default value already set
my $ltidal_mixing = $nl->get_value('ltidal_mixing');
$ltidal_mixing =~ s/ //g;
add_default($nl, 'lhoriz_varying_bckgrnd', 'ocn_onedim'=>"$OCN_ONEDIM");
my $lhoriz_varying_bckgrnd= $nl->get_value('lhoriz_varying_bckgrnd');
$lhoriz_varying_bckgrnd =~ s/ //g;
add_default($nl, 'linertial');
add_default($nl, 'Prandtl');
add_default($nl, 'lrich');
add_default($nl, 'ldbl_diff');
add_default($nl, 'lshort_wave');
add_default($nl, 'lcheckekmo');
add_default($nl, 'larctic_bckgrnd_vdc');
add_default($nl, 'num_v_smooth_Ri');
add_default($nl, 'bckgrnd_vdc1', 'lhoriz_varying_bckgrnd'=>"$lhoriz_varying_bckgrnd", 'ltidal_mixing'=>"$ltidal_mixing");
add_default($nl, 'bckgrnd_vdc2', 'lhoriz_varying_bckgrnd'=>"$lhoriz_varying_bckgrnd", 'ltidal_mixing'=>"$ltidal_mixing");
add_default($nl, 'bckgrnd_vdc_dpth', 'lhoriz_varying_bckgrnd'=>"$lhoriz_varying_bckgrnd", 'ltidal_mixing'=>"$ltidal_mixing");
add_default($nl, 'bckgrnd_vdc_eq', 'lhoriz_varying_bckgrnd'=>"$lhoriz_varying_bckgrnd", 'ltidal_mixing'=>"$ltidal_mixing");
add_default($nl, 'bckgrnd_vdc_psim', 'lhoriz_varying_bckgrnd'=>"$lhoriz_varying_bckgrnd", 'ltidal_mixing'=>"$ltidal_mixing");
add_default($nl, 'bckgrnd_vdc_ban', 'lhoriz_varying_bckgrnd'=>"$lhoriz_varying_bckgrnd", 'ltidal_mixing'=>"$ltidal_mixing");
add_default($nl, 'bckgrnd_vdc_linv');
# QL, 150526, langmuir_opt
add_default($nl, 'langmuir_opt');
##########################################
# namelist group: advect_nml #
##########################################
add_default($nl, 'tadvect_ctype');
##########################################
# namelist group: hmix_nml #
##########################################
add_default($nl, 'hmix_momentum_choice');
add_default($nl, 'hmix_tracer_choice');
add_default($nl, 'lsubmesoscale_mixing');
##########################################
# namelist group: hmix_del2u_nml #
##########################################
add_default($nl, 'lauto_hmix&hmix_del2u_nml');
add_default($nl, 'lvariable_hmix&hmix_del2u_nml');
add_default($nl, 'am&hmix_del2u_nml');
##########################################
# namelist group: hmix_del2t_nml #
##########################################
add_default($nl, 'lauto_hmix&hmix_del2t_nml');
add_default($nl, 'lvariable_hmix&hmix_del2t_nml');
add_default($nl, 'ah&hmix_del2t_nml');
##########################################
# namelist group: hmix_del4u_nml #
##########################################
add_default($nl, 'lauto_hmix&hmix_del4u_nml');
add_default($nl, 'lvariable_hmix&hmix_del4u_nml');
add_default($nl, 'am&hmix_del4u_nml');
##########################################
# namelist group: hmix_del4t_nml #
##########################################
add_default($nl, 'lauto_hmix&hmix_del4t_nml');
add_default($nl, 'lvariable_hmix&hmix_del4t_nml');
add_default($nl, 'ah&hmix_del4t_nml');
##########################################
# namelist group: hmix_gm_nml #
##########################################
add_default($nl, 'kappa_isop_choice');
add_default($nl, 'kappa_thic_choice');
add_default($nl, 'kappa_isop_deep');
add_default($nl, 'kappa_thic_deep');
# All namelist values are stored in exactly the format
# that is required in a valid namelist. So if that value
# is a string, then the quotes are stored as part of the value.
my $kappa_isop_choice = $nl->get_value('kappa_isop_choice');
my $kappa_thic_choice = $nl->get_value('kappa_thic_choice');
$kappa_isop_choice =~ s/[\'\"]//g;
$kappa_thic_choice =~ s/[\'\"]//g;
# note that ah_gm_value is explicitly put below since ah is
# contained in several namelist variables
add_default($nl, 'ah_bolus' ,
'kappa_isop_choice'=>"$kappa_isop_choice",
'kappa_thic_choice'=>"$kappa_thic_choice");
add_default($nl, 'ah_bkg_srfbl',
'kappa_isop_choice'=>"$kappa_isop_choice",
'kappa_thic_choice'=>"$kappa_thic_choice");
add_default($nl, 'use_const_ah_bkg_srfbl',
'kappa_isop_choice'=>"$kappa_isop_choice",
'kappa_thic_choice'=>"$kappa_thic_choice");
add_default($nl, 'ah&hmix_gm_nml',
'kappa_isop_choice'=>"$kappa_isop_choice",
'kappa_thic_choice'=>"$kappa_thic_choice");
# note that ocn_grid dependence for ah_bolus, ah_bkg_srfbl
# is obtained from config_cache.xml
add_default($nl, 'buoyancy_freq_filename', 'val'=>"${RUNDIR}/buoyancy_freq");
add_default($nl, 'diag_gm_bolus','ocn_onedim'=>"$OCN_ONEDIM");
add_default($nl, 'kappa_freq_choice');
add_default($nl, 'slope_control_choice');
add_default($nl, 'kappa_depth_1');
add_default($nl, 'kappa_depth_2');
add_default($nl, 'kappa_depth_scale');
add_default($nl, 'ah_bkg_bottom');
add_default($nl, 'slm_r');
add_default($nl, 'slm_b');
add_default($nl, 'transition_layer_on');
add_default($nl, 'read_n2_data');
add_default($nl, 'buoyancy_freq_fmt');
add_default($nl, 'const_eg');
add_default($nl, 'gamma_eg');
add_default($nl, 'kappa_min_eg');
add_default($nl, 'kappa_max_eg');
##########################################
# namelist group: hmix_gm_aniso_nml #
##########################################
add_default($nl, 'kdir_type_choice');
add_default($nl, 'krat_type_choice');
add_default($nl, 'kmin_type_choice');
# All namelist values are stored in exactly the format
# that is required in a valid namelist. So if that value
# is a string, then the quotes are stored as part of the value.
my $kdir_type_choice = $nl->get_value('kdir_type_choice');
my $krat_type_choice = $nl->get_value('krat_type_choice');
my $kmin_type_choice = $nl->get_value('kmin_type_choice');
$kdir_type_choice =~ s/[\'\"]//g;
$krat_type_choice =~ s/[\'\"]//g;
$kmin_type_choice =~ s/[\'\"]//g;
add_default($nl, 'efficiency_factor');
add_default($nl, 'addrandfluc');
add_default($nl, 'cflmajoronly');
add_default($nl, 'cflmult');
add_default($nl, 'erat_const');
add_default($nl, 'erat_factor');
add_default($nl, 'isominoronly');
add_default($nl, 'isoonly');
add_default($nl, 'kdir_type_choice');
add_default($nl, 'kmin_type_choice');
add_default($nl, 'krat_type_choice');
add_default($nl, 'minorfactor');