source: TOOLS/MOSAIX/CreateRestartOce4Oasis.bash @ 3620

Last change on this file since 3620 was 3620, checked in by omamce, 6 years ago

O.M. : continue first commit

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