source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 4259

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

O.M. : MOSAIX

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