source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 3719

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

O.M. : add normalization

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