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 8 # Number of processors |
---|
7 | #MSUB -T 1800 # Time limit (seconds) |
---|
8 | #MSUB -q skylake |
---|
9 | #MSUB -Q test |
---|
10 | #MSUB -p gen2212 |
---|
11 | #MSUB -m work |
---|
12 | |
---|
13 | ### =========================================================================== |
---|
14 | ### |
---|
15 | ### Creates interpolation weights between ORCA and atmosphere grids. |
---|
16 | ### Interpolates ORCA mask to atmosphere grid. |
---|
17 | ### Weight files are at OASIS-MCT format. |
---|
18 | ### |
---|
19 | ### Atmosphere grid may be lon/lat LMDZ or DYNAMICO icosahedron |
---|
20 | ### |
---|
21 | ### Documentation : https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX |
---|
22 | ### =========================================================================== |
---|
23 | ## |
---|
24 | ## Warning, to install, configure, run, use any of Olivier Marti's |
---|
25 | ## software or to read the associated documentation you'll need at least |
---|
26 | ## one (1) brain in a reasonably working order. Lack of this implement |
---|
27 | ## will void any warranties (either express or implied). |
---|
28 | ## O. Marti assumes no responsability for errors, omissions, |
---|
29 | ## data loss, or any other consequences caused directly or indirectly by |
---|
30 | ## the usage of his software by incorrectly or partially configured |
---|
31 | ## personal. |
---|
32 | ## |
---|
33 | ## SVN information |
---|
34 | # $Author$ |
---|
35 | # $Date$ |
---|
36 | # $Revision$ |
---|
37 | # $Id$ |
---|
38 | # $HeadURL$ |
---|
39 | # |
---|
40 | export Bold=$(tput bold) |
---|
41 | export Unde=$(tput smul) ; export OffUnde=$(tput rmul) |
---|
42 | export Stou=$(tput smso) ; export OffStou=$(tput rmso) |
---|
43 | export Reve=$(tput rev ) |
---|
44 | couleurs=( "Black" "Blue" "Green" "Cyan" "Red" "Magenta" "Yellow" "White" ) |
---|
45 | for i in $(seq 0 7 ) ; do eval "export ${couleurs[$i]}=$(tput setf $i)" ; done |
---|
46 | export Norm=$(tput sgr0 ) |
---|
47 | |
---|
48 | ## |
---|
49 | ## Configuration |
---|
50 | ## =========================================================================== |
---|
51 | |
---|
52 | # |
---|
53 | # Defines models |
---|
54 | # ============== |
---|
55 | OCE=ORCA2.3 |
---|
56 | #OCE=eORCA1.2 |
---|
57 | #OCE=ORCA025 |
---|
58 | |
---|
59 | #ATM=ICO30 |
---|
60 | #ATM=ICO40 |
---|
61 | #ATM=ICO450 |
---|
62 | ATM=LMD9695 |
---|
63 | #ATM=LMD144X142 |
---|
64 | |
---|
65 | # |
---|
66 | # Defines OCE grids to handle |
---|
67 | # =========================== |
---|
68 | ListOCEGRID="T" # U V |
---|
69 | ListOrder="1st" # 2nd |
---|
70 | ListNormalize="false true" |
---|
71 | ListQuantity="false true" |
---|
72 | |
---|
73 | ## =========================================================================== |
---|
74 | ## |
---|
75 | ## You should not change anything below this line .... |
---|
76 | ## |
---|
77 | ## =========================================================================== |
---|
78 | SUBMIT_DIR=$(pwd) |
---|
79 | |
---|
80 | # |
---|
81 | # Defines computer |
---|
82 | # ================ |
---|
83 | if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi |
---|
84 | if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi |
---|
85 | if [[ $(hostname) = lsce3005* ]] ; then arch=spip ; center=spip ; fi |
---|
86 | |
---|
87 | PROGRAM=$(basename ${0}) |
---|
88 | |
---|
89 | case ${arch} in |
---|
90 | ( irene ) |
---|
91 | set +vx |
---|
92 | module purge |
---|
93 | source $(ccc_home -u igcmg)/MachineEnvironment/irene/env_irene |
---|
94 | module load python/2.7.8 |
---|
95 | module load datadir/igcmg |
---|
96 | R_IN=$(ccc_home -u igcmg --cccwork)/IGCM |
---|
97 | TMPDIR=${CCCWORKDIR}/TMP |
---|
98 | SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}} |
---|
99 | PROGRAM=${BRIDGE_MSUB_REQNAME} |
---|
100 | MPIRUN=ccc_mprun |
---|
101 | module list |
---|
102 | ;; |
---|
103 | ( spip ) |
---|
104 | R_IN=${HOME}/Scratch/IGCM |
---|
105 | TMPDIR=${HOME}/Scratch/TMP |
---|
106 | SUBMIT_DIR=$(pwd) |
---|
107 | MPIRUN=/opt/local/bin/mpirun-openmpi-gcc49 -n 2 |
---|
108 | ;; |
---|
109 | ( * ) exit -1 ;; |
---|
110 | esac |
---|
111 | |
---|
112 | set -x ; set -e |
---|
113 | |
---|
114 | mkdir -p ${TMPDIR}/${OCE}x${ATM} || exit 1 |
---|
115 | cd ${TMPDIR}/${OCE}x${ATM} || exit 1 |
---|
116 | rm -fr * |
---|
117 | |
---|
118 | # |
---|
119 | # Suffixes |
---|
120 | # --------------------------------------------------------------------------- |
---|
121 | Listocegrid=${ListOCEGRID,,} |
---|
122 | |
---|
123 | case ${OCE} in |
---|
124 | ( *ORC* ) oce=orc ; oce_domain_type=curvilinear ;; |
---|
125 | esac |
---|
126 | case ${ATM} in |
---|
127 | ( *dynamico* ) atm=ico ; atm_domain_type=unstructured ;; |
---|
128 | ( *ICO* ) atm=ico ; atm_domain_type=unstructured ;; |
---|
129 | ( *lmd* | *LMD* ) atm=lmd ; atm_domain_type=rectilinear ;; |
---|
130 | esac |
---|
131 | |
---|
132 | case ${OCE} in |
---|
133 | ( ORCA2.3* ) OcePerio=4 ;; |
---|
134 | ( ORCA1* | eORCA1* ) OcePerio=6 ;; |
---|
135 | ( ORCA025* ) OcePerio=6 ;; |
---|
136 | esac |
---|
137 | # |
---|
138 | # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits |
---|
139 | # --------------------------------------------------------------------------- |
---|
140 | FMT_OASIS=64bit |
---|
141 | FMT_XIOS=netcdf4 |
---|
142 | |
---|
143 | cp ${SUBMIT_DIR}/bin/interpol.exe . |
---|
144 | cp ${SUBMIT_DIR}/*.py . |
---|
145 | |
---|
146 | cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc . |
---|
147 | cp ${R_IN}/ATM/GRID/${ATM}_grid.nc . |
---|
148 | |
---|
149 | ncks --overwrite --fl_fmt=${FMT_OASIS} --history ${OCE}_coordinates_mask.nc ${OCE}_coordinates_mask_${FMT_OASIS}.nc |
---|
150 | ncks --overwrite --fl_fmt=${FMT_OASIS} --history ${ATM}_grid.nc ${ATM}_grid_${FMT_OASIS}.nc |
---|
151 | # |
---|
152 | # Creates OCEAN C grid : redundant point removed to compute proper integrals # A passer dans CreateWeights |
---|
153 | # -------------------------------------------------------------------------------------------------------- |
---|
154 | cat <<EOF >add_c_grid.nco |
---|
155 | defdim("x_grid_C", \$x_grid_T.size) ; |
---|
156 | defdim("y_grid_C", \$y_grid_T.size) ; |
---|
157 | defdim("nvertex_grid_C", 4) ; |
---|
158 | nav_lon_grid_C[y_grid_C,x_grid_C] = nav_lon_grid_T(:,:) ; |
---|
159 | nav_lat_grid_C[y_grid_C,x_grid_C] = nav_lat_grid_T(:,:) ; |
---|
160 | bounds_lon_grid_C[y_grid_C,x_grid_C,nvertex_grid_C] = bounds_lon_grid_T(:,:,:) ; |
---|
161 | bounds_lat_grid_C[y_grid_C,x_grid_C,nvertex_grid_C] = bounds_lat_grid_T(:,:,:) ; |
---|
162 | mask_C[y_grid_C,x_grid_C] = maskutil_T(:,:) ; |
---|
163 | area_grid_C[y_grid_C,x_grid_C] = area_grid_T(:,:) ; |
---|
164 | EOF |
---|
165 | |
---|
166 | ncap2 --overwrite --history --script-file add_c_grid.nco ${OCE}_coordinates_mask.nc tmp_${OCE}_coordinates_mask.nc |
---|
167 | ncatted --history --attribute bounds,nav_lon_grid_C,m,c,"bounds_lon_grid_C" tmp_${OCE}_coordinates_mask.nc |
---|
168 | ncatted --history --attribute bounds,nav_lat_grid_C,m,c,"bounds_lat_grid_C" tmp_${OCE}_coordinates_mask.nc |
---|
169 | ncks --history --overwrite --variable nav_lon_grid_C,nav_lat_grid_C tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc |
---|
170 | ncks --history --append --variable bounds_lon_grid_C,bounds_lat_grid_C tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc |
---|
171 | ncks --history --append --variable area_grid_C tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc |
---|
172 | |
---|
173 | ncks --history --append C_${OCE}_coordinates_mask.nc ${OCE}_coordinates_mask.nc |
---|
174 | rm C_${OCE}_coordinates_mask.nc |
---|
175 | |
---|
176 | ncks --history --overwrite --fl_fmt=${FMT_OASIS} ${OCE}_coordinates_mask.nc ${OCE}_coordinates_mask_${FMT_OASIS}.nc |
---|
177 | |
---|
178 | ls -al |
---|
179 | |
---|
180 | ## |
---|
181 | ## NEMO T point towards ATM - 1st order |
---|
182 | ## =========================================================================== |
---|
183 | echo ${Green}"Initial case - ${OCE} T toward ${ATM} - 1stOrder - UnNormalized - Surfacic"${Norm} |
---|
184 | cp ${SUBMIT_DIR}/iodef_oce_to_atm.xml iodef.xml |
---|
185 | Suffix=1stOrder_UnNormalized_Surfacic |
---|
186 | |
---|
187 | 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 |
---|
188 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
189 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
190 | 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 |
---|
191 | 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}_${Suffix} |
---|
192 | 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}" |
---|
193 | 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} |
---|
194 | 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} |
---|
195 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t 1 |
---|
196 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
197 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
198 | 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}_${Suffix}.nc |
---|
199 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1 |
---|
200 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t false |
---|
201 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="quantity"]' -t false |
---|
202 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v false |
---|
203 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k quantity -v false |
---|
204 | |
---|
205 | cp iodef.xml iodef_t${oce}_to_t${atm}_${Suffix}.xml |
---|
206 | ln -fs ${OCE}_coordinates_mask.nc oce_grid.nc |
---|
207 | ln -fs ${ATM}_grid.nc atm_grid.nc |
---|
208 | |
---|
209 | time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=no |
---|
210 | ## |
---|
211 | ## Correct spurious values (extremes) |
---|
212 | ## =========================================================================== |
---|
213 | cat <<EOF > correction_masque.nco |
---|
214 | where (OceFrac < 0.00001 ) OceFrac=OceFrac.get_miss() ; |
---|
215 | where (OceFrac > 0.99999 ) OceFrac=1.0 ; |
---|
216 | OceFrac.delete_miss() ; |
---|
217 | // Fill masked values to land values |
---|
218 | where (OceFrac > 1.0 ) OceFrac=0.0 ; |
---|
219 | where (OceFrac < 0.0 ) OceFrac=0.0 ; |
---|
220 | EOF |
---|
221 | ncap2 --history --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_${Suffix}.nc tmp_dia_t${oce}_to_t${atm}_${Suffix}.nc ; mv tmp_dia_t${oce}_to_t${atm}_${Suffix}.nc dia_t${oce}_to_t${atm}_${Suffix}.nc |
---|
222 | ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_${Suffix}.nc |
---|
223 | |
---|
224 | ## |
---|
225 | ## Creates mask on ATM grid |
---|
226 | ## =========================================================================== |
---|
227 | cp dia_t${oce}_to_t${atm}_${Suffix}.nc dia_t${oce}_to_t${atm}_${Suffix}_mask.nc |
---|
228 | ncks --alphabetize --history --overwrite --variable OceFrac dia_t${oce}_to_t${atm}_${Suffix}_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
229 | |
---|
230 | cat <<EOF > creation_masque.nco |
---|
231 | where (OceFrac > 0.0 ) OceFrac=1 ; |
---|
232 | where (OceFrac <= 0.0 ) OceFrac=0 ; |
---|
233 | EOF |
---|
234 | |
---|
235 | ncap2 --history --overwrite --script-file creation_masque.nco dia_t${oce}_to_t${atm}_${Suffix}_mask.nc tmp_dia_t${oce}_to_t${atm}_${Suffix}_mask.nc ; mv tmp_dia_t${oce}_to_t${atm}_${Suffix}_mask.nc dia_t${oce}_to_t${atm}_${Suffix}_mask.nc |
---|
236 | ncrename --history --variable OceFrac,OceMask dia_t${oce}_to_t${atm}_${Suffix}_mask.nc |
---|
237 | |
---|
238 | ncks --overwrite --history --variable OceMask dia_t${oce}_to_t${atm}_${Suffix}_mask.nc tmp_OceMask.nc |
---|
239 | ncks --history --append tmp_OceMask.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
240 | rm dia_t${oce}_to_t${atm}_${Suffix}_mask.nc |
---|
241 | |
---|
242 | # Change dimension names, and some attributes accordingly |
---|
243 | if [[ $(ncdump -h ${ATM}_grid_maskFrom_${OCE}.nc | grep domain_dst | wc -l) -gt 0 ]] ; then |
---|
244 | case ${atm} in |
---|
245 | ( *ico* ) |
---|
246 | ncrename --history --dimension cell_domain_dst,cell ${ATM}_grid_maskFrom_${OCE}.nc |
---|
247 | ncrename --history --dimension nvertex_domain_dst,nvertex ${ATM}_grid_maskFrom_${OCE}.nc |
---|
248 | ncrename --history --variable lat_domain_dst,lat ${ATM}_grid_maskFrom_${OCE}.nc |
---|
249 | ncrename --history --variable lon_domain_dst,lon ${ATM}_grid_maskFrom_${OCE}.nc |
---|
250 | ncrename --history --variable bounds_lat_domain_dst,bounds_lat ${ATM}_grid_maskFrom_${OCE}.nc |
---|
251 | ncrename --history --variable bounds_lon_domain_dst,bounds_lon ${ATM}_grid_maskFrom_${OCE}.nc |
---|
252 | ncatted --history --attribute bounds,lat,m,c,"bounds_lat" ${ATM}_grid_maskFrom_${OCE}.nc |
---|
253 | ncatted --history --attribute bounds,lon,m,c,"bounds_lon" ${ATM}_grid_maskFrom_${OCE}.nc |
---|
254 | ;; |
---|
255 | ( *lmd* ) |
---|
256 | ncrename --history --dimension lon_domain_dst,lon ${ATM}_grid_maskFrom_${OCE}.nc |
---|
257 | ncrename --history --dimension lat_domain_dst,lat ${ATM}_grid_maskFrom_${OCE}.nc |
---|
258 | ;; |
---|
259 | esac |
---|
260 | ncatted --history --attribute coordinates,OceFrac,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc |
---|
261 | ncatted --history --attribute coordinates,OceMask,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc |
---|
262 | |
---|
263 | fi |
---|
264 | |
---|
265 | ncks --history --alphabetize --append --variable aire atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
266 | [[ ${atm} = *ico* ]] && ncks --alphabetize --history --append --variable bounds_lon,bounds_lat atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
267 | |
---|
268 | |
---|
269 | ## |
---|
270 | ## NEMO, other case, towards ATM |
---|
271 | ## =========================================================================== |
---|
272 | for order in ${ListOrder} ; do |
---|
273 | case ${order} in |
---|
274 | ( 1st ) num_order=1 ;; |
---|
275 | ( 2nd ) num_order=2 ;; |
---|
276 | esac |
---|
277 | for normalize in ${ListNormalize} ; do |
---|
278 | for quantity in ${ListQuantity} ; do |
---|
279 | for OCEGRID in ${ListOCEGRID} ; do |
---|
280 | ocegrid=${OCEGRID,,} |
---|
281 | |
---|
282 | case ${normalize} in |
---|
283 | ( true ) NormName=Normalized ;; |
---|
284 | ( false ) NormName=UnNormalized ;; |
---|
285 | esac |
---|
286 | case ${quantity} in |
---|
287 | ( true ) QuantName=Integrated ;; |
---|
288 | ( false ) QuantName=Surfacic ;; |
---|
289 | esac |
---|
290 | |
---|
291 | Suffix=${order}Order_${NormName}_${QuantName} |
---|
292 | |
---|
293 | if [[ ! -f rmp_${ocegrid}${oce}_to_t${atm}_${Suffix}.nc ]] ; then |
---|
294 | |
---|
295 | echo ${Green}"${OCE} ${OCEGRID} toward ${ATM} - ${order}Order - normalize: ${normalize} - quantity: ${quantity}"${Norm} |
---|
296 | |
---|
297 | 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} |
---|
298 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
299 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
300 | 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} |
---|
301 | 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}_${Suffix} |
---|
302 | 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}" |
---|
303 | 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} |
---|
304 | 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} |
---|
305 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t ${num_order} |
---|
306 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize} |
---|
307 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="quantity"]' -t ${quantity} |
---|
308 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
309 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
310 | 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} |
---|
311 | 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}_${Suffix}.nc |
---|
312 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v ${normalize} |
---|
313 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k quantity -v ${quantity} |
---|
314 | |
---|
315 | cp iodef.xml iodef_${ocegrid}${oce}_t${atm}_${Suffix}.xml |
---|
316 | |
---|
317 | ln -fs ${OCE}_coordinates_mask.nc oce_grid.nc |
---|
318 | ln -fs ${ATM}_grid.nc atm_grid.nc |
---|
319 | time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
320 | fi |
---|
321 | |
---|
322 | done |
---|
323 | done |
---|
324 | done |
---|
325 | done |
---|
326 | ## |
---|
327 | ## ATM towards NEMO points |
---|
328 | ## =========================================================================== |
---|
329 | cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml iodef.xml |
---|
330 | |
---|
331 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} |
---|
332 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} |
---|
333 | 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}" |
---|
334 | 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} |
---|
335 | 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} |
---|
336 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} |
---|
337 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} |
---|
338 | |
---|
339 | for order in ${ListOrder} ; do |
---|
340 | case ${order} in |
---|
341 | ( 1st ) num_order=1 ;; |
---|
342 | ( 2nd ) num_order=2 ;; |
---|
343 | esac |
---|
344 | for normalize in ${ListNormalize} ; do |
---|
345 | for quantity in ${ListQuantity} ; do |
---|
346 | case ${normalize} in |
---|
347 | ( true ) NormName=Normalized ;; |
---|
348 | ( false ) NormName=UnNormalized ;; |
---|
349 | esac |
---|
350 | case ${quantity} in |
---|
351 | ( true ) QuantName=Integrated ;; |
---|
352 | ( false ) QuantName=Surfacic ;; |
---|
353 | esac |
---|
354 | |
---|
355 | Suffix=${order}Order_${NormName}_${QuantName} |
---|
356 | |
---|
357 | 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} |
---|
358 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t ${num_order} |
---|
359 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize} |
---|
360 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="quantity"]' -t ${quantity} |
---|
361 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v ${normalize} |
---|
362 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k quantity -v ${quantity} |
---|
363 | |
---|
364 | for OCEGRID in ${ListOCEGRID} ; do |
---|
365 | ocegrid=${OCEGRID,,} |
---|
366 | |
---|
367 | echo ${Green}"${ATM} toward ${OCE} ${OCEGRID} - ${order}Order - normalize: ${normalize} - quantity: ${quantity}"${Norm} |
---|
368 | 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} |
---|
369 | 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} |
---|
370 | 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}_${Suffix} |
---|
371 | 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}_${Suffix}.nc |
---|
372 | cp iodef.xml iodef_t${atm}_to_${ocegrid}${oce}_${Suffix}.xml |
---|
373 | |
---|
374 | ln -fs ${OCE}_coordinates_mask.nc oce_grid.nc |
---|
375 | ln -fs ${ATM}_grid.nc atm_grid.nc |
---|
376 | time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
377 | |
---|
378 | done |
---|
379 | done |
---|
380 | done |
---|
381 | done |
---|
382 | ## |
---|
383 | ## Creates mask of coastal OCE points |
---|
384 | ## =========================================================================== |
---|
385 | python ComputeNemoCoast.py -n ${OcePerio} -i ${OCE}_coordinates_mask.nc # Creates OceCoastal |
---|
386 | ## |
---|
387 | ## Creates mask of coastal ATM points |
---|
388 | ## =========================================================================== |
---|
389 | cat <<EOF > coastal.nco |
---|
390 | AtmCoastal = OceFrac * 0.0 ; |
---|
391 | where (OceFrac > 0.0 && OceFrac < 1.0 ) AtmCoastal = 1.0 ; |
---|
392 | EOF |
---|
393 | ncap2 --history --overwrite --script-file coastal.nco ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_coastal_maskFrom_${OCE}.nc |
---|
394 | ncks --history --append --variable AtmCoastal ${ATM}_coastal_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
395 | rm ${ATM}_coastal_maskFrom_${OCE}.nc |
---|
396 | ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc |
---|
397 | |
---|
398 | ## |
---|
399 | ## ATM towards NEMO points - runoff |
---|
400 | ## =========================================================================== |
---|
401 | cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml iodef.xml |
---|
402 | for normalize in ${ListNormalize} ; do |
---|
403 | for quantity in ${ListQuantity} ; do |
---|
404 | case ${normalize} in |
---|
405 | ( true ) NormName=Normalized ;; |
---|
406 | ( false ) NormName=UnNormalized ;; |
---|
407 | esac |
---|
408 | case ${quantity} in |
---|
409 | ( true ) QuantName=Integrated ;; |
---|
410 | ( false ) QuantName=Surfacic ;; |
---|
411 | esac |
---|
412 | |
---|
413 | Suffix=${order}Order_${NormName}_${QuantName} |
---|
414 | |
---|
415 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} |
---|
416 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} |
---|
417 | 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}" |
---|
418 | 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} |
---|
419 | 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} |
---|
420 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} |
---|
421 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} |
---|
422 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1 |
---|
423 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t 1 |
---|
424 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize} |
---|
425 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="quantity"]' -t ${quantity} |
---|
426 | 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} |
---|
427 | 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 |
---|
428 | 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 |
---|
429 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_o${atm}_to_c${oce}_${Suffix} |
---|
430 | 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_o${atm}_to_c${oce}_${Suffix}.nc |
---|
431 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v ${normalize} |
---|
432 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k quantity -v ${quantity} |
---|
433 | |
---|
434 | cp iodef.xml iodef_o${atm}_to_c${oce}_${Suffix}.xml |
---|
435 | |
---|
436 | ln -fs ${OCE}_coordinates_mask.nc oce_grid.nc |
---|
437 | ln -fs ${ATM}_grid.nc atm_grid.nc |
---|
438 | time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
439 | |
---|
440 | # Now we should divide weight par source (atm) grid area : run-off is a quantity/s integrated on the grid mox, not a flux |
---|
441 | done |
---|
442 | done |
---|
443 | ## |
---|
444 | ## Copy all NetCDF files to NetCDF 3 format (needed for OASIS) |
---|
445 | ## =========================================================================== |
---|
446 | for InFile in *.nc ; do |
---|
447 | OuFile=$(basename ${InFile} .nc)_${FMT_OASIS}.nc |
---|
448 | if [[ ! -f ${OuFile} ]] ; then |
---|
449 | ncks --alphabetize --history --fl_fmt=${FMT_OASIS} ${InFile} ${OuFile} |
---|
450 | fi |
---|
451 | done |
---|
452 | |
---|
453 | ## |
---|
454 | ## Add time axis and coordinates information |
---|
455 | ## (needed if files need to be read by XIOS) |
---|
456 | ## =========================================================================== |
---|
457 | #ncatted --history -a coordinates,aire,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc |
---|
458 | 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 |
---|
459 | |
---|
460 | ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc |
---|
461 | |
---|
462 | if [[ ${atm} = ico ]] ; then |
---|
463 | cat <<EOF > add_time.nco |
---|
464 | OceFrac [time_counter,cell] = OceFrac [cell] ; |
---|
465 | OceMask [time_counter,cell] = OceMask [cell] ; |
---|
466 | AtmCoastal [time_counter,cell] = AtmCoastal [cell] ; |
---|
467 | EOF |
---|
468 | 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 |
---|
469 | ncatted --history \ |
---|
470 | -a coordinates,OceFrac,m,c,"time_counter lat lon" \ |
---|
471 | -a coordinates,OceMask,m,c,"time_counter lat lon" \ |
---|
472 | -a coordinates,AtmCoastal,m,c,"time_counter lat lon" \ |
---|
473 | -a coordinates,aire,c,c,"lat lon" \ |
---|
474 | ${ATM}_grid_maskFrom_${OCE}.nc |
---|
475 | fi |
---|
476 | ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc |
---|
477 | |
---|
478 | if [[ ${atm} = lmd ]] ; then |
---|
479 | cat <<EOF > add_time.nco |
---|
480 | OceFrac [time_counter,lat,lon] = OceFrac [lat,lon] ; |
---|
481 | OceMask [time_counter,lat,lon] = OceMask [lat,lon] ; |
---|
482 | AtmCoastal [time_counter,lat,lon] = AtmCoastal [lat,lon] ; |
---|
483 | EOF |
---|
484 | ncap2 --overwrite --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc |
---|
485 | ncdump -h tmp_${ATM}_grid_maskFrom_${OCE}.nc |
---|
486 | mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
487 | |
---|
488 | ncatted --history \ |
---|
489 | -a coordinates,OceFrac,m,c,"time_counter lat lon" \ |
---|
490 | -a coordinates,OceMask,m,c,"time_counter lat lon" \ |
---|
491 | -a coordinates,AtmCoastal,m,c,"time_counter lat lon" \ |
---|
492 | -a coordinates,aire,m,c,"lat lon" \ |
---|
493 | ${ATM}_grid_maskFrom_${OCE}.nc |
---|
494 | fi |
---|
495 | ncks --alphabetize --history --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 |
---|
496 | ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc |
---|
497 | |
---|
498 | ## |
---|
499 | ## Add some metadata in file headers |
---|
500 | ## =========================================================================== |
---|
501 | |
---|
502 | UUID=$(uuid) |
---|
503 | NCO="$(ncks --version |& tail -1|sed 's/ncks //')" |
---|
504 | PYTHON_VER=$( python -c "import sys ; print (sys.version.split(' ')[0])" ) |
---|
505 | for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc; do |
---|
506 | ncatted --history \ |
---|
507 | --attribute uuid,global,d,, \ |
---|
508 | --attribute LongName,global,d,, \ |
---|
509 | --attribute nco_openmp_thread_number,global,d,, \ |
---|
510 | --attribute Conventions,global,o,c,"CF-1.6" \ |
---|
511 | --attribute source,global,o,c,"IPSL Earth system model" \ |
---|
512 | --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center" \ |
---|
513 | --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr" \ |
---|
514 | --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu" \ |
---|
515 | --attribute Atmosphere,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr" \ |
---|
516 | --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') " \ |
---|
517 | --attribute originalFiles,global,o,c,"${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc" \ |
---|
518 | --attribute associatedFiles,global,o,c,"grids_${OCE}x${ATM}.nc areas_${OCE}x${ATM}.nc masks_${OCE}x${ATM}.nc" \ |
---|
519 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
520 | --attribute description,global,o,c,"Fields needed by OASIS-MCT" \ |
---|
521 | --attribute title,global,o,c,"${InFile}.nc" \ |
---|
522 | --attribute Program,global,o,c,"Generated by ${PROGRAM}" \ |
---|
523 | --attribute timeStamp,global,o,c,"$(date)" \ |
---|
524 | --attribute uuid,global,o,c,"${UUID}" \ |
---|
525 | --attribute HOSTNAME,global,o,c,"$(hostname)" \ |
---|
526 | --attribute LOGNAME,global,o,c,"$(whoami)" \ |
---|
527 | --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \ |
---|
528 | --attribute Python,global,o,c,"Python version ${PYTHON_VER}" \ |
---|
529 | --attribute OS,global,o,c,"$(uname -o)" \ |
---|
530 | --attribute release,global,o,c,"$(uname -r)" \ |
---|
531 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
532 | --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" \ |
---|
533 | --attribute Comment,global,o,c,"Preliminary attempt - Do not trust !" \ |
---|
534 | --attribute SVN_Author,global,o,c,'$Author$' \ |
---|
535 | --attribute SVN_Date,global,o,c,'$Date$' \ |
---|
536 | --attribute SVN_Revision,global,o,c,'$Revision$' \ |
---|
537 | --attribute SVN_Id,global,o,c,'$Id$' \ |
---|
538 | ${InFile} |
---|
539 | done |
---|
540 | ## |
---|
541 | ## Update and complete weights file to fit OASIS requested format |
---|
542 | ## =========================================================================== |
---|
543 | cat <<EOF > add_dim.nco |
---|
544 | defdim("num_wgts",1) ; |
---|
545 | weight[n_weight, num_wgts] = weight ; |
---|
546 | EOF |
---|
547 | |
---|
548 | for rmpFile in rmp_*.nc ; do |
---|
549 | mv ${rmpFile} xios_${rmpFile} |
---|
550 | ncap2 --fl_fmt=${FMT_OASIS} --history --script-file add_dim.nco xios_${rmpFile} ${rmpFile} |
---|
551 | |
---|
552 | ncrename --history --dimension n_weight,num_links ${rmpFile} |
---|
553 | ncrename --history --variable src_idx,src_address ${rmpFile} |
---|
554 | ncrename --history --variable dst_idx,dst_address ${rmpFile} |
---|
555 | ncrename --history --variable weight,remap_matrix ${rmpFile} |
---|
556 | case ${rmpFile} in |
---|
557 | ( *1storder* ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order" ${rmpFile} ;; |
---|
558 | ( *2ndorder* ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order" ${rmpFile} ;; |
---|
559 | esac |
---|
560 | case ${rmpFile} in |
---|
561 | ( *_Normalized* ) ncatted --history --attribute map_method,global,o,c,"Normalization: true" ${rmpFile} ;; |
---|
562 | ( *_UnNormalized* ) ncatted --history --attribute map_method,global,o,c,"Normalization: false" ${rmpFile} ;; |
---|
563 | esac |
---|
564 | case ${rmpFile} in |
---|
565 | ( *Integrated* ) ncatted --history --attribute map_method,global,o,c,"Quantity: true" ${rmpFile} ;; |
---|
566 | ( *Surfacic* ) ncatted --history --attribute map_method,global,o,c,"Quantity: false" ${rmpFile} ;; |
---|
567 | esac |
---|
568 | ncatted --history --attribute conventions,global,o,c,"SCRIP" ${rmpFile} |
---|
569 | ncatted --history --attribute normalization,global,o,c,"none" ${rmpFile} |
---|
570 | |
---|
571 | case ${rmpFile} in |
---|
572 | ( rmp_*${oce}_to_t${atm}_* ) |
---|
573 | ncatted --history \ |
---|
574 | --attribute title,global,o,c,"Weights ${OCE} to ${ATM}" \ |
---|
575 | --attribute source_grid,global,o,c,"${oce_domain_type}" \ |
---|
576 | --attribute dest_grid,global,o,c,"${atm_domain_type}" \ |
---|
577 | ${rmpFile} |
---|
578 | ;; |
---|
579 | ( rmp_*${atm}_to_*${oce}_* ) |
---|
580 | ncatted --history \ |
---|
581 | --attribute title,global,o,c,"Weights ${ATM} to ${OCE}" \ |
---|
582 | --attribute source_grid,global,o,c,"${atm_domain_type}" \ |
---|
583 | --attribute dest_grid,global,o,c,"${oce_domain_type}" \ |
---|
584 | ${rmpFile} |
---|
585 | ;; |
---|
586 | esac |
---|
587 | done |
---|
588 | |
---|
589 | ## |
---|
590 | ## Add missing variables in rmp files |
---|
591 | ## =========================================================================== |
---|
592 | for rmpFile in rmp_?${atm}_to_[tuv]${oce}_*.nc rmp_[tuv]${oce}_to_t${atm}_*.nc* ; do |
---|
593 | echo ${rmpFile} |
---|
594 | a_to_o=false ; o_to_a=false |
---|
595 | case ${rmpFile} in |
---|
596 | ( rmp_?${oce}_to_?${atm}_*.nc ) o_to_a=true ;; |
---|
597 | ( rmp_?${atm}_to_?${oce}_*.nc ) a_to_o=true ;; |
---|
598 | esac |
---|
599 | |
---|
600 | for Grid in t u v o c ; do # Identify grids |
---|
601 | [[ ${rmpFile} = rmp_${Grid}${oce}_to_?${atm}_*.nc ]] && ogrid=${Grid} |
---|
602 | [[ ${rmpFile} = rmp_?${oce}_to_${Grid}${atm}_*.nc ]] && agrid=${Grid} |
---|
603 | [[ ${rmpFile} = rmp_${Grid}${atm}_to_?${oce}_*.nc ]] && agrid=${Grid} |
---|
604 | [[ ${rmpFile} = rmp_?${atm}_to_${Grid}${oce}_*.nc ]] && ogrid=${Grid} |
---|
605 | done |
---|
606 | OGRID=${ogrid^} |
---|
607 | AGRID=${agrid^} |
---|
608 | |
---|
609 | cat <<EOF >add_varoce.nco |
---|
610 | defdim ("src_grid_size" , \$x_grid_${OGRID}.size*\$y_grid_${OGRID}.size) ; |
---|
611 | defdim ("src_grid_corners", 4) ; |
---|
612 | defdim ("src_grid_rank" , 2) ; |
---|
613 | // |
---|
614 | src_grid_dims[src_grid_rank] = { \$y_grid_${OGRID}.size, \$x_grid_${OGRID}.size } ; |
---|
615 | // |
---|
616 | src_grid_center_lat [src_grid_size] = 0.0d ; |
---|
617 | src_grid_center_lon [src_grid_size] = 0.0d ; |
---|
618 | src_grid_center_lat (:) = nav_lat_grid_${OGRID}(:,:) ; |
---|
619 | src_grid_center_lon (:) = nav_lon_grid_${OGRID}(:,:) ; |
---|
620 | // |
---|
621 | src_grid_corner_lat [src_grid_size, src_grid_corners] = 0.0d ; |
---|
622 | src_grid_corner_lon [src_grid_size, src_grid_corners] = 0.0d ; |
---|
623 | src_grid_corner_lat(:,:) = bounds_lat_grid_${OGRID}(:,:,:) ; |
---|
624 | src_grid_corner_lon(:,:) = bounds_lon_grid_${OGRID}(:,:,:) ; |
---|
625 | // |
---|
626 | src_grid_imask [src_grid_size] = 0 ; |
---|
627 | src_grid_area [src_grid_size] = 0.0d ; |
---|
628 | src_grid_frac [src_grid_size] = 1.0d ; |
---|
629 | src_grid_imask (:) = 1 - mask_${OGRID}(:,:) ; |
---|
630 | src_grid_imask.int() ; |
---|
631 | src_grid_area (:) = area_grid_${OGRID}(:,:) ; |
---|
632 | EOF |
---|
633 | |
---|
634 | cp add_varoce.nco add_varoce_$(basename ${rmpFile} .nc)_o_to_a.nco |
---|
635 | [[ ${o_to_a} = true ]] && ncap2 --history --append --script-file add_varoce_$(basename ${rmpFile} .nc)_o_to_a.nco ${OCE}_coordinates_mask_${FMT_OASIS}.nc ${rmpFile} |
---|
636 | sed --in-place "s/src_/dst_/g" add_varoce.nco |
---|
637 | cp add_varoce.nco add_varoce_$(basename ${rmpFile} .nc)_a_to_o.nco |
---|
638 | [[ ${a_to_o} = true ]] && ncap2 --history --append --script-file add_varoce_$(basename ${rmpFile} .nc)_a_to_o.nco ${OCE}_coordinates_mask_${FMT_OASIS}.nc ${rmpFile} |
---|
639 | |
---|
640 | if [[ ${atm} = ico ]] ; then |
---|
641 | cat <<EOF >add_varatm.nco |
---|
642 | defdim ("dst_grid_size" , \$cell.size) ; |
---|
643 | defdim ("dst_grid_corners", 6) ; |
---|
644 | defdim ("dst_grid_rank" , 2) ; |
---|
645 | // |
---|
646 | dst_grid_dims[dst_grid_rank] = { \$cell.size, 1 } ; |
---|
647 | // |
---|
648 | dst_grid_center_lat [dst_grid_size] = 0.0d ; |
---|
649 | dst_grid_center_lon [dst_grid_size] = 0.0d ; |
---|
650 | dst_grid_center_lat (:) = lat(:) ; |
---|
651 | dst_grid_center_lon (:) = lon(:) ; |
---|
652 | // |
---|
653 | dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ; |
---|
654 | dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ; |
---|
655 | dst_grid_corner_lat(:,:) = bounds_lat(:,:) ; |
---|
656 | dst_grid_corner_lon(:,:) = bounds_lon(:,:) ; |
---|
657 | // |
---|
658 | dst_grid_imask [dst_grid_size] = 0 ; |
---|
659 | dst_grid_area [dst_grid_size] = 0.0d ; |
---|
660 | dst_grid_frac [dst_grid_size] = 1.0d ; |
---|
661 | dst_grid_imask (:) = 1 - OceMask(0,:) ; |
---|
662 | dst_grid_imask.int() ; |
---|
663 | dst_grid_area (:) = aire(:) ; |
---|
664 | dst_grid_frac (:) = OceFrac(0,:) ; |
---|
665 | EOF |
---|
666 | cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco |
---|
667 | if [[ ${o_to_a} = true ]] ; then |
---|
668 | ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile} |
---|
669 | 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 |
---|
670 | mv rmp_tmp.nc ${rmpFile} |
---|
671 | fi |
---|
672 | |
---|
673 | sed --in-place "s/dst_/src_/g" add_varatm.nco |
---|
674 | cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco |
---|
675 | if [[ ${a_to_o} = true ]] ; then |
---|
676 | ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile} |
---|
677 | 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 |
---|
678 | mv rmp_tmp.nc ${rmpFile} |
---|
679 | fi |
---|
680 | fi |
---|
681 | |
---|
682 | if [[ ${atm} = lmd ]] ; then |
---|
683 | cat <<EOF >add_varatm.nco |
---|
684 | defdim ("dst_grid_size" , \$lon.size*\$lat.size) ; |
---|
685 | defdim ("dst_grid_corners", 4) ; |
---|
686 | defdim ("dst_grid_rank" , 2) ; |
---|
687 | // |
---|
688 | dst_grid_dims[dst_grid_rank] = { \$lat.size, \$lon.size } ; |
---|
689 | // |
---|
690 | dst_grid_center_lat [dst_grid_size] = 0.0d ; |
---|
691 | dst_grid_center_lon [dst_grid_size] = 0.0d ; |
---|
692 | lat0lon[lat,lon] = lat(:)+0*lon(:) ; |
---|
693 | lon0lat[lat,lon] = lon(:)+0*lat(:) ; |
---|
694 | dst_grid_center_lat (:) = lat0lon(:,:) ; |
---|
695 | dst_grid_center_lon (:) = lon0lat(:,:) ; |
---|
696 | // |
---|
697 | //dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ; // Not available for LMDZ lon/lat grid |
---|
698 | //dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ; |
---|
699 | //dst_grid_corner_lat(:,:) = bounds_lat(:,:) ; |
---|
700 | //dst_grid_corner_lon(:,:) = bounds_lon(:,:) ; |
---|
701 | // |
---|
702 | dst_grid_imask [dst_grid_size] = 0 ; |
---|
703 | dst_grid_area [dst_grid_size] = 0.0d ; |
---|
704 | dst_grid_frac [dst_grid_size] = 1.0d ; |
---|
705 | dst_grid_imask (:) = 1 - OceMask(0,:,:) ; |
---|
706 | dst_grid_imask.int() ; |
---|
707 | dst_grid_area (:) = aire(:,:) ; |
---|
708 | dst_grid_frac (:) = OceFrac(0,:,:) ; |
---|
709 | EOF |
---|
710 | cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco |
---|
711 | if [[ ${o_to_a} = true ]] ; then |
---|
712 | ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile} |
---|
713 | 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 |
---|
714 | mv rmp_tmp.nc ${rmpFile} |
---|
715 | fi |
---|
716 | |
---|
717 | sed --in-place "s/dst/src/g" add_varatm.nco |
---|
718 | cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco |
---|
719 | if [[ ${a_to_o} = true ]] ; then |
---|
720 | ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile} |
---|
721 | 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 |
---|
722 | mv rmp_tmp.nc ${rmpFile} |
---|
723 | fi |
---|
724 | fi |
---|
725 | done |
---|
726 | ls -al ${OCE}_coordinates_mask.nc |
---|
727 | |
---|
728 | ## |
---|
729 | ## Creates and save auxiliary files for OASIS |
---|
730 | ## =========================================================================== |
---|
731 | bash ${SUBMIT_DIR}/CreateOasisGrids.bash --oce ${OCE} --atm ${ATM} |
---|
732 | |
---|
733 | cp areas_${OCE}x${ATM}.nc ${SUBMIT_DIR} |
---|
734 | cp grids_${OCE}x${ATM}.nc ${SUBMIT_DIR} |
---|
735 | cp masks_${OCE}x${ATM}.nc ${SUBMIT_DIR} |
---|
736 | |
---|
737 | ## |
---|
738 | ## Calving |
---|
739 | ## =========================================================================== |
---|
740 | case ${OCE} in |
---|
741 | ( eORCA1.2 ) |
---|
742 | cp ${R_IN}/OCE/NEMO/ORCA1_LIM3_PISCES/v3.6_stable/runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc . |
---|
743 | for Type in nosouth iceberg iceshelf ; do |
---|
744 | python CalvingWeights.py --oce=${OCE} --atm=${ATM} --type=${Type} --dir=. --isf_icb=runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc |
---|
745 | done |
---|
746 | ;; |
---|
747 | ( * ) |
---|
748 | python CalvingWeights.py --oce=${OCE} --atm=${ATM} --type=full --dir=. |
---|
749 | ;; |
---|
750 | esac |
---|
751 | |
---|
752 | ## |
---|
753 | ## Save results |
---|
754 | ## =========================================================================== |
---|
755 | cp ${ATM}_grid_maskFrom_${OCE}.nc ${SUBMIT_DIR} |
---|
756 | for File in dia_*.nc rmp_*.nc |
---|
757 | do |
---|
758 | ncatted --history --attribute history_of_appended_files,global,d,c,"" ${File} |
---|
759 | NewFile=$(echo ${File} | sed -e "s/${atm}/${ATM}/" -e "s/${oce}/${OCE}/" ) |
---|
760 | cp ${File} ${SUBMIT_DIR}/${NewFile} |
---|
761 | done |
---|
762 | |
---|
763 | ## |
---|
764 | ## Creates a README.txt file |
---|
765 | ## =========================================================================== |
---|
766 | [[ -f README.txt ]] && rm README.txt |
---|
767 | |
---|
768 | cat <<EOF > README.txt |
---|
769 | Files produced by CreateWeightsMask.bash and CreateOasisGrids.bash |
---|
770 | |
---|
771 | rmp_* are weights files |
---|
772 | dia_* are diagnostic files not needed for the coupler |
---|
773 | grids_${OCE}x${ATM}.nc areas_${OCE}x${ATM}.nc masks_${OCE}x${ATM}.nc are auxiliary file needed by OASIS-MCT |
---|
774 | All files have the same uuid in the global attributes |
---|
775 | |
---|
776 | Description : Weigths and auxiliary files for coupling ${OCE} and ${ATM} needed by OASIS-MCT |
---|
777 | Conventions : CF-1.6 |
---|
778 | source : IPSL Earth system model |
---|
779 | group : ICMC IPSL Climate Modelling Center |
---|
780 | Institution : IPSL https://www.ipsl.fr |
---|
781 | Ocean : ${OCE} https://www.nemo-ocean.eu |
---|
782 | Atmosphere : ${ATM} http://lmdz.lmd.jussieu.fr |
---|
783 | production : $(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') |
---|
784 | originalFiles : ${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc |
---|
785 | associatedFiles : grids_${OCE}x${ATM}.nc areas_${OCE}x${ATM}.nc masks_${OCE}x${ATM}.nc |
---|
786 | directory : $(pwd) |
---|
787 | timeStamp : $(date) |
---|
788 | uuid : ${UUID} |
---|
789 | HOSTNAME : $(hostname) |
---|
790 | LOGNAME : $(whoami) |
---|
791 | NCO : NCO netCDF Operator ${NCO} http://nco.sourceforge.net |
---|
792 | Python version : ${PYTHON_VER} |
---|
793 | OS : $(uname -o) |
---|
794 | release : $(uname -r) |
---|
795 | hardware : $(uname -i) |
---|
796 | EOF |
---|
797 | |
---|
798 | echo 'SVN Information : ' >> README.txt |
---|
799 | echo '$Author$ ' >> README.txt |
---|
800 | echo '$Date$ ' >> README.txt |
---|
801 | echo '$Revision$ ' >> README.txt |
---|
802 | echo '$Id$ ' >> README.txt |
---|
803 | echo '$HeadURL$ ' >> README.txt |
---|
804 | |
---|
805 | cat << EOF >> README.txt |
---|
806 | UUID common to all files : ${UUID} |
---|
807 | |
---|
808 | Files produced, with checksum produce by Unix command shasum (version $(shasum --version)) with default algorithm |
---|
809 | |
---|
810 | EOF |
---|
811 | |
---|
812 | for file in *.nc ; do |
---|
813 | echo "$(shasum ${file})" >> README.txt |
---|
814 | done |
---|
815 | |
---|
816 | cat <<EOF >> README.txt |
---|
817 | |
---|
818 | ================= That's all folk's ! ======================== |
---|
819 | EOF |
---|
820 | |
---|
821 | cp README.txt ${SUBMIT_DIR}/README_${OCE}x${ATM}.txt |
---|
822 | |
---|
823 | ## =========================================================================== |
---|
824 | ## |
---|
825 | ## That's all folk's !!! |
---|
826 | ## |
---|
827 | ## =========================================================================== |
---|
828 | |
---|