Subversion Repositories lagranto.um

Rev

Rev 3 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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