source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 4317

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

O.M: Mosaix. Correct NEMO mask to use maskutil

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