Subversion Repositories lagranto.um

Rev

Rev 3 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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