Subversion Repositories lagranto.20cr

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 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
 
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 -rotated
106
     set gridtype = 'rotated'
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 '-rotated     ->  ${clon}, ${clat}, ${nlonlat}, ${dlonlat}  (user defined)"
113
     shift;
114
     shift;
115
     shift;
116
     shift;
117
    breaksw
118
 
119
    case -index
120
       set sel_file   = $argv[2]
121
       set sel_format = 'index'
122
       echo "Flag '-index'     -> ${sel_file} (user defined)"
123
       shift;
124
   breaksw
125
 
126
   case -boolean
127
       set sel_file   = $argv[2]
128
       set sel_format = 'boolean'
129
       echo "Flag '-boolean'   -> ${sel_file} (user defined)"
130
       shift;
131
   breaksw
132
 
133
   case -field
134
       set field   = $argv[2]
135
       echo "Flag '-field'   -> ${field} (user defined)"
136
       shift;
137
   breaksw
138
 
139
  endsw
140
 
141
  shift;
142
 
143
end
144
 
145
# ---------------------------------------------------------------------
146
# Do some checks and preparation, then run the program
147
# ---------------------------------------------------------------------
148
 
149
# Rename field <time> to <TIME> to avoid conflict with time coordinate
150
# on the netCDF file
151
if ( "${field}" == "time" ) set field = "TIME"    
152
 
153
# Determine the time step 
154
if ( "${tratime}" == "all" ) then
155
    set step = 0
156
else
157
    set timelist = (`${LAGRANTO}/bin/trainfo.sh $inpfile times`) 
158
    set step     = 0
159
    set found    = 0
160
    foreach val ( ${timelist} )
161
       @ step = ${step} + 1
162
       if ( "${tratime}" == "${val}" ) then
163
          set found   = ${step}
164
       endif
165
     end
166
     if ( ${found} == 0 ) then
167
       echo "Invalid time ${tratime} for gridding"
168
       echo "${timelist}"
169
       exit 1
170
      endif
171
      set step = ${found}
172
endif
173
 
174
# Check consistency of arguments
175
if ( ( "${mode}" == "time" ) & ( ${step} != 0 ) ) then
176
    echo " ERROR: Options 'interp -time' and 'step' incompatible' "
177
    exit 1
178
endif
179
if ( ( "${mode}" == "space" ) & ( ${step} != 0 ) ) then
180
    echo " ERROR: Options 'interp -space' and 'step' incompatible' "
181
    exit 1
182
endif
183
 
184
# Get trajectory info
185
set ntra   = (`${LAGRANTO}/bin/trainfo.sh $inpfile ntra`)
186
set ntime  = (`${LAGRANTO}/bin/trainfo.sh $inpfile ntim`)
187
set nfield = (`${LAGRANTO}/bin/trainfo.sh $inpfile ncol`)
188
 
189
# Check whether selection file is available
190
if ( "${sel_file}" != "nil" ) then
191
   if ( ! -f ${sel_file} ) then
192
     echo " ERROR: selection file ${sel_file} is missing... Stop"
193
     exit 1
194
   endif
195
endif
196
 
197
# Check whether output file exists - set the <crefile> flag
198
if ( "${crefile}" == "0" ) then
199
   if ( ! -f ${outfile} ) then
200
       set crefile = 1
201
       echo
202
       echo "${outfile} will be created... "
203
   else
204
       echo
205
       echo "${outfile} will be modified ..."
206
   endif
207
else
208
   echo
209
   echo "${outfile} will be created... "
210
endif
211
 
212
# Chewck whether the variable exists - set the <crevar> flag
213
if ( "${crefile}" == "0" ) then    
214
    set varlist = ` ${LAGRANTO}/goodies/getvars ${outfile}` 
215
    set crevar  = 1
216
    foreach var ( ${varlist} )
217
       if ( "${var}" == "${field}" ) set crevar = 0
218
    end
219
else
220
   set crevar = 1
221
endif
222
 
223
# Prepare parameter file and run program
224
\rm -f density.param
225
touch density.param
226
echo ${inpfile}                 >> density.param
227
echo ${outfile}                 >> density.param
228
echo \"${field}\"               >> density.param
229
echo ${ntime} ${nfield} ${ntra} >> density.param
230
echo ${gridtype}                >> density.param
231
echo ${grid}                    >> density.param
232
echo ${radius} ${unit}          >> density.param
233
echo ${mode}                    >> density.param
234
echo ${param}                   >> density.param
235
echo ${step}                    >> density.param
236
echo \"${sel_file}\"            >> density.param
237
echo \"${sel_format}\"          >> density.param
238
echo ${crefile}                 >> density.param
239
echo ${crevar}                  >> density.param
240
 
241
# Write status info
242
echo 
243
echo '       *** END OF PREPROCESSOR DENSITY ***              '
244
echo '========================================================='
245
echo
246
 
247
# Run density
248
${LAGRANTO}/density/density
249
 
250
# Make clean
251
\rm -f density.param
252
 
253
exit 0
254
 
255
 
256
 
257