source: TOOLS/MOSAIX/CreateRestartAtm4Oasis.bash @ 3620

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

O.M. : continue first commit

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