source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 3901

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

O.M. : add weight for coastal points only, to prepare computation

of weights for river run-off

  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 35.1 KB
Line 
1#!/bin/bash
2#MSUB -r WeightsMask        # Job name
3#MSUB -o Out_WeightsMask    # Standard output
4#MSUB -e Out_WeightsMask    # Error output
5#MSUB -eo
6#MSUB -n 4              # Number of processors
7#MSUB -T 1800           # Time limit (seconds)
8#MSUB -q standard
9#MSUB -Q test
10#MSUB -p devcmip6
11
12### ===========================================================================
13###
14### Creates interpolation weights between ORCA and atmosphere grids.
15### Interpolates ORCA mask to atmosphere grid.
16### Weight files are at OASIS-MCT format.
17###
18### Atmosphere grid may be lon/lat LMDZ or DYNAMICO icosahedron
19###
20### Documentation : https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX
21### ===========================================================================
22##
23##  Warning, to install, configure, run, use any of Olivier Marti's
24##  software or to read the associated documentation you'll need at least
25##  one (1) brain in a reasonably working order. Lack of this implement
26##  will void any warranties (either express or implied).
27##  O. Marti assumes no responsability for errors, omissions,
28##  data loss, or any other consequences caused directly or indirectly by
29##  the usage of his software by incorrectly or partially configured
30##  personal.
31##
32## SVN information
33#  $Author$
34#  $Date$
35#  $Revision$
36#  $Id$
37#  $HeadURL$
38export Bold=$(tput bold) 
39export Unde=$(tput smul) ; export OffUnde=$(tput rmul)
40export Stou=$(tput smso) ; export OffStou=$(tput rmso)
41export Reve=$(tput rev ) 
42couleurs=( "Black" "Blue" "Green" "Cyan" "Red" "Magenta" "Yellow" "White" )
43for i in $(seq 0 7 ) ; do eval "export ${couleurs[$i]}=$(tput setf $i)" ; done
44export Norm=$(tput sgr0 )
45
46##
47## Configuration
48## ===========================================================================
49
50#
51# Defines models
52# ==============
53OCE=ORCA2.3
54#OCE=eORCA1.2
55#OCE=ORCA025
56
57#ATM=ICO30
58#ATM=ICO40
59#ATM=ICO450
60ATM=LMD9695
61#ATM=LMD144X142
62
63#
64# Defines OCE grids to handle
65# ===========================
66ListOCEGRID="T U V"
67ListOrder="1st" # 2nd"
68ListNormalize="false true"
69
70## ===========================================================================
71##
72## You should not change anything below this line ....
73##
74## ===========================================================================
75SUBMIT_DIR=$(pwd)
76
77#
78# Defines computer
79# ================
80if [[ $(hostname) = curie*    ]] ; then arch=curie ; center=tgcc ; fi
81if [[ $(hostname) = irene*    ]] ; then arch=irene ; center=tgcc ; fi
82if [[ $(hostname) = lsce3005* ]] ; then arch=spip  ; center=spip ; fi
83
84PROGRAM=$(basename ${0})
85
86case ${arch} in
87    ( curie | irene )
88    set +vx
89    module purge
90    source /ccc/cont003/home/dsm/p86ipsl/.env_intel17.0.2_curie;
91    source /ccc/cont003/home/dsm/p86ipsl/.env_netcdf4.3.3.1_curie
92    R_IN=$(ccc_home -u igcmg --cccwork)/IGCM
93    TMPDIR=${SCRATCHDIR}/TMP
94    SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}}
95    PROGRAM=${BRIDGE_MSUB_REQNAME}
96    MPIRUN=ccc_mprun
97    ;;
98    ( spip )
99    R_IN=${HOME}/Scratch/IGCM
100    TMPDIR=${HOME}/Scratch/TMP
101    SUBMIT_DIR=$(pwd)
102    MPIRUN=/opt/local/bin/mpirun-openmpi-gcc49 -n 2
103    ;;
104    ( * ) exit -1 ;;
105esac
106
107set -x ; set -e
108
109mkdir -p ${TMPDIR}/${OCE}x${ATM} || exit 1
110cd       ${TMPDIR}/${OCE}x${ATM} || exit 1
111rm -f *
112
113#
114# Suffixes
115# ---------------------------------------------------------------------------
116Listocegrid=${ListOCEGRID,,}
117
118case ${OCE} in
119    ( *ORC* )         oce=orc ; oce_domain_type=curvilinear   ;;
120esac
121case ${ATM} in
122    ( *dynamico*    ) atm=ico ; atm_domain_type=unstructured  ;;
123    ( *ICO*         ) atm=ico ; atm_domain_type=unstructured  ;;
124    ( *lmd* | *LMD* ) atm=lmd ; atm_domain_type=rectilinear   ;;
125esac
126
127case ${OCE} in
128    ( ORCA2.3*         ) OcePerio=4 ;;
129    ( ORCA1* | eORCA1* ) OcePerio=6 ;;
130esac
131#
132# Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits
133# ---------------------------------------------------------------------------
134FMT_OASIS=64bit
135FMT_XIOS=netcdf4
136
137
138cp ${SUBMIT_DIR}/bin/interpol.exe    .
139cp ${SUBMIT_DIR}/*.py                .
140
141
142cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc  .
143cp ${R_IN}/ATM/GRID/${ATM}_grid.nc .
144
145ncks --overwrite --fl_fmt=${FMT_OASIS} --history ${OCE}_coordinates_mask.nc ${OCE}_coordinates_mask_${FMT_OASIS}.nc
146ncks --overwrite --fl_fmt=${FMT_OASIS} --history ${ATM}_grid.nc                    ${ATM}_grid_${FMT_OASIS}.nc
147#
148# Creates OCEAN C grid : redundant point removed to compute proper integrals # A passer dans CreateWeights
149# ----------------------------------------------------------------------------
150cat <<EOF >add_c_grid.nco
151nav_lon_grid_C    = nav_lon_grid_T    ;
152nav_lat_grid_C    = nav_lat_grid_T    ;
153bounds_lon_grid_C = bounds_lon_grid_T ;
154bounds_lat_grid_C = bounds_lat_grid_T ;
155area_grid_C       = area_grid_T       ;
156mask_C            = maskutil_T        ;
157EOF
158
159ncap2 --overwrite --history --script-file add_c_grid.nco ${OCE}_coordinates_mask.nc tmp_${OCE}_coordinates_mask.nc
160ncks --overwrite --variable nav_lon_grid_C,nav_lat_grid_C,bounds_lon_grid_C,bounds_lat_grid_C,area_grid_C,mask_C tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc
161rm tmp_${OCE}_coordinates_mask_${FMT_OASIS}.nc
162ncrename --dimension x_grid_T,x_grid_C                C_${OCE}_coordinates_mask.nc
163ncrename --dimension y_grid_T,y_grid_C                C_${OCE}_coordinates_mask.nc
164ncrename --dimension nvertex_grid_T,nvertex_grid_C    C_${OCE}_coordinates_mask.nc
165ncks --append C_${OCE}_coordinates_mask.nc            ${OCE}_coordinates_mask.nc
166rm C_${OCE}_coordinates_mask.nc
167
168ncks --overwrite --fl_fmt=${FMT_OASIS} --history {OCE}_coordinates_mask.nc ${OCE}_coordinates_mask_${FMT_OASIS}.nc
169
170ls -al
171
172##
173## NEMO T point towards ATM - 1st order
174## ===========================================================================
175echo ${Green}"${OCE} T toward ${ATM} - 1storder"${Norm}
176cp ${SUBMIT_DIR}/iodef_oce_to_atm.xml   iodef.xml
177
178python 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
179python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                   -k type  -v ${oce_domain_type}
180python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                   -k type  -v ${atm_domain_type}
181python 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
182python 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}_1storder_false
183python 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}"
184python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${oce_domain_type}
185python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]'   -t ${atm_domain_type}
186python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'       -t 1
187python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${oce_domain_type}
188python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${atm_domain_type}
189python 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}_1storder_false.nc
190python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1
191python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t false
192python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k renormalize -v false
193
194cp iodef.xml iodef_t${oce}_to_t${atm}_1storder_false.xml
195ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
196ln -fs ${ATM}_grid.nc              atm_grid.nc
197
198time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=no
199
200##
201## Correct spurious values (extremes)
202## ===========================================================================
203cat <<EOF > correction_masque.nco
204where (OceFrac <   0.00001 )  OceFrac=OceFrac.get_miss() ;
205where (OceFrac >   0.99999 )  OceFrac=1.0 ;
206OceFrac.delete_miss() ;
207// Fill masked values to land values
208where (OceFrac >  1.0 )  OceFrac=0.0 ;
209where (OceFrac <  0.0 )  OceFrac=0.0 ;
210EOF
211ncap2 --history --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_1storder_false.nc tmp_dia_t${oce}_to_t${atm}_1storder_false.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_false.nc dia_t${oce}_to_t${atm}_1storder_false.nc
212ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_1storder_false.nc
213
214##
215##  Creates mask on ATM grid
216## ===========================================================================
217cp dia_t${oce}_to_t${atm}_1storder_false.nc  dia_t${oce}_to_t${atm}_1storder_false_mask.nc
218ncks --alphabetize --history --overwrite --variable OceFrac dia_t${oce}_to_t${atm}_1storder_false_mask.nc  ${ATM}_grid_maskFrom_${OCE}.nc
219ncks --alphabetize --history --append    --variable aire    atm_grid.nc                                    ${ATM}_grid_maskFrom_${OCE}.nc
220[[ ${atm} = *ico* ]] && ncks --alphabetize --history --append --variable bounds_lon,bounds_lat atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc
221
222cat <<EOF > creation_masque.nco
223where (OceFrac >  0.0 )  OceFrac=1 ;
224where (OceFrac <= 0.0 )  OceFrac=0 ;
225EOF
226ncap2 --history --overwrite --script-file creation_masque.nco dia_t${oce}_to_t${atm}_1storder_false_mask.nc tmp_dia_t${oce}_to_t${atm}_1storder_false_mask.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_false_mask.nc dia_t${oce}_to_t${atm}_1storder_false_mask.nc
227ncrename --history --variable OceFrac,OceMask dia_t${oce}_to_t${atm}_1storder_false_mask.nc
228
229ncks --alphabetize --history --append --variable OceMask dia_t${oce}_to_t${atm}_1storder_false_mask.nc   ${ATM}_grid_maskFrom_${OCE}.nc
230rm dia_t${oce}_to_t${atm}_1storder_false_mask.nc
231
232
233
234##
235## NEMO, other case, towards ATM
236## ===========================================================================
237for order in ${ListOrder} ; do
238    case ${order} in
239        ( 1st ) num_order=1 ;;
240        ( 2nd ) num_order=2 ;;
241    esac
242    for normalize in ${ListNormalize} ; do
243        for OCEGRID in ${ListOCEGRID} ; do
244            ocegrid=${OCEGRID,,}
245           
246            if [[ ! -f rmp_${ocegrid}${oce}_to_t${atm}_${order}order_${normalize}.nc ]] ; then
247               
248                echo ${Green}"${OCE} ${OCEGRID} toward ${ATM} - ${order}order - normalize: ${normalize}"${Norm}
249               
250                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}
251                python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                     -k type  -v ${oce_domain_type}
252                python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                     -k type  -v ${atm_domain_type}
253                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}
254                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}_${order}order_${normalize}
255                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}"
256                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}
257                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}
258                python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'         -t ${num_order}
259                python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize}
260                python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                      -k type  -v ${oce_domain_type}
261                python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                      -k type  -v ${atm_domain_type}
262                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}
263                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}_${order}order_${normalize}.nc
264                python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize     -v ${normalize}
265               
266                cp iodef.xml iodef_${ocegrid}${oce}_t${atm}_${order}order_${normalize}.xml
267               
268                ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
269                ln -fs ${ATM}_grid.nc              atm_grid.nc
270                time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes
271            fi
272           
273        done
274    done
275done
276
277##
278## ATM towards NEMO points
279## ===========================================================================
280cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml           iodef.xml
281
282python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                   -k type  -v ${atm_domain_type}
283python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                   -k type  -v ${oce_domain_type}
284python 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}"
285python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${atm_domain_type}
286python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]'   -t ${oce_domain_type}
287python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${atm_domain_type}
288python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${oce_domain_type}
289           
290for order in ${ListOrder} ; do
291    case ${order} in
292        ( 1st ) num_order=1 ;;
293        ( 2nd ) num_order=2 ;;
294    esac
295    for normalize in ${ListNormalize} ; do
296        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}
297        python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'         -t ${num_order}   
298        python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize}
299        python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k renormalize     -v ${normalize}
300       
301        for OCEGRID in ${ListOCEGRID} ; do
302            ocegrid=${OCEGRID,,}
303           
304            echo ${Green}"${ATM} toward ${OCE} ${OCEGRID} - ${order}order - normalize: ${normalize}"${Norm}
305            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}
306            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}
307            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}_${order}order_${normalize}
308            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}_${order}order_${normalize}.nc
309            cp iodef.xml iodef_t${atm}_to_${ocegrid}${oce}_${order}order_${normalize}.xml
310           
311            ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
312            ln -fs ${ATM}_grid.nc              atm_grid.nc
313            time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes
314           
315        done
316    done
317done
318
319##
320## Creates mask of coastal OCE points
321## ===========================================================================
322python ComputeNemoCoast.py -n ${OcePerio} -i ${OCE}_coordinates_mask.nc # Creates OceCoastal
323##
324## Creates mask of coastal ATM points
325## ===========================================================================
326cat <<EOF > coastal.nco
327AtmCoastal = OceFrac * 0.0 ;
328where (OceFrac > 0.0 && OceFrac < 1.0 )  AtmCoastal = 1.0 ;
329EOF
330ncap2 --history --overwrite --script-file coastal.nco ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_coastal_maskFrom_${OCE}.nc
331ncks --history --append --variable AtmCoastal ${ATM}_coastal_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
332rm ${ATM}_coastal_maskFrom_${OCE}.nc
333ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc
334##
335## ATM towards NEMO points - runoff
336## ===========================================================================
337cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml           iodef.xml
338for normalize in ${ListNormalize} ; do
339    python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                   -k type  -v ${atm_domain_type}
340    python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                   -k type  -v ${oce_domain_type}
341    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}"
342    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}
343    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}
344    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${atm_domain_type}
345    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${oce_domain_type}
346    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1
347    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'       -t 1
348    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize}
349    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}
350    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
351    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
352    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}_1storder_${normalize}
353    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}_1storder_${normalize}.nc
354    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize     -v ${normalize}
355   
356    cp iodef.xml iodef_o${atm}_to_c${oce}_1storder_${normalize}.xml
357   
358    ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
359    ln -fs ${ATM}_grid.nc              atm_grid.nc
360    time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes
361
362    # Now we should divide weight par source (atm) grid area : run-off is a quantity/s integrated on the grid mox, not a flux
363done
364##
365## Copy all NetCDF files to NetCDF 3 format (needed for OASIS)
366## ===========================================================================
367for InFile in *.nc ; do
368    OuFile=$(basename ${InFile} .nc)_${FMT_OASIS}.nc
369    if [[ ! -f ${OuFile} ]] ; then
370        ncks --alphabetize --history --fl_fmt=${FMT_OASIS} ${InFile} ${OuFile}
371    fi
372done
373
374##
375## Add time axis and coordinates information
376## (needed if files need to be read by XIOS)
377## ===========================================================================
378#ncatted --history -a coordinates,aire,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc
379ncap2 --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
380ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc
381
382if [[ ${atm} = ico ]] ; then
383    cat <<EOF > add_time.nco
384OceFrac    [time_counter,cell] = OceFrac    (:) ;
385OceMask    [time_counter,cell] = OceMask    (:) ;
386AtmCoastal [time_counter,cell] = AtmCoastal (:) ;
387EOF
388    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
389    ncatted --history \
390            -a coordinates,OceFrac,c,c,"time_counter cell"    \
391            -a coordinates,OceMask,c,c,"time_counter cell"    \
392            -a coordinates,AtmCoastal,c,c,"time_counter cell" \
393            -a coordinates,aire,c,c,"cell" \
394            ${ATM}_grid_maskFrom_${OCE}.nc
395fi
396ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc
397
398if [[ ${atm} = lmd ]] ; then
399    cat <<EOF > add_time.nco
400OceFrac    [time_counter,lat,lon] = OceFrac    (:,:) ;
401OceMask    [time_counter,lat,lon] = OceMask    (:,:) ;
402AtmCoastal [time_counter,lat,lon] = AtmCoastal (:,:) ;
403EOF
404    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
405    ncatted --history \
406            -a coordinates,OceFrac,c,c,"time_counter lat lon"    \
407            -a coordinates,OceMask,c,c,"time_counter lat lon"    \
408            -a coordinates,AtmCoastal,c,c,"time_counter lat lon" \
409            -a coordinates,aire,c,c,"lat lon" \
410            ${ATM}_grid_maskFrom_${OCE}.nc
411fi
412ncks --alphabetize --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
413ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc
414
415##
416## Add some metadata in file headers
417## ===========================================================================
418
419UUID=$(uuid)
420NCO="$(ncks --version |& tail -1|sed 's/ncks //')"
421PYTHON_VER=$( python -i -c "import sys ; print (sys.version.split(' ')[0])" )
422for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc; do
423    ncatted --history \
424            --attribute uuid,global,d,,                                           \
425            --attribute LongName,global,d,,                                       \
426            --attribute nco_openmp_thread_number,global,d,,                       \
427            --attribute Conventions,global,o,c,"CF-1.6"                           \
428            --attribute source,global,o,c,"IPSL Earth system model"               \
429            --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center"     \
430            --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr"         \
431            --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu"       \
432            --attribute Atmosphere,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr" \
433            --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') " \
434            --attribute originalFiles,global,o,c,"${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc"      \
435            --attribute associatedFiles,global,o,c,"grids_${OCE}x${ATM}.nc areas_${OCE}x${ATM}.nc masks_${OCE}x${ATM}.nc" \
436            --attribute directory,global,o,c,"$(pwd)"                             \
437            --attribute description,global,o,c,"Fields needed by OASIS-MCT"       \
438            --attribute title,global,o,c,"${InFile}.nc"                           \
439            --attribute Program,global,o,c,"Generated by ${PROGRAM}"              \
440            --attribute timeStamp,global,o,c,"$(date)"                            \
441            --attribute uuid,global,o,c,"${UUID}"                                 \
442            --attribute HOSTNAME,global,o,c,"$(hostname)"                         \
443            --attribute LOGNAME,global,o,c,"$(whoami)"                            \
444            --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \
445            --attribute Python,global,o,c,"Python version ${PYTHON_VER}"          \
446            --attribute OS,global,o,c,"$(uname -o)"                               \
447            --attribute release,global,o,c,"$(uname -r)"                          \
448            --attribute hardware,global,o,c,"$(uname -i)"                         \
449            --attribute directory,global,o,c,"$(pwd)"                             \
450            --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" \
451            --attribute Comment,global,o,c,"Preliminary attempt - Do not trust !" \
452            --attribute SVN_Author,global,o,c,"$Author$"                 \
453            --attribute SVN_Date,global,o,c,"$Date$"                            \
454            --attribute SVN_Revision,global,o,c,"$Revision$"               \
455            --attribute SVN_Id,global,o,c,"$Id$"                                \
456            ${InFile}
457done
458
459
460##
461## Update and complete weights file to fit OASIS requested format
462## ===========================================================================
463cat <<EOF > add_dim.nco
464defdim("num_wgts",1) ;
465weight[n_weight, num_wgts] = weight ;
466EOF
467
468for rmpFile in rmp_*.nc ; do
469    mv ${rmpFile} xios_${rmpFile}
470    ncap2 --fl_fmt=${FMT_OASIS} --history --script-file add_dim.nco xios_${rmpFile} ${rmpFile}
471   
472    ncrename --history --dimension n_weight,num_links   ${rmpFile}
473    ncrename --history --variable  src_idx,src_address  ${rmpFile}
474    ncrename --history --variable  dst_idx,dst_address  ${rmpFile}
475    ncrename --history --variable  weight,remap_matrix  ${rmpFile}
476    case ${rmpFile} in
477        ( *_1storder_*.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  ${rmpFile} ;;
478        ( *_2ndorder_*.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order"  ${rmpFile} ;;
479    esac
480    case ${rmpFile} in
481        ( *_true.nc  ) ncatted --history --attribute map_method,global,o,c,"Normalization: true"  ${rmpFile} ;;
482        ( *_false.nc ) ncatted --history --attribute map_method,global,o,c,"Normalization: false" ${rmpFile} ;;
483    esac
484    ncatted --history --attribute conventions,global,o,c,"SCRIP"   ${rmpFile}
485    ncatted --history --attribute normalization,global,o,c,"none"  ${rmpFile}
486   
487    case ${rmpFile} in
488        ( rmp_*${oce}_to_t${atm}_* )
489        ncatted --history \
490                --attribute title,global,o,c,"Weights ${OCE} to ${ATM}" \
491                --attribute source_grid,global,o,c,"${oce_domain_type}" \
492                --attribute dest_grid,global,o,c,"${atm_domain_type}"   \
493                ${rmpFile}     
494        ;;
495        ( rmp_*${atm}_to_*${oce}_* )
496        ncatted --history \
497                --attribute title,global,o,c,"Weights ${ATM} to ${OCE}" \
498                --attribute source_grid,global,o,c,"${atm_domain_type}" \
499                --attribute dest_grid,global,o,c,"${oce_domain_type}"   \
500                ${rmpFile}
501        ;;
502    esac
503done
504
505##
506## Add missing variables in rmp files
507## ===========================================================================
508for rmpFile in rmp_* ; do
509    echo ${rmpFile}
510    a_to_o=false ; o_to_a=false
511    case ${rmpFile} in
512        (  rmp_?${oce}_to_?${atm}_*.nc ) o_to_a=true ;;
513        (  rmp_?${atm}_to_?${oce}_*.nc ) a_to_o=true ;;
514    esac
515
516    for Grid in t u v o c ; do # Identify grids
517        [[ ${rmpFile} = rmp_${Grid}${oce}_to_?${atm}_*.nc ]] && ogrid=${Grid}
518        [[ ${rmpFile} = rmp_?${oce}_to_${Grid}${atm}_*.nc ]] && agrid=${Grid}
519        [[ ${rmpFile} = rmp_${Grid}${atm}_to_?${oce}_*.nc ]] && agrid=${Grid}
520        [[ ${rmpFile} = rmp_?${atm}_to_${Grid}${oce}_*.nc ]] && ogrid=${Grid}
521    done
522    OGRID=${ogrid^}
523    AGRID=${agrid^}
524       
525    cat <<EOF >add_varoce.nco
526defdim ("src_grid_size"   , \$x_grid_${OGRID}.size*\$y_grid_${OGRID}.size) ;
527defdim ("src_grid_corners", 4) ;
528defdim ("src_grid_rank"   , 2) ;
529//
530src_grid_dims[src_grid_rank] = { \$y_grid_${OGRID}.size, \$x_grid_${OGRID}.size } ;
531//
532src_grid_center_lat [src_grid_size] =  0.0d ;
533src_grid_center_lon [src_grid_size] =  0.0d ;
534src_grid_center_lat (:) = nav_lat_grid_${OGRID}(:,:)   ;
535src_grid_center_lon (:) = nav_lon_grid_${OGRID}(:,:)   ;
536//
537src_grid_corner_lat [src_grid_size, src_grid_corners] = 0.0d ;
538src_grid_corner_lon [src_grid_size, src_grid_corners] = 0.0d ;
539src_grid_corner_lat(:,:) = bounds_lat_grid_${OGRID}(:,:,:) ;
540src_grid_corner_lon(:,:) = bounds_lon_grid_${OGRID}(:,:,:) ;
541//
542src_grid_imask [src_grid_size] =    0 ;
543src_grid_area  [src_grid_size] = 0.0d ;
544src_grid_frac  [src_grid_size] = 1.0d ;
545src_grid_imask (:) = 1 - mask_${OGRID}(:,:) ;
546src_grid_imask.int() ;
547src_grid_area  (:) = area_grid_${OGRID}(:,:) ;
548EOF
549
550    [[ ${o_to_a} = true ]] && ncap2 --history --append --script-file add_varoce.nco ${OCE}_coordinates_mask_${FMT_OASIS}.nc ${rmpFile}
551    sed --in-place "s/src_/dst_/g" add_varoce.nco
552    [[ ${a_to_o} = true ]] && ncap2 --history --append --script-file add_varoce.nco ${OCE}_coordinates_mask_${FMT_OASIS}.nc ${rmpFile}
553               
554    if [[ ${atm} = ico ]] ; then
555        cat <<EOF >add_varatm.nco
556defdim ("dst_grid_size"   , \$cell.size) ;
557defdim ("dst_grid_corners", 6) ;
558defdim ("dst_grid_rank"   , 2) ;
559//
560dst_grid_dims[dst_grid_rank] = { \$cell.size, 1 } ;
561//
562dst_grid_center_lat [dst_grid_size] =  0.0d ;
563dst_grid_center_lon [dst_grid_size] =  0.0d ;
564dst_grid_center_lat (:) = lat(:)   ;
565dst_grid_center_lon (:) = lon(:)   ;
566//
567dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ;
568dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ;
569dst_grid_corner_lat(:,:) = bounds_lat(:,:) ;
570dst_grid_corner_lon(:,:) = bounds_lon(:,:) ;
571//
572dst_grid_imask [dst_grid_size] =    0 ;
573dst_grid_area  [dst_grid_size] = 0.0d ;
574dst_grid_frac  [dst_grid_size] = 1.0d ;
575dst_grid_imask (:) = 1 - OceMask(0,:) ;
576dst_grid_imask.int() ;
577dst_grid_area  (:) = aire(:) ;
578EOF
579        if [[ ${o_to_a} = true ]] ; then
580            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile}
581            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
582            mv rmp_tmp.nc ${rmpFile}
583        fi
584                   
585        sed --in-place "s/dst_/src_/g" add_varatm.nco
586        if [[ ${a_to_o} = true ]] ; then
587            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile}
588            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
589            mv rmp_tmp.nc ${rmpFile}
590        fi
591    fi
592    if [[ ${atm} = lmd ]] ; then
593        cat <<EOF >add_varatm.nco
594defdim ("dst_grid_size"   , \$lon.size*\$lat.size) ;
595defdim ("dst_grid_corners", 4) ;
596defdim ("dst_grid_rank"   , 2) ;
597//
598dst_grid_dims[dst_grid_rank] = { \$lat.size, \$lon.size } ;
599//
600dst_grid_center_lat [dst_grid_size] =  0.0d ;
601dst_grid_center_lon [dst_grid_size] =  0.0d ;
602lat0lon[lat,lon] = lat(:)+0*lon(:) ;
603lon0lat[lat,lon] = lon(:)+0*lat(:) ;
604dst_grid_center_lat (:) = lat0lon(:,:)   ;
605dst_grid_center_lon (:) = lon0lat(:,:)   ;
606//
607//dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ; // Not available for LMDZ lon/lat grid
608//dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ;
609//dst_grid_corner_lat(:,:) = bounds_lat(:,:) ;
610//dst_grid_corner_lon(:,:) = bounds_lon(:,:) ;
611//
612dst_grid_imask [dst_grid_size] =    0 ;
613dst_grid_area  [dst_grid_size] = 0.0d ;
614dst_grid_frac  [dst_grid_size] = 1.0d ;
615dst_grid_imask (:) = 1 - OceMask(0,:,:) ;
616dst_grid_imask.int() ;
617dst_grid_area  (:) = aire(:,:) ;
618dst_grid_frac (:)  = OceFrac(0,:,:) ;
619EOF
620        if [[ ${o_to_a} = true ]] ; then
621            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile}
622            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
623            mv rmp_tmp.nc ${rmpFile}
624        fi
625       
626        sed --in-place "s/dst/src/g" add_varatm.nco
627        if [[ ${a_to_o} = true ]] ; then
628            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile}
629            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
630            mv rmp_tmp.nc ${rmpFile}
631        fi
632    fi
633done
634ls -al ${OCE}_coordinates_mask.nc
635##
636## Save results
637## ===========================================================================
638cp ${ATM}_grid_maskFrom_${OCE}.nc ${SUBMIT_DIR}
639for File in dia_*.nc rmp_*.nc
640do
641    NewFile=$(echo ${File} | sed -e "s/${atm}/${ATM}/" -e "s/${oce}/${OCE}/" )
642    cp ${File} ${SUBMIT_DIR}/${NewFile}
643done
644
645##
646## Creates and save auxiliary files for OASIS
647## ===========================================================================
648bash ${SUBMIT_DIR}/CreateOasisGrids.bash --oce ${OCE} --atm ${ATM}
649
650cp areas_${OCE}x${ATM}.nc ${SUBMIT_DIR}
651cp grids_${OCE}x${ATM}.nc ${SUBMIT_DIR}
652cp masks_${OCE}x${ATM}.nc ${SUBMIT_DIR}
653
654
655## ===========================================================================
656##
657##                               That's all folk's !!!
658##
659## ===========================================================================
660
Note: See TracBrowser for help on using the repository browser.