Subversion Repositories lagranto.wrf

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 michaesp 1
#!/bin/csh
2
 
11 michaesp 3
# Set Lagranto 
4
set LAGRANTO = ${LAGRANTOBASE}.${MODEL}/
5
 
2 michaesp 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
 
93
  endsw
94
 
95
  shift;
96
 
97
end
98
 
99
# Mode: -create startdate finaldate
100
if ( "${mode}" == "-create" ) then
101
 
102
   \rm -f datelist.param
103
   echo \"${filename}\"    >  datelist.param
104
   echo \"${mode}\"        >> datelist.param
105
   echo \"${startdate}00\" >> datelist.param
106
   echo \"${finaldate}00\" >> datelist.param
107
   echo ${interval}        >> datelist.param
108
 
109
   ${LAGRANTO}/goodies/datelist
110
 
111
endif
112
 
113
# Mode: -first 
114
if ( "${mode}" == "-first" ) then
115
 
116
   head -1 ${filename} 
117
 
118
endif
119
 
120
# Mode: -last 
121
if ( "${mode}" == "-last" ) then
122
 
123
   tail -1 ${filename} 
124
 
125
endif
126
 
127
# Mode: -ndates 
128
if ( "${mode}" == "-ndates" ) then
129
 
130
   wc -l ${filename} | awk '{ print $1}'
131
 
132
endif
133
 
134
# Mode: -timerange 
135
if ( "${mode}" == "-timerange" ) then
136
 
137
   set firstdate = `head -1 ${filename}`
138
   set finaldate = `tail -1 ${filename}`  
139
 
140
   ${LAGRANTO}/goodies/gettidiff ${finaldate} ${firstdate}
141
 
142
endif
143
 
144
# Mode: -indir {directory name}
145
if ( "${mode}" == "-indir" ) then
146
 
147
    ls -1 ${dirname} | perl -ne 'print  if s/.*([0-9]{8}_[0-9]{2}).*/\1/' | sort | uniq >! ${filename}
148
 
149
endif
150
 
151
# Mode: -next
152
if ( "${mode}" == "-next" ) then
153
 
154
  set last = `tail -1 ${filename}` 
155
  if ( "${date}" != "${last}" ) then
156
     set next = `sed -n "/${date}/{n;p;}" ${filename}`
157
     echo ${next}
158
  else
159
     echo "nil"
160
  endif
161
 
162
endif
163
 
164
# Mode: -prev
165
if ( "${mode}" == "-prev" ) then
166
 
167
  set first = `head -1 ${filename}` 
168
  if ( "${date}" != "${first}" ) then
169
     set prev = `sed -n "/${date}/{g;p;};h" ${filename}`
170
     echo ${prev}
171
  else
172
     echo "nil"
173
  endif
174
 
175
endif 
176
 
177
# Mode: -isin
178
if ( "${mode}" == "-isin" ) then
179
 
180
  set flag = `sed -n "/${date}/p" ${filename}`
181
 
182
  if ( "${flag}" != "" ) then
183
    echo "1"
184
  else
185
    echo "0"
186
  endif
187
 
188
endif 
189
 
190
# Mode: -overlap
191
if ( "${mode}" == "-overlap" ) then
192
    if ( "${filename}" != "/dev/stdout" ) then 
193
       set outfile = ${filename}.$$
194
       \rm -f ${outfile}
195
       grep -f ${file1} ${file2} > ${outfile}
196
       \mv ${outfile} ${filename}
197
    else
198
       grep -f ${file1} ${file2}
199
    endif
200
endif
201
 
202
# Mode: -onlyin1
203
if ( "${mode}" == "-onlyin1" ) then
204
    set outfile1 = "tmp1.$$"
205
    set outfile2 = "tmp2.$$"
206
    \rm -f ${outfile1}
207
    \rm -f ${outfile2}
208
    grep -f  ${file1}    ${file2} >! ${outfile1}
209
    grep -vf ${outfile1} ${file1} >! ${outfile2}
210
    if ( "${filename}" != "/dev/stdout" ) then
211
      \mv ${outfile2} ${filename}
212
    else
213
      cat  ${outfile2}
214
    endif
215
    \rm -f ${outfile1}
216
    \rm -f ${outfile2}
217
endif
218
 
219
# Mode: -onlyin2
220
if ( "${mode}" == "-onlyin2" ) then
221
    set outfile1 = "tmp1.$$"
222
    set outfile2 = "tmp2.$$"
223
    \rm -f ${outfile1}
224
    \rm -f ${outfile2}
225
    grep -f  ${file2}    ${file1} >! ${outfile1}
226
    grep -vf ${outfile1} ${file2} >! ${outfile2}
227
    if ( "${filename}" != "/dev/stdout" ) then
228
      \mv ${outfile2} ${filename}
229
    else
230
      cat  ${outfile2}
231
    endif
232
    \rm -f ${outfile1}
233
    \rm -f ${outfile2}
234
endif
235
 
236
# Mode: -totime 
237
if ( "${mode}" == "-totime" ) then
238
 
239
   \rm -f datelist.param
240
   echo \"${filename}\"    >  datelist.param
241
   echo \"${mode}\"        >> datelist.param
242
   echo \"${refdate}00\"   >> datelist.param
243
 
244
   ${LAGRANTO}/goodies/datelist
245
 
246
endif
247
 
248
# Mode: -todate
249
if ( "${mode}" == "-todate" ) then
250
 
251
   \rm -f datelist.param
252
   echo \"${filename}\"    >  datelist.param
253
   echo \"${mode}\"        >> datelist.param
254
   echo \"${refdate}00\"   >> datelist.param
255
 
256
   ${LAGRANTO}/goodies/datelist
257
 
258
endif
259
 
260
exit 0
261