[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] | 27 | set +vx |
---|
| 28 | |
---|
| 29 | echo ${Titre}"Starting CreateOasisGrids.bash"${Norm} |
---|
| 30 | |
---|
[3620] | 31 | ## |
---|
[4172] | 32 | echo ${Titre}"Default configuration (may be overrided by command line parameters)"${Norm} |
---|
[3620] | 33 | ## =========================================================================== |
---|
[5158] | 34 | #OCE=ORCA2.3 |
---|
| 35 | OCE=eORCA1.2 |
---|
[4298] | 36 | #ATM=ICO30 |
---|
[5158] | 37 | ATM=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] | 48 | echo ${Titre}"Defines computer"${Norm} |
---|
[3620] | 49 | # ================ |
---|
[3901] | 50 | if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi |
---|
[5159] | 51 | if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi |
---|
[3901] | 52 | if [[ $(hostname) = lsce3005* ]] ; then arch=spip ; center=spip ; fi |
---|
| 53 | |
---|
[3620] | 54 | PROGRAM=$(basename ${0}) |
---|
| 55 | |
---|
[4298] | 56 | if [[ "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 |
---|
| 85 | fi |
---|
[3620] | 86 | ## |
---|
[4172] | 87 | echo ${Titre}"Command line parameters"${Norm} |
---|
[3620] | 88 | ## =========================================================================== |
---|
[3686] | 89 | set -e |
---|
[3620] | 90 | set -o verbose |
---|
| 91 | set -o xtrace |
---|
| 92 | |
---|
| 93 | while [[ ${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 |
---|
| 109 | done |
---|
| 110 | |
---|
| 111 | ## |
---|
[4172] | 112 | echo ${Titre}"Short names (grid names in Oasis)"${Norm} |
---|
[3620] | 113 | ## =========================================================================== |
---|
| 114 | case ${OCE} in |
---|
| 115 | ( *ORC*) oce=orc ;; |
---|
| 116 | esac |
---|
| 117 | case ${ATM} in |
---|
| 118 | ( *ICO* ) atm=ico ;; |
---|
| 119 | ( *dynamico* ) atm=ico ;; |
---|
| 120 | ( *lmd* | *LMD* ) atm=lmd ;; |
---|
| 121 | esac |
---|
| 122 | |
---|
| 123 | CplModel=${OCE}x${ATM} |
---|
| 124 | |
---|
| 125 | ## |
---|
[4172] | 126 | echo ${Titre}"Get input files"${Norm} |
---|
[3620] | 127 | ## =========================================================================== |
---|
| 128 | [[ -f ${OCE}_coordinates_mask.nc ]] || cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc . |
---|
[3686] | 129 | [[ -f ${ATM}_grid.nc ]] || cp ${R_IN}/ATM/GRID/${ATM}_grid.nc . |
---|
[3620] | 130 | |
---|
| 131 | # |
---|
[4172] | 132 | echo ${Titre}"Format for OASIS-MCT files : should be NetCDF3 classic or NetCDF3 64 bits"${Norm} |
---|
[3620] | 133 | # --------------------------------------------------------------------------- |
---|
[4199] | 134 | FL_FMT=netcdf4 |
---|
[3620] | 135 | # |
---|
[4172] | 136 | echo ${Titre}"Cleaning"${Norm} |
---|
[3620] | 137 | # ---------------------------------------------------------------------------- |
---|
| 138 | rm -f grids_${CplModel}.nc masks_${CplModel}.nc areas_${CplModel}.nc |
---|
| 139 | rm -f *_tmp.nc |
---|
| 140 | |
---|
| 141 | # |
---|
[4298] | 142 | if [[ ${atm} = *lmd* ]] ; then |
---|
| 143 | ncrename --dimension lon,x ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 144 | ncrename --dimension lat,y ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 145 | fi |
---|
[3620] | 146 | # |
---|
[4298] | 147 | # |
---|
[4172] | 148 | echo ${Titre}"Creates ocean fields"${Norm} |
---|
[3620] | 149 | # ---------------------------------------------------------------------------- |
---|
[3913] | 150 | for OCEGRID in T U V ; do |
---|
[4199] | 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 |
---|
[3620] | 153 | # Inverts mask values and switch to integer |
---|
[4199] | 154 | ncks --history -C --variable mask_${OCEGRID} ${OCE}_coordinates_mask.nc mask_${OCEGRID}_tmp.nc |
---|
[3620] | 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 | |
---|
[4199] | 161 | ncap2 --history --append --script "mask_${OCEGRID}=int(1-mask_${OCEGRID});" mask_${OCEGRID}_tmp.nc masks_${CplModel}.nc |
---|
[3901] | 162 | rm mask_${OCEGRID}_tmp.nc |
---|
[3620] | 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 |
---|
[3901] | 169 | rm grids_${CplModel}_tmp.nc |
---|
[3620] | 170 | done |
---|
| 171 | |
---|
[4199] | 172 | ncks --history --append --variable lon,lat ${ATM}_grid_maskFrom_${OCE}.nc grids_${CplModel}.nc |
---|
[3901] | 173 | |
---|
[3620] | 174 | # |
---|
[4172] | 175 | echo ${Titre}"We need to have different names for dimensions and variables"${Norm} |
---|
[4298] | 176 | # -------------------------------------------------------------------------------- |
---|
[3686] | 177 | ncrename --history --variable lon,alon grids_${CplModel}.nc |
---|
| 178 | ncrename --history --variable lat,alat grids_${CplModel}.nc |
---|
[3620] | 179 | |
---|
| 180 | if [[ ${ATM} = dynamico* || ${ATM} = ICO* ]] ; then |
---|
[4199] | 181 | ncks --history --append --variable bounds_lon,bounds_lat ${ATM}_grid_maskFrom_${OCE}.nc grids_${CplModel}.nc |
---|
[3620] | 182 | fi |
---|
| 183 | |
---|
[4199] | 184 | ncks --history -C --append --variable aire ${ATM}_grid_maskFrom_${OCE}.nc areas_${CplModel}.nc |
---|
[3620] | 185 | ncatted --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 | |
---|
[4298] | 193 | ncks --history -C --variable OceMask,OceFrac,Oce2AtmMask ${ATM}_grid_maskFrom_${OCE}.nc OceMask_tmp.nc |
---|
[3620] | 194 | ncatted --history \ |
---|
[4186] | 195 | --attribute cell_methods,OceMask,d,c, \ |
---|
[3620] | 196 | --attribute coordinates,OceMask,d,, \ |
---|
| 197 | --attribute online_operation,OceMask,d,, \ |
---|
| 198 | --attribute _FillValue,OceMask,d,, \ |
---|
| 199 | --attribute missing_value,OceMask,d,, \ |
---|
[4298] | 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,, \ |
---|
[3620] | 212 | OceMask_tmp.nc |
---|
[4298] | 213 | |
---|
| 214 | ncap2 --history --append --script "Oce2AtmMask=int(1-Oce2AtmMask)" OceMask_tmp.nc masks_${CplModel}.nc # For OASIS, ocean=0, land=1 |
---|
[5159] | 215 | #rm OceMask_tmp.nc |
---|
[3620] | 216 | ncatted --history \ |
---|
[4298] | 217 | --attribute long_name,Oce2AtmMask,o,c,"Land-sea mask" \ |
---|
[3620] | 218 | --attribute units,OceMask,o,c,"Land:1, Ocean:0" masks_${CplModel}.nc |
---|
| 219 | |
---|
| 220 | ncatted --history --attribute history,global,d,, grids_${CplModel}.nc |
---|
| 221 | ncatted --history --attribute history,global,d,, masks_${CplModel}.nc |
---|
| 222 | ncatted --history --attribute history,global,d,, areas_${CplModel}.nc |
---|
| 223 | |
---|
| 224 | if [[ ${atm} = *dynamico* || ${atm} = ico* ]] ; then |
---|
[3686] | 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 |
---|
[3620] | 228 | fi |
---|
| 229 | |
---|
| 230 | # |
---|
| 231 | if [[ ${atm} = dynamico* || ${atm} = ico* ]] ; then |
---|
[4186] | 232 | echo ${Titre}"DYNAMICO grids : 1) Set correct order of dimensions, 2) Add a dimension"${Norm} |
---|
| 233 | # ------------------------------------------------------------------------------------------- |
---|
[3620] | 234 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
| 235 | ncpdq --permute nvertex,ycell,xcell grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
[4186] | 236 | |
---|
[3620] | 237 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
| 238 | cat <<EOF >add_dim.nco |
---|
| 239 | // |
---|
| 240 | defdim("xcell",1) ; |
---|
| 241 | alat [ycell,xcell] = alat ; |
---|
| 242 | alon [ycell,xcell] = alon ; |
---|
| 243 | bounds_lat [nvertex,ycell,xcell] = bounds_lat ; |
---|
| 244 | bounds_lon [nvertex,ycell,xcell] = bounds_lon ; |
---|
| 245 | // |
---|
| 246 | EOF |
---|
[4186] | 247 | |
---|
[4199] | 248 | ncap2 --history --append --script-file add_dim.nco grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
[3620] | 249 | |
---|
| 250 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4199] | 251 | ncap2 --history --append --script 'defdim("xcell",1) ' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[4186] | 252 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4298] | 253 | ncap2 --history --append --script 'OceFrac [ycell,xcell]=OceFrac' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[5159] | 254 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4298] | 255 | ncap2 --history --append --script 'OceMask [ycell,xcell]=OceMask' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[5159] | 256 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4298] | 257 | ncap2 --history --append --script 'Oce2AtmMask[ycell,xcell]=Oce2AtmMask' masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[3620] | 258 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
[4199] | 259 | ncap2 --history --append --script 'defdim("xcell",1) ; aire[ycell,xcell]=aire ; ' areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
[3901] | 260 | rm -f grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc |
---|
[3620] | 261 | fi |
---|
[4186] | 262 | |
---|
[3620] | 263 | # |
---|
[4172] | 264 | echo ${Titre}"Some changes specific to LMDZ lon/lat grid"${Norm} |
---|
[3620] | 265 | # ---------------------------------------------------------------------------- |
---|
| 266 | if [[ ${atm} = lmd* ]] ; then |
---|
[4172] | 267 | echo ${Titre}"Spreads lon and lat to get 2D fields"${Norm} |
---|
[3620] | 268 | # ----------------------------------------------------------------------- |
---|
| 269 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
[4298] | 270 | ncap2 --history --append --script "alon[y,x]=alon; alat[y,x]=alat" grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
[3901] | 271 | rm -f grids_${CplModel}_tmp.nc |
---|
[3620] | 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 | |
---|
[4172] | 282 | echo ${Titre}"Generates cell corners"${Norm} |
---|
[3620] | 283 | # ----------------------------------------------------------------------- |
---|
| 284 | cat <<EOF > add_bounds.nco |
---|
| 285 | defdim ("nvertex_lmd", 4) ; |
---|
| 286 | *delta_x = alon(0,1) - alon(0,0) ; |
---|
| 287 | *delta_y = alat(1,0) - alat(0,0) ; |
---|
| 288 | // |
---|
[4298] | 289 | bounds_lon[nvertex_lmd,y,x] = 0.0 ; |
---|
| 290 | bounds_lat[nvertex_lmd,y,x] = 0.0 ; |
---|
[3620] | 291 | // |
---|
| 292 | bounds_lon (0,:,:) = alon + delta_x*0.5 ; |
---|
| 293 | bounds_lat (0,:,:) = alat + delta_y*0.5 ; |
---|
| 294 | bounds_lon (1,:,:) = alon + delta_x*0.5 ; |
---|
| 295 | bounds_lat (1,:,:) = alat - delta_y*0.5 ; |
---|
| 296 | bounds_lon (2,:,:) = alon - delta_x*0.5 ; |
---|
| 297 | bounds_lat (2,:,:) = alat - delta_y*0.5 ; |
---|
| 298 | bounds_lon (3,:,:) = alon - delta_x*0.5 ; |
---|
| 299 | bounds_lat (3,:,:) = alat + delta_y*0.5 ; |
---|
| 300 | // |
---|
| 301 | where (bounds_lat > 90.0 ) bounds_lat = 90.0 ;; |
---|
| 302 | where (bounds_lat < -90.0 ) bounds_lat = -90.0 ;; |
---|
| 303 | // |
---|
| 304 | EOF |
---|
| 305 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
[4199] | 306 | ncap2 --history --script-file add_bounds.nco -O grids_${CplModel}_tmp.nc grids_${CplModel}.nc |
---|
[3901] | 307 | rm grids_${CplModel}_tmp.nc |
---|
[3620] | 308 | fi |
---|
| 309 | |
---|
| 310 | # |
---|
[4186] | 311 | |
---|
[4172] | 312 | echo ${Titre}"Generates grid o${atm}, 'o' meaning 'one'"${Norm} |
---|
| 313 | # same as t${atm} grid, with surfaces set to 1 |
---|
[3686] | 314 | # and mask to 0 (ocean everywhere, to compute integral over the whole grid)) |
---|
[3620] | 315 | # This grid is used when field are quantities instead of fluxes (i.e river flow) |
---|
| 316 | # ---------------------------------------------------------------------------- |
---|
| 317 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
[4199] | 318 | 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] | 319 | |
---|
| 320 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
[4199] | 321 | ncap2 --history --script "o${atm}_aire=aire*0.0d+1.0d ; " areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
[3620] | 322 | |
---|
| 323 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4298] | 324 | ncap2 --history --script "o${atm}_mask=int(Oce2AtmMask)*0+0 ; " masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[3620] | 325 | |
---|
[3901] | 326 | rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc |
---|
| 327 | |
---|
[4186] | 328 | |
---|
[4199] | 329 | echo ${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 | # ---------------------------------------------------------------------------- |
---|
| 333 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
| 334 | 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 |
---|
| 335 | |
---|
| 336 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
| 337 | ncap2 --history --script "c${atm}_aire=aire" areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
| 338 | |
---|
| 339 | mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc |
---|
[4298] | 340 | ncap2 --history --script "c${atm}_mask=int(Oce2AtmMask)*0+0 ; " masks_${CplModel}_tmp.nc masks_${CplModel}.nc |
---|
[4199] | 341 | |
---|
| 342 | rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc |
---|
| 343 | |
---|
[4186] | 344 | echo ${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 | # -------------------------------------------------------------------------------------------------------- |
---|
| 349 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
[4199] | 350 | 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] | 351 | |
---|
| 352 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
[4199] | 353 | ncap2 --history --script "area_grid_O=area_grid_T*0.0d+1.0d;" areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
[4186] | 354 | |
---|
[4199] | 355 | ncks -C --history --overwrite -v maskutil_T ${OCE}_coordinates_mask.nc maskutil_T.nc |
---|
| 356 | ncap2 --history --append --script "mask_O=maskutil_T; " maskutil_T.nc masks_${CplModel}.nc |
---|
[4186] | 357 | |
---|
| 358 | rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc |
---|
| 359 | |
---|
| 360 | |
---|
| 361 | echo ${Titre}"Creates OCEAN C grid : redundant points removed to compute proper integrals"${Norm} |
---|
| 362 | # -------------------------------------------------------------------------------------------------------- |
---|
| 363 | |
---|
| 364 | mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc |
---|
[4199] | 365 | 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] | 366 | |
---|
| 367 | mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc |
---|
[4199] | 368 | ncap2 --history --script "area_grid_C=area_grid_T ; " areas_${CplModel}_tmp.nc areas_${CplModel}.nc |
---|
[4186] | 369 | |
---|
[4199] | 370 | ncap2 --history --append --script "mask_C=maskutil_T; " maskutil_T.nc masks_${CplModel}.nc |
---|
[4186] | 371 | |
---|
[4199] | 372 | rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc maskutil_T.nc |
---|
[4186] | 373 | |
---|
[3620] | 374 | # |
---|
[4172] | 375 | echo ${Titre}"Final renaming"${Norm} |
---|
[3620] | 376 | # ---------------------------------------------------------------------------- |
---|
[4186] | 377 | for OCEGRID in T U V O C |
---|
[3620] | 378 | do |
---|
| 379 | ocegrid=${OCEGRID~} # To lowercase |
---|
[3686] | 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 |
---|
[3620] | 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 |
---|
| 392 | done |
---|
| 393 | |
---|
[3686] | 394 | ncrename --history --variable alon,t${atm}.lon grids_${CplModel}.nc |
---|
| 395 | ncrename --history --variable alat,t${atm}.lat grids_${CplModel}.nc |
---|
[4298] | 396 | ncrename --history --variable Oce2AtmMask,t${atm}.msk masks_${CplModel}.nc |
---|
[3686] | 397 | ncrename --history --variable aire,t${atm}.srf areas_${CplModel}.nc |
---|
| 398 | ncrename --history --variable bounds_lon,t${atm}.clo grids_${CplModel}.nc |
---|
| 399 | ncrename --history --variable bounds_lat,t${atm}.cla grids_${CplModel}.nc |
---|
[3620] | 400 | |
---|
[4199] | 401 | for ATMGRID in O C ; do |
---|
[4186] | 402 | atmgrid=${ATMGRID~} # To lowercase |
---|
[4199] | 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 |
---|
| 409 | done |
---|
| 410 | |
---|
| 411 | for ATMGRID in T O C ; do |
---|
| 412 | atmgrid=${ATMGRID~} # To lowercase |
---|
[3620] | 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" \ |
---|
[3686] | 416 | --attribute units,${atmgrid}${atm}.clo,o,c,"degrees_east" \ |
---|
[3620] | 417 | --attribute units,${atmgrid}${atm}.cla,o,c,"degrees_north" grids_${CplModel}.nc |
---|
| 418 | done |
---|
| 419 | |
---|
[4259] | 420 | |
---|
| 421 | echo ${Titre}"Add time axis and coordinates information"${Norm} |
---|
| 422 | # (needed if files need to be read by XIOS) ??? |
---|
| 423 | ## =========================================================================== |
---|
| 424 | ncap2 --overwrite --history --script 'defdim("time_counter",1) ;' ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
| 425 | |
---|
| 426 | if [[ ${atm} = ico ]] ; then |
---|
| 427 | cat <<EOF > add_time.nco |
---|
[4298] | 428 | OceFrac [time_counter,cell] = OceFrac [cell] ; |
---|
| 429 | OceMask [time_counter,cell] = OceMask [cell] ; |
---|
| 430 | Oce2AtmMask [time_counter,cell] = Oce2AtmMask [cell] ; |
---|
[4259] | 431 | EOF |
---|
| 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 |
---|
| 438 | fi |
---|
| 439 | |
---|
| 440 | if [[ ${atm} = lmd ]] ; then |
---|
| 441 | cat <<EOF > add_time.nco |
---|
[4298] | 442 | OceFrac [time_counter,y,x] = OceFrac [y,x] ; |
---|
| 443 | OceMask [time_counter,y,x] = OceMask [y,x] ; |
---|
| 444 | Oce2AtmMask [time_counter,y,x] = Oce2AtmMask [y,x] ; |
---|
[4259] | 445 | EOF |
---|
| 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" \ |
---|
[4298] | 453 | -a coordinates,Oce2AtmMask,m,c,"time_counter lat lon" \ |
---|
[4259] | 454 | -a coordinates,aire,m,c,"lat lon" \ |
---|
| 455 | ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 456 | fi |
---|
| 457 | ncks --alphabetize --history --overwrite --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}_time.nc tmp_${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
| 458 | mv tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ${ATM}_grid_maskFrom_${OCE}_time.nc |
---|
[3620] | 459 | ## |
---|
[4172] | 460 | echo ${Titre}"Add some useful information in NetCDF headers"${Norm} |
---|
[3620] | 461 | ## =========================================================================== |
---|
| 462 | NCO=$(ncks --version |& tail -1|sed 's/ncks //') |
---|
| 463 | for 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}" \ |
---|
[3718] | 478 | --attribute name,global,o,c,"${type}_${CplModel}.nc" \ |
---|
[3620] | 479 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
| 480 | --attribute description,global,o,c,"Fields needed by OASIS-MCT" \ |
---|
[3718] | 481 | --attribute title,global,o,c,"${type}_${CplModel}.nc" \ |
---|
[3620] | 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)" \ |
---|
[3718] | 488 | --attribute SVN_Author,global,o,c,"$Author$" \ |
---|
| 489 | --attribute SVN_Date,global,o,c,"$Date$" \ |
---|
[3665] | 490 | --attribute SVN_Revision,global,o,c,"$Revision$" \ |
---|
[3718] | 491 | --attribute SVN_Id,global,o,c,"$Id$" \ |
---|
| 492 | --attribute SVN_HeardURL,global,o,c,"$HeadURL $" \ |
---|
[3620] | 493 | ${type}_${CplModel}.nc |
---|
| 494 | done |
---|
| 495 | |
---|
| 496 | |
---|
| 497 | exit |
---|
| 498 | # |
---|
[4172] | 499 | echo ${Titre}"Name of the dimensions ?"${Norm} |
---|
[3620] | 500 | # ---------------------------------------------------------------------------- |
---|
[3913] | 501 | for OCEGRID in T U V ; do |
---|
[3620] | 502 | ocegrid=${OCEGRID~} # Downcase name of grids |
---|
[3686] | 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 |
---|
[3620] | 506 | done |
---|
| 507 | |
---|
| 508 | ## =========================================================================== |
---|
[4186] | 509 | echo ${Titre}"Exit from CreateOasisGrids "${Norm} |
---|
[4172] | 510 | |
---|
| 511 | ## =========================================================================== |
---|
[3620] | 512 | ## |
---|
[4172] | 513 | echo ${Titre}" That's all folk's !!! "${Norm} |
---|
[3620] | 514 | ## |
---|
| 515 | ## =========================================================================== |
---|