source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 4146

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

O.M. : small corrections on diagnostics only

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