source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 6446

Last change on this file since 6446 was 6360, checked in by omamce, 14 months ago

Mosaix - O.M. :

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