Subversion Repositories lagranto.ocean

Rev

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