source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 3725

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

O.M. : first step to implement run-off

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