Subversion Repositories lagranto.ecmwf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 michaesp 1
#!/bin/csh
2
#+
3
# grb2cdf is used to convert a GRIB file (from the ECMWF) to NetCDF
4
# fast version!!
5
#
6
# Usage : grb2cdf [-v varfile] [-y] [-s] [-r] [-m mdv] [-n] [-c constfn] -o cdffilename grib-files
7
#
8
#
9
# Options:
10
#
11
#	-v varfile	where varfile is the path of the variable file to
12
#			be used (the default is ~henry/ecmwf/etc/varfile).
13
#
14
#	-y		for MARS retrieves from CRAY (old version)
15
#			don't give that option for MARS retrieves from
16
#			ecgate1 (new version)
17
#
18
#	-s		single files for every date (in this case the argument
19
#			given with the -o option is complemented with the
20
#			date: e.g. -o sst gives file names like sst970606_00
21
#
22
#	-r		rotate hemispheric data such that domain is from 0 to
23
#			360 deg
24
#
25
#	-l		do not close periodic data
26
#
27
#       -m mdv		where is the missing-data value for the NetCDF file
28
#			(the default is -999.98999).
29
#
30
#	-c constfn	where constfn is the of the NetCDF constants file
31
#			if this option is not given, the constfn is defined
32
#			as 'cdffilename_cst'
33
#			if constn='no' then no constants file is written
34
#
35
#	-o cdffilename	where cdffilename is the name of the NetCDF file
36
#			to be written
37
#
38
# Author: H.Wernli, 29. June 1993
39
#-
40
 
41
set USAGE = "Usage: fgrb2cdf_api [-v varfile] [-y] [-s] [-r] [-m mdv] [-n] [-c constfn] [-3 3dim vars] [-2 2dim vars] -o cdffilename -g grib-files"
42
set varfile = /home/ms/ch/chw/program.ecgb/grbtocdf/etc/varf_api
43
set mdv = -999.98999
44
set version = 1
45
set rotate = 0
46
set noclose = 0
47
set single = 0
48
set writecst = yes
49
set constfn = default
50
set cdfname =
51
set files =
52
set nv = 0
53
 
54
set varinp=${PWD}/grb2cdf_$$
55
\rm -f $varinp
56
 
57
#set argv = `getopt v:ysro:m:lnc:3 $*`
58
#if ( $status != 0 ) then
59
#  echo "$USAGE"
60
#  exit 1
61
#endif
62
 
63
while ( $#argv > 0)
64
 
65
  switch ($argv[1])
66
 
67
    case -v:
68
      set varfile = $argv[2]
69
      shift; shift
70
    breaksw
71
 
72
    case -m:
73
      set mdv = $argv[2]
74
      shift; shift
75
    breaksw
76
 
77
    case -n:
78
      set writecst = no
79
      shift
80
    breaksw
81
 
82
    case -y:
83
      set version = 0
84
      shift
85
    breaksw
86
 
87
    case -s:
88
      set single = 1
89
      shift
90
    breaksw
91
 
92
    case -r:
93
      set rotate = 1
94
      shift
95
    breaksw
96
 
97
    case -l:
98
      set noclose = 1
99
      shift
100
    breaksw
101
 
102
    case -c:
103
      set constfn = $argv[2]
104
      shift; shift
105
    breaksw
106
 
107
    case -o:
108
      set cdfname = $argv[2]
109
      shift; shift
110
    breaksw
111
 
112
    case -3:
113
      shift
114
      set char=""
115
      while ( ( $char != - ) && ( $#argv > 0 ) )
116
        @ nv ++
117
        if ( ! -f $varinp ) touch $varinp
118
        echo $argv[1] >> $varinp
119
        echo 3 >> $varinp
120
        shift
121
        if ( $#argv > 0 ) set char=`echo $argv[1] | cut -c 1`
122
      end
123
    breaksw
124
 
125
    case -2:
126
      shift
127
      set char=""
128
      while ( ( $char != - ) && ( $#argv > 0 ) )
129
        @ nv ++
130
        if ( ! -f $varinp ) touch $varinp
131
        echo $argv[1] >> $varinp
132
        echo 2 >> $varinp
133
        shift
134
        if ( $#argv > 0 ) set char=`echo $argv[1] | cut -c 1`
135
      end
136
    breaksw
137
 
138
    case -g:
139
      shift
140
      set files = "`echo $argv`"
141
      while ( $#argv > 0 )
142
        shift
143
      end
144
    breaksw
145
 
146
  endsw
147
end
148
 
149
if ( $nv > 0 ) then
150
  echo $nv >! fort.16
151
  cat $varinp >> fort.16
152
  \rm -f $varinp
153
endif
154
 
155
if ( "`echo $files`" == "" ) then
156
  echo "grb2cdf: No grib files specified"
157
  echo "$USAGE"
158
  exit 2
159
endif
160
 
161
if ( $cdfname == "" ) then
162
  echo "grb2cdf: No name for NetCDF file specified"
163
  echo "$USAGE"
164
  exit 2
165
endif
166
 
167
if ( ! -r $varfile ) then
168
  echo "grb2cdf: Can't access $varfile"
169
  echo "$USAGE"
170
  exit 2
171
endif
172
 
173
foreach i ( $files )
174
  if ( ! -r $i ) then
175
    echo "grb2cdf: Can't access grib-file $i"
176
    exit 2
177
  endif
178
end
179
 
180
\rm -f fort.14
181
\rm -f fort.15
182
 
183
touch fort.15
184
echo $cdfname >> fort.15
185
echo $writecst >> fort.15
186
echo $constfn >> fort.15
187
echo $mdv >> fort.15
188
echo $version >> fort.15
189
echo $rotate >> fort.15
190
echo $noclose >> fort.15
191
echo $single >> fort.15
192
 
193
ln -s $varfile fort.14
194
 
195
set count=0
196
foreach i ( $files )
197
  \rm -f fort.11
198
  ln -s $i fort.11
199
  if (( $count > 0 ) && ( $nv > 0 )) then
200
    echo 0 >! fort.16
201
  endif
202
  /net/rossby/lhome/sprenger/tmp/ectest/grbtocdf/fgrbtocdf_api
203
  @ count ++
204
end
205
 
206
\rm -f fort.11
207
\rm -f fort.14
208
\rm -f fort.15
209
#\rm -f fort.16