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