Subversion Repositories lagranto.um

Rev

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

Rev 7 Rev 15
1
#!/bin/csh
1
#!/bin/csh
2
 
2
 
3
# ---------------------------------------------------------------------
3
# ---------------------------------------------------------------------
4
# Usage
4
# Usage
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) ) then
11
if ( (${#argv} == 0) ) then
9
  echo 
12
  echo 
10
  echo "-----------------------------------------------------------------------------------"
13
  echo "-----------------------------------------------------------------------------------"
11
  echo "Usage: "
14
  echo "Usage: "
12
  echo 
15
  echo 
13
  echo "  1. lagranto {caseid[.label]} startdate enddate {startf} {select} [flags] "
16
  echo "  1. lagranto {caseid[.label]} startdate enddate {startf} {select} [flags] "
14
  echo
17
  echo
15
  echo "         caseid     : case     (name of case directories; label appears in output directoy)"
18
  echo "         caseid     : case     (name of case directories; label appears in output directoy)"
16
  echo "                      local    (everything is run in local directory)"
19
  echo "                      local    (everything is run in local directory)"
17
  echo "                      interim  (take wind fields from Era-Interim)"
20
  echo "                      interim  (take wind fields from Era-Interim)"
18
  echo "                      analysis (take wind fields from ECMWF operational analysis)"
21
  echo "                      analysis (take wind fields from ECMWF operational analysis)"
19
  echo "                      forecast (take wind fields from ECMWF operational forecast)" 
22
  echo "                      forecast (take wind fields from ECMWF operational forecast)" 
20
  echo
23
  echo
21
  echo "         startdate  : start date in format yyyymmdd_hh(mm)"
24
  echo "         startdate  : start date in format yyyymmdd_hh(mm)"
22
  echo 
25
  echo 
23
  echo "         enddate    : end date in format yyyymmdd_hh(mm)"
26
  echo "         enddate    : end date in format yyyymmdd_hh(mm)"
24
  echo  
27
  echo  
25
  echo "         startf     : [ file | criterion ] with starting coordinates (lon,lat,p)"
28
  echo "         startf     : [ file | criterion ] with starting coordinates (lon,lat,p)"
26
  echo
29
  echo
27
  echo "         select     : [ file | criterion ] for trajectory selection (set 'nil' for none)"
30
  echo "         select     : [ file | criterion ] for trajectory selection (set 'nil' for none)"
28
  echo
31
  echo
29
  echo "         flags      : -o     outfile   (name of output trajectory file) "
32
  echo "         flags      : -o     outfile   (name of output trajectory file) "
30
  echo "                      -j               (jumping flag for crossing lower boundary)"
33
  echo "                      -j               (jumping flag for crossing lower boundary)"
31
  echo "                      -v     filename  (name of tracing file)"
34
  echo "                      -v     filename  (name of tracing file)"
32
  echo "                      -r     filename  (name of region file)"
35
  echo "                      -r     filename  (name of region file)"
33
  echo "                      -noclean         (do not clean trajectory directory after run)"
36
  echo "                      -noclean         (do not clean trajectory directory after run)"
34
  echo "                      -prep            (prepare run script, but do not run lagranto)"
37
  echo "                      -prep            (prepare run script, but do not run lagranto)"
35
  echo "                      -log             (logfile is written to screen instead of logfile)"
38
  echo "                      -log             (logfile is written to screen instead of logfile)"
36
  echo "                      -changet         (change times on netCDF files realtive to startdate)"
39
  echo "                      -changet         (change times on netCDF files realtive to startdate)"
37
  echo
40
  echo
38
  echo "  2. lagranto [ -open | -remove ] caseid[.label] "
41
  echo "  2. lagranto [ -open | -remove ] caseid[.label] "
39
  echo
42
  echo
40
  echo "        -open   : change to the run directory [open a new Xterm window]"
43
  echo "        -open   : change to the run directory [open a new Xterm window]"
41
  echo "        -remove : remove the whole run directory"
44
  echo "        -remove : remove the whole run directory"
42
  echo
45
  echo
43
  echo "Examples:"
46
  echo "Examples:"
44
  echo 
47
  echo 
45
  echo "-----------------------------------------------------------------------------------"
48
  echo "-----------------------------------------------------------------------------------"
46
  exit 0
49
  exit 0
47
endif
50
endif
48
 
51
 
49
# Check whether LAGRANTO was set with setenv
52
# Check whether LAGRANTO was set with setenv
50
set test = `setenv | grep LAGRANTO` 
53
set test = `setenv | grep LAGRANTO` 
51
if ( "${test}" == "" ) then
54
if ( "${test}" == "" ) then
52
   echo "---------------------------------------------------------------------"
55
   echo "---------------------------------------------------------------------"
53
   echo "Please set environmental variable <LAGRANTO> to your source directory"
56
   echo "Please set environmental variable <LAGRANTO> to your source directory"
54
   echo 'csh > setenv LAGRANTO ${TO_YOUR_LAGRANTO_INSTALLATION}'
57
   echo 'csh > setenv LAGRANTO ${TO_YOUR_LAGRANTO_INSTALLATION}'
55
   echo "---------------------------------------------------------------------"
58
   echo "---------------------------------------------------------------------"
56
   exit 1
59
   exit 1
57
endif
60
endif
58
  
61
  
59
# ---------------------------------------------------------------------
62
# ---------------------------------------------------------------------
60
# Set some general parameters
63
# Set some general parameters
61
# ---------------------------------------------------------------------
64
# ---------------------------------------------------------------------
62
 
65
 
63
# Set the prefix of the primary and secondary data files
66
# Set the prefix of the primary and secondary data files
64
set charp = 'P'
67
set charp = 'P'
65
set chars = 'S'
68
set chars = 'S'
66
 
69
 
67
# Set the name of the run script
70
# Set the name of the run script
68
set runscript = "runscript"
71
set runscript = "runscript"
69
 
72
 
70
# Remember the calling directory
73
# Remember the calling directory
71
set calldir = $PWD
74
set calldir = $PWD
72
 
75
 
73
# ---------------------------------------------------------------------
76
# ---------------------------------------------------------------------
74
# Parameter handling
77
# Parameter handling
75
# ---------------------------------------------------------------------
78
# ---------------------------------------------------------------------
76
 
79
 
77
# Write title
80
# Write title
78
echo
81
echo
79
echo '========================================================='
82
echo '========================================================='
80
echo '             *** START OF LAGRANTO ***             '
83
echo '             *** START OF LAGRANTO ***             '
81
echo
84
echo
82
 
85
 
83
# Save the complete argument list
86
# Save the complete argument list
84
set lagranto_call = "$*"
87
set lagranto_call = "$*"
85
 
88
 
86
echo '---- HANDLE ARGUMENTS -----------------------------------'
89
echo '---- HANDLE ARGUMENTS -----------------------------------'
87
echo
90
echo
88
 
91
 
89
# Get fixed arguments
92
# Get fixed arguments
90
if (${#argv} == 1) then
93
if (${#argv} == 1) then
91
  set mode = '-open'
94
  set mode = '-open'
92
  set caseid    = "$1"
95
  set caseid    = "$1"
93
  shift
96
  shift
94
 
97
 
95
else if (${#argv} == 2) then
98
else if (${#argv} == 2) then
96
  set mode      = "$1"
99
  set mode      = "$1"
97
  set caseid    = "$2"
100
  set caseid    = "$2"
98
  shift
101
  shift
99
  shift
102
  shift
100
 
103
 
101
else
104
else
102
  set caseid    = "$1"
105
  set caseid    = "$1"
103
  set startdate = "$2"
106
  set startdate = "$2"
104
  set enddate   = "$3"
107
  set enddate   = "$3"
105
  set startf    = "$4"
108
  set startf    = "$4"
106
  set select    = "$5"
109
  set select    = "$5"
107
  set mode      = "runlagranto"
110
  set mode      = "runlagranto"
108
  shift
111
  shift
109
  shift
112
  shift
110
  shift
113
  shift
111
  shift
114
  shift
112
  shift
115
  shift
113
 
116
 
114
endif
117
endif
115
 
118
 
116
# Split <caseid> into base and appendix 
119
# Split <caseid> into base and appendix 
117
set casebase = `(echo $caseid | awk -F "." '{print $1}')`   
120
set casebase = `(echo $caseid | awk -F "." '{print $1}')`   
118
set appendix = `(echo $caseid | awk -F "." '{print $2}')`   
121
set appendix = `(echo $caseid | awk -F "." '{print $2}')`   
119
if ( "${appendix}" != "" ) then
122
if ( "${appendix}" != "" ) then
120
  set appendix = ".${appendix}"
123
  set appendix = ".${appendix}"
121
endif
124
endif
122
 
125
 
123
# Set the directories (depending on <caseid>)
126
# Set the directories (depending on <caseid>)
124
if ( "${casebase}" == "local" ) then
127
if ( "${casebase}" == "local" ) then
125
  set cdfdir = $PWD
128
  set cdfdir = $PWD
126
  set tradir = $PWD
129
  set tradir = $PWD
127
 
130
 
128
else if ( "${casebase}" == "interim" ) then
131
else if ( "${casebase}" == "interim" ) then
129
  set cdfdir = /net/dansgaard/atmosdyn/erainterim/cdf/
132
  set cdfdir = /net/dansgaard/atmosdyn/erainterim/cdf/
130
  set tradir = $PWD
133
  set tradir = $PWD
131
 
134
 
132
else if ( "${casebase}" == "analysis" ) then
135
else if ( "${casebase}" == "analysis" ) then
133
  set cdfdir = 'TO_BE_SPECIFIED'
136
  set cdfdir = 'TO_BE_SPECIFIED'
134
  set tradir = $PWD
137
  set tradir = $PWD
135
  echo "ERROR: caseid (analysis) not yet implemented"
138
  echo "ERROR: caseid (analysis) not yet implemented"
136
  exit 1  
139
  exit 1  
137
 
140
 
138
else if ( "${casebase}" == "forecast" ) then
141
else if ( "${casebase}" == "forecast" ) then
139
  set cdfdir = 'TO_BE_SPECIFIED'
142
  set cdfdir = 'TO_BE_SPECIFIED'
140
  set tradir = $PWD
143
  set tradir = $PWD
141
  echo "ERROR: caseid (forecast) not yet implemented"
144
  echo "ERROR: caseid (forecast) not yet implemented"
142
  exit 1  
145
  exit 1  
143
 
146
 
144
else
147
else
145
  set cdfdir = ${HOME}/cdf/${casebase}
148
  set cdfdir = ${HOME}/cdf/${casebase}
146
  set tradir = ${HOME}/tra/${casebase}
149
  set tradir = ${HOME}/tra/${casebase}
147
endif
150
endif
148
 
151
 
149
# Change to the run directory if requested
152
# Change to the run directory if requested
150
if ( "${mode}" == "-open" ) then
153
if ( "${mode}" == "-open" ) then
151
   set count = 0   
154
   set count = 0   
152
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
155
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
153
     @ count = ${count} + 1
156
     @ count = ${count} + 1
154
     echo "[${count}] ${folder}"
157
     echo "[${count}] ${folder}"
155
   end
158
   end
156
   echo
159
   echo
157
   echo "Please select directory [0...${count}]"
160
   echo "Please select directory [0...${count}]"
158
   set id = $<
161
   set id = $<
159
   set count = 0   
162
   set count = 0   
160
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
163
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
161
     @ count = ${count} + 1
164
     @ count = ${count} + 1
162
     if ( "${count}" == "${id}" ) then 
165
     if ( "${count}" == "${id}" ) then 
163
        cd ${folder}
166
        cd ${folder}
164
        xterm &
167
        xterm &
165
     endif
168
     endif
166
   end
169
   end
167
   exit 0
170
   exit 0
168
endif
171
endif
169
 
172
 
170
# Remove the whole run directory if requested
173
# Remove the whole run directory if requested
171
if ( "${mode}" == "-remove" ) then
174
if ( "${mode}" == "-remove" ) then
172
   set count = 0   
175
   set count = 0   
173
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
176
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
174
     @ count = ${count} + 1
177
     @ count = ${count} + 1
175
     echo "[${count}] ${folder}"
178
     echo "[${count}] ${folder}"
176
   end
179
   end
177
   echo
180
   echo
178
   echo "Please select directory [0...${count}, all]"
181
   echo "Please select directory [0...${count}, all]"
179
   set id = $<
182
   set id = $<
180
   set count = 0   
183
   set count = 0   
181
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
184
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
182
     @ count = ${count} + 1
185
     @ count = ${count} + 1
183
     if ( ( "${count}" == "${id}" ) | ( "${id}" == "all" ) ) then 
186
     if ( ( "${count}" == "${id}" ) | ( "${id}" == "all" ) ) then 
184
        \rm -r ${folder}
187
        \rm -r ${folder}
185
     endif
188
     endif
186
   end
189
   end
187
   exit 0
190
   exit 0
188
endif
191
endif
189
 
192
 
190
# Show the trajectory file
193
# Show the trajectory file
191
if ( "${mode}" == "-show" ) then
194
if ( "${mode}" == "-show" ) then
192
   set count = 0   
195
   set count = 0   
193
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
196
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
194
     @ count = ${count} + 1
197
     @ count = ${count} + 1
195
     echo "[${count}] ${folder}"
198
     echo "[${count}] ${folder}"
196
   end
199
   end
197
   echo
200
   echo
198
   echo "Please select directory [0...${count}]"
201
   echo "Please select directory [0...${count}]"
199
   set id = $<
202
   set id = $<
200
   set count = 0   
203
   set count = 0   
201
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
204
   foreach folder ( ${tradir}/ntr_*_${caseid}_* )
202
     @ count = ${count} + 1
205
     @ count = ${count} + 1
203
     if ( "${count}" == "${id}" ) then 
206
     if ( "${count}" == "${id}" ) then 
204
        cd ${folder}
207
        cd ${folder}
205
        set filename = ` sed -ne '9,9p' runscript.sh | cut -c 2-` 
208
        set filename = ` sed -ne '9,9p' runscript.sh | cut -c 2-` 
206
	${LAGRANTO}/goodies/trainfo.sh ${filename} list | less
209
	${LAGRANTO}/goodies/trainfo.sh ${filename} list | less
207
     endif
210
     endif
208
   end
211
   end
209
   exit 0
212
   exit 0
210
endif
213
endif
211
 
214
 
212
# Decide whether <select> is a file or an explicit criterion
215
# Decide whether <select> is a file or an explicit criterion
213
set flag_select = 'file'
216
set flag_select = 'file'
214
set test = `echo ${select} | grep ':' | wc -c`
217
set test = `echo ${select} | grep ':' | wc -c`
215
if ( "${test}" != "0" ) then 
218
if ( "${test}" != "0" ) then 
216
  set flag_select = 'criterion'
219
  set flag_select = 'criterion'
217
endif
220
endif
218
 
221
 
219
# Decide whether <startf> is a file or an explicit criterion
222
# Decide whether <startf> is a file or an explicit criterion
220
set flag_startf = 'file'
223
set flag_startf = 'file'
221
 
224
 
222
set test = `echo ${startf} | grep ' ' | wc -c`
225
set test = `echo ${startf} | grep ' ' | wc -c`
223
if ( "${test}" != "0" ) then 
226
if ( "${test}" != "0" ) then 
224
  set flag_startf = 'point'
227
  set flag_startf = 'point'
225
endif
228
endif
226
 
229
 
227
set test = `echo ${startf} | grep '@' | wc -c`
230
set test = `echo ${startf} | grep '@' | wc -c`
228
if ( "${test}" != "0" ) then 
231
if ( "${test}" != "0" ) then 
229
  set flag_startf = 'criterion'
232
  set flag_startf = 'criterion'
230
endif
233
endif
231
 
234
 
232
 
235
 
233
# Write some status information
236
# Write some status information
234
echo " Case ID       : ${caseid}"
237
echo " Case ID       : ${caseid}"
235
echo " Start date    : ${startdate}"
238
echo " Start date    : ${startdate}"
236
echo " End date      : ${enddate}"
239
echo " End date      : ${enddate}"
237
 
240
 
238
if ( "${flag_startf}" == "criterion" ) then
241
if ( "${flag_startf}" == "criterion" ) then
239
    echo " Start file    : ${startf} [criterion] -> startf.criterion [file]"
242
    echo " Start file    : ${startf} [criterion] -> startf.criterion [file]"
240
else if ( "${flag_startf}" == "file" ) then
243
else if ( "${flag_startf}" == "file" ) then
241
    echo " Start points  : ${startf} [file]"
244
    echo " Start points  : ${startf} [file]"
242
else if ( "${flag_startf}" == "point" ) then
245
else if ( "${flag_startf}" == "point" ) then
243
    echo " Start points  : ${startf} [point] -> startf [file]"
246
    echo " Start points  : ${startf} [point] -> startf [file]"
244
endif
247
endif
245
 
248
 
246
if ( "${flag_select}" == "criterion" ) then
249
if ( "${flag_select}" == "criterion" ) then
247
    echo " Selection     : ${select} [criterion] -> selectf.criterion [file]"
250
    echo " Selection     : ${select} [criterion] -> selectf.criterion [file]"
248
else
251
else
249
    echo " Selection     : ${select} [file]"
252
    echo " Selection     : ${select} [file]"
250
endif    
253
endif    
251
 
254
 
252
echo
255
echo
253
 
256
 
254
# Set defaults for flags
257
# Set defaults for flags
255
set jumpflag   = ""
258
set jumpflag   = ""
256
set tracefile  = "tracevars"
259
set tracefile  = "tracevars"
257
set outfile    = "lsl_${startdate}"
260
set outfile    = "lsl_${startdate}"
258
set keepflag   = ""
261
set keepflag   = ""
259
set prepflag   = ""
262
set prepflag   = ""
260
set logfile    = "${runscript}.logfile"
263
set logfile    = "${runscript}.logfile"
261
set regionf    = "regionf"
264
set regionf    = "regionf"
262
set changet    = "false"
265
set changet    = "false"
263
 
266
 
264
# Handle flags
267
# Handle flags
265
while ( $#argv > 0 )
268
while ( $#argv > 0 )
266
 
269
 
267
  switch ( $argv[1] )
270
  switch ( $argv[1] )
268
 
271
 
269
  echo $argv[1]
272
  echo $argv[1]
270
 
273
 
271
   case -j
274
   case -j
272
     set jumpflag = "-j"
275
     set jumpflag = "-j"
273
     echo " Flag '-j [jump]'             -> True "
276
     echo " Flag '-j [jump]'             -> True "
274
     echo
277
     echo
275
   breaksw
278
   breaksw
276
 
279
 
277
   case -prep
280
   case -prep
278
     set prepflag = "prep"
281
     set prepflag = "prep"
279
     echo " Flag '-prep [prepare only]'  -> ${prepflag} "
282
     echo " Flag '-prep [prepare only]'  -> ${prepflag} "
280
     echo
283
     echo
281
   breaksw
284
   breaksw
282
 
285
 
283
   case -noclean
286
   case -noclean
284
    set keepflag = "keep"
287
    set keepflag = "keep"
285
     echo " Flag '-noclean [no cleaning]' -> ${keepflag} "
288
     echo " Flag '-noclean [no cleaning]' -> ${keepflag} "
286
     echo
289
     echo
287
   breaksw
290
   breaksw
288
 
291
 
289
   case -o
292
   case -o
290
     set outfile =  $argv[2]
293
     set outfile =  $argv[2]
291
     echo " Flag '-o [output]'            -> ${outfile} "
294
     echo " Flag '-o [output]'            -> ${outfile} "
292
     echo
295
     echo
293
   breaksw
296
   breaksw
294
 
297
 
295
   case -v
298
   case -v
296
     set tracefile = $argv[2]
299
     set tracefile = $argv[2]
297
     echo " Flag '-v [tracevars]'         -> ${tracefile} "
300
     echo " Flag '-v [tracevars]'         -> ${tracefile} "
298
     echo
301
     echo
299
     shift
302
     shift
300
   breaksw
303
   breaksw
301
 
304
 
302
   case -r
305
   case -r
303
     set regionfile = $argv[2]
306
     set regionfile = $argv[2]
304
     echo " Flag '-r [regionfile]'        -> ${regionfile} "
307
     echo " Flag '-r [regionfile]'        -> ${regionfile} "
305
     echo
308
     echo
306
     shift
309
     shift
307
   breaksw
310
   breaksw
308
 
311
 
309
   case -log
312
   case -log
310
     set logfile = "/dev/stdout"
313
     set logfile = "/dev/stdout"
311
     echo " Flag '-v [log]'               -> ${logfile} "
314
     echo " Flag '-v [log]'               -> ${logfile} "
312
   breaksw
315
   breaksw
313
 
316
 
314
   case -changet
317
   case -changet
315
     set changet = "true"
318
     set changet = "true"
316
     echo " Flag '-changet [change times]'-> True "
319
     echo " Flag '-changet [change times]'-> True "
317
     echo
320
     echo
318
   breaksw
321
   breaksw
319
 
322
 
320
  endsw
323
  endsw
321
 
324
 
322
  shift;
325
  shift;
323
 
326
 
324
end
327
end
325
 
328
 
326
# Decide whether a tracevars file is given or not
329
# Decide whether a tracevars file is given or not
327
if ( -f ${tradir}/${tracefile} ) then
330
if ( -f ${tradir}/${tracefile} ) then
328
   set flag_tracevars = 'file'
331
   set flag_tracevars = 'file'
329
else
332
else
330
   set flag_tracevars = 'nil'
333
   set flag_tracevars = 'nil'
331
endif
334
endif
332
 
335
 
333
echo
336
echo
334
if ( "${flag_tracevars}" == "file" ) then
337
if ( "${flag_tracevars}" == "file" ) then
335
    echo " Trace Vars    : ${tracefile} [file]"
338
    echo " Trace Vars    : ${tracefile} [file]"
336
else
339
else
337
    echo " Trace Vars    : [no fields are traced]"
340
    echo " Trace Vars    : [no fields are traced]"
338
endif    
341
endif    
339
echo
342
echo
340
 
343
 
341
# Set the name of the run directory (forward/backward distinction)
344
# Set the name of the run directory (forward/backward distinction)
342
set dir   = 'f'
345
set dir   = 'f'
343
set range = `${LAGRANTO}/bin/gettidiff.sh ${enddate} ${startdate}`
346
set range = `${LAGRANTO}/bin/gettidiff.sh ${enddate} ${startdate}`
344
if ( ${range} < 0 ) then
347
if ( ${range} < 0 ) then
345
  set dir   = 'b'
348
  set dir   = 'b'
346
  set range = `${LAGRANTO}/bin/gettidiff.sh ${startdate} ${enddate}`
349
  set range = `${LAGRANTO}/bin/gettidiff.sh ${startdate} ${enddate}`
347
endif
350
endif
348
set rundir = ${tradir}/ntr_${startdate}_${dir}${range}_${caseid}
351
set rundir = ${tradir}/ntr_${startdate}_${dir}${range}_${caseid}
349
 
352
 
350
if ( "${flag_startf}" == "criterion" ) then
353
if ( "${flag_startf}" == "criterion" ) then
351
  set rundir = "${rundir}_startf"
354
  set rundir = "${rundir}_startf"
352
else if ( "${flag_startf}" == "point" ) then
355
else if ( "${flag_startf}" == "point" ) then
353
  set rundir = "${rundir}_startf"
356
  set rundir = "${rundir}_startf"
354
else if ( "${flag_startf}" == "file" ) then
357
else if ( "${flag_startf}" == "file" ) then
355
  set rundir = "${rundir}_${startf}"
358
  set rundir = "${rundir}_${startf}"
356
endif
359
endif
357
 
360
 
358
if (  "${flag_select}" != "file" ) then
361
if (  "${flag_select}" != "file" ) then
359
  set rundir = "${rundir}_selectf"
362
  set rundir = "${rundir}_selectf"
360
else
363
else
361
 set rundir = "${rundir}_${select}"
364
 set rundir = "${rundir}_${select}"
362
endif
365
endif
363
 
366
 
364
# Write directory names
367
# Write directory names
365
echo '---- DIRECTORIES ----------------------------------------'
368
echo '---- DIRECTORIES ----------------------------------------'
366
echo
369
echo
367
echo " CDF = ${cdfdir}"
370
echo " CDF = ${cdfdir}"
368
echo " TRA = ${tradir}"
371
echo " TRA = ${tradir}"
369
echo " RUN = ${rundir}"
372
echo " RUN = ${rundir}"
370
 
373
 
371
# Check whether CDF and TRA directories exist
374
# Check whether CDF and TRA directories exist
372
if ( ! -d ${cdfdir} ) then
375
if ( ! -d ${cdfdir} ) then
373
    echo 'Cannot find CDF directory ... Stop'
376
    echo 'Cannot find CDF directory ... Stop'
374
    exit 1
377
    exit 1
375
endif
378
endif
376
if ( ! -d ${tradir} ) then
379
if ( ! -d ${tradir} ) then
377
    echo 'Cannot find TRA directory ... Stop'
380
    echo 'Cannot find TRA directory ... Stop'
378
    exit 1
381
    exit 1
379
endif
382
endif
380
 
383
 
381
# Create the run directory
384
# Create the run directory
382
if ( ! -d ${rundir} ) then
385
if ( ! -d ${rundir} ) then
383
   mkdir ${rundir}
386
   mkdir ${rundir}
384
endif 
387
endif 
385
if ( ! -d ${rundir} ) then
388
if ( ! -d ${rundir} ) then
386
    echo 'Cannot create RUN directory ... Stop'
389
    echo 'Cannot create RUN directory ... Stop'
387
    exit 1
390
    exit 1
388
endif 
391
endif 
389
 
392
 
390
# ---------------------------------------------------------------------
393
# ---------------------------------------------------------------------
391
# Handle the time specifier - startdate, enddate
394
# Handle the time specifier - startdate, enddate
392
# ---------------------------------------------------------------------
395
# ---------------------------------------------------------------------
393
 
396
 
394
echo
397
echo
395
echo '---- TIME RANGE -----------------------------------------'
398
echo '---- TIME RANGE -----------------------------------------'
396
echo
399
echo
397
 
400
 
398
# Check format of start and end date - must be the same
401
# Check format of start and end date - must be the same
399
set ns=`echo $startdate | sed -e 's/_[0-9]*//' | wc -c`
402
set ns=`echo $startdate | sed -e 's/_[0-9]*//' | wc -c`
400
set ne=`echo $enddate   | sed -e 's/_[0-9]*//' | wc -c`
403
set ne=`echo $enddate   | sed -e 's/_[0-9]*//' | wc -c`
401
if ( $ns != $ne ) then
404
if ( $ns != $ne ) then
402
  echo " ERROR: start and end date must be in the same format ***"
405
  echo " ERROR: start and end date must be in the same format ***"
403
  exit 1
406
  exit 1
404
endif
407
endif
405
if ( $ns != 9 ) then
408
if ( $ns != 9 ) then
406
  echo " ERROR: Date format must be yyyymmdd ***"
409
  echo " ERROR: Date format must be yyyymmdd ***"
407
  exit 1
410
  exit 1
408
endif
411
endif
409
set ns=`echo $startdate | sed -e 's/[0-9]*_//' | wc -c`
412
set ns=`echo $startdate | sed -e 's/[0-9]*_//' | wc -c`
410
set ne=`echo $enddate   | sed -e 's/[0-9]*_//' | wc -c`
413
set ne=`echo $enddate   | sed -e 's/[0-9]*_//' | wc -c`
411
if ( $ns != $ne ) then
414
if ( $ns != $ne ) then
412
  echo " ERROR: start and end date must be in the same format ***"
415
  echo " ERROR: start and end date must be in the same format ***"
413
  exit 1
416
  exit 1
414
endif
417
endif
415
if ( ( $ns != 5 ) & ( $ns != 3 ) ) then
418
if ( ( $ns != 5 ) & ( $ns != 3 ) ) then
416
  echo " ERROR: Time format must be hh(mm) ***"
419
  echo " ERROR: Time format must be hh(mm) ***"
417
  exit 1
420
  exit 1
418
endif
421
endif
419
 
422
 
420
# Split the start and end date into <yymmdd_hh and mm>
423
# Split the start and end date into <yymmdd_hh and mm>
421
set startdate_ymdh = `echo $startdate | cut -c 1-11`
424
set startdate_ymdh = `echo $startdate | cut -c 1-11`
422
set startdate_min  = `echo $startdate | cut -c 12-13`
425
set startdate_min  = `echo $startdate | cut -c 12-13`
423
if ( $startdate_min == "" ) set startdate_min = 00
426
if ( $startdate_min == "" ) set startdate_min = 00
424
 
427
 
425
set enddate_ymdh = `echo $enddate | cut -c 1-11`
428
set enddate_ymdh = `echo $enddate | cut -c 1-11`
426
set enddate_min  = `echo $enddate | cut -c 12-13`
429
set enddate_min  = `echo $enddate | cut -c 12-13`
427
if ( $enddate_min == "" ) set enddate_min = 00
430
if ( $enddate_min == "" ) set enddate_min = 00
428
 
431
 
429
# Get the time difference between <start_ymdh> and <end_ymdh> date
432
# Get the time difference between <start_ymdh> and <end_ymdh> date
430
# Decide whether trajectoriesare forward or backward
433
# Decide whether trajectoriesare forward or backward
431
set timediff_hh = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${startdate_ymdh}`
434
set timediff_hh = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${startdate_ymdh}`
432
 
435
 
433
if ( $timediff_hh == 0 ) then
436
if ( $timediff_hh == 0 ) then
434
  if ( $enddate_min > $startdate_min ) then
437
  if ( $enddate_min > $startdate_min ) then
435
    set direction = f
438
    set direction = f
436
    set idir      = 1
439
    set idir      = 1
437
  else
440
  else
438
    set direction = b
441
    set direction = b
439
    set idir      = -1
442
    set idir      = -1
440
  endif
443
  endif
441
else if ( $timediff_hh > 0 ) then
444
else if ( $timediff_hh > 0 ) then
442
  set direction = f
445
  set direction = f
443
  set idir      = 1
446
  set idir      = 1
444
else
447
else
445
  set direction = b
448
  set direction = b
446
  set idir      = -1
449
  set idir      = -1
447
  @ timediff_hh = $idir * $timediff_hh
450
  @ timediff_hh = $idir * $timediff_hh
448
endif
451
endif
449
 
452
 
450
# Get also minutes for time difference, if <start_min> or <end_min> != 0
453
# Get also minutes for time difference, if <start_min> or <end_min> != 0
451
set timediff_mm=
454
set timediff_mm=
452
 
455
 
453
if ( $startdate_min != 00 || $enddate_min != 00 ) then
456
if ( $startdate_min != 00 || $enddate_min != 00 ) then
454
  @ min = ( $enddate_min - $startdate_min )
457
  @ min = ( $enddate_min - $startdate_min )
455
  if ( $min == 0 ) then
458
  if ( $min == 0 ) then
456
    set timediff_mm=
459
    set timediff_mm=
457
  else if ( $min > 0 ) then
460
  else if ( $min > 0 ) then
458
    if ( $idir == 1 ) then
461
    if ( $idir == 1 ) then
459
      set timediff_mm=$min
462
      set timediff_mm=$min
460
    else
463
    else
461
      @ timediff_hh --
464
      @ timediff_hh --
462
      @ timediff_mm = 60 - $min
465
      @ timediff_mm = 60 - $min
463
    endif
466
    endif
464
  else
467
  else
465
    if ( $idir == 1 ) then
468
    if ( $idir == 1 ) then
466
      @ timediff_hh --
469
      @ timediff_hh --
467
      @ timediff_mm = 60 + $min
470
      @ timediff_mm = 60 + $min
468
    else
471
    else
469
      @ timediff_mm = 0 - $min
472
      @ timediff_mm = 0 - $min
470
    endif
473
    endif
471
  endif
474
  endif
472
endif
475
endif
473
 
476
 
474
# Set the reference date equal to the startdate
477
# Set the reference date equal to the startdate
475
set refdate=${startdate}
478
set refdate=${startdate}
476
 
479
 
477
# Write status information
480
# Write status information
478
echo "Time range      : ${startdate} -> ${enddate}"
481
echo "Time range      : ${startdate} -> ${enddate}"
479
if ( ${timediff_mm} !=  "" ) then
482
if ( ${timediff_mm} !=  "" ) then
480
   echo "Time difference : ${timediff_hh} h ${timediff_mm} min"
483
   echo "Time difference : ${timediff_hh} h ${timediff_mm} min"
481
else
484
else
482
   echo "Time difference : ${timediff_hh} h"
485
   echo "Time difference : ${timediff_hh} h"
483
endif
486
endif
484
echo "Direction       : ${direction} (${idir})"
487
echo "Direction       : ${direction} (${idir})"
485
echo "Reference date  : ${refdate}"
488
echo "Reference date  : ${refdate}"
486
 
489
 
487
# ---------------------------------------------------------------------
490
# ---------------------------------------------------------------------
488
# Decide which files are needed and check availability
491
# Decide which files are needed and check availability
489
# ---------------------------------------------------------------------
492
# ---------------------------------------------------------------------
490
 
493
 
491
echo
494
echo
492
echo '---- INPUT FILES ----------------------------------------'
495
echo '---- INPUT FILES ----------------------------------------'
493
echo
496
echo
494
 
497
 
495
# Change to input data (cdf) directory
498
# Change to input data (cdf) directory
496
cd ${cdfdir}
499
cd ${cdfdir}
497
echo
500
echo
498
 
501
 
499
# Take the time increment from flag list ('nil', if not defined)
502
# Take the time increment from flag list ('nil', if not defined)
500
set timeinc = 'nil'
503
set timeinc = 'nil'
501
 
504
 
502
# Find a first data file (if possible corresponding to start/end date
505
# Find a first data file (if possible corresponding to start/end date
503
# If starttime is not a data time, take the first file in the direectory
506
# If starttime is not a data time, take the first file in the direectory
504
if ( $direction == "f" ) then
507
if ( $direction == "f" ) then
505
  set file=${charp}${startdate_ymdh}
508
  set file=${charp}${startdate_ymdh}
506
else
509
else
507
  set file=${charp}${enddate_ymdh}
510
  set file=${charp}${enddate_ymdh}
508
endif
511
endif
509
if ( ! -f $file ) then
512
if ( ! -f $file ) then
510
  set file=`ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
513
  set file=`ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
511
endif
514
endif
512
 
515
 
513
# Determine timeinc (the time difference in hours between two data file)
516
# Determine timeinc (the time difference in hours between two data file)
514
# if not already defined with option -i
517
# if not already defined with option -i
515
if ( ${timeinc} == "nil" ) then
518
if ( ${timeinc} == "nil" ) then
516
  set date1=`echo $file | cut -c 2-12`
519
  set date1=`echo $file | cut -c 2-12`
517
  set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
520
  set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
518
  @ n ++
521
  @ n ++
519
  set date2=`ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-12`
522
  set date2=`ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-12`
520
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
523
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
521
endif
524
endif
522
if ( $timeinc == 0 ) then
525
if ( $timeinc == 0 ) then
523
    echo " ERROR: cannot set the time increment between input files ***"
526
    echo " ERROR: cannot set the time increment between input files ***"
524
    exit 1
527
    exit 1
525
endif
528
endif
526
 
529
 
527
# Search the first file to use
530
# Search the first file to use
528
set flag=0
531
set flag=0
529
set td=
532
set td=
530
foreach i ( ${charp}????????_?? )
533
foreach i ( ${charp}????????_?? )
531
 
534
 
532
  set date = `echo $i | cut -c 2-12`
535
  set date = `echo $i | cut -c 2-12`
533
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
536
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
534
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
537
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
535
 
538
 
536
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
539
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
537
      set datfiles=$date
540
      set datfiles=$date
538
      if ( $td1 < $timeinc    ) set td=$td1
541
      if ( $td1 < $timeinc    ) set td=$td1
539
      if ( $td2 < $timeinc    ) set td=$td2
542
      if ( $td2 < $timeinc    ) set td=$td2
540
      if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++ 
543
      if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++ 
541
      goto label2
544
      goto label2
542
  endif
545
  endif
543
 
546
 
544
end
547
end
545
 
548
 
546
# if no P/T-files are available for the specified time period, then $td is
549
# if no P/T-files are available for the specified time period, then $td is
547
# still undefined
550
# still undefined
548
if ( $td == "" ) then
551
if ( $td == "" ) then
549
  echo " ERROR: no data files available for the specified time period"
552
  echo " ERROR: no data files available for the specified time period"
550
  exit 1
553
  exit 1
551
endif
554
endif
552
 
555
 
553
# Everything is fine so far: proceed
556
# Everything is fine so far: proceed
554
label2:
557
label2:
555
 
558
 
556
# Calculate the number of further files
559
# Calculate the number of further files
557
@ num = ( $timediff_hh + $td ) / $timeinc + 1
560
@ num = ( $timediff_hh + $td ) / $timeinc + 1
558
@ dum1 = ( $num - 1 ) * $timeinc
561
@ dum1 = ( $num - 1 ) * $timeinc
559
@ dum2 = $timediff_hh + $td
562
@ dum2 = $timediff_hh + $td
560
if ( $dum1 != $dum2 ) @ num ++
563
if ( $dum1 != $dum2 ) @ num ++
561
 
564
 
562
# Get a list of all needed files
565
# Get a list of all needed files
563
set numfiles=$num
566
set numfiles=$num
564
set sfiles=1
567
set sfiles=1
565
while ( $num > 1 )
568
while ( $num > 1 )
566
  set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
569
  set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
567
  if ( ! -f ${charp}${date} ) then
570
  if ( ! -f ${charp}${date} ) then
568
    echo " ERROR: file with primary data is missing for $date"
571
    echo " ERROR: file with primary data is missing for $date"
569
    exit 1
572
    exit 1
570
  else if ( ! -f ${chars}${date} ) then
573
  else if ( ! -f ${chars}${date} ) then
571
    set sfiles=0
574
    set sfiles=0
572
    set datfiles=`echo $datfiles $date`
575
    set datfiles=`echo $datfiles $date`
573
  else
576
  else
574
    set datfiles=`echo $datfiles $date`
577
    set datfiles=`echo $datfiles $date`
575
  endif
578
  endif
576
  @ num --
579
  @ num --
577
end
580
end
578
 
581
 
579
# Write some status information
582
# Write some status information
580
echo "Primary file prefix            : ${charp}"
583
echo "Primary file prefix            : ${charp}"
581
echo "Secondary file prefix          : ${chars}"
584
echo "Secondary file prefix          : ${chars}"
582
echo "Time increment for input files : ${timeinc}"
585
echo "Time increment for input files : ${timeinc}"
583
echo "# input files                  : ${numfiles}"
586
echo "# input files                  : ${numfiles}"
584
echo "${charp} files availability           : 1"  
587
echo "${charp} files availability           : 1"  
585
echo "${chars} files availability           : ${sfiles}"     
588
echo "${chars} files availability           : ${sfiles}"     
586
echo "First input file               : $datfiles[1] " 
589
echo "First input file               : $datfiles[1] " 
587
echo "Last input file                : $datfiles[$numfiles] " 
590
echo "Last input file                : $datfiles[$numfiles] " 
588
 
591
 
589
 
592
 
590
# ---------------------------------------------------------------------
593
# ---------------------------------------------------------------------
591
# Prepare run directory - copy all needed files
594
# Prepare run directory - copy all needed files
592
# ---------------------------------------------------------------------
595
# ---------------------------------------------------------------------
593
 
596
 
594
echo
597
echo
595
echo '---- PREPARE RUN DIRECTORY ------------------------------'
598
echo '---- PREPARE RUN DIRECTORY ------------------------------'
596
echo
599
echo
597
 
600
 
598
# Change to run directory
601
# Change to run directory
599
cd ${rundir}
602
cd ${rundir}
600
echo
603
echo
601
 
604
 
602
 
605
 
603
# Link cdf input files
606
# Link cdf input files
604
foreach date ( $datfiles )
607
foreach date ( $datfiles )
605
  if ( -f ${cdfdir}/${charp}${date} ) then
608
  if ( -f ${cdfdir}/${charp}${date} ) then
606
     if ( ! -f  ${charp}${date} ) then
609
     if ( ! -f  ${charp}${date} ) then
607
        ln -s  ${cdfdir}/${charp}${date}  ${charp}${date}
610
        ln -s  ${cdfdir}/${charp}${date}  ${charp}${date}
608
        echo "Linking  ${date} "
611
        echo "Linking  ${date} "
609
     else
612
     else
610
        echo "Existing ${date} "
613
        echo "Existing ${date} "
611
     endif
614
     endif
612
  endif
615
  endif
613
  if ( -f ${cdfdir}/${chars}${date} ) then
616
  if ( -f ${cdfdir}/${chars}${date} ) then
614
     if ( ! -f  ${chars}${date} ) then
617
     if ( ! -f  ${chars}${date} ) then
615
        ln -sf  ${cdfdir}/${chars}${date}  ${chars}${date}
618
        ln -sf  ${cdfdir}/${chars}${date}  ${chars}${date}
616
     endif
619
     endif
617
  endif
620
  endif
618
end
621
end
619
 
622
 
620
# Change times on netCDF files relative to reference date
623
# Change times on netCDF files relative to reference date
621
if ( "${changet}" == "true" ) then
624
if ( "${changet}" == "true" ) then
622
 echo
625
 echo
623
 foreach i ( $datfiles )
626
 foreach i ( $datfiles )
624
   ${LAGRANTO}/goodies/changet.sh ${refdate} ${charp}${i}
627
   ${LAGRANTO}/goodies/changet.sh ${refdate} ${charp}${i}
625
 end
628
 end
626
 if ( ${sfiles} == 1 ) then
629
 if ( ${sfiles} == 1 ) then
627
   echo
630
   echo
628
   foreach i ( $datfiles )
631
   foreach i ( $datfiles )
629
     ${LAGRANTO}/goodies/changet.sh ${refdate} ${chars}${i}
632
     ${LAGRANTO}/goodies/changet.sh ${refdate} ${chars}${i}
630
   end
633
   end
631
 endif
634
 endif
632
endif
635
endif
633
 
636
 
634
# Get the constants file for each file
637
# Get the constants file for each file
635
set first = 1
638
set first = 1
636
foreach date ( $datfiles )
639
foreach date ( $datfiles )
637
  set cstname = `ncdump -h ${charp}${date} | grep constants_file_name`
640
  set cstname = `ncdump -h ${charp}${date} | grep constants_file_name`
638
  set cstname = `echo \'${cstname}\' |   awk -F\" '{print $2}'`
641
  set cstname = `echo \'${cstname}\' |   awk -F\" '{print $2}'`
639
  if ( -f ${cdfdir}/${cstname} ) then
642
  if ( -f ${cdfdir}/${cstname} ) then
640
    if ( ! -f ${cstname} ) then
643
    if ( ! -f ${cstname} ) then
641
       ln -s  ${cdfdir}/${cstname}  ${cstname}
644
       ln -s  ${cdfdir}/${cstname}  ${cstname}
642
       echo "Linking  constants file ${cstname}"
645
       echo "Linking  constants file ${cstname}"
643
       set first = 0
646
       set first = 0
644
    else if ( "${first}" == "1" ) then
647
    else if ( "${first}" == "1" ) then
645
       echo "Existing constants file ${cstname}"
648
       echo "Existing constants file ${cstname}"
646
       set first = 0
649
       set first = 0
647
    endif
650
    endif
648
  endif
651
  endif
649
end
652
end
650
 
653
 
651
# Copy the tracevars file
654
# Copy the tracevars file
652
if ( "${flag_tracevars}" == "file" ) then
655
if ( "${flag_tracevars}" == "file" ) then
653
   if ( -f ${tradir}/${tracefile} ) then
656
   if ( -f ${tradir}/${tracefile} ) then
654
      \cp ${tradir}/${tracefile} .
657
      \cp ${tradir}/${tracefile} .
655
   endif
658
   endif
656
endif
659
endif
657
 
660
 
658
# Copy the start file/criterion
661
# Copy the start file/criterion
659
if ( "${flag_startf}" == "criterion" ) then
662
if ( "${flag_startf}" == "criterion" ) then
660
   \rm -f startf.criterion
663
   \rm -f startf.criterion
661
   echo ${startf} > startf.criterion
664
   echo ${startf} > startf.criterion
662
   set startf =  "startf.criterion"
665
   set startf =  "startf.criterion"
663
else if ( "${flag_startf}" == "file" ) then
666
else if ( "${flag_startf}" == "file" ) then
664
   if ( -f ${tradir}/${startf} ) then
667
   if ( -f ${tradir}/${startf} ) then
665
     \cp ${tradir}/${startf} .
668
     \cp ${tradir}/${startf} .
666
   endif
669
   endif
667
else if ( "${flag_startf}" == "point" ) then
670
else if ( "${flag_startf}" == "point" ) then
668
   \rm -f startf
671
   \rm -f startf
669
   echo ${startf}  > startf
672
   echo ${startf}  > startf
670
   set startf      =  "startf"
673
   set startf      =  "startf"
671
   set flag_startf = "file"
674
   set flag_startf = "file"
672
endif 
675
endif 
673
 
676
 
674
# Copy the select file/criterion
677
# Copy the select file/criterion
675
if ( "${flag_select}" == "criterion" ) then
678
if ( "${flag_select}" == "criterion" ) then
676
   \rm -f select.criterion
679
   \rm -f select.criterion
677
   echo ${select} > select.criterion
680
   echo ${select} > select.criterion
678
   set select = "select.criterion"
681
   set select = "select.criterion"
679
else
682
else
680
   if ( -f ${tradir}/${select} ) then
683
   if ( -f ${tradir}/${select} ) then
681
     \cp ${tradir}/${select} .
684
     \cp ${tradir}/${select} .
682
   endif
685
   endif
683
endif 
686
endif 
684
 
687
 
685
 
688
 
686
# ---------------------------------------------------------------------
689
# ---------------------------------------------------------------------
687
# Prepare the run script
690
# Prepare the run script
688
# ---------------------------------------------------------------------
691
# ---------------------------------------------------------------------
689
 
692
 
690
echo
693
echo
691
echo '---- PREPARE RUN SCRIPT ---------------------------------'
694
echo '---- PREPARE RUN SCRIPT ---------------------------------'
692
echo
695
echo
693
 
696
 
694
# Remove runscript if it already exists
697
# Remove runscript if it already exists
695
if ( -f ${runscript}.sh ) then
698
if ( -f ${runscript}.sh ) then
696
   \rm -f ${runscript}.sh
699
   \rm -f ${runscript}.sh
697
endif 
700
endif 
698
 
701
 
699
# Write header
702
# Write header
700
echo '#\!/bin/csh'                    >! ${runscript}.sh
703
echo '#\!/bin/csh'                    >! ${runscript}.sh
701
echo "#"                              >> ${runscript}.sh
704
echo "#"                              >> ${runscript}.sh
702
echo "#----- Calling command"         >> ${runscript}.sh
705
echo "#----- Calling command"         >> ${runscript}.sh
703
echo "#"                              >> ${runscript}.sh
706
echo "#"                              >> ${runscript}.sh
704
echo "# lagranto ${lagranto_call} "   >> ${runscript}.sh
707
echo "# lagranto ${lagranto_call} "   >> ${runscript}.sh
705
echo "#"                              >> ${runscript}.sh 
708
echo "#"                              >> ${runscript}.sh 
706
echo "#----- Output file    "         >> ${runscript}.sh
709
echo "#----- Output file    "         >> ${runscript}.sh
707
echo "#"                              >> ${runscript}.sh
710
echo "#"                              >> ${runscript}.sh
708
echo "# ${outfile}                "   >> ${runscript}.sh
711
echo "# ${outfile}                "   >> ${runscript}.sh
709
echo "#"                              >> ${runscript}.sh 
712
echo "#"                              >> ${runscript}.sh 
710
 
713
 
711
# Decide whether <create_startf> has to be run
714
# Decide whether <create_startf> has to be run
712
if ( "${flag_startf}" == "criterion" ) then
715
if ( "${flag_startf}" == "criterion" ) then
713
  echo "#------ Run <startf>"                                                                                       >> ${runscript}.sh
716
  echo "#------ Run <startf>"                                                                                       >> ${runscript}.sh
714
  echo "#"                                                                                                                 >> ${runscript}.sh
717
  echo "#"                                                                                                                 >> ${runscript}.sh
715
  echo ${LAGRANTO}/bin/create.sh ${startdate} startf \"`cat startf.criterion`\" -t ${tracefile} -regionf ${regionf} >> ${runscript}.sh 
718
  echo ${LAGRANTO}/bin/create.sh ${startdate} startf \"`cat startf.criterion`\" -t ${tracefile} -regionf ${regionf} >> ${runscript}.sh 
716
  echo "#"                                                                                                                 >> ${runscript}.sh
719
  echo "#"                                                                                                                 >> ${runscript}.sh
717
  set startf = "startf"
720
  set startf = "startf"
718
endif
721
endif
719
 
722
 
720
# Check whether startfile is ready
723
# Check whether startfile is ready
721
cat >> ${runscript}.sh <<EOF 
724
cat >> ${runscript}.sh <<EOF 
722
#------ Abort if no startf is available
725
#------ Abort if no startf is available
723
#
726
#
724
if ( ! -f ${startf} ) then
727
if ( ! -f ${startf} ) then
725
  echo " ERROR: no start file available .... Stop"
728
  echo " ERROR: no start file available .... Stop"
726
  exit 1
729
  exit 1
727
endif
730
endif
728
EOF
731
EOF
729
 
732
 
730
# Decide wich intermediate format is used (needed for efficient communication between different programs)
733
# Decide wich intermediate format is used (needed for efficient communication between different programs)
731
set iform1 = ""
734
set iform1 = ""
732
set iform2 = ""
735
set iform2 = ""
733
if ( "${tracefile}" != ""    ) set iform1 = ".4"
736
if ( "${tracefile}" != ""    ) set iform1 = ".4"
734
if ( "${select}"    != "nil" ) set iform2 = ".4"
737
if ( "${select}"    != "nil" ) set iform2 = ".4"
735
 
738
 
736
# Remove all trajectory files which might already be there
739
# Remove all trajectory files which might already be there
737
cat >> ${runscript}.sh <<EOF 
740
cat >> ${runscript}.sh <<EOF 
738
#
741
#
739
#------ Remove existing trajectory files
742
#------ Remove existing trajectory files
740
#
743
#
741
if ( -f ${outfile}${iform1} ) then
744
if ( -f ${outfile}${iform1} ) then
742
  \rm -f ${outfile}${iform1}
745
  \rm -f ${outfile}${iform1}
743
endif
746
endif
744
if ( -f ${outfile}${iform2} ) then
747
if ( -f ${outfile}${iform2} ) then
745
  \rm -f ${outfile}${iform2}
748
  \rm -f ${outfile}${iform2}
746
endif
749
endif
747
if ( -f ${outfile} ) then
750
if ( -f ${outfile} ) then
748
  \rm -f ${outfile}
751
  \rm -f ${outfile}
749
endif
752
endif
750
 
753
 
751
EOF
754
EOF
752
 
755
 
753
# Write call to <caltra> into runscript
756
# Write call to <caltra> into runscript
754
echo "#"                                                                                      >> ${runscript}.sh
757
echo "#"                                                                                      >> ${runscript}.sh
755
echo "#------ Run <caltra>"                                                                   >> ${runscript}.sh
758
echo "#------ Run <caltra>"                                                                   >> ${runscript}.sh
756
echo "#"                                                                                      >> ${runscript}.sh
759
echo "#"                                                                                      >> ${runscript}.sh
757
echo ${LAGRANTO}/bin/caltra.sh ${startdate} ${enddate} startf ${outfile}${iform1} ${jumpflag} >> ${runscript}.sh  
760
echo ${LAGRANTO}/bin/caltra.sh ${startdate} ${enddate} startf ${outfile}${iform1} ${jumpflag} >> ${runscript}.sh  
758
 
761
 
759
# Check whether caltra was successful
762
# Check whether caltra was successful
760
cat >> ${runscript}.sh <<EOF 
763
cat >> ${runscript}.sh <<EOF 
761
#
764
#
762
#------ Abort if caltra was not successful
765
#------ Abort if caltra was not successful
763
#
766
#
764
if ( ! -f ${outfile}${iform1} ) then
767
if ( ! -f ${outfile}${iform1} ) then
765
  echo " ERROR: caltra failed .... Stop"
768
  echo " ERROR: caltra failed .... Stop"
766
  exit 1
769
  exit 1
767
endif
770
endif
768
EOF
771
EOF
769
 
772
 
770
#  Decide whether <trace> has to be run
773
#  Decide whether <trace> has to be run
771
if ( "${tracefile}" != "" ) then
774
if ( "${tracefile}" != "" ) then
772
  echo "#"                                                                                    >> ${runscript}.sh
775
  echo "#"                                                                                    >> ${runscript}.sh
773
  echo "#------ Run <trace>"                                                                  >> ${runscript}.sh
776
  echo "#------ Run <trace>"                                                                  >> ${runscript}.sh
774
  echo "#"                                                                                    >> ${runscript}.sh
777
  echo "#"                                                                                    >> ${runscript}.sh
775
  echo ${LAGRANTO}/bin/trace.sh ${outfile}${iform1} ${outfile}${iform2} -v ${tracefile}       >> ${runscript}.sh 
778
  echo ${LAGRANTO}/bin/trace.sh ${outfile}${iform1} ${outfile}${iform2} -v ${tracefile}       >> ${runscript}.sh 
776
 
779
 
777
endif
780
endif
778
 
781
 
779
# Check whether trace was successful
782
# Check whether trace was successful
780
cat >> ${runscript}.sh <<EOF 
783
cat >> ${runscript}.sh <<EOF 
781
#
784
#
782
#------ Abort if trace was not successful
785
#------ Abort if trace was not successful
783
#
786
#
784
if ( ! -f ${outfile}${iform2} ) then
787
if ( ! -f ${outfile}${iform2} ) then
785
  echo " ERROR: trace failed .... Stop"
788
  echo " ERROR: trace failed .... Stop"
786
  exit 1
789
  exit 1
787
endif
790
endif
788
EOF
791
EOF
789
 
792
 
790
#  Decide whether <select> has to be run
793
#  Decide whether <select> has to be run
791
if ( "${select}" != "nil" ) then                        
794
if ( "${select}" != "nil" ) then                        
792
  echo "#"                                                                                               >> ${runscript}.sh
795
  echo "#"                                                                                               >> ${runscript}.sh
793
  echo "#------ Run <select>"                                                                            >> ${runscript}.sh
796
  echo "#------ Run <select>"                                                                            >> ${runscript}.sh
794
  echo "#"                                                                                               >> ${runscript}.sh
797
  echo "#"                                                                                               >> ${runscript}.sh
795
  echo ${LAGRANTO}/bin/select.sh ${outfile}${iform2} ${outfile}  \"`cat ${select}`\" -regionf ${regionf} >> ${runscript}.sh 
798
  echo ${LAGRANTO}/bin/select.sh ${outfile}${iform2} ${outfile}  \"`cat ${select}`\" -regionf ${regionf} >> ${runscript}.sh 
796
  echo "#"                                                                                               >> ${runscript}.sh
799
  echo "#"                                                                                               >> ${runscript}.sh
797
endif
800
endif
798
 
801
 
799
# Show runscript on screen
802
# Show runscript on screen
800
more ${runscript}.sh
803
more ${runscript}.sh
801
 
804
 
802
# Change runscript to executable
805
# Change runscript to executable
803
chmod u+x ${runscript}.sh
806
chmod u+x ${runscript}.sh
804
 
807
 
805
# Decide whether to stop at this place (only preparation for Lagranto run)
808
# Decide whether to stop at this place (only preparation for Lagranto run)
806
if ( "${prepflag}" == "prep" ) then
809
if ( "${prepflag}" == "prep" ) then
807
  echo
810
  echo
808
  echo '---- READY TO RUN ----- ---------------------------------'
811
  echo '---- READY TO RUN ----- ---------------------------------'
809
  echo
812
  echo
810
  echo " Would you like to change to the rundirectory [y/n] "
813
  echo " Would you like to change to the rundirectory [y/n] "
811
 
814
 
812
  set id = $<
815
  set id = $<
813
  if ( ( "${id}" == "y" ) | ( "${id}" == "Y" ) ) then
816
  if ( ( "${id}" == "y" ) | ( "${id}" == "Y" ) ) then
814
     cd ${rundir}
817
     cd ${rundir}
815
     xterm &
818
     xterm &
816
  endif
819
  endif
817
 
820
 
818
  exit 0
821
  exit 0
819
 
822
 
820
endif  
823
endif  
821
 
824
 
822
# Define environment variable for the case
825
# Define environment variable for the case
823
echo
826
echo
824
echo '---- REMEMBER MOST RECENT CALL --------------------------'
827
echo '---- REMEMBER MOST RECENT CALL --------------------------'
825
echo
828
echo
826
cd ${calldir}
829
cd ${calldir}
827
if ( -f lagranto.param ) \rm lagranto.param
830
if ( -f lagranto.param ) \rm lagranto.param
828
echo "${rundir}"  >! lagranto.param
831
echo "${rundir}"  >! lagranto.param
829
echo "${outfile}" >> lagranto.param
832
echo "${outfile}" >> lagranto.param
830
cd ${rundir}
833
cd ${rundir}
831
echo
834
echo
832
echo " run directory + output file -> lagranto.param"
835
echo " run directory + output file -> lagranto.param"
833
 
836
 
834
# ---------------------------------------------------------------------
837
# ---------------------------------------------------------------------
835
# Run lagranto
838
# Run lagranto
836
# ---------------------------------------------------------------------
839
# ---------------------------------------------------------------------
837
 
840
 
838
echo
841
echo
839
echo '---- RUN LAGRANTO ---------------------------------------'
842
echo '---- RUN LAGRANTO ---------------------------------------'
840
echo
843
echo
841
 
844
 
842
if ( "${logfile}" != "/dev/stdout" ) then
845
if ( "${logfile}" != "/dev/stdout" ) then
843
    echo "log goes to ${logfile}"
846
    echo "log goes to ${logfile}"
844
endif
847
endif
845
 
848
 
846
# Remove logfile
849
# Remove logfile
847
if ( "${logfile}" != "/dev/stdout" ) then
850
if ( "${logfile}" != "/dev/stdout" ) then
848
    \rm -f    ${logfile}
851
    \rm -f    ${logfile}
849
endif
852
endif
850
 
853
 
851
# Run it
854
# Run it
852
${rundir}/${runscript}.sh > ${logfile}
855
${rundir}/${runscript}.sh > ${logfile}
853
 
856
 
854
# Check for errors in logfile
857
# Check for errors in logfile
855
if ( "${logfile}" != "/dev/stdout" ) then
858
if ( "${logfile}" != "/dev/stdout" ) then
856
   grep ERROR ${logfile} 
859
   grep ERROR ${logfile} 
857
endif
860
endif
858
 
861
 
859
# ---------------------------------------------------------------------
862
# ---------------------------------------------------------------------
860
# Make clean and finish lagranto run
863
# Make clean and finish lagranto run
861
# ---------------------------------------------------------------------
864
# ---------------------------------------------------------------------
862
 
865
 
863
# Remove unneeded files
866
# Remove unneeded files
864
\rm -f fort.9
867
\rm -f fort.9
865
 
868
 
866
# Remove files if requested
869
# Remove files if requested
867
if ( "${keepflag}" != "keep" ) then
870
if ( "${keepflag}" != "keep" ) then
868
 
871
 
869
   echo 
872
   echo 
870
   echo '---- MAKING CLEAN ---------------------------------------'
873
   echo '---- MAKING CLEAN ---------------------------------------'
871
   echo
874
   echo
872
 
875
 
873
   cd ${rundir}
876
   cd ${rundir}
874
 
877
 
875
       
878
       
876
   set runscript = "${runscript}.sh"
879
   set runscript = "${runscript}.sh"
877
 
880
 
878
   foreach file ( `\ls -L1` )
881
   foreach file ( `\ls -L1` )
879
    
882
    
880
      set id = "0"
883
      set id = "0"
881
 
884
 
882
      if ( "${file}" == "${outfile}"   ) set id="1" 
885
      if ( "${file}" == "${outfile}"   ) set id="1" 
883
      if ( "${file}" == "${runscript}" ) set id="1" 
886
      if ( "${file}" == "${runscript}" ) set id="1" 
884
      if ( "${file}" == "${logfile}"   ) set id="1" 
887
      if ( "${file}" == "${logfile}"   ) set id="1" 
885
  
888
  
886
      if ( "${id}" == "0" ) \rm -f ${file}      
889
      if ( "${id}" == "0" ) \rm -f ${file}      
887
 
890
 
888
   end
891
   end
889
  
892
  
890
endif
893
endif
891
 
894
 
892
# Everything is fine!
895
# Everything is fine!
893
echo
896
echo
894
echo '             *** END OF LAGRANTO ***             '
897
echo '             *** END OF LAGRANTO ***             '
895
echo '========================================================='
898
echo '========================================================='
896
echo
899
echo
897
 
900
 
898
exit 0 
901
exit 0 
899
   
902
   
900
   
903