source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 4153

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

O.M. : include areas correction

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