source: TOOLS/MOSAIX/CreateRestartAtm4Oasis.bash @ 3639

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

O.M. : continue with propset

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