source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 3686

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

O.M. : correct OIceFrc variable name.
More documentation

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