source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 5926

Last change on this file since 5926 was 5926, checked in by snguyen, 3 years ago

revert de make_mosaix a 5924 et update de CreateWeightsMask?.bash pour utiliser ocePeriod avec RunoffWeights?.py et CalvingWeights?.py

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