-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconv2nc.tcl
74 lines (63 loc) · 1.85 KB
/
conv2nc.tcl
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
#! ~jecole/bin/Convsh1.94
# Convsh script conv2nc.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:
#
# ./conv2nc.tcl -i xaavaa.pc* -o xaava.nc -f 148 149
# Write out netCDF file
set outformat netcdf
# Automatically work out input file type
set filetype 0
# Get command line arguments:
# -i input files (can be more than one file)
# -o output file (single file only)
# -f field list (defaults to all fields)
set i false
set o false
set f false
foreach arg $argv {
switch -glob -- $arg {
-i {set i true ; set o false ; set f false}
-o {set i false ; set o true ; set f false}
-f {set i false ; set o false ; set f true}
-* {puts "unknown option $arg" ; set i false; set o false ; set f false}
default {
if {$i} {
set infile [lappend infile $arg]
} elseif {$o} {
set outfile [lappend outfile $arg]
} elseif {$f} {
set fieldlist [lappend fieldlist $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
}
if {! [info exists fieldlist]} {
# Convert all fields in input files to netCDF
set fieldlist -1
}
# Read in each of the input files
foreach file $infile {
readfile $filetype $file
}
# Write out all input fields to a single netCDF file
writefile $outformat $outfile $fieldlist