source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 3639

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

O.M. : add full description in rmp files.
Note: bounds are still missing for LMD lon/lat grid.

  • Property svn:executable set to *
  • Property svn:keywords set to HeadURL
File size: 26.5 KB
Line 
1#!/bin/bash
2#MSUB -r WeightsMask        # nom de la requete
3#MSUB -o Out_WeightsMask    # nom du fichier de sortie
4#MSUB -e Out_WeightsMask    # nom du fichier de sortie
5#MSUB -eo
6#MSUB -n 4              # Reservation des processeurs pour le job
7#MSUB -T 1800           # Limite temps (en secondes)
8#MSUB -q standard
9#MSUB -Q test
10#MSUB -p devcmip6
11
12### ===========================================================================
13###
14### Creates interpolation weights between ORCA and atmospher 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: omamce $
34#  $Date: 2018-03-12 11:17:59 +0100 (Mon, 12 Mar 2018) $
35#  $Revision: 3625 $
36#  $Id: CreateWeightsMask.bash 3625 2018-03-12 10:17:59Z omamce $
37#  $HeadURL$
38#  $Log: $
39
40##
41## Configuration
42## ===========================================================================
43
44#
45# Defines models
46# ==============
47#OCE=ORCA2.3
48OCE=eORCA1.2
49#OCE=ORCA025
50
51ATM=ICO30
52#ATM=ICO40
53#ATM=ICO450
54#ATM=LMD9695
55#ATM=LMD144X142
56
57#
58# Defines OCE grids to handle
59# ===========================
60ListOCEGRID="T U V"
61Listorder="1st" # " 2nd
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 unload cdo nco ferret
81    module unload netcdf hdf5
82    module load python # /2.7.12
83    module load netcdf/4.3.3.1_hdf5_parallel # Version for XIOS
84    module load nco
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    ;;
90    ( * )
91    exit -1
92    ;;
93esac
94
95set -x ; set -e
96
97mkdir -p ${TMPDIR}/${OCE}x${ATM} || exit 1
98cd       ${TMPDIR}/${OCE}x${ATM} || exit 1
99rm -f *
100
101#
102# Suffixes
103# ---------------------------------------------------------------------------
104Listocegrid=${ListOCEGRID~}
105
106case ${OCE} in
107    ( *ORC* )         oce=orc ; oce_domain_type=curvilinear   ;;
108esac
109case ${ATM} in
110    ( *dynamico*    ) atm=ico ; atm_domain_type=unstructured  ;;
111    ( *ICO*         ) atm=ico ; atm_domain_type=unstructured  ;;
112    ( *lmd* | *LMD* ) atm=lmd ; atm_domain_type=rectilinear   ;;
113esac
114
115#
116# Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits
117# ---------------------------------------------------------------------------
118FL_FMT=64bit
119
120
121cp ${SUBMIT_DIR}/bin/interpol.exe                 .
122cp ${SUBMIT_DIR}/update_xml.py                    .
123
124##
125## NEMO T point towards ATM - 1st order
126## ===========================================================================
127cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc  .
128cp ${R_IN}/ATM/GRID/${ATM}_grid.nc .
129
130ln -s ${OCE}_coordinates_mask.nc  oce_grid.nc
131ln -s ${ATM}_grid.nc              atm_grid.nc
132
133echo ${Green}"${OCE} T toward ${ATM} - 1storder"${Norm}
134cp ${SUBMIT_DIR}/iodef_oce_to_atm.xml   iodef.xml
135
136python 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
137python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                   -k type  -v ${oce_domain_type}
138python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                   -k type  -v ${atm_domain_type}
139python 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
140python 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
141python 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}"
142python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${oce_domain_type}
143python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]'   -t ${atm_domain_type}
144python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'       -t 1
145python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${oce_domain_type}
146python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${atm_domain_type}
147python 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.nc
148python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1
149
150cp iodef.xml iodef_t${oce}_to_t${atm}_1storder.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.nc tmp_dia_t${oce}_to_t${atm}_1storder.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder.nc dia_t${oce}_to_t${atm}_1storder.nc
166ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_1storder.nc
167
168##
169##  Creates mask on ATM grid
170## ===========================================================================
171cp dia_t${oce}_to_t${atm}_1storder.nc  dia_t${oce}_to_t${atm}_1storder_mask.nc
172ncks --alphabetize --history --overwrite -v OceFrac dia_t${oce}_to_t${atm}_1storder_mask.nc  ${ATM}_grid_maskFrom_${OCE}.nc
173ncks --alphabetize --history --append    -v aire    atm_grid.nc                              ${ATM}_grid_maskFrom_${OCE}.nc
174[[ ${atm} = *ico* ]] && ncks --alphabetize --history --append -v 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_mask.nc tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc dia_t${oce}_to_t${atm}_1storder_mask.nc
181ncrename --history -v OceFrac,OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc
182
183ncks --alphabetize --history --append  -v OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc   ${ATM}_grid_maskFrom_${OCE}.nc
184
185
186##
187## NEMO, other case, towards ATM
188## ===========================================================================
189for order in ${Listorder} ; do
190    case ${order} in
191        ( 1st ) num_order=1 ;;
192        ( 2nd ) num_order=2 ;;
193    esac
194   
195    for OCEGRID in ${ListOCEGRID} ; do
196        ocegrid=${OCEGRID~}
197
198        if [[ !( ${order} = 1st && ${OCEGRID} = T ) ]] ; then
199
200            echo ${Green}"${OCE} ${OCEGRID} toward ${ATM} - ${order}order"${Norm}
201
202            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}
203            python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                   -k type  -v ${oce_domain_type}
204            python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                   -k type  -v ${atm_domain_type}
205            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}
206            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
207            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}"
208            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}
209            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}
210            python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'       -t ${num_order}
211            python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${oce_domain_type}
212            python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${atm_domain_type}
213            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}
214            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.nc
215            cp iodef.xml iodef_${ocegrid}${oce}_t${atm}_${order}order.xml
216           
217            time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes
218        fi
219       
220    done
221done
222
223##
224## ATM towards NEMO points
225## ===========================================================================
226cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml           iodef.xml
227
228python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                   -k type  -v ${atm_domain_type}
229python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                   -k type  -v ${oce_domain_type}
230python 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}"
231python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${atm_domain_type}
232python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]'   -t ${oce_domain_type}
233python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${atm_domain_type}
234python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${oce_domain_type}
235           
236for order in ${Listorder} ; do
237    case ${order} in
238        ( 1st ) num_order=1 ;;
239        ( 2nd ) num_order=2 ;;
240    esac
241    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}
242    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'       -t ${num_order}   
243   
244    for OCEGRID in ${ListOCEGRID} ; do
245        ocegrid=${OCEGRID~}
246
247        echo ${Green}"${ATM} toward ${OCE} ${OCEGRID} - ${order}order"${Norm}
248        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}
249        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}
250        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
251        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.nc
252        cp iodef.xml iodef_t${atm}_to_${ocegrid}${oce}_${order}order.xml
253       
254        time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes
255       
256    done
257done
258
259##
260## Change all NetCDF files to NetCDF 3 format (needed for OASIS)
261## ===========================================================================
262for InFile in *.nc ; do
263    if [[ $(ncdump -k ${InFile}) = *netCDF-4* ]] ; then
264        mv ${InFile} tmp_${InFile}
265        ncks --alphabetize --fl_fmt=${FL_FMT} --history  tmp_${InFile}  ${InFile}
266    fi
267done
268
269##
270## Add time axis and coordinates information
271## (needed if files need to be read by XIOS)
272## ===========================================================================
273if [[ ${atm} = ico ]] ; then
274    cat <<EOF > add_time.nco
275defdim("time_counter",1) ;
276OceFrac [time_counter,cell] = OceFrac (:) ;
277OceMask [time_counter,cell] = OceMask (:) ;
278EOF
279    ncap2 -O --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
280    ncks --alphabetize -O --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
281    ncatted --history \
282            -a coordinates,OceFrac,c,c,"time_counter cell" \
283            -a coordinates,OceMask,c,c,"time_counter cell" \
284            -a coordinates,aire,c,c,"time_counter cell"    ${ATM}_grid_maskFrom_${OCE}.nc
285fi
286if [[ ${atm} = lmd ]] ; then
287    cat <<EOF > add_time.nco
288defdim("time_counter",1) ;
289OceFrac [time_counter,lat,lon] = OceFrac (:,:) ;
290OceMask [time_counter,lat,lon] = OceMask (:,:) ;
291EOF
292    ncap2 -O --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
293    ncks --alphabetize -O --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
294    ncatted --history \
295            -a coordinates,OceFrac,c,c,"time_counter lat lon" \
296            -a coordinates,OceMask,c,c,"time_counter lat lon" \
297            -a coordinates,aire,c,c,"time_counter lat lon"    ${ATM}_grid_maskFrom_${OCE}.nc
298fi
299
300##
301## Add some information in file headers
302## ===========================================================================
303
304UUID=$(uuid)
305NCO="$(ncks --version |& tail -1|sed 's/ncks //')"
306PYTHON_VER=$( python -i -c "import sys ; print (sys.version.split(' ')[0])" )
307for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ; do
308    ncatted --history \
309            --attribute uuid,global,d,,                                           \
310            --attribute LongName,global,d,,                                       \
311            --attribute nco_openmp_thread_number,global,d,,                       \
312            --attribute Conventions,global,o,c,"CF-1.6"                           \
313            --attribute source,global,o,c,"IPSL Earth system model"               \
314            --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center"     \
315            --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr"         \
316            --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu"       \
317            --attribute Atmosphere,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr" \
318            --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') " \
319            --attribute originalFiles,global,o,c,"${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc"      \
320            --attribute associatedFiles,global,o,c,"grids_${OCE}x${ATM}.nc areas_${OCE}x${ATM}.nc masks_${OCE}x${ATM}.nc" \
321            --attribute directory,global,o,c,"$(pwd)"                             \
322            --attribute description,global,o,c,"Fields needed by OASIS-MCT"       \
323            --attribute title,global,o,c,"${InFile}.nc"                           \
324            --attribute Program,global,o,c,"Generated by ${PROGRAM}"              \
325            --attribute timeStamp,global,o,c,"$(date)"                            \
326            --attribute uuid,global,o,c,"${UUID}"                                 \
327            --attribute HOSTNAME,global,o,c,"$(hostname)"                         \
328            --attribute LOGNAME,global,o,c,"$(whoami)"                            \
329            --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \
330            --attribute Python,global,o,c,"Python version ${PYTHON_VER}"          \
331            --attribute OS,global,o,c,"$(uname -o)"                               \
332            --attribute release,global,o,c,"$(uname -r)"                          \
333            --attribute hardware,global,o,c,"$(uname -i)"                         \
334            --attribute directory,global,o,c,"$(pwd)"                             \
335            --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" \
336            --attribute Comment,global,o,c,"Preliminary attempt - Do not trust !" \
337            --attribute SVN_Author,global,o,c,"$Author: omamce $"                 \
338            --attribute SVN_Date,global,o,c,"$Date: 2018-03-12 11:17:59 +0100 (Mon, 12 Mar 2018) $"                            \
339            --attribute SVN_Revision,global,o,c,"$Revision: 3625 $"               \
340            --attribute SVN_Id,global,o,c,"$Id: CreateWeightsMask.bash 3625 2018-03-12 10:17:59Z omamce $"                                \
341            --attribute SVN_Log,global,o,c,"$Log: $"                              \
342            ${InFile}
343done
344
345
346##
347## Update and complete weights file to fit OASIS requested format
348## ===========================================================================
349cat <<EOF > add_dim.nco
350defdim("num_wgts",1) ;
351weight[n_weight, num_wgts] = weight ;
352EOF
353
354for file in rmp_*${oce}_to_*${atm}_*.nc rmp_*${atm}_to_*${oce}_*.nc ; do
355    mv ${file} xios_${file}
356    ncap2 --fl_fmt=${FL_FMT} --history --script-file add_dim.nco xios_${file} ${file}
357   
358    ncrename --history --dimension n_weight,num_links   ${file}
359    ncrename --history --variable  src_idx,src_address  ${file}
360    ncrename --history --variable  dst_idx,dst_address  ${file}
361    ncrename --history --variable  weight,remap_matrix  ${file}
362    case ${file} in
363        ( *1storder.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  ${file} ;;
364        ( *2ndorder.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order"  ${file} ;;
365    esac
366    ncatted --history --attribute conventions,global,o,c,"SCRIP"   ${file}
367    ncatted --history --attribute normalization,global,o,c,"none"  ${file}
368   
369    case ${file} in
370        ( rmp_*${oce}_to_t${atm}_* )
371        ncatted --history \
372                --attribute title,global,o,c,"Weights ${OCE} to ${ATM}" \
373                --attribute source_grid,global,o,c,"${oce_domain_type}" \
374                --attribute dest_grid,global,o,c,"${atm_domain_type}"   \
375                ${file} 
376        ;;
377        ( rmp_*${atm}_to_*${oce}_* )
378        ncatted --history \
379                --attribute title,global,o,c,"Weights ${ATM} to ${OCE}" \
380                --attribute source_grid,global,o,c,"${atm_domain_type}" \
381                --attribute dest_grid,global,o,c,"${oce_domain_type}"   \
382                ${file}
383        ;;
384    esac
385done
386
387##
388## Add missing variables in rmp files
389## ===========================================================================
390for OGRID in ${ListOCEGRID} ; do
391    for order in ${Listorder} ; do
392        ogrid=${OGRID~}
393        agrid=t
394       
395        file_o_to_a=rmp_${ogrid}${oce}_to_${agrid}${atm}_${order}order.nc
396        file_a_to_o=rmp_${agrid}${atm}_to_${ogrid}${oce}_${order}order.nc
397       
398        cat <<EOF >add_varoce.nco
399defdim ("src_grid_size"   , \$x_grid_${OGRID}.size*\$y_grid_${OGRID}.size) ;
400defdim ("src_grid_corners", 4) ;
401defdim ("src_grid_rank"   , 2) ;
402//
403src_grid_dims[src_grid_rank] = { \$y_grid_${OGRID}.size, \$x_grid_${OGRID}.size } ;
404//
405src_grid_center_lat [src_grid_size] =  0.0d ;
406src_grid_center_lon [src_grid_size] =  0.0d ;
407src_grid_center_lat (:) = nav_lat_grid_${OGRID}(:,:)   ;
408src_grid_center_lon (:) = nav_lon_grid_${OGRID}(:,:)   ;
409//
410src_grid_corner_lat [src_grid_size, src_grid_corners] = 0.0d ;
411src_grid_corner_lon [src_grid_size, src_grid_corners] = 0.0d ;
412src_grid_corner_lat(:,:) = bounds_lat_grid_${OGRID}(:,:,:) ;
413src_grid_corner_lon(:,:) = bounds_lon_grid_${OGRID}(:,:,:) ;
414//
415src_grid_imask [src_grid_size] =    0 ;
416src_grid_area  [src_grid_size] = 0.0d ;
417src_grid_frac  [src_grid_size] = 1.0d ;
418src_grid_imask (:) = 1 - mask_${OGRID}(:,:) ;
419src_grid_imask.int() ;
420src_grid_area  (:) = area_grid_${OGRID}(:,:) ;
421EOF
422
423        ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${file_o_to_a}
424        sed --in-place "s/src_/dst_/g" add_varoce.nco
425        ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${file_a_to_o}
426
427        if [[ ${atm} = ico ]] ; then
428            cat <<EOF >add_varatm.nco
429defdim ("dst_grid_size"   , \$cell.size) ;
430defdim ("dst_grid_corners", 6) ;
431defdim ("dst_grid_rank"   , 2) ;
432//
433dst_grid_dims[dst_grid_rank] = { \$cell.size, 1 } ;
434//
435dst_grid_center_lat [dst_grid_size] =  0.0d ;
436dst_grid_center_lon [dst_grid_size] =  0.0d ;
437dst_grid_center_lat (:) = lat(:)   ;
438dst_grid_center_lon (:) = lon(:)   ;
439//
440dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ;
441dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ;
442dst_grid_corner_lat(:,:) = bounds_lat(:,:) ;
443dst_grid_corner_lon(:,:) = bounds_lon(:,:) ;
444//
445dst_grid_imask [dst_grid_size] =    0 ;
446dst_grid_area  [dst_grid_size] = 0.0d ;
447dst_grid_frac  [dst_grid_size] = 1.0d ;
448dst_grid_imask (:) = 1 - OceMask(0,:) ;
449dst_grid_imask.int() ;
450dst_grid_area  (:) = aire(:) ;
451EOF
452            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_o_to_a}
453            sed --in-place "s/dst_/src_/g" add_varatm.nco
454            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_a_to_o}
455           
456            ncks --alphabetize --history --overwrite  -v 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 ${file_o_to_a} rmp_tmp.nc
457            mv rmp_tmp.nc ${file_o_to_a}
458            ncks --alphabetize --history --overwrite  -v 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 ${file_a_to_o} rmp_tmp.nc
459            mv rmp_tmp.nc ${file_a_to_o}
460
461        fi
462        if [[ ${atm} = lmd ]] ; then
463            cat <<EOF >add_varatm.nco
464defdim ("dst_grid_size"   , \$lon.size*\$lat.size) ;
465defdim ("dst_grid_corners", 4) ;
466defdim ("dst_grid_rank"   , 2) ;
467//
468dst_grid_dims[dst_grid_rank] = { \$lat.size, \$lon.size } ;
469//
470dst_grid_center_lat [dst_grid_size] =  0.0d ;
471dst_grid_center_lon [dst_grid_size] =  0.0d ;
472lat0lon[lat,lon] = lat(:)+0*lon(:) ;
473lon0lat[lat,lon] = lon(:)+0*lat(:) ;
474dst_grid_center_lat (:) = lat0lon(:,:)   ;
475dst_grid_center_lon (:) = lon0lat(:,:)   ;
476//
477//dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ; // Not available for LMDZ lon/lat grid
478//dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ;
479//dst_grid_corner_lat(:,:) = bounds_lat(:,:) ;
480//dst_grid_corner_lon(:,:) = bounds_lon(:,:) ;
481//
482dst_grid_imask [dst_grid_size] =    0 ;
483dst_grid_area  [dst_grid_size] = 0.0d ;
484dst_grid_frac  [dst_grid_size] = 1.0d ;
485dst_grid_imask (:) = 1 - OceMask(0,:,:) ;
486dst_grid_imask.int() ;
487dst_grid_area  (:) = aire(:,:) ;
488dst_grid_frac (:)  = OceFrac(0,:,:) ;
489EOF
490            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_o_to_a}
491            sed --in-place "s/dst/src/g" add_varatm.nco
492            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_a_to_o}
493
494            ncks --alphabetize --history --overwrite  -v 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 ${file_o_to_a} rmp_tmp.nc
495            mv rmp_tmp.nc ${file_o_to_a}
496            ncks --alphabetize --history --overwrite  -v 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 ${file_a_to_o} rmp_tmp.nc
497            mv rmp_tmp.nc ${file_a_to_o}
498
499        fi
500    done
501done
502
503##
504## Save results
505## ===========================================================================
506cp ${ATM}_grid_maskFrom_${OCE}.nc ${SUBMIT_DIR}
507for order in ${Listorder}
508do
509    cp dia_t${oce}_to_t${atm}_${order}order.nc ${SUBMIT_DIR}/dia_t${OCE}_to_t${ATM}_${order}order.nc
510    cp rmp_t${oce}_to_t${atm}_${order}order.nc ${SUBMIT_DIR}/rmp_t${OCE}_to_t${ATM}_${order}order.nc
511    for grid in ${Listocegrid} ; do
512        cp rmp_t${atm}_to_${grid}${oce}_${order}order.nc ${SUBMIT_DIR}/rmp_t${ATM}_to_${grid}${OCE}_${order}order.nc
513        cp dia_t${atm}_to_${grid}${oce}_${order}order.nc ${SUBMIT_DIR}/dia_t${ATM}_to_${grid}${OCE}_${order}order.nc
514    done
515done
516
517##
518## Creates and save auxiliary files for OASIS
519## ===========================================================================
520bash ${SUBMIT_DIR}/CreateOasisGrids.bash --oce ${OCE} --atm ${ATM}
521
522cp areas_${OCE}x${ATM}.nc ${SUBMIT_DIR}
523cp grids_${OCE}x${ATM}.nc ${SUBMIT_DIR}
524cp masks_${OCE}x${ATM}.nc ${SUBMIT_DIR}
525
526
527## ===========================================================================
528##
529##                               That's all folk's !!!
530##
531## ===========================================================================
532
Note: See TracBrowser for help on using the repository browser.