source: TOOLS/CPLRESTART/CreateRestartOce4Oasis.bash @ 6446

Last change on this file since 6446 was 6228, checked in by omamce, 22 months ago

O.M. : CPLRESTART
Switch complexe nco script to python

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