source: TOOLS/MOSAIX/CreateWeightsMask.bash

Last change on this file was 5548, checked in by omamce, 8 weeks ago

O.M. : small changes

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