source: TOOLS/MOSAIX/CreateRestartAtm4Oasis.bash @ 3665

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

O.M. : mise a jour des properties

  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 12.0 KB
Line 
1#!/bin/bash
2### ===========================================================================
3###
4### Creates initial state for coupler, atmosphere side
5### Takes state from atmospheric hist file
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# CreateRestartAtm4Oasis.bash --oce ORCA2.3 /ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/ATM/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_histmth.nc
30# CreateRestartAtm4Oasis.bash --oce ORCA2.3 /ccc/work/cont003/gencmip6/bedidil/SAVE8_ORCA2/STORE1/dynamico_grid.nc
31# CreateRestartAtm4Oasis.bash --oce ORCA2.3 /ccc/work/cont003/gencmip6/bedidil/SAVE9_ORCA2_DYN30_1MO/STORE1/histmth.nc
32
33## ===========================================================================
34##
35## You should not change anything below this line ....
36##
37## ===========================================================================
38
39##
40## Command line parameters
41## ===========================================================================
42# Default values
43Comment="Preliminary attempt - Do not trust !"
44OCE="Unknown"
45
46#
47# Defines computer
48# ================
49if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi
50if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi
51
52case ${arch} in
53    ( curie | irene )
54    set +vx
55    module unload cdo nco ferret
56    module unload netcdf hdf5
57    module load python # /2.7.12
58    module load netcdf/4.3.3.1_hdf5_parallel # Version for XIOS
59    module load nco
60    R_IN=$(ccc_home -u igcmg --cccwork)/IGCM
61    TMPDIR=${SCRATCHDIR}/TMP
62    SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}}
63    ;;
64    ( * )
65    exit -1
66    ;;
67esac
68set -o verbose
69set -o xtrace
70set -e
71
72while [[ ${1} = -* ]] ; do
73    case ${1} in
74        ( -- ) shift ; break ;;
75        ( -o   | --oce      ) shift ; OCE=${1}     ;; # Just needed to add information in the file and file name
76        ( -c   | --comment  ) shift ; Comment=${1} ;; # Just needed to add information in the file
77        ( -v | --verbose    ) set -o verbose         ;;
78        ( -x | --xtrace     ) set -o xtrace          ;;
79        ( -xv | -vx         ) set -o xtrace verbose  ;;
80        ( -e                ) set -e                 ;;
81        ( -V | --noverbose  ) set +o verbose         ;;
82        ( -X | --noxtrace   ) set +o xtrace          ;;
83        ( -XV | -VX         ) set +o xtrace verbose  ;;
84        ( -E                ) set +e                 ;;
85        ( -* ) echo ${Bold}"Unknown option : ${1}"${Norm} ; return 1 ;;
86    esac
87    shift
88done
89
90#AtmFile=${1:-/ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/ATM/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_histmth.nc}
91#AtmFile=${1:-/ccc/work/cont003/gencmip6/bedidil/SAVE8_ORCA2/STORE1/dynamico_grid.nc}
92AtmFile=${1:-/ccc/work/cont003/gencmip6/bedidil/SAVE9_ORCA2_DYN30_1MO/STORE1/histmth.nc}
93
94#
95# Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits
96# ---------------------------------------------------------------------------
97FL_FMT=64bit
98
99##
100## Extract variables
101## ===========================================================================
102ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 -v lon,lat,sols,soll,fract_oce,fract_sic,precip,snow,evap_sic,evap_oce,wind10m,taux_oce,tauy_oce,taux_sic,tauy_sic ${AtmFile} flxat_fields.nc
103ncwa --overwrite --fl_fmt=${FL_FMT} --history -a time_counter flxat_fields.nc flxat_fields_notime.nc # remove time dimension
104ncatted --history --attribute history,global,d,c,""  flxat_fields_notime.nc          # cleaning of history attributes
105
106##
107## Determines if the file is unstructured (Dynamico) or lon/lat (LMDZ)
108## Set atmosphere name
109## ===========================================================================
110Count=$(ncdump -h flxat_fields_notime.nc | grep nvertex | wc -l)
111if [[ ${Count} -gt 0 ]] ; then
112    IsUnstructured=yes
113    dim_cell=$(ncdump -h flxat_fields_notime.nc |& grep "cell *=" | awk '{print $3}' ) # Get nominal DYNAMICO resolution (nbp parameter)
114    ico_nbp=$( echo "sqrt(($dim_cell-2)/10)+1" | bc -l | sed 's/\..*//' )
115    ATM=ICO${ico_nbp}
116    ncrename --history -d cell,y flxat_fields_notime.nc
117cat <<EOF > add_dim.nco
118defdim("x",1) ;
119lon      [y,x] = lon       ;
120lat      [y,x] = lat       ;
121sols     [y,x] = sols      ;
122soll     [y,x] = soll      ;
123fract_oce[y,x] = fract_oce ;
124fract_sic[y,x] = fract_sic ;
125precip   [y,x] = precip    ;
126snow     [y,x] = snow      ;
127evap_sic [y,x] = evap_sic  ;
128evap_oce [y,x] = evap_oce  ;
129wind10m  [y,x] = wind10m   ;
130taux_oce [y,x] = taux_oce  ;
131tauy_oce [y,x] = tauy_oce  ;
132taux_sic [y,x] = taux_sic  ;
133tauy_sic [y,x] = tauy_sic  ;
134EOF
135    ncap2 --history --overwrite --fl_fmt=${FL_FMT} -S add_dim.nco flxat_fields_notime.nc tmp_flxat_fields_notime.nc
136    mv tmp_flxat_fields_notime.nc flxat_fields_notime.nc
137
138cat<<EOF > lonlat2xyz.nco
139// Value at North Pole for DYNAMICO grid
140where ( lat(:,:) >= 90.0d ) COTAUXXU = double(-tau_y) ;
141where ( lat(:,:) >= 90.0d ) COTAUYYU = double( tau_x) ;
142// Value at South Pole for DYNAMICO grid ?
143EOF
144else
145    # lat/lon
146    IsUnstructured=no
147    dim_lat=$(ncdump -h flxat_fields_notime.nc | grep "lat *=" | awk '{print $3}' )
148    dim_lon=$(ncdump -h flxat_fields_notime.nc | grep "lon *=" | awk '{print $3}' )
149    ncrename --history -d lon,x flxat_fields_notime.nc
150    ncrename --history -d lat,y flxat_fields_notime.nc
151cat <<EOF > add_dim.nco
152lon[y,x] = lon ;
153lat[y,x] = lat ;
154EOF
155    ncap2 --history --overwrite --fl_fmt=${FL_FMT} -S add_dim.nco flxat_fields_notime.nc tmp_flxat_fields_notime.nc
156    mv tmp_flxat_fields_notime.nc flxat_fields_notime.nc
157    (( dim_lat = dim_lat - 1 ))
158    #ATM=lmdz${dim_lon}x${dim_lat}
159    ATM=LMD${dim_lon}${dim_lat}
160    (( n_lat = dim_lat-1 ))
161cat<<EOF > lonlat2xyz.nco
162// Value at North Pole for LMDZ lon/lat grid
163COTAUXXU(0,:) = double( -tau_x (0, 0) ) ;
164COTAUYYU(0,:) = double( -tau_y (0, 0) ) ;
165COTAUZZU(0,:) =  0.0d ;
166// Value at south Pole for LMDZ lon/lat grid ?
167COTAUXXU(${n_lat},:) = double( -tau_x (${n_lat}, 0) ) ;
168COTAUYYU(${n_lat},:) = double( -tau_y (${n_lat}, 0) ) ;
169COTAUZZU(${n_lat},:) =  0.0d ;
170EOF
171
172fi
173
174echo "Version atmosphere : " ${ATM}
175
176
177##
178## Creates flxat file
179## ===========================================================================
180
181cat <<EOF > create_flxat.nco
182//
183*fract_oce_plus_sic  = double(fract_oce + fract_sic) ; // ocean fraction
184*fract_oce_norm[y,x] = 0.0d ; fract_sic_norm[y,x] = 0.0d ;
185where (fract_oce_plus_sic >  0.0d ) *fract_oce_norm = double(fract_oce)/fract_oce_plus_sic ; // free ocean vs. total ocen fraction
186where (fract_oce_plus_sic >  0.0d ) *fract_sic_norm = double(fract_sic)/fract_oce_plus_sic ; // sea ice vs. total ocean fraction
187//
188COTOTRAI[y,x] = double(precip-snow)    ;  //  Liquid precip
189COTOTSNO[y,x] = double(snow)           ;  //  Solid precipitation
190COTOTEVA[y,x] = double(evap_oce*fract_oce_norm + evap_sic*fract_sic_norm) ;
191COICEVAP[y,x] = double(evap_sic(:,:))  ; // Evaporation on sea ice
192COQSRMIX[y,x] = double(sols(:,:))      ; // Heat flux short wave
193COQNSMIX[y,x] = double(soll(:,:))      ; // Heat flux minus short wave
194COSHFICE[y,x] = double(sols(:,:))      ; // Heat flux short wave over sea ice
195CONSFICE[y,x] = double(soll(:,:))      ; // Heat flux minus short wave over sea ice
196CODFLXDT[y,x] = -20.0d       ; // W/m2 - dQ/dt
197COCALVIN[y,x] =   0.0d       ; // Calving of icebergs, solid
198COLIQRUN[y,x] =   0.0d       ; // River run-off , liquid
199COWINDSP[y,x] = double( wind10m(:,:) ) ; // Wind speed at 10m high
200COTAUMOD[y,x] =   0.0d                 ; // Wind stress modulus
201// Wind stress
202*tau_x[y,x] = double(taux_oce*fract_oce_norm + taux_sic*fract_sic_norm) ;
203*tau_y[y,x] = double(tauy_oce*fract_oce_norm + tauy_sic*fract_sic_norm) ;
204COTAUMOD[y,x] = sqrt ( double(tau_x*tau_x + tau_y*tau_y) )  ;
205// Wind stress, from east/north components to geocentric
206*rpi = acos (-1.0d) ;  *rad = rpi / 180.0d  ;
207COTAUXXU[y,x] = double( -tau_x(:,:) * sin(rad * lon(:,:)) - tau_y(:,:) * sin(rad * lat(:,:)) * cos(rad * lon(:,:)) );
208COTAUYYU[y,x] = double(  tau_x(:,:) * cos(rad * lon(:,:)) - tau_y(:,:) * sin(rad * lat(:,:)) * sin(rad * lon(:,:)) );
209COTAUZZU[y,x] = double(  tau_y(:,:) * cos(rad * lat(:,:)) ) ;
210// Value at North Pole
211#include "lonlat2xyz.nco"
212//
213COTAUXXV[y,x] = COTAUXXU(:,:) ;
214COTAUYYV[y,x] = COTAUYYU(:,:) ;
215COTAUZZV[y,x] = COTAUZZU(:,:) ;
216//
217EOF
218ncap2 --overwrite --fl_fmt=${FL_FMT} -h -S create_flxat.nco flxat_fields_notime.nc tmp_flxat.nc
219 
220ncks --fl_fmt=${FL_FMT} --overwrite -h -v lon,lat tmp_flxat.nc flxat.nc
221[[ ${IsUnstructured} = yes ]] && ncks --fl_fmt=${FL_FMT} --append -v bounds_lon,bounds_lat tmp_flxat.nc flxat.nc
222ncks --fl_fmt=${FL_FMT} --append  -h -v COTAUXXU,COTAUYYU,COTAUZZU,COTAUXXV,COTAUYYV,COTAUZZV,COTOTRAI,COTOTSNO,COTOTEVA,COICEVAP,COQSRMIX,COQNSMIX,COSHFICE,CONSFICE,CODFLXDT,COCALVIN,COLIQRUN,COWINDSP,COTAUMOD tmp_flxat.nc flxat.nc
223
224##
225## Add some information in file headers
226## ===========================================================================
227
228UUID=$(uuid)
229NCO="$(ncks --version |& tail -1|sed 's/ncks //')"
230ncatted --history \
231        --attribute nco_openmp_thread_number,global,d,,                       \
232        --attribute source,global,o,c,"IPSL Earth system model"               \
233        --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center"     \
234        --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr"         \
235        --attribute Model,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr"      \
236        --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu"       \
237        --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}')" \
238        --attribute originalFiles,global,o,c,"${AtmFile}"                     \
239        --attribute directory,global,o,c,"$(pwd)"                             \
240        --attribute description,global,o,c,"Fields needed by OASIS-MCT"       \
241        --attribute timeStamp,global,o,c,"$(date)"                            \
242        --attribute Program,global,o,c,"Generated by ${0}"                    \
243        --attribute uuid,global,o,c,"${UUID}"                                 \
244        --attribute HOSTNAME,global,o,c,"$(hostname)"                         \
245        --attribute LOGNAME,global,o,c,"$(whoami)"                            \
246        --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \
247        --attribute OS,global,o,c,"$(uname -o)"                               \
248        --attribute release,global,o,c,"$(uname -r)"                          \
249        --attribute hardware,global,o,c,"$(uname -i)"                         \
250        --attribute directory,global,o,c,"$(pwd)"                             \
251        --attribute Comment,global,o,c,"${Comment}"                           \
252        --attribute Comment,global,o,c,"Preliminary attempt - Do not trust !" \
253        --attribute SVN_Author,global,o,c,"$Author$"                 \
254        --attribute SVN_Date,global,o,c,"$Date$"                            \
255        --attribute SVN_Revision,global,o,c,"$Revision$"               \
256        --attribute SVN_Id,global,o,c,"$Id$"                                \
257        flxat.nc
258
259
260##
261## Creates other files
262## ===========================================================================
263mv flxat.nc flxat_${ATM}_maskFrom_${OCE}.nc
264ncks -v COCALVIN flxat_${ATM}_maskFrom_${OCE}.nc icbrg_${ATM}_maskFrom_${OCE}.nc
265ncks -v COCALVIN flxat_${ATM}_maskFrom_${OCE}.nc icshf_${ATM}_maskFrom_${OCE}.nc
266
267##
268## Cleaning
269## ===========================================================================
270rm -f flxat_fields.nc flxat_fields_notime.nc tmp_flxat.nc
271
272## ===========================================================================
273##
274##                               That's all folk's !!!
275##
276## ===========================================================================
Note: See TracBrowser for help on using the repository browser.