source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 6093

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

MOSAIX

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