source: TOOLS/MOSAIX/CreateOasisGrids.bash

Last change on this file was 6446, checked in by snguyen, 12 months ago

change modules for nco and cdo in CreateOasisGrids?.bash

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