source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 6066

Last change on this file since 6066 was 6066, checked in by omamce, 2 years ago

O.M. : changes in MOSAIX

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