pp2nc.tcl 1.75 KB
Newer Older
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
#!/users/modellers/pica/Software/bin/convsh

#  Convsh script pp2nc.tcl
#
#  Convert input files into single Netcdf file.
#
#  All input files must contain the same fields and have identical dimensions
#  except for the time dimension.  For example to convert UM output files into
#  a Netcdf file use the following command:
#
#      pp2nc.tcl -i xaavaa.pc* -o xaava.nc

#  Write out Netcdf file
set outformat netcdf

#  Automatically work out input file type
set filetype 0

#  Convert all fields in input files to Netcdf
set fieldlist -1

#  Get command line arguments:
#      -i input files (can be more than one file)
#      -o output file (single file only)

set i false
set o false
foreach arg $argv {
   switch -glob -- $arg {
      -i      {set i true ; set o false}
      -o      {set i false ; set o true}
      -*      {puts "unknown option $arg" ; set i false; set o false}
      default {
         if {$i} {
            set infile [lappend infile $arg]
         } elseif {$o} {
            set outfile [lappend outfile $arg]
         } else {
            puts "unknown option $arg"
         }
      }
   }
}

if {! [info exists infile]} {
   puts "input file name must be given"
   exit
}

if {[info exists outfile]} {
   if {[llength $outfile] > 1} {
      set outfile [lindex $outfile 0]
      puts "Only one output file can be specified, using $outfile"
   }
} else {
   puts "output file name must be given"
   exit
}

60 61
#  Need to interpolate output onto reduced, rotated pole grid (J Wolf)

62 63 64
#setgrid 1 218 -13. 0.11
#setgrid 2 136 48.39 0.11
#setrotpole 0. 90.
65

66 67 68 69 70 71
#  Read in each of the input files

foreach file $infile {
   readfile $filetype $file
}

72
#interp_grid $fieldlist
73

74 75 76
#  Write out all input fields to a single Netcdf file

writefile $outformat $outfile $fieldlist