1 | #!/bin/bash |
---|
2 | ### =========================================================================== |
---|
3 | ### |
---|
4 | ### Creates grids.nc, masks.nc and areas.nc for OASIS-MCT |
---|
5 | ### |
---|
6 | ### =========================================================================== |
---|
7 | ## |
---|
8 | ## Warning, to install, configure, run, use any of Olivier Marti's |
---|
9 | ## software or to read the associated documentation you'll need at least |
---|
10 | ## one (1) brain in a reasonably working order. Lack of this implement |
---|
11 | ## will void any warranties (either express or implied). |
---|
12 | ## O. Marti assumes no responsability for errors, omissions, |
---|
13 | ## data loss, or any other consequences caused directly or indirectly by |
---|
14 | ## the usage of his software by incorrectly or partially configured |
---|
15 | ## personal. |
---|
16 | ## |
---|
17 | ### |
---|
18 | ### Documentation : https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX |
---|
19 | ### |
---|
20 | ## SVN information |
---|
21 | # $Author$ |
---|
22 | # $Date$ |
---|
23 | # $Revision$ |
---|
24 | # $Id$ |
---|
25 | # $HeadURL$ |
---|
26 | |
---|
27 | set +vx |
---|
28 | |
---|
29 | echo ${Titre}"Starting CreateOasisGrids.bash"${Norm} |
---|
30 | |
---|
31 | ## |
---|
32 | echo ${Titre}"Default configuration (may be overrided by command line parameters)"${Norm} |
---|
33 | ## =========================================================================== |
---|
34 | #OCE=ORCA2.3 |
---|
35 | OCE=eORCA1.2 |
---|
36 | #ATM=ICO30 |
---|
37 | ATM=ICO40 |
---|
38 | #ATM=ICO450 |
---|
39 | #ATM=LMD144142 |
---|
40 | #ATM=LMD9695 |
---|
41 | |
---|
42 | ## =========================================================================== |
---|
43 | ## |
---|
44 | ## You should not change anything below this line .... |
---|
45 | ## |
---|
46 | ## =========================================================================== |
---|
47 | |
---|
48 | echo ${Titre}"Defines computer"${Norm} |
---|
49 | # ================ |
---|
50 | if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi |
---|
51 | if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi |
---|
52 | if [[ $(hostname) = lsce3005* ]] ; then arch=spip ; center=spip ; fi |
---|
53 | if [[ $(hostname) = lsce5138* ]] ; then arch=spip ; center=spip ; fi |
---|
54 | |
---|
55 | PROGRAM=$(basename ${0}) |
---|
56 | |
---|
57 | if [[ "X${R_IN}" = "X" ]] ; then |
---|
58 | |
---|
59 | case ${arch} in |
---|
60 | ( irene ) |
---|
61 | set +vx |
---|
62 | set +e |
---|
63 | TMPDIR=${CCCWORKDIR}/TMP |
---|
64 | SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}} |
---|
65 | PROGRAM=${BRIDGE_MSUB_REQNAME} |
---|
66 | MpiRun="time ccc_mprun" |
---|
67 | PyRun="time ccc_mprun -n 1" # Needed to force python to run on one process only |
---|
68 | module purge |
---|
69 | source ${SUBMIT_DIR}/arch.env |
---|
70 | module load nco/4.9.1 |
---|
71 | module load cdo/1.9.5 |
---|
72 | module load python3 |
---|
73 | module load datadir/igcmg |
---|
74 | module list |
---|
75 | set -e |
---|
76 | ;; |
---|
77 | ( spip ) |
---|
78 | R_IN=${HOME}/Scratch/IGCM |
---|
79 | TMPDIR=${HOME}/Scratch/TMP |
---|
80 | SUBMIT_DIR=$(pwd) |
---|
81 | MpiRun="/opt/local/bin/mpirun -n 4" |
---|
82 | PyRun="time" |
---|
83 | ;; |
---|
84 | ( * ) exit -1 ;; |
---|
85 | esac |
---|
86 | fi |
---|
87 | ## |
---|
88 | echo ${Titre}"Command line parameters"${Norm} |
---|
89 | ## =========================================================================== |
---|
90 | set -e |
---|
91 | set -o verbose |
---|
92 | set -o xtrace |
---|
93 | |
---|
94 | while [[ ${1} = -* ]] ; do |
---|
95 | case ${1} in |
---|
96 | ( -- ) shift ; break ;; |
---|
97 | ( -o=* | --oce=* ) OCE=${1##*=} ; echo OCE:${OCE} ;; |
---|
98 | ( -o | --oce ) shift ; OCE=${1} ; echo OCE:${OCE} ;; |
---|
99 | ( -a=* | --atm=* ) ATM=${1##*=} ; echo ATM:${ATM} ;; |
---|
100 | ( -a | --atm ) shift ; ATM=${1} ; echo ATM:${ATM} ;; |
---|
101 | ( -v | --verbose ) set -o verbose ;; |
---|
102 | ( -x | --xtrace ) set -o xtrace ;; |
---|
103 | ( -e ) set -e ;; |
---|
104 | ( -V | --noverbose ) set +o verbose ;; |
---|
105 | ( -X | --noxtrace ) set +o xtrace ;; |
---|
106 | ( -E ) set +e ;; |
---|
107 | ( -* ) echo ${Bold}"Unknown option : ${1}"${Norm} ; return 1 ;; |
---|
108 | esac |
---|
109 | shift |
---|
110 | done |
---|
111 | |
---|
112 | ## |
---|
113 | echo ${Titre}"Short names (grid names in Oasis)"${Norm} |
---|
114 | ## =========================================================================== |
---|
115 | case ${OCE} in |
---|
116 | ( *ORC*) oce=orc ;; |
---|
117 | esac |
---|
118 | case ${ATM} in |
---|
119 | ( *ICO* ) atm=ico ;; |
---|
120 | ( *dynamico* ) atm=ico ;; |
---|
121 | ( *lmd* | *LMD* ) atm=lmd ;; |
---|
122 | esac |
---|
123 | |
---|
124 | CplModel=${OCE}x${ATM} |
---|
125 | |
---|
126 | ## |
---|
127 | echo ${Titre}"Get input files"${Norm} |
---|
128 | ## =========================================================================== |
---|
129 | [[ -f ${OCE}_coordinates_mask.nc ]] || cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc . |
---|
130 | [[ -f ${ATM}_grid.nc ]] || cp ${R_IN}/ATM/GRID/${ATM}_grid.nc . |
---|
131 | |
---|
132 | # |
---|
133 | echo ${Titre}"Format for OASIS-MCT files : should be NetCDF3 classic or NetCDF3 64 bits"${Norm} |
---|
134 | # --------------------------------------------------------------------------- |
---|
135 | FL_FMT=netcdf4 |
---|
136 | # |
---|
137 | echo ${Titre}"Cleaning"${Norm} |
---|
138 | # ---------------------------------------------------------------------------- |
---|
139 | rm -f grids_${CplModel}.nc masks_${CplModel}.nc areas_${CplModel}.nc |
---|
140 | rm -f *_tmp.nc |
---|
141 | |
---|
142 | # |
---|
143 | if [[ ${atm} = *lmd* ]] ; then |
---|
144 | ncrename --dimension lon,x ${ATM}_grid_maskFrom_${OCE}.nc |
---|
145 | ncrename --dimension lat,y ${ATM}_grid_maskFrom_${OCE}.nc |
---|
146 | fi |
---|
147 | # |
---|
148 | # |
---|
149 | echo ${Titre}"Creates ocean fields"${Norm} |
---|
150 | # ---------------------------------------------------------------------------- |
---|
151 | for OCEGRID in T U V ; do |
---|
152 | ncks -C --history --append --variable nav_lon_grid_${OCEGRID},nav_lat_grid_${OCEGRID},bounds_lon_grid_${OCEGRID},bounds_lat_grid_${OCEGRID} ${OCE}_coordinates_mask.nc grids_${CplModel}.nc |
---|
153 | ncks -C --history --append --variable area_grid_${OCEGRID} ${OCE}_coordinates_mask.nc areas_${CplModel}.nc |
---|
154 | # Inverts mask values and switch to integer |
---|
155 | ncks --history -C --variable maskutil_${OCEGRID} ${OCE}_coordinates_mask.nc mask_${OCEGRID}_tmp.nc |
---|
156 | ncatted --history \ |
---|
157 | --attribute coordinates,maskutil_${OCEGRID},d,, \ |
---|
158 | --attribute online_operation,maskutil_${OCEGRID},d,, \ |
---|
159 | --attribute cell_measures,maskutil_${OCEGRID},d,, \ |
---|
160 | mask_${OCEGRID}_tmp.nc |
---|
161 | |
---|
162 | ncap2 --history --append --script "maskutil_${OCEGRID}=int(1-maskutil_${OCEGRID});" mask_${OCEGRID}_tmp.nc masks_${CplModel}.nc |
---|
163 | rm mask_${OCEGRID}_tmp.nc |
---|
164 | ncatted --history \ |
---|
165 | --attribute long_name,maskutil_${OCEGRID},o,c,"Land-sea mask" \ |
---|
166 | --attribute units,maskutil_${OCEGRID},o,c,"Land:1, Ocean:0" masks_${CplModel}.nc |
---|
167 | # Change order of dimensions |
---|
168 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
169 | ncpdq --permute nvertex_grid_${OCEGRID},y_grid_${OCEGRID},x_grid_${OCEGRID} grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
170 | rm grids_${CplModel}_tmp.nc |
---|
171 | done |
---|
172 | |
---|
173 | ncks --history --append --variable lon,lat ${ATM}_grid_maskFrom_${OCE}.nc grids_${CplModel}.nc |
---|
174 | |
---|
175 | # |
---|
176 | echo ${Titre}"We need to have different names for dimensions and variables"${Norm} |
---|
177 | # -------------------------------------------------------------------------------- |
---|
178 | ncrename --history --variable lon,alon grids_${CplModel}.nc |
---|
179 | ncrename --history --variable lat,alat grids_${CplModel}.nc |
---|
180 | |
---|
181 | if [[ ${ATM} = dynamico* || ${ATM} = ICO* ]] ; then |
---|
182 | ncks --history --append --variable bounds_lon,bounds_lat ${ATM}_grid_maskFrom_${OCE}.nc grids_${CplModel}.nc |
---|
183 | fi |
---|
184 | |
---|
185 | ncks --history -C --append --variable aire ${ATM}_grid_maskFrom_${OCE}.nc areas_${CplModel}.nc |
---|
186 | ncatted --history --attribute coordinates,aire,d,, \ |
---|
187 | --attribute _FillValue,aire,d,, \ |
---|
188 | --attribute missing_value,aire,d,, \ |
---|
189 | --attribute online_operation,aire,d,, \ |
---|
190 | --attribute units,aire,o,c,"m2" \ |
---|
191 | --attribute standard_name,aire,o,c,"cell_area" \ |
---|
192 | areas_${CplModel}.nc |
---|
193 | |
---|
194 | ncks --history -C --variable OceMask,OceFrac,Oce2AtmMask ${ATM}_grid_maskFrom_${OCE}.nc OceMask_tmp.nc |
---|
195 | ncatted --history \ |
---|
196 | --attribute cell_methods,OceMask,d,c, \ |
---|
197 | --attribute coordinates,OceMask,d,, \ |
---|
198 | --attribute online_operation,OceMask,d,, \ |
---|
199 | --attribute _FillValue,OceMask,d,, \ |
---|
200 | --attribute missing_value,OceMask,d,, \ |
---|
201 | \ |
---|
202 | --attribute cell_methods,OceFrac,d,c, \ |
---|
203 | --attribute coordinates,OceFrac,d,, \ |
---|
204 | --attribute online_operation,OceFrac,d,, \ |
---|
205 | --attribute _FillValue,OceFrac,d,, \ |
---|
206 | --attribute missing_value,OceFrac,d,, \ |
---|
207 | \ |
---|
208 | --attribute cell_methods,Oce2AtmMask,d,c, \ |
---|
209 | --attribute coordinates,Oce2AtmMask,d,, \ |
---|
210 | --attribute online_operation,Oce2AtmMask,d,, \ |
---|
211 | --attribute _FillValue,Oce2AtmMask,d,, \ |
---|
212 | --attribute missing_value,Oce2AtmMask,d,, \ |
---|
213 | OceMask_tmp.nc |
---|
214 | |
---|
215 | ncap2 --history --append --script "Oce2AtmMask=int(1-Oce2AtmMask)" OceMask_tmp.nc masks_${CplModel}.nc # For OASIS, ocean=0, land=1 |
---|
216 | #rm OceMask_tmp.nc |
---|
217 | ncatted --history \ |
---|
218 | --attribute long_name,Oce2AtmMask,o,c,"Land-sea mask" \ |
---|
219 | --attribute units,OceMask,o,c,"Land:1, Ocean:0" masks_${CplModel}.nc |
---|
220 | |
---|
221 | ncatted --history --attribute history,global,d,, grids_${CplModel}.nc |
---|
222 | ncatted --history --attribute history,global,d,, masks_${CplModel}.nc |
---|
223 | ncatted --history --attribute history,global,d,, areas_${CplModel}.nc |
---|
224 | |
---|
225 | if [[ ${atm} = *dynamico* || ${atm} = ico* ]] ; then |
---|
226 | ncrename --history --dimension cell,ycell grids_${CplModel}.nc |
---|
227 | ncrename --history --dimension cell,ycell areas_${CplModel}.nc |
---|
228 | ncrename --history --dimension cell,ycell masks_${CplModel}.nc |
---|
229 | fi |
---|
230 | |
---|
231 | # |
---|
232 | if [[ ${atm} = dynamico* || ${atm} = ico* ]] ; then |
---|
233 | echo ${Titre}"DYNAMICO grids : 1) Set correct order of dimensions, 2) Add a dimension"${Norm} |
---|
234 | # ------------------------------------------------------------------------------------------- |
---|
235 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
236 | ncpdq --permute nvertex,ycell,xcell grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
237 | |
---|
238 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
239 | cat <<EOF >add_dim.nco |
---|
240 | // |
---|
241 | defdim("xcell",1) ; |
---|
242 | alat [ycell,xcell] = alat ; |
---|
243 | alon [ycell,xcell] = alon ; |
---|
244 | bounds_lat [nvertex,ycell,xcell] = bounds_lat ; |
---|
245 | bounds_lon [nvertex,ycell,xcell] = bounds_lon ; |
---|
246 | // |
---|
247 | EOF |
---|
248 | |
---|
249 | ncap2 --history --append --script-file add_dim.nco grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
250 | |
---|
251 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
252 | ncap2 --history --append --script 'defdim("xcell",1) ' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
253 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
254 | ncap2 --history --append --script 'OceFrac [ycell,xcell]=OceFrac' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
255 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
256 | ncap2 --history --append --script 'OceMask [ycell,xcell]=OceMask' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
257 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
258 | ncap2 --history --append --script 'Oce2AtmMask[ycell,xcell]=Oce2AtmMask' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
259 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
260 | ncap2 --history --append --script 'defdim("xcell",1) ; aire[ycell,xcell]=aire ; ' areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
261 | rm -f grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc |
---|
262 | fi |
---|
263 | |
---|
264 | # |
---|
265 | echo ${Titre}"Some changes specific to LMDZ lon/lat grid"${Norm} |
---|
266 | # ---------------------------------------------------------------------------- |
---|
267 | if [[ ${atm} = lmd* ]] ; then |
---|
268 | echo ${Titre}"Spreads lon and lat to get 2D fields"${Norm} |
---|
269 | # ----------------------------------------------------------------------- |
---|
270 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
271 | ncap2 --history --append --script "alon[y,x]=alon; alat[y,x]=alat" grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
272 | rm -f grids_${CplModel}_tmp.nc |
---|
273 | ncatted --history \ |
---|
274 | --attribute long_name,alon,o,c,"Longitude" \ |
---|
275 | --attribute long_name,alat,o,c,"Latitude" \ |
---|
276 | --attribute units,alon,o,c,"degrees_east" \ |
---|
277 | --attribute units,alat,o,c,"degrees_north" \ |
---|
278 | --attribute grid_type,alon,o,c,"P" \ |
---|
279 | --attribute grid_type,alat,o,c,"P" \ |
---|
280 | --attribute overlap,alon,o,i,0 \ |
---|
281 | --attribute overlap,alat,o,i,0 grids_${CplModel}.nc |
---|
282 | |
---|
283 | echo ${Titre}"Generates cell corners"${Norm} |
---|
284 | # ----------------------------------------------------------------------- |
---|
285 | cat <<EOF > add_bounds.nco |
---|
286 | defdim ("nvertex_lmd", 4) ; |
---|
287 | *delta_x = alon(0,1) - alon(0,0) ; |
---|
288 | *delta_y = alat(1,0) - alat(0,0) ; |
---|
289 | // |
---|
290 | bounds_lon[nvertex_lmd,y,x] = 0.0 ; |
---|
291 | bounds_lat[nvertex_lmd,y,x] = 0.0 ; |
---|
292 | // |
---|
293 | bounds_lon (0,:,:) = alon + delta_x*0.5 ; |
---|
294 | bounds_lat (0,:,:) = alat + delta_y*0.5 ; |
---|
295 | bounds_lon (1,:,:) = alon + delta_x*0.5 ; |
---|
296 | bounds_lat (1,:,:) = alat - delta_y*0.5 ; |
---|
297 | bounds_lon (2,:,:) = alon - delta_x*0.5 ; |
---|
298 | bounds_lat (2,:,:) = alat - delta_y*0.5 ; |
---|
299 | bounds_lon (3,:,:) = alon - delta_x*0.5 ; |
---|
300 | bounds_lat (3,:,:) = alat + delta_y*0.5 ; |
---|
301 | // |
---|
302 | where (bounds_lat > 90.0 ) bounds_lat = 90.0 ;; |
---|
303 | where (bounds_lat < -90.0 ) bounds_lat = -90.0 ;; |
---|
304 | // |
---|
305 | EOF |
---|
306 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
307 | ncap2 --history --script-file add_bounds.nco -O grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
308 | rm grids_${CplModel}_tmp.nc |
---|
309 | fi |
---|
310 | |
---|
311 | # |
---|
312 | |
---|
313 | echo ${Titre}"Generates grid o${atm}, 'o' meaning 'one'"${Norm} |
---|
314 | # same as t${atm} grid, with surfaces set to 1 |
---|
315 | # and mask to 0 (ocean everywhere, to compute integral over the whole grid)) |
---|
316 | # This grid is used when field are quantities instead of fluxes (i.e river flow) |
---|
317 | # ---------------------------------------------------------------------------- |
---|
318 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
319 | ncap2 --history --script "o${atm}_lon=alon ; o${atm}_lat=alat ; bounds_o${atm}_lon=bounds_lon; bounds_o${atm}_lat=bounds_lat ; " grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
320 | |
---|
321 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
322 | ncap2 --history --script "o${atm}_aire=aire*0.0d+1.0d ; " areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
323 | |
---|
324 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
325 | ncap2 --history --script "o${atm}_mask=int(Oce2AtmMask)*0+0 ; " masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
326 | |
---|
327 | rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc |
---|
328 | |
---|
329 | |
---|
330 | # echo ${Titre}"Generates grid c${atm}, 'o' meaning 'one'"${Norm} |
---|
331 | # # same as t${atm} grid, with surfaces set to grid area |
---|
332 | # # and mask to 0 (ocean everywhere, to compute integral over the whole grid)) |
---|
333 | # # ---------------------------------------------------------------------------- |
---|
334 | # mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
335 | # ncap2 --history --script "c${atm}_lon=alon ; c${atm}_lat=alat ; bounds_c${atm}_lon=bounds_lon ; bounds_c${atm}_lat=bounds_lat ; " grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
336 | |
---|
337 | # mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
338 | # ncap2 --history --script "c${atm}_aire=aire" areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
339 | |
---|
340 | # mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
341 | # ncap2 --history --script "c${atm}_mask=int(Oce2AtmMask)*0+0 ; " masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
342 | |
---|
343 | # rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc |
---|
344 | |
---|
345 | echo ${Titre}"Generates grid o${oce}, 'o' meaning 'one'"${Norm} |
---|
346 | # same as t${oce} grid, with surfaces set to 1 |
---|
347 | # and mask to 0 (ocean everywhere, to compute integral over the whole grid)) |
---|
348 | # This grid is used when field are quantities instead of fluxes |
---|
349 | # -------------------------------------------------------------------------------------------------------- |
---|
350 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
351 | ncap2 --history --script "nav_lon_grid_O=nav_lon_grid_T; nav_lat_grid_O=nav_lat_grid_T; bounds_lon_grid_O=bounds_lon_grid_T; bounds_lat_grid_O=bounds_o${oce}_lat=bounds_lat_grid_T; " grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
352 | |
---|
353 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
354 | ncap2 --history --script "area_grid_O=area_grid_T*0.0d+1.0d;" areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
355 | |
---|
356 | ncks -C --history --overwrite -v maskutil_T ${OCE}_coordinates_mask.nc maskutil_T.nc |
---|
357 | ncap2 --history --append --script "maskutil_O=maskutil_T; " maskutil_T.nc masks_${CplModel}.nc |
---|
358 | |
---|
359 | rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc |
---|
360 | |
---|
361 | |
---|
362 | # echo ${Titre}"Creates OCEAN C grid : redundant points removed to compute proper integrals"${Norm} |
---|
363 | # # -------------------------------------------------------------------------------------------------------- |
---|
364 | |
---|
365 | # mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
366 | # ncap2 --history --script "nav_lon_grid_C=nav_lon_grid_T; nav_lat_grid_C=nav_lat_grid_T; bounds_lon_grid_C=bounds_lon_grid_T; bounds_lat_grid_C=bounds_o${oce}_lat=bounds_lat_grid_T; " grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
367 | |
---|
368 | # mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
369 | # ncap2 --history --script "area_grid_C=area_grid_T ; " areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
370 | |
---|
371 | # ncap2 --history --append --script "mask_C=maskutil_T; " maskutil_T.nc masks_${CplModel}.nc |
---|
372 | |
---|
373 | # rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc maskutil_T.nc |
---|
374 | |
---|
375 | # |
---|
376 | echo ${Titre}"Final renaming"${Norm} |
---|
377 | # ---------------------------------------------------------------------------- |
---|
378 | for OCEGRID in T U V O |
---|
379 | do |
---|
380 | ocegrid=${OCEGRID~} # To lowercase |
---|
381 | ncrename --history --variable nav_lon_grid_${OCEGRID},${ocegrid}${oce}.lon grids_${CplModel}.nc |
---|
382 | ncrename --history --variable nav_lat_grid_${OCEGRID},${ocegrid}${oce}.lat grids_${CplModel}.nc |
---|
383 | ncrename --history --variable bounds_lon_grid_${OCEGRID},${ocegrid}${oce}.clo grids_${CplModel}.nc |
---|
384 | ncrename --history --variable bounds_lat_grid_${OCEGRID},${ocegrid}${oce}.cla grids_${CplModel}.nc |
---|
385 | ncrename --history --variable maskutil_${OCEGRID},${ocegrid}${oce}.msk masks_${CplModel}.nc |
---|
386 | ncrename --history --variable area_grid_${OCEGRID},${ocegrid}${oce}.srf areas_${CplModel}.nc |
---|
387 | |
---|
388 | ncatted --history \ |
---|
389 | --attribute bounds,${ocegrid}${oce}.lon,m,c,"${ocegrid}${oce}.clo" \ |
---|
390 | --attribute bounds,${ocegrid}${oce}.lat,m,c,"${ocegrid}${oce}.cla" \ |
---|
391 | --attribute units,${ocegrid}${oce}.clo,o,c,"degrees_east" \ |
---|
392 | --attribute units,${ocegrid}${oce}.clo,o,c,"degrees_north" grids_${CplModel}.nc |
---|
393 | done |
---|
394 | |
---|
395 | ncrename --history --variable alon,t${atm}.lon grids_${CplModel}.nc |
---|
396 | ncrename --history --variable alat,t${atm}.lat grids_${CplModel}.nc |
---|
397 | ncrename --history --variable Oce2AtmMask,t${atm}.msk masks_${CplModel}.nc |
---|
398 | ncrename --history --variable aire,t${atm}.srf areas_${CplModel}.nc |
---|
399 | ncrename --history --variable bounds_lon,t${atm}.clo grids_${CplModel}.nc |
---|
400 | ncrename --history --variable bounds_lat,t${atm}.cla grids_${CplModel}.nc |
---|
401 | |
---|
402 | for ATMGRID in O ; do |
---|
403 | atmgrid=${ATMGRID~} # To lowercase |
---|
404 | ncrename --history --variable ${atmgrid}${atm}_lon,${atmgrid}${atm}.lon grids_${CplModel}.nc |
---|
405 | ncrename --history --variable ${atmgrid}${atm}_lat,${atmgrid}${atm}.lat grids_${CplModel}.nc |
---|
406 | ncrename --history --variable ${atmgrid}${atm}_mask,${atmgrid}${atm}.msk masks_${CplModel}.nc |
---|
407 | ncrename --history --variable ${atmgrid}${atm}_aire,${atmgrid}${atm}.srf areas_${CplModel}.nc |
---|
408 | ncrename --history --variable bounds_${atmgrid}${atm}_lon,${atmgrid}${atm}.clo grids_${CplModel}.nc |
---|
409 | ncrename --history --variable bounds_${atmgrid}${atm}_lat,${atmgrid}${atm}.cla grids_${CplModel}.nc |
---|
410 | done |
---|
411 | |
---|
412 | for ATMGRID in T O ; do |
---|
413 | atmgrid=${ATMGRID~} # To lowercase |
---|
414 | ncatted --history \ |
---|
415 | --attribute bounds,${atmgrid}${atm}.lon,c,c,"${atmgrid}${atm}.clo" \ |
---|
416 | --attribute bounds,${atmgrid}${atm}.lat,c,c,"${atmgrid}${atm}.cla" \ |
---|
417 | --attribute units,${atmgrid}${atm}.clo,o,c,"degrees_east" \ |
---|
418 | --attribute units,${atmgrid}${atm}.cla,o,c,"degrees_north" grids_${CplModel}.nc |
---|
419 | done |
---|
420 | |
---|
421 | |
---|
422 | echo ${Titre}"Add time axis and coordinates information"${Norm} |
---|
423 | # (needed if files need to be read by XIOS) ??? |
---|
424 | ## =========================================================================== |
---|
425 | ncap2 --overwrite --history --script 'defdim("time_counter",1) ;' ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
426 | |
---|
427 | if [[ ${atm} = ico ]] ; then |
---|
428 | cat <<EOF > add_time.nco |
---|
429 | OceFrac [time_counter,cell] = OceFrac [cell] ; |
---|
430 | OceMask [time_counter,cell] = OceMask [cell] ; |
---|
431 | Oce2AtmMask [time_counter,cell] = Oce2AtmMask [cell] ; |
---|
432 | EOF |
---|
433 | ncap2 --overwrite --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}_time.nc tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
434 | ncatted --history \ |
---|
435 | -a coordinates,OceFrac,m,c,"time_counter lat lon" \ |
---|
436 | -a coordinates,OceMask,m,c,"time_counter lat lon" \ |
---|
437 | -a coordinates,aire,c,c,"lat lon" \ |
---|
438 | ${ATM}_grid_maskFrom_${OCE}.nc |
---|
439 | fi |
---|
440 | |
---|
441 | if [[ ${atm} = lmd ]] ; then |
---|
442 | cat <<EOF > add_time.nco |
---|
443 | OceFrac [time_counter,y,x] = OceFrac [y,x] ; |
---|
444 | OceMask [time_counter,y,x] = OceMask [y,x] ; |
---|
445 | Oce2AtmMask [time_counter,y,x] = Oce2AtmMask [y,x] ; |
---|
446 | EOF |
---|
447 | ncap2 --overwrite --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}_time.nc tmp_${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
448 | ncdump -h tmp_${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
449 | mv tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
450 | |
---|
451 | ncatted --history \ |
---|
452 | -a coordinates,OceFrac,m,c,"time_counter lat lon" \ |
---|
453 | -a coordinates,OceMask,m,c,"time_counter lat lon" \ |
---|
454 | -a coordinates,Oce2AtmMask,m,c,"time_counter lat lon" \ |
---|
455 | -a coordinates,aire,m,c,"lat lon" \ |
---|
456 | ${ATM}_grid_maskFrom_${OCE}.nc |
---|
457 | fi |
---|
458 | ncks --alphabetize --history --overwrite --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}_time.nc tmp_${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
459 | mv tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
460 | ## |
---|
461 | echo ${Titre}"Add some useful information in NetCDF headers"${Norm} |
---|
462 | ## =========================================================================== |
---|
463 | NCO=$(ncks --version |& tail -1|sed 's/ncks //') |
---|
464 | for type in areas masks grids ; do |
---|
465 | ncatted --history \ |
---|
466 | --attribute nco_openmp_thread_number,global,d,, \ |
---|
467 | --attribute LongName,global,d,, \ |
---|
468 | --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \ |
---|
469 | --attribute Conventions,global,o,c,"CF-1.6" \ |
---|
470 | --attribute source,global,o,c,"IPSL Earth system model" \ |
---|
471 | --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center" \ |
---|
472 | --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') " \ |
---|
473 | --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr" \ |
---|
474 | --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu" \ |
---|
475 | --attribute Atmosphere,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr" \ |
---|
476 | --attribute HOSTNAME,global,o,c,"$(hostname)" \ |
---|
477 | --attribute LOGNAME,global,o,c,"$(whoami)" \ |
---|
478 | --attribute Program,global,o,c,"Generated by ${0}" \ |
---|
479 | --attribute name,global,o,c,"${type}_${CplModel}.nc" \ |
---|
480 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
481 | --attribute description,global,o,c,"Fields needed by OASIS-MCT" \ |
---|
482 | --attribute title,global,o,c,"${type}_${CplModel}.nc" \ |
---|
483 | --attribute timeStamp,global,o,c,"$(date)" \ |
---|
484 | --attribute associatedFiles,global,o,c,"grids_${CplModel}.nc areas_${CplModel}.nc masks_${CplModel}.nc" \ |
---|
485 | --attribute originalFiles,global,o,c,"${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc"\ |
---|
486 | --attribute OS,global,o,c,"$(uname -o)" \ |
---|
487 | --attribute release,global,o,c,"$(uname -r)" \ |
---|
488 | --attribute hardware,global,o,c,"$(uname -i)" \ |
---|
489 | --attribute SVN_Author,global,o,c,"$Author$" \ |
---|
490 | --attribute SVN_Date,global,o,c,"$Date$" \ |
---|
491 | --attribute SVN_Revision,global,o,c,"$Revision$" \ |
---|
492 | --attribute SVN_Id,global,o,c,"$Id$" \ |
---|
493 | --attribute SVN_HeardURL,global,o,c,"$HeadURL $" \ |
---|
494 | ${type}_${CplModel}.nc |
---|
495 | done |
---|
496 | |
---|
497 | |
---|
498 | exit |
---|
499 | # |
---|
500 | echo ${Titre}"Name of the dimensions ?"${Norm} |
---|
501 | # ---------------------------------------------------------------------------- |
---|
502 | for OCEGRID in T U V ; do |
---|
503 | ocegrid=${OCEGRID~} # Downcase name of grids |
---|
504 | ncrename --history --dimension x_grid_${OCEGRID},x${ocegrid}${oce} grids_${CplModel}.nc |
---|
505 | ncrename --history --dimension y_grid_${OCEGRID},y${ocegrid}${oce} grids_${CplModel}.nc |
---|
506 | ncrename --history --dimension nvertex_grid_${OCEGRID},crn${ocegrid}${oce} grids_${CplModel}.nc |
---|
507 | done |
---|
508 | |
---|
509 | ## =========================================================================== |
---|
510 | echo ${Titre}"Exit from CreateOasisGrids "${Norm} |
---|
511 | |
---|
512 | ## =========================================================================== |
---|
513 | ## |
---|
514 | echo ${Titre}" That's all folk's !!! "${Norm} |
---|
515 | ## |
---|
516 | ## =========================================================================== |
---|