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