source: TOOLS/CPLRESTART/CreateRestartOce4Oasis.bash @ 4249

Last change on this file since 4249 was 4249, checked in by cetlod, 5 years ago

CPLRestart: update cplrestart tools for New NEMO files

  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 8.3 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# CreateRestartOce4Oasis.bash /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/ccc/store/c# CreateRestartOce4Oasis.bash /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
30## ===========================================================================
31##
32## You should not change anything below this line ....
33##
34## ===========================================================================
35
36##
37## Command line parameters
38## ===========================================================================
39# Default values
40Comment="Preliminary attempt - Do not trust !"
41##IceVar=ice_pres # siconc #> Variable containing sea ice fraction [0-1]
42IceVar=siconc #> Variable containing sea ice fraction [0-1]
43
44#
45# Defines computer
46# ================
47if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi
48if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi
49
50case ${arch} in
51    ( curie | irene )
52    set +vx
53    module unload cdo nco ferret
54    module unload netcdf hdf5
55    module load python # /2.7.12
56    module load netcdf/4.3.3.1_hdf5_parallel # Version for XIOS
57    module load nco
58    R_IN=$(ccc_home -u igcmg --cccwork)/IGCM
59    TMPDIR=${SCRATCHDIR}/TMP
60    SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}}
61    ;;
62    ( * )
63    exit -1
64    ;;
65esac
66set -o verbose
67set -o xtrace
68set -e
69
70while [[ ${1} = -* ]] ; do
71    case ${1} in
72        ( -- ) shift ; break ;;
73        ( -c   | --comment  ) shift ; Comment=${1} ;;
74        ( -i   | --ice      ) shift ; IceVar=${1}  ;;
75        ( -a   | --alb      ) shift ; AlbVar=${1}  ;;
76        ( -v | --verbose    ) set -o verbose   ;;
77        ( -x | --xtrace     ) set -o xtrace    ;;
78        ( -xv | -vx         ) set -o xtrace verbose  ;;
79        ( -e                ) set -e           ;;
80        ( -V | --noverbose  ) set +o verbose   ;;
81        ( -X | --noxtrace   ) set +o xtrace    ;;
82        ( -XV | -VX         ) set +o xtrace verbose    ;;
83        ( -E                ) set +e           ;;
84        ( -* ) echo ${Bold}"Unknown option : ${1}"${Norm} ; return 1 ;;
85    esac
86    shift
87done
88
89OceFile=${1:-/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}
90
91#OceFile=${1:-/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}
92#
93
94#
95# Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits
96# ---------------------------------------------------------------------------
97FL_FMT=64bit
98
99##
100## Defines associated sea ice file
101## ===========================================================================
102###IceFile=$(echo ${OceFile} | sed 's=/OCE/=/ICE/=' | sed 's=grid_T=icemod=')
103IceFile=${OceFile}
104
105##
106## Extract variables
107## ===========================================================================
108ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceVar} ${IceFile} sstoce_fields.nc
109ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable tos       ${OceFile} oce_fields.nc
110ncks --append --fl_fmt=${FL_FMT} --history oce_fields.nc   sstoce_fields.nc
111ncwa --overwrite --fl_fmt=${FL_FMT} --history --average time_counter sstoce_fields.nc sstoce_fields_notime.nc # Remove time dimension
112ncatted --history --attribute history,global,d,c,""  sstoce_fields_notime.nc           # Clean attributes
113
114##
115## Find ocean name
116## ===========================================================================
117dim_y=$(ncdump -h sstoce_fields_notime.nc | grep "y *=" | awk '{print $3}' )
118dim_x=$(ncdump -h sstoce_fields_notime.nc | grep "x *=" | grep -v "nvertex" | awk '{print $3}' )
119echo ${dim_x} ${dim_y}
120
121[[ ${dim_x} = 182 && ${dim_y} = 149 ]] && OCE=ORCA2.3
122[[ ${dim_x} = 362 && ${dim_y} = 332 ]] && OCE=eORCA2.1
123[[ ${dim_x} = 1442 && ${dim_y} = 1207 ]] && OCE=eORCA025.1
124
125
126##
127## Creates sstoce file
128## ===========================================================================
129
130cat <<EOF > create_sstoce.nco
131OIceFrc[y,x]   = double ( ${IceVar}(:,:) ) ;
132//tos.simple_fill_miss(tos)               ;
133O_SSTSST[y,x]  = double ( (tos   (:,:) + 273.15d) * (1.0d-OIceFrc(:,:)) ) ;
134//O_AlbIce[y,x]  = double ( ialb   (:,:)            * OIceFrc(:,:)   ) ;
135//O_TepIce[y,x]  = double ( (tsice (:,:) + 273.15d) * OIceFrc(:,:)   ) ;
136O_AlbIce[y,x]  = double (   0.65d            * OIceFrc(:,:)   ) ;
137O_TepIce[y,x]  = double ( (-20.0d + 273.15d) * OIceFrc(:,:)   ) ;
138O_OCurx1[y,x]  = 0.0d ;
139O_OCury1[y,x]  = 0.0d ;
140O_OCurz1[y,x]  = 0.0d ;
141EOF
142
143ncap2 --overwrite --fl_fmt=${FL_FMT} --history --script-file create_sstoce.nco sstoce_fields_notime.nc tmp_sstoc.nc
144ncks --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
145ncatted --history --attribute comment,O_SSTSST,o,c,"SST weighted by fraction of open ocean"          sstoc.nc
146ncatted --history --attribute comment,O_AlbIce,o,c,"Albedo weighted by fraction of sea ice"          sstoc.nc
147ncatted --history --attribute comment,O_TepIce,o,c,"Ice temperature weighted by fraction of sea ice" sstoc.nc
148
149##
150## Add some information in file headers
151## ===========================================================================
152
153UUID=$(uuid)
154NCO="$(ncks --version |& tail -1|sed 's/ncks //')"
155ncatted --history \
156        --attribute nco_openmp_thread_number,global,d,,                       \
157        --attribute source,global,o,c,"IPSL Earth system model"               \
158        --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center"     \
159        --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr"         \
160        --attribute Model,global,o,c,"${OCE} https://www.nemo-ocean.eu"       \
161        --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}')" \
162        --attribute originalFiles,global,o,c,"${OceFile} ${IceFile}"          \
163        --attribute directory,global,o,c,"$(pwd)"                             \
164        --attribute description,global,o,c,"Fields needed by OASIS-MCT"       \
165        --attribute timeStamp,global,o,c,"$(date)"                            \
166        --attribute uuid,global,o,c,"${UUID}"                                 \
167        --attribute Program,global,o,c,"Generated by ${0}"                    \
168        --attribute HOSTNAME,global,o,c,"$(hostname)"                         \
169        --attribute LOGNAME,global,o,c,"$(whoami)"                            \
170        --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \
171        --attribute OS,global,o,c,"$(uname -o)"                               \
172        --attribute release,global,o,c,"$(uname -r)"                          \
173        --attribute hardware,global,o,c,"$(uname -i)"                         \
174        --attribute directory,global,o,c,"$(pwd)"                             \
175        --attribute Comment,global,o,c,"${Comment}"                           \
176        --attribute SVN_Author,global,o,c,"$Author$"                 \
177        --attribute SVN_Date,global,o,c,"$Date$" \
178        --attribute SVN_Revision,global,o,c,"$Revision$"               \
179        --attribute SVN_Id,global,o,c,"$Id$" \
180        sstoc.nc
181
182##
183## Cleaning
184## ===========================================================================
185rm -f sstoce_fields.nc sstoce_fields_notime.nc tmp_flxat.nc oce_fields.nc
186
187mv sstoc.nc sstoc_${OCE}.nc
188
189## ===========================================================================
190##
191##                               That's all folk's !!!
192##
193## ===========================================================================
Note: See TracBrowser for help on using the repository browser.