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/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 |
---|
49 | Comment="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 : |
---|
56 | OceSst=tos #> Variable containing sea surface temperature (°C) : --ocesst tos |
---|
57 | ## Variables in ice file |
---|
58 | IceFrc=ice_pres #> Variable containing sea ice fraction [0-1] : --icefrc ice_pres |
---|
59 | IceAlb=none #> Variable containing sea ice albedo [0-1]. If 'none', set to 0.65 : --icealb ialb |
---|
60 | IceTem=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 |
---|
71 | Fill=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 | |
---|
76 | DefaultIceAlb=0.65 |
---|
77 | DefaultIceTem=-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 | # ================ |
---|
86 | if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi |
---|
87 | |
---|
88 | case ${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 | ;; |
---|
104 | esac |
---|
105 | set -o verbose |
---|
106 | set -o xtrace |
---|
107 | set -e |
---|
108 | |
---|
109 | Nperio="" |
---|
110 | |
---|
111 | while [[ ${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 |
---|
135 | done |
---|
136 | |
---|
137 | # |
---|
138 | # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits |
---|
139 | # --------------------------------------------------------------------------- |
---|
140 | FL_FMT=64bit |
---|
141 | |
---|
142 | ## |
---|
143 | ## Defines associated sea ice file |
---|
144 | ## =========================================================================== |
---|
145 | if [[ -z ${IceFile} ]] ; then IceFile=${OceFile} ; fi |
---|
146 | IceFrcFile=${IceFile} |
---|
147 | IceTemFile=${IceFile} |
---|
148 | IceAlbFile=${IceFile} |
---|
149 | |
---|
150 | ## Select file for each variable |
---|
151 | OceSstFile=${OceFile} |
---|
152 | if [[ ${OceSst} = */ice ]] ; then |
---|
153 | OceSstFile=${IceFile} |
---|
154 | OceSst=${OceSst%%/*} |
---|
155 | fi |
---|
156 | |
---|
157 | |
---|
158 | if [[ ${IceAlb} = */oce ]] ; then |
---|
159 | IceAlbFile=${OceFile} |
---|
160 | IceAlb=${IceFrc%%/*} |
---|
161 | fi |
---|
162 | if [[ ${IceFrc} = */oce ]] ; then |
---|
163 | IceFrcFile=${OceFile} |
---|
164 | IceFrc=${IceFrc%%/*} |
---|
165 | fi |
---|
166 | if [[ ${IceTem} = */oce ]] ; then |
---|
167 | IceTemFile=${OceFile} |
---|
168 | IceTem=${IceTem%%/*} |
---|
169 | fi |
---|
170 | |
---|
171 | |
---|
172 | echo "Oce sst - Variable ${OceSst} - File ${OceSstFile}" |
---|
173 | echo "Ice fraction - Variable ${IceFrc} - File ${IceFrcFile}" |
---|
174 | echo "Ice albedo - Variable ${IceAlb} - File ${IceAlbFile}" |
---|
175 | echo "Ice temperature - Variable ${IceTem} - File ${IcetemFile}" |
---|
176 | |
---|
177 | |
---|
178 | ## |
---|
179 | ## Extract variables |
---|
180 | ## =========================================================================== |
---|
181 | ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceFrc} ${IceFrcFile} sstoce_fields.nc |
---|
182 | ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${OceSst} ${OceSstFile} oce_sst.nc |
---|
183 | |
---|
184 | ncks --append --fl_fmt=${FL_FMT} --history oce_sst.nc sstoce_fields.nc |
---|
185 | if [[ "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 |
---|
188 | fi |
---|
189 | if [[ "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 |
---|
192 | fi |
---|
193 | ncwa --overwrite --fl_fmt=${FL_FMT} --history --average time_counter sstoce_fields.nc sstoce_fields_notime.nc # Remove time dimension |
---|
194 | ncatted --history --attribute history,global,d,c,"" sstoce_fields_notime.nc # Clean attributes |
---|
195 | |
---|
196 | ## |
---|
197 | ## Find ocean name |
---|
198 | ## =========================================================================== |
---|
199 | dim_y=$(ncdump -h sstoce_fields_notime.nc | grep "y *=" | grep -v "nvertex" | awk '{print $3}' ) |
---|
200 | dim_x=$(ncdump -h sstoce_fields_notime.nc | grep "x *=" | grep -v "nvertex" | awk '{print $3}' ) |
---|
201 | echo ${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 | ## =========================================================================== |
---|
210 | cat <<EOF > create_sstoce.nco |
---|
211 | *OceSst[y,x] = double ( ${OceSst}(:,:) + 273.15d ) ; |
---|
212 | OIceFrc[y,x] = double ( ${IceFrc}(:,:) ) ; |
---|
213 | // |
---|
214 | EOF |
---|
215 | |
---|
216 | if [[ "X${IceAlb}" != "Xnone" ]] ; then |
---|
217 | cat <<EOF >> create_sstoce.nco |
---|
218 | *IceAlb[y,x] = double ( ${IceAlb}(:,:) ) ; |
---|
219 | // |
---|
220 | EOF |
---|
221 | else |
---|
222 | cat <<EOF >> create_sstoce.nco |
---|
223 | *IceAlb[y,x] = double ( ${DefaultIceAlb}d ) ; |
---|
224 | // |
---|
225 | EOF |
---|
226 | fi |
---|
227 | |
---|
228 | if [[ "X${IceTem}" != "Xnone" ]] ; then |
---|
229 | cat <<EOF >> create_sstoce.nco |
---|
230 | *IceTem[y,x] = double ( ${IceTem}(:,:) + 273.15d ) ; |
---|
231 | // |
---|
232 | EOF |
---|
233 | else |
---|
234 | cat <<EOF >> create_sstoce.nco |
---|
235 | *IceTem[y,x] = double ( ${DefaultIceTem}d + 273.15d ) ; |
---|
236 | // |
---|
237 | EOF |
---|
238 | fi |
---|
239 | |
---|
240 | cat <<EOF >> create_sstoce.nco |
---|
241 | O_SSTSST[y,x] = OceSst (:,:) * (1.0d-OIceFrc(:,:)) ; |
---|
242 | O_AlbIce[y,x] = IceAlb (:,:) * OIceFrc(:,:) ; |
---|
243 | O_TepIce[y,x] = IceTem (:,:) * OIceFrc(:,:) ; |
---|
244 | O_OCurx1[y,x] = 0.0d ; |
---|
245 | O_OCury1[y,x] = 0.0d ; |
---|
246 | O_OCurz1[y,x] = 0.0d ; |
---|
247 | EOF |
---|
248 | |
---|
249 | ncap2 --overwrite --fl_fmt=${FL_FMT} --history --script-file create_sstoce.nco sstoce_fields_notime.nc tmp_sstoc.nc |
---|
250 | 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 |
---|
251 | ncatted --history --attribute long_name,O_SSTSST,o,c,"SST weighted by fraction of open ocean" sstoc.nc |
---|
252 | ncatted --history --attribute long_name,O_AlbIce,o,c,"Albedo weighted by fraction of sea ice" sstoc.nc |
---|
253 | ncatted --history --attribute long_name,O_TepIce,o,c,"Ice temperature weighted by fraction of sea ice" sstoc.nc |
---|
254 | |
---|
255 | ncatted --history --attribute comment,O_SSTSST,o,c,"Variable ${OceSst} taken in ${OceSstFile}" sstoc.nc |
---|
256 | ncatted --history --attribute comment,OIceFrc,o,c,"Variable ${IceFrc} taken in ${IceFrcFile}" sstoc.nc |
---|
257 | |
---|
258 | if [[ ${IceAlb} = none ]] ; then ncatted --history --attribute comment,O_AlbIce,o,c,"Set to ${DefaultIceAlb}" sstoc.nc |
---|
259 | else ncatted --history --attribute comment,O_AlbIce,o,c,"Variable ${IceAlb} taken in ${IceAlbFile}" sstoc.nc |
---|
260 | fi |
---|
261 | if [[ ${IceTem} = none ]] ; then ncatted --history --attribute comment,O_TepIce,o,c,"Set to ${DefaultIceTem}" sstoc.nc |
---|
262 | else ncatted --history --attribute comment,O_TepIce,o,c,"Variable ${IceTem} taken in ${IceTemFile}" sstoc.nc |
---|
263 | fi |
---|
264 | |
---|
265 | ## |
---|
266 | ## Filling the fields |
---|
267 | ## =========================================================================== |
---|
268 | if [[ ${Fill} = yes ]] ; then |
---|
269 | mv sstoc.nc sstoc_nofilled.nc |
---|
270 | python3 FillOceRestart.py --input sstoc_nofilled.nc --output sstoc.nc ${Nperio} |
---|
271 | fi |
---|
272 | |
---|
273 | ## |
---|
274 | ## Add some information in file header |
---|
275 | ## =========================================================================== |
---|
276 | |
---|
277 | UUID=$(uuid) |
---|
278 | NCO="$(ncks --version |& tail -1|sed 's/ncks //')" |
---|
279 | ncatted --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 | |
---|
311 | mv sstoc.nc sstoc_${OCE}.nc |
---|
312 | |
---|
313 | ## =========================================================================== |
---|
314 | ## |
---|
315 | ## That's all folk's !!! |
---|
316 | ## |
---|
317 | ## =========================================================================== |
---|