source: TOOLS/MOSAIX/CreateOasisGrids.bash @ 6064

Last change on this file since 6064 was 6064, checked in by omamce, 2 years ago

O.M. : changes in MOSAIX

  • Correct ocean mask to remove periodic duplicated points, to have full conservation of run-off
  • Suppress creation of corc mask, which is not used
  • Put SVN keywords in make_mosaic
  • Update nemo.py with somùe additionnal utilities
  • Adapt RunOffWeights?.py to new nemo module
  • Adapt CalvingWeights?.py to new ORCA configurations
  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 23.4 KB
RevLine 
[5158]1#!/bin/bash
[3620]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##
[3627]17###
18### Documentation : https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX
19###
[3623]20## SVN information
[3665]21#  $Author$
22#  $Date$
23#  $Revision$
24#  $Id$
[3633]25#  $HeadURL$
[3620]26
[4172]27set +vx
28
29echo ${Titre}"Starting CreateOasisGrids.bash"${Norm}
30
[3620]31##
[4172]32echo ${Titre}"Default configuration (may be overrided by command line parameters)"${Norm}
[3620]33## ===========================================================================
[5158]34#OCE=ORCA2.3
35OCE=eORCA1.2
[4298]36#ATM=ICO30
[5158]37ATM=ICO40
[4172]38#ATM=ICO450
39#ATM=LMD144142
[5159]40#ATM=LMD9695
[3620]41
42## ===========================================================================
43##
44## You should not change anything below this line ....
45##
46## ===========================================================================
47
[4172]48echo ${Titre}"Defines computer"${Norm}
[3620]49# ================
[3901]50if [[ $(hostname) = curie* ]]    ; then arch=curie ; center=tgcc ; fi
[5159]51if [[ $(hostname) = irene* ]]    ; then arch=irene ; center=tgcc ; fi
[3901]52if [[ $(hostname) = lsce3005* ]] ; then arch=spip  ; center=spip ; fi
[6064]53if [[ $(hostname) = lsce5138* ]] ; then arch=spip  ; center=spip ; fi
[3901]54
[3620]55PROGRAM=$(basename ${0})
56
[4298]57if [[ "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 $(ccc_home -u igcmg)/MachineEnvironment/irene/env_irene
70        source ${SUBMIT_DIR}/arch.env
71        #module load nco
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
86fi
[3620]87##
[4172]88echo ${Titre}"Command line parameters"${Norm}
[3620]89## ===========================================================================
[3686]90set -e
[3620]91set -o verbose
92set -o xtrace
93
94while [[ ${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
110done
111
112##
[4172]113echo ${Titre}"Short names (grid names in Oasis)"${Norm}
[3620]114## ===========================================================================
115case ${OCE} in
116    ( *ORC*) oce=orc ;;
117esac
118case ${ATM} in
119    ( *ICO*         ) atm=ico ;;
120    ( *dynamico*    ) atm=ico ;;
121    ( *lmd* | *LMD* ) atm=lmd ;;
122esac
123
124CplModel=${OCE}x${ATM}
125
126##
[4172]127echo ${Titre}"Get input files"${Norm}
[3620]128## ===========================================================================
129[[ -f ${OCE}_coordinates_mask.nc ]] || cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc  .
[3686]130[[ -f ${ATM}_grid.nc             ]] || cp ${R_IN}/ATM/GRID/${ATM}_grid.nc                   .
[3620]131
132#
[4172]133echo ${Titre}"Format for OASIS-MCT files : should be NetCDF3 classic or NetCDF3 64 bits"${Norm}
[3620]134# ---------------------------------------------------------------------------
[4199]135FL_FMT=netcdf4
[3620]136#
[4172]137echo ${Titre}"Cleaning"${Norm}
[3620]138# ----------------------------------------------------------------------------
139rm -f grids_${CplModel}.nc masks_${CplModel}.nc areas_${CplModel}.nc
140rm  -f *_tmp.nc
141
142#
[4298]143if [[ ${atm} = *lmd* ]] ; then
144    ncrename --dimension lon,x  ${ATM}_grid_maskFrom_${OCE}.nc
145    ncrename --dimension lat,y  ${ATM}_grid_maskFrom_${OCE}.nc
146fi
[3620]147#
[4298]148#
[4172]149echo ${Titre}"Creates ocean fields"${Norm}
[3620]150# ----------------------------------------------------------------------------
[3913]151for OCEGRID in T U V ; do
[4199]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
[3620]154    # Inverts mask values and switch to integer
[6064]155    ncks --history -C --variable maskutil_${OCEGRID} ${OCE}_coordinates_mask.nc mask_${OCEGRID}_tmp.nc
[3620]156    ncatted --history \
[6064]157            --attribute coordinates,maskutil_${OCEGRID},d,,         \
158            --attribute online_operation,maskutil_${OCEGRID},d,,    \
159            --attribute cell_measures,maskutil_${OCEGRID},d,,       \
[3620]160    mask_${OCEGRID}_tmp.nc
161   
[6064]162    ncap2 --history --append --script "maskutil_${OCEGRID}=int(1-maskutil_${OCEGRID});"    mask_${OCEGRID}_tmp.nc masks_${CplModel}.nc
[3901]163    rm mask_${OCEGRID}_tmp.nc
[3620]164    ncatted --history \
[6064]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
[3620]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
[3901]170    rm grids_${CplModel}_tmp.nc
[3620]171done
172
[4199]173ncks --history --append --variable lon,lat ${ATM}_grid_maskFrom_${OCE}.nc grids_${CplModel}.nc
[3901]174 
[3620]175#
[4172]176echo ${Titre}"We need to have different names for dimensions and variables"${Norm}
[4298]177# --------------------------------------------------------------------------------
[3686]178ncrename --history --variable lon,alon   grids_${CplModel}.nc
179ncrename --history --variable lat,alat   grids_${CplModel}.nc
[3620]180
181if [[ ${ATM} = dynamico* || ${ATM} = ICO* ]] ; then
[4199]182    ncks --history --append --variable bounds_lon,bounds_lat ${ATM}_grid_maskFrom_${OCE}.nc grids_${CplModel}.nc
[3620]183fi
184
[4199]185ncks --history -C --append --variable aire   ${ATM}_grid_maskFrom_${OCE}.nc areas_${CplModel}.nc
[3620]186ncatted --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
[4298]194ncks --history -C --variable OceMask,OceFrac,Oce2AtmMask ${ATM}_grid_maskFrom_${OCE}.nc OceMask_tmp.nc
[3620]195ncatted --history \
[4186]196        --attribute cell_methods,OceMask,d,c,       \
[3620]197        --attribute coordinates,OceMask,d,,         \
198        --attribute online_operation,OceMask,d,,    \
199        --attribute _FillValue,OceMask,d,,          \
200        --attribute missing_value,OceMask,d,,       \
[4298]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,,       \
[3620]213        OceMask_tmp.nc
[4298]214
215ncap2 --history --append --script "Oce2AtmMask=int(1-Oce2AtmMask)" OceMask_tmp.nc masks_${CplModel}.nc # For OASIS, ocean=0, land=1
[5159]216#rm OceMask_tmp.nc
[3620]217ncatted --history \
[4298]218        --attribute long_name,Oce2AtmMask,o,c,"Land-sea mask"   \
[3620]219        --attribute units,OceMask,o,c,"Land:1, Ocean:0"  masks_${CplModel}.nc
220
221ncatted --history --attribute history,global,d,, grids_${CplModel}.nc
222ncatted --history --attribute history,global,d,, masks_${CplModel}.nc
223ncatted --history --attribute history,global,d,, areas_${CplModel}.nc
224
225if [[ ${atm} = *dynamico* || ${atm} = ico* ]] ; then
[3686]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
[3620]229fi
230
231#
232if [[ ${atm} = dynamico* || ${atm} = ico* ]] ; then
[4186]233    echo ${Titre}"DYNAMICO grids : 1) Set correct order of dimensions, 2) Add a dimension"${Norm}
234    # -------------------------------------------------------------------------------------------
[3620]235    mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc
236    ncpdq --permute nvertex,ycell,xcell  grids_${CplModel}_tmp.nc grids_${CplModel}.nc
[4186]237
[3620]238    mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc
239    cat <<EOF >add_dim.nco
240//
241defdim("xcell",1) ;
242alat               [ycell,xcell] = alat       ;
243alon               [ycell,xcell] = alon       ;
244bounds_lat [nvertex,ycell,xcell] = bounds_lat ;
245bounds_lon [nvertex,ycell,xcell] = bounds_lon ;
246//
247EOF
[4186]248   
[4199]249    ncap2 --history --append --script-file add_dim.nco  grids_${CplModel}_tmp.nc grids_${CplModel}.nc
[3620]250   
251    mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc
[4199]252    ncap2 --history --append --script 'defdim("xcell",1) '   masks_${CplModel}_tmp.nc masks_${CplModel}.nc
[4186]253    mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc
[4298]254    ncap2 --history --append --script 'OceFrac    [ycell,xcell]=OceFrac'      masks_${CplModel}_tmp.nc masks_${CplModel}.nc
[5159]255    mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc
[4298]256    ncap2 --history --append --script 'OceMask    [ycell,xcell]=OceMask'      masks_${CplModel}_tmp.nc masks_${CplModel}.nc
[5159]257    mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc
[4298]258    ncap2 --history --append --script 'Oce2AtmMask[ycell,xcell]=Oce2AtmMask'  masks_${CplModel}_tmp.nc masks_${CplModel}.nc
[3620]259    mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc
[4199]260    ncap2 --history --append --script 'defdim("xcell",1) ; aire[ycell,xcell]=aire ; ' areas_${CplModel}_tmp.nc areas_${CplModel}.nc
[3901]261    rm -f grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc
[3620]262fi
[4186]263 
[3620]264#
[4172]265echo ${Titre}"Some changes specific to LMDZ lon/lat grid"${Norm}
[3620]266# ----------------------------------------------------------------------------
267if [[ ${atm} = lmd* ]] ; then
[4172]268    echo ${Titre}"Spreads lon and lat to get 2D fields"${Norm}
[3620]269    # -----------------------------------------------------------------------
270    mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc
[4298]271    ncap2 --history --append --script "alon[y,x]=alon; alat[y,x]=alat"  grids_${CplModel}_tmp.nc grids_${CplModel}.nc
[3901]272    rm -f grids_${CplModel}_tmp.nc
[3620]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   
[4172]283    echo ${Titre}"Generates cell corners"${Norm}
[3620]284    # -----------------------------------------------------------------------
285cat <<EOF > add_bounds.nco
286defdim ("nvertex_lmd", 4) ;
287*delta_x = alon(0,1) - alon(0,0) ;
288*delta_y = alat(1,0) - alat(0,0) ;
289//
[4298]290bounds_lon[nvertex_lmd,y,x] = 0.0 ;
291bounds_lat[nvertex_lmd,y,x] = 0.0 ;
[3620]292//
293bounds_lon (0,:,:) = alon + delta_x*0.5 ;
294bounds_lat (0,:,:) = alat + delta_y*0.5 ;
295bounds_lon (1,:,:) = alon + delta_x*0.5 ;
296bounds_lat (1,:,:) = alat - delta_y*0.5 ;
297bounds_lon (2,:,:) = alon - delta_x*0.5 ;
298bounds_lat (2,:,:) = alat - delta_y*0.5 ;
299bounds_lon (3,:,:) = alon - delta_x*0.5 ;
300bounds_lat (3,:,:) = alat + delta_y*0.5 ;
301//
302where (bounds_lat >  90.0 ) bounds_lat =  90.0 ;;
303where (bounds_lat < -90.0 ) bounds_lat = -90.0 ;;
304//
305EOF
306    mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc
[4199]307    ncap2 --history --script-file add_bounds.nco -O grids_${CplModel}_tmp.nc grids_${CplModel}.nc
[3901]308    rm grids_${CplModel}_tmp.nc
[3620]309fi
310
311#
[4186]312 
[4172]313echo ${Titre}"Generates grid o${atm}, 'o' meaning 'one'"${Norm}
314# same as t${atm} grid, with surfaces set to 1
[3686]315# and mask to 0 (ocean everywhere, to compute integral over the whole grid))
[3620]316# This grid is used when field are quantities instead of fluxes (i.e river flow)
317# ----------------------------------------------------------------------------
318mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc
[4199]319ncap2 --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
[3620]320
321mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc
[4199]322ncap2 --history --script "o${atm}_aire=aire*0.0d+1.0d ; "   areas_${CplModel}_tmp.nc areas_${CplModel}.nc
[3620]323
324mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc
[4298]325ncap2 --history --script "o${atm}_mask=int(Oce2AtmMask)*0+0 ; " masks_${CplModel}_tmp.nc masks_${CplModel}.nc
[3620]326
[3901]327rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc
328
[4186]329
[6064]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
[4199]336
[6064]337# mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc
338# ncap2 --history --script "c${atm}_aire=aire"   areas_${CplModel}_tmp.nc areas_${CplModel}.nc
[4199]339
[6064]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
[4199]342
[6064]343# rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc
[4199]344
[4186]345echo ${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))
[6064]348# This grid is used when field are quantities instead of fluxes
[4186]349# --------------------------------------------------------------------------------------------------------
350mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc
[4199]351ncap2 --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
[4186]352
353mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc
[4199]354ncap2 --history --script "area_grid_O=area_grid_T*0.0d+1.0d;"   areas_${CplModel}_tmp.nc areas_${CplModel}.nc
[4186]355
[4199]356ncks -C --history --overwrite -v maskutil_T ${OCE}_coordinates_mask.nc maskutil_T.nc
[6064]357ncap2 --history --append --script "maskutil_O=maskutil_T; " maskutil_T.nc masks_${CplModel}.nc
[4186]358
359rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc
360
361
[6064]362# echo ${Titre}"Creates OCEAN C grid : redundant points removed to compute proper integrals"${Norm}
363# # --------------------------------------------------------------------------------------------------------
[4186]364
[6064]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
[4186]367
[6064]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
[4186]370
[6064]371# ncap2 --history --append --script "mask_C=maskutil_T; " maskutil_T.nc masks_${CplModel}.nc
[4186]372
[6064]373# rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc maskutil_T.nc
[4186]374
[3620]375#
[4172]376echo ${Titre}"Final renaming"${Norm}
[3620]377# ----------------------------------------------------------------------------
[6064]378for OCEGRID in T U V O
[3620]379do
380    ocegrid=${OCEGRID~} # To lowercase
[3686]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
[6064]385    ncrename --history --variable maskutil_${OCEGRID},${ocegrid}${oce}.msk         masks_${CplModel}.nc
[3686]386    ncrename --history --variable area_grid_${OCEGRID},${ocegrid}${oce}.srf        areas_${CplModel}.nc
[3620]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
393done
394
[3686]395ncrename --history --variable alon,t${atm}.lon                grids_${CplModel}.nc
396ncrename --history --variable alat,t${atm}.lat                grids_${CplModel}.nc
[4298]397ncrename --history --variable Oce2AtmMask,t${atm}.msk         masks_${CplModel}.nc
[3686]398ncrename --history --variable aire,t${atm}.srf                areas_${CplModel}.nc
399ncrename --history --variable bounds_lon,t${atm}.clo          grids_${CplModel}.nc
400ncrename --history --variable bounds_lat,t${atm}.cla          grids_${CplModel}.nc
[3620]401
[6064]402for ATMGRID in O ; do
[4186]403    atmgrid=${ATMGRID~} # To lowercase
[4199]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
410done
411   
[6064]412for ATMGRID in T O ; do
[4199]413    atmgrid=${ATMGRID~} # To lowercase
[3620]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"   \
[3686]417            --attribute units,${atmgrid}${atm}.clo,o,c,"degrees_east"            \
[3620]418            --attribute units,${atmgrid}${atm}.cla,o,c,"degrees_north"        grids_${CplModel}.nc
419done
420
[4259]421
422echo ${Titre}"Add time axis and coordinates information"${Norm}
423# (needed if files need to be read by XIOS) ???
424## ===========================================================================
425ncap2 --overwrite --history --script 'defdim("time_counter",1) ;' ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_time.nc
426
427if [[ ${atm} = ico ]] ; then
428    cat <<EOF > add_time.nco
[4298]429OceFrac     [time_counter,cell] = OceFrac     [cell] ;
430OceMask     [time_counter,cell] = OceMask     [cell] ;
431Oce2AtmMask [time_counter,cell] = Oce2AtmMask [cell] ;
[4259]432EOF
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
439fi
440
441if [[ ${atm} = lmd ]] ; then
442    cat <<EOF > add_time.nco
[4298]443OceFrac     [time_counter,y,x] = OceFrac     [y,x] ;
444OceMask     [time_counter,y,x] = OceMask     [y,x]  ;
445Oce2AtmMask [time_counter,y,x] = Oce2AtmMask [y,x]  ;
[4259]446EOF
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"    \
[4298]454            -a coordinates,Oce2AtmMask,m,c,"time_counter lat lon"    \
[4259]455            -a coordinates,aire,m,c,"lat lon" \
456            ${ATM}_grid_maskFrom_${OCE}.nc
457fi
458ncks --alphabetize --history --overwrite --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}_time.nc tmp_${ATM}_grid_maskFrom_${OCE}_time.nc
459mv tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ${ATM}_grid_maskFrom_${OCE}_time.nc
[3620]460##
[4172]461echo ${Titre}"Add some useful information in NetCDF headers"${Norm}
[3620]462## ===========================================================================
463NCO=$(ncks --version |& tail -1|sed 's/ncks //')
464for 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}"         \
[3718]479            --attribute name,global,o,c,"${type}_${CplModel}.nc"       \
[3620]480            --attribute directory,global,o,c,"$(pwd)"                  \
481            --attribute description,global,o,c,"Fields needed by OASIS-MCT" \
[3718]482            --attribute title,global,o,c,"${type}_${CplModel}.nc"      \
[3620]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)"              \
[3718]489            --attribute SVN_Author,global,o,c,"$Author$"      \
490            --attribute SVN_Date,global,o,c,"$Date$" \
[3665]491            --attribute SVN_Revision,global,o,c,"$Revision$"                    \
[3718]492            --attribute SVN_Id,global,o,c,"$Id$" \
493            --attribute SVN_HeardURL,global,o,c,"$HeadURL $" \
[3620]494            ${type}_${CplModel}.nc
495done
496
497
498exit
499#
[4172]500echo ${Titre}"Name of the dimensions ?"${Norm} 
[3620]501# ----------------------------------------------------------------------------
[3913]502for OCEGRID in T U V ; do
[3620]503    ocegrid=${OCEGRID~} # Downcase name of grids
[3686]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
[3620]507done
508
509## ===========================================================================
[4186]510echo ${Titre}"Exit from CreateOasisGrids "${Norm}
[4172]511
512## ===========================================================================
[3620]513##
[4172]514echo ${Titre}"                  That's all folk's !!!   "${Norm}
[3620]515##
516## ===========================================================================
Note: See TracBrowser for help on using the repository browser.