Subversion Repositories lagranto.ecmwf

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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