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 |
---|
51 | Comment="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 : |
---|
58 | OceSst=tos #> Variable containing sea surface temperature (°C) : --ocesst tos |
---|
59 | ## Variables in ice file |
---|
60 | IceFrc=ice_pres #> Variable containing sea ice fraction [0-1] : --icefrc ice_pres |
---|
61 | IceAlb=none #> Variable containing sea ice albedo [0-1]. If 'none', set to 0.65 : --icealb ialb |
---|
62 | IceTem=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 |
---|
73 | Fill=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 | |
---|
78 | DefaultIceAlb=0.65 |
---|
79 | DefaultIceTem=-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 | # ================ |
---|
88 | if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi |
---|
89 | |
---|
90 | case ${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 | ;; |
---|
118 | esac |
---|
119 | set -o verbose |
---|
120 | set -o xtrace |
---|
121 | set -e |
---|
122 | |
---|
123 | Nperio="" |
---|
124 | |
---|
125 | while [[ ${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 |
---|
149 | done |
---|
150 | |
---|
151 | # |
---|
152 | # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits |
---|
153 | # --------------------------------------------------------------------------- |
---|
154 | FL_FMT=64bit |
---|
155 | |
---|
156 | ## |
---|
157 | ## Defines associated sea ice file |
---|
158 | ## =========================================================================== |
---|
159 | if [[ -z ${IceFile} ]] ; then IceFile=${OceFile} ; fi |
---|
160 | IceFrcFile=${IceFile} |
---|
161 | IceTemFile=${IceFile} |
---|
162 | IceAlbFile=${IceFile} |
---|
163 | |
---|
164 | ## Select file for each variable |
---|
165 | OceSstFile=${OceFile} |
---|
166 | if [[ ${OceSst} = */ice ]] ; then |
---|
167 | OceSstFile=${IceFile} |
---|
168 | OceSst=${OceSst%%/*} |
---|
169 | fi |
---|
170 | |
---|
171 | |
---|
172 | if [[ ${IceAlb} = */oce ]] ; then |
---|
173 | IceAlbFile=${OceFile} |
---|
174 | IceAlb=${IceFrc%%/*} |
---|
175 | fi |
---|
176 | if [[ ${IceFrc} = */oce ]] ; then |
---|
177 | IceFrcFile=${OceFile} |
---|
178 | IceFrc=${IceFrc%%/*} |
---|
179 | fi |
---|
180 | if [[ ${IceTem} = */oce ]] ; then |
---|
181 | IceTemFile=${OceFile} |
---|
182 | IceTem=${IceTem%%/*} |
---|
183 | fi |
---|
184 | |
---|
185 | |
---|
186 | echo "Oce sst - Variable ${OceSst} - File ${OceSstFile}" |
---|
187 | echo "Ice fraction - Variable ${IceFrc} - File ${IceFrcFile}" |
---|
188 | echo "Ice albedo - Variable ${IceAlb} - File ${IceAlbFile}" |
---|
189 | echo "Ice temperature - Variable ${IceTem} - File ${IcetemFile}" |
---|
190 | |
---|
191 | |
---|
192 | ## |
---|
193 | ## Extract variables |
---|
194 | ## =========================================================================== |
---|
195 | ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceFrc} ${IceFrcFile} sstoce_fields.nc |
---|
196 | ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${OceSst} ${OceSstFile} oce_sst.nc |
---|
197 | |
---|
198 | ncks --append --fl_fmt=${FL_FMT} --history oce_sst.nc sstoce_fields.nc |
---|
199 | if [[ "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 |
---|
202 | fi |
---|
203 | if [[ "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 |
---|
206 | fi |
---|
207 | ncwa --overwrite --fl_fmt=${FL_FMT} --history --average time_counter sstoce_fields.nc sstoce_fields_notime.nc # Remove time dimension |
---|
208 | ncatted --history --attribute history,global,d,c,"" sstoce_fields_notime.nc # Clean attributes |
---|
209 | |
---|
210 | ## |
---|
211 | ## Find ocean name |
---|
212 | ## =========================================================================== |
---|
213 | dim_y=$(ncdump -h sstoce_fields_notime.nc | grep "y *=" | grep -v "nvertex" | awk '{print $3}' ) |
---|
214 | dim_x=$(ncdump -h sstoce_fields_notime.nc | grep "x *=" | grep -v "nvertex" | awk '{print $3}' ) |
---|
215 | echo ${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 | ## =========================================================================== |
---|
225 | cat <<EOF > create_sstoce.nco |
---|
226 | *OceSst[y,x] = double ( ${OceSst}(:,:) + 273.15d ) ; |
---|
227 | OIceFrc[y,x] = double ( ${IceFrc}(:,:) ) ; |
---|
228 | // |
---|
229 | EOF |
---|
230 | |
---|
231 | if [[ "X${IceAlb}" != "Xnone" ]] ; then |
---|
232 | cat <<EOF >> create_sstoce.nco |
---|
233 | *IceAlb[y,x] = double ( ${IceAlb}(:,:) ) ; |
---|
234 | // |
---|
235 | EOF |
---|
236 | else |
---|
237 | cat <<EOF >> create_sstoce.nco |
---|
238 | *IceAlb[y,x] = double ( ${DefaultIceAlb}d ) ; |
---|
239 | // |
---|
240 | EOF |
---|
241 | fi |
---|
242 | |
---|
243 | if [[ "X${IceTem}" != "Xnone" ]] ; then |
---|
244 | cat <<EOF >> create_sstoce.nco |
---|
245 | *IceTem[y,x] = double ( ${IceTem}(:,:) + 273.15d ) ; |
---|
246 | // |
---|
247 | EOF |
---|
248 | else |
---|
249 | cat <<EOF >> create_sstoce.nco |
---|
250 | *IceTem[y,x] = double ( ${DefaultIceTem}d + 273.15d ) ; |
---|
251 | // |
---|
252 | EOF |
---|
253 | fi |
---|
254 | |
---|
255 | cat <<EOF >> create_sstoce.nco |
---|
256 | O_SSTSST[y,x] = OceSst (:,:) * (1.0d-OIceFrc(:,:)) ; |
---|
257 | O_AlbIce[y,x] = IceAlb (:,:) * OIceFrc(:,:) ; |
---|
258 | O_TepIce[y,x] = IceTem (:,:) * OIceFrc(:,:) ; |
---|
259 | O_OCurx1[y,x] = 0.0d ; |
---|
260 | O_OCury1[y,x] = 0.0d ; |
---|
261 | O_OCurz1[y,x] = 0.0d ; |
---|
262 | EOF |
---|
263 | |
---|
264 | ncap2 --overwrite --fl_fmt=${FL_FMT} --history --script-file create_sstoce.nco sstoce_fields_notime.nc tmp_sstoc.nc |
---|
265 | ncks --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 |
---|
266 | ncatted --history --attribute long_name,O_SSTSST,o,c,"SST weighted by fraction of open ocean" sstoc.nc |
---|
267 | ncatted --history --attribute long_name,O_AlbIce,o,c,"Albedo weighted by fraction of sea ice" sstoc.nc |
---|
268 | ncatted --history --attribute long_name,O_TepIce,o,c,"Ice temperature weighted by fraction of sea ice" sstoc.nc |
---|
269 | |
---|
270 | ncatted --history --attribute comment,O_SSTSST,o,c,"Variable ${OceSst} taken in ${OceSstFile}" sstoc.nc |
---|
271 | ncatted --history --attribute comment,OIceFrc,o,c,"Variable ${IceFrc} taken in ${IceFrcFile}" sstoc.nc |
---|
272 | |
---|
273 | if [[ ${IceAlb} = none ]] ; then ncatted --history --attribute comment,O_AlbIce,o,c,"Set to ${DefaultIceAlb}" sstoc.nc |
---|
274 | else ncatted --history --attribute comment,O_AlbIce,o,c,"Variable ${IceAlb} taken in ${IceAlbFile}" sstoc.nc |
---|
275 | fi |
---|
276 | if [[ ${IceTem} = none ]] ; then ncatted --history --attribute comment,O_TepIce,o,c,"Set to ${DefaultIceTem}" sstoc.nc |
---|
277 | else ncatted --history --attribute comment,O_TepIce,o,c,"Variable ${IceTem} taken in ${IceTemFile}" sstoc.nc |
---|
278 | fi |
---|
279 | |
---|
280 | ## |
---|
281 | ## Filling the fields |
---|
282 | ## =========================================================================== |
---|
283 | if [[ ${Fill} = yes ]] ; then |
---|
284 | mv sstoc.nc sstoc_nofilled.nc |
---|
285 | python3 FillOceRestart.py --input sstoc_nofilled.nc --output sstoc.nc ${Nperio} |
---|
286 | fi |
---|
287 | |
---|
288 | ## |
---|
289 | ## Add some information in file header |
---|
290 | ## =========================================================================== |
---|
291 | |
---|
292 | UUID=$(uuid) |
---|
293 | NCO="$(ncks --version |& tail -1|sed 's/ncks //')" |
---|
294 | ncatted --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 | |
---|
326 | mv sstoc.nc sstoc_${OCE}.nc |
---|
327 | |
---|
328 | ## =========================================================================== |
---|
329 | ## |
---|
330 | ## That's all folk's !!! |
---|
331 | ## |
---|
332 | ## =========================================================================== |
---|