[3707] | 1 | #!/bin/bash |
---|
| 2 | ### =========================================================================== |
---|
| 3 | ### |
---|
| 4 | ### Creates initial state for coupler, atmosphere side |
---|
| 5 | ### Takes state from atmospheric hist file |
---|
| 6 | ### |
---|
| 7 | ### =========================================================================== |
---|
| 8 | ## |
---|
| 9 | ## Warning, to install, configure, run, use any of Olivier Marti's |
---|
| 10 | ## software or to read the associated documentation you'll need at least |
---|
| 11 | ## one (1) brain in a reasonably working order. Lack of this implement |
---|
| 12 | ## will void any warranties (either express or implied). |
---|
| 13 | ## O. Marti assumes no responsability for errors, omissions, |
---|
| 14 | ## data loss, or any other consequences caused directly or indirectly by |
---|
| 15 | ## the usage of his software by incorrectly or partially configured |
---|
| 16 | ## personal. |
---|
| 17 | ## |
---|
| 18 | ### |
---|
| 19 | ### Documentation : https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX |
---|
| 20 | ### |
---|
| 21 | ## SVN information |
---|
| 22 | # $Author$ |
---|
| 23 | # $Date$ |
---|
| 24 | # $Revision$ |
---|
| 25 | # $Id$ |
---|
| 26 | # $HeadURL$ |
---|
| 27 | |
---|
| 28 | # Usage exemples : |
---|
| 29 | # CreateRestartAtm4Oasis.bash --oce ORCA2.3 /ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/ATM/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_histmth.nc |
---|
| 30 | # CreateRestartAtm4Oasis.bash --oce ORCA2.3 /ccc/work/cont003/gencmip6/bedidil/SAVE8_ORCA2/STORE1/dynamico_grid.nc |
---|
| 31 | # CreateRestartAtm4Oasis.bash --oce ORCA2.3 /ccc/work/cont003/gencmip6/bedidil/SAVE9_ORCA2_DYN30_1MO/STORE1/histmth.nc |
---|
| 32 | |
---|
| 33 | ## =========================================================================== |
---|
| 34 | ## |
---|
| 35 | ## You should not change anything below this line .... |
---|
| 36 | ## |
---|
| 37 | ## =========================================================================== |
---|
| 38 | |
---|
| 39 | ## |
---|
| 40 | ## Command line parameters |
---|
| 41 | ## =========================================================================== |
---|
| 42 | # Default values |
---|
| 43 | Comment="Preliminary attempt - Do not trust !" |
---|
| 44 | OCE="Unknown" |
---|
| 45 | |
---|
| 46 | # |
---|
| 47 | # Defines computer |
---|
| 48 | # ================ |
---|
| 49 | if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi |
---|
| 50 | if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi |
---|
| 51 | |
---|
| 52 | case ${arch} in |
---|
| 53 | ( curie | irene ) |
---|
| 54 | set +vx |
---|
| 55 | module unload cdo nco ferret |
---|
| 56 | module unload netcdf hdf5 |
---|
| 57 | module load python # /2.7.12 |
---|
| 58 | module load netcdf/4.3.3.1_hdf5_parallel # Version for XIOS |
---|
| 59 | module load nco |
---|
| 60 | R_IN=$(ccc_home -u igcmg --cccwork)/IGCM |
---|
| 61 | TMPDIR=${SCRATCHDIR}/TMP |
---|
| 62 | SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}} |
---|
| 63 | ;; |
---|
| 64 | ( * ) |
---|
| 65 | exit -1 |
---|
| 66 | ;; |
---|
| 67 | esac |
---|
| 68 | set -o verbose |
---|
| 69 | set -o xtrace |
---|
| 70 | set -e |
---|
| 71 | |
---|
| 72 | while [[ ${1} = -* ]] ; do |
---|
| 73 | case ${1} in |
---|
| 74 | ( -- ) shift ; break ;; |
---|
| 75 | ( -o | --oce ) shift ; OCE=${1} ;; # Just needed to add information in the file and file name |
---|
| 76 | ( -c | --comment ) shift ; Comment=${1} ;; # Just needed to add information in the file |
---|
| 77 | ( -v | --verbose ) set -o verbose ;; |
---|
| 78 | ( -x | --xtrace ) set -o xtrace ;; |
---|
| 79 | ( -xv | -vx ) set -o xtrace verbose ;; |
---|
| 80 | ( -e ) set -e ;; |
---|
| 81 | ( -V | --noverbose ) set +o verbose ;; |
---|
| 82 | ( -X | --noxtrace ) set +o xtrace ;; |
---|
| 83 | ( -XV | -VX ) set +o xtrace verbose ;; |
---|
| 84 | ( -E ) set +e ;; |
---|
| 85 | ( -* ) echo ${Bold}"Unknown option : ${1}"${Norm} ; return 1 ;; |
---|
| 86 | esac |
---|
| 87 | shift |
---|
| 88 | done |
---|
| 89 | |
---|
| 90 | #AtmFile=${1:-/ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/ATM/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_histmth.nc} |
---|
| 91 | #AtmFile=${1:-/ccc/work/cont003/gencmip6/bedidil/SAVE8_ORCA2/STORE1/dynamico_grid.nc} |
---|
| 92 | AtmFile=${1:-/ccc/work/cont003/gencmip6/bedidil/SAVE9_ORCA2_DYN30_1MO/STORE1/histmth.nc} |
---|
| 93 | |
---|
| 94 | # |
---|
| 95 | # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits |
---|
| 96 | # --------------------------------------------------------------------------- |
---|
| 97 | FL_FMT=64bit |
---|
| 98 | |
---|
| 99 | ## |
---|
| 100 | ## Extract variables |
---|
| 101 | ## =========================================================================== |
---|
| 102 | ncks --overwrite --fl_fmt=${FL_FMT} --history --dimension time_counter,0,0 --variable lon,lat,sols,soll,fract_oce,fract_sic,precip,snow,evap_sic,evap_oce,wind10m,taux_oce,tauy_oce,taux_sic,tauy_sic ${AtmFile} flxat_fields.nc |
---|
| 103 | ncwa --overwrite --fl_fmt=${FL_FMT} --history --average time_counter flxat_fields.nc flxat_fields_notime.nc # remove time dimension |
---|
| 104 | ncatted --history --attribute history,global,d,c,"" flxat_fields_notime.nc # cleaning of history attributes |
---|
| 105 | |
---|
| 106 | ## |
---|
| 107 | ## Determines if the file is unstructured (Dynamico) or lon/lat (LMDZ) |
---|
| 108 | ## Set atmosphere name |
---|
| 109 | ## =========================================================================== |
---|
| 110 | Count=$(ncdump -h flxat_fields_notime.nc | grep nvertex | wc -l) |
---|
| 111 | if [[ ${Count} -gt 0 ]] ; then |
---|
| 112 | IsUnstructured=yes |
---|
| 113 | dim_cell=$(ncdump -h flxat_fields_notime.nc |& grep "cell *=" | awk '{print $3}' ) # Get nominal DYNAMICO resolution (nbp parameter) |
---|
| 114 | ico_nbp=$( echo "sqrt(($dim_cell-2)/10)+1" | bc -l | sed 's/\..*//' ) |
---|
| 115 | ATM=ICO${ico_nbp} |
---|
| 116 | ncrename --history --dimension cell,y flxat_fields_notime.nc |
---|
| 117 | cat <<EOF > add_dim.nco |
---|
| 118 | defdim("x",1) ; |
---|
| 119 | lon [y,x] = lon ; |
---|
| 120 | lat [y,x] = lat ; |
---|
| 121 | sols [y,x] = sols ; |
---|
| 122 | soll [y,x] = soll ; |
---|
| 123 | fract_oce[y,x] = fract_oce ; |
---|
| 124 | fract_sic[y,x] = fract_sic ; |
---|
| 125 | precip [y,x] = precip ; |
---|
| 126 | snow [y,x] = snow ; |
---|
| 127 | evap_sic [y,x] = evap_sic ; |
---|
| 128 | evap_oce [y,x] = evap_oce ; |
---|
| 129 | wind10m [y,x] = wind10m ; |
---|
| 130 | taux_oce [y,x] = taux_oce ; |
---|
| 131 | tauy_oce [y,x] = tauy_oce ; |
---|
| 132 | taux_sic [y,x] = taux_sic ; |
---|
| 133 | tauy_sic [y,x] = tauy_sic ; |
---|
| 134 | EOF |
---|
| 135 | ncap2 --history --overwrite --fl_fmt=${FL_FMT} --script-file add_dim.nco flxat_fields_notime.nc tmp_flxat_fields_notime.nc |
---|
| 136 | mv tmp_flxat_fields_notime.nc flxat_fields_notime.nc |
---|
| 137 | |
---|
| 138 | cat<<EOF > lonlat2xyz.nco |
---|
| 139 | // Value at North Pole for DYNAMICO grid |
---|
| 140 | where ( lat(:,:) >= 90.0d ) COTAUXXU = double(-tau_y) ; |
---|
| 141 | where ( lat(:,:) >= 90.0d ) COTAUYYU = double( tau_x) ; |
---|
| 142 | // Value at South Pole for DYNAMICO grid ? |
---|
| 143 | EOF |
---|
| 144 | else |
---|
| 145 | # lat/lon |
---|
| 146 | IsUnstructured=no |
---|
| 147 | dim_lat=$(ncdump -h flxat_fields_notime.nc | grep "lat *=" | awk '{print $3}' ) |
---|
| 148 | dim_lon=$(ncdump -h flxat_fields_notime.nc | grep "lon *=" | awk '{print $3}' ) |
---|
| 149 | ncrename --history --dimension lon,x flxat_fields_notime.nc |
---|
| 150 | ncrename --history --dimension lat,y flxat_fields_notime.nc |
---|
| 151 | cat <<EOF > add_dim.nco |
---|
| 152 | lon[y,x] = lon ; |
---|
| 153 | lat[y,x] = lat ; |
---|
| 154 | EOF |
---|
| 155 | ncap2 --history --overwrite --fl_fmt=${FL_FMT} --script-file add_dim.nco flxat_fields_notime.nc tmp_flxat_fields_notime.nc |
---|
| 156 | mv tmp_flxat_fields_notime.nc flxat_fields_notime.nc |
---|
| 157 | (( dim_lat = dim_lat - 1 )) |
---|
| 158 | #ATM=lmdz${dim_lon}x${dim_lat} |
---|
| 159 | ATM=LMD${dim_lon}${dim_lat} |
---|
| 160 | (( n_lat = dim_lat-1 )) |
---|
| 161 | cat<<EOF > lonlat2xyz.nco |
---|
| 162 | // Value at North Pole for LMDZ lon/lat grid |
---|
| 163 | COTAUXXU(0,:) = double( -tau_x (0, 0) ) ; |
---|
| 164 | COTAUYYU(0,:) = double( -tau_y (0, 0) ) ; |
---|
| 165 | COTAUZZU(0,:) = 0.0d ; |
---|
| 166 | // Value at south Pole for LMDZ lon/lat grid ? |
---|
| 167 | COTAUXXU(${n_lat},:) = double( -tau_x (${n_lat}, 0) ) ; |
---|
| 168 | COTAUYYU(${n_lat},:) = double( -tau_y (${n_lat}, 0) ) ; |
---|
| 169 | COTAUZZU(${n_lat},:) = 0.0d ; |
---|
| 170 | EOF |
---|
| 171 | |
---|
| 172 | fi |
---|
| 173 | |
---|
| 174 | echo "Version atmosphere : " ${ATM} |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | ## |
---|
| 178 | ## Creates flxat file |
---|
| 179 | ## =========================================================================== |
---|
| 180 | |
---|
| 181 | cat <<EOF > create_flxat.nco |
---|
| 182 | // |
---|
| 183 | *fract_oce_plus_sic = double(fract_oce + fract_sic) ; // ocean fraction |
---|
| 184 | *fract_oce_norm[y,x] = 0.0d ; fract_sic_norm[y,x] = 0.0d ; |
---|
| 185 | where (fract_oce_plus_sic > 0.0d ) *fract_oce_norm = double(fract_oce)/fract_oce_plus_sic ; // free ocean vs. total ocen fraction |
---|
| 186 | where (fract_oce_plus_sic > 0.0d ) *fract_sic_norm = double(fract_sic)/fract_oce_plus_sic ; // sea ice vs. total ocean fraction |
---|
| 187 | // |
---|
| 188 | COTOTRAI[y,x] = double(precip-snow) ; // Liquid precip |
---|
| 189 | COTOTSNO[y,x] = double(snow) ; // Solid precipitation |
---|
| 190 | COTOTEVA[y,x] = double(evap_oce*fract_oce_norm + evap_sic*fract_sic_norm) ; |
---|
| 191 | COICEVAP[y,x] = double(evap_sic(:,:)) ; // Evaporation on sea ice |
---|
| 192 | COQSRMIX[y,x] = double(sols(:,:)) ; // Heat flux short wave |
---|
| 193 | COQNSMIX[y,x] = double(soll(:,:)) ; // Heat flux minus short wave |
---|
| 194 | COSHFICE[y,x] = double(sols(:,:)) ; // Heat flux short wave over sea ice |
---|
| 195 | CONSFICE[y,x] = double(soll(:,:)) ; // Heat flux minus short wave over sea ice |
---|
| 196 | CODFLXDT[y,x] = -20.0d ; // W/m2 - dQ/dt |
---|
| 197 | COCALVIN[y,x] = 0.0d ; // Calving of icebergs, solid |
---|
| 198 | COLIQRUN[y,x] = 0.0d ; // River run-off , liquid |
---|
| 199 | COWINDSP[y,x] = double( wind10m(:,:) ) ; // Wind speed at 10m high |
---|
| 200 | COTAUMOD[y,x] = 0.0d ; // Wind stress modulus |
---|
| 201 | // Wind stress |
---|
| 202 | *tau_x[y,x] = double(taux_oce*fract_oce_norm + taux_sic*fract_sic_norm) ; |
---|
| 203 | *tau_y[y,x] = double(tauy_oce*fract_oce_norm + tauy_sic*fract_sic_norm) ; |
---|
| 204 | COTAUMOD[y,x] = sqrt ( double(tau_x*tau_x + tau_y*tau_y) ) ; |
---|
| 205 | // Wind stress, from east/north components to geocentric |
---|
| 206 | *rpi = acos (-1.0d) ; *rad = rpi / 180.0d ; |
---|
| 207 | COTAUXXU[y,x] = double( -tau_x(:,:) * sin(rad * lon(:,:)) - tau_y(:,:) * sin(rad * lat(:,:)) * cos(rad * lon(:,:)) ); |
---|
| 208 | COTAUYYU[y,x] = double( tau_x(:,:) * cos(rad * lon(:,:)) - tau_y(:,:) * sin(rad * lat(:,:)) * sin(rad * lon(:,:)) ); |
---|
| 209 | COTAUZZU[y,x] = double( tau_y(:,:) * cos(rad * lat(:,:)) ) ; |
---|
| 210 | // Value at North Pole |
---|
| 211 | #include "lonlat2xyz.nco" |
---|
| 212 | // |
---|
| 213 | COTAUXXV[y,x] = COTAUXXU(:,:) ; |
---|
| 214 | COTAUYYV[y,x] = COTAUYYU(:,:) ; |
---|
| 215 | COTAUZZV[y,x] = COTAUZZU(:,:) ; |
---|
| 216 | // |
---|
| 217 | EOF |
---|
| 218 | ncap2 --overwrite --fl_fmt=${FL_FMT} --history --script-file create_flxat.nco flxat_fields_notime.nc tmp_flxat.nc |
---|
| 219 | |
---|
| 220 | ncks --fl_fmt=${FL_FMT} --overwrite --history --variable lon,lat tmp_flxat.nc flxat.nc |
---|
| 221 | [[ ${IsUnstructured} = yes ]] && ncks --fl_fmt=${FL_FMT} --history --append --variable bounds_lon,bounds_lat tmp_flxat.nc flxat.nc |
---|
| 222 | ncks --fl_fmt=${FL_FMT} --append --history --variable COTAUXXU,COTAUYYU,COTAUZZU,COTAUXXV,COTAUYYV,COTAUZZV,COTOTRAI,COTOTSNO,COTOTEVA,COICEVAP,COQSRMIX,COQNSMIX,COSHFICE,CONSFICE,CODFLXDT,COCALVIN,COLIQRUN,COWINDSP,COTAUMOD tmp_flxat.nc flxat.nc |
---|
| 223 | |
---|
| 224 | ## |
---|
| 225 | ## Add some information in file headers |
---|
| 226 | ## =========================================================================== |
---|
| 227 | |
---|
| 228 | UUID=$(uuid) |
---|
| 229 | NCO="$(ncks --version |& tail -1|sed 's/ncks //')" |
---|
| 230 | ncatted --history \ |
---|
| 231 | --attribute nco_openmp_thread_number,global,d,, \ |
---|
| 232 | --attribute source,global,o,c,"IPSL Earth system model" \ |
---|
| 233 | --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center" \ |
---|
| 234 | --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr" \ |
---|
| 235 | --attribute Model,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr" \ |
---|
| 236 | --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu" \ |
---|
| 237 | --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}')" \ |
---|
| 238 | --attribute originalFiles,global,o,c,"${AtmFile}" \ |
---|
| 239 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
| 240 | --attribute description,global,o,c,"Fields needed by OASIS-MCT" \ |
---|
| 241 | --attribute timeStamp,global,o,c,"$(date)" \ |
---|
| 242 | --attribute Program,global,o,c,"Generated by ${0}" \ |
---|
| 243 | --attribute uuid,global,o,c,"${UUID}" \ |
---|
| 244 | --attribute HOSTNAME,global,o,c,"$(hostname)" \ |
---|
| 245 | --attribute LOGNAME,global,o,c,"$(whoami)" \ |
---|
| 246 | --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \ |
---|
| 247 | --attribute OS,global,o,c,"$(uname -o)" \ |
---|
| 248 | --attribute release,global,o,c,"$(uname -r)" \ |
---|
| 249 | --attribute hardware,global,o,c,"$(uname -i)" \ |
---|
| 250 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
| 251 | --attribute Comment,global,o,c,"${Comment}" \ |
---|
| 252 | --attribute Comment,global,o,c,"Preliminary attempt - Do not trust !" \ |
---|
| 253 | --attribute SVN_Author,global,o,c,"$Author$" \ |
---|
| 254 | --attribute SVN_Date,global,o,c,"$Date$" \ |
---|
| 255 | --attribute SVN_Revision,global,o,c,"$Revision$" \ |
---|
| 256 | --attribute SVN_Id,global,o,c,"$Id$" \ |
---|
| 257 | flxat.nc |
---|
| 258 | |
---|
| 259 | |
---|
| 260 | ## |
---|
| 261 | ## Creates other files |
---|
| 262 | ## =========================================================================== |
---|
| 263 | mv flxat.nc flxat_${ATM}_maskFrom_${OCE}.nc |
---|
| 264 | ncks --history --variable COCALVIN flxat_${ATM}_maskFrom_${OCE}.nc icbrg_${ATM}_maskFrom_${OCE}.nc |
---|
| 265 | ncks --history --variable COCALVIN flxat_${ATM}_maskFrom_${OCE}.nc icshf_${ATM}_maskFrom_${OCE}.nc |
---|
| 266 | |
---|
| 267 | ## |
---|
| 268 | ## Cleaning |
---|
| 269 | ## =========================================================================== |
---|
| 270 | rm -f flxat_fields.nc flxat_fields_notime.nc tmp_flxat.nc |
---|
| 271 | |
---|
| 272 | ## =========================================================================== |
---|
| 273 | ## |
---|
| 274 | ## That's all folk's !!! |
---|
| 275 | ## |
---|
| 276 | ## =========================================================================== |
---|