source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 4159

Last change on this file since 4159 was 4159, checked in by omamce, 6 years ago

O.M. : correct eORC025 case for calving weights

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