source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 4091

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

O.M. : text SVN

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