1 | #!/bin/bash |
---|
2 | #MSUB -r NemoAtm # nom de la requete |
---|
3 | #MSUB -o NemoAtm.out # nom du fichier de sortie |
---|
4 | #MSUB -e NemoAtm.out # nom du fichier de sortie |
---|
5 | #MSUB -eo |
---|
6 | #MSUB -n 16 # Reservation des processeurs pour le job |
---|
7 | #MSUB -T 1800 # Limite temps (en secondes) |
---|
8 | #MSUB -q standard |
---|
9 | #MSUB -Q test |
---|
10 | #MSUB -p devcmip6 |
---|
11 | |
---|
12 | ### =========================================================================== |
---|
13 | ### |
---|
14 | ### Creates interpolation weights between ORCA and DYNAMICO grids |
---|
15 | ### Interpolates ORCA mask to DYNAMICO grid |
---|
16 | ### |
---|
17 | ### =========================================================================== |
---|
18 | ## |
---|
19 | ## Warning, to install, configure, run, use any of Olivier Marti's |
---|
20 | ## software or to read the associated documentation you'll need at least |
---|
21 | ## one (1) brain in a reasonably working order. Lack of this implement |
---|
22 | ## will void any warranties (either express or implied). |
---|
23 | ## O. Marti assumes no responsability for errors, omissions, |
---|
24 | ## data loss, or any other consequences caused directly or indirectly by |
---|
25 | ## the usage of his software by incorrectly or partially configured |
---|
26 | ## personal. |
---|
27 | ## |
---|
28 | |
---|
29 | ## |
---|
30 | ## Configuration |
---|
31 | ## =========================================================================== |
---|
32 | |
---|
33 | # |
---|
34 | # Defines models |
---|
35 | # ============== |
---|
36 | OCE=ORCA2.3 |
---|
37 | OCE=eORCA1.2 |
---|
38 | #OCE=ORCA025 |
---|
39 | |
---|
40 | ATM=dynamico30 |
---|
41 | #ATM=dynamico40 |
---|
42 | #ATM=dynamico450 |
---|
43 | #ATM=LMD9695 |
---|
44 | #ATM=LMD144X142 |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | # |
---|
49 | # Defines OCE grids to handle |
---|
50 | # =========================== |
---|
51 | |
---|
52 | OCEGRIDS="T" # " UV |
---|
53 | |
---|
54 | ### =========================================================================== |
---|
55 | ### |
---|
56 | ### You should not change anything below this line .... |
---|
57 | ### |
---|
58 | ### =========================================================================== |
---|
59 | SUBMIT_DIR=$(pwd) |
---|
60 | |
---|
61 | # Defines computer |
---|
62 | # ================ |
---|
63 | [[ $(hostname) = curie* ]] && arch=curie |
---|
64 | |
---|
65 | case ${arch} in |
---|
66 | ( curie | irene ) |
---|
67 | module load netcdf/4.3.3.1_hdf5_parallel |
---|
68 | module load nco/4.4.8 |
---|
69 | R_IN=$(ccc_home -u igcmg --cccwork)/IGCM |
---|
70 | TMPDIR=${SCRATCHDIR}/TMP/${OCE}x${ATM} |
---|
71 | ;; |
---|
72 | ( * ) |
---|
73 | exit -1 |
---|
74 | ;; |
---|
75 | esac |
---|
76 | |
---|
77 | |
---|
78 | set -vx ; set -e |
---|
79 | |
---|
80 | mkdir -p ${TMPDIR}/${OCE}x${ATM} || exit 1 |
---|
81 | cd ${TMPDIR}/${OCE}x${ATM} || exit 1 |
---|
82 | rm -f * |
---|
83 | |
---|
84 | # |
---|
85 | # Suffixes |
---|
86 | # --------------------------------------------------------------------------- |
---|
87 | ocegrids=${OCEGRIDS~} |
---|
88 | |
---|
89 | case ${OCE} in |
---|
90 | ( *ORC*) oce=orc ;; |
---|
91 | esac |
---|
92 | case ${ATM} in |
---|
93 | ( *dynamico* ) atm=ico ;; |
---|
94 | ( *lmd* | *LMD* ) atm=lmd ;; |
---|
95 | esac |
---|
96 | |
---|
97 | # |
---|
98 | # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits |
---|
99 | # --------------------------------------------------------------------------- |
---|
100 | FL_FMT=64bit |
---|
101 | |
---|
102 | ## |
---|
103 | ## NEMO T point towards ATM - 1st order |
---|
104 | ## =========================================================================== |
---|
105 | cp ${SUBMIT_DIR}/bin/interpol.exe . |
---|
106 | cp ${SUBMIT_DIR}/iodef_t${oce}_to_t${atm}_1storder.xml iodef.xml |
---|
107 | |
---|
108 | cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc . |
---|
109 | cp ${R_IN}/ATM/${ATM}/${ATM}_grid.nc . |
---|
110 | |
---|
111 | ln -s ${OCE}_coordinates_mask.nc oce_grid.nc |
---|
112 | ln -s ${ATM}_grid.nc atm_grid.nc |
---|
113 | |
---|
114 | sed --in-place -e 's/"mask_[TUV]"/"mask_T"/g' -e "s/[tuv]${oce}/t${oce}/" -e 's/_...order/_1storder/g' -e 's/order="."/order="1"/' iodef.xml |
---|
115 | time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=no |
---|
116 | |
---|
117 | ## |
---|
118 | ## Correct spurious values (extremes) |
---|
119 | ## =========================================================================== |
---|
120 | cat <<EOF > correction_masque.nco |
---|
121 | where (OceFrac < 0.00001 ) OceFrac=OceFrac.get_miss() ; |
---|
122 | where (OceFrac > 0.99999 ) OceFrac=1.0 ; |
---|
123 | OceFrac.delete_miss() ; |
---|
124 | // Fill masked values to land values |
---|
125 | where (OceFrac > 1.0 ) OceFrac=0.0 ; |
---|
126 | where (OceFrac < 0.0 ) OceFrac=0.0 ; |
---|
127 | EOF |
---|
128 | ncap2 -h --overwrite --script-file correction_masque.nco t${oce}_to_t${atm}_1storder.nc tmp_t${oce}_to_t${atm}_1storder.nc ; mv tmp_t${oce}_to_t${atm}_1storder.nc t${oce}_to_t${atm}_1storder.nc |
---|
129 | ncatted -h -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" t${oce}_to_t${atm}_1storder.nc |
---|
130 | |
---|
131 | ## |
---|
132 | ## Creates mask on ATM grid |
---|
133 | ## =========================================================================== |
---|
134 | cp t${oce}_to_t${atm}_1storder.nc t${oce}_to_t${atm}_1storder_mask.nc |
---|
135 | ncks -h --overwrite -v OceFrac t${oce}_to_t${atm}_1storder_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
136 | ncks -h --append -v aire atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
137 | [[ ${atm} = *ico* ]] && ncks -h --append -v bounds_lon,bounds_lat atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
138 | |
---|
139 | cat <<EOF > creation_masque.nco |
---|
140 | where (OceFrac > 0.0 ) OceFrac=1 ; |
---|
141 | where (OceFrac <= 0.0 ) OceFrac=0 ; |
---|
142 | EOF |
---|
143 | ncap2 -h --overwrite --script-file creation_masque.nco t${oce}_to_t${atm}_1storder_mask.nc tmp_t${oce}_to_t${atm}_1storder_mask.nc ; mv tmp_t${oce}_to_t${atm}_1storder_mask.nc t${oce}_to_t${atm}_1storder_mask.nc |
---|
144 | ncrename -h -v OceFrac,OceMask t${oce}_to_t${atm}_1storder_mask.nc |
---|
145 | |
---|
146 | ncks -h --append -v OceMask t${oce}_to_t${atm}_1storder_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
147 | |
---|
148 | ## |
---|
149 | ## NEMO T point towards ATM - 2nd order |
---|
150 | ## =========================================================================== |
---|
151 | sed --in-place -e 's/"mask_[TUV]"/"mask_T"/g' -e "s/[tuv]${oce}/t${oce}/" -e 's/_...order/_2ndorder/g' -e 's/order="."/order="2"/' iodef.xml |
---|
152 | #time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
153 | |
---|
154 | ## |
---|
155 | ## ATM towards NEMO T point - 1st order |
---|
156 | ## =========================================================================== |
---|
157 | cp ${SUBMIT_DIR}/iodef_t${atm}_to_t${oce}_1storder.xml iodef.xml |
---|
158 | sed --in-place -e 's/"mask_[TUV]"/"mask_T"/g' -e "s/[tuv]${oce}/t${oce}/" -e 's/_...order/_1storder/g' -e 's/order="."/order="1"/' iodef.xml |
---|
159 | time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
160 | |
---|
161 | ## |
---|
162 | ## ATM towards NEMO U Point - 1st order |
---|
163 | ## =========================================================================== |
---|
164 | sed --in-place -e 's/"mask_[TUV]"/"mask_U"/g' -e "s/[tuv]${oce}/u${oce}/" -e 's/_...order/_1storder/g' -e 's/order="."/order="1"/' iodef.xml |
---|
165 | #time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
166 | |
---|
167 | ## |
---|
168 | ## ATM towards NEMO V Point - 1st order |
---|
169 | ## =========================================================================== |
---|
170 | sed --in-place -e 's/"mask_[TUV]"/"mask_V"/g' -e "s/[tuv]${oce}/v${oce}/" -e 's/_...order/_1storder/g' -e 's/order="."/order="1"/' iodef.xml |
---|
171 | #time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
172 | |
---|
173 | ## |
---|
174 | ## ATM verstowards NEMO T point - 2nd order |
---|
175 | ## =========================================================================== |
---|
176 | sed --in-place -e 's/"mask_[TUV]"/"mask_T"/g' -e "s/[tuv]${oce}/t${oce}/" -e 's/_...order/_2ndorder/g' -e 's/order="."/order="2"/' iodef.xml |
---|
177 | #/usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
178 | |
---|
179 | |
---|
180 | ## |
---|
181 | ## Change all NetCDF files to NetCDF 3 format (needed for OASIS) |
---|
182 | ## =========================================================================== |
---|
183 | for InFile in *.nc ; do |
---|
184 | if [[ $(ncdump -k ${InFile}) = *netCDF-4* ]] ; then |
---|
185 | mv ${InFile} tmp_${InFile} |
---|
186 | ncks --fl_fmt=${FL_FMT} -h tmp_${InFile} ${InFile} |
---|
187 | fi |
---|
188 | done |
---|
189 | |
---|
190 | |
---|
191 | ## |
---|
192 | ## Add time axis and coordinates information |
---|
193 | ## (needed if files need to be read by XIOS) |
---|
194 | ## =========================================================================== |
---|
195 | if [[ ${atm} = ico ]] ; then |
---|
196 | cat <<EOF > add_time.nco |
---|
197 | defdim("time_counter",1) ; |
---|
198 | OceFrac [time_counter,cell] = OceFrac (:) ; |
---|
199 | OceMask [time_counter,cell] = OceMask (:) ; |
---|
200 | EOF |
---|
201 | ncap2 -O -h -S 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 |
---|
202 | ncks -O --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 |
---|
203 | ncatted -h \ |
---|
204 | -a coordinates,OceFrac,c,c,"time_counter cell" \ |
---|
205 | -a coordinates,OceMask,c,c,"time_counter cell" \ |
---|
206 | -a coordinates,aire,c,c,"time_counter cell" ${ATM}_grid_maskFrom_${OCE}.nc |
---|
207 | fi |
---|
208 | if [[ ${atm} = lmd ]] ; then |
---|
209 | cat <<EOF > add_time.nco |
---|
210 | defdim("time_counter",1) ; |
---|
211 | OceFrac [time_counter,lat,lon] = OceFrac (:,:) ; |
---|
212 | OceMask [time_counter,lat,lon] = OceMask (:,:) ; |
---|
213 | EOF |
---|
214 | ncap2 -O -h -S 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 |
---|
215 | ncks -O --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 |
---|
216 | ncatted -h \ |
---|
217 | -a coordinates,OceFrac,c,c,"time_counter lat lon" \ |
---|
218 | -a coordinates,OceMask,c,c,"time_counter lat lon" \ |
---|
219 | -a coordinates,aire,c,c,"time_counter lat lon" ${ATM}_grid_maskFrom_${OCE}.nc |
---|
220 | fi |
---|
221 | |
---|
222 | ## |
---|
223 | ## Add some information in file headers |
---|
224 | ## =========================================================================== |
---|
225 | |
---|
226 | UUID=$(uuid) |
---|
227 | NCO="$(ncks --version |& tail -1|sed 's/ncks //')" |
---|
228 | for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ; do |
---|
229 | ncatted -h \ |
---|
230 | --attribute uuid,global,d,, \ |
---|
231 | --attribute LongName,global,d,, \ |
---|
232 | --attribute nco_openmp_thread_number,global,d,, \ |
---|
233 | --attribute Conventions,global,o,c,"CF-1.6" \ |
---|
234 | --attribute source,global,o,c,"IPSL Earth system model" \ |
---|
235 | --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center" \ |
---|
236 | --attribute Institution,global,o,c,"IPSL" \ |
---|
237 | --attribute Ocean,global,o,c,"${OCE}" \ |
---|
238 | --attribute Atmosphere,global,o,c,"${ATM}" \ |
---|
239 | --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') " \ |
---|
240 | --attribute originalFiles,global,o,c,"${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc" \ |
---|
241 | --attribute associatedFiles,global,o,c,"grids_${OCE}x${ATM}.nc areas_${OCE}x${ATM}.nc masks_${OCE}x${ATM}.nc" \ |
---|
242 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
243 | --attribute description,global,o,c,"Fields needed by OASIS-MCT" \ |
---|
244 | --attribute title,global,o,c,"${type}_${OCE}x${ATM}.nc" \ |
---|
245 | --attribute timeStamp,global,o,c,"$(date)" \ |
---|
246 | --attribute uuid,global,o,c,"${UUID}" \ |
---|
247 | --attribute HOSTNAME,global,o,c,"$(hostname)" \ |
---|
248 | --attribute LOGNAME,global,o,c,"$(whoami)" \ |
---|
249 | --attribute NCO,global,o,c,"NCO ${NCO}" \ |
---|
250 | --attribute OS,global,o,c,"$(uname -o)" \ |
---|
251 | --attribute release,global,o,c,"$(uname -r)" \ |
---|
252 | --attribute hardware,global,o,c,"$(uname -i)" \ |
---|
253 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
254 | --attribute description,global,o,c,"Generated with XIOS" \ |
---|
255 | --attribute Comment,global,o,c,"Preliminary attempt - Do not trust !" \ |
---|
256 | ${InFile} |
---|
257 | done |
---|
258 | |
---|
259 | |
---|
260 | ## |
---|
261 | ## Update and complete weights file to fit OASIS requested format |
---|
262 | ## =========================================================================== |
---|
263 | cat <<EOF > add_dim.nco |
---|
264 | defdim("num_wgts",1) ; |
---|
265 | weight[n_weight, num_wgts] = weight ; |
---|
266 | EOF |
---|
267 | |
---|
268 | for file in rmp_*${oce}_to_*${atm}_*.nc rmp_*${atm}_to_*${oce}_*.nc ; do |
---|
269 | mv ${file} xios_${file} |
---|
270 | ncap2 --fl_fmt=${FL_FMT} -h --script-file add_dim.nco xios_${file} ${file} |
---|
271 | |
---|
272 | ncrename -h --dimension n_weight,num_links ${file} |
---|
273 | ncrename -h --variable src_idx,src_address ${file} |
---|
274 | ncrename -h --variable dst_idx,dst_address ${file} |
---|
275 | ncrename -h --variable weight,remap_matrix ${file} |
---|
276 | case ${file} in |
---|
277 | ( *1storder.nc ) ncatted -h --attribute map_method,global,o,c,"Conservative Remapping - 1st order" ${file} ;; |
---|
278 | ( *2ndorder.nc ) ncatted -h --attribute map_method,global,o,c,"Conservative Remapping - 2nd order" ${file} ;; |
---|
279 | esac |
---|
280 | ncatted -h --attribute conventions,global,o,c,"SCRIP" ${file} |
---|
281 | ncatted -h --attribute normalization,global,o,c,"none" ${file} |
---|
282 | |
---|
283 | case ${file} in |
---|
284 | ( rmp_*${oce}_to_t${atm}_* ) |
---|
285 | ncatted -h \ |
---|
286 | --attribute title,global,o,c,"Weights ${OCE} to ${ATM}" \ |
---|
287 | --attribute source_grid,global,o,c,"curvilinear" \ |
---|
288 | --attribute dest_grid,global,o,c,"unstructured" \ |
---|
289 | ${file} |
---|
290 | ;; |
---|
291 | ( rmp_*${atm}_to_*${oce}_* ) |
---|
292 | ncatted -h \ |
---|
293 | --attribute title,global,o,c,"Weights ${ATM} to ${OCE}" \ |
---|
294 | --attribute source_grid,global,o,c,"unstructured" \ |
---|
295 | --attribute dest_grid,global,o,c,"curvilinear" \ |
---|
296 | ${file} |
---|
297 | ;; |
---|
298 | esac |
---|
299 | done |
---|
300 | |
---|
301 | ## |
---|
302 | ## Save results |
---|
303 | ## =========================================================================== |
---|
304 | cp ${ATM}_grid_maskFrom_${OCE}.nc ${SUBMIT_DIR} |
---|
305 | for order in 1st # 2nd |
---|
306 | do |
---|
307 | cp t${oce}_to_t${atm}_${order}order.nc ${SUBMIT_DIR}/t${OCE}_to_t${ATM}_${order}order.nc |
---|
308 | cp rmp_t${oce}_to_t${atm}_${order}order.nc ${SUBMIT_DIR}/rmp_t${OCE}_to_t${ATM}_${order}order.nc |
---|
309 | for grid in ${ocegrids} ; do |
---|
310 | cp rmp_t${atm}_to_${grid}${oce}_${order}order.nc ${SUBMIT_DIR}/rmp_t${ATM}_to_${grid}${OCE}_${order}order.nc |
---|
311 | cp t${atm}_to_${grid}${oce}_${order}order.nc ${SUBMIT_DIR}/t${ATM}_to_${grid}${OCE}_${order}order.nc |
---|
312 | done |
---|
313 | done |
---|
314 | |
---|
315 | ## |
---|
316 | ## Creates and save auxiliary files for OASIS |
---|
317 | ## =========================================================================== |
---|
318 | bash ${SUBMIT_DIR}/GenerateOasisGrids.bash --oce ${OCE} --atm ${ATM} |
---|
319 | |
---|
320 | cp areas_${OCE}_${ATM}.nc ${SUBMIT_DIR} |
---|
321 | cp grids_${OCE}_${ATM}.nc ${SUBMIT_DIR} |
---|
322 | cp masks_${OCE}_${ATM}.nc ${SUBMIT_DIR} |
---|
323 | |
---|
324 | |
---|
325 | ### =========================================================================== |
---|
326 | ### |
---|
327 | ### That's all folk's !!! |
---|
328 | ### |
---|
329 | ### =========================================================================== |
---|
330 | |
---|