source: TOOLS/MOSAIX/CreateOasisGrids.bash @ 5156

Last change on this file since 5156 was 5156, checked in by omamce, 4 years ago

O.M. - MOSAIX : chnage shebang line for portability

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