⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cam_config.pm

📁 CCSM Research Tools: Community Atmosphere Model (CAM)
💻 PM
字号:
#-----------------------------------------------------------------------------------------------## CAM_config.pm## Object to read in configure config_cache.xml # configuration files.## Methods:## new ---------------- Constructor# read_config_cache -- Read in the config_cache.xml file.# exists ------------- Check if a configuration name exists# setcfg ------------- Set configuration value# unsetcfg ----------- unset configuration value# cfg ---------------- Return configuration value## Date        Author                  Modification# ---------------------------------------------------------------------------# 23.Apr.2002 Erik Kluzek             Original version#-----------------------------------------------------------------------------------------------package CAM_config;use strict;#use warnings;#use diagnostics;use XML::Lite;sub new {## Constructor#  my $class = shift;  my $self = {};  my @cfg_vars = (         "CAMROOT",         # CAM root location         "MODEL_BLDDIR",    # Model build location         "MODEL_EXEDIR",    # Model execution location         "MODEL_CFGDIR",    # Model configuration/build location         "EXENAME",         # Executable name         "MODEL_MODDIR",    # Directory with modified code         "COUP_CSM",        # If running coupled or not         "DYNAMICS",        # Dynamics to use         "ICEMODEL",        # Sea-Ice model to use         "PHYSICS",         # Physics directory to use         "LANDMODEL",       # Land-model to use         "OCEANMODEL",      # Ocean-model to use         "PERGRO",          # Error growth option         "RESOLUTION",      # Horizontal resolution         "PLON",            # No. of longitudes         "PLAT",            # No. of latitudes         "PLEV",            # No. of vertical levels         "PCNST",           # No. of advected constituents         "PNATS",           # No. of non-advected constituents         "PTRM",            # M truncation         "PTRN",            # N truncation         "PTRK",            # K truncation         "DEBUG",           # Compiler debug setting         "SPMD",            # SPMD mode         "INC_NETCDF",      # NetCDF include         "LIB_NETCDF",      # NetCDF library         "INC_MPI",         # MPI include         "LIB_MPI"          # MPI library  );  $self->{CFG_LIST} = \@cfg_vars;  foreach my $cfg ( @cfg_vars ) {    $self->{$cfg} = undef;  }  bless( $self, $class );}sub read_config_cache {## Read in the config_cache.xml file#  my $self = shift;  my $file = shift;  if ( ! defined($file) ) {    die "ERROR:: Configuration cache file not given to read_config_cache\n";  }  if ( ! -f "$file" ) {    die "ERROR:: Configuration cache file: $file does not exist!";  }  my $xml = XML::Lite->new( $file );  my $root = $xml->root_element();  my $class = ref($self);  # Check for valid root node  my $name = $root->get_name();  $name eq "config_bld" or die  "file $file is not a CAM configuration file\n";  # Get source and build directories  my $dirs = $xml->elements_by_name( "directories" );  my %dirs = $dirs->get_attributes();  my @list = ( "cam_root", "cam_bld", "cam_exedir", "usr_src" );  foreach my $item ( @list ) {    if ( ! defined($dirs{$item}) ) {      die ref($class) . " ERROR:: $item not included in directories element in $file\n";    }  }  $self->setcfg("CAMROOT",       $dirs{cam_root}."/" );  $self->setcfg("MODEL_BLDDIR",  $dirs{cam_bld}."/" );  $self->setcfg("MODEL_EXEDIR",  $dirs{cam_exedir}."/" );  $self->setcfg("MODEL_CFGDIR",  $dirs{cam_root}."/models/atm/cam/bld/" );  $self->setcfg("MODEL_MODDIR",  $dirs{usr_src} );  # Get packages  my $pkgs = $xml->elements_by_name( "packages" );  my %pkgs = $pkgs->get_attributes();  my @list = ( "dyn", "phys", "lnd", "ocn", "pergro" );  foreach my $item ( @list ) {    if ( ! defined($pkgs{$item}) ) {      die ref($class) . " ERROR:: $item not included in packages element in $file\n";    }  }  $self->setcfg("COUP_CSM",    "FALSE" );  $self->setcfg("DYNAMICS",    $pkgs{dyn} );  $self->setcfg("PHYSICS",     $pkgs{phys} );  $self->setcfg("LANDMODEL",   $pkgs{lnd} );  $self->setcfg("ICEMODEL",    $pkgs{sice} );  $self->setcfg("OCEANMODEL",  $pkgs{ocn} );  if ( $pkgs{pergro} ) {    $self->setcfg("PERGRO",  "TRUE" );  } else {    $self->setcfg("PERGRO",  "FALSE" );  }  # Get resolution parameters  my $resparms = $xml->elements_by_name( "resolution" );  my %resparms = $resparms->get_attributes();  my @list = ( "res", "nlon", "nlat", "nlev", "nadv", "nnadv", "trm", "trn", "trk" );  foreach my $item ( @list ) {    if ( ! defined($resparms{$item}) ) {      die ref($class) . " ERROR:: $item not included in resolution element in $file\n";    }  }  $self->setcfg("RESOLUTION",  $resparms{res} );  $self->setcfg("PLON",        $resparms{nlon} );  $self->setcfg("PLAT",        $resparms{nlat} );  $self->setcfg("PLEV",        $resparms{nlev} );  $self->setcfg("PCNST",       $resparms{nadv} );  $self->setcfg("PNATS",       $resparms{nnadv} );  $self->setcfg("PTRM",        $resparms{trm} );  $self->setcfg("PTRN",        $resparms{trn} );  $self->setcfg("PTRK",        $resparms{trk} );  # Get settings for Makefile (parallelism and library locations)  my $make = $xml->elements_by_name( "makefile" );  my %make = $make->get_attributes();  my @list = ( 'cam_exe', "debug", "spmd", "nc_inc", "nc_lib", "mpi_inc", "mpi_lib" );  foreach my $item ( @list ) {    if ( ! defined($make{$item}) ) {      die ref($class) . " ERROR:: $item not included in makefile element in $file\n";    }  }  if ( $make{debug} ) {    $self->setcfg("DEBUG",  "TRUE" );  } else {    $self->setcfg("DEBUG",  "FALSE" );  }  if ( $make{spmd} ) {    $self->setcfg("SPMD",  "TRUE" );  } else {    $self->setcfg("SPMD",  "FALSE" );  }  $self->setcfg("EXENAME",     $make{cam_exe} );  $self->setcfg("INC_NETCDF",  $make{nc_inc} );  $self->setcfg("LIB_NETCDF",  $make{nc_lib} );  $self->setcfg("INC_MPI",     $make{mpi_inc} );  $self->setcfg("LIB_MPI",     $make{mpi_lib} );}sub exists {## Check if the given cfg variable is defined here#  my $self = shift;  my $cfg = shift;  if ( ! defined($cfg) ) {    print "ERROR:: Configuration variable not given to exists method\n";  }  my $list = $self->{'CFG_LIST'};  my @list = @$list;  # Make sure this config var defined in list  my $found = 0;  foreach my $item ( @list ) {    if ( $item eq $cfg ) { $found = 1; last; }  }  return( $found );}sub setcfg {## Set a given cfg value setting#  my $self = shift;  my $cfg = shift;  my $value = shift;  if ( defined($cfg) ) {    if ( ! $self->exists($cfg) ) {      die ref($self) . "::ERROR:: config variable $cfg not found in this class.\n";    }    if ( defined($value) ) {      $self->{$cfg} = $value;    } else {      die ref($self) . "::ERROR:: value not passed into setcfg method for $cfg\n";    }  } else {    die ref($self) . "::ERROR:: config variable not passed into setcfg method\n";  }}sub unsetcfg {## un-Set a given cfg value setting#  my $self = shift;  my $cfg = shift;  if ( defined($cfg) ) {    if ( ! $self->exists($cfg) ) {      die ref($self) . "::ERROR:: config variable $cfg not found in this class.\n";    }    $self->{$cfg} = undef;  } else {    die ref($self) . "::ERROR:: config variable not passed into setcfg method\n";  }}sub cfg {## Get the value of a given cfg variable#  my $self = shift;  my $cfg = shift;  if ( defined($cfg) ) {    if ( ! $self->exists($cfg) ) {      die \ref($self) . "::ERROR:: config variable $cfg not found in this class.\n";    }    my $value = $self->{$cfg};    return( $value );  } else {    die \ref($self) . "::ERROR:: config variable not passed into this method\n";  }}1 # to make use or require happy

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -