source: TOOLS/CPLRESTART/CreateRestartAtm4Oasis.bash @ 6228

Last change on this file since 6228 was 6228, checked in by omamce, 2 years ago

O.M. : CPLRESTART
Switch complexe nco script to python

  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 9.9 KB
Line 
1#!/usr/bin/env 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 eORCA1.2 /ccc/store/cont003/gencmip6/p86maf/IGCM_OUT/IPSLCM6/PROD/piControl/CM61-LR-pi-03/ATM/Output/MO/CM61-LR-pi-03_23400101_23491231_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
52if [[ $(hostname) = lsce*  ]] ; then arch=spip  ; center=spip ; fi
53
54case ${arch} in
55    ( irene )
56    set +e
57    R_IN=$(ccc_home -u igcmg --cccwork)/IGCM
58    TMPDIR=${CCCWORKDIR}/TMP
59    SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}}
60    MpiRun="time ccc_mprun"
61    PyRun="time ccc_mprun -n 1" # Needed to force python to run on one process only
62    module purge
63    module load hdf5
64    module load netcdf-c
65    module load nco
66    module load cdo
67    module load python3
68    module load datadir/igcmg
69    module list
70    set -e
71    ;;
72    ( spip )
73    R_IN=${HOME}/Scratch/IGCM
74    TMPDIR=${HOME}/Scratch/TMP
75    SUBMIT_DIR=$(pwd)
76    MpiRun="/opt/local/bin/mpirun -n 1"
77    PyRun="time"
78    ;;
79    ( * )
80    exit -1
81    ;;
82esac
83set -o verbose
84set -o xtrace
85set -e
86
87while [[ ${1} = -* ]] ; do
88    case ${1} in
89        ( -- ) shift ; break ;;
90        ( -o   | --oce      ) shift ; OCE=${1}     ;; # Just needed to add information in the file and file name
91        ( -c   | --comment  ) shift ; Comment=${1} ;; # Just needed to add information in the file
92        ( -v | --verbose    ) set -o verbose         ;;
93        ( -x | --xtrace     ) set -o xtrace          ;;
94        ( -xv | -vx         ) set -o xtrace verbose  ;;
95        ( -e                ) set -e                 ;;
96        ( -V | --noverbose  ) set +o verbose         ;;
97        ( -X | --noxtrace   ) set +o xtrace          ;;
98        ( -XV | -VX         ) set +o xtrace verbose  ;;
99        ( -E                ) set +e                 ;;
100        ( -* ) echo ${Bold}"Unknown option : ${1}"${Norm} ; return 1 ;;
101    esac
102    shift
103done
104
105
106set -e
107
108#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}
109#AtmFile=${1:-/ccc/work/cont003/gencmip6/bedidil/SAVE8_ORCA2/STORE1/dynamico_grid.nc}
110AtmFile=${1:-/ccc/work/cont003/gencmip6/bedidil/SAVE9_ORCA2_DYN30_1MO/STORE1/histmth.nc}
111
112#
113# Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits
114# ---------------------------------------------------------------------------
115FL_FMT=64bit
116
117##
118## Extract variables
119## ===========================================================================
120ncks --overwrite --fl_fmt=${FL_FMT} --history --dimension time_counter,0,0 --variable 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
121ncwa --overwrite --fl_fmt=${FL_FMT} --history --average time_counter flxat_fields.nc flxat_fields_notime.nc # remove time dimension
122ncatted --history --attribute history,global,d,c,""  flxat_fields_notime.nc          # cleaning of history attributes
123
124##
125## Determines if the file is unstructured (Dynamico) or lon/lat (LMDZ)
126## Set atmosphere name
127## ===========================================================================
128Count=$(ncdump -h flxat_fields_notime.nc | grep nvertex | wc -l)
129if [[ ${Count} -gt 0 ]] ; then
130    IsUnstructured=yes
131    dim_cell=$(ncdump -h flxat_fields_notime.nc |& grep "cell *=" | awk '{print $3}' ) # Get nominal DYNAMICO resolution (nbp parameter)
132    ico_nbp=$( echo "sqrt(($dim_cell-2)/10)" | bc -l | sed 's/\..*//' )
133    ATM=ICO${ico_nbp}
134    ncrename --history --dimension cell,y flxat_fields_notime.nc
135cat <<EOF > add_dim.nco
136defdim("x",1) ;
137lon      [y,x] = lon       ;
138lat      [y,x] = lat       ;
139sols     [y,x] = sols      ;
140soll     [y,x] = soll      ;
141fract_oce[y,x] = fract_oce ;
142fract_sic[y,x] = fract_sic ;
143precip   [y,x] = precip    ;
144snow     [y,x] = snow      ;
145evap_sic [y,x] = evap_sic  ;
146evap_oce [y,x] = evap_oce  ;
147wind10m  [y,x] = wind10m   ;
148taux_oce [y,x] = taux_oce  ;
149tauy_oce [y,x] = tauy_oce  ;
150taux_sic [y,x] = taux_sic  ;
151tauy_sic [y,x] = tauy_sic  ;
152EOF
153    ncap2 --history --overwrite --fl_fmt=${FL_FMT} --script-file add_dim.nco flxat_fields_notime.nc tmp_flxat_fields_notime.nc
154    mv tmp_flxat_fields_notime.nc flxat_fields_notime.nc
155else
156    # lat/lon
157    IsUnstructured=no
158    dim_lat=$(ncdump -h flxat_fields_notime.nc | grep "lat *=" | awk '{print $3}' )
159    dim_lon=$(ncdump -h flxat_fields_notime.nc | grep "lon *=" | awk '{print $3}' )
160    ncrename --history --dimension lon,x flxat_fields_notime.nc
161    ncrename --history --dimension lat,y flxat_fields_notime.nc
162cat <<EOF > add_dim.nco
163lon[y,x] = lon ;
164lat[y,x] = lat ;
165EOF
166    ncap2 --history --overwrite --fl_fmt=${FL_FMT} --script-file add_dim.nco flxat_fields_notime.nc tmp_flxat_fields_notime.nc
167    mv tmp_flxat_fields_notime.nc flxat_fields_notime.nc
168    (( dim_lat = dim_lat - 1 ))
169    ATM=LMD${dim_lon}${dim_lat}
170    (( n_lat = dim_lat - 1 ))
171
172
173fi
174
175echo "Version atmosphere : " ${ATM}
176
177
178##
179## Creates flxat file
180## ===========================================================================
181
182python3 create_flxat.py --IsUnstructured=${IsUnstructured} --input flxat_fields_notime.nc --output tmp_flxat.nc
183
184[[ ${IsUnstructured} = yes ]] && ncks --fl_fmt=${FL_FMT} --history --append --variable bounds_lon,bounds_lat flxat.nc  tmp_flxat.nc
185ncks --fl_fmt=${FL_FMT} --append --history --variable COTAUXXU,COTAUYYU,COTAUZZU,COTAUXXV,COTAUYYV,COTAUZZV,COTOTRAI,COTOTSNO,COTOTEVA,COICEVAP,COQSRMIX,COQNSMIX,COSHFICE,CONSFICE,CODFLXDT,COCALVIN,COLIQRUN,COWINDSP,COTAUMOD tmp_flxat.nc flxat.nc
186
187##
188## Add some information in file headers
189## ===========================================================================
190
191UUID=$(uuid)
192NCO="$(ncks --version |& tail -1|sed 's/ncks //')"
193ncatted --history \
194        --attribute nco_openmp_thread_number,global,d,,                       \
195        --attribute source,global,o,c,"IPSL Earth system model"               \
196        --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center"     \
197        --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr"         \
198        --attribute Model,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr"      \
199        --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu"       \
200        --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}')" \
201        --attribute originalFiles,global,o,c,"${AtmFile}"                     \
202        --attribute directory,global,o,c,"$(pwd)"                             \
203        --attribute description,global,o,c,"Fields needed by OASIS-MCT"       \
204        --attribute timeStamp,global,o,c,"$(date)"                            \
205        --attribute Program,global,o,c,"Generated by ${0}"                    \
206        --attribute uuid,global,o,c,"${UUID}"                                 \
207        --attribute HOSTNAME,global,o,c,"$(hostname)"                         \
208        --attribute LOGNAME,global,o,c,"$(whoami)"                            \
209        --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \
210        --attribute OS,global,o,c,"$(uname -o)"                               \
211        --attribute release,global,o,c,"$(uname -r)"                          \
212        --attribute hardware,global,o,c,"$(uname -i)"                         \
213        --attribute directory,global,o,c,"$(pwd)"                             \
214        --attribute Comment,global,o,c,"${Comment}"                           \
215        --attribute Comment,global,o,c,"Preliminary attempt - Do not trust !" \
216        --attribute SVN_Author,global,o,c,"$Author$"                 \
217        --attribute SVN_Date,global,o,c,"$Date$" \
218        --attribute SVN_Revision,global,o,c,"$Revision$"               \
219        --attribute SVN_Id,global,o,c,"$Id$" \
220        flxat.nc
221
222
223##
224## Creates other files
225## ===========================================================================
226mv flxat.nc flxat_${ATM}_maskFrom_${OCE}.nc
227ncks --history --variable COCALVIN flxat_${ATM}_maskFrom_${OCE}.nc icbrg_${ATM}_maskFrom_${OCE}.nc
228ncks --history --variable COCALVIN flxat_${ATM}_maskFrom_${OCE}.nc icshf_${ATM}_maskFrom_${OCE}.nc
229
230##
231## Cleaning
232## ===========================================================================
233rm -f flxat_fields.nc flxat_fields_notime.nc tmp_flxat.nc
234
235## ===========================================================================
236##
237##                               That's all folk's !!!
238##
239## ===========================================================================
Note: See TracBrowser for help on using the repository browser.