[3620] | 1 | #!/bin/bash |
---|
| 2 | #MSUB -r WeightsMask # nom de la requete |
---|
| 3 | #MSUB -o Out_WeightsMask # nom du fichier de sortie |
---|
| 4 | #MSUB -e Out_WeightsMask # nom du fichier de sortie |
---|
| 5 | #MSUB -eo |
---|
| 6 | #MSUB -n 4 # Reservation des processeurs pour le job |
---|
| 7 | #MSUB -T 1800 # Limite temps (en secondes) |
---|
| 8 | #MSUB -q standard |
---|
| 9 | #MSUB -Q test |
---|
| 10 | #MSUB -p devcmip6 |
---|
| 11 | |
---|
| 12 | ### =========================================================================== |
---|
| 13 | ### |
---|
| 14 | ### Creates interpolation weights between ORCA and atmospher grids. |
---|
| 15 | ### Interpolates ORCA mask to atmosphere grid. |
---|
| 16 | ### Weight files are at OASIS-MCT format. |
---|
| 17 | ### |
---|
| 18 | ### Atmosphere grid may be lon/lat LMDZ or DYNAMICO icosahedron |
---|
[3627] | 19 | ### |
---|
| 20 | ### Documentation : https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX |
---|
[3620] | 21 | ### =========================================================================== |
---|
| 22 | ## |
---|
| 23 | ## Warning, to install, configure, run, use any of Olivier Marti's |
---|
| 24 | ## software or to read the associated documentation you'll need at least |
---|
| 25 | ## one (1) brain in a reasonably working order. Lack of this implement |
---|
| 26 | ## will void any warranties (either express or implied). |
---|
| 27 | ## O. Marti assumes no responsability for errors, omissions, |
---|
| 28 | ## data loss, or any other consequences caused directly or indirectly by |
---|
| 29 | ## the usage of his software by incorrectly or partially configured |
---|
| 30 | ## personal. |
---|
| 31 | ## |
---|
[3623] | 32 | ## SVN information |
---|
[3626] | 33 | # $Author: omamce $ |
---|
| 34 | # $Date: 2018-03-12 11:17:59 +0100 (Mon, 12 Mar 2018) $ |
---|
| 35 | # $Revision: 3625 $ |
---|
| 36 | # $Id: CreateWeightsMask.bash 3625 2018-03-12 10:17:59Z omamce $ |
---|
[3632] | 37 | # $HeadURL$ |
---|
[3620] | 38 | |
---|
| 39 | ## |
---|
| 40 | ## Configuration |
---|
| 41 | ## =========================================================================== |
---|
| 42 | |
---|
| 43 | # |
---|
| 44 | # Defines models |
---|
| 45 | # ============== |
---|
[3639] | 46 | #OCE=ORCA2.3 |
---|
| 47 | OCE=eORCA1.2 |
---|
[3620] | 48 | #OCE=ORCA025 |
---|
| 49 | |
---|
| 50 | ATM=ICO30 |
---|
| 51 | #ATM=ICO40 |
---|
| 52 | #ATM=ICO450 |
---|
| 53 | #ATM=LMD9695 |
---|
| 54 | #ATM=LMD144X142 |
---|
| 55 | |
---|
| 56 | # |
---|
| 57 | # Defines OCE grids to handle |
---|
| 58 | # =========================== |
---|
| 59 | ListOCEGRID="T U V" |
---|
| 60 | Listorder="1st" # " 2nd |
---|
| 61 | |
---|
| 62 | ## =========================================================================== |
---|
| 63 | ## |
---|
| 64 | ## You should not change anything below this line .... |
---|
| 65 | ## |
---|
| 66 | ## =========================================================================== |
---|
| 67 | SUBMIT_DIR=$(pwd) |
---|
| 68 | |
---|
| 69 | # |
---|
| 70 | # Defines computer |
---|
| 71 | # ================ |
---|
| 72 | if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi |
---|
| 73 | if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi |
---|
| 74 | PROGRAM=$(basename ${0}) |
---|
| 75 | |
---|
| 76 | case ${arch} in |
---|
| 77 | ( curie | irene ) |
---|
| 78 | set +vx |
---|
| 79 | module unload cdo nco ferret |
---|
| 80 | module unload netcdf hdf5 |
---|
| 81 | module load python # /2.7.12 |
---|
| 82 | module load netcdf/4.3.3.1_hdf5_parallel # Version for XIOS |
---|
| 83 | module load nco |
---|
| 84 | R_IN=$(ccc_home -u igcmg --cccwork)/IGCM |
---|
| 85 | TMPDIR=${SCRATCHDIR}/TMP |
---|
| 86 | SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}} |
---|
| 87 | PROGRAM=${BRIDGE_MSUB_REQNAME} |
---|
| 88 | ;; |
---|
| 89 | ( * ) |
---|
| 90 | exit -1 |
---|
| 91 | ;; |
---|
| 92 | esac |
---|
| 93 | |
---|
| 94 | set -x ; set -e |
---|
| 95 | |
---|
| 96 | mkdir -p ${TMPDIR}/${OCE}x${ATM} || exit 1 |
---|
| 97 | cd ${TMPDIR}/${OCE}x${ATM} || exit 1 |
---|
| 98 | rm -f * |
---|
| 99 | |
---|
| 100 | # |
---|
| 101 | # Suffixes |
---|
| 102 | # --------------------------------------------------------------------------- |
---|
| 103 | Listocegrid=${ListOCEGRID~} |
---|
| 104 | |
---|
| 105 | case ${OCE} in |
---|
| 106 | ( *ORC* ) oce=orc ; oce_domain_type=curvilinear ;; |
---|
| 107 | esac |
---|
| 108 | case ${ATM} in |
---|
| 109 | ( *dynamico* ) atm=ico ; atm_domain_type=unstructured ;; |
---|
| 110 | ( *ICO* ) atm=ico ; atm_domain_type=unstructured ;; |
---|
| 111 | ( *lmd* | *LMD* ) atm=lmd ; atm_domain_type=rectilinear ;; |
---|
| 112 | esac |
---|
| 113 | |
---|
| 114 | # |
---|
| 115 | # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits |
---|
| 116 | # --------------------------------------------------------------------------- |
---|
| 117 | FL_FMT=64bit |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | cp ${SUBMIT_DIR}/bin/interpol.exe . |
---|
| 121 | cp ${SUBMIT_DIR}/update_xml.py . |
---|
| 122 | |
---|
| 123 | ## |
---|
| 124 | ## NEMO T point towards ATM - 1st order |
---|
| 125 | ## =========================================================================== |
---|
| 126 | cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc . |
---|
[3639] | 127 | cp ${R_IN}/ATM/GRID/${ATM}_grid.nc . |
---|
[3620] | 128 | |
---|
| 129 | ln -s ${OCE}_coordinates_mask.nc oce_grid.nc |
---|
| 130 | ln -s ${ATM}_grid.nc atm_grid.nc |
---|
| 131 | |
---|
| 132 | echo ${Green}"${OCE} T toward ${ATM} - 1storder"${Norm} |
---|
| 133 | cp ${SUBMIT_DIR}/iodef_oce_to_atm.xml iodef.xml |
---|
| 134 | |
---|
| 135 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' -k name -v maskutil_T |
---|
| 136 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
| 137 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
| 138 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name -v maskutil_T |
---|
| 139 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_t${oce}_to_t${atm}_1storder |
---|
| 140 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${OCE} mask interpolated to ${ATM}" |
---|
| 141 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${oce_domain_type} |
---|
| 142 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${atm_domain_type} |
---|
| 143 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t 1 |
---|
| 144 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
| 145 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
| 146 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_t${oce}_to_t${atm}_1storder.nc |
---|
| 147 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1 |
---|
| 148 | |
---|
| 149 | cp iodef.xml iodef_t${oce}_to_t${atm}_1storder.xml |
---|
| 150 | |
---|
| 151 | time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=no |
---|
| 152 | |
---|
| 153 | ## |
---|
| 154 | ## Correct spurious values (extremes) |
---|
| 155 | ## =========================================================================== |
---|
| 156 | cat <<EOF > correction_masque.nco |
---|
| 157 | where (OceFrac < 0.00001 ) OceFrac=OceFrac.get_miss() ; |
---|
| 158 | where (OceFrac > 0.99999 ) OceFrac=1.0 ; |
---|
| 159 | OceFrac.delete_miss() ; |
---|
| 160 | // Fill masked values to land values |
---|
| 161 | where (OceFrac > 1.0 ) OceFrac=0.0 ; |
---|
| 162 | where (OceFrac < 0.0 ) OceFrac=0.0 ; |
---|
| 163 | EOF |
---|
[3639] | 164 | ncap2 --history --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_1storder.nc tmp_dia_t${oce}_to_t${atm}_1storder.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder.nc dia_t${oce}_to_t${atm}_1storder.nc |
---|
| 165 | ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_1storder.nc |
---|
[3620] | 166 | |
---|
| 167 | ## |
---|
| 168 | ## Creates mask on ATM grid |
---|
| 169 | ## =========================================================================== |
---|
| 170 | cp dia_t${oce}_to_t${atm}_1storder.nc dia_t${oce}_to_t${atm}_1storder_mask.nc |
---|
[3639] | 171 | ncks --alphabetize --history --overwrite -v OceFrac dia_t${oce}_to_t${atm}_1storder_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 172 | ncks --alphabetize --history --append -v aire atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 173 | [[ ${atm} = *ico* ]] && ncks --alphabetize --history --append -v bounds_lon,bounds_lat atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
[3620] | 174 | |
---|
| 175 | cat <<EOF > creation_masque.nco |
---|
| 176 | where (OceFrac > 0.0 ) OceFrac=1 ; |
---|
| 177 | where (OceFrac <= 0.0 ) OceFrac=0 ; |
---|
| 178 | EOF |
---|
[3639] | 179 | ncap2 --history --overwrite --script-file creation_masque.nco dia_t${oce}_to_t${atm}_1storder_mask.nc tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc dia_t${oce}_to_t${atm}_1storder_mask.nc |
---|
| 180 | ncrename --history -v OceFrac,OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc |
---|
[3620] | 181 | |
---|
[3639] | 182 | ncks --alphabetize --history --append -v OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
[3620] | 183 | |
---|
| 184 | |
---|
| 185 | ## |
---|
| 186 | ## NEMO, other case, towards ATM |
---|
| 187 | ## =========================================================================== |
---|
| 188 | for order in ${Listorder} ; do |
---|
| 189 | case ${order} in |
---|
| 190 | ( 1st ) num_order=1 ;; |
---|
| 191 | ( 2nd ) num_order=2 ;; |
---|
| 192 | esac |
---|
| 193 | |
---|
| 194 | for OCEGRID in ${ListOCEGRID} ; do |
---|
| 195 | ocegrid=${OCEGRID~} |
---|
| 196 | |
---|
| 197 | if [[ !( ${order} = 1st && ${OCEGRID} = T ) ]] ; then |
---|
| 198 | |
---|
| 199 | echo ${Green}"${OCE} ${OCEGRID} toward ${ATM} - ${order}order"${Norm} |
---|
| 200 | |
---|
| 201 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' -k name -v maskutil_${OCEGRID} |
---|
| 202 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
| 203 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
| 204 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name -v maskutil_${OCEGRID} |
---|
| 205 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_${ocegrid}${oce}_to_t${atm}_${order}order |
---|
| 206 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${OCE} mask interpolated to ${ATM}" |
---|
| 207 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${oce_domain_type} |
---|
| 208 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${atm_domain_type} |
---|
| 209 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t ${num_order} |
---|
| 210 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} |
---|
| 211 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} |
---|
| 212 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v ${num_order} |
---|
| 213 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_${ocegrid}${oce}_to_t${atm}_${order}order.nc |
---|
| 214 | cp iodef.xml iodef_${ocegrid}${oce}_t${atm}_${order}order.xml |
---|
| 215 | |
---|
| 216 | time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
| 217 | fi |
---|
| 218 | |
---|
| 219 | done |
---|
| 220 | done |
---|
| 221 | |
---|
| 222 | ## |
---|
| 223 | ## ATM towards NEMO points |
---|
| 224 | ## =========================================================================== |
---|
| 225 | cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml iodef.xml |
---|
| 226 | |
---|
| 227 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} |
---|
| 228 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} |
---|
| 229 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${ATM} mask interpolated to ${OCE}" |
---|
| 230 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${atm_domain_type} |
---|
| 231 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${oce_domain_type} |
---|
| 232 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} |
---|
| 233 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} |
---|
| 234 | |
---|
| 235 | for order in ${Listorder} ; do |
---|
| 236 | case ${order} in |
---|
| 237 | ( 1st ) num_order=1 ;; |
---|
| 238 | ( 2nd ) num_order=2 ;; |
---|
| 239 | esac |
---|
| 240 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v ${num_order} |
---|
| 241 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t ${num_order} |
---|
| 242 | |
---|
| 243 | for OCEGRID in ${ListOCEGRID} ; do |
---|
| 244 | ocegrid=${OCEGRID~} |
---|
| 245 | |
---|
| 246 | echo ${Green}"${ATM} toward ${OCE} ${OCEGRID} - ${order}order"${Norm} |
---|
| 247 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]' -k name -v mask_${OCEGRID} |
---|
| 248 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="mask_dest"]' -k name -v mask_${OCEGRID} |
---|
| 249 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_t${atm}_to_${ocegrid}${oce}_${order}order |
---|
| 250 | python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_t${atm}_to_${ocegrid}${oce}_${order}order.nc |
---|
| 251 | cp iodef.xml iodef_t${atm}_to_${ocegrid}${oce}_${order}order.xml |
---|
| 252 | |
---|
| 253 | time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes |
---|
| 254 | |
---|
| 255 | done |
---|
| 256 | done |
---|
| 257 | |
---|
| 258 | ## |
---|
| 259 | ## Change all NetCDF files to NetCDF 3 format (needed for OASIS) |
---|
| 260 | ## =========================================================================== |
---|
| 261 | for InFile in *.nc ; do |
---|
| 262 | if [[ $(ncdump -k ${InFile}) = *netCDF-4* ]] ; then |
---|
| 263 | mv ${InFile} tmp_${InFile} |
---|
[3639] | 264 | ncks --alphabetize --fl_fmt=${FL_FMT} --history tmp_${InFile} ${InFile} |
---|
[3620] | 265 | fi |
---|
| 266 | done |
---|
| 267 | |
---|
| 268 | ## |
---|
| 269 | ## Add time axis and coordinates information |
---|
| 270 | ## (needed if files need to be read by XIOS) |
---|
| 271 | ## =========================================================================== |
---|
| 272 | if [[ ${atm} = ico ]] ; then |
---|
| 273 | cat <<EOF > add_time.nco |
---|
| 274 | defdim("time_counter",1) ; |
---|
| 275 | OceFrac [time_counter,cell] = OceFrac (:) ; |
---|
| 276 | OceMask [time_counter,cell] = OceMask (:) ; |
---|
| 277 | EOF |
---|
[3639] | 278 | ncap2 -O --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 279 | ncks --alphabetize -O --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 280 | ncatted --history \ |
---|
[3620] | 281 | -a coordinates,OceFrac,c,c,"time_counter cell" \ |
---|
| 282 | -a coordinates,OceMask,c,c,"time_counter cell" \ |
---|
| 283 | -a coordinates,aire,c,c,"time_counter cell" ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 284 | fi |
---|
| 285 | if [[ ${atm} = lmd ]] ; then |
---|
| 286 | cat <<EOF > add_time.nco |
---|
| 287 | defdim("time_counter",1) ; |
---|
| 288 | OceFrac [time_counter,lat,lon] = OceFrac (:,:) ; |
---|
| 289 | OceMask [time_counter,lat,lon] = OceMask (:,:) ; |
---|
| 290 | EOF |
---|
[3639] | 291 | ncap2 -O --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 292 | ncks --alphabetize -O --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 293 | ncatted --history \ |
---|
[3620] | 294 | -a coordinates,OceFrac,c,c,"time_counter lat lon" \ |
---|
| 295 | -a coordinates,OceMask,c,c,"time_counter lat lon" \ |
---|
| 296 | -a coordinates,aire,c,c,"time_counter lat lon" ${ATM}_grid_maskFrom_${OCE}.nc |
---|
| 297 | fi |
---|
| 298 | |
---|
| 299 | ## |
---|
| 300 | ## Add some information in file headers |
---|
| 301 | ## =========================================================================== |
---|
| 302 | |
---|
| 303 | UUID=$(uuid) |
---|
| 304 | NCO="$(ncks --version |& tail -1|sed 's/ncks //')" |
---|
| 305 | PYTHON_VER=$( python -i -c "import sys ; print (sys.version.split(' ')[0])" ) |
---|
| 306 | for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ; do |
---|
[3639] | 307 | ncatted --history \ |
---|
[3620] | 308 | --attribute uuid,global,d,, \ |
---|
| 309 | --attribute LongName,global,d,, \ |
---|
| 310 | --attribute nco_openmp_thread_number,global,d,, \ |
---|
| 311 | --attribute Conventions,global,o,c,"CF-1.6" \ |
---|
| 312 | --attribute source,global,o,c,"IPSL Earth system model" \ |
---|
| 313 | --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center" \ |
---|
| 314 | --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr" \ |
---|
| 315 | --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu" \ |
---|
| 316 | --attribute Atmosphere,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr" \ |
---|
| 317 | --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') " \ |
---|
| 318 | --attribute originalFiles,global,o,c,"${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc" \ |
---|
| 319 | --attribute associatedFiles,global,o,c,"grids_${OCE}x${ATM}.nc areas_${OCE}x${ATM}.nc masks_${OCE}x${ATM}.nc" \ |
---|
| 320 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
| 321 | --attribute description,global,o,c,"Fields needed by OASIS-MCT" \ |
---|
| 322 | --attribute title,global,o,c,"${InFile}.nc" \ |
---|
| 323 | --attribute Program,global,o,c,"Generated by ${PROGRAM}" \ |
---|
| 324 | --attribute timeStamp,global,o,c,"$(date)" \ |
---|
| 325 | --attribute uuid,global,o,c,"${UUID}" \ |
---|
| 326 | --attribute HOSTNAME,global,o,c,"$(hostname)" \ |
---|
| 327 | --attribute LOGNAME,global,o,c,"$(whoami)" \ |
---|
| 328 | --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \ |
---|
| 329 | --attribute Python,global,o,c,"Python version ${PYTHON_VER}" \ |
---|
| 330 | --attribute OS,global,o,c,"$(uname -o)" \ |
---|
| 331 | --attribute release,global,o,c,"$(uname -r)" \ |
---|
| 332 | --attribute hardware,global,o,c,"$(uname -i)" \ |
---|
| 333 | --attribute directory,global,o,c,"$(pwd)" \ |
---|
[3624] | 334 | --attribute description,global,o,c,"Generated with XIOS http://forge.ipsl.jussieu.fr/ioserver and MOSAIX https://forge.ipsl.jussieu.fr/igcmg/browser/TOOLS/MOSAIX" \ |
---|
[3620] | 335 | --attribute Comment,global,o,c,"Preliminary attempt - Do not trust !" \ |
---|
[3626] | 336 | --attribute SVN_Author,global,o,c,"$Author: omamce $" \ |
---|
| 337 | --attribute SVN_Date,global,o,c,"$Date: 2018-03-12 11:17:59 +0100 (Mon, 12 Mar 2018) $" \ |
---|
| 338 | --attribute SVN_Revision,global,o,c,"$Revision: 3625 $" \ |
---|
| 339 | --attribute SVN_Id,global,o,c,"$Id: CreateWeightsMask.bash 3625 2018-03-12 10:17:59Z omamce $" \ |
---|
[3620] | 340 | ${InFile} |
---|
| 341 | done |
---|
| 342 | |
---|
| 343 | |
---|
| 344 | ## |
---|
| 345 | ## Update and complete weights file to fit OASIS requested format |
---|
| 346 | ## =========================================================================== |
---|
| 347 | cat <<EOF > add_dim.nco |
---|
| 348 | defdim("num_wgts",1) ; |
---|
| 349 | weight[n_weight, num_wgts] = weight ; |
---|
| 350 | EOF |
---|
| 351 | |
---|
| 352 | for file in rmp_*${oce}_to_*${atm}_*.nc rmp_*${atm}_to_*${oce}_*.nc ; do |
---|
| 353 | mv ${file} xios_${file} |
---|
[3639] | 354 | ncap2 --fl_fmt=${FL_FMT} --history --script-file add_dim.nco xios_${file} ${file} |
---|
[3620] | 355 | |
---|
[3639] | 356 | ncrename --history --dimension n_weight,num_links ${file} |
---|
| 357 | ncrename --history --variable src_idx,src_address ${file} |
---|
| 358 | ncrename --history --variable dst_idx,dst_address ${file} |
---|
| 359 | ncrename --history --variable weight,remap_matrix ${file} |
---|
[3620] | 360 | case ${file} in |
---|
[3639] | 361 | ( *1storder.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order" ${file} ;; |
---|
| 362 | ( *2ndorder.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order" ${file} ;; |
---|
[3620] | 363 | esac |
---|
[3639] | 364 | ncatted --history --attribute conventions,global,o,c,"SCRIP" ${file} |
---|
| 365 | ncatted --history --attribute normalization,global,o,c,"none" ${file} |
---|
[3620] | 366 | |
---|
| 367 | case ${file} in |
---|
| 368 | ( rmp_*${oce}_to_t${atm}_* ) |
---|
[3639] | 369 | ncatted --history \ |
---|
[3620] | 370 | --attribute title,global,o,c,"Weights ${OCE} to ${ATM}" \ |
---|
| 371 | --attribute source_grid,global,o,c,"${oce_domain_type}" \ |
---|
| 372 | --attribute dest_grid,global,o,c,"${atm_domain_type}" \ |
---|
| 373 | ${file} |
---|
| 374 | ;; |
---|
| 375 | ( rmp_*${atm}_to_*${oce}_* ) |
---|
[3639] | 376 | ncatted --history \ |
---|
[3620] | 377 | --attribute title,global,o,c,"Weights ${ATM} to ${OCE}" \ |
---|
| 378 | --attribute source_grid,global,o,c,"${atm_domain_type}" \ |
---|
| 379 | --attribute dest_grid,global,o,c,"${oce_domain_type}" \ |
---|
| 380 | ${file} |
---|
| 381 | ;; |
---|
| 382 | esac |
---|
| 383 | done |
---|
| 384 | |
---|
| 385 | ## |
---|
[3639] | 386 | ## Add missing variables in rmp files |
---|
| 387 | ## =========================================================================== |
---|
| 388 | for OGRID in ${ListOCEGRID} ; do |
---|
| 389 | for order in ${Listorder} ; do |
---|
| 390 | ogrid=${OGRID~} |
---|
| 391 | agrid=t |
---|
| 392 | |
---|
| 393 | file_o_to_a=rmp_${ogrid}${oce}_to_${agrid}${atm}_${order}order.nc |
---|
| 394 | file_a_to_o=rmp_${agrid}${atm}_to_${ogrid}${oce}_${order}order.nc |
---|
| 395 | |
---|
| 396 | cat <<EOF >add_varoce.nco |
---|
| 397 | defdim ("src_grid_size" , \$x_grid_${OGRID}.size*\$y_grid_${OGRID}.size) ; |
---|
| 398 | defdim ("src_grid_corners", 4) ; |
---|
| 399 | defdim ("src_grid_rank" , 2) ; |
---|
| 400 | // |
---|
| 401 | src_grid_dims[src_grid_rank] = { \$y_grid_${OGRID}.size, \$x_grid_${OGRID}.size } ; |
---|
| 402 | // |
---|
| 403 | src_grid_center_lat [src_grid_size] = 0.0d ; |
---|
| 404 | src_grid_center_lon [src_grid_size] = 0.0d ; |
---|
| 405 | src_grid_center_lat (:) = nav_lat_grid_${OGRID}(:,:) ; |
---|
| 406 | src_grid_center_lon (:) = nav_lon_grid_${OGRID}(:,:) ; |
---|
| 407 | // |
---|
| 408 | src_grid_corner_lat [src_grid_size, src_grid_corners] = 0.0d ; |
---|
| 409 | src_grid_corner_lon [src_grid_size, src_grid_corners] = 0.0d ; |
---|
| 410 | src_grid_corner_lat(:,:) = bounds_lat_grid_${OGRID}(:,:,:) ; |
---|
| 411 | src_grid_corner_lon(:,:) = bounds_lon_grid_${OGRID}(:,:,:) ; |
---|
| 412 | // |
---|
| 413 | src_grid_imask [src_grid_size] = 0 ; |
---|
| 414 | src_grid_area [src_grid_size] = 0.0d ; |
---|
| 415 | src_grid_frac [src_grid_size] = 1.0d ; |
---|
| 416 | src_grid_imask (:) = 1 - mask_${OGRID}(:,:) ; |
---|
| 417 | src_grid_imask.int() ; |
---|
| 418 | src_grid_area (:) = area_grid_${OGRID}(:,:) ; |
---|
| 419 | EOF |
---|
| 420 | |
---|
| 421 | ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${file_o_to_a} |
---|
| 422 | sed --in-place "s/src_/dst_/g" add_varoce.nco |
---|
| 423 | ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${file_a_to_o} |
---|
| 424 | |
---|
| 425 | if [[ ${atm} = ico ]] ; then |
---|
| 426 | cat <<EOF >add_varatm.nco |
---|
| 427 | defdim ("dst_grid_size" , \$cell.size) ; |
---|
| 428 | defdim ("dst_grid_corners", 6) ; |
---|
| 429 | defdim ("dst_grid_rank" , 2) ; |
---|
| 430 | // |
---|
| 431 | dst_grid_dims[dst_grid_rank] = { \$cell.size, 1 } ; |
---|
| 432 | // |
---|
| 433 | dst_grid_center_lat [dst_grid_size] = 0.0d ; |
---|
| 434 | dst_grid_center_lon [dst_grid_size] = 0.0d ; |
---|
| 435 | dst_grid_center_lat (:) = lat(:) ; |
---|
| 436 | dst_grid_center_lon (:) = lon(:) ; |
---|
| 437 | // |
---|
| 438 | dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ; |
---|
| 439 | dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ; |
---|
| 440 | dst_grid_corner_lat(:,:) = bounds_lat(:,:) ; |
---|
| 441 | dst_grid_corner_lon(:,:) = bounds_lon(:,:) ; |
---|
| 442 | // |
---|
| 443 | dst_grid_imask [dst_grid_size] = 0 ; |
---|
| 444 | dst_grid_area [dst_grid_size] = 0.0d ; |
---|
| 445 | dst_grid_frac [dst_grid_size] = 1.0d ; |
---|
| 446 | dst_grid_imask (:) = 1 - OceMask(0,:) ; |
---|
| 447 | dst_grid_imask.int() ; |
---|
| 448 | dst_grid_area (:) = aire(:) ; |
---|
| 449 | EOF |
---|
| 450 | ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_o_to_a} |
---|
| 451 | sed --in-place "s/dst_/src_/g" add_varatm.nco |
---|
| 452 | ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_a_to_o} |
---|
| 453 | |
---|
| 454 | ncks --alphabetize --history --overwrite -v src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_o_to_a} rmp_tmp.nc |
---|
| 455 | mv rmp_tmp.nc ${file_o_to_a} |
---|
| 456 | ncks --alphabetize --history --overwrite -v src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_a_to_o} rmp_tmp.nc |
---|
| 457 | mv rmp_tmp.nc ${file_a_to_o} |
---|
| 458 | |
---|
| 459 | fi |
---|
| 460 | if [[ ${atm} = lmd ]] ; then |
---|
| 461 | cat <<EOF >add_varatm.nco |
---|
| 462 | defdim ("dst_grid_size" , \$lon.size*\$lat.size) ; |
---|
| 463 | defdim ("dst_grid_corners", 4) ; |
---|
| 464 | defdim ("dst_grid_rank" , 2) ; |
---|
| 465 | // |
---|
| 466 | dst_grid_dims[dst_grid_rank] = { \$lat.size, \$lon.size } ; |
---|
| 467 | // |
---|
| 468 | dst_grid_center_lat [dst_grid_size] = 0.0d ; |
---|
| 469 | dst_grid_center_lon [dst_grid_size] = 0.0d ; |
---|
| 470 | lat0lon[lat,lon] = lat(:)+0*lon(:) ; |
---|
| 471 | lon0lat[lat,lon] = lon(:)+0*lat(:) ; |
---|
| 472 | dst_grid_center_lat (:) = lat0lon(:,:) ; |
---|
| 473 | dst_grid_center_lon (:) = lon0lat(:,:) ; |
---|
| 474 | // |
---|
| 475 | //dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ; // Not available for LMDZ lon/lat grid |
---|
| 476 | //dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ; |
---|
| 477 | //dst_grid_corner_lat(:,:) = bounds_lat(:,:) ; |
---|
| 478 | //dst_grid_corner_lon(:,:) = bounds_lon(:,:) ; |
---|
| 479 | // |
---|
| 480 | dst_grid_imask [dst_grid_size] = 0 ; |
---|
| 481 | dst_grid_area [dst_grid_size] = 0.0d ; |
---|
| 482 | dst_grid_frac [dst_grid_size] = 1.0d ; |
---|
| 483 | dst_grid_imask (:) = 1 - OceMask(0,:,:) ; |
---|
| 484 | dst_grid_imask.int() ; |
---|
| 485 | dst_grid_area (:) = aire(:,:) ; |
---|
| 486 | dst_grid_frac (:) = OceFrac(0,:,:) ; |
---|
| 487 | EOF |
---|
| 488 | ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_o_to_a} |
---|
| 489 | sed --in-place "s/dst/src/g" add_varatm.nco |
---|
| 490 | ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_a_to_o} |
---|
| 491 | |
---|
| 492 | ncks --alphabetize --history --overwrite -v src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_area,dst_grid_imask ${file_o_to_a} rmp_tmp.nc |
---|
| 493 | mv rmp_tmp.nc ${file_o_to_a} |
---|
| 494 | ncks --alphabetize --history --overwrite -v src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_a_to_o} rmp_tmp.nc |
---|
| 495 | mv rmp_tmp.nc ${file_a_to_o} |
---|
| 496 | |
---|
| 497 | fi |
---|
| 498 | done |
---|
| 499 | done |
---|
| 500 | |
---|
| 501 | ## |
---|
[3620] | 502 | ## Save results |
---|
| 503 | ## =========================================================================== |
---|
| 504 | cp ${ATM}_grid_maskFrom_${OCE}.nc ${SUBMIT_DIR} |
---|
| 505 | for order in ${Listorder} |
---|
| 506 | do |
---|
| 507 | cp dia_t${oce}_to_t${atm}_${order}order.nc ${SUBMIT_DIR}/dia_t${OCE}_to_t${ATM}_${order}order.nc |
---|
| 508 | cp rmp_t${oce}_to_t${atm}_${order}order.nc ${SUBMIT_DIR}/rmp_t${OCE}_to_t${ATM}_${order}order.nc |
---|
| 509 | for grid in ${Listocegrid} ; do |
---|
| 510 | cp rmp_t${atm}_to_${grid}${oce}_${order}order.nc ${SUBMIT_DIR}/rmp_t${ATM}_to_${grid}${OCE}_${order}order.nc |
---|
| 511 | cp dia_t${atm}_to_${grid}${oce}_${order}order.nc ${SUBMIT_DIR}/dia_t${ATM}_to_${grid}${OCE}_${order}order.nc |
---|
| 512 | done |
---|
| 513 | done |
---|
| 514 | |
---|
| 515 | ## |
---|
| 516 | ## Creates and save auxiliary files for OASIS |
---|
| 517 | ## =========================================================================== |
---|
| 518 | bash ${SUBMIT_DIR}/CreateOasisGrids.bash --oce ${OCE} --atm ${ATM} |
---|
| 519 | |
---|
| 520 | cp areas_${OCE}x${ATM}.nc ${SUBMIT_DIR} |
---|
| 521 | cp grids_${OCE}x${ATM}.nc ${SUBMIT_DIR} |
---|
| 522 | cp masks_${OCE}x${ATM}.nc ${SUBMIT_DIR} |
---|
| 523 | |
---|
| 524 | |
---|
| 525 | ## =========================================================================== |
---|
| 526 | ## |
---|
| 527 | ## That's all folk's !!! |
---|
| 528 | ## |
---|
| 529 | ## =========================================================================== |
---|
| 530 | |
---|