source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 4186

Last change on this file since 4186 was 4186, checked in by omamce, 3 years ago

O.M. :

Runoff weight for both ICO and LMDZ
Correct corc grid

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