Skip to content

Commit

Permalink
clm4_5_16_r259
Browse files Browse the repository at this point in the history
Update CLM to use version 3 for config_components.xml which has additional error checking of compset names. Also
update it for mosart, cism and rtm. And cime is updated to the version used in cesm2_0_beta07. There are a few
new features brought in with the latest cime that are described below. CLM now requires one and only one modifier
for what type it is in the compset name (i.e. only one "%" as in CLM45%BGC or CLM50%SP). Will now abort when
CLM build-namelist encounters a warning (after printing information on all warnings). To ignore the warnings
and continue add the new "-ignore_warnings" to CLM_BLDNML_OPTS. "-irrig" is now an option to CLM_BLDNML_OPTS
only for clm4_0, set "irrigate" namelist item in your user_nl_clm file for clm4_5 or clm5_0. By default build-namelist
sets irrigate to true for transient or present-day configurations if crop is on and clm5_0 (unless DV on). Get PTCLMmkdata fully
converted over to cheyenne, and create a new set of files for testing it's ability to create cases. Checking for
.true. or .false. in CLM build-namelist is now more robust and allows for "F" or "T" as newer FORTRAN versions do.

Fix several bugs as described below. PTCLM and CLM tools were both verified to work and pass testing.
The PE layout for f10 on hobart was changed to a single-node so that it would compare exactly to previous versions.
Fix a bug for NCK tests in RTM and MOSART. Get mksurfdata_map working correctly for f05. Error message when
you set finidat=' ' is more clear on what to do. You can also now do a cold-start for a hybrid case prints a warning),
but not allowed on a branch case.
  • Loading branch information
ekluzek authored and bjandre committed Dec 20, 2017
1 parent ace51ec commit ac3c1a1
Show file tree
Hide file tree
Showing 47 changed files with 1,484 additions and 873 deletions.
2 changes: 1 addition & 1 deletion SVN_EXTERNAL_DIRECTORIES
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
src/fates https://github.com/NCAR/fates-release/tags/fates_s1.0.0_a1.0.0
tools/PTCLM https://svn-ccsm-models.cgd.ucar.edu/PTCLM/trunk_tags/PTCLM2_170706
tools/PTCLM https://svn-ccsm-models.cgd.ucar.edu/PTCLM/trunk_tags/PTCLM2_171016d
10 changes: 5 additions & 5 deletions SVN_EXTERNAL_DIRECTORIES.standalone
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cime https://github.com/CESM-Development/cime/tags/mvertens/updates_for_clm.tag2
components/clm/tools/gen_domain https://github.com/CESM-Development/cime/tags/mvertens/updates_for_clm.tag2/tools/mapping/gen_domain_files
components/cism https://svn-ccsm-models.cgd.ucar.edu/glc/trunk_tags/cism2_1_37
components/rtm https://svn-ccsm-models.cgd.ucar.edu/rivrtm/trunk_tags/rtm1_0_62
components/mosart https://svn-ccsm-models.cgd.ucar.edu/mosart/branch_tags/rlen_min_tags/rlen_min_n01_mosart1_0_26
cime https://github.com/CESM-Development/cime/tags/cime5.4.0-alpha.03
components/clm/tools/gen_domain https://github.com/CESM-Development/cime/tags/cime5.4.0-alpha.03/tools/mapping/gen_domain_files
components/cism https://svn-ccsm-models.cgd.ucar.edu/glc/trunk_tags/cism2_1_40
components/rtm https://svn-ccsm-models.cgd.ucar.edu/rivrtm/trunk_tags/rtm1_0_63
components/mosart https://svn-ccsm-models.cgd.ucar.edu/mosart/trunk_tags/mosart1_0_28
1,334 changes: 643 additions & 691 deletions bld/CLMBuildNamelist.pm

Large diffs are not rendered by default.

