1 | #!/bin/bash |
---|
2 | #MSUB -r WeightsMask # Job name |
---|
3 | #MSUB -o Out_WeightsMask # Standard output |
---|
4 | #MSUB -e Out_WeightsMask # Error output |
---|
5 | #MSUB -eo |
---|
6 | #MSUB -n 4 # Number of processors |
---|
7 | #MSUB -T 1800 # Time limit (seconds) |
---|
8 | #MSUB -q standard |
---|
9 | #MSUB -Q test |
---|
10 | #MSUB -p devcmip6 |
---|
11 | |
---|
12 | ### =========================================================================== |
---|
13 | ### |
---|
14 | ### Creates interpolation weights between ORCA and atmosphere grids. |
---|
15 | ### Interpolates ORCA mask to atmosphere grid. |
---|
16 | ### Weight files are at OASIS-MCT format. |
---|
17 | ### |
---|
18 | ### Atmosphere grid may be lon/lat LMDZ or DYNAMICO icosahedron |
---|
19 | ### |
---|
20 | ### Documentation : https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX |
---|
21 | ### =========================================================================== |
---|
22 | ## |
---|
23 | ## Warning, to install, configure, run, use any of Olivier Marti's |
---|
24 | ## software or to read the associated documentation you'll need at least |
---|
25 | ## one (1) brain in a reasonably working order. Lack of this implement |
---|
26 | ## will void any warranties (either express or implied). |
---|
27 | ## O. Marti assumes no responsability for errors, omissions, |
---|
28 | ## data loss, or any other consequences caused directly or indirectly by |
---|
29 | ## the usage of his software by incorrectly or partially configured |
---|
30 | ## personal. |
---|
31 | ## |
---|
32 | ## SVN information |
---|
33 | # $Author$ |
---|
34 | # $Date$ |
---|
35 | # $Revision$ |
---|
36 | # $Id$ |
---|
37 | # $HeadURL$ |
---|
38 | |
---|
39 | ## |
---|
40 | ## Configuration |
---|
41 | ## =========================================================================== |
---|
42 | |
---|
43 | # |
---|
44 | # Defines models |
---|
45 | # ============== |
---|
46 | OCE=ORCA2.3 |
---|
47 | #OCE=eORCA1.2 |
---|
48 | #OCE=ORCA025 |
---|
49 | |
---|
50 | #ATM=ICO30 |
---|
51 | #ATM=ICO40 |
---|
52 | #ATM=ICO450 |
---|
53 | ATM=LMD9695 |
---|
54 | #ATM=LMD144X142 |
---|
55 | |
---|
56 | # |
---|
57 | # Defines OCE grids to handle |
---|
58 | # =========================== |
---|
59 | ListOCEGRID="T U V" |
---|
60 | ListOrder="1st" # " 2nd |
---|
61 | ListNormalize="false true" |
---|
62 | |
---|
63 | ## =========================================================================== |
---|
64 | ## |
---|
65 | ## You should not change anything below this line .... |
---|
66 | ## |
---|
67 | ## =========================================================================== |
---|
68 | SUBMIT_DIR=$(pwd) |
---|
69 | |
---|
70 | # |
---|
71 | # Defines computer |
---|
72 | # ================ |
---|
73 | if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi |
---|
74 | if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi |
---|
75 | PROGRAM=$(basename ${0}) |
---|
76 | |
---|
77 | case ${arch} in |
---|
78 | ( curie | irene ) |
---|
79 | set +vx |
---|
80 | module purge |
---|
81 | source /ccc/cont003/home/dsm/p86ipsl/.env_intel17.0.2_curie; |
---|
82 | source /ccc/cont003/home/dsm/p86ipsl/.env_netcdf4.3.3.1_curie |
---|
83 | R_IN=$(ccc_home -u igcmg --cccwork)/IGCM |
---|
84 | TMPDIR=${SCRATCHDIR}/TMP |
---|
85 | SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}} |
---|
86 | PROGRAM=${BRIDGE_MSUB_REQNAME} |
---|
87 | ;; |
---|
88 | ( * ) |
---|
89 | exit -1 |
---|
90 | ;; |
---|
91 | esac |
---|
92 | |
---|
93 | set -x ; set -e |
---|
94 | |
---|
95 | mkdir -p ${TMPDIR}/${OCE}x${ATM} || exit 1 |
---|
96 | cd ${TMPDIR}/${OCE}x${ATM} || exit 1 |
---|
97 | rm -f * |
---|
98 | |
---|
99 | # |
---|
100 | # Suffixes |
---|
101 | # --------------------------------------------------------------------------- |
---|
102 | Listocegrid=${ListOCEGRID,,} |
---|
103 | |
---|
104 | case ${OCE} in |
---|
105 | ( *ORC* ) oce=orc ; oce_domain_type=curvilinear ;; |
---|
106 | esac |
---|
107 | case ${ATM} in |
---|
108 | ( *dynamico* ) atm=ico ; atm_domain_type=unstructured ;; |
---|
109 | ( *ICO* ) atm=ico ; atm_domain_type=unstructured ;; |
---|
110 | ( *lmd* | *LMD* ) atm=lmd ; atm_domain_type=rectilinear ;; |
---|
111 | esac |
---|
112 | |
---|
113 | case ${OCE} in |
---|
114 | ( ORCA2.3* ) OcePerio=4 ;; |
---|
115 | ( ORCA1* | eORCA1* ) OcePerio=6 ;; |
---|
116 | esac |
---|
117 | # |
---|
118 | # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits |
---|
119 | # --------------------------------------------------------------------------- |
---|
120 | FL_FMT=64bit |
---|
121 | |
---|
122 | |
---|
123 | cp ${SUBMIT_DIR}/bin/interpol.exe . |
---|
124 | cp ${SUBMIT_DIR}/*.py . |
---|
125 | |
---|
126 | ## |
---|
127 | ## NEMO T point towards ATM - 1st order |
---|
128 | ## =========================================================================== |
---|
129 | cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc . |
---|
130 | cp ${R_IN}/ATM/GRID/${ATM}_grid.nc . |
---|
131 | |
---|
132 | ln -s ${OCE}_coordinates_mask.nc oce_grid.nc |
---|
133 | ln -s ${ATM}_grid.nc atm_grid.nc |
---|
134 | |
---|
135 | echo ${Green}"${OCE} T toward ${ATM} - 1storder"${Norm} |
---|
136 | cp ${SUBMIT_DIR}/iodef_oce_to_atm.xml iodef.xml |
---|
137 | |
---|
138 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' -k name -v maskutil_T |
---|
139 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
140 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
141 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name -v maskutil_T |
---|
142 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_t${oce}_to_t${atm}_1storder_false |
---|
143 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${OCE} mask interpolated to ${ATM}" |
---|
144 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${oce_domain_type} |
---|
145 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${atm_domain_type} |
---|
146 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t 1 |
---|
147 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
148 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
149 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_t${oce}_to_t${atm}_1storder_false.nc |
---|
150 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1 |
---|
151 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t false |
---|
152 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v false |
---|
153 | |
---|
154 | cp iodef.xml iodef_t${oce}_to_t${atm}_1storder_false.xml |
---|
155 | |
---|
156 | time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=no |
---|
157 | |
---|
158 | ## |
---|
159 | ## Correct spurious values (extremes) |
---|
160 | ## =========================================================================== |
---|
161 | cat <<EOF > correction_masque.nco |
---|
162 | where (OceFrac < 0.00001 ) OceFrac=OceFrac.get_miss() ; |
---|
163 | where (OceFrac > 0.99999 ) OceFrac=1.0 ; |
---|
164 | OceFrac.delete_miss() ; |
---|
165 | // Fill masked values to land values |
---|
166 | where (OceFrac > 1.0 ) OceFrac=0.0 ; |
---|
167 | where (OceFrac < 0.0 ) OceFrac=0.0 ; |
---|
168 | EOF |
---|
169 | ncap2 --history --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_1storder_false.nc tmp_dia_t${oce}_to_t${atm}_1storder_false.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_false.nc dia_t${oce}_to_t${atm}_1storder_false.nc |
---|
170 | ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_1storder_false.nc |
---|
171 | |
---|
172 | ## |
---|
173 | ## Creates mask on ATM grid |
---|
174 | ## =========================================================================== |
---|
175 | cp dia_t${oce}_to_t${atm}_1storder_false.nc dia_t${oce}_to_t${atm}_1storder_false_mask.nc |
---|
176 | ncks --alphabetize --history --overwrite --variable OceFrac dia_t${oce}_to_t${atm}_1storder_false_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
177 | ncks --alphabetize --history --append --variable aire atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
178 | [[ ${atm} = *ico* ]] && ncks --alphabetize --history --append --variable bounds_lon,bounds_lat atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
179 | |
---|
180 | cat <<EOF > creation_masque.nco |
---|
181 | where (OceFrac > 0.0 ) OceFrac=1 ; |
---|
182 | where (OceFrac <= 0.0 ) OceFrac=0 ; |
---|
183 | EOF |
---|
184 | ncap2 --history --overwrite --script-file creation_masque.nco dia_t${oce}_to_t${atm}_1storder_false_mask.nc tmp_dia_t${oce}_to_t${atm}_1storder_false_mask.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_false_mask.nc dia_t${oce}_to_t${atm}_1storder_false_mask.nc |
---|
185 | ncrename --history --variable OceFrac,OceMask dia_t${oce}_to_t${atm}_1storder_false_mask.nc |
---|
186 | |
---|
187 | ncks --alphabetize --history --append --variable OceMask dia_t${oce}_to_t${atm}_1storder_false_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
188 | rm dia_t${oce}_to_t${atm}_1storder_false_mask.nc |
---|
189 | |
---|
190 | ## |
---|
191 | ## Creates mask of coastal OCE points |
---|
192 | ## =========================================================================== |
---|
193 | python ComputeNemoCoast.py -n ${OcePerio} -i oce_grid.nc |
---|
194 | |
---|
195 | ## |
---|
196 | ## Creates mask of coastal ATM points |
---|
197 | ## =========================================================================== |
---|
198 | cat <<EOF > coastal.nco |
---|
199 | AtmCoastal = OceFrac * 0.0 ; |
---|
200 | where (OceFrac > 0.0 && OceFrac < 1.0 ) AtmCoastal = 1.0 ; |
---|
201 | EOF |
---|
202 | ncap2 --history --overwrite --script-file coastal.nco ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_coastal_maskFrom_${OCE}.nc |
---|
203 | ncks --history --append --variable AtmCoastal ${ATM}_coastal_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
204 | rm ${ATM}_coastal_maskFrom_${OCE}.nc |
---|
205 | |
---|
206 | ## |
---|
207 | ## NEMO, other case, towards ATM |
---|
208 | ## =========================================================================== |
---|
209 | for order in ${ListOrder} ; do |
---|
210 | case ${order} in |
---|
211 | ( 1st ) num_order=1 ;; |
---|
212 | ( 2nd ) num_order=2 ;; |
---|
213 | esac |
---|
214 | for normalize in ${ListNormalize} ; do |
---|
215 | for OCEGRID in ${ListOCEGRID} ; do |
---|
216 | ocegrid=${OCEGRID,,} |
---|
217 | |
---|
218 | if [[ ! -f rmp_${ocegrid}${oce}_to_t${atm}_${order}order_${normalize}.nc ]] ; then |
---|
219 | |
---|
220 | echo ${Green}"${OCE} ${OCEGRID} toward ${ATM} - ${order}order - normalize: ${normalize}"${Norm} |
---|
221 | |
---|
222 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' -k name -v maskutil_${OCEGRID} |
---|
223 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
224 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
225 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name -v maskutil_${OCEGRID} |
---|
226 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_${ocegrid}${oce}_to_t${atm}_${order}order_${normalize} |
---|
227 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${OCE} mask interpolated to ${ATM}" |
---|
228 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${oce_domain_type} |
---|
229 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${atm_domain_type} |
---|
230 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t ${num_order} |
---|
231 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize} |
---|
232 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
233 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
234 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v ${num_order} |
---|
235 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_${ocegrid}${oce}_to_t${atm}_${order}order_${normalize}.nc |
---|
236 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v ${normalize} |
---|
237 | |
---|
238 | cp iodef.xml iodef_${ocegrid}${oce}_t${atm}_${order}order_${normalize}.xml |
---|
239 | |
---|
240 | time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
241 | fi |
---|
242 | |
---|
243 | done |
---|
244 | done |
---|
245 | done |
---|
246 | |
---|
247 | ## |
---|
248 | ## ATM towards NEMO points |
---|
249 | ## =========================================================================== |
---|
250 | cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml iodef.xml |
---|
251 | |
---|
252 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} |
---|
253 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} |
---|
254 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${ATM} mask interpolated to ${OCE}" |
---|
255 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${atm_domain_type} |
---|
256 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${oce_domain_type} |
---|
257 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} |
---|
258 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} |
---|
259 | |
---|
260 | for order in ${ListOrder} ; do |
---|
261 | case ${order} in |
---|
262 | ( 1st ) num_order=1 ;; |
---|
263 | ( 2nd ) num_order=2 ;; |
---|
264 | esac |
---|
265 | for normalize in ${ListNormalize} ; do |
---|
266 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v ${num_order} |
---|
267 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t ${num_order} |
---|
268 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize} |
---|
269 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v ${normalize} |
---|
270 | |
---|
271 | for OCEGRID in ${ListOCEGRID} ; do |
---|
272 | ocegrid=${OCEGRID,,} |
---|
273 | |
---|
274 | echo ${Green}"${ATM} toward ${OCE} ${OCEGRID} - ${order}order - normalize: ${normalize}"${Norm} |
---|
275 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]' -k name -v mask_${OCEGRID} |
---|
276 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="mask_dest"]' -k name -v mask_${OCEGRID} |
---|
277 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_t${atm}_to_${ocegrid}${oce}_${order}order_${normalize} |
---|
278 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_t${atm}_to_${ocegrid}${oce}_${order}order_${normalize}.nc |
---|
279 | cp iodef.xml iodef_t${atm}_to_${ocegrid}${oce}_${order}order_${normalize}.xml |
---|
280 | |
---|
281 | time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
282 | |
---|
283 | done |
---|
284 | done |
---|
285 | done |
---|
286 | |
---|
287 | ## |
---|
288 | ## ATM towards NEMO points - runoff |
---|
289 | ## =========================================================================== |
---|
290 | cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml iodef.xml |
---|
291 | for normalize in ${ListNormalize} ; do |
---|
292 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} |
---|
293 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} |
---|
294 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${ATM} coastal mask interpolated to ${OCE}" |
---|
295 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${atm_domain_type} |
---|
296 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${oce_domain_type} |
---|
297 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} |
---|
298 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} |
---|
299 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1 |
---|
300 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t 1 |
---|
301 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize} |
---|
302 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]' -k name -v ${ATM}_grid_maskFrom_${OCE} |
---|
303 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' -k name -v AtmCoastal |
---|
304 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]' -k name -v OceCoastal |
---|
305 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_c${atm}_to_t${oce}_1storder_${normalize} |
---|
306 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_c${atm}_to_t${oce}_1storder_${normalize}.nc |
---|
307 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v ${normalize} |
---|
308 | |
---|
309 | cp iodef.xml iodef_c${atm}_to_t${oce}_1storder_${normalize}.xml |
---|
310 | |
---|
311 | time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
312 | done |
---|
313 | ## |
---|
314 | ## Change all NetCDF files to NetCDF 3 format (needed for OASIS) |
---|
315 | ## =========================================================================== |
---|
316 | for InFile in *.nc ; do |
---|
317 | mv ${InFile} tmp_${InFile} |
---|
318 | ncks --alphabetize --fl_fmt=${FL_FMT} --history tmp_${InFile} ${InFile} |
---|
319 | done |
---|
320 | |
---|
321 | ## |
---|
322 | ## Add time axis and coordinates information |
---|
323 | ## (needed if files need to be read by XIOS) |
---|
324 | ## =========================================================================== |
---|
325 | #ncatted --history -a coordinates,aire,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc |
---|
326 | ncap2 --overwrite --history --script 'defdim("time_counter",1) ;' ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
327 | |
---|
328 | if [[ ${atm} = ico ]] ; then |
---|
329 | cat <<EOF > add_time.nco |
---|
330 | OceFrac [time_counter,cell] = OceFrac (:) ; |
---|
331 | OceMask [time_counter,cell] = OceMask (:) ; |
---|
332 | AtmCoastal [time_counter,cell] = AtmCoastal (:) ; |
---|
333 | EOF |
---|
334 | ncap2 --overwrite --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
335 | ncatted --history \ |
---|
336 | -a coordinates,OceFrac,c,c,"time_counter cell" \ |
---|
337 | -a coordinates,OceMask,c,c,"time_counter cell" \ |
---|
338 | -a coordinates,AtmCoastal,c,c,"time_counter cell" \ |
---|
339 | -a coordinates,aire,c,c,"cell" \ |
---|
340 | ${ATM}_grid_maskFrom_${OCE}.nc |
---|
341 | fi |
---|
342 | if [[ ${atm} = lmd ]] ; then |
---|
343 | cat <<EOF > add_time.nco |
---|
344 | OceFrac [time_counter,lat,lon] = OceFrac (:,:) ; |
---|
345 | OceMask [time_counter,lat,lon] = OceMask (:,:) ; |
---|
346 | AtmCoastal [time_counter,lat,lon] = AtmCoastal (:,:) ; |
---|
347 | EOF |
---|
348 | ncap2 --overwrite --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
349 | ncatted --history \ |
---|
350 | -a coordinates,OceFrac,c,c,"time_counter lat lon" \ |
---|
351 | -a coordinates,OceMask,c,c,"time_counter lat lon" \ |
---|
352 | -a coordinates,AtmCoastal,c,c,"time_counter lat lon" \ |
---|
353 | -a coordinates,aire,c,c,"lat lon" \ |
---|
354 | ${ATM}_grid_maskFrom_${OCE}.nc |
---|
355 | fi |
---|
356 | ncks --alphabetize --overwrite --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
357 | |
---|
358 | |
---|
359 | ## |
---|
360 | ## Add some metadata in file headers |
---|
361 | ## =========================================================================== |
---|
362 | |
---|
363 | UUID=$(uuid) |
---|
364 | NCO="$(ncks --version |& tail -1|sed 's/ncks //')" |
---|
365 | PYTHON_VER=$( python -i -c "import sys ; print (sys.version.split(' ')[0])" ) |
---|
366 | for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ; do |
---|
367 | ncatted --history \ |
---|
368 | --attribute uuid,global,d,, \ |
---|
369 | --attribute LongName,global,d,, \ |
---|
370 | --attribute nco_openmp_thread_number,global,d,, \ |
---|
371 | --attribute Conventions,global,o,c,"CF-1.6" \ |
---|
372 | --attribute source,global,o,c,"IPSL Earth system model" \ |
---|
373 | --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center" \ |
---|
374 | --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr" \ |
---|
375 | --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu" \ |
---|
376 | --attribute Atmosphere,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr" \ |
---|
377 | --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') " \ |
---|
378 | --attribute originalFiles,global,o,c,"${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc" \ |
---|
379 | --attribute associatedFiles,global,o,c,"grids_${OCE}x${ATM}.nc areas_${OCE}x${ATM}.nc masks_${OCE}x${ATM}.nc" \ |
---|
380 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
381 | --attribute description,global,o,c,"Fields needed by OASIS-MCT" \ |
---|
382 | --attribute title,global,o,c,"${InFile}.nc" \ |
---|
383 | --attribute Program,global,o,c,"Generated by ${PROGRAM}" \ |
---|
384 | --attribute timeStamp,global,o,c,"$(date)" \ |
---|
385 | --attribute uuid,global,o,c,"${UUID}" \ |
---|
386 | --attribute HOSTNAME,global,o,c,"$(hostname)" \ |
---|
387 | --attribute LOGNAME,global,o,c,"$(whoami)" \ |
---|
388 | --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \ |
---|
389 | --attribute Python,global,o,c,"Python version ${PYTHON_VER}" \ |
---|
390 | --attribute OS,global,o,c,"$(uname -o)" \ |
---|
391 | --attribute release,global,o,c,"$(uname -r)" \ |
---|
392 | --attribute hardware,global,o,c,"$(uname -i)" \ |
---|
393 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
394 | --attribute description,global,o,c,"Generated with XIOS http://forge.ipsl.jussieu.fr/ioserver and MOSAIX https://forge.ipsl.jussieu.fr/igcmg/browser/TOOLS/MOSAIX" \ |
---|
395 | --attribute Comment,global,o,c,"Preliminary attempt - Do not trust !" \ |
---|
396 | --attribute SVN_Author,global,o,c,"$Author$" \ |
---|
397 | --attribute SVN_Date,global,o,c,"$Date$" \ |
---|
398 | --attribute SVN_Revision,global,o,c,"$Revision$" \ |
---|
399 | --attribute SVN_Id,global,o,c,"$Id$" \ |
---|
400 | ${InFile} |
---|
401 | done |
---|
402 | |
---|
403 | |
---|
404 | ## |
---|
405 | ## Update and complete weights file to fit OASIS requested format |
---|
406 | ## =========================================================================== |
---|
407 | cat <<EOF > add_dim.nco |
---|
408 | defdim("num_wgts",1) ; |
---|
409 | weight[n_weight, num_wgts] = weight ; |
---|
410 | EOF |
---|
411 | |
---|
412 | for rmpFile in rmp_*.nc ; do |
---|
413 | mv ${rmpFile} xios_${rmpFile} |
---|
414 | ncap2 --fl_fmt=${FL_FMT} --history --script-file add_dim.nco xios_${rmpFile} ${rmpFile} |
---|
415 | |
---|
416 | ncrename --history --dimension n_weight,num_links ${rmpFile} |
---|
417 | ncrename --history --variable src_idx,src_address ${rmpFile} |
---|
418 | ncrename --history --variable dst_idx,dst_address ${rmpFile} |
---|
419 | ncrename --history --variable weight,remap_matrix ${rmpFile} |
---|
420 | case ${rmpFile} in |
---|
421 | ( *_1storder_*.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order" ${rmpFile} ;; |
---|
422 | ( *_2ndorder_*.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order" ${rmpFile} ;; |
---|
423 | esac |
---|
424 | case ${rmpFile} in |
---|
425 | ( *_true.nc ) ncatted --history --attribute map_method,global,o,c,"Normalization: true" ${rmpFile} ;; |
---|
426 | ( *_false.nc ) ncatted --history --attribute map_method,global,o,c,"Normalization: false" ${rmpFile} ;; |
---|
427 | esac |
---|
428 | ncatted --history --attribute conventions,global,o,c,"SCRIP" ${rmpFile} |
---|
429 | ncatted --history --attribute normalization,global,o,c,"none" ${rmpFile} |
---|
430 | |
---|
431 | case ${rmpFile} in |
---|
432 | ( rmp_*${oce}_to_t${atm}_* ) |
---|
433 | ncatted --history \ |
---|
434 | --attribute title,global,o,c,"Weights ${OCE} to ${ATM}" \ |
---|
435 | --attribute source_grid,global,o,c,"${oce_domain_type}" \ |
---|
436 | --attribute dest_grid,global,o,c,"${atm_domain_type}" \ |
---|
437 | ${rmpFile} |
---|
438 | ;; |
---|
439 | ( rmp_*${atm}_to_*${oce}_* ) |
---|
440 | ncatted --history \ |
---|
441 | --attribute title,global,o,c,"Weights ${ATM} to ${OCE}" \ |
---|
442 | --attribute source_grid,global,o,c,"${atm_domain_type}" \ |
---|
443 | --attribute dest_grid,global,o,c,"${oce_domain_type}" \ |
---|
444 | ${rmpFile} |
---|
445 | ;; |
---|
446 | esac |
---|
447 | done |
---|
448 | |
---|
449 | ## |
---|
450 | ## Add missing variables in rmp files |
---|
451 | ## =========================================================================== |
---|
452 | for rmpFile in rmp_* ; do |
---|
453 | a_to_o=false ; o_to_a=false |
---|
454 | case ${rmpFile} in |
---|
455 | ( rmp_?${oce}_to_?${atm}_*.nc ) o_to_a=true ;; |
---|
456 | ( rmp_?${atm}_to_?${oce}_*.nc ) a_to_o=true ;; |
---|
457 | esac |
---|
458 | |
---|
459 | for Grid in t u v c ; do # Identify grids |
---|
460 | case ${rmpFile} in |
---|
461 | ( rmp_${Grid}${oce}_to_?${atm}_*.nc ) ogrid=${Grid} ;; |
---|
462 | ( rmp_?${oce}_to_${Grid}${atm}_*.nc ) agrid=${Grid} ;; |
---|
463 | ( rmp_${Grid}${atm}_to_?${oce}_*.nc ) agrid=${Grid} ;; |
---|
464 | ( rmp_?${atm}_to_${Grid}${oce}_*.nc ) ogrid=${Grid} ;; |
---|
465 | esac |
---|
466 | done |
---|
467 | OGRID=${ogrid^} |
---|
468 | AGRID=${agrid^} |
---|
469 | |
---|
470 | cat <<EOF >add_varoce.nco |
---|
471 | defdim ("src_grid_size" , \$x_grid_${OGRID}.size*\$y_grid_${OGRID}.size) ; |
---|
472 | defdim ("src_grid_corners", 4) ; |
---|
473 | defdim ("src_grid_rank" , 2) ; |
---|
474 | // |
---|
475 | src_grid_dims[src_grid_rank] = { \$y_grid_${OGRID}.size, \$x_grid_${OGRID}.size } ; |
---|
476 | // |
---|
477 | src_grid_center_lat [src_grid_size] = 0.0d ; |
---|
478 | src_grid_center_lon [src_grid_size] = 0.0d ; |
---|
479 | src_grid_center_lat (:) = nav_lat_grid_${OGRID}(:,:) ; |
---|
480 | src_grid_center_lon (:) = nav_lon_grid_${OGRID}(:,:) ; |
---|
481 | // |
---|
482 | src_grid_corner_lat [src_grid_size, src_grid_corners] = 0.0d ; |
---|
483 | src_grid_corner_lon [src_grid_size, src_grid_corners] = 0.0d ; |
---|
484 | src_grid_corner_lat(:,:) = bounds_lat_grid_${OGRID}(:,:,:) ; |
---|
485 | src_grid_corner_lon(:,:) = bounds_lon_grid_${OGRID}(:,:,:) ; |
---|
486 | // |
---|
487 | src_grid_imask [src_grid_size] = 0 ; |
---|
488 | src_grid_area [src_grid_size] = 0.0d ; |
---|
489 | src_grid_frac [src_grid_size] = 1.0d ; |
---|
490 | src_grid_imask (:) = 1 - mask_${OGRID}(:,:) ; |
---|
491 | src_grid_imask.int() ; |
---|
492 | src_grid_area (:) = area_grid_${OGRID}(:,:) ; |
---|
493 | EOF |
---|
494 | |
---|
495 | [[ ${o_to_a} = true ]] && ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${rmpFile} |
---|
496 | sed --in-place "s/src_/dst_/g" add_varoce.nco |
---|
497 | [[ ${a_to_o} = true ]] && ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${rmpFile} |
---|
498 | |
---|
499 | if [[ ${atm} = ico ]] ; then |
---|
500 | cat <<EOF >add_varatm.nco |
---|
501 | defdim ("dst_grid_size" , \$cell.size) ; |
---|
502 | defdim ("dst_grid_corners", 6) ; |
---|
503 | defdim ("dst_grid_rank" , 2) ; |
---|
504 | // |
---|
505 | dst_grid_dims[dst_grid_rank] = { \$cell.size, 1 } ; |
---|
506 | // |
---|
507 | dst_grid_center_lat [dst_grid_size] = 0.0d ; |
---|
508 | dst_grid_center_lon [dst_grid_size] = 0.0d ; |
---|
509 | dst_grid_center_lat (:) = lat(:) ; |
---|
510 | dst_grid_center_lon (:) = lon(:) ; |
---|
511 | // |
---|
512 | dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ; |
---|
513 | dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ; |
---|
514 | dst_grid_corner_lat(:,:) = bounds_lat(:,:) ; |
---|
515 | dst_grid_corner_lon(:,:) = bounds_lon(:,:) ; |
---|
516 | // |
---|
517 | dst_grid_imask [dst_grid_size] = 0 ; |
---|
518 | dst_grid_area [dst_grid_size] = 0.0d ; |
---|
519 | dst_grid_frac [dst_grid_size] = 1.0d ; |
---|
520 | dst_grid_imask (:) = 1 - OceMask(0,:) ; |
---|
521 | dst_grid_imask.int() ; |
---|
522 | dst_grid_area (:) = aire(:) ; |
---|
523 | EOF |
---|
524 | if [[ ${o_to_a} = true ]] ; then |
---|
525 | ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile} |
---|
526 | ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${rmpFile} rmp_tmp.nc |
---|
527 | mv rmp_tmp.nc ${rmpFile} |
---|
528 | fi |
---|
529 | |
---|
530 | sed --in-place "s/dst_/src_/g" add_varatm.nco |
---|
531 | if [[ ${a_to_o} = true ]] ; then |
---|
532 | ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile} |
---|
533 | ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${rmpFile} rmp_tmp.nc |
---|
534 | mv rmp_tmp.nc ${rmpFile} |
---|
535 | fi |
---|
536 | fi |
---|
537 | if [[ ${atm} = lmd ]] ; then |
---|
538 | cat <<EOF >add_varatm.nco |
---|
539 | defdim ("dst_grid_size" , \$lon.size*\$lat.size) ; |
---|
540 | defdim ("dst_grid_corners", 4) ; |
---|
541 | defdim ("dst_grid_rank" , 2) ; |
---|
542 | // |
---|
543 | dst_grid_dims[dst_grid_rank] = { \$lat.size, \$lon.size } ; |
---|
544 | // |
---|
545 | dst_grid_center_lat [dst_grid_size] = 0.0d ; |
---|
546 | dst_grid_center_lon [dst_grid_size] = 0.0d ; |
---|
547 | lat0lon[lat,lon] = lat(:)+0*lon(:) ; |
---|
548 | lon0lat[lat,lon] = lon(:)+0*lat(:) ; |
---|
549 | dst_grid_center_lat (:) = lat0lon(:,:) ; |
---|
550 | dst_grid_center_lon (:) = lon0lat(:,:) ; |
---|
551 | // |
---|
552 | //dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ; // Not available for LMDZ lon/lat grid |
---|
553 | //dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ; |
---|
554 | //dst_grid_corner_lat(:,:) = bounds_lat(:,:) ; |
---|
555 | //dst_grid_corner_lon(:,:) = bounds_lon(:,:) ; |
---|
556 | // |
---|
557 | dst_grid_imask [dst_grid_size] = 0 ; |
---|
558 | dst_grid_area [dst_grid_size] = 0.0d ; |
---|
559 | dst_grid_frac [dst_grid_size] = 1.0d ; |
---|
560 | dst_grid_imask (:) = 1 - OceMask(0,:,:) ; |
---|
561 | dst_grid_imask.int() ; |
---|
562 | dst_grid_area (:) = aire(:,:) ; |
---|
563 | dst_grid_frac (:) = OceFrac(0,:,:) ; |
---|
564 | EOF |
---|
565 | if [[ ${o_to_a} = true ]] ; then |
---|
566 | ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile} |
---|
567 | ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_area,dst_grid_imask ${rmpFile} rmp_tmp.nc |
---|
568 | mv rmp_tmp.nc ${rmpFile} |
---|
569 | fi |
---|
570 | |
---|
571 | sed --in-place "s/dst/src/g" add_varatm.nco |
---|
572 | if [[ ${a_to_o} = true ]] ; then |
---|
573 | ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile} |
---|
574 | ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${rmpFile} rmp_tmp.nc |
---|
575 | mv rmp_tmp.nc ${rmpFile} |
---|
576 | fi |
---|
577 | fi |
---|
578 | done |
---|
579 | |
---|
580 | ## |
---|
581 | ## Save results |
---|
582 | ## =========================================================================== |
---|
583 | cp ${ATM}_grid_maskFrom_${OCE}.nc ${SUBMIT_DIR} |
---|
584 | for File in dia_*.nc rmp_*.nc |
---|
585 | do |
---|
586 | NewFile=$(echo ${File} | sed -e "s/${atm}/${ATM}/" -e "s/${oce}/${OCE}/" ) |
---|
587 | cp ${File} ${SUBMIT_DIR}/${NewFile} |
---|
588 | done |
---|
589 | |
---|
590 | ## |
---|
591 | ## Creates and save auxiliary files for OASIS |
---|
592 | ## =========================================================================== |
---|
593 | bash ${SUBMIT_DIR}/CreateOasisGrids.bash --oce ${OCE} --atm ${ATM} |
---|
594 | |
---|
595 | cp areas_${OCE}x${ATM}.nc ${SUBMIT_DIR} |
---|
596 | cp grids_${OCE}x${ATM}.nc ${SUBMIT_DIR} |
---|
597 | cp masks_${OCE}x${ATM}.nc ${SUBMIT_DIR} |
---|
598 | |
---|
599 | |
---|
600 | ## =========================================================================== |
---|
601 | ## |
---|
602 | ## That's all folk's !!! |
---|
603 | ## |
---|
604 | ## =========================================================================== |
---|
605 | |
---|