source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 4298

Last change on this file since 4298 was 4298, checked in by omamce, 5 years ago

O.M. : corection on MOSAIX

  • add ORCA025.1 to known resolutions
  • Correct mask used to generate weigths
  • Suppress the second computation of uuid
  • OceMask? is now ocean fraction like it was in MOZAIC. OceFrac? still exists (and equals OceFrac?)
  • Add Oce2AtmMask as a 1/0 mask
  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 46.3 KB
RevLine 
[3620]1#!/bin/bash
[3719]2#MSUB -r WeightsMask        # Job name
3#MSUB -o Out_WeightsMask    # Standard output
4#MSUB -e Out_WeightsMask    # Error output
[3620]5#MSUB -eo
[4159]6#MSUB -n 16                 # Number of processors
[4186]7#MSUB -T 7200               # Time limit (seconds)
[3966]8#MSUB -q skylake
9#MSUB -p gen2212
10#MSUB -m work
[3620]11
12### ===========================================================================
13###
[3719]14### Creates interpolation weights between ORCA and atmosphere grids.
[3620]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
[3665]33#  $Author$
34#  $Date$
35#  $Revision$
36#  $Id$
[3632]37#  $HeadURL$
[4090]38#
[4298]39# export CplModel=eORCA1.2xLMD144142 ; qsub -r ${CplModel} -o Out_${CplModel} -e Out_${CplModel} CreateWeightsMask.bash
40# export CplModel=ORCA2.3xLMD9695
41# export CplModel=ORCA2.3xICO30
42# export CplModel=ORCA2.3xICO40
43# export CplModel=eORCA1.2xICO40
44# export CplModel=eORCA1.2xLMD256256
45# export CplModel=eORCA1.2xICO450
46# export CplModel=eORCA025.1xLMD256256
[4195]47#
48
[4172]49set +vx
[3901]50export Bold=$(tput bold) 
51export Unde=$(tput smul) ; export OffUnde=$(tput rmul)
52export Stou=$(tput smso) ; export OffStou=$(tput rmso)
53export Reve=$(tput rev ) 
54couleurs=( "Black" "Blue" "Green" "Cyan" "Red" "Magenta" "Yellow" "White" )
[4259]55for i in $(seq 0 7) ; do eval "export ${couleurs[$i]}=$(tput setf ${i})" ; done
[4186]56export Norm=$(tput sgr0)
[4172]57export Titre=${Bold}${Blue}
[3620]58
59##
60## Configuration
61## ===========================================================================
[4159]62set -e
[3620]63
64#
[4172]65echo ${Titre}"Defines models"${Norm}
[4199]66# ==================================
[4298]67OCE=ORCA2.3
68#OCE=eORCA1.2
69#OCE=eORCA025.1
[3620]70
[4298]71ATM=ICO30
[4195]72#ATM=ICO40
[3620]73#ATM=ICO450
[4186]74#ATM=LMD9695
[4298]75#ATM=LMD144142
[4172]76#ATM=LMD256256
[3620]77
[4199]78
79Comment="Preliminary attempt - Do not trust !"
[4298]80Version="v2"
[4199]81
[4195]82CplModel=${OCE}x${ATM}
[4298]83# If available, get model names from job name
[4195]84if [[ X${SLURM_JOB_NAME} = X*ORC* ||  X${SLURM_JOB_NAME} = X*LMD*  ||  X${SLURM_JOB_NAME} = X*ICO* ]] ; then
85    CplModel=${SLURM_JOB_NAME} ; OCE=${CplModel//x*} ; ATM=${CplModel##*x}
86fi
87
[4186]88echo ${Titre}"ATM model : ${ATM}"${Norm}
89echo ${Titre}"OCE model : ${OCE}"${Norm}
[4195]90echo ${Titre}"Cpl model : ${CplModel}"${Norm}
[4172]91
[4186]92# Runoff parameter. atmCoastWidth and oceCoastWidth in grid points, searchRadius in km
93atmCoastWidth=2 ; oceCoastWidth=2 ; searchRadius=600.0
[4298]94runOff_atmQuantity=Quantity ; runOff_oceQuantity=Surfacic
[4172]95
[4298]96[[ ${ATM} = ICO*      ]] && atmCoastWidth=0 # Parameter relevant for LMD rectilinear grid only
97[[ ${ATM} = LMD*      ]] && atmCoastWidth=2
98[[ ${OCE} = ORCA2.3   ]] && oceCoastWidth=1
99[[ ${OCE} = eORCA1.2  ]] && oceCoastWidth=3
100[[ ${OCE} = eORCA025* ]] && oceCoastWidth=1
[4186]101
102
[4153]103# Default values, used to create ocean fraction on atmospheric grid
[4186]104DefaultValues=( Direction=o2a,oceGrid=t,atmGrid=t,Order=1st,Quantity=false,Renormalize=false,useArea=false,maskSrc=true,maskDst=false,Name=OceFrac )
[3620]105
[4172]106## List of weights to build
107## ====================================================================================================================================
108#
109# Each item in CommandList describes the properties of interpolation weights to generate.
[4159]110# White spaces separate analysis. No spaces in any analysis.
111#
[4172]112# Specific commands : 'Runoff', 'Calving'
113#
[4159]114# Keywords :
[4298]115#   Direction   : o2a for ocean to atmosphere, a2o for atmosphere to ocean.
116#   Order       : 1st or 2nd.
[4159]117#   Quantity    : true if integrated quantity over a grid box, false for flux (quantity / m^2)
[4298]118#                 or intensive value (temperature, salinity, sea-ice fraction, ...).
119#   Renormalize : used when source grid is masked, to use values on non masked points only.
120#   oceGrid     : t, u or v point for NEMO C grid.
121#   atmGrid     : up to know, only t grid used in the atmosphere.
122#   useArea     : if true area from the model metrics is used. If false, areas are computed by XIOS from grid corners.
123#   maskSrc     : true to use the source grid mask, false to used all grid points.
124#   maskDst     : true to use the destination grid mask, false to use all grid points.
[4159]125#
[4259]126## Classic cases for IPSLCM6
127AtmOceFluxes="   Direction=a2o,Order=1st,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=HeatWaterFluxes" # Heat and water fluxes
128OceAtmTemp="     Direction=o2a,Order=1st,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=TempIceAlb" # Temperature, sea-ice fraction, albedo
129OceAtmTemp2nd="  Direction=o2a,Order=2nd,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=TempIceAlb" # Temperature, sea-ice fraction, albedo
130AtmOceStressU="  Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=u,useArea=true,maskSrc=true,maskDst=true,Name=WindStress" # Wind stress to NEMO U point
131AtmOceStressV="  Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=v,useArea=true,maskSrc=true,maskDst=true,Name=WindStress" # Wind stress to NEMO V point
132AtmOceQuantity=" Direction=a2o,Order=1st,Quantity=true,Renormalize=false,atmGrid=t,oceGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=Quantity"   # e.g. runoff
[4298]133# For new parameterization
134AtmOceTemp="     Direction=o2a,Order=1st,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=OceTemp" # e.g. T and S correction from DWL parametrization
[4259]135OceAtmFluxes="   Direction=o2a,Order=1st,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=OceAtmFluxes" # e.g. CO2 fluxes
[4298]136# Test to do with 2nd order
137AtmOceFluxes2nd="Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=HeatWaterFluxes" # Heat and water fluxes
[4259]138OceAtmFluxes2nd="Direction=o2a,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=OceAtmFluxes" # e.g. CO2 fluxes
139AtmOceTemps2nd=" Direction=o2a,Order=2nd,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=OceTemp" # e.g. T and S correction from DWL parametrization
[4159]140
[4259]141## Creates the list
142
[4186]143# Standard list for IPSLCM6
144#CommandList=( ${AtmOceFluxes} ${OceAtmTemp} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} Runoff Calving Grids )
[4172]145
[4259]146# More comprehensive list for IPSLCM6 with new features
[4298]147CommandList=( ${AtmOceFluxes} ${OceAtmTemp} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} ${AtmOceTemp} Runoff Calving Grids )
[4172]148
[4259]149# With 2nd order
[4298]150#CommandList=( ${AtmOceFluxes} ${AtmOceFluxes2nd} ${OceAtmTemp} ${OceAtmTemp2nd} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} ${OceAtmFluxes2nd} ${AtmOceTemp} ${AtmOceTemp2nd} Runoff Calving Grids )
[4259]151
[4186]152# Debugs
153#CommandList=( ${AtmOceFluxes} ${OceAtmTemp} Runoff Calving Grids )
[4199]154#CommandList=( ${AtmOceFluxes} Runoff Calving Grids )
[4259]155#CommandList=( ${AtmOceFluxes}  )
156#CommandList=( Runoff )
157#CommandList=( Runoff Calving Grids )
[4186]158#CommandList=( Calving )
159#CommandList=( Grids )
[4172]160
[3620]161## ===========================================================================
162##
163## You should not change anything below this line ....
164##
165## ===========================================================================
[4199]166Tag="MOSAIX"
[3620]167SUBMIT_DIR=$(pwd)
[4259]168FMT_XIOS=netcdf4
[4159]169
170# Functions to handle command parameters
171# ======================================
[4153]172function read_Command {
173    # Decipher the command line to set bash variables
174    local l_Debug="no" l_Element
175    while [[ ${1} = -* ]] ; do
176        case ${1} in
177            ( -- ) shift ; break ;;
178            ( -d | --debug ) l_Debug="true" ; shift ;;
179        esac
180    done
181    local l_Command=${1}
[4159]182    for l_Element in $(echo ${l_Command} | tr "," "\n" ) ; do
[4153]183        [[ "X${l_Debug}" = "Xtrue" ]] && echo ${l_Element}
184        eval export ${l_Element}
185    done
186}
[3620]187
[4153]188function setValues {
189    #
[4186]190    read_Command "Direction=None,Order=None,Quantity=None,Renormalize=None,atmGrid=None,oceGrid=None,useArea=None,maskSrc=None,maskDst=None"
191    read_Command ${1}
192    #
[4159]193    oceGrid=${oceGrid,,} ; atmGrid=${atmGrid,,}
194    OCEGRID=${oceGrid^^} ; ATMGRID=${atmGrid^^}
[4153]195
196    case ${Order} in
197        ( 1st ) numOrder=1 ;;
198        ( 2nd ) numOrder=2 ;;
199    esac
200    case ${Renormalize} in
201        ( true )  NormName=Normalized   ;;
202        ( false ) NormName=UnNormalized ;;
203    esac
204    case ${Quantity} in
205        ( true )  QuantName=Integrated ;;
206        ( false ) QuantName=Surfacic   ;;
207    esac
208    case ${useArea} in
209        ( true )  AreaName=Area   ;;
210        ( false ) AreaName=NoArea ;;
211    esac
212
[4186]213    if [[ "${Name}" != "None" ]] ; then
[4259]214        FullName=${Name}_${Order}Order
[4186]215    else
[4199]216        FullName=${Order}Order_${NormName}_${QuantName}_${AreaName}
[4186]217    fi
218
[4153]219    case ${Direction} in
220        ( o2a )
[4159]221        src=${oce} ; SRC=${OCE} ; srcGrid=${oceGrid} ; srcDomainType=${oceDomainType} ; SRCGRID=${OCEGRID} ; srcArea=area_grid_${OCEGRID}
222        dst=${atm} ; DST=${ATM} ; dstGrid=${atmGrid} ; dstDomainType=${atmDomainType} ; DSTGRID=${ATMGRID} ; dstArea=aire
[4153]223        ;;
224        ( a2o )
[4159]225        src=${atm} ; SRC=${ATM} ; srcGrid=${atmGrid} ; srcDomainType=${atmDomainType} ; SRCGRID=${ATMGRID} ; srcArea=aire
226        dst=${oce} ; DST=${OCE} ; dstGrid=${oceGrid} ; dstDomainType=${oceDomainType} ; DSTGRID=${OCEGRID} ; dstArea=area_grid_${OCEGRID}
[4153]227        ;;
228    esac
[4186]229    echo ${Green}"${SRC} ${SRCGRID} toward ${DST} ${DSTGRID} - ${Order} Order - Normalize: ${Renormalize} - Quantity: ${QuantName} - Area: ${AreaName}  "${Norm}
[4199]230    echo ${Green}"FullName : ${FullName}"${Norm}
[4153]231}
[4186]232
[3620]233#
234# Defines computer
235# ================
[3901]236if [[ $(hostname) = irene*    ]] ; then arch=irene ; center=tgcc ; fi
[4153]237if [[ $(hostname) = lsce*     ]] ; then arch=spip  ; center=spip ; fi
[3734]238
[3620]239PROGRAM=$(basename ${0})
240
241case ${arch} in
[4153]242    ( irene )
[3620]243    set +vx
[4259]244    set +e
[3966]245    R_IN=$(ccc_home -u igcmg --cccwork)/IGCM
246    TMPDIR=${CCCWORKDIR}/TMP
247    SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}}
248    PROGRAM=${BRIDGE_MSUB_REQNAME}
[4172]249    MpiRun="time ccc_mprun"
[4195]250    PyRun="time ccc_mprun -n 1" # Needed to force python to run on one process only
[4259]251    #module purge
252    source $(ccc_home -u igcmg)/MachineEnvironment/irene/env_irene
[4153]253    source ${SUBMIT_DIR}/arch.env
[4259]254    #module load nco
[4172]255    module load python3
[4153]256    module load datadir/igcmg
[3966]257    module list
[4259]258    set -e
[3966]259    ;;
[3734]260    ( spip )
261    R_IN=${HOME}/Scratch/IGCM
262    TMPDIR=${HOME}/Scratch/TMP
263    SUBMIT_DIR=$(pwd)
[4172]264    MpiRun="/opt/local/bin/mpirun -n 4"
265    PyRun="time"
[3734]266    ;;
[3901]267    ( * ) exit -1 ;;
[3620]268esac
269
270set -x ; set -e
271
[4195]272mkdir -p ${TMPDIR}/${CplModel} || exit 1
273cd       ${TMPDIR}/${CplModel} || exit 1
[4146]274rm -fr *
[3620]275
276#
277# Suffixes
278# ---------------------------------------------------------------------------
279
280case ${OCE} in
[4153]281    ( *ORC* )         oce=orc ; oceDomainType=curvilinear   ;;
[3620]282esac
[4159]283
[3620]284case ${ATM} in
[4153]285    ( *dynamico*    ) atm=ico ; atmDomainType=unstructured  ;;
286    ( *ICO*         ) atm=ico ; atmDomainType=unstructured  ;;
287    ( *lmd* | *LMD* ) atm=lmd ; atmDomainType=rectilinear   ;;
[3620]288esac
289
[4159]290case ${OCE} in # Periodicity type of ORCA grid
[4298]291    ( ORCA2*               ) OcePerio=4 ;;
[4172]292    ( ORCA1*   | eORCA1*   ) OcePerio=6 ;;
[4298]293    ( ORCA025* | eORCA025* ) OcePerio=6 ;;
[3723]294esac
[3620]295#
296
[4195]297cp ${SUBMIT_DIR}/bin/interpol.exe       .
298cp ${SUBMIT_DIR}/*.py                   .
[4153]299cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml   .
300cp ${SUBMIT_DIR}/iodef_oce_to_atm.xml   .
[3620]301
302cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc  .
[3639]303cp ${R_IN}/ATM/GRID/${ATM}_grid.nc .
[3620]304
[3901]305#
[4186]306# echo ${Titre}"Creates OCEAN C grid : redundant points removed to compute proper integrals # A passer dans CreateWeights"${Norm}
307# # --------------------------------------------------------------------------------------------------------
308# cat <<EOF >add_c_grid.nco
309# defdim("x_grid_C", \$x_grid_T.size) ;
310# defdim("y_grid_C", \$y_grid_T.size) ;
311# defdim("nvertex_grid_C",  4)         ;
312# nav_lon_grid_C[y_grid_C,x_grid_C]    = nav_lon_grid_T(:,:)    ;
313# nav_lat_grid_C[y_grid_C,x_grid_C]    = nav_lat_grid_T(:,:)    ;
314# bounds_lon_grid_C[y_grid_C,x_grid_C,nvertex_grid_C] = bounds_lon_grid_T(:,:,:) ;
315# bounds_lat_grid_C[y_grid_C,x_grid_C,nvertex_grid_C] = bounds_lat_grid_T(:,:,:) ;
316# mask_C[y_grid_C,x_grid_C]            = maskutil_T(:,:)        ;
317# area_grid_C[y_grid_C,x_grid_C]       = area_grid_T(:,:)       ;
318# EOF
[3620]319
[4186]320# ncap2 --overwrite --history --script-file add_c_grid.nco ${OCE}_coordinates_mask.nc tmp_${OCE}_coordinates_mask.nc
321# ncatted --history --attribute bounds,nav_lon_grid_C,m,c,"bounds_lon_grid_C" tmp_${OCE}_coordinates_mask.nc
322# ncatted --history --attribute bounds,nav_lat_grid_C,m,c,"bounds_lat_grid_C" tmp_${OCE}_coordinates_mask.nc
323# ncks --history --overwrite --variable nav_lon_grid_C,nav_lat_grid_C       tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc
324# ncks --history --append    --variable bounds_lon_grid_C,bounds_lat_grid_C tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc
325# ncks --history --append    --variable area_grid_C             tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc
[3912]326
[4186]327# ncks --history --append C_${OCE}_coordinates_mask.nc            ${OCE}_coordinates_mask.nc
328# rm C_${OCE}_coordinates_mask.nc
[3901]329
[4186]330# ls -al
[3901]331
332##
[4172]333echo ${Titre}"NEMO T point towards ATM - 1st order"${Norm}
[3901]334## ===========================================================================
[4153]335echo "Command parameters : ${Command}"
[4186]336setValues ${DefaultValues}
[3620]337
[4153]338cp iodef_oce_to_atm.xml   iodef.xml
339
[4172]340python3 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
341python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="area_src"]'   -k name  -v area_grid_T
342python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                   -k type  -v ${srcDomainType}
343python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                   -k type  -v ${dstDomainType}
344python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1
345python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k quantity    -v false
346python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v false
347python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k use_area -v false
348python3 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
349python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="area_source"]' -k name  -v area_grid_T
[4199]350python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}
[4172]351python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]'       -t "${SRC} mask interpolated to ${DST}"
352python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${srcDomainType}
353python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]'   -t ${dstDomainType}
354python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'       -t 1
355python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${srcDomainType}
356python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${dstDomainType}
[4199]357python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}.nc
[4172]358python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k order -v 1
359python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t false
360python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="quantity"]'      -t false
361python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="use_area"]'      -t false
362python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k renormalize -v false
363python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k quantity    -v false
364python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k use_area    -v false
[3620]365
[4199]366cp iodef.xml iodef_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}.xml
[3901]367ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
368ln -fs ${ATM}_grid.nc              atm_grid.nc
[3620]369
[4172]370${MpiRun} ./interpol.exe --mask_src=${maskSrc} --mask_dst=${maskDst} --use_area=${useArea}
371
[3620]372##
[4172]373echo ${Titre}"Correct spurious values (extremes)"${Norm}
[3620]374## ===========================================================================
375cat <<EOF > correction_masque.nco
376where (OceFrac <   0.00001 )  OceFrac=OceFrac.get_miss() ;
377where (OceFrac >   0.99999 )  OceFrac=1.0 ;
378OceFrac.delete_miss() ;
379// Fill masked values to land values
380where (OceFrac >  1.0 )  OceFrac=0.0 ;
381where (OceFrac <  0.0 )  OceFrac=0.0 ;
[4298]382OceMask = OceFrac ;
[3620]383EOF
[4199]384ncap2 --history --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_${FullName}.nc tmp_dia_t${oce}_to_t${atm}_${FullName}.nc ; mv tmp_dia_t${oce}_to_t${atm}_${FullName}.nc dia_t${oce}_to_t${atm}_${FullName}.nc
385ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_${FullName}.nc
[4298]386ncatted --history -a missing_value,OceMask,d,,"" -a _FillValue,OceMask,d,,"" dia_t${oce}_to_t${atm}_${FullName}.nc
387 
[3620]388##
[4298]389echo ${Titre}"Creates mask on ATM grid"${Norm}
[3620]390## ===========================================================================
[4199]391cp dia_t${oce}_to_t${atm}_${FullName}.nc  dia_t${oce}_to_t${atm}_${FullName}_mask.nc
[4298]392ncks --alphabetize --history --overwrite --variable OceFrac dia_t${oce}_to_t${atm}_${FullName}_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc
[3620]393
394cat <<EOF > creation_masque.nco
[4298]395Oce2AtmMask = OceMask ;
396where (OceMask >  0.0 )  Oce2AtmMask=1 ;
397where (OceMask <= 0.0 )  Oce2AtmMask=0 ;
[3620]398EOF
[4081]399
[4298]400ncap2 --history --overwrite --script-file creation_masque.nco dia_t${oce}_to_t${atm}_${FullName}.nc tmp_dia_${ATM}_grid_maskFrom_${OCE}.nc
401ncks --overwrite --history --variable OceMask,OceFrac,Oce2AtmMask tmp_dia_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
[3620]402
[4172]403echo "Change dimension names, and some attributes accordingly"
[4298]404## ===========================================================
[4081]405if [[ $(ncdump -h ${ATM}_grid_maskFrom_${OCE}.nc | grep domain_dst | wc -l) -gt 0 ]] ; then
406    case ${atm} in
407        ( *ico* ) 
[4088]408        ncrename --history --dimension cell_domain_dst,cell              ${ATM}_grid_maskFrom_${OCE}.nc
409        ncrename --history --dimension nvertex_domain_dst,nvertex        ${ATM}_grid_maskFrom_${OCE}.nc
410        ncrename --history --variable  lat_domain_dst,lat                ${ATM}_grid_maskFrom_${OCE}.nc
411        ncrename --history --variable  lon_domain_dst,lon                ${ATM}_grid_maskFrom_${OCE}.nc
412        ncrename --history --variable  bounds_lat_domain_dst,bounds_lat  ${ATM}_grid_maskFrom_${OCE}.nc
413        ncrename --history --variable  bounds_lon_domain_dst,bounds_lon  ${ATM}_grid_maskFrom_${OCE}.nc
414        ncatted  --history --attribute bounds,lat,m,c,"bounds_lat"       ${ATM}_grid_maskFrom_${OCE}.nc
415        ncatted  --history --attribute bounds,lon,m,c,"bounds_lon"       ${ATM}_grid_maskFrom_${OCE}.nc
[4081]416        ;;
417        ( *lmd* ) 
[4088]418        ncrename --history --dimension lon_domain_dst,lon            ${ATM}_grid_maskFrom_${OCE}.nc
419        ncrename --history --dimension lat_domain_dst,lat            ${ATM}_grid_maskFrom_${OCE}.nc
[4081]420        ;;
421    esac
422    ncatted  --history --attribute coordinates,OceFrac,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc
423    ncatted  --history --attribute coordinates,OceMask,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc
[4298]424    ncatted  --history --attribute coordinates,Oce2AtmMask,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc
[4088]425 
[4081]426fi
427
428ncks --history --alphabetize  --append    --variable aire    atm_grid.nc                                   ${ATM}_grid_maskFrom_${OCE}.nc
429[[ ${atm} = *ico* ]] && ncks --alphabetize --history --append --variable bounds_lon,bounds_lat atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc
430
[3620]431##
[4298]432
433#cp ${ATM}_grid.nc ${ATM}_gridFromOce.nc
434
435
436##
[4199]437#echo ${Titre}"Creates mask of coastal OCE points"${Norm}
[3901]438## ===========================================================================
[4199]439#${PyRun} python3 -u ComputeNemoCoast.py -n ${OcePerio} -i ${OCE}_coordinates_mask.nc # Creates OceCoastal
[4172]440
[3901]441##
[4199]442#echo ${Titre}"Creates mask of coastal ATM points"${Norm}
[3901]443## ===========================================================================
[4199]444#cat <<EOF > coastal.nco
445#AtmCoastal = OceFrac * 0.0 ;
446#where (OceFrac > 0.0 && OceFrac < 1.0 )  AtmCoastal = 1.0 ;
447#EOF
448#ncap2 --history --overwrite --script-file coastal.nco ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_coastal_maskFrom_${OCE}.nc
449#ncks --history --append --variable AtmCoastal ${ATM}_coastal_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
450#rm ${ATM}_coastal_maskFrom_${OCE}.nc
[4081]451
[3901]452##
[4172]453echo ${Titre}"Other weights files"${Norm}
[3718]454## ===========================================================================
[4153]455# Loop on commands
456for Command in ${CommandList[@]}
457do
458    echo "Command parameters : ${Command}"
[4186]459    setValues ${Command}
[4172]460    if [[ ${Command} = "Runoff"  ]] ; then okRunoff=yes  ; continue ; fi
461    if [[ ${Command} = "Calving" ]] ; then okCalving=yes ; continue ; fi
[4186]462    if [[ ${Command} = "Grids"   ]] ; then okGrids=yes   ; continue ; fi
[4172]463   
[4153]464    ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
[4298]465    #ln -fs ${ATM}_grid.nc              atm_grid.nc
466    ln -fs ${ATM}_grid_maskFrom_${OCE}.nc atm_grid.nc
[4153]467   
468    case ${Direction} in
469        ( o2a )
470        cp iodef_oce_to_atm.xml iodef.xml
[4082]471       
[4172]472        python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]'   -k name -v mask_${DSTGRID} 
[4298]473        python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]'   -k name -v Oce2AtmMask
[4082]474       
[4172]475        python3 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_${SRCGRID}
476        python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="area_source"]' -k name -v area_grid_${SRCGRID}
[4298]477        python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="mask_dest"]'   -k name -v Oce2AtmMask
[4172]478        python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="area_dest"]'   -k name -v aire
[4153]479        ;;
480        ( a2o )
481        cp iodef_atm_to_oce.xml iodef.xml
[4082]482       
[4298]483        python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]'   -k name -v Oce2AtmMask
[4172]484        python3 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_${DSTGRID}
[4082]485       
[4298]486        python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name  -v Oce2AtmMask
[4172]487        python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="area_source"]' -k name  -v aire
488        python3 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_${DSTGRID}
489        python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="area_dest"]'   -k name  -v area_grid_${DSTGRID}
[4153]490        ;;
491    esac
492   
[4172]493    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                     -k type  -v ${dstDomainType}
494    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                     -k type  -v ${srcDomainType}
[4153]495   
[4172]496    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                      -k type  -v ${srcDomainType}
497    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                      -k type  -v ${dstDomainType}
[4153]498   
[4199]499    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k weight_filename -v rmp_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}.nc
[4172]500    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k order       -v ${numOrder}
501    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k quantity    -v ${Quantity}
502    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k renormalize -v ${Renormalize}
503    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k use_area    -v ${useArea}
[4153]504   
[4199]505    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                                 -k name -v dia_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}
[4172]506    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]'         -t "${SRC} mask interpolated to ${DST}"
507    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]'     -t ${dstDomainType}
508    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]'   -t ${srcDomainType}
509    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${Renormalize}
510    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'         -t ${numOrder}   
511    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="quantity"]'      -t ${Quantity}
512    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="use_area"]'      -t ${useArea}
[4153]513   
[4199]514    cp iodef.xml iodef_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}.xml
[4172]515    ${MpiRun} ./interpol.exe --mask_src=${maskSrc} --mask_dst=${maskDst} --use_area=${useArea}
[3719]516done
[4153]517
[3620]518##
[4172]519echo ${Titre}"Add some metadata in file headers"${Norm}
[3620]520## ===========================================================================
521
522NCO="$(ncks --version |& tail -1|sed 's/ncks //')"
[4172]523PYTHON_VER=$( python3 -c "import sys ; print (sys.version.split(' ')[0])" )
[4199]524for InFile in $(ls *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc 2> /dev/null) ; do
[3639]525    ncatted --history \
[3620]526            --attribute LongName,global,d,,                                       \
527            --attribute nco_openmp_thread_number,global,d,,                       \
528            --attribute Conventions,global,o,c,"CF-1.6"                           \
529            --attribute source,global,o,c,"IPSL Earth system model"               \
530            --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center"     \
531            --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr"         \
532            --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu"       \
533            --attribute Atmosphere,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr" \
534            --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') " \
535            --attribute originalFiles,global,o,c,"${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc"      \
[4195]536            --attribute associatedFiles,global,o,c,"grids_${CplModel}.nc areas_${CplModel}.nc masks_${CplModel}.nc" \
[3620]537            --attribute directory,global,o,c,"$(pwd)"                             \
538            --attribute description,global,o,c,"Fields needed by OASIS-MCT"       \
539            --attribute title,global,o,c,"${InFile}.nc"                           \
540            --attribute Program,global,o,c,"Generated by ${PROGRAM}"              \
541            --attribute timeStamp,global,o,c,"$(date)"                            \
542            --attribute HOSTNAME,global,o,c,"$(hostname)"                         \
543            --attribute LOGNAME,global,o,c,"$(whoami)"                            \
544            --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \
[4172]545            --attribute Python,global,o,c,"Python3 version ${PYTHON_VER}"          \
[3620]546            --attribute OS,global,o,c,"$(uname -o)"                               \
547            --attribute release,global,o,c,"$(uname -r)"                          \
548            --attribute directory,global,o,c,"$(pwd)"                             \
[3624]549            --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" \
[4090]550            --attribute SVN_Author,global,o,c,'$Author$'                 \
551            --attribute SVN_Date,global,o,c,'$Date$'                            \
552            --attribute SVN_Revision,global,o,c,'$Revision$'               \
553            --attribute SVN_Id,global,o,c,'$Id$'                                \
[3620]554            ${InFile}
555done
556##
[4172]557echo ${Titre}"Update and complete weight files to fit OASIS requested format"${Norm}
[3620]558## ===========================================================================
559cat <<EOF > add_dim.nco
560defdim("num_wgts",1) ;
561weight[n_weight, num_wgts] = weight ;
562EOF
563
[3719]564for rmpFile in rmp_*.nc ; do
[4199]565    mv ${rmpFile} tmp_${rmpFile}
566    ncap2 --history --script-file add_dim.nco tmp_${rmpFile} ${rmpFile} ; rm tmp_${rmpFile}
[3620]567   
[3719]568    ncrename --history --dimension n_weight,num_links   ${rmpFile}
569    ncrename --history --variable  src_idx,src_address  ${rmpFile}
570    ncrename --history --variable  dst_idx,dst_address  ${rmpFile}
571    ncrename --history --variable  weight,remap_matrix  ${rmpFile}
572    case ${rmpFile} in
[4082]573        ( *1storder* ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  ${rmpFile} ;;
574        ( *2ndorder* ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order"  ${rmpFile} ;;
[3620]575    esac
[3719]576    case ${rmpFile} in
[4082]577        ( *_Normalized*   ) ncatted --history --attribute map_method,global,o,c,"Normalization: true"  ${rmpFile} ;;
578        ( *_UnNormalized* ) ncatted --history --attribute map_method,global,o,c,"Normalization: false" ${rmpFile} ;;
[3719]579    esac
[4082]580    case ${rmpFile} in
581        ( *Integrated*   ) ncatted --history --attribute map_method,global,o,c,"Quantity: true"  ${rmpFile} ;;
582        ( *Surfacic*     ) ncatted --history --attribute map_method,global,o,c,"Quantity: false" ${rmpFile} ;;
583    esac
[3719]584    ncatted --history --attribute conventions,global,o,c,"SCRIP"   ${rmpFile}
585    ncatted --history --attribute normalization,global,o,c,"none"  ${rmpFile}
[3620]586   
[3719]587    case ${rmpFile} in
[3620]588        ( rmp_*${oce}_to_t${atm}_* )
[3639]589        ncatted --history \
[3620]590                --attribute title,global,o,c,"Weights ${OCE} to ${ATM}" \
[4153]591                --attribute source_grid,global,o,c,"${oceDomainType}" \
592                --attribute dest_grid,global,o,c,"${atmDomainType}"   \
[3719]593                ${rmpFile}     
[3620]594        ;;
595        ( rmp_*${atm}_to_*${oce}_* )
[3639]596        ncatted --history \
[3620]597                --attribute title,global,o,c,"Weights ${ATM} to ${OCE}" \
[4153]598                --attribute source_grid,global,o,c,"${atmDomainType}" \
599                --attribute dest_grid,global,o,c,"${oceDomainType}"   \
[3719]600                ${rmpFile}
[3620]601        ;;
602    esac
603done
604
[4186]605ls
[3620]606##
[4172]607echo ${Titre}"Add missing variables in rmp files"${Norm}
[3639]608## ===========================================================================
[4259]609for rmpFile in $(ls rmp_?${atm}_to_[tuv]${oce}_*.nc rmp_[tuv]${oce}_to_t${atm}_*.nc 2> /dev/null ) ; do
[3901]610    echo ${rmpFile}
[3719]611    a_to_o=false ; o_to_a=false
612    case ${rmpFile} in
613        (  rmp_?${oce}_to_?${atm}_*.nc ) o_to_a=true ;;
614        (  rmp_?${atm}_to_?${oce}_*.nc ) a_to_o=true ;;
615    esac
616
[3901]617    for Grid in t u v o c ; do # Identify grids
618        [[ ${rmpFile} = rmp_${Grid}${oce}_to_?${atm}_*.nc ]] && ogrid=${Grid}
619        [[ ${rmpFile} = rmp_?${oce}_to_${Grid}${atm}_*.nc ]] && agrid=${Grid}
620        [[ ${rmpFile} = rmp_${Grid}${atm}_to_?${oce}_*.nc ]] && agrid=${Grid}
621        [[ ${rmpFile} = rmp_?${atm}_to_${Grid}${oce}_*.nc ]] && ogrid=${Grid}
[3719]622    done
623    OGRID=${ogrid^}
624    AGRID=${agrid^}
[3639]625       
[3719]626    cat <<EOF >add_varoce.nco
[3639]627defdim ("src_grid_size"   , \$x_grid_${OGRID}.size*\$y_grid_${OGRID}.size) ;
628defdim ("src_grid_corners", 4) ;
629defdim ("src_grid_rank"   , 2) ;
630//
631src_grid_dims[src_grid_rank] = { \$y_grid_${OGRID}.size, \$x_grid_${OGRID}.size } ;
632//
633src_grid_center_lat [src_grid_size] =  0.0d ;
634src_grid_center_lon [src_grid_size] =  0.0d ;
635src_grid_center_lat (:) = nav_lat_grid_${OGRID}(:,:)   ;
636src_grid_center_lon (:) = nav_lon_grid_${OGRID}(:,:)   ;
637//
638src_grid_corner_lat [src_grid_size, src_grid_corners] = 0.0d ;
639src_grid_corner_lon [src_grid_size, src_grid_corners] = 0.0d ;
640src_grid_corner_lat(:,:) = bounds_lat_grid_${OGRID}(:,:,:) ;
641src_grid_corner_lon(:,:) = bounds_lon_grid_${OGRID}(:,:,:) ;
642//
643src_grid_imask [src_grid_size] =    0 ;
644src_grid_area  [src_grid_size] = 0.0d ;
645src_grid_frac  [src_grid_size] = 1.0d ;
646src_grid_imask (:) = 1 - mask_${OGRID}(:,:) ;
647src_grid_imask.int() ;
648src_grid_area  (:) = area_grid_${OGRID}(:,:) ;
649EOF
650
[4146]651    cp add_varoce.nco add_varoce_$(basename ${rmpFile} .nc)_o_to_a.nco
[4199]652    [[ ${o_to_a} = true ]] && ncap2 --history --append --script-file add_varoce_$(basename ${rmpFile} .nc)_o_to_a.nco ${OCE}_coordinates_mask.nc ${rmpFile}
[3719]653    sed --in-place "s/src_/dst_/g" add_varoce.nco
[4146]654    cp add_varoce.nco add_varoce_$(basename ${rmpFile} .nc)_a_to_o.nco
[4199]655    [[ ${a_to_o} = true ]] && ncap2 --history --append --script-file add_varoce_$(basename ${rmpFile} .nc)_a_to_o.nco ${OCE}_coordinates_mask.nc ${rmpFile}
[3719]656               
657    if [[ ${atm} = ico ]] ; then
658        cat <<EOF >add_varatm.nco
[3639]659defdim ("dst_grid_size"   , \$cell.size) ;
660defdim ("dst_grid_corners", 6) ;
661defdim ("dst_grid_rank"   , 2) ;
662//
663dst_grid_dims[dst_grid_rank] = { \$cell.size, 1 } ;
664//
665dst_grid_center_lat [dst_grid_size] =  0.0d ;
666dst_grid_center_lon [dst_grid_size] =  0.0d ;
667dst_grid_center_lat (:) = lat(:)   ;
668dst_grid_center_lon (:) = lon(:)   ;
669//
670dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ;
671dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ;
672dst_grid_corner_lat(:,:) = bounds_lat(:,:) ;
673dst_grid_corner_lon(:,:) = bounds_lon(:,:) ;
674//
675dst_grid_imask [dst_grid_size] =    0 ;
676dst_grid_area  [dst_grid_size] = 0.0d ;
677dst_grid_frac  [dst_grid_size] = 1.0d ;
[4298]678dst_grid_imask (:) = 1 - Oce2AtmMask(:) ;
[3639]679dst_grid_imask.int() ;
680dst_grid_area  (:) = aire(:) ;
[4259]681dst_grid_frac  (:) = OceFrac(:) ;
[3639]682EOF
[4146]683        cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco
[3719]684        if [[ ${o_to_a} = true ]] ; then
[4199]685            ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
[3719]686            ncks --alphabetize --history --overwrite --variable 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 ${rmpFile} rmp_tmp.nc
687            mv rmp_tmp.nc ${rmpFile}
688        fi
[3718]689                   
[3719]690        sed --in-place "s/dst_/src_/g" add_varatm.nco
[4146]691        cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco
[3719]692        if [[ ${a_to_o} = true ]] ; then
[4199]693            ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
[3719]694            ncks --alphabetize --history --overwrite --variable 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 ${rmpFile} rmp_tmp.nc
695            mv rmp_tmp.nc ${rmpFile}
696        fi
697    fi
[3966]698   
[3719]699    if [[ ${atm} = lmd ]] ; then
700        cat <<EOF >add_varatm.nco
[3639]701defdim ("dst_grid_size"   , \$lon.size*\$lat.size) ;
702defdim ("dst_grid_corners", 4) ;
703defdim ("dst_grid_rank"   , 2) ;
704//
705dst_grid_dims[dst_grid_rank] = { \$lat.size, \$lon.size } ;
706//
707dst_grid_center_lat [dst_grid_size] =  0.0d ;
708dst_grid_center_lon [dst_grid_size] =  0.0d ;
709lat0lon[lat,lon] = lat(:)+0*lon(:) ;
710lon0lat[lat,lon] = lon(:)+0*lat(:) ;
711dst_grid_center_lat (:) = lat0lon(:,:)   ;
712dst_grid_center_lon (:) = lon0lat(:,:)   ;
713//
714//dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ; // Not available for LMDZ lon/lat grid
715//dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ;
716//dst_grid_corner_lat(:,:) = bounds_lat(:,:) ;
717//dst_grid_corner_lon(:,:) = bounds_lon(:,:) ;
718//
719dst_grid_imask [dst_grid_size] =    0 ;
720dst_grid_area  [dst_grid_size] = 0.0d ;
721dst_grid_frac  [dst_grid_size] = 1.0d ;
[4298]722dst_grid_imask (:) = 1 - Oce2AtmMask(:,:) ;
[3639]723dst_grid_imask.int() ;
724dst_grid_area  (:) = aire(:,:) ;
[4259]725dst_grid_frac (:)  = OceFrac(:,:) ;
[3639]726EOF
[4146]727        cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco
[3719]728        if [[ ${o_to_a} = true ]] ; then
[4199]729            ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
[3719]730            ncks --alphabetize --history --overwrite --variable 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 ${rmpFile} rmp_tmp.nc
731            mv rmp_tmp.nc ${rmpFile}
732        fi
733       
734        sed --in-place "s/dst/src/g" add_varatm.nco
[4146]735        cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco
[3719]736        if [[ ${a_to_o} = true ]] ; then
[4199]737            ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
[3719]738            ncks --alphabetize --history --overwrite --variable 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 ${rmpFile} rmp_tmp.nc
739            mv rmp_tmp.nc ${rmpFile}
740        fi
741    fi
[3639]742done
[3901]743ls -al ${OCE}_coordinates_mask.nc
[4097]744
[3639]745##
[4186]746## ============================================================================
[4172]747echo ${Titre}"Creates and save auxiliary files for OASIS : grids.nc, areas.nc and masks.nc"${Norm}
[4186]748cp ${SUBMIT_DIR}/CreateOasisGrids.bash .
749bash CreateOasisGrids.bash --oce ${OCE} --atm ${ATM}
[4097]750
751
752##
[4172]753echo ${Titre}"Runoff weights"${Norm}
[4097]754## ===========================================================================
[4186]755if [[ "X${okRunoff}" = "Xyes" ]] ; then
[4195]756    ${PyRun} python3 -u RunoffWeights.py --oce=${OCE} --atm=${ATM} \
[4172]757              --atmCoastWidth=${atmCoastWidth} --oceCoastWidth=${oceCoastWidth} --searchRadius=${searchRadius} \
[4195]758              --grids=grids_${CplModel}.nc --areas=areas_${CplModel}.nc --masks=masks_${CplModel}.nc \
[4199]759              --o2a=${ATM}_grid_maskFrom_${OCE}.nc --output=rmp_t${atm}_to_t${oce}_runoff_${runOff_atmQuantity}_to_${runOff_oceQuantity}.nc \
760              --fmt=${FMT_XIOS} \
[4186]761              --atmQuantity=${runOff_atmQuantity} --oceQuantity=${runOff_oceQuantity}
[4172]762fi
[4097]763
764##
[4172]765echo ${Titre}"Calving weights"${Norm}
[3620]766## ===========================================================================
[4172]767if [[ "X${okCalving}" = "Xyes" ]] ; then
768    case ${OCE} in
[4298]769        ( eORCA025* )
[4186]770        cp /ccc/work/cont003/gencmip6/deshayej/eORCA_R025_runoff_v1.2.nc .
[4199]771        ${PyRun} python3 -u CalvingWeights.py --output=rmp_t${atm}_to_t${oce}_calving_nosouth.nc  --fmt=${FMT_XIOS} \
[4186]772                  --oce=${OCE} --atm=${ATM} --type=nosouth  --dir=.
[4199]773        ${PyRun} python3 -u CalvingWeights.py --output=rmp_t${atm}_to_t${oce}_calving_iceberg.nc  --fmt=${FMT_XIOS} \
[4186]774                  --oce=${OCE} --atm=${ATM} --type=iceberg  --dir=.  --repartition_file=eORCA_R025_runoff_v1.2.nc --repartition_var=Icb_flux
[4199]775        ${PyRun} python3 -u CalvingWeights.py --output=rmp_t${atm}_to_t${oce}_calving_iceshelf.nc --fmt=${FMT_XIOS} \
[4186]776                  --oce=${OCE} --atm=${ATM} --type=iceshelf --dir=.  --repartition_file=eORCA_R025_runoff_v1.2.nc --repartition_var=sornfisf
[4172]777        ;;
778       
779        ( eORCA1.2 )
780        cp ${R_IN}/OCE/NEMO/ORCA1_LIM3_PISCES/v3.6_stable/runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc .
[4199]781        ${PyRun} python3 -u CalvingWeights.py --output=rmp_t${atm}_to_t${oce}_calving_nosouth.nc  --fmt=${FMT_XIOS}\
[4172]782                  --oce=${OCE} --atm=${ATM} --type=nosouth  --dir=.
[4199]783        ${PyRun} python3 -u CalvingWeights.py --output=rmp_t${atm}_to_t${oce}_calving_iceberg.nc  --fmt=${FMT_XIOS}\
[4172]784                  --oce=${OCE} --atm=${ATM} --type=iceberg  --dir=. --repartition_file=runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc --repartition_var=Icb_flux
[4199]785        ${PyRun} python3 -u CalvingWeights.py --output=rmp_t${atm}_to_t${oce}_calving_iceshelf.nc --fmt=${FMT_XIOS}\
[4172]786                  --oce=${OCE} --atm=${ATM} --type=iceshelf --dir=. --repartition_file=runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc --repartition_var=sornfisf
787        ;;
788       
789        ( * )
[4199]790        ${PyRun} python3 -u CalvingWeights.py --output=rmp_t${atm}_to_t${oce}_calving_full.nc --fmt=${FMT_XIOS} \
[4172]791                  --oce=${OCE} --atm=${ATM} --type=full     --dir=.
792        ;;
793
794    esac
795fi
796
797##
[4199]798echo ${Titre}"Simplifies headers, add version and comment"${Norm}
[4172]799## ===========================================================================
[4199]800for File in $(ls dia_*.nc rmp_*.nc ${ATM}_grid_maskFrom_${OCE}*.nc areas_${OCE}x${ATM}*.nc grids_${OCE}x${ATM}*.nc masks_${OCE}x${ATM}*.nc 2> /dev/null ) ; do
[4037]801    ncatted --history --attribute history_of_appended_files,global,d,c,"" ${File}
[4199]802    ncatted --history --attribute history,global,d,c,"" ${File}
[4172]803    [[ "X${Comment}" != "X" ]] && ncatted --history --attribute Comment,global,o,c,"${Comment}"  ${File}
804    [[ "X${Version}" != "X" ]] && ncatted --history --attribute Version,global,o,c,"${Version}"  ${File}
[4199]805    [[ "X${Tag}" != "X"     ]] && ncatted --history --attribute Version,global,o,c,"${Tag}"      ${File}
806done
807
808##
809echo ${Titre}"Rename rmp and dia files"${Norm}
810## ===========================================================================
[4259]811for File in $(ls *${oce}*${atm}* *${atm}*${oce}*  2> /dev/null ); do
[3719]812    NewFile=$(echo ${File} | sed -e "s/${atm}/${ATM}/" -e "s/${oce}/${OCE}/" )
[4259]813    mv ${File} ${NewFile}
[3620]814done
815
[4199]816##
817echo ${Titre}"Add Tag"${Norm}
818## ===========================================================================
819if [[ "X${Tag}" != "X" ]] ; then
820    for File in $(ls dia_*.nc rmp_*.nc ${ATM}_grid_maskFrom_${OCE}*.nc areas_${OCE}x${ATM}*.nc grids_${OCE}x${ATM}*.nc masks_${OCE}x${ATM}*.nc 2> /dev/null ) ; do
821        mv ${File} $(basename ${File} .nc)_${Tag}.nc
822    done
[4186]823fi
[4199]824##
825echo ${Titre}"Add Version"${Norm}
826## ===========================================================================
827if [[ "X${Version}" != "X" ]] ; then
828    for File in $(ls dia_*.nc rmp_*.nc ${ATM}_grid_maskFrom_${OCE}*.nc areas_${OCE}x${ATM}*.nc grids_${OCE}x${ATM}*.nc masks_${OCE}x${ATM}*.nc 2> /dev/null ) ; do
829        mv ${File} $(basename ${File} .nc)_${Version}.nc
830    done
831fi
832   
833## ===========================================================================
834echo ${Titre}"Save results"${Norm}
835## ===========================================================================
836for File in $(ls dia_*.nc rmp_*.nc ${ATM}_grid_maskFrom_${OCE}*.nc areas_${OCE}x${ATM}*.nc grids_${OCE}x${ATM}*.nc masks_${OCE}x${ATM}*.nc 2> /dev/null ) ; do
837    cp ${File} ${SUBMIT_DIR}
838done
[4172]839
[4199]840
[3620]841##
[4172]842echo ${Titre}"Creates a README.txt file"${Norm}
[4090]843## ===========================================================================
844[[ -f README.txt ]] && rm README.txt
[4298]845UUID=$(uuid)
[3620]846
[4090]847cat <<EOF > README.txt
848Files produced by CreateWeightsMask.bash and CreateOasisGrids.bash
849
850rmp_* are weights files
851dia_* are diagnostic files not needed for the coupler
[4195]852grids_${CplModel}.nc areas_${CplModel}.nc masks_${CplModel}.nc are auxiliary file needed by OASIS-MCT
[4090]853All files have the same uuid in the global attributes
854
855Description     : Weigths and auxiliary files for coupling ${OCE} and ${ATM} needed by OASIS-MCT
856Conventions     : CF-1.6
857source          : IPSL Earth system model
858group           : ICMC IPSL Climate Modelling Center
859Institution     : IPSL https://www.ipsl.fr
860Ocean           : ${OCE} https://www.nemo-ocean.eu
861Atmosphere      : ${ATM} http://lmdz.lmd.jussieu.fr
862production      : $(finger ${LOGNAME} | head -1 | awk '{print $4, $5}')
863originalFiles   : ${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc
[4195]864associatedFiles : grids_${CplModel}.nc areas_${CplModel}.nc masks_${CplModel}.nc
[4090]865directory       : $(pwd)
866timeStamp       : $(date)
867uuid            : ${UUID}
868HOSTNAME        : $(hostname)
869LOGNAME         : $(whoami)
870NCO             : NCO netCDF Operator ${NCO} http://nco.sourceforge.net
871Python version  : ${PYTHON_VER}
872OS              : $(uname -o)
873release         : $(uname -r)
874hardware        : $(uname -i)
[4091]875EOF
[4090]876
[4091]877echo 'SVN Information : ' >> README.txt
878echo '$Author$ ' >> README.txt
879echo '$Date$ ' >> README.txt
880echo '$Revision$ ' >> README.txt
881echo '$Id$ ' >> README.txt
882echo '$HeadURL$ ' >> README.txt
[4090]883
[4172]884echo ${Titre}"Compute checksums and add them to README"${Norm}
[4199]885# ------------------------------------------------------------
[4091]886cat << EOF >> README.txt
[4090]887
[4159]888Files produced, with checksum produced by Unix command shasum (version $(shasum --version)) with default algorithm
[4090]889
890EOF
891
[4199]892for file in $(ls dia_*.nc rmp_*.nc ${ATM}_grid_maskFrom_${OCE}*.nc areas_${OCE}x${ATM}*.nc grids_${OCE}x${ATM}*.nc masks_${OCE}x${ATM}*.nc 2> /dev/null ) ; do
[4298]893    ncatted --attribute uuid,global,o,c,"${UUID}" ${file}
[4090]894    echo "$(shasum ${file})" >> README.txt
895done
896
897cat <<EOF >> README.txt
898
899================= That's all folk's ! ========================
900EOF
901
[4259]902if [[ "X${Version}" != "X" ]] ; then
903    cp README.txt ${SUBMIT_DIR}/README_${CplModel}_MOSAIX_${Version}.txt
904else
905    cp README.txt ${SUBMIT_DIR}/README_${CplModel}_MOSAIX.txt
906fi
[3620]907## ===========================================================================
908##
[4172]909echo ${Titre}"     That's all folk's !!!    "${Norm}
[3620]910##
911## ===========================================================================
912
Note: See TracBrowser for help on using the repository browser.