244 changes: 244 additions & 0 deletions bld/namelist_files/LogMessages.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
package namelist_files::LogMessages;
my $pkg_nm = 'namelist_files::LogMessages';
#-----------------------------------------------------------------------------------------------
#
# SYNOPSIS
#
# require namelist_files::LogMessages;
#
# my %opts;
# my $log = namelist_files::LogMessages->new("ProgName", \%opts);
# $log->message("message to print");
# $log->verbose_message("message to print only if verbose mode is on");
# $log->warning("Warning message");
# $log->exit_message("clean exit");
# $log->fatal_error("die with fatal error");
# $log->final_exit("Final message to send (and exit");
#
#
# DESCRIPTION
#
# Handles log messages for perl. Sets up log messages according to verbose
# or silent setting. It also handles warnings printing them, but on finalization
# aborting unless ignore_warnings was set.
#
# COLLABORATORS: None
#
#-----------------------------------------------------------------------------------------------
#
# Date Author Modification
# 10/06/2017 Erik Kluzek creation
#
#--------------------------------------------------------------------------------------------

use strict;
#use warnings;
#use diagnostics;

#-------------------------------------------------------------------------------

sub new {
my $class = shift;
my $ProgName = shift;
my %opts = %{shift()};

my $nm = "$class\:\:new";
my $self = {};
bless($self, $class);
$self->{'nwarns'} = 0;
$self->{'verbosity'} = 1;
$self->{'NO_EXIT'} = $opts{'NO_EXIT'};
$self->{'ProgName'} = $ProgName;
$self->{'ignore_warnings'} = $opts{'ignore_warnings'};
$self->__set_print_level( \%opts );
return( $self );
}


#-------------------------------------------------------------------------------

sub __set_print_level {
my $self = shift;
# Define print levels:
# 0 - only issue fatal error messages
# 1 - only informs what files are created (default)
# 2 - verbose
my %opts = %{shift()};

if ( $opts{'silent'} && $opts{'verbose'} ) {
$self->fatal_error( "Can not set both the -silent and the -verbose options -- set one or the other" );
}
my $verbosity = 1;
if ($opts{'silent'}) { $verbosity = 0; }
if ($opts{'verbose'}) { $verbosity = 2; }
$self->{'verbosity'} = $verbosity;
$self->{'print_verbose'} = 2;
}

#-------------------------------------------------------------------------------

sub message {
my $self = shift;
my ($message) = @_;
if ($self->{'verbosity'} > 0) {
print "$message\n";
}
}

#-------------------------------------------------------------------------------

sub verbose_message {
my $self = shift;

my ($message) = @_;
if ($self->{'verbosity'} >= $self->{'print_verbose'}) {
print "$message\n";
}
}
#-------------------------------------------------------------------------------

sub nwarns {
my $self = shift;

return( $self->{'nwarns'} );
}

#-------------------------------------------------------------------------------

sub final_exit {
my $self = shift;
my ($message) = @_;
if ( $self->{'nwarns'} > 0 ) {
$self->message( "\n\nYou ran with the -ignore_warnings options and allowed $self->{'nwarns'} to go past\n" );
}
$self->verbose_message( $message );
if ( $self->{'NO_EXIT'} ) {
die
} else {
exit;
}
}

#-------------------------------------------------------------------------------
# Some simple subroutines to do a clean exit, print warning, or a fatal error

sub exit_message {
my $self = shift;
my ($message) = @_;
print "$self->{ProgName} : $message\n";
if ( $self->{'NO_EXIT'} ) {
die
} else {
exit;
}
}

#-------------------------------------------------------------------------------

sub warning {
my $self = shift;
my $message = shift;

$self->{'nwarns'} = $self->{'nwarns'} + 1;
my $func_name = (caller(1))[3];
if ( $self->{'ignore_warnings'} ) {
print "Warning : $self->{ProgName}::${func_name}() : $message\n\n";
} else {
die "Warning : $self->{ProgName}::${func_name}() : $message\n" .
" -- Add -ignore_warnings option to CLM_BLDNML_OPTS to ignore this warning\n\n";
}
}

