1 | #! /bin/sh |
---|
2 | #+ |
---|
3 | # |
---|
4 | # NAME |
---|
5 | # ==== |
---|
6 | # |
---|
7 | # cat_clim_olr.sh - build OLR climatology file |
---|
8 | # |
---|
9 | # SYNOPSYS |
---|
10 | # ======== |
---|
11 | # |
---|
12 | # ``cat_clim_olr.sh`` |
---|
13 | # |
---|
14 | # |
---|
15 | # DESCRIPTION |
---|
16 | # =========== |
---|
17 | # |
---|
18 | # Build OLR climatology file |
---|
19 | # using mean daily file by year and reduce geographical domain |
---|
20 | # to [60 ° W, 50 ° E] [30 ° S, 45 ° N]. |
---|
21 | # |
---|
22 | # EXAMPLES |
---|
23 | # ======== |
---|
24 | # |
---|
25 | # |
---|
26 | # To build OLR climatology : |
---|
27 | # :: |
---|
28 | # |
---|
29 | # $ cat_clim_olr.sh |
---|
30 | # |
---|
31 | # FILES |
---|
32 | # ===== |
---|
33 | # |
---|
34 | # original location |
---|
35 | # ~~~~~~~~~~~~~~~~~ |
---|
36 | # |
---|
37 | # /usr/home/fplod/incas/varamma/varamma_ws/src/cat_clim_olr.sh sur aedon.locean-ipsl.upmc.fr |
---|
38 | # |
---|
39 | # COMMENTS |
---|
40 | # ======== |
---|
41 | # |
---|
42 | # |
---|
43 | # If yearmin and yearmax are the same one can compare input and output files |
---|
44 | # like this: |
---|
45 | # |
---|
46 | # |
---|
47 | # For yearmin=yearmax=2000 |
---|
48 | # :: |
---|
49 | # |
---|
50 | # $ cdo diffv ${VARAMMA_ID}/olr.day.mean_2000_ng.nc \ |
---|
51 | # ${VARAMMA_OD}/olr.day.mean_climato_ng.nc |
---|
52 | # |
---|
53 | # |
---|
54 | # There must be a difference because 2000 is a leap year. |
---|
55 | # |
---|
56 | # |
---|
57 | # For yearmin=yearmax=2001 |
---|
58 | # :: |
---|
59 | # |
---|
60 | # $ cdo diffv ${VARAMMA_ID}/olr.day.mean_2001_ng.nc \ |
---|
61 | # ${VARAMMA_OD}/olr.day.mean_climato_ng.nc |
---|
62 | # |
---|
63 | # There must be no difference on values of olr and info fields ++ à vérifier |
---|
64 | # |
---|
65 | # |
---|
66 | # SEE ALSO |
---|
67 | # ======== |
---|
68 | # |
---|
69 | # EVOLUTIONS |
---|
70 | # ========== |
---|
71 | # |
---|
72 | # ++ unset |
---|
73 | # |
---|
74 | # ++ option debug/verbose |
---|
75 | # |
---|
76 | # ++ gestion log |
---|
77 | # |
---|
78 | # ++ vérification accès filein |
---|
79 | # |
---|
80 | # !! pb zeus et dedale signalé à reseau le 200807 |
---|
81 | # |
---|
82 | # $Id$ |
---|
83 | # |
---|
84 | # - fplod 2008-08-05T09:37:14Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
85 | # |
---|
86 | # * creation from /homedata/eymard/scripts/script_cat_clim_AMSU |
---|
87 | # |
---|
88 | #- |
---|
89 | # |
---|
90 | # main program |
---|
91 | system=$(uname) |
---|
92 | case "${system}" in |
---|
93 | AIX|IRIX64) |
---|
94 | echo " www : no specific posix checking" |
---|
95 | ;; |
---|
96 | *) |
---|
97 | set -o posix |
---|
98 | ;; |
---|
99 | esac |
---|
100 | # |
---|
101 | command=$(basename ${0}) |
---|
102 | log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
---|
103 | # |
---|
104 | usage=" Usage : ${command}" |
---|
105 | # |
---|
106 | # ++ test si ncks available |
---|
107 | # |
---|
108 | yearmin=2000 |
---|
109 | yearmax=2007 |
---|
110 | # |
---|
111 | yearmin=2000 # ++ pour debug |
---|
112 | yearmax=2000 #++ pour debug |
---|
113 | # |
---|
114 | minargcount=0 |
---|
115 | if [ ${#} -lt ${minargcount} ] |
---|
116 | then |
---|
117 | echo "eee : not enought arguments" |
---|
118 | echo "${usage}" |
---|
119 | exit 1 |
---|
120 | fi |
---|
121 | # |
---|
122 | while [ ! -z "${1}" ] # ++ pb bash |
---|
123 | do |
---|
124 | case ${1} in |
---|
125 | -h) |
---|
126 | echo "${usage}" |
---|
127 | ;; |
---|
128 | *) # other choice |
---|
129 | echo "${usage}" |
---|
130 | ;; |
---|
131 | esac |
---|
132 | shift # next flag |
---|
133 | done |
---|
134 | # |
---|
135 | set -u |
---|
136 | # |
---|
137 | # check for ${VARAMMA_LOG} definition |
---|
138 | if [ "${VARAMMA_LOG}" = "" ] |
---|
139 | then |
---|
140 | echo " eee : \${VARAMMA_LOG} not defined" |
---|
141 | exit 1 |
---|
142 | fi |
---|
143 | # |
---|
144 | # check for ${VARAMMA_LOG} existence |
---|
145 | if [ ! -d ${VARAMMA_LOG} ] |
---|
146 | then |
---|
147 | echo " eee : ${VARAMMA_LOG} not found" |
---|
148 | exit 1 |
---|
149 | fi |
---|
150 | # |
---|
151 | # check for permission access on VARAMMA_LOG |
---|
152 | if [ ! -x ${VARAMMA_LOG} ] |
---|
153 | then |
---|
154 | echo " eee : ${VARAMMA_LOG} not reachable" |
---|
155 | exit 1 |
---|
156 | fi |
---|
157 | # |
---|
158 | # check for write permission on VARAMMA_LOG |
---|
159 | if [ ! -w ${VARAMMA_LOG} ] |
---|
160 | then |
---|
161 | echo " eee : ${VARAMMA_LOG} not writable" |
---|
162 | exit 1 |
---|
163 | fi |
---|
164 | # |
---|
165 | log=${VARAMMA_LOG}/$(basename ${0} .sh).log.${log_date} |
---|
166 | #++echo "runtime = ${log_date}" 1>> ${log} |
---|
167 | # |
---|
168 | # ++ VARAMMA_ID |
---|
169 | # ++ VARAMMA_OD |
---|
170 | # |
---|
171 | # check for input files |
---|
172 | listin="" |
---|
173 | iyear=${yearmin} |
---|
174 | while [ ${iyear} -le ${yearmax} ] |
---|
175 | do |
---|
176 | cyear=$(echo ${iyear} | awk ' {printf "%4.4d",$0}') |
---|
177 | filein=${VARAMMA_ID}/olr.day.mean_${cyear}_ng.nc |
---|
178 | if [ ! -r ${VARAMMA_ID}/olr.day.mean.nc ] |
---|
179 | then |
---|
180 | echo "eee : ${filein} not accessible" |
---|
181 | exit 1 |
---|
182 | fi |
---|
183 | file365[${iyear}]=${VARAMMA_OD}/olr.day.mean_${cyear}_365d_ng.nc |
---|
184 | file365_1=${VARAMMA_OD}/olr.day.mean_${cyear}_365d1_ng.nc |
---|
185 | file365_2=${VARAMMA_OD}/olr.day.mean_${cyear}_365d2_ng.nc |
---|
186 | # get rid of yyyy0229 |
---|
187 | is_leap_year.sh ${iyear} |
---|
188 | ily_status=${?} |
---|
189 | if [ ${ily_status} -eq 0 ] |
---|
190 | then |
---|
191 | time1=$(echo ${iyear} | awk ' {printf "%4.4d-01-01 00:00:00.0",$1}') |
---|
192 | time2=$(echo ${iyear} | awk ' {printf "%4.4d-02-28 00:00:00.0",$1}') #++23:59 |
---|
193 | time3=$(echo ${iyear} | awk ' {printf "%4.4d-03-01 00:00:00.0",$1}') |
---|
194 | time4=$(echo ${iyear} | awk ' {printf "%4.4d-12-31 00:00:00.0",$1}') #++23:59 |
---|
195 | # cut first part of year |
---|
196 | ncks \ |
---|
197 | --dimension time,"${time1}","${time2}" \ |
---|
198 | ${filein} ${file365_1} |
---|
199 | status_ncks=${?} |
---|
200 | if [ ${status_ncks} -ne 0 ] |
---|
201 | then |
---|
202 | echo "eee : pb with ncks ${filein} between yyyy0101 and yyyy0228" |
---|
203 | exit 1 |
---|
204 | fi |
---|
205 | # cut second part of year |
---|
206 | ncks \ |
---|
207 | --dimension time,"${time3}","${time4}" \ |
---|
208 | ${filein} ${file365_2} |
---|
209 | status_ncks=${?} |
---|
210 | if [ ${status_ncks} -ne 0 ] |
---|
211 | then |
---|
212 | echo "eee : pb with ncks ${filein} between yyyy0301 and yyyy1231" |
---|
213 | exit 1 |
---|
214 | fi |
---|
215 | # join first and second part |
---|
216 | ncrcat ${file365_1} ${file365_2} ${file365[${iyear}]} |
---|
217 | status_ncrcat=${?} |
---|
218 | if [ ${status_ncrcat} -ne 0 ] |
---|
219 | then |
---|
220 | echo "eee : pb with ncrcat ${filein}" |
---|
221 | exit 1 |
---|
222 | fi |
---|
223 | else |
---|
224 | cp ${filein} ${file365[${iyear}]} |
---|
225 | fi |
---|
226 | listin="${listin} ${file365[${iyear}]}" |
---|
227 | iyear=$(( ${iyear} + 1 )) |
---|
228 | done |
---|
229 | # |
---|
230 | # build fileout |
---|
231 | # based on the first file of the serie (ie yearmin) |
---|
232 | fileout=${VARAMMA_OD}/$(basename ${file365[${yearmin}]} ${yearmin}_ng.nc)climato_ng.nc |
---|
233 | if [ -f ${fileout} ] |
---|
234 | then |
---|
235 | echo "eee : ${fileout} already exists" |
---|
236 | exit 1 |
---|
237 | fi |
---|
238 | # |
---|
239 | # ++ ncea ou ncra |
---|
240 | ncea ${listin} ${fileout}_ncea |
---|
241 | ncra ${listin} ${fileout}_ncra |
---|
242 | status_ncks=${?} |
---|
243 | if [ ${status_ncks} -ne 0 ] |
---|
244 | then |
---|
245 | echo "eee : pb with ncks" |
---|
246 | exit 1 |
---|
247 | fi |
---|
248 | # |
---|
249 | # end |
---|
250 | exit 0 |
---|