source: TOOLS/CPLRESTART/CreateRestartOce4Oasis.bash @ 4289

Last change on this file since 4289 was 4289, checked in by omamce, 5 years ago

O.M. : CPLRESTART

  • Add filling of ocean variable on continents
  • Add more parameters to increase versability
  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 13.0 KB
Line 
1#!/bin/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/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
35#
36# 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
37#
38#
39## ===========================================================================
40##
41## You should not change anything below this line ....
42##
43## ===========================================================================
44
45##
46## Command line parameters
47## ===========================================================================
48# Default values
49Comment="Preliminary attempt - Do not trust !"
50#
51# --ocefile : file in which sea surface temperature is read
52# --icefile : file in which sea ice fraction, albedo and surface temperature are read.
53#             if not specified, these variables are readed in the ocean file
54#
55## Variable in ocean file :
56OceSst=tos      #> Variable containing sea surface temperature (°C) : --ocesst tos
57## Variables in ice file
58IceFrc=ice_pres #> Variable containing sea ice fraction [0-1]       : --icefrc ice_pres
59IceAlb=none     #> Variable containing sea ice albedo [0-1]. If 'none', set to 0.65         : --icealb ialb
60IceTem=none     #> Variable containing sea ice surface temperature (°C). If 'none', set to -20°C : --icetem tsice
61
62# Complementary syntaxes for variables names
63# --icefrc siconc/oce means that siconc variable should be taken in the ocean file ...
64# --icealb ialb/oce
65# --icetem tsice/oce
66
67## Filling
68# If the ocean in the coupled model has a different geometry that the one in the files.
69# In general, the forced ocean does run with no closed sea, when the coupled model does.
70# This step is he mandatory
71Fill=yes # If yes, fill the continents. --fill / --nofill
72
73# 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
74# --nperio 4
75
76DefaultIceAlb=0.65
77DefaultIceTem=-20.0
78
79#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
80#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
81#
82
83#
84# Defines computer
85# ================
86if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi
87
88case ${arch} in
89    ( irene )
90    set +vx
91    module unload cdo nco ferret
92    module unload netcdf hdf5
93    module load python # /2.7.12
94    #module load netcdf/4.3.3.1_hdf5_parallel # Version for XIOS
95    module load nco
96    module load python3
97    R_IN=$(ccc_home -u igcmg --cccwork)/IGCM
98    TMPDIR=${SCRATCHDIR}/TMP
99    SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}}
100    ;;
101    ( * )
102    exit -1
103    ;;
104esac
105set -o verbose
106set -o xtrace
107set -e
108
109Nperio=""
110
111while [[ ${1} = -* ]] ; do
112    case ${1} in
113        ( -- ) shift ; break ;;
114        ( -c   | --comment  ) shift ; Comment=${1}  ;;
115        ( --ocefile         ) shift ; OceFile=${1}  ;;
116        ( --icefile         ) shift ; IceFile=${1}  ;;
117        ( --ocesst          ) shift ; OceSst=${1}   ;;
118        ( --icefrc          ) shift ; IceFrc=${1}   ;;
119        ( --icetem          ) shift ; IceTem=${1}   ;;
120        ( --icealb          ) shift ; IceAlb=${1}   ;;
121        ( --fill            ) Fill="yes" ;;
122        ( --nofill          ) Fill="no"  ;;
123        ( --nperio          ) shift ; Nperio="--nperio ${1}" ;;
124        ( -v | --verbose    ) set -o verbose   ;;
125        ( -x | --xtrace     ) set -o xtrace    ;;
126        ( -xv | -vx         ) set -o xtrace verbose  ;;
127        ( -e                ) set -e           ;;
128        ( -V | --noverbose  ) set +o verbose   ;;
129        ( -X | --noxtrace   ) set +o xtrace    ;;
130        ( -XV | -VX         ) set +o xtrace verbose    ;;
131        ( -E                ) set +e           ;;
132        ( -* ) echo ${Bold}"Unknown option : ${1}"${Norm} ; exit 1 ;;
133    esac
134    shift
135done
136
137#
138# Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits
139# ---------------------------------------------------------------------------
140FL_FMT=64bit
141
142##
143## Defines associated sea ice file
144## ===========================================================================
145if [[ -z ${IceFile} ]] ; then IceFile=${OceFile} ; fi
146IceFrcFile=${IceFile}
147IceTemFile=${IceFile}
148IceAlbFile=${IceFile}
149
150## Select file for each variable
151OceSstFile=${OceFile}
152if [[ ${OceSst} = */ice ]] ; then
153    OceSstFile=${IceFile}
154    OceSst=${OceSst%%/*}
155fi
156
157
158if [[ ${IceAlb} = */oce ]] ; then
159    IceAlbFile=${OceFile}
160    IceAlb=${IceFrc%%/*}
161fi
162if [[ ${IceFrc} = */oce ]] ; then
163    IceFrcFile=${OceFile}
164    IceFrc=${IceFrc%%/*}
165fi
166if [[ ${IceTem} = */oce ]] ; then
167    IceTemFile=${OceFile}
168    IceTem=${IceTem%%/*}
169fi
170
171
172echo "Oce sst         - Variable ${OceSst} - File ${OceSstFile}"
173echo "Ice fraction    - Variable ${IceFrc} - File ${IceFrcFile}"
174echo "Ice albedo      - Variable ${IceAlb} - File ${IceAlbFile}"
175echo "Ice temperature - Variable ${IceTem} - File ${IcetemFile}"
176
177
178##
179## Extract variables
180## ===========================================================================
181ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceFrc} ${IceFrcFile} sstoce_fields.nc
182ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${OceSst} ${OceSstFile} oce_sst.nc
183
184ncks --append    --fl_fmt=${FL_FMT} --history oce_sst.nc   sstoce_fields.nc
185if [[ "X${IceAlb}" != "Xnone" ]] ; then
186    ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceAlb} ${IceAlbFile} ice_alb.nc
187    ncks --append    --fl_fmt=${FL_FMT} --history ice_alb.nc   sstoce_fields.nc
188fi
189if [[ "X${IceTem}" != "Xnone" ]] ; then
190    ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceTem} ${IceTemFile} ice_tem.nc
191    ncks --append    --fl_fmt=${FL_FMT} --history ice_tem.nc   sstoce_fields.nc
192fi
193ncwa --overwrite --fl_fmt=${FL_FMT} --history --average time_counter sstoce_fields.nc sstoce_fields_notime.nc # Remove time dimension
194ncatted --history --attribute history,global,d,c,""  sstoce_fields_notime.nc           # Clean attributes
195
196##
197## Find ocean name
198## ===========================================================================
199dim_y=$(ncdump -h sstoce_fields_notime.nc | grep "y *=" | grep -v "nvertex" | awk '{print $3}' )
200dim_x=$(ncdump -h sstoce_fields_notime.nc | grep "x *=" | grep -v "nvertex" | awk '{print $3}' )
201echo ${dim_x} ${dim_y}
202
203[[ ${dim_x} =  182 && ${dim_y} =  149 ]] && OCE=ORCA2.3
204[[ ${dim_x} =  362 && ${dim_y} =  332 ]] && OCE=eORCA1.2
205[[ ${dim_x} = 1442 && ${dim_y} = 1207 ]] && OCE=eORCA025.1
206
207##
208## Creates sstoce file
209## ===========================================================================
210cat <<EOF > create_sstoce.nco
211*OceSst[y,x]    = double ( ${OceSst}(:,:) + 273.15d ) ;
212OIceFrc[y,x]   = double ( ${IceFrc}(:,:) ) ;
213//
214EOF
215
216if [[ "X${IceAlb}" != "Xnone" ]] ; then
217    cat <<EOF >> create_sstoce.nco
218*IceAlb[y,x]  = double ( ${IceAlb}(:,:) ) ;
219//
220EOF
221else
222     cat <<EOF >> create_sstoce.nco
223*IceAlb[y,x] = double ( ${DefaultIceAlb}d ) ;
224//
225EOF
226fi
227
228if [[ "X${IceTem}" != "Xnone" ]] ; then
229    cat <<EOF >> create_sstoce.nco
230*IceTem[y,x] = double ( ${IceTem}(:,:) + 273.15d ) ;
231//
232EOF
233else
234     cat <<EOF >> create_sstoce.nco
235*IceTem[y,x] = double ( ${DefaultIceTem}d + 273.15d ) ;
236//
237EOF
238fi
239
240cat <<EOF >>  create_sstoce.nco
241O_SSTSST[y,x]  = OceSst (:,:) * (1.0d-OIceFrc(:,:)) ;
242O_AlbIce[y,x]  = IceAlb (:,:)       * OIceFrc(:,:)  ;
243O_TepIce[y,x]  = IceTem (:,:)       * OIceFrc(:,:)  ;
244O_OCurx1[y,x]  = 0.0d ;
245O_OCury1[y,x]  = 0.0d ;
246O_OCurz1[y,x]  = 0.0d ;
247EOF
248
249ncap2 --overwrite --fl_fmt=${FL_FMT} --history --script-file create_sstoce.nco sstoce_fields_notime.nc tmp_sstoc.nc
250ncks --fl_fmt=${FL_FMT} --overwrite --history --variable OIceFrc,O_SSTSST,O_AlbIce,O_TepIce,O_OCurx1,O_OCury1,O_OCurz1 tmp_sstoc.nc sstoc.nc
251ncatted --history --attribute long_name,O_SSTSST,o,c,"SST weighted by fraction of open ocean"          sstoc.nc
252ncatted --history --attribute long_name,O_AlbIce,o,c,"Albedo weighted by fraction of sea ice"          sstoc.nc
253ncatted --history --attribute long_name,O_TepIce,o,c,"Ice temperature weighted by fraction of sea ice" sstoc.nc
254
255ncatted --history --attribute comment,O_SSTSST,o,c,"Variable ${OceSst} taken in ${OceSstFile}"  sstoc.nc
256ncatted --history --attribute comment,OIceFrc,o,c,"Variable ${IceFrc} taken in ${IceFrcFile}"   sstoc.nc
257
258if [[ ${IceAlb} = none ]] ; then  ncatted --history --attribute comment,O_AlbIce,o,c,"Set to ${DefaultIceAlb}"  sstoc.nc
259else                              ncatted --history --attribute comment,O_AlbIce,o,c,"Variable ${IceAlb} taken in ${IceAlbFile}"  sstoc.nc
260fi
261if [[ ${IceTem} = none ]] ; then  ncatted --history --attribute comment,O_TepIce,o,c,"Set to ${DefaultIceTem}"  sstoc.nc
262else                              ncatted --history --attribute comment,O_TepIce,o,c,"Variable ${IceTem} taken in ${IceTemFile}"  sstoc.nc
263fi
264
265##
266## Filling the fields
267## ===========================================================================
268if [[ ${Fill} = yes ]] ; then
269    mv sstoc.nc sstoc_nofilled.nc
270    python3 FillOceRestart.py --input sstoc_nofilled.nc --output sstoc.nc ${Nperio}
271fi
272
273##
274## Add some information in file header
275## ===========================================================================
276
277UUID=$(uuid)
278NCO="$(ncks --version |& tail -1|sed 's/ncks //')"
279ncatted --history \
280        --attribute nco_openmp_thread_number,global,d,,                       \
281        --attribute source,global,o,c,"IPSL Earth system model"               \
282        --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center"     \
283        --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr"         \
284        --attribute Model,global,o,c,"${OCE} https://www.nemo-ocean.eu"       \
285        --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}')" \
286        --attribute originalFiles,global,o,c,"${OceFile} ${IceFile}"          \
287        --attribute directory,global,o,c,"$(pwd)"                             \
288        --attribute description,global,o,c,"Fields needed by OASIS-MCT"       \
289        --attribute timeStamp,global,o,c,"$(date)"                            \
290        --attribute uuid,global,o,c,"${UUID}"                                 \
291        --attribute Program,global,o,c,"Generated by ${0}"                    \
292        --attribute HOSTNAME,global,o,c,"$(hostname)"                         \
293        --attribute LOGNAME,global,o,c,"$(whoami)"                            \
294        --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \
295        --attribute OS,global,o,c,"$(uname -o)"                               \
296        --attribute release,global,o,c,"$(uname -r)"                          \
297        --attribute hardware,global,o,c,"$(uname -i)"                         \
298        --attribute directory,global,o,c,"$(pwd)"                             \
299        --attribute Comment,global,o,c,"${Comment}"                           \
300        --attribute SVN_Author,global,o,c,"$Author$"                 \
301        --attribute SVN_Date,global,o,c,"$Date$" \
302        --attribute SVN_Revision,global,o,c,"$Revision$"               \
303        --attribute SVN_Id,global,o,c,"$Id$" \
304        sstoc.nc
305
306##
307## Cleaning
308## ===========================================================================
309#rm -f sstoce_fields.nc sstoce_fields_notime.nc tmp_sstoce.nc oce_fields.nc
310
311mv sstoc.nc sstoc_${OCE}.nc
312
313## ===========================================================================
314##
315##                               That's all folk's !!!
316##
317## ===========================================================================
Note: See TracBrowser for help on using the repository browser.