#-------------------------------------------------------------------------------

sub fatal_error {
my $self = shift;
my ($message) = @_;
my $func_name = (caller(1))[3];
die "ERROR : $self->{ProgName}::${func_name}() : $message\n";
}

#-------------------------------------------------------------------------------

#-----------------------------------------------------------------------------------------------
# Unit testing of above
#-----------------------------------------------------------------------------------------------
if ( ! defined(caller) && $#ARGV == -1 ) {
package LogMessage_unit_tester;

require Test::More;
Test::More->import( );

plan( tests=>11 );

sub testit {
print "unit tester\n";
my %opts;
my $message;

# Standard verbose level, test all methods
$opts{'NO_EXIT'} = 1;
my $log = namelist_files::LogMessages->new("ProgName", \%opts);
isa_ok($log, "namelist_files::LogMessages", "Created LogMessages object");
$log->message("message to print");
$log->verbose_message("YOU SHOULD NOT SEE THIS MESSAGE BECAUSE IT IS VERBOSE AND VERBOSE NOT ON");
$message = "Warning message";
is ( $log->nwarns(), 0, "Make sure have zero warnings" );
eval{ $log->warning($message); };
like( $@, qr/$message/, "check that a warning dies without ignore_warnings option" );
is ( $log->nwarns(), 1, "Make sure have one warning" );
$message = "die with fatal error";
eval{ $log->fatal_error($message); };
like( $@, qr/$message/, "check that a fatal_error dies" );
$message = "exit with exit message";
eval{ $log->exit_message($message); };
like( $@, qr/Died/, "check that a exit_message exits" );
$message = "Final message to send";
eval{ $log->final_exit($message); };
like( $@, qr/Died/, "check that a final exits" );

# Test ignore_warnings option and verbose mode
$opts{'ignore_warnings'} = 1;
$opts{'verbose'} = 1;
$opts{'NO_EXIT'} = 1;
$log = namelist_files::LogMessages->new("ProgName", \%opts);
isa_ok($log, "namelist_files::LogMessages", "Created LogMessages object");
$log->verbose_message("message to print only if verbose mode is on");
$log->warning("Warning message");
$log->warning("Warning message2");
$log->warning("Warning message3");
$log->warning("Warning message4");
$log->warning("Warning message5");
is ( $log->nwarns(), 5, "Make sure have five warnings" );
eval{ $log->final_exit($message); };
print "content: $@\n";
like( $@, qr/Died/, "check that a final_exit with warning exits" );
# silent mode
$opts{'ignore_warnings'} = 0;
$opts{'verbose'} = 0;
$opts{'silent'} = 1;
$opts{'NO_EXIT'} = 1;
$log = namelist_files::LogMessages->new("ProgName", \%opts);
$log->message("YOU SHOULD NOT SEE THIS MESSAGE BECAUSE SILENT MODE IS ON");
$log->verbose_message("YOU SHOULD NOT SEE THIS VERBOSE MESSAGE BECAUSE SILENT MODE IS ON");
# Should die with error if both silent and verbose mode is on
$opts{'ignore_warnings'} = 0;
$opts{'verbose'} = 1;
$opts{'silent'} = 1;
$opts{'NO_EXIT'} = 1;
eval{ $log = namelist_files::LogMessages->new("ProgName", \%opts); };
print "content: $@\n";
like( $@, qr/ERROR : /, "check that died if both verbose and silent mode is on" );
print "\nSuccessfully ran all tests\n";
}
}

#-----------------------------------------------------------------------------------------------
# Determine if you should run the unit test or if this is being called from a require statement
#-----------------------------------------------------------------------------------------------

if ( defined(caller) ) {
1 # to make use or require happy
} elsif ( $#ARGV == -1 ) {
&LogMessage_unit_tester::testit();
}
Loading

0 comments on commit ac3c1a1

Please sign in to comment.