source: TOOLS/MOSAIX/CreateRestartAtm4Oasis.bash @ 3624

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

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