source: TOOLS/CPLRESTART/CreateRestartOce4Oasis.bash

Last change on this file was 6669, checked in by omamce, 6 months ago

O.M. : CPLRESTART

  • More comments
  • Python cleanup
  • More use of nemo.py functionalities
  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 15.2 KB
Line 
1#!/usr/bin/env bash
2### ===========================================================================
3###
4### Creates initial state for coupler, ocean side
5### Take data from NEMO grid_T and icemod files
6###
7### ===========================================================================
8##
9##  Warning, to install, configure, run, use any of Olivier Marti's
10##  software or to read the associated documentation you'll need at least
11##  one (1) brain in a reasonably working order. Lack of this implement
12##  will void any warranties (either express or implied).
13##  O. Marti assumes no responsability for errors, omissions,
14##  data loss, or any other consequences caused directly or indirectly by
15##  the usage of his software by incorrectly or partially configured
16##  personal.
17##
18###
19### Documentation : https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX
20###
21## SVN information
22#  $Author$
23#  $Date$
24#  $Revision$
25#  $Id$
26#  $HeadURL$
27
28## Usage exemples :
29#
30# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/OCE/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_grid_T.nc --icefile /ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/ICE/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_icemod.nc --icefrc ice_pres --icetem tsice --icealb ialb
31
32# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/gencmip6/p86mart/IGCM_OUT/IPSLCM6/DEVT/pdControl/CM6010.2.rivgeo-LR-pdCtrl/OCE/Output/MO/CM6010.2.rivgeo-LR-pdCtrl_22400101_22491231_1M_grid_T.nc  --icefrc siconc
33
34# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/gencmip6/p86maf/IGCM_OUT/IPSLCM6/PROD/piControl/CM61-LR-pi-03/OCE/Output/MO/CM61-LR-pi-03_23400101_23491231_1M_grid_T.nc --icefile /ccc/store/cont003/gencmip6/p86maf/IGCM_OUT/IPSLCM6/PROD/piControl/CM61-LR-pi-03/ICE/Output/MO/CM61-LR-pi-03_23400101_23491231_1M_icemod.nc --icefrc siconc
35
36# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/gen7451/personr/IGCM_OUT/ORCA025_LIM3_PISCES/DEVT/ORCA025ia/eOR025L3P-IA-REF07-MUSCL/OCE/Output/MO/eOR025L3P-IA-REF07-MUSCL_20090101_20091231_1M_grid_T.nc
37
38# CreateRestartOce4Oasis.bash --ocefile /ccc/work/cont003/gencmip6/p48ethe/ICMC-TOOLS/DATA/eOR025L3P-IA-REF07-MUSCL_20090101_20091231_1M_grid_T.nc --icefile /ccc/work/cont003/gencmip6/p48ethe/ICMC-TOOLS/DATA/eOR025L3P-IA-REF07-MUSCL_20090101_20091231_1M_icemod.nc --icefrc siconc/oce --icetem sistem
39#
40#
41## ===========================================================================
42##
43## You should not change anything below this line ....
44##
45## ===========================================================================
46
47## Creates colors for petty prints
48## ===============================
49export Bold=$(tput bold)
50export Unde=$(tput smul) ; export OffUnde=$(tput rmul)
51export Stou=$(tput smso) ; export OffStou=$(tput rmso)
52export Reve=$(tput rev )
53declare -a couleurs=( "Black" "Blue" "Green" "Cyan" "Red" "Magenta" "Yellow" "White" )
54[[ "${bash_debug}" = "true" ]] && echod ".bash_login Couleurs : ${couleurs[*]}"
55[[ "${bash_debug}" = "true" ]] && echod "Demmarrage de la boucle"
56for i in $(seq 1 7)
57do
58    [[ "${bash_debug}" = "true" ]] && echod i:${i}
59    [[ "${bash_debug}" = "true" ]] && echod ".bashrc Couleur ${i} : ${couleurs[${i}]}"
60    eval "export ${couleurs[$i]}=$(tput setf $i)"
61    eval "export ${couleurs[$i]}F=$(tput setb $i)"         
62done
63export Norm=$(tput sgr0 )
64##
65## Command line parameters
66## ===========================================================================
67# Default values
68Comment="Preliminary attempt - Do not trust !"
69#
70# --ocefile : file in which sea surface temperature is read
71# --icefile : file in which sea ice fraction, albedo and ice surface temperature are read.
72#             if not specified, these variables are readed in the ocean file
73#
74## Variable in ocean file :
75OceSst=tos      #> Variable containing sea surface temperature (°C) : --ocesst tos
76## Variables in ice file
77IceFrc=ice_pres #> Variable containing sea ice fraction [0-1]       : --icefrc ice_pres
78IceAlb=none     #> Variable containing sea ice albedo [0-1]. If 'none', set to 0.65         : --icealb ialb
79IceTem=none     #> Variable containing sea ice surface temperature (°C). If 'none', set to -20°C : --icetem tsice
80
81# Complementary syntaxes for variables names
82# --icefrc siconc/oce means that siconc variable should be taken in the ocean file ...
83# --icealb ialb/oce
84# --icetem tsice/oce
85
86## Filling
87# If the ocean in the coupled model has a different geometry that the one in the files.
88# In general, the forced ocean does run with no closed sea, when the coupled model does.
89# This step is he mandatory
90Fill=yes # If yes, fill the continents. --fill / --nofill
91
92# nperio parameter for ORCA. Normally guess from name or dimensions. For ORCA2, set to nperio=4, but should be set to nperio=6 for some paleo configs
93# --nperio 4
94
95DefaultIceAlb=0.65
96DefaultIceTem=-20.0
97
98#OceFile=/ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/OCE/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_grid_T.nc
99#OceFile=/ccc/store/cont003/gencmip6/p86mart/IGCM_OUT/IPSLCM6/DEVT/pdControl/CM6010.2.rivgeo-LR-pdCtrl/OCE/Output/MO/CM6010.2.rivgeo-LR-pdCtrl_22400101_22491231_1M_grid_T.nc
100#
101
102#
103# Defines computer
104# ================
105if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi
106
107case ${arch} in
108    ( irene )
109    set +e
110    R_IN=$(ccc_home -u igcmg --cccwork)/IGCM
111    TMPDIR=$(ccc_home --cccwork)/TMP/CPLRESTART
112    SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}}
113    MpiRun="time ccc_mprun"
114    PyRun="time ccc_mprun -n 1" # Needed to force python to run on one process only
115    source $(ccc_home -u igcmg)/MachineEnvironment/irene/env_atlas_irene
116    set -e
117    ;;
118    ( spip )
119    R_IN=${HOME}/Scratch/IGCM
120    TMPDIR=${HOME}/Scratch/TMP
121    SUBMIT_DIR=$(pwd)
122    MpiRun="/opt/local/bin/mpirun -n 1"
123    PyRun="time"
124    ;;
125    ( * )
126    exit -1
127    ;;
128esac
129
130Nperio=''
131bVerbose='Yes'
132bXtrace='Yes'
133bError='Yes'
134Fill='yes'
135
136while [[ ${1} = -* || ${1} = +* ]] ; do
137    case ${1} in
138        ( -- ) shift ; break ;;
139        ( -c   | --comment  ) shift ; Comment=${1}  ;;
140        ( --ocefile         ) shift ; OceFile=${1}  ;;
141        ( --icefile         ) shift ; IceFile=${1}  ;;
142        ( --ocesst          ) shift ; OceSst=${1}   ;;
143        ( --icefrc          ) shift ; IceFrc=${1}   ;;
144        ( --icetem          ) shift ; IceTem=${1}   ;;
145        ( --icealb          ) shift ; IceAlb=${1}   ;;
146        ( --fill            ) Fill="yes" ;;
147        ( --nofill          ) Fill="no"  ;;
148        ( --nperio          ) shift ; Nperio="--nperio ${1}" ;;
149        ( -v | --verbose    ) bVerbose='Yes'   ;;
150        ( -x | --xtrace     ) bXtrace='Yes'    ;;
151        ( -xv | -vx         ) bVerbose='Yes' ; bXtrace='Yes' ;;
152        ( -e                ) bError='Yes'     ;;
153        ( -V | +v | --noverbose  ) bVerbose='No'  ;;
154        ( -X | +x | --noxtrace   ) bXtrace='No'   ;;
155        ( -XV | -VX | +vx | +xv  ) bVerbose='No'; bXtrace='No' ;;
156        ( -E | +e           ) bError='No'    ;;
157        ( -* ) echo ${Bold}${Red}"Unknown option : ${1}"${Norm} ; exit 1 ;;
158    esac
159    shift
160done
161
162[[ "X${bVerbose}" = "XYes"  ]] && set -o verbose
163[[ "X${bVerbose}" = "XNo"   ]] && set +o verbose
164[[ "X${bXtrace}"  = "XYes"  ]] && set -o xtrace
165[[ "X${bXtrace}"  = "XNo"   ]] && set +o xtrace
166[[ "X${bError}"   = "XYes"  ]] && set -o errexit
167[[ "X${bError}"   = "XNo"   ]] && set +o errexit
168#
169# Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits
170# ---------------------------------------------------------------------------
171FL_FMT=64bit
172
173##
174## Defines associated sea ice file
175## ===========================================================================
176if [[ -z ${IceFile} ]] ; then IceFile=${OceFile} ; fi
177IceFrcFile=${IceFile}
178IceTemFile=${IceFile}
179IceAlbFile=${IceFile}
180
181## Select file for each variable
182OceSstFile=${OceFile}
183if [[ ${OceSst} = */ice ]] ; then
184    OceSstFile=${IceFile}
185    OceSst=${OceSst%%/*}
186fi
187
188
189if [[ ${IceAlb} = */oce ]] ; then
190    IceAlbFile=${OceFile}
191    IceAlb=${IceFrc%%/*}
192fi
193if [[ ${IceFrc} = */oce ]] ; then
194    IceFrcFile=${OceFile}
195    IceFrc=${IceFrc%%/*}
196fi
197if [[ ${IceTem} = */oce ]] ; then
198    IceTemFile=${OceFile}
199    IceTem=${IceTem%%/*}
200fi
201
202
203echo ${Blue}"Oce sst         - Variable ${OceSst} - File ${OceSstFile}"${Norm}
204echo ${Blue}"Ice fraction    - Variable ${IceFrc} - File ${IceFrcFile}"${Norm}
205echo ${Blue}"Ice albedo      - Variable ${IceAlb} - File ${IceAlbFile}"${Norm}
206echo ${Blue}"Ice temperature - Variable ${IceTem} - File ${IcetemFile}"${Norm}
207
208
209if [[ ! -f ${OceSstFile} ]] ; then
210    echo ${Red}"Not found : ${OceSstFile}"${Norm}
211fi
212
213if [[ ! -f ${IceFrcFile} ]] ; then
214    echo ${Red}"Not found : ${IceFrcFile}"${Norm}
215fi
216
217##
218## Extract variables
219## ===========================================================================
220ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceFrc} ${IceFrcFile} ${TMPDIR}/sstoce_fields.nc
221ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${OceSst} ${OceSstFile} ${TMPDIR}/oce_sst.nc
222
223ncks --append    --fl_fmt=${FL_FMT} --history ${TMPDIR}/oce_sst.nc ${TMPDIR}/sstoce_fields.nc
224if [[ "X${IceAlb}" != "Xnone" ]] ; then
225    ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceAlb} ${IceAlbFile} ${TMPDIR}/ice_alb.nc
226    ncks --append    --fl_fmt=${FL_FMT} --history ${TMPDIR}/ice_alb.nc ${TMPDIR}/sstoce_fields.nc
227fi
228if [[ "X${IceTem}" != "Xnone" ]] ; then
229    ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceTem} ${IceTemFile} ${TMPDIR}/ice_tem.nc
230    ncks --append    --fl_fmt=${FL_FMT} --history ${TMPDIR}/ice_tem.nc ${TMPDIR}/sstoce_fields.nc
231fi
232
233#
234## Remove time dimension
235## ===========================================================================
236
237ncwa --overwrite --fl_fmt=${FL_FMT} --history --average time_counter ${TMPDIR}/sstoce_fields.nc ${TMPDIR}/sstoce_fields_notime.nc
238
239# Clean attributes
240ncatted --history --attribute history,global,d,c,"" ${TMPDIR}/sstoce_fields_notime.nc
241
242##
243## Find ocean name
244## ===========================================================================
245dim_y=$(ncdump -h ${TMPDIR}/sstoce_fields_notime.nc | grep "y *=" | grep -v "nvertex" | awk '{print $3}' )
246dim_x=$(ncdump -h ${TMPDIR}/sstoce_fields_notime.nc | grep "x *=" | grep -v "nvertex" | awk '{print $3}' )
247echo ${dim_x} ${dim_y}
248
249[[ ${dim_x} =  182 && ${dim_y} =  149 ]] && OCE=ORCA2.3
250[[ ${dim_x} =  362 && ${dim_y} =  332 ]] && OCE=eORCA1.2
251[[ ${dim_x} =  360 && ${dim_y} =  331 ]] && OCE=eORCA1.4
252[[ ${dim_x} = 1442 && ${dim_y} = 1207 ]] && OCE=eORCA025.1
253
254##
255## Creates sstoce file
256## ===========================================================================
257cat <<EOF > ${TMPDIR}/create_sstoce.nco
258*OceSst[y,x] = double ( ${OceSst}(:,:) + 273.15d ) ;
259OIceFrc[y,x] = double ( ${IceFrc}(:,:) ) ;
260//
261EOF
262
263if [[ "X${IceAlb}" != "Xnone" ]] ; then
264    cat <<EOF >> ${TMPDIR}/create_sstoce.nco
265*IceAlb[y,x] = double ( ${IceAlb}(:,:) ) ;
266//
267EOF
268else
269     cat <<EOF >> ${TMPDIR}/create_sstoce.nco
270*IceAlb[y,x] = double ( ${DefaultIceAlb}d ) ;
271//
272EOF
273fi
274
275if [[ "X${IceTem}" != "Xnone" ]] ; then
276    cat <<EOF >> ${TMPDIR}/create_sstoce.nco
277*IceTem[y,x] = double ( ${IceTem}(:,:) + 273.15d ) ;
278//
279EOF
280else
281     cat <<EOF >> ${TMPDIR}/create_sstoce.nco
282*IceTem[y,x] = double ( ${DefaultIceTem}d + 273.15d ) ;
283//
284EOF
285fi
286
287cat <<EOF >>  ${TMPDIR}/create_sstoce.nco
288O_SSTSST[y,x] = OceSst (:,:) * (1.0d-OIceFrc(:,:)) ;
289O_AlbIce[y,x] = IceAlb (:,:)       * OIceFrc(:,:)  ;
290O_TepIce[y,x] = IceTem (:,:)       * OIceFrc(:,:)  ;
291O_OCurx1[y,x] = 0.0d ;
292O_OCury1[y,x] = 0.0d ;
293O_OCurz1[y,x] = 0.0d ;
294EOF
295
296ncap2 --overwrite --fl_fmt=${FL_FMT} --history --script-file ${TMPDIR}/create_sstoce.nco ${TMPDIR}/sstoce_fields_notime.nc ${TMPDIR}/tmp_sstoc.nc
297ncks --fl_fmt=${FL_FMT} --overwrite --history --variable OIceFrc,O_SSTSST,O_AlbIce,O_TepIce,O_OCurx1,O_OCury1,O_OCurz1 ${TMPDIR}/tmp_sstoc.nc ${TMPDIR}/sstoc.nc
298ncatted --history --attribute long_name,O_SSTSST,o,c,"SST weighted by fraction of open ocean"          ${TMPDIR}/sstoc.nc
299ncatted --history --attribute long_name,O_AlbIce,o,c,"Albedo weighted by fraction of sea ice"          ${TMPDIR}/sstoc.nc
300ncatted --history --attribute long_name,O_TepIce,o,c,"Ice temperature weighted by fraction of sea ice" ${TMPDIR}/sstoc.nc
301
302ncatted --history --attribute comment,O_SSTSST,o,c,"Variable ${OceSst} taken in ${OceSstFile}"  ${TMPDIR}/sstoc.nc
303ncatted --history --attribute comment,OIceFrc,o,c,"Variable ${IceFrc} taken in ${IceFrcFile}"   ${TMPDIR}/sstoc.nc
304
305if [[ ${IceAlb} = none ]] ; then
306    ncatted --history --attribute comment,O_AlbIce,o,c,"Set to ${DefaultIceAlb}"  ${TMPDIR}/sstoc.nc
307else
308    ncatted --history --attribute comment,O_AlbIce,o,c,"Variable ${IceAlb} taken in ${IceAlbFile}"  ${TMPDIR}/sstoc.nc
309fi
310
311if [[ ${IceTem} = none ]] ; then
312    ncatted --history --attribute comment,O_TepIce,o,c,"Set to ${DefaultIceTem}"  ${TMPDIR}/sstoc.nc
313else
314    ncatted --history --attribute comment,O_TepIce,o,c,"Variable ${IceTem} taken in ${IceTemFile}" ${TMPDIR}/sstoc.nc
315fi
316
317##
318## Filling the fields
319## ===========================================================================
320if [[ ${Fill} = yes ]] ; then
321    mv  ${TMPDIR}/sstoc.nc  ${TMPDIR}/sstoc_nofilled.nc
322    python3 FillOceRestart.py --input ${TMPDIR}/sstoc_nofilled.nc --output ${TMPDIR}/sstoc.nc ${Nperio}
323fi
324
325##
326## Add some information in file header
327## ===========================================================================
328
329UUID=$(uuid)
330NCO="$(ncks --version |& tail -1|sed 's/ncks //')"
331ncatted --history \
332        --attribute nco_openmp_thread_number,global,d,,                       \
333        --attribute source,global,o,c,"IPSL Earth system model"               \
334        --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center"     \
335        --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr"         \
336        --attribute Model,global,o,c,"${OCE} https://www.nemo-ocean.eu"       \
337        --attribute originalFiles,global,o,c,"${OceFile} ${IceFile}"          \
338        --attribute directory,global,o,c,"$(pwd)"                             \
339        --attribute description,global,o,c,"Fields needed by OASIS-MCT"       \
340        --attribute timeStamp,global,o,c,"$(date)"                            \
341        --attribute uuid,global,o,c,"${UUID}"                                 \
342        --attribute Program,global,o,c,"Generated by ${0}"                    \
343        --attribute HOSTNAME,global,o,c,"$(hostname)"                         \
344        --attribute LOGNAME,global,o,c,"$(whoami)"                            \
345        --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \
346        --attribute OS,global,o,c,"$(uname -o)"                               \
347        --attribute release,global,o,c,"$(uname -r)"                          \
348        --attribute hardware,global,o,c,"$(uname -i)"                         \
349        --attribute directory,global,o,c,"$(pwd)"                             \
350        --attribute Comment,global,o,c,"${Comment}"                           \
351        --attribute SVN_Author,global,o,c,"$Author$"                 \
352        --attribute SVN_Date,global,o,c,"$Date$" \
353        --attribute SVN_Revision,global,o,c,"$Revision$"               \
354        --attribute SVN_Id,global,o,c,"$Id$" \
355         ${TMPDIR}/sstoc.nc
356
357##
358## Cleaning
359## ===========================================================================
360#rm -f sstoce_fields.nc sstoce_fields_notime.nc tmp_sstoce.nc oce_fields.nc
361
362mv ${TMPDIR}/sstoc.nc ${TMPDIR}/sstoc_${OCE}.nc
363
364##
365
366echo ${Blue}"TMPDIR : ${TMPDIR}"${Norm}
367## ===========================================================================
368##
369##                               That's all folk's !!!
370##
371## ===========================================================================
Note: See TracBrowser for help on using the repository browser.