source: TOOLS/MOSAIX/CreateWeightsMask.bash @ 3671

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

O.M. : mise a jour des properties

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