source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 4411

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

O.M. : MOSAIX. Weights v1 for IPSLCM6 LR

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