From cecf5d9b3b3d75991fe6ca6fad8c4c7e08b913fb Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Thu, 16 Nov 2023 00:03:41 -0700 Subject: [PATCH] Remove scripts no longer needed with mksurfdata_esmf, and README documentation for it, resolves #2180 --- bld/README | 17 -- bld/listDefaultNamelist.pl | 349 ------------------------ bld/namelist_files/checkmapfiles.ncl | 236 ---------------- bld/namelist_files/createMapEntry.pl | 73 ----- bld/namelist_files/createMkSrfEntry.py | 56 ---- bld/queryDefaultNamelist.pl | 315 --------------------- bld/queryDefaultXML.pm | 161 ----------- tools/README | 3 +- tools/ncl_scripts/README | 15 - tools/ncl_scripts/getco2_historical.ncl | 196 ------------- 10 files changed, 1 insertion(+), 1420 deletions(-) delete mode 100755 bld/listDefaultNamelist.pl delete mode 100644 bld/namelist_files/checkmapfiles.ncl delete mode 100755 bld/namelist_files/createMapEntry.pl delete mode 100755 bld/namelist_files/createMkSrfEntry.py delete mode 100755 bld/queryDefaultNamelist.pl delete mode 100644 bld/queryDefaultXML.pm delete mode 100644 tools/ncl_scripts/README delete mode 100644 tools/ncl_scripts/getco2_historical.ncl diff --git a/bld/README b/bld/README index 71c663c268..ca87566ced 100644 --- a/bld/README +++ b/bld/README @@ -19,21 +19,6 @@ build-namelist --- Build the namelists needed env_run.xml --- Sample case runtime environment variables, so build-namelist can run outside of a case directory. ---------- Scripts to query namelist defaults -listDefaultNamelist.pl -- List the files needed, for a list of resolutions, - to run CLM that are currently NOT on your machine. - This file can then be used by - cime/CIME/Tools/check_input_data - to retreive them from the inputdata repository. - Setting up cases with create_newcase also does - this -- but only for the exact configuration - given. This tries to get all the files need - for several different resolutions and configurations - at once. -queryDefaultNamelist.pl - Query default namelist for settings of variables -queryDefaultXML.pm ------ Subroutines needed by queryDefaultNamelist.pl script - - --------- Test scripts directory unit_testers --- Directory of scripts to test scipts in this directory (most notably build-namelist) @@ -59,7 +44,5 @@ namelist_files/namelist_definition_drv_flds.xml --- Definition of add driver fie ---------- XML helper files namelist_files/LogMessages.pm ---- Perl module to handle log output -namelist_files/checkmapfiles.ncl -- NCL script to check that all of the mapping files are valid -namelist_files/createMapEntry.pl -- Perl script to create a map entry for the namelist_files/history_fields.xsl - Style sheet for history fields as created by script that lists all of the history fields from the source files (../src/main/findHistFields.pl) diff --git a/bld/listDefaultNamelist.pl b/bld/listDefaultNamelist.pl deleted file mode 100755 index a05618523f..0000000000 --- a/bld/listDefaultNamelist.pl +++ /dev/null @@ -1,349 +0,0 @@ -#!/usr/bin/env perl -#======================================================================= -# -# This is a script to list the missing files in your CESM inputdata area -# for a list of resolutions and model configurations. The list goes -# out to the file: clm.input_data_list. The check_input_data script -# can then be used to get this list of files from the SVN inputdata -# repository. -# -# Usage: -# -# listDefaultNamelist.pl [options] -# -# To get help on options and usage: -# -# listDefaultNamelist.pl -help -# -# To then get the files from the CESM SVN repository: -# -# ../cime/CIME/Tools/check_input_data --data-list-dir . --download -# -#======================================================================= - -use strict; -use Cwd qw(getcwd abs_path); -use Getopt::Long; -use English; -#use diagnostics; - -#----------------------------------------------------------------------------------------------- - -my $ProgName; -($ProgName = $PROGRAM_NAME) =~ s!(.*)/!!; # name of program -my $ProgDir = $1; # name of directory where program lives - -my $cwd = getcwd(); # current working directory -my $cfgdir; - -my $printTimes = 0; - -if ($ProgDir) { $cfgdir = $ProgDir; } -else { $cfgdir = $cwd; } - -#----------------------------------------------------------------------------------------------- -# Add $cfgdir to the list of paths that Perl searches for modules - -my @dirs = ( "$cfgdir", "../cime/utils/perl5lib" ); -unshift @INC, @dirs; - -require queryDefaultXML; - -# Defaults -my $cesmroot = abs_path( "$cfgdir/../"); - -# The namelist defaults file contains default values for all required namelist variables. -my @nl_defaults_files = ( "$cfgdir/namelist_files/namelist_defaults_overall.xml", - "$cfgdir/namelist_files/namelist_defaults_drv.xml", - ); -my $list = "clm.input_data_list"; -my %list_of_all_files; - -sub usage { - die <new($config_cachefile, '>') or die "can't open file: $config_cachefile"; - print $fh < - - -Specifies clm physics - -EOF - $fh->close(); -} - -#----------------------------------------------------------------------------------------------- - -sub GetListofNeededFiles { -# -# Get list of files that are needed to be copied to disk from the XML file. -# - my $inputopts_ref = shift; - my $settings_ref = shift; - my $files_ref = shift; - - my $defaults_ref = &queryDefaultXML::ReadDefaultXMLFile( $inputopts_ref, $settings_ref ); - my @keys = keys(%$defaults_ref); - my $csmdata = $$inputopts_ref{'csmdata'}; - my $printing = $$inputopts_ref{'printing'}; - foreach my $var ( @keys ) { - my $value = $$defaults_ref{$var}{'value'}; - my $isafile = $$defaults_ref{$var}{'isfile'}; - # If is a file - if ( $isafile ) { - $value =~ m#$csmdata/(.+?)/([^/]+)$#; - my $dir = $1; - my $file = $2; - - # If file is already in the list then do NOT do anything - if ( defined($list_of_all_files{"$dir/$file"} ) ) { - # Test that this file exists - } elsif ( -f "$value" ) { - print "File $value exists\n" if $printing; - $list_of_all_files{"$dir/$file"} = 1; - } else { - # If doesn't exist add it to the list of files to copy - my $cfile = $$inputopts_ref{'scpfrom'} . "$dir/$file"; - my @dfiles; - if ( defined($$files_ref{$dir}) ) { - my $dir_ref = $$files_ref{$dir}; - @dfiles = @$dir_ref; - my $match = 0; - foreach my $i ( @dfiles ) { - if ( $i eq $cfile ) { $match = 1; } - } - if ( $match == 0 ) { push( @dfiles, $cfile ); } - } else { - @dfiles = ( "$cfile" ); - } - if ( ! defined($$files_ref{$dir}) ) { - print " ADD $cfile to list to copy\n"; - } - $$files_ref{$dir} = \@dfiles; - $list_of_all_files{"$dir/$file"} = 0; - } - } - } - $printTimes++; -} - -#----------------------------------------------------------------------------------------------- - - my %opts = ( - res => undef, - silent => undef, - csmdata => "default", - list => $list, - usrdat => undef, - help => undef, - ); - - my $cmdline = "@ARGV"; - GetOptions( - "d|csmdata=s" => \$opts{'csmdata'}, - "r|res=s" => \$opts{'res'}, - "s|silent" => \$opts{'silent'}, - "u|usrdat=s" => \$opts{'usrdat'}, - "h|elp" => \$opts{'help'}, - ) or usage(); - - # Check for unparsed arguments - if (@ARGV) { - print "ERROR: unrecognized arguments: @ARGV\n"; - usage(); - } - if ( $opts{'help'} ) { - usage(); - } - # Set if should do extra printing or not (if silent mode is not set) - my $printing = 1; - if ( defined($opts{'silent'}) ) { - $printing = 0; - } - # - # Check for required arguments - # - foreach my $req ( "res", "list" ) { - if ( ! defined($opts{$req}) ) { - print "ERROR: $req NOT set and it is a required argument\n"; - usage(); - } - } - my %inputopts; - my @nl_definition_files = ( - "$cfgdir/namelist_files/namelist_definition_ctsm.xml" - ); - $inputopts{'nldef_files'} = \@nl_definition_files; - $inputopts{'empty_cfg_file'} = "config_cache.xml"; - - my $definition = Build::NamelistDefinition->new( $nl_definition_files[0] ); - foreach my $nl_defin_file ( @nl_definition_files ) { - $definition->add( "$nl_defin_file" ); - } - # Resolutions... - my @resolutions; - if ( $opts{'res'} eq "all" ) { - @resolutions = $definition->get_valid_values( "res", 'noquotes'=>1 ); - } else { - @resolutions = split( /,/, $opts{'res'} ); - } - - # Input options - &make_config_cache( "clm5_0", $inputopts{'empty_cfg_file'} ); - push @nl_defaults_files, "$cfgdir/namelist_files/namelist_defaults_ctsm.xml"; - if ( defined($opts{'usrdat'}) ) { - push @nl_defaults_files, "$cfgdir/namelist_files/namelist_defaults_usr_files.xml"; - } - $inputopts{'files'} = \@nl_defaults_files; - $inputopts{'printing'} = $printing; - $inputopts{'ProgName'} = $ProgName; - $inputopts{'cmdline'} = $cmdline; - $inputopts{'cfgdir'} = $cfgdir; - if ( $opts{'csmdata'} eq "default" && $ENV{'CSMDATA'} ne "" ) { - $opts{'csmdata'} = $ENV{'CSMDATA'}; - } - $inputopts{'csmdata'} = $opts{'csmdata'}; - $inputopts{'config'} = "noconfig"; - my %files; - # - # Loop over all resolutions asked for: 1.9x2.5, 10x15, 64x128 etc. - # - foreach my $res ( @resolutions ) { - if ( ! $definition->is_valid_value( "res", "'$res'" ) && $res ne $opts{'usrdat'} ) { - die "ERROR: Input resolution: $res is NOT a valid resolution\n"; - } - $inputopts{'hgrid'} = $res; - print "Resolution = $res\n" if $printing; - my %settings; - if ( $res eq $opts{'usrdat'} ) { - $settings{'clm_usr_name'} = $opts{'usrdat'}; - $settings{'csmdata'} = $opts{'csmdata'}; - $settings{'notest'} = 1; - } - # - # Loop for all possible land masks: USGS, gx1v6, gx3v5 etc. - # - foreach my $mask ( $definition->get_valid_values( "mask", 'noquotes'=>1 ) ) { - print "Mask = $mask \n" if $printing; - $settings{'mask'} = $mask; - # - # Loop over all possible simulation year: 1890, 2000, 2100 etc. - # - $settings{'sim_year_range'} = "constant"; - my @ssp_rcps = $definition->get_valid_values( "ssp_rcp", 'noquotes'=>1 ); - $settings{'ssp_rcp'} = $ssp_rcps[0]; -YEAR: foreach my $sim_year ( $definition->get_valid_values( "sim_year", 'noquotes'=>1 ) ) { - print "sim_year = $sim_year\n" if $printing; - $settings{'sim_year'} = $sim_year; - if ( $sim_year ne 1850 && $sim_year ne 2000 && $sim_year > 1800 ) { next YEAR; } - - my @bgcsettings = $definition->get_valid_values( "bgc_mode", 'noquotes'=>1 ); - print "bgc=@bgcsettings\n" if $printing; - # - # Loop over all possible BGC settings - # - foreach my $bgc ( @bgcsettings ) { - $settings{'bgc'} = $bgc; - my @crop_vals; - if ( $bgc =~ /^cn/ ) { - @crop_vals = ( "on", "off" ); - } else { - @crop_vals = ( "off" ); - } - $settings{'glc_nec'} = 10; - # - # Loop over all possible crop settings - # - foreach my $crop ( @crop_vals ) { - $settings{'crop'} = $crop; - if ( $crop eq "on" ) { - $settings{'maxpft'} = 78; - } else { - $settings{'maxpft'} = 17; - } - $inputopts{'namelist'} = "clm_inparm"; - &GetListofNeededFiles( \%inputopts, \%settings, \%files ); - if ( $printTimes >= 1 ) { - $inputopts{'printing'} = 0; - } - } - } - } - # - # Now do sim-year ranges - # - $settings{'bgc'} = "cn"; - $inputopts{'namelist'} = "clm_inparm"; - foreach my $sim_year_range ( $definition->get_valid_values( "sim_year_range", 'noquotes'=>1 ) ) { - $settings{'sim_year_range'} = $sim_year_range; - if ( $sim_year_range =~ /([0-9]+)-([0-9]+)/ ) { - $settings{'sim_year'} = $1; - } - # - # Loop over all possible ssp_rcp's - # - print "sim_year_range=$sim_year_range ssp_rcp=@ssp_rcps\n" if $printing; - foreach my $ssp_rcp ( @ssp_rcps ) { - $settings{'ssp_rcp'} = $ssp_rcp; - &GetListofNeededFiles( \%inputopts, \%settings, \%files ); - if ( $printTimes >= 1 ) { - $inputopts{'printing'} = 0; - } - } - } - } - } - # - # Loop over directories that need to have files copied into - # - my $hostname; - my $csmdata = $inputopts{'csmdata'}; - open( OUT, ">$list" ) || die "ERROR: trouble opening output file: $list"; - foreach my $dir ( sort(keys(%files)) ) { - if ( $dir eq "." ) { next; } - if ( $dir eq "/" ) { next; } - if ( $dir eq "\n" ) { next; } - if ( $dir eq "" ) { next; } - if ( ! defined($dir) ) { next; } - my $files_ref = $files{$dir}; - my @files = @$files_ref; - foreach my $file ( @files ) { - if ( $file !~ /\n$/ ) { $file = "$file\n"; } - print OUT "file = \$DIN_LOC_ROOT/$file"; - } - } - close( OUT ); - if ( $printing ) { - print "\n\nSuccessful\n\n" - } diff --git a/bld/namelist_files/checkmapfiles.ncl b/bld/namelist_files/checkmapfiles.ncl deleted file mode 100644 index e37100747a..0000000000 --- a/bld/namelist_files/checkmapfiles.ncl +++ /dev/null @@ -1,236 +0,0 @@ -; -; Check that the *_b values are the same between the mapping files -; at the same output resolution. -; -; Erik Kluzek -; Nov/18/2011 -; $Id$ -; $HeadURL; -; - - print( "Check that datm mapping files are consistent" ); - resolutions = (/ "128x256", "64x128", "48x96", "94x192", "0.23x0.31", "0.47x0.63", "0.9x1.25", "1.9x2.5", "2.5x3.33", "4x5", "10x15", "0.125nldas2", "5x5_amazon", "1x1_vancouverCAN", "1x1_mexicocityMEX", "1x1_asphaltjungleNJ", "1x1_brazil", "1x1_urbanc_alpha", "1x1_numaIA", "1x1_smallvilleIA", "ne4np4", "ne16np4", "ne30np4", "ne60np4", "ne120np4", "ne240np4" /); - - space = " "; - badres = 0 - badresolutions = new( (/ 1000 /), string ) - chkres = 0 - chkresolutions = new( (/ 1000 /), string ) - -procedure checkit( desc:string, maxdiff:numeric, res:string, lmask:string, eps:numeric ) -; -; check that difference is within reasonable tolerance... -; -begin - reso = res+"_"+lmask; - if ( maxdiff .gt. eps )then - print( space+space+space+desc+" are off by more than tolerance for "+reso+" resolution" ); - print( space+space+space+"maximum difference = "+maxdiff ); - if ( .not. any(badresolutions .eq. reso ) )then - badresolutions(badres) = reso; - badres = badres + 1 - end if - else - print( space+space+space+"File OK for "+desc+"!" ); - end if - if ( .not. any(chkresolutions .eq. reso ) )then - chkresolutions(chkres) = reso; - chkres = chkres + 1 - end if -end - - -function checkdims( desc:string, dsizefile1 [*]:integer, dsizefile2 [*]:integer, res:string, lmask:string ) -; -; check that dimensions are the same between the file variables -; -begin - reso = res+"_"+lmask; - if ( any( dsizefile1 .ne. dsizefile2) )then - print( space+space+space+desc+" dimensions are different for "+reso+" resolution" ); - print( space+space+space+"dim first file "+dsizefile1 ); - print( space+space+space+"dim second file "+dsizefile2 ); - if ( .not. any(badresolutions .eq. reso ) )then - badresolutions(badres) = reso; - badres = badres + 1 - end if - return( False ); - else - print( space+space+space+"File dims OK for "+desc+"!" ); - return( True ); - end if - if ( .not. any(chkresolutions .eq. reso ) )then - chkresolutions(chkres) = reso; - chkres = chkres + 1 - end if -end - -begin - - csmdata = getenv("CSMDATA"); - clmroot = getenv("CLM_ROOT"); - querynml = "bld/queryDefaultNamelist.pl -silent -justvalue -namelist clmexp"; - if ( .not. ismissing(csmdata) )then - querynml = querynml+" -csmdata "+csmdata; - end if - if ( ismissing(clmroot) )then - querynml = "../../"+querynml; - else - querynml = clmroot+"/components/clm/"+querynml; - end if - - print( "query string="+querynml ) - - - mapgrids = (/"0.5x0.5_nomask", "0.25x0.25_nomask", "0.125x0.125_nomask", "3x3min_nomask", "5x5min_nomask", "10x10min_nomask", "0.9x1.25_nomask", "1km-merge-10min_HYDRO1K-merge-nomask"/); - do i = 0, dimsizes(resolutions)-1 - res = resolutions(i); - print( "Go through maps for Resolution: "+res ); - do j = 0, dimsizes(mapgrids)-1 - grid = str_get_field( mapgrids(j), 1, "_" ); - lmask = str_get_field( mapgrids(j), 2, "_" ); - print( space+"Look for maps from Grid: "+grid+"_"+lmask); - - querynmlres = querynml+" -options frm_lmask="+lmask+",frm_hgrid="+grid+",to_hgrid="+res+",to_lmask=nomask"; - ; - ; Get map filename and open it - ; - mapfile = systemfunc( querynmlres+" -var map" ); - if ( systemfunc("test -f "+mapfile+"; echo $?" ) .ne. 0 )then - delete( mapfile ); - continue; - end if - print( space+"Use mapfile: "+mapfile ); - ncm = addfile( mapfile, "r" ); - - if ( .not. isvar("ncm0") )then - ncm0 = ncm; - else - vars = (/"yc_b", "xc_b", "area_b", "xv_b", "yv_b" /); - k = 0; - if ( checkdims( vars(k), dimsizes(ncm->$vars(k)$), dimsizes(ncm0->$vars(k)$), res, "nomask" ) )then - do k = 0, dimsizes(vars)-1 - maxdiff = max( abs(ncm->$vars(k)$ - ncm0->$vars(k)$) ); - checkit( vars(k), maxdiff, res, "nomask", 1.e-12 ); - delete( maxdiff ); - end do - var = "mask_b" - imaxdiff = max( abs(ncm->$var$ - ncm0->$var$) ); - checkit( var, imaxdiff, res, "nomask", 1.e-12 ); - delete( imaxdiff ); - end if - delete( ncm ); - end if - delete( mapfile ); - - end do - - delete( grid ); - delete( lmask ); - delete( res ); - if ( isvar("ncm0") )then - delete( ncm0 ); - end if - - end do - ; - ; go the other direction now check the _a variables - ; - mksrf_files = (/"mksrf_fvegtyp", "mksrf_fglacier", "mksrf_furbtopo", "mksrf_flai", "mksrf_fsoitex", "mksrf_fsoicol", "mksrf_ffrac", "mksrf_fmax", "mksrf_ftopo", "mksrf_firrig", "mksrf_forganic", "mksrf_flakwat", "mksrf_fwetlnd", "mksrf_furban", "mksrf_fvocef"/) - do i = 0, dimsizes(mapgrids)-1 - grid = str_get_field( mapgrids(i), 1, "_" ); - lmask = str_get_field( mapgrids(i), 2, "_" ); - print( "Grid: "+grid); - print( "Mask: "+lmask); - do j = 0, dimsizes(resolutions)-1 - res = resolutions(j); - print( "res: "+res ); - - querynmlres = querynml+" -options frm_lmask="+lmask+",frm_hgrid="+grid+",to_hgrid="+res+",to_lmask=nomask"; - ; - ; Get map filename and open it - ; - mapfile = systemfunc( querynmlres+" -var map" ); - if ( systemfunc("test -f "+mapfile+"; echo $?" ) .ne. 0 )then - delete( mapfile ); - continue; - end if - print( space+"Use mapfile: "+mapfile ); - ncm = addfile( mapfile, "r" ); - - if ( .not. isvar("ncm0") )then - ncm0 = ncm; - else - vars = (/"yc_a", "xc_a", "area_a", "xv_a", "yv_a" /); - vars2 = (/"LATIXY", "LONGXY", "AREA" /); - k = 0; - if ( checkdims( vars(k), dimsizes(ncm->$vars(k)$), dimsizes(ncm0->$vars(k)$), res, "nomask" ) )then - do k = 0, dimsizes(vars)-1 - maxdiff = max( abs(ncm->$vars(k)$ - ncm0->$vars(k)$) ); - checkit( vars(k), maxdiff, res, "nomask", 1.e-12 ); - delete( maxdiff ); - end do - end if - var = "mask_a" - imaxdiff = max( abs(ncm->$var$ - ncm0->$var$) ); - checkit( var, imaxdiff, res, "nomask", 1.e-12 ); - delete( imaxdiff ); - ; - ; Get mksurfdata input datasets - ; - do k = 0, dimsizes(mksrf_files)-1 - srffile = systemfunc( querynmlres+" -var "+mksrf_files(k) ); - if ( systemfunc("test -f "+srffile+"; echo $?" ) .ne. 0 )then - delete( srffile ); - continue; - end if - print( space+"Use srffile: "+srffile ); - ncs = addfile( srffile, "r" ); - n = 0; - if ( checkdims( vars(n), dimsizes(ncm->$vars(n)$), ndtooned(dimsizes(ncs->$vars2(n)$)), res, "nomask" ) )then - do n = 0, dimsizes(vars2)-1 - maxdiff = max( abs(ncm->$vars(n)$ - ndtooned(ncs->$vars2(n)$)) ); - checkit( vars(n), maxdiff, res, "nomask", 1.e-12 ); - delete( maxdiff ); - end do - var = "mask_a" - var2 = "LANDMASK" - imaxdiff = max( abs(ncm->$var$ - ndtooned(ncs->$var2$)) ); - checkit( var, imaxdiff, res, "nomask", 1.e-12 ); - end if - delete( ncs ); - end do - delete( ncm ); - end if - delete( mapfile ); - - end do - - if ( isvar("vars") )then - delete( vars ) - end if - if ( isvar("vars2") )then - delete( vars2 ) - end if - delete( grid ); - delete( lmask ); - delete( res ); - if ( isvar("ncm0") )then - delete( ncm0 ); - end if - - end do - if ( chkres .gt. 0 )then - print( "resolutions checked = " ); - print( chkresolutions(0:chkres-1) ); - end if - if ( badres .gt. 0 )then - print( "badresolutions = " ); - print( badresolutions(0:badres-1) ); - end if - - print( "===============================" ); - print( "Successfully went through files" ); - -end - diff --git a/bld/namelist_files/createMapEntry.pl b/bld/namelist_files/createMapEntry.pl deleted file mode 100755 index 561683bb05..0000000000 --- a/bld/namelist_files/createMapEntry.pl +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env perl -# -# July 18 2012 Muszala -# -# createMapEntry.pl - A simple script to dump a list of mappings for a specified resolution to then -# cut and paste into namelist_defaults_ctsm.xml. A better way is to write the output of this script -# to a file and then directly insert that file into namelist_defaults_ctsm.xml (using :r foo in vim for -# example). -# -# Example usage:>> ./createMapEntry.pl 1x1_brazil -# will create XML entries for maps in ../lnd/clm2/mappingdata/maps/1x1_brazil such as: -# -# lnd/clm2/mappingdata/maps/1x1_brazil/map_0.5x0.5_AVHRR_to_1x1_brazil_nomask_aave_da_c120717.nc -# -use Cwd; -use strict; -use English; -use IO::File; -use Getopt::Long; - - my $date = scalar localtime() ; - my $scriptName; - ($scriptName = $0) =~ s!(.*)/!!; # get name of script - my $cwd = getcwd(); - my $CSMDATA = "/glade/p/cesm/cseg/inputdata"; - - if ($#ARGV != 0 ) { - usage(); - exit; - } - my $grid=$ARGV[0]; - - sub usage { - die < - is the resolution to use to dump text to paste into namelist_defaults_ctsm.xml -EOF - } - - #~# set up directory paths - my $pathStub="lnd/clm2/mappingdata/maps"; - my $partialPath="$pathStub/$grid"; - my $fullPath = "$CSMDATA/$partialPath"; - - #~# open and read directory - opendir DIR, $fullPath or die "Cannot read dir! $fullPath"; - my @list = readdir DIR; - - #~# print a unique start string in the XML comments - print "\n"; - print "\n \n\n"; - - foreach my $foo ( @list ) { - next if ($foo =~ m/^\./); #~# skip anything in the directory with a leading or stand alone 'dot' - $foo =~ s/$grid/RES/; # Replace grid trying to match with RES (so underscores in the grid name don't mess up the matching) - my @tokens = split(/_/, $foo); #~# split foo name by the underscore - #~# write out lines for namelist_defaults_ctsm.xml nomask" files - my $from_mask = $tokens[2]; - if ( $from_mask =~ /nomask/ ) { - if ( $tokens[5] eq "nomask" && $tokens[4] eq "RES" ) { - print "$partialPath/$foo\n"; - } - } - } - - #~# print a unique end string in the XML comments - print "\n \n"; - closedir(DIR); - exit 0; diff --git a/bld/namelist_files/createMkSrfEntry.py b/bld/namelist_files/createMkSrfEntry.py deleted file mode 100755 index 3f12df1509..0000000000 --- a/bld/namelist_files/createMkSrfEntry.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python3 - -import os, sys - -class mksrfDataEntry_prog: - - # Class data - year_start = 850 - year_end = 1849 - ssp_rcp = "hist" - subdir = "pftcftdynharv.0.25x0.25.LUH2.histsimyr0850-1849.c171012" - cdate = 171012 - desc = "histclm50_LUH2" - - def parse_cmdline_args( self ): - "Parse the command line arguments for create data entry list" - from optparse import OptionParser, OptionGroup - - parser = OptionParser( usage="%prog [options]" ) - options = OptionGroup( parser, "Options" ) - options.add_option( "-s", "--year_start", dest="year_start", default=self.year_start, \ - help="Start year" ) - options.add_option( "-f", "--year_end", dest="year_end", default=self.year_end, \ - help="End year" ) - options.add_option( "-d", "--subdir", dest="subdir", default=self.subdir, \ - help="Subdirectory" ) - options.add_option( "--cdate", dest="cdate", default=self.cdate, \ - help="Creation date" ) - options.add_option( "--desc", dest="desc", default=self.desc, \ - help="Description string" ) - parser.add_option_group(options) - (options, args) = parser.parse_args() - if len(args) != 0: - parser.error("incorrect number of arguments") - - self.year_start = options.year_start - self.year_end = options.year_end - self.subdir = options.subdir - self.cdate = options.cdate - self.desc = options.desc - - def printentry( self, year ): - "Print a single entry" - print( 'lnd/clm2/rawdata/%s/mksrf_landuse_%s_%s.c%s.nc' % (self.subdir, self.desc, year, self.cdate) ) - print( '\n' ) - -entry = mksrfDataEntry_prog() -entry.parse_cmdline_args() - -for year in range(entry.year_start, entry.year_end+1): - entry.printentry( year ) - - - - diff --git a/bld/queryDefaultNamelist.pl b/bld/queryDefaultNamelist.pl deleted file mode 100755 index 920e91eb48..0000000000 --- a/bld/queryDefaultNamelist.pl +++ /dev/null @@ -1,315 +0,0 @@ -#!/usr/bin/env perl -#======================================================================= -# -# This is a script to read the CLM namelist XML file -# -# Usage: -# -# queryDefaultNamelist.pl [options] -# -# To get help on options and usage: -# -# queryDefaultNamelist.pl -help -# -#======================================================================= - -use Cwd; -use strict; -#use diagnostics; -use Getopt::Long; -use English; - -#----------------------------------------------------------------------------------------------- - -#Figure out where configure directory is and where can use the XML/Lite module from -my $ProgName; -($ProgName = $PROGRAM_NAME) =~ s!(.*)/!!; # name of program -my $ProgDir = $1; # name of directory where program lives - -my $cwd = getcwd(); # current working directory -my $cfgdir; - -if ($ProgDir) { $cfgdir = $ProgDir; } -else { $cfgdir = $cwd; } - -#----------------------------------------------------------------------------------------------- -# Add $cfgdir to the list of paths that Perl searches for modules -my @dirs = ( "$cfgdir", - "$cfgdir/../cime/utils/perl5lib", - "$cfgdir/../../../cime/utils/perl5lib" ); -unshift @INC, @dirs; -my $result = eval "require XML::Lite"; -if ( ! defined($result) ) { - die <<"EOF"; -** Cannot find perl module \"XML/Lite.pm\" from directories: @dirs ** -EOF -} -require Build::Config; -require Build::NamelistDefinition; -require queryDefaultXML; - -# Defaults -my $namelist = "clm_inparm"; -my $config = "config_cache.xml"; - - -sub usage { - die < $namelist, - var => undef, - hgrid => undef, - config => undef, - cesm => undef, - csmdata => undef, - demand => undef, - test => undef, - onlyfiles => undef, - fileonly => undef, - silent => undef, - usrname => undef, - help => undef, - options => undef, - ); - - my $cmdline = "@ARGV"; - GetOptions( - "f|file=s" => \$opts{'file'}, - "n|namelist=s" => \$opts{'namelist'}, - "v|var=s" => \$opts{'var'}, - "r|res=s" => \$opts{'hgrid'}, - "config=s" => \$opts{'config'}, - "cesm" => \$opts{'cesm'}, - "csmdata=s" => \$opts{'csmdata'}, - "demand" => \$opts{'demand'}, - "options=s" => \$opts{'options'}, - "t|test" => \$opts{'test'}, - "onlyfiles" => \$opts{'onlyfiles'}, - "filenameonly" => \$opts{'fileonly'}, - "justvalues" => \$opts{'justvalues'}, - "usrname=s" => \$opts{'usrname'}, - "s|silent" => \$opts{'silent'}, - "h|elp" => \$opts{'help'}, - ) or usage(); - - # Check for unparsed arguments - if (@ARGV) { - print "ERROR: unrecognized arguments: @ARGV\n"; - usage(); - } - if ( $opts{'help'} ) { - usage(); - } - # Set if should do extra printing or not (if silent mode is not set) - my $printing = 1; - if ( defined($opts{'silent'}) ) { - $printing = 0; - } - # Get list of options from command-line into the settings hash - my %settings; - if ( defined($opts{'options'}) ) { - $opts{'options'} =~ s/\s//g; # Remove all white-space in options - my @optionlist = split( ",", $opts{'options'} ); - foreach my $item ( @optionlist ) { - my ($key,$value) = split( "=", $item ); - $settings{$key} = $value; - } - } - my $csmdata = ""; - if ( defined($opts{'fileonly'}) ) { - if ( ! defined($opts{'justvalues'}) ) { print "When -filenameonly option used, -justvalues is set as well\n" if $printing; } - if ( ! defined($opts{'onlyfiles'}) ) { print "When -filenameonly option used, -onlyfiles is set as well\n" if $printing; } - $opts{'justvalues'} = 1; - $opts{'onlyfiles'} = 1; - } - # List of input options - my %inputopts; - # This namelist files under the cime directories are in version 2 format and can't be read by perl code EBK 11/15/2016 - my @nl_definition_files = ("$cfgdir/namelist_files/namelist_definition_drv.xml", - "$cfgdir/namelist_files/namelist_definition_ctsm.xml" - ); - $inputopts{empty_cfg_file} = "$cfgdir/config_files/config_definition_ctsm.xml"; - $inputopts{nldef_files} = \@nl_definition_files; - $inputopts{namelist} = $opts{namelist}; - $inputopts{printing} = $printing; - $inputopts{cfgdir} = $cfgdir; - $inputopts{ProgName} = $ProgName; - $inputopts{cmdline} = $cmdline; - - my $exitearly = 0; - my $definition = Build::NamelistDefinition->new( $nl_definition_files[0] ); - foreach my $nl_defin_file ( @nl_definition_files ) { - if ( ! -f "$nl_defin_file" ) { - die "($ProgName $cmdline) ERROR:: bad namelist definition filename: $nl_defin_file.\n"; - } - $definition->add( "$nl_defin_file" ); - } - - if ( ! defined($opts{csmdata}) ) { - $inputopts{csmdata} = "default"; - } else { - $inputopts{csmdata} = $opts{csmdata}; - } - if ( defined($opts{cesm}) ) { - $inputopts{csmdata} = '$DIN_LOC_ROOT'; - } - if ( ! defined($opts{config}) ) { - $inputopts{config} = "noconfig"; - } else { - $inputopts{config} = $opts{config}; - } - if ( ! defined($opts{var}) ) { - $settings{'var'} = undef; - } elsif ( $opts{var} eq "list" ) { - print "Valid variables: " if $printing; - my @vars = $definition->get_var_names( ); - print "@vars\n"; - $exitearly = 1; - } else { - $settings{'var'} = $opts{'var'}; - } - if ( ! defined($opts{hgrid}) ) { - $inputopts{hgrid} = "any"; - } elsif ( $opts{hgrid} eq "list" ) { - print "Valid resolutions: " if $printing; - my @hgrids = $definition->get_valid_values( "res", 'noquotes'=>1 ); - print "@hgrids\n"; - $exitearly = 1; - } else { - if ( ! $definition->is_valid_value( "res", $opts{hgrid}, 'noquotes'=>1 ) ) { - if ( $opts{'hgrid'} ne $opts{'usrname'} ) { - die "($ProgName $cmdline) ERROR:: invalid resolution entered.\n"; - } - } - $inputopts{hgrid} = $opts{hgrid}; - } - # The namelist defaults file contains default values for all required namelist variables. - my @nl_defaults_files = ( "$cfgdir/namelist_files/namelist_defaults_overall.xml" ); - if ( defined($opts{'usrname'}) ) { - my $nl_defaults_file = "$cfgdir/namelist_files/namelist_defaults_usr_files.xml"; - push( @nl_defaults_files, $nl_defaults_file ); - $settings{'clm_usr_name'} = $opts{'usrname'}; - $settings{'notest'} = ! $opts{'test'}; - $settings{'csmdata'} = $inputopts{csmdata}; - } else { - my @files = ( "$cfgdir/namelist_files/namelist_defaults_ctsm.xml", - "$cfgdir/namelist_files/namelist_defaults_ctsm_tools.xml", - "$cfgdir/namelist_files/namelist_defaults_drv.xml", - "$cfgdir/namelist_files/namelist_defaults_drydep.xml", - ); - push( @nl_defaults_files, @files ); - } - if ( ! $exitearly ) { - $inputopts{files} = \@nl_defaults_files; - - my $defaults_ref = &queryDefaultXML::ReadDefaultXMLFile( \%inputopts, \%settings ); - my %defaults = %$defaults_ref; - my @keys = keys(%defaults); - if ( defined($opts{'demand'}) && ($#keys == -1) ) { - die "($ProgName $cmdline) ERROR:: demand option is set and nothing was found.\n"; - } - my $print; - foreach my $var ( @keys ) { - $print = 1; - my $value = $defaults{$var}{value}; - my $isadir = $defaults{$var}{isdir}; - my $isafile = $defaults{$var}{isfile}; - my $isastr = $defaults{$var}{isstr}; - # If onlyfiles option set do NOT print if is NOT a file - if ( defined($opts{'onlyfiles'}) && (! $isafile) ) { - $print = undef; - } - # If is a directory - if ( $isadir ) { - # Test that this directory exists - if ( defined($opts{'test'}) && defined($print) ) { - print "Test that directory $value exists\n" if $printing; - if ( ! -d "$value" ) { - die "($ProgName) ERROR:: directory $value does NOT exist!\n"; - } - } - } - # If is a file - if ( $isafile ) { - # Test that this file exists - if ( defined($opts{'test'}) && defined($print) ) { - chomp( $value ); - print "Test that file $value exists\n" if $printing; - if ( ! -f "$value" ) { - die "($ProgName) ERROR:: file $value does NOT exist!\n"; - } - } - } - # If a string - if ( (! defined($opts{'justvalues'}) ) && ($isastr) ) { - $value = "\'$value\'"; - } - # if you just want the filename -- not the full path with the directory - if ( defined($opts{'fileonly'}) ) { - $value =~ s!(.*)/!!; - } - if ( defined($print) ) { - if ( ! defined($opts{'justvalues'}) ) { - print "$var = "; - } - print "$value\n"; - } - } - } - if ( $printing && defined($opts{'test'}) ) { - print "\n\nTesting was successful\n\n" - } - diff --git a/bld/queryDefaultXML.pm b/bld/queryDefaultXML.pm deleted file mode 100644 index 85a81d8f9a..0000000000 --- a/bld/queryDefaultXML.pm +++ /dev/null @@ -1,161 +0,0 @@ -#======================================================================= -# -# This is a perl module to read in a list of namelist_default files. -# -#======================================================================= -use strict; -use Build::Config; -use Build::NamelistDefinition; -use Build::NamelistDefaults; -use Build::Namelist; - -package queryDefaultXML; - -#------------------------------------------------------------------------------- - -sub read_cfg_file -# -# Read in the configuration cache XML file on the build-time configuration -# -{ - my ($file, $empty_cfg_file, $printing, $settings_ref) = @_; - - my $cfg; - my %config; - if ( $file eq "noconfig" ) { - print "No configuration cache file to read in.\n" if $printing; - $cfg = Build::Config->new( $empty_cfg_file ); - } elsif ( -f "$file" ) { - $cfg = Build::Config->new($file); - } else { - die "Bad filename entered: $file does NOT exist or can not open it.\n"; - } - # - # Make sure variables are set to valid values - # - foreach my $key ( keys( %config ) ) { - if ( $cfg->is_valid_name( $key ) ) { - $cfg->set( $key, $config{$key} ); - } - } - foreach my $key ( $cfg->get_names( ) ) { - if ( defined($$settings_ref{$key}) ) { - if ( $cfg->is_valid_name( $key ) ) { - $cfg->set( $key, $$settings_ref{$key} ); - } - } - } - return( $cfg ); -} - -#------------------------------------------------------------------------------- - -sub ReadDefaultXMLFile { -# -# Read in the default XML file for the default namelist settings -# - my $opts_ref = shift; - my $settings_ref = shift; - - # Error check that input and opts hash has the expected variables - my $ProgName = $$opts_ref{'ProgName'}; - my $nm = "${ProgName}::ReadDefaultXMLFile"; - my @required_list = ( "files", "nldef_files", "empty_cfg_file", "config", "namelist", - "csmdata", "hgrid", "printing", "ProgName", "cmdline", - "cfgdir" ); - foreach my $var ( @required_list ) { - if ( ! defined($$opts_ref{$var}) ) { - die "ERROR($nm): Required input variable $var was not found\n"; - } - } - my $printing = $$opts_ref{'printing'}; - my $cmdline = $$opts_ref{'cmdline'}; - # Initialize some local variables - my $files_ref = $$opts_ref{'files'}; - my @files = @$files_ref; - my $nldef_ref = $$opts_ref{'nldef_files'}; - my @nl_definition_files= @$nldef_ref; - my $empty_config_file = $$opts_ref{'empty_cfg_file'}; - my $namelist = $$opts_ref{'namelist'}; - - my $cfg = read_cfg_file( $$opts_ref{'config'}, $$opts_ref{'empty_cfg_file'}, - $printing, $settings_ref ); - - # - # Set up options to send to namelist defaults object - # - my %nlopts; - foreach my $var ( keys( %$settings_ref) ) { - if ( $var ne "csmdata" ) { - $nlopts{$var} = $$settings_ref{$var}; - } - } - if ( $$opts_ref{'hgrid'} ne "any" ) { - $nlopts{'hgrid'} = $$opts_ref{'hgrid'}; - } - # - # Loop through all variables in files - # - print "($nm) Read: $files[0]\n" if $printing; - my %defaults; - my $nldefaults = Build::NamelistDefaults->new($files[0], $cfg); - for ( my $i = 1; $i <= $#files; $i++ ) { - print "($nm) Read: $files[$i]\n" if $printing; - $nldefaults->add( $files[$i] ); - } - my $definition = Build::NamelistDefinition->new( $nl_definition_files[0] ); - for ( my $i = 1; $i <= $#nl_definition_files; $i++ ) { - print "($nm) Read: $nl_definition_files[$i]\n" if $printing; - $definition->add( $nl_definition_files[$i] ); - } - if ( $$opts_ref{'csmdata'} eq "default" ) { - $$opts_ref{'csmdata'} = $nldefaults->get_value( "csmdata", \%nlopts ); - } - $nlopts{'csmdata'} = $$opts_ref{'csmdata'}; - foreach my $name ( $nldefaults->get_variable_names() ) { - my $value = $nldefaults->get_value( $name, \%nlopts ); - if ( $value eq "null" ) { next; } - if ( defined($$settings_ref{'var'}) ) { - if ( $name ne $$settings_ref{'var'} ) { next; } - } - $value =~ s/\n//g; - my $isafile = 0; - if ( $definition->is_input_pathname($name) ) { - - if ( defined($$settings_ref{'clm_usr_name'}) ) { - $value = $nldefaults->get_usr_file( $name, $definition, \%nlopts ); - } - if ( $value && ($value !~ /^\/.+$/) ) { - $value = $$opts_ref{'csmdata'} . "/" . $value; - } - $isafile = 1; - } - my $isadir = 0; - my $isastr = 0; - if ( $definition->get_str_len($name) > 0 ) { - $isastr = 1; - } - # - # If is a directory (is a file and csmdata or a var with dir in name) - # - if ( $isafile && (($name eq "csmdata") || ($name =~ /dir/)) ) { - if ( $name eq "csmdata" ) { - $value = $$opts_ref{'csmdata'}; - $isadir = 1; - } else { - $isadir = 1; - } - } - # Return hash with the results - my $group = $definition->get_group_name( $name ); - if ( $group eq $namelist && $value && (! exists($defaults{$name}{'value'})) ) { - $defaults{$name}{'value'} = $value; - $defaults{$name}{'isfile'} = $isafile; - $defaults{$name}{'isdir'} = $isadir; - $defaults{$name}{'isstr'} = $isastr; - } - } - return( \%defaults ); -} - -1 # To make use or require happy diff --git a/tools/README b/tools/README index c65e694b98..34f106069b 100644 --- a/tools/README +++ b/tools/README @@ -11,7 +11,6 @@ I. General directory structure: mkmapgrids ------- Create regular lat/lon SCRIP grid files mkprocdata_map --- Convert output unstructured grids into a 2D format that can be plotted easily - ncl_scripts ------ NCL post or pre processing scripts. site_and_regional Scripts for handling input datasets for site and regional cases. These scripts both help with creation of datasets using the @@ -80,7 +79,7 @@ II. Notes on building/running for each of the above tools: CMakeLists.txt -- Tells CMake how to build the source code Makefile -------- GNU makefile to link the program together - mkmapgrids, site_and_regional, and ncl_scripts only contain scripts so don't have the above build files. + mkmapgrids, and site_and_regional only contain scripts so don't have the above build files. Some tools have copies of files from other directories -- see the README.filecopies file for more information on this. diff --git a/tools/ncl_scripts/README b/tools/ncl_scripts/README deleted file mode 100644 index 72073f5035..0000000000 --- a/tools/ncl_scripts/README +++ /dev/null @@ -1,15 +0,0 @@ -$CTSMROOT/tools/ncl_scripts Jun/08/2018 - -CLM NCL script tools for analysis of CLM history files -- or for creation or -modification of CLM input files. - -In order to make these scripts work in the testing framework the following must -be done. - -1.) Respond to CSMDATA and CLM_ROOT as needed. -2.) Print a line with "success" after the work is completed. - -NCL Scripts available: - -getco2_historical.ncl ------- Get historical CO2 to use for input in datm8 streams - diff --git a/tools/ncl_scripts/getco2_historical.ncl b/tools/ncl_scripts/getco2_historical.ncl deleted file mode 100644 index c071fa42d6..0000000000 --- a/tools/ncl_scripts/getco2_historical.ncl +++ /dev/null @@ -1,196 +0,0 @@ -; -; Take the greenhouse gas file used by CAM for historical (and future) representations of -; greenhouse gases, and convert it to a format that can be used by streams. -; So include domain data for a single point (or latitude bands) that covers the globe, as well -; as CO2 data over those latitude bands. In the process we also discard the other -; greenhouse gases, as the datm can only pass CO2. -; -; Erik Kluzek -; Mar/03/2010 -; -begin - ; =========================================================================================================== - - - ; =========================================================================================================== - ; - ; Setup the namelist query script - ; - csmdata = getenv("CSMDATA"); - clmroot = getenv("CLM_ROOT"); - hgrid = getenv("HGRID"); ; Get horizontal grid to use from env variable - querynml = "bld/queryDefaultNamelist.pl -silent -justvalue "; - if ( .not. ismissing(csmdata) )then - querynml = querynml+" -csmdata "+csmdata; - end if - if ( ismissing(clmroot) )then - querynml = "../../"+querynml; - else - querynml = clmroot+"/"+querynml; - end if - if ( ismissing(hgrid) )then - hgrid = "lat-bands" - end if - ; - ; Get input Greenhouse gas file and open it - ; - filetype = "mkghg_bndtvghg"; - print( querynml+" -namelist clmexp -var "+filetype+" -options hgrid="+hgrid ); - ghgfile = systemfunc( querynml+" -namelist clmexp -var "+filetype+" -options hgrid="+hgrid ); - print( "Use "+filetype+" file: "+ghgfile ); - if ( systemfunc("test -f "+ghgfile+"; echo $?" ) .ne. 0 )then - print( "Input "+filetype+" file does not exist or not found: "+ghgfile ); - exit - end if - ncg = addfile( ghgfile, "r" ); - - ; - ; Get date time-stamp to put on output CO2 file - ; - sdate = systemfunc( "date +%y%m%d" ); - ldate = systemfunc( "date" ); - - sim_yr0 = ncg->date(0) / 10000; - ntime = dimsizes( ncg->date ); - sim_yr2 = ncg->date(ntime-1) / 10000; - - sim_yr_rng = "simyr_"+sim_yr0 + "-" + sim_yr2; - - cmip_vers = "_CMIP6_"; - outco2filename = "fco2_datm_"+hgrid+sim_yr_rng+cmip_vers+"c"+sdate+".nc"; - system( "/bin/rm -f "+outco2filename ); - print( "output file: "+outco2filename ); - nco = addfile( outco2filename, "c" ); - ; - ; Define dimensions - ; - if ( hgrid .eq. "lat-bands" )then - nlat = dimsizes(ncg->lat); - else - if ( hgrid .eq. "global" )then - nlat = 1 - else - print( "hgrid type can only be global or lat-bands: "+hgrid ) - exit - end if - end if - nlon = 1; - nv = 4; - dimnames = (/ "time", "lat", "lon", "nv", "bounds" /); - dsizes = (/ ntime, nlat, nlon, nv, 2 /); - is_unlim = (/ True, False, False, False, False /); - filedimdef( nco, dimnames, dsizes, is_unlim ); - ; - ; Define variables - ; - vars = (/ "lonc", "latc", "lonv", "latv", "mask", "frac", "area", "CO2" /); - units= (/ "degrees_east", "degrees_north", "degree_east", "degrees_north", "unitless", "unitless", "radians^2", "ppmv" /); - lname= (/ "Longitude of grid cell center", "Latitude of grid cell center", "Longitudes of grid cell vertices", "Latitudes of grid cell vertices", "Mask of active cells: 1=active", "Fraction of grid cell that is active", "Area of grid cell", "CO2 concentration" /); - print( "Define variables: "+vars ); - do i= 0, dimsizes(vars)-1 - if ( vars(i) .eq. "lonv" .or. vars(i) .eq. "latv" )then - filevardef ( nco, vars(i), "double", (/ "lat", "lon", "nv" /) ); - else - if ( vars(i) .eq. "CO2" )then - filevardef ( nco, vars(i), "float", (/ "time", "lat", "lon" /) ); - nco->$vars(i)$@coordinate = "latc lonc time"; - else - filevardef ( nco, vars(i), "double", (/ "lat", "lon" /) ); - end if - end if - nco->$vars(i)$@units = units(i); - nco->$vars(i)$@long_name = lname(i); - end do - filevardef ( nco, "time", "float", (/ "time" /) ); - filevardef ( nco, "time_bnds", "float", (/ "time", "bounds" /) ); - filevardef ( nco, "date", "integer", (/ "time" /) ); - varstatic = (/ "mask", "frac", "area" /); - do i = 0, dimsizes(varstatic)-1 - nco->$varstatic(i)$@coordinate = "latc lonc"; - end do - nco->lonc@bounds = "lonv"; - nco->latc@bounds = "latv"; - ; - ; Add attributes - ; - fileattdef ( nco, ncg ); - nco@history = ldate+": Convert by getco2_historical.ncl"; - nco@source = "Convert from:"+ghgfile; - nco@Version = systemfunc( "git describe" ); - filevarattdef( nco, "time", ncg->time ); - filevarattdef( nco, "date", ncg->date ); - nco->time_bnds@long_name = nco->time@long_name; - nco->time_bnds@units = nco->time@units; - nco->time_bnds@calendar = nco->time@calendar; - ; - ; Set static variables - ; - pi = 3.14159265358979323846d00; - nco->mask = 1; - nco->frac = 1.0; - if ( nlat .gt. 1 )then - nco->latc = (/ ncg->lat/); - else - nco->latc = (/ 0.0d00 /); - end if - nco->latv(nlat-1,0,0) = 90.0d00; - nco->latv(nlat-1,0,3) = 90.0d00; - if ( nlat .gt. 1 )then - nco->latv(0:nlat-2,0,0) = ( (/ ncg->lat(0:nlat-2) /) + (/ncg->lat(1:nlat-1) /) )*0.5d00 - nco->latv(0:nlat-2,0,3) = (/ nco->latv(0:nlat-2,0,0) /); - nco->latv(1:nlat-1,0,1) = (/ nco->latv(0:nlat-2,0,0) /); - nco->latv(1:nlat-1,0,2) = (/ nco->latv(1:nlat-1,0,1) /); - end if - nco->latv(0,0,1) = -90.0d00; - nco->latv(0,0,2) = -90.0d00; - nco->lonv(:,0,0) = 0.0d00; - nco->lonv(:,0,3) = 0.0d00; - nco->lonc = 180.0d00; - nco->lonv(:,0,1) = 360.0d00; - nco->lonv(:,0,2) = 360.0d00; - clkws = gc_clkwise( nco->latv, nco->lonv ); - if ( any(clkws .eq. False) )then - print( "Some varticies are NOT clockwise" ); - exit - end if - ; EBK -- NOTE The NCL function wasn't giving me the correct answer so I used the mathmatical expression - ;nco->area = dble2flt( gc_qarea( nco->latv, nco->lonv ) ); - conv2rad = pi/180.0d00 - nco->area(:,0) = 2.0d00*pi*abs( sin((/nco->latv(:,0,0)/)*conv2rad) - sin((/nco->latv(:,0,1)/)*conv2rad) ); - if ( abs(sum(nco->area) - 4.0d00*pi) .gt. 1.d-14 )then - print( "Area of globe does not sum to 4*pi as expected" ); - exit - end if - ; - ; Time and date - ; - nco->date = (/ ncg->date /); - nco->time = (/ ncg->time /); - nco->time_bnds = (/ ncg->time_bnds /); - nco->date@comment = "This variable is NOT used when read by datm, the time coordinate is used"; - ; - ; CO2 - ; - print( "Copy CO2 for "+ntime+" time samples of data" ); - if ( nlat .gt. 1 )then - do y = 0, nlat-1 - print( "latitude: "+ nco->latc(y,0) ); - nco->CO2(:,y,0) = (/ ncg->CO2_LBC(:,y) /) * 1.e6; - end do - else - ; make sure all latitudes on file are the same for each time - do itime = 0, ntime-1 - if ( max(ncg->CO2_LBC(itime,:)) .ne. min(ncg->CO2_LBC(itime,:)) )then - print( "Global average, but latitudes are NOT constant" ); - exit - end if - end do - nco->CO2(:,0,0) = (/ ncg->CO2_LBC(:,0) /) * 1.e6; - end if - print( "Average Global First CO2 ppmv value: Date="+nco->date(0)+" CO2="+avg(nco->CO2(0,:,0) ) ); - print( "Average Global Last CO2 ppmv value: Date="+nco->date(ntime-1)+" CO2="+avg(nco->CO2(ntime-1,:,0)) ); - - print( "================================================================================================" ); - print( "Successfully created output historical CO2 file: "+outco2filename); - -end