Subversion Repositories lagranto.20cr

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 michaesp 1
#!/bin/csh
2
 
3
# Set Lagranto 
4
set LAGRANTO = ${LAGRANTOBASE}.${MODEL}/
5
 
6
# Write usage information
7
if ( ${#argv} == 0) then
8
  echo 
9
  ${LAGRANTO}/bin/lagrantohelp datelist short
10
  echo  
11
  exit 0
12
endif
13
 
14
# Handle fixed arguments
15
set filename = $1
16
set mode     = $2
17
 
18
# Redirect output to screen if requested
19
if ( "${filename}" == "stdout" ) set filename="/dev/stdout"
20
if ( "${filename}" == "screen" ) set filename="/dev/stdout"
21
 
22
# Handle optional arguments
23
set interval = "6"
24
 
25
while ( $#argv > 0 )
26
 
27
  switch ( $argv[1] )
28
 
29
   case -create
30
     set startdate = $argv[2] 
31
     set finaldate = $argv[3] 
32
     shift;
33
     shift;
34
   breaksw
35
 
36
   case -indir
37
     set dirname = $argv[2] 
38
     shift;
39
   breaksw
40
 
41
   case -next
42
     set date = $argv[2] 
43
     shift;
44
   breaksw
45
 
46
   case -prev
47
     set date = $argv[2] 
48
     shift;
49
   breaksw
50
 
51
   case -isin
52
     set date = $argv[2] 
53
     shift;
54
   breaksw
55
 
56
   case -interval
57
     set interval = $argv[2] 
58
     shift;
59
   breaksw
60
 
61
   case -overlap
62
     set file1 = $argv[2] 
63
     set file2 = $argv[3] 
64
     shift;
65
     shift;
66
   breaksw
67
 
68
   case -onlyin1
69
     set file1 = $argv[2] 
70
     set file2 = $argv[3] 
71
     shift;
72
     shift;
73
   breaksw
74
 
75
   case -onlyin2
76
     set file1 = $argv[2] 
77
     set file2 = $argv[3] 
78
     shift;
79
     shift;
80
   breaksw
81
 
82
   case -totime
83
     set refdate = $argv[2] 
84
     shift;
85
   breaksw
86
 
87
   case -todate
88
     set refdate = $argv[2] 
89
     shift;
90
   breaksw
91
 
92
  endsw
93
 
94
  shift;
95
 
96
end
97
 
98
# Mode: -create startdate finaldate
99
if ( "${mode}" == "-create" ) then
100
 
101
   \rm -f datelist.param
102
   echo \"${filename}\"    >  datelist.param
103
   echo \"${mode}\"        >> datelist.param
104
   echo \"${startdate}00\" >> datelist.param
105
   echo \"${finaldate}00\" >> datelist.param
106
   echo ${interval}        >> datelist.param
107
 
108
   ${LAGRANTO}/goodies/datelist
109
 
110
endif
111
 
112
# Mode: -first 
113
if ( "${mode}" == "-first" ) then
114
 
115
   head -1 ${filename} 
116
 
117
endif
118
 
119
# Mode: -last 
120
if ( "${mode}" == "-last" ) then
121
 
122
   tail -1 ${filename} 
123
 
124
endif
125
 
126
# Mode: -ndates 
127
if ( "${mode}" == "-ndates" ) then
128
 
129
   wc -l ${filename} | awk '{ print $1}'
130
 
131
endif
132
 
133
# Mode: -timerange 
134
if ( "${mode}" == "-timerange" ) then
135
 
136
   set firstdate = `head -1 ${filename}`
137
   set finaldate = `tail -1 ${filename}`  
138
 
139
   ${LAGRANTO}/goodies/gettidiff ${finaldate} ${firstdate}
140
 
141
endif
142
 
143
# Mode: -indir {directory name}
144
if ( "${mode}" == "-indir" ) then
145
 
146
    ls -1 ${dirname} | perl -ne 'print  if s/.*([0-9]{8}_[0-9]{2}).*/\1/' | sort | uniq >! ${filename}
147
 
148
endif
149
 
150
# Mode: -next
151
if ( "${mode}" == "-next" ) then
152
 
153
  set last = `tail -1 ${filename}` 
154
  if ( "${date}" != "${last}" ) then
155
     set next = `sed -n "/${date}/{n;p;}" ${filename}`
156
     echo ${next}
157
  else
158
     echo "nil"
159
  endif
160
 
161
endif
162
 
163
# Mode: -prev
164
if ( "${mode}" == "-prev" ) then
165
 
166
  set first = `head -1 ${filename}` 
167
  if ( "${date}" != "${first}" ) then
168
     set prev = `sed -n "/${date}/{g;p;};h" ${filename}`
169
     echo ${prev}
170
  else
171
     echo "nil"
172
  endif
173
 
174
endif 
175
 
176
# Mode: -isin
177
if ( "${mode}" == "-isin" ) then
178
 
179
  set flag = `sed -n "/${date}/p" ${filename}`
180
 
181
  if ( "${flag}" != "" ) then
182
    echo "1"
183
  else
184
    echo "0"
185
  endif
186
 
187
endif 
188
 
189
# Mode: -overlap
190
if ( "${mode}" == "-overlap" ) then
191
    if ( "${filename}" != "/dev/stdout" ) then 
192
       set outfile = ${filename}.$$
193
       \rm -f ${outfile}
194
       grep -f ${file1} ${file2} > ${outfile}
195
       \mv ${outfile} ${filename}
196
    else
197
       grep -f ${file1} ${file2}
198
    endif
199
endif
200
 
201
# Mode: -onlyin1
202
if ( "${mode}" == "-onlyin1" ) then
203
 
204
   \rm -f datelist.param
205
   echo \"${filename}\"    >  datelist.param
206
   echo \"${mode}\"        >> datelist.param
207
   echo \"${file1}\"       >> datelist.param
208
   echo \"${file2}\"       >> datelist.param
209
 
210
   ${LAGRANTO}/goodies/datelist
211
 
212
endif
213
 
214
# Mode: -onlyin2
215
if ( "${mode}" == "-onlyin2" ) then
216
    set outfile1 = "tmp1.$$"
217
    set outfile2 = "tmp2.$$"
218
    \rm -f ${outfile1}
219
    \rm -f ${outfile2}
220
    grep -f  ${file2}    ${file1} >! ${outfile1}
221
    grep -vf ${outfile1} ${file2} >! ${outfile2}
222
    if ( "${filename}" != "/dev/stdout" ) then
223
      \mv ${outfile2} ${filename}
224
    else
225
      cat  ${outfile2}
226
    endif
227
    \rm -f ${outfile1}
228
    \rm -f ${outfile2}
229
endif
230
 
231
# Mode: -totime 
232
if ( "${mode}" == "-totime" ) then
233
 
234
   \rm -f datelist.param
235
   echo \"${filename}\"    >  datelist.param
236
   echo \"${mode}\"        >> datelist.param
237
   echo \"${refdate}00\"   >> datelist.param
238
 
239
   ${LAGRANTO}/goodies/datelist
240
 
241
endif
242
 
243
# Mode: -todate
244
if ( "${mode}" == "-todate" ) then
245
 
246
   \rm -f datelist.param
247
   echo \"${filename}\"    >  datelist.param
248
   echo \"${mode}\"        >> datelist.param
249
   echo \"${refdate}00\"   >> datelist.param
250
 
251
   ${LAGRANTO}/goodies/datelist
252
 
253
endif
254
 
255
# Mode: -randsample
256
if ( "${mode}" == "-randsample" ) then
257
 
258
   \rm -f datelist.param
259
   echo \"${filename}\"    >  datelist.param
260
   echo \"${mode}\"        >> datelist.param
261
   echo ${randsample}      >> datelist.param
262
 
263
   ${LAGRANTO}/goodies/datelist
264
 
265
endif
266
 
267
exit 0
268