[5158] | 1 | #!/bin/bash |
---|
[3620] | 2 | ### =========================================================================== |
---|
| 3 | ### |
---|
| 4 | ### Creates grids.nc, masks.nc and areas.nc for OASIS-MCT |
---|
| 5 | ### |
---|
| 6 | ### =========================================================================== |
---|
| 7 | ## |
---|
[6190] | 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. |
---|
[3620] | 11 | ## |
---|
[6190] | 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 | ## |
---|
[3627] | 28 | ### |
---|
| 29 | ### Documentation : https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX |
---|
| 30 | ### |
---|
[3623] | 31 | ## SVN information |
---|
[3665] | 32 | # $Author$ |
---|
| 33 | # $Date$ |
---|
| 34 | # $Revision$ |
---|
| 35 | # $Id$ |
---|
[3633] | 36 | # $HeadURL$ |
---|
[3620] | 37 | |
---|
[4172] | 38 | set +vx |
---|
| 39 | |
---|
| 40 | echo ${Titre}"Starting CreateOasisGrids.bash"${Norm} |
---|
| 41 | |
---|
[3620] | 42 | ## |
---|
[4172] | 43 | echo ${Titre}"Default configuration (may be overrided by command line parameters)"${Norm} |
---|
[3620] | 44 | ## =========================================================================== |
---|
[5158] | 45 | #OCE=ORCA2.3 |
---|
| 46 | OCE=eORCA1.2 |
---|
[4298] | 47 | #ATM=ICO30 |
---|
[5158] | 48 | ATM=ICO40 |
---|
[4172] | 49 | #ATM=ICO450 |
---|
| 50 | #ATM=LMD144142 |
---|
[5159] | 51 | #ATM=LMD9695 |
---|
[3620] | 52 | |
---|
| 53 | ## =========================================================================== |
---|
| 54 | ## |
---|
| 55 | ## You should not change anything below this line .... |
---|
| 56 | ## |
---|
| 57 | ## =========================================================================== |
---|
| 58 | |
---|
[4172] | 59 | echo ${Titre}"Defines computer"${Norm} |
---|
[3620] | 60 | # ================ |
---|
[3901] | 61 | if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi |
---|
[5159] | 62 | if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi |
---|
[3901] | 63 | if [[ $(hostname) = lsce3005* ]] ; then arch=spip ; center=spip ; fi |
---|
[6064] | 64 | if [[ $(hostname) = lsce5138* ]] ; then arch=spip ; center=spip ; fi |
---|
[3901] | 65 | |
---|
[3620] | 66 | PROGRAM=$(basename ${0}) |
---|
| 67 | |
---|
[4298] | 68 | if [[ "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 |
---|
[6107] | 79 | module purge |
---|
[4298] | 80 | source ${SUBMIT_DIR}/arch.env |
---|
[6446] | 81 | module load nco #/4.9.1 |
---|
| 82 | module load cdo #/1.9.5 |
---|
[4298] | 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 |
---|
| 97 | fi |
---|
[3620] | 98 | ## |
---|
[4172] | 99 | echo ${Titre}"Command line parameters"${Norm} |
---|
[3620] | 100 | ## =========================================================================== |
---|
[3686] | 101 | set -e |
---|
[3620] | 102 | set -o verbose |
---|
| 103 | set -o xtrace |
---|
| 104 | |
---|
| 105 | while [[ ${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 |
---|
| 121 | done |
---|
| 122 | |
---|
| 123 | ## |
---|
[4172] | 124 | echo ${Titre}"Short names (grid names in Oasis)"${Norm} |
---|
[3620] | 125 | ## =========================================================================== |
---|
| 126 | case ${OCE} in |
---|
| 127 | ( *ORC*) oce=orc ;; |
---|
| 128 | esac |
---|
| 129 | case ${ATM} in |
---|
| 130 | ( *ICO* ) atm=ico ;; |
---|
| 131 | ( *dynamico* ) atm=ico ;; |
---|
| 132 | ( *lmd* | *LMD* ) atm=lmd ;; |
---|
| 133 | esac |
---|
| 134 | |
---|
| 135 | CplModel=${OCE}x${ATM} |
---|
| 136 | |
---|
| 137 | ## |
---|
[4172] | 138 | echo ${Titre}"Get input files"${Norm} |
---|
[3620] | 139 | ## =========================================================================== |
---|
| 140 | [[ -f ${OCE}_coordinates_mask.nc ]] || cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc . |
---|
[3686] | 141 | [[ -f ${ATM}_grid.nc ]] || cp ${R_IN}/ATM/GRID/${ATM}_grid.nc . |
---|
[3620] | 142 | |
---|
| 143 | # |
---|
[4172] | 144 | echo ${Titre}"Format for OASIS-MCT files : should be NetCDF3 classic or NetCDF3 64 bits"${Norm} |
---|
[3620] | 145 | # --------------------------------------------------------------------------- |
---|
[4199] | 146 | FL_FMT=netcdf4 |
---|
[3620] | 147 | # |
---|
[4172] | 148 | echo ${Titre}"Cleaning"${Norm} |
---|
[3620] | 149 | # ---------------------------------------------------------------------------- |
---|
| 150 | rm -f grids_${CplModel}.nc masks_${CplModel}.nc areas_${CplModel}.nc |
---|
| 151 | rm -f *_tmp.nc |
---|
| 152 | |
---|
| 153 | # |
---|
[4298] | 154 | if [[ ${atm} = *lmd* ]] ; then |
---|
| 155 | ncrename --dimension lon,x ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 156 | ncrename --dimension lat,y ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 157 | fi |
---|
[3620] | 158 | # |
---|
[4298] | 159 | # |
---|
[4172] | 160 | echo ${Titre}"Creates ocean fields"${Norm} |
---|
[3620] | 161 | # ---------------------------------------------------------------------------- |
---|
[3913] | 162 | for OCEGRID in T U V ; do |
---|
[4199] | 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 |
---|
[3620] | 165 | # Inverts mask values and switch to integer |
---|
[6064] | 166 | ncks --history -C --variable maskutil_${OCEGRID} ${OCE}_coordinates_mask.nc mask_${OCEGRID}_tmp.nc |
---|
[3620] | 167 | ncatted --history \ |
---|
[6064] | 168 | --attribute coordinates,maskutil_${OCEGRID},d,, \ |
---|
| 169 | --attribute online_operation,maskutil_${OCEGRID},d,, \ |
---|
| 170 | --attribute cell_measures,maskutil_${OCEGRID},d,, \ |
---|
[3620] | 171 | mask_${OCEGRID}_tmp.nc |
---|
| 172 | |
---|
[6064] | 173 | ncap2 --history --append --script "maskutil_${OCEGRID}=int(1-maskutil_${OCEGRID});" mask_${OCEGRID}_tmp.nc masks_${CplModel}.nc |
---|
[3901] | 174 | rm mask_${OCEGRID}_tmp.nc |
---|
[3620] | 175 | ncatted --history \ |
---|
[6064] | 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 |
---|
[3620] | 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 |
---|
[3901] | 181 | rm grids_${CplModel}_tmp.nc |
---|
[3620] | 182 | done |
---|
| 183 | |
---|
[4199] | 184 | ncks --history --append --variable lon,lat ${ATM}_grid_maskFrom_${OCE}.nc grids_${CplModel}.nc |
---|
[3901] | 185 | |
---|
[3620] | 186 | # |
---|
[4172] | 187 | echo ${Titre}"We need to have different names for dimensions and variables"${Norm} |
---|
[4298] | 188 | # -------------------------------------------------------------------------------- |
---|
[3686] | 189 | ncrename --history --variable lon,alon grids_${CplModel}.nc |
---|
| 190 | ncrename --history --variable lat,alat grids_${CplModel}.nc |
---|
[3620] | 191 | |
---|
| 192 | if [[ ${ATM} = dynamico* || ${ATM} = ICO* ]] ; then |
---|
[4199] | 193 | ncks --history --append --variable bounds_lon,bounds_lat ${ATM}_grid_maskFrom_${OCE}.nc grids_${CplModel}.nc |
---|
[3620] | 194 | fi |
---|
| 195 | |
---|
[4199] | 196 | ncks --history -C --append --variable aire ${ATM}_grid_maskFrom_${OCE}.nc areas_${CplModel}.nc |
---|
[3620] | 197 | ncatted --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 | |
---|
[4298] | 205 | ncks --history -C --variable OceMask,OceFrac,Oce2AtmMask ${ATM}_grid_maskFrom_${OCE}.nc OceMask_tmp.nc |
---|
[3620] | 206 | ncatted --history \ |
---|
[4186] | 207 | --attribute cell_methods,OceMask,d,c, \ |
---|
[3620] | 208 | --attribute coordinates,OceMask,d,, \ |
---|
| 209 | --attribute online_operation,OceMask,d,, \ |
---|
| 210 | --attribute _FillValue,OceMask,d,, \ |
---|
| 211 | --attribute missing_value,OceMask,d,, \ |
---|
[4298] | 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,, \ |
---|
[3620] | 224 | OceMask_tmp.nc |
---|
[4298] | 225 | |
---|
| 226 | ncap2 --history --append --script "Oce2AtmMask=int(1-Oce2AtmMask)" OceMask_tmp.nc masks_${CplModel}.nc # For OASIS, ocean=0, land=1 |
---|
[5159] | 227 | #rm OceMask_tmp.nc |
---|
[3620] | 228 | ncatted --history \ |
---|
[4298] | 229 | --attribute long_name,Oce2AtmMask,o,c,"Land-sea mask" \ |
---|
[3620] | 230 | --attribute units,OceMask,o,c,"Land:1, Ocean:0" masks_${CplModel}.nc |
---|
| 231 | |
---|
| 232 | ncatted --history --attribute history,global,d,, grids_${CplModel}.nc |
---|
| 233 | ncatted --history --attribute history,global,d,, masks_${CplModel}.nc |
---|
| 234 | ncatted --history --attribute history,global,d,, areas_${CplModel}.nc |
---|
| 235 | |
---|
| 236 | if [[ ${atm} = *dynamico* || ${atm} = ico* ]] ; then |
---|
[3686] | 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 |
---|
[3620] | 240 | fi |
---|
| 241 | |
---|
| 242 | # |
---|
| 243 | if [[ ${atm} = dynamico* || ${atm} = ico* ]] ; then |
---|
[4186] | 244 | echo ${Titre}"DYNAMICO grids : 1) Set correct order of dimensions, 2) Add a dimension"${Norm} |
---|
| 245 | # ------------------------------------------------------------------------------------------- |
---|
[3620] | 246 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
| 247 | ncpdq --permute nvertex,ycell,xcell grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
[4186] | 248 | |
---|
[3620] | 249 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
| 250 | cat <<EOF >add_dim.nco |
---|
| 251 | // |
---|
| 252 | defdim("xcell",1) ; |
---|
| 253 | alat [ycell,xcell] = alat ; |
---|
| 254 | alon [ycell,xcell] = alon ; |
---|
| 255 | bounds_lat [nvertex,ycell,xcell] = bounds_lat ; |
---|
| 256 | bounds_lon [nvertex,ycell,xcell] = bounds_lon ; |
---|
| 257 | // |
---|
| 258 | EOF |
---|
[4186] | 259 | |
---|
[4199] | 260 | ncap2 --history --append --script-file add_dim.nco grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
[3620] | 261 | |
---|
| 262 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4199] | 263 | ncap2 --history --append --script 'defdim("xcell",1) ' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[4186] | 264 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4298] | 265 | ncap2 --history --append --script 'OceFrac [ycell,xcell]=OceFrac' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[5159] | 266 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4298] | 267 | ncap2 --history --append --script 'OceMask [ycell,xcell]=OceMask' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[5159] | 268 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4298] | 269 | ncap2 --history --append --script 'Oce2AtmMask[ycell,xcell]=Oce2AtmMask' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[3620] | 270 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
[4199] | 271 | ncap2 --history --append --script 'defdim("xcell",1) ; aire[ycell,xcell]=aire ; ' areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
[3901] | 272 | rm -f grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc |
---|
[3620] | 273 | fi |
---|
[4186] | 274 | |
---|
[3620] | 275 | # |
---|
[4172] | 276 | echo ${Titre}"Some changes specific to LMDZ lon/lat grid"${Norm} |
---|
[3620] | 277 | # ---------------------------------------------------------------------------- |
---|
| 278 | if [[ ${atm} = lmd* ]] ; then |
---|
[4172] | 279 | echo ${Titre}"Spreads lon and lat to get 2D fields"${Norm} |
---|
[3620] | 280 | # ----------------------------------------------------------------------- |
---|
| 281 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
[4298] | 282 | ncap2 --history --append --script "alon[y,x]=alon; alat[y,x]=alat" grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
[3901] | 283 | rm -f grids_${CplModel}_tmp.nc |
---|
[3620] | 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 | |
---|
[4172] | 294 | echo ${Titre}"Generates cell corners"${Norm} |
---|
[3620] | 295 | # ----------------------------------------------------------------------- |
---|
| 296 | cat <<EOF > add_bounds.nco |
---|
| 297 | defdim ("nvertex_lmd", 4) ; |
---|
| 298 | *delta_x = alon(0,1) - alon(0,0) ; |
---|
| 299 | *delta_y = alat(1,0) - alat(0,0) ; |
---|
| 300 | // |
---|
[4298] | 301 | bounds_lon[nvertex_lmd,y,x] = 0.0 ; |
---|
| 302 | bounds_lat[nvertex_lmd,y,x] = 0.0 ; |
---|
[3620] | 303 | // |
---|
| 304 | bounds_lon (0,:,:) = alon + delta_x*0.5 ; |
---|
| 305 | bounds_lat (0,:,:) = alat + delta_y*0.5 ; |
---|
| 306 | bounds_lon (1,:,:) = alon + delta_x*0.5 ; |
---|
| 307 | bounds_lat (1,:,:) = alat - delta_y*0.5 ; |
---|
| 308 | bounds_lon (2,:,:) = alon - delta_x*0.5 ; |
---|
| 309 | bounds_lat (2,:,:) = alat - delta_y*0.5 ; |
---|
| 310 | bounds_lon (3,:,:) = alon - delta_x*0.5 ; |
---|
| 311 | bounds_lat (3,:,:) = alat + delta_y*0.5 ; |
---|
| 312 | // |
---|
| 313 | where (bounds_lat > 90.0 ) bounds_lat = 90.0 ;; |
---|
| 314 | where (bounds_lat < -90.0 ) bounds_lat = -90.0 ;; |
---|
| 315 | // |
---|
| 316 | EOF |
---|
| 317 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
[4199] | 318 | ncap2 --history --script-file add_bounds.nco -O grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
[3901] | 319 | rm grids_${CplModel}_tmp.nc |
---|
[3620] | 320 | fi |
---|
| 321 | |
---|
| 322 | # |
---|
[4186] | 323 | |
---|
[4172] | 324 | echo ${Titre}"Generates grid o${atm}, 'o' meaning 'one'"${Norm} |
---|
| 325 | # same as t${atm} grid, with surfaces set to 1 |
---|
[3686] | 326 | # and mask to 0 (ocean everywhere, to compute integral over the whole grid)) |
---|
[3620] | 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 |
---|
[4199] | 330 | 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 |
---|
[3620] | 331 | |
---|
| 332 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
[4199] | 333 | ncap2 --history --script "o${atm}_aire=aire*0.0d+1.0d ; " areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
[3620] | 334 | |
---|
| 335 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4298] | 336 | ncap2 --history --script "o${atm}_mask=int(Oce2AtmMask)*0+0 ; " masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[3620] | 337 | |
---|
[3901] | 338 | rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc |
---|
| 339 | |
---|
[4186] | 340 | |
---|
[6064] | 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 |
---|
[4199] | 347 | |
---|
[6064] | 348 | # mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
| 349 | # ncap2 --history --script "c${atm}_aire=aire" areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
[4199] | 350 | |
---|
[6064] | 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 |
---|
[4199] | 353 | |
---|
[6064] | 354 | # rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc |
---|
[4199] | 355 | |
---|
[4186] | 356 | echo ${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)) |
---|
[6064] | 359 | # This grid is used when field are quantities instead of fluxes |
---|
[4186] | 360 | # -------------------------------------------------------------------------------------------------------- |
---|
| 361 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
[4199] | 362 | 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 |
---|
[4186] | 363 | |
---|
| 364 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
[4199] | 365 | ncap2 --history --script "area_grid_O=area_grid_T*0.0d+1.0d;" areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
[4186] | 366 | |
---|
[4199] | 367 | ncks -C --history --overwrite -v maskutil_T ${OCE}_coordinates_mask.nc maskutil_T.nc |
---|
[6064] | 368 | ncap2 --history --append --script "maskutil_O=maskutil_T; " maskutil_T.nc masks_${CplModel}.nc |
---|
[4186] | 369 | |
---|
| 370 | rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc |
---|
| 371 | |
---|
| 372 | |
---|
[6064] | 373 | # echo ${Titre}"Creates OCEAN C grid : redundant points removed to compute proper integrals"${Norm} |
---|
| 374 | # # -------------------------------------------------------------------------------------------------------- |
---|
[4186] | 375 | |
---|
[6064] | 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 |
---|
[4186] | 378 | |
---|
[6064] | 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 |
---|
[4186] | 381 | |
---|
[6064] | 382 | # ncap2 --history --append --script "mask_C=maskutil_T; " maskutil_T.nc masks_${CplModel}.nc |
---|
[4186] | 383 | |
---|
[6064] | 384 | # rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc maskutil_T.nc |
---|
[4186] | 385 | |
---|
[3620] | 386 | # |
---|
[4172] | 387 | echo ${Titre}"Final renaming"${Norm} |
---|
[3620] | 388 | # ---------------------------------------------------------------------------- |
---|
[6064] | 389 | for OCEGRID in T U V O |
---|
[3620] | 390 | do |
---|
| 391 | ocegrid=${OCEGRID~} # To lowercase |
---|
[3686] | 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 |
---|
[6064] | 396 | ncrename --history --variable maskutil_${OCEGRID},${ocegrid}${oce}.msk masks_${CplModel}.nc |
---|
[3686] | 397 | ncrename --history --variable area_grid_${OCEGRID},${ocegrid}${oce}.srf areas_${CplModel}.nc |
---|
[3620] | 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 |
---|
| 404 | done |
---|
| 405 | |
---|
[3686] | 406 | ncrename --history --variable alon,t${atm}.lon grids_${CplModel}.nc |
---|
| 407 | ncrename --history --variable alat,t${atm}.lat grids_${CplModel}.nc |
---|
[4298] | 408 | ncrename --history --variable Oce2AtmMask,t${atm}.msk masks_${CplModel}.nc |
---|
[3686] | 409 | ncrename --history --variable aire,t${atm}.srf areas_${CplModel}.nc |
---|
| 410 | ncrename --history --variable bounds_lon,t${atm}.clo grids_${CplModel}.nc |
---|
| 411 | ncrename --history --variable bounds_lat,t${atm}.cla grids_${CplModel}.nc |
---|
[3620] | 412 | |
---|
[6064] | 413 | for ATMGRID in O ; do |
---|
[4186] | 414 | atmgrid=${ATMGRID~} # To lowercase |
---|
[4199] | 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 |
---|
| 421 | done |
---|
| 422 | |
---|
[6064] | 423 | for ATMGRID in T O ; do |
---|
[4199] | 424 | atmgrid=${ATMGRID~} # To lowercase |
---|
[3620] | 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" \ |
---|
[3686] | 428 | --attribute units,${atmgrid}${atm}.clo,o,c,"degrees_east" \ |
---|
[3620] | 429 | --attribute units,${atmgrid}${atm}.cla,o,c,"degrees_north" grids_${CplModel}.nc |
---|
| 430 | done |
---|
| 431 | |
---|
[4259] | 432 | |
---|
| 433 | echo ${Titre}"Add time axis and coordinates information"${Norm} |
---|
| 434 | # (needed if files need to be read by XIOS) ??? |
---|
| 435 | ## =========================================================================== |
---|
| 436 | ncap2 --overwrite --history --script 'defdim("time_counter",1) ;' ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
| 437 | |
---|
| 438 | if [[ ${atm} = ico ]] ; then |
---|
| 439 | cat <<EOF > add_time.nco |
---|
[4298] | 440 | OceFrac [time_counter,cell] = OceFrac [cell] ; |
---|
| 441 | OceMask [time_counter,cell] = OceMask [cell] ; |
---|
| 442 | Oce2AtmMask [time_counter,cell] = Oce2AtmMask [cell] ; |
---|
[4259] | 443 | EOF |
---|
| 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 |
---|
| 450 | fi |
---|
| 451 | |
---|
| 452 | if [[ ${atm} = lmd ]] ; then |
---|
| 453 | cat <<EOF > add_time.nco |
---|
[4298] | 454 | OceFrac [time_counter,y,x] = OceFrac [y,x] ; |
---|
| 455 | OceMask [time_counter,y,x] = OceMask [y,x] ; |
---|
| 456 | Oce2AtmMask [time_counter,y,x] = Oce2AtmMask [y,x] ; |
---|
[4259] | 457 | EOF |
---|
| 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" \ |
---|
[4298] | 465 | -a coordinates,Oce2AtmMask,m,c,"time_counter lat lon" \ |
---|
[4259] | 466 | -a coordinates,aire,m,c,"lat lon" \ |
---|
| 467 | ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 468 | fi |
---|
| 469 | ncks --alphabetize --history --overwrite --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}_time.nc tmp_${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
| 470 | mv tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
[6368] | 471 | |
---|
| 472 | mv ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_notime.nc |
---|
| 473 | mv ${ATM}_grid_maskFrom_${OCE}_time.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 474 | |
---|
[3620] | 475 | ## |
---|
[4172] | 476 | echo ${Titre}"Add some useful information in NetCDF headers"${Norm} |
---|
[3620] | 477 | ## =========================================================================== |
---|
| 478 | NCO=$(ncks --version |& tail -1|sed 's/ncks //') |
---|
| 479 | for 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}" \ |
---|
[3718] | 494 | --attribute name,global,o,c,"${type}_${CplModel}.nc" \ |
---|
[3620] | 495 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
| 496 | --attribute description,global,o,c,"Fields needed by OASIS-MCT" \ |
---|
[3718] | 497 | --attribute title,global,o,c,"${type}_${CplModel}.nc" \ |
---|
[3620] | 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)" \ |
---|
[3718] | 504 | --attribute SVN_Author,global,o,c,"$Author$" \ |
---|
| 505 | --attribute SVN_Date,global,o,c,"$Date$" \ |
---|
[3665] | 506 | --attribute SVN_Revision,global,o,c,"$Revision$" \ |
---|
[3718] | 507 | --attribute SVN_Id,global,o,c,"$Id$" \ |
---|
| 508 | --attribute SVN_HeardURL,global,o,c,"$HeadURL $" \ |
---|
[3620] | 509 | ${type}_${CplModel}.nc |
---|
| 510 | done |
---|
| 511 | |
---|
| 512 | exit |
---|
| 513 | # |
---|
[4172] | 514 | echo ${Titre}"Name of the dimensions ?"${Norm} |
---|
[3620] | 515 | # ---------------------------------------------------------------------------- |
---|
[3913] | 516 | for OCEGRID in T U V ; do |
---|
[3620] | 517 | ocegrid=${OCEGRID~} # Downcase name of grids |
---|
[3686] | 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 |
---|
[3620] | 521 | done |
---|
| 522 | |
---|
| 523 | ## =========================================================================== |
---|
[4186] | 524 | echo ${Titre}"Exit from CreateOasisGrids "${Norm} |
---|
[4172] | 525 | |
---|
| 526 | ## =========================================================================== |
---|
[3620] | 527 | ## |
---|
[4172] | 528 | echo ${Titre}" That's all folk's !!! "${Norm} |
---|
[3620] | 529 | ## |
---|
| 530 | ## =========================================================================== |
---|