source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 3740

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

O.M. : add my Mac to known computers

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