Subversion Repositories lagranto.icon

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 michaesp 1
#!/bin/csh
2
 
3
# ---------------------------------------------------------------------
4
# Usage, parameter settings
5
# ---------------------------------------------------------------------
6
 
7
# Set Lagranto 
8
set LAGRANTO = ${LAGRANTOBASE}.${MODEL}/
9
 
10
# Write usage information
11
if ( (${#argv} == 0) | (${#argv} < 2) ) then
12
  echo 
13
  ${LAGRANTO}/bin/lagrantohelp density short
14
  echo
15
  exit 0
16
endif
17
 
18
# Write title
19
echo 
20
echo '========================================================='
21
echo '       *** START OF PREPROCESSOR DENSITY ***              '
22
echo
23
 
24
# ---------------------------------------------------------------------
25
# Handle input parameters
26
# ---------------------------------------------------------------------
27
 
28
# Get input parameters
29
set inpfile = $1
30
set outfile = $2
31
 
32
# Set default values
33
set radius     = 100
34
set unit       = 'km'
35
set grid       = "360 180 -180. -90. 1. 1."
36
set mode       = 'keep'
37
set tratime    = 'all'
38
set param      = 0
39
set gridtype   = 'latlon'
40
set sel_file   = 'nil'
41
set sel_format = 'nil'
42
set field      = 'nil'    
43
set crefile    = 0
44
set pollon     = 0
45
set pollat     = 90
46
 
47
# Handle optional arguments
48
while ( $#argv > 0 )
49
 
50
  switch ( $argv[1] )
51
 
52
   case -radius
53
     set radius = $argv[2]
54
     set unit   = $argv[3]
55
     echo "Flag '-radius'     -> ${radius} ${unit} (user defined)"
56
     shift;
57
     shift;
58
   breaksw
59
 
60
   case -time
61
     set tratime=$argv[2]
62
     echo "Flag '-tratime'    -> ${tratime} (user defined)"
63
     shift;
64
   breaksw
65
 
66
   case -interp
67
     set param=$argv[2]
68
 
69
     if ( "$argv[3]" == "h"   ) set mode = "time"
70
     if ( "$argv[3]" == "km"  ) set mode = "space"
71
     if ( "$argv[3]" == "deg" ) set mode = "grid"
72
 
73
     echo "Flag '-interp'      -> ${mode} ${param} (user defined)"
74
     shift;
75
     shift;
76
   breaksw
77
 
78
   case -create
79
     set crefile = 1
80
     echo "Flag '-create'      -> true (user defined)"
81
   breaksw
82
 
83
   case -latlon
84
     set gridtype = 'latlon'
85
     if ( "$argv[2]" == "dynamic" ) then
86
	   set grid = "0 0 0 0 0 0"
87
	   echo "Flag '-latlon'        -> dynamic  (user defined)"
88
	   shift;
89
     else
90
        set nlon   = $argv[2]
91
        set nlat   = $argv[3]
92
        set lonmin = $argv[4]
93
        set latmin = $argv[5]
94
        set dlon   = $argv[6]
95
        set dlat   = $argv[7]
96
        set grid   = "${nlon} ${nlat} ${lonmin} ${latmin} ${dlon} ${dlat}"
97
        echo "Flag '-latlon      ->  ${grid}  (user defined)"
98
        shift;
99
        shift;
100
        shift;
101
        shift;
102
        shift;
103
        shift;
104
     endif
105
   breaksw
106
 
107
   case -centered
108
     set gridtype = 'centered'
109
     set clon     =  $argv[2]
110
     set clat     =  $argv[3]
111
     set nlonlat = $argv[4]
112
     set dlonlat = $argv[5]
113
     set grid   = "${clon} ${clat} ${nlonlat} ${dlonlat}"
114
     echo "Flag '-centered    ->  ${clon}, ${clat}, ${nlonlat}, ${dlonlat}  (user defined)"
115
     shift;
116
     shift;
117
     shift;
118
     shift;
119
    breaksw
120
 
121
    case -pole
122
     set pollon = $argv[2]
123
     set pollat = $argv[3]
124
     echo "Flag '-pole (lon/lat) ->  ${pollon}, ${pollat}   (user defined)"
125
     shift;
126
     shift;
127
    breaksw
128
 
129
    case -index
130
       set sel_file   = $argv[2]
131
       set sel_format = 'index'
132
       echo "Flag '-index'     -> ${sel_file} (user defined)"
133
       shift;
134
   breaksw
135
 
136
   case -boolean
137
       set sel_file   = $argv[2]
138
       set sel_format = 'boolean'
139
       echo "Flag '-boolean'   -> ${sel_file} (user defined)"
140
       shift;
141
   breaksw
142
 
143
   case -field
144
       set field   = $argv[2]
145
       echo "Flag '-field'   -> ${field} (user defined)"
146
       shift;
147
   breaksw
148
 
149
  endsw
150
 
151
  shift;
152
 
153
end
154
 
155
# ---------------------------------------------------------------------
156
# Do some checks and preparation, then run the program
157
# ---------------------------------------------------------------------
158
 
159
# Rename field <time> to <TIME> to avoid conflict with time coordinate
160
# on the netCDF file
161
if ( "${field}" == "time" ) set field = "TIME"    
162
 
163
# Determine the time step 
164
if ( "${tratime}" == "all" ) then
165
    set step = 0
166
else
167
    set timelist = (`${LAGRANTO}/goodies/trainfo.sh $inpfile times`) 
168
    set step     = 0
169
    set found    = 0
170
    foreach val ( ${timelist} )
171
       @ step = ${step} + 1
172
       if ( "${tratime}" == "${val}" ) then
173
          set found   = ${step}
174
       endif
175
     end
176
     if ( ${found} == 0 ) then
177
       echo "Invalid time ${tratime} for gridding"
178
       echo "${timelist}"
179
       exit 1
180
      endif
181
      set step = ${found}
182
endif
183
 
184
# Check consistency of arguments
185
if ( ( "${mode}" == "time" ) & ( ${step} != 0 ) ) then
186
    echo " ERROR: Options 'interp -time' and 'step' incompatible' "
187
    exit 1
188
endif
189
if ( ( "${mode}" == "space" ) & ( ${step} != 0 ) ) then
190
    echo " ERROR: Options 'interp -space' and 'step' incompatible' "
191
    exit 1
192
endif
193
 
194
# Get trajectory info
195
set ntra   = (`${LAGRANTO}/goodies/trainfo.sh $inpfile ntra`)
196
set ntime  = (`${LAGRANTO}/goodies/trainfo.sh $inpfile ntim`)
197
set nfield = (`${LAGRANTO}/goodies/trainfo.sh $inpfile ncol`)
198
 
199
# Check whether selection file is available
200
if ( "${sel_file}" != "nil" ) then
201
   if ( ! -f ${sel_file} ) then
202
     echo " ERROR: selection file ${sel_file} is missing... Stop"
203
     exit 1
204
   endif
205
endif
206
 
207
# Check whether output file exists - set the <crefile> flag
208
if ( "${crefile}" == "0" ) then
209
   if ( ! -f ${outfile} ) then
210
       set crefile = 1
211
       echo
212
       echo "${outfile} will be created... "
213
   else
214
       echo
215
       echo "${outfile} will be modified ..."
216
   endif
217
else
218
   echo
219
   echo "${outfile} will be created... "
220
endif
221
 
222
# Chewck whether the variable exists - set the <crevar> flag
223
if ( "${crefile}" == "0" ) then    
224
    set varlist = ` ${LAGRANTO}/goodies/getvars ${outfile}` 
225
    set crevar  = 1
226
    foreach var ( ${varlist} )
227
       if ( "${var}" == "${field}" ) set crevar = 0
228
    end
229
else
230
   set crevar = 1
231
endif
232
 
233
# Prepare parameter file and run program
234
\rm -f density.param
235
touch density.param
236
echo ${inpfile}                 >> density.param
237
echo ${outfile}                 >> density.param
238
echo \"${field}\"               >> density.param
239
echo ${ntime} ${nfield} ${ntra} >> density.param
240
echo ${gridtype}                >> density.param
241
echo ${grid}                    >> density.param
242
echo ${radius} ${unit}          >> density.param
243
echo ${mode}                    >> density.param
244
echo ${param}                   >> density.param
245
echo ${step}                    >> density.param
246
echo \"${sel_file}\"            >> density.param
247
echo \"${sel_format}\"          >> density.param
248
echo ${crefile}                 >> density.param
249
echo ${crevar}                  >> density.param
250
echo ${pollon} ${pollat}        >> density.param
251
 
252
# Write status info
253
echo 
254
echo '       *** END OF PREPROCESSOR DENSITY ***              '
255
echo '========================================================='
256
echo
257
 
258
# Run density
259
${LAGRANTO}/density/density
260
 
261
# Make clean
262
#\rm -f density.param
263
 
264
exit 0
265
 
266
 
267
 
268