-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts to restore the "lev" dimension
fixlev/fixlev_gcap2_104.sh fixlev/fixlev_gcap2_74.sh fixlev/fixlev_gcap2_40.sh - Script that uses the NCO "ncap2" function to restore the "lev" dimension to netCDF files created by NCL scripts. fixlev/nc_chunk.pl - Script for compressing and chunking README.md - Updated accordingly Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
- Loading branch information
Showing
6 changed files
with
273 additions
and
1,282 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# Add the lev dimension back into the file | ||
ncap2 -O -h -s 'lev[lev]={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}; lev@long_name="GEOS-Chem level"; lev@units="level"; lev@positive="up";lev@axis="Z"' "${1}" "tmp.nc" | ||
mv "tmp.nc" "${1}" | ||
|
||
# Compress and chunk the file | ||
./nc_chunk.pl "${1}" 1 | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# Add the lev dimension back into the file | ||
ncap2 -O -h -s 'lev[lev]={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}; lev@long_name="GEOS-Chem level"; lev@units="level"; lev@positive="up";lev@axis="Z"' "${1}" "tmp.nc" | ||
mv "tmp.nc" "${1}" | ||
|
||
# Compress and chunk the file | ||
./nc_chunk.pl "${1}" 1 | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# Add the lev dimension back into the file | ||
ncap2 -O -h -s 'lev[lev]={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}; lev@long_name="GEOS-Chem level"; lev@units="level"; lev@positive="up";lev@axis="Z"' "${1}" "tmp.nc" | ||
mv "tmp.nc" "${1}" | ||
|
||
# Compress and chunk the file | ||
./nc_chunk.pl "${1}" 1 | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
#!/usr/bin/perl -w | ||
|
||
#------------------------------------------------------------------------------ | ||
# GEOS-Chem Global Chemical Transport Model ! | ||
#------------------------------------------------------------------------------ | ||
#BOP | ||
# | ||
# !MODULE: nc_chunk.pl | ||
# | ||
# !DESCRIPTION: This perl script can be used to chunk and/or deflate a | ||
# netCDF file. It will first do a ncdump command to find out the dimensions | ||
# of the file, and then chunk the file along lon and lat. This is optimal | ||
# for GEOS-Chem and GCHP. | ||
#\\ | ||
#\\ | ||
# !USES: | ||
# | ||
require 5.003; # Need this version of Perl or newer | ||
use English; # Use English language | ||
use Carp; # Get detailed error messages | ||
use strict; | ||
|
||
# !CALLING SEQUENCE: | ||
# nc_chunk.pl NETCDF-FILE-NAME [DEFLATION-LEVEL] | ||
# | ||
# !REMARKS: | ||
# Must have the NetCDF Operators (NCO) installed. | ||
# | ||
# !REVISION HISTORY: | ||
# 12 Apr 2018 - R. Yantosca - Initial version | ||
#EOP | ||
#------------------------------------------------------------------------------ | ||
# GEOS-Chem Global Chemical Transport Model ! | ||
#------------------------------------------------------------------------------ | ||
#BOP | ||
# | ||
# !IROUTINE: chunkTheFile | ||
# | ||
# !DESCRIPTION: Calls nccopy to chunk a netCDF file along lon and lat | ||
# dimensions. If the deflation factor is greater than zero, it will also | ||
# tell nccopy to compress the netCDF file with that deflation level. | ||
#\\ | ||
#\\ | ||
# !INTERFACE: | ||
# | ||
sub chunkTheFile($$) { | ||
# | ||
# !INPUT PARAMETERS: | ||
# | ||
my ( $ncFile, $deflate ) = @_; # NetCDF file name to be chunked | ||
# and the deflation factor | ||
# | ||
# !REVISION HISTORY: | ||
# 12 Apr 2018 - R. Yantosca - Initial version | ||
#EOP | ||
#------------------------------------------------------------------------------ | ||
#BOC | ||
# | ||
# !LOCAL VARIABLES: | ||
# | ||
# Scalars | ||
my $isDims = 0; | ||
|
||
# Strings | ||
my $cmd = ""; | ||
my $latCmd = ""; | ||
my $latSize = ""; | ||
my $lonCmd = ""; | ||
my $lonSize = ""; | ||
my $levCmd = ""; | ||
my $timeCmd = ""; | ||
my $nfCmd = ""; | ||
my $line = ""; | ||
my $result = ""; | ||
|
||
# Arrays | ||
my @ncDumpTxt = (); | ||
my @subStrs = (); | ||
|
||
# Exit if the file does not exist | ||
if ( !( -f $ncFile ) ) { print "Could not find $ncFile!\n"; exit(-1); } | ||
|
||
# Save the contents of ncdump to an array | ||
@ncDumpTxt = qx/ncdump -cts $ncFile/; | ||
|
||
# Parse the ncdump line | ||
foreach $line ( @ncDumpTxt ) { | ||
|
||
# Remove newlines | ||
chomp( $line ); | ||
|
||
# We have entered the dimensions section | ||
if ( $line =~ m/dimensions:/ ) { $isDims = 1; } | ||
|
||
# Look for the lon and lat dimensions | ||
if ( $isDims > 0 ) { | ||
|
||
# Create chunking command for lon dimension | ||
if ( $line =~ m/[Ll][0o][Nn]/ || $line =~ m/[Xx][Dd][Ii][Mm]/ ) { | ||
$lonCmd = $line; | ||
$lonCmd =~ s/ = /\//g; | ||
$lonCmd =~ s/ ;//g; | ||
$lonCmd =~ s/^\s+|\s+$//g | ||
} | ||
|
||
# Create chunking command for lat dimension | ||
if ( $line =~ m/[Ll][Aa][Tt]/ || $line =~ m/[Yy][Dd][Ii][Mm]/) { | ||
$latCmd = $line; | ||
$latCmd =~ s/ = /\//g; | ||
$latCmd =~ s/ ;//g; | ||
$latCmd =~ s/^\s+|\s+$//g | ||
} | ||
|
||
# Create chunking command for level midpoints dimension | ||
if ( $line =~ m/[Ll][Ee][Vv]/ ) { | ||
@subStrs = split( ' = ', $line ); | ||
$levCmd = "$subStrs[0]/1"; | ||
$levCmd =~ s/^\s+|\s+$//g | ||
} | ||
|
||
# Create chunking command for level interfaces dimension | ||
if ( $line =~ m/[Ii][Ll][Ee][Vv]/ ) { | ||
@subStrs = split( ' = ', $line ); | ||
$levCmd = "$subStrs[0]/1"; | ||
$levCmd =~ s/^\s+|\s+$//g | ||
} | ||
|
||
# Create chunking command for time dimension | ||
if ( $line =~ m/[Tt][Ii][Mm][Ee]/ ) { | ||
@subStrs = split( ' = ', $line ); | ||
$timeCmd = "$subStrs[0]/1"; | ||
$timeCmd =~ s/^\s+|\s+$//g | ||
} | ||
|
||
# Create chunking command for Xdim dimension | ||
if ( $line =~ m/[Nn][Ff]/ ) { | ||
$nfCmd = $line; | ||
$nfCmd =~ s/ = /\//g; | ||
$nfCmd =~ s/ ;//g; | ||
$nfCmd =~ s/^\s+|\s+$//g | ||
} | ||
|
||
} | ||
|
||
# We have exited the dimensions section | ||
if ( $line =~ m/variables:/ ) { goto quit; } | ||
} | ||
|
||
quit: | ||
|
||
# Chunking command | ||
if ( $nfCmd ne "" ) { | ||
|
||
# Cubed-sphere options | ||
if ( $levCmd eq "" && $timeCmd eq "" ) | ||
{ $cmd = "nccopy -c $lonCmd,$latCmd,$nfCmd"; } | ||
elsif ( $levCmd eq "" ) | ||
{ $cmd = "nccopy -c $lonCmd,$latCmd,$nfCmd,$timeCmd"; } | ||
else | ||
{ $cmd = "nccopy -c $lonCmd,$latCmd,$nfCmd,$levCmd,$timeCmd"; } | ||
|
||
} else { | ||
|
||
# Lat-lon options | ||
if ( $levCmd eq "" && $timeCmd eq "" ) | ||
{ $cmd = "nccopy -c $lonCmd,$latCmd"; } | ||
elsif ( $levCmd eq "" ) | ||
{ $cmd = "nccopy -c $lonCmd,$latCmd,$timeCmd"; } | ||
else | ||
{ $cmd = "nccopy -c $lonCmd,$latCmd,$levCmd,$timeCmd"; } | ||
} | ||
|
||
# Deflation command | ||
if ( $deflate > 0 ) { $cmd .= " -d$deflate" } | ||
|
||
# Add file name to the command | ||
$cmd .= " $ncFile tmp.$ncFile; mv tmp.$ncFile $ncFile"; | ||
print "$cmd\n"; | ||
|
||
# Execute the command | ||
$result = qx/$cmd/; | ||
chomp( $result ); | ||
if ( $result ne "" ) { print "$result\n"; } | ||
|
||
# Exit and pass status code back | ||
return( $? ); | ||
} | ||
#EOP | ||
#------------------------------------------------------------------------------ | ||
# GEOS-Chem Global Chemical Transport Model ! | ||
#------------------------------------------------------------------------------ | ||
#BOP | ||
# | ||
# !IROUTINE: main | ||
# | ||
# !DESCRIPTION: Driver program for the nc_chunk.pl script. | ||
#\\ | ||
#\\ | ||
# !INTERFACE: | ||
# | ||
sub main(@) { | ||
# | ||
# !REVISION HISTORY: | ||
# 12 Apr 2018 - R. Yantosca - Initial version | ||
#EOP | ||
#------------------------------------------------------------------------------ | ||
#BOC | ||
|
||
# Error message | ||
my $errMsg = "Usage: nc_chunk.pl NETCDF-FILE-NAME"; | ||
|
||
# If the user passes a filename from the command line, use it | ||
# Otherwise, default to "UnitTest.input" | ||
if ( scalar( @ARGV ) == 2 ) { &chunkTheFile( @ARGV, ); } | ||
elsif ( scalar( @ARGV ) == 1 ) { &chunkTheFile( @ARGV, 0 ); } | ||
else { print "$errMsg\n"; exit( -1 ); } | ||
|
||
# Exit and pass status code backq | ||
return( $? ); | ||
} | ||
#EOC | ||
|
||
#------------------------------------------------------------------------------ | ||
|
||
# Call main program | ||
main(); | ||
|
||
# Exit and pass status code back to Unix shell | ||
exit( $? ); |