Subversion Repositories lagranto.wrf

Rev

Details | Last modification | View Log | RSS feed

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