Ignore:
Timestamp:
10/27/23 13:32:18 (9 months ago)
Author:
omamce
Message:

O.M. : CPLRESTART

  • More comments
  • Python cleanup
  • More use of nemo.py functionalities
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/CPLRESTART/CreateRestartOce4Oasis.bash

    r6512 r6669  
    2929# 
    3030# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/OCE/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_grid_T.nc --icefile /ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/ICE/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_icemod.nc --icefrc ice_pres --icetem tsice --icealb ialb 
     31 
    3132# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/gencmip6/p86mart/IGCM_OUT/IPSLCM6/DEVT/pdControl/CM6010.2.rivgeo-LR-pdCtrl/OCE/Output/MO/CM6010.2.rivgeo-LR-pdCtrl_22400101_22491231_1M_grid_T.nc  --icefrc siconc 
     33 
    3234# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/gencmip6/p86maf/IGCM_OUT/IPSLCM6/PROD/piControl/CM61-LR-pi-03/OCE/Output/MO/CM61-LR-pi-03_23400101_23491231_1M_grid_T.nc --icefile /ccc/store/cont003/gencmip6/p86maf/IGCM_OUT/IPSLCM6/PROD/piControl/CM61-LR-pi-03/ICE/Output/MO/CM61-LR-pi-03_23400101_23491231_1M_icemod.nc --icefrc siconc 
     35 
    3336# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/gen7451/personr/IGCM_OUT/ORCA025_LIM3_PISCES/DEVT/ORCA025ia/eOR025L3P-IA-REF07-MUSCL/OCE/Output/MO/eOR025L3P-IA-REF07-MUSCL_20090101_20091231_1M_grid_T.nc 
     37 
    3438# CreateRestartOce4Oasis.bash --ocefile /ccc/work/cont003/gencmip6/p48ethe/ICMC-TOOLS/DATA/eOR025L3P-IA-REF07-MUSCL_20090101_20091231_1M_grid_T.nc --icefile /ccc/work/cont003/gencmip6/p48ethe/ICMC-TOOLS/DATA/eOR025L3P-IA-REF07-MUSCL_20090101_20091231_1M_icemod.nc --icefrc siconc/oce --icetem sistem 
    3539#  
     
    4145## =========================================================================== 
    4246 
     47## Creates colors for petty prints 
     48## =============================== 
     49export Bold=$(tput bold) 
     50export Unde=$(tput smul) ; export OffUnde=$(tput rmul) 
     51export Stou=$(tput smso) ; export OffStou=$(tput rmso) 
     52export Reve=$(tput rev ) 
     53declare -a couleurs=( "Black" "Blue" "Green" "Cyan" "Red" "Magenta" "Yellow" "White" ) 
     54[[ "${bash_debug}" = "true" ]] && echod ".bash_login Couleurs : ${couleurs[*]}" 
     55[[ "${bash_debug}" = "true" ]] && echod "Demmarrage de la boucle" 
     56for i in $(seq 1 7) 
     57do 
     58    [[ "${bash_debug}" = "true" ]] && echod i:${i} 
     59    [[ "${bash_debug}" = "true" ]] && echod ".bashrc Couleur ${i} : ${couleurs[${i}]}" 
     60    eval "export ${couleurs[$i]}=$(tput setf $i)" 
     61    eval "export ${couleurs[$i]}F=$(tput setb $i)"           
     62done 
     63export Norm=$(tput sgr0 ) 
    4364## 
    4465## Command line parameters 
     
    88109    set +e 
    89110    R_IN=$(ccc_home -u igcmg --cccwork)/IGCM 
    90     TMPDIR=${CCCWORKDIR}/TMP 
     111    TMPDIR=$(ccc_home --cccwork)/TMP/CPLRESTART 
    91112    SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}} 
    92113    MpiRun="time ccc_mprun" 
    93114    PyRun="time ccc_mprun -n 1" # Needed to force python to run on one process only 
    94     module purge 
    95     module load hdf5 
    96     module load netcdf-c 
    97     module load nco 
    98     module load cdo 
    99     module load python3 
    100     module load datadir/igcmg 
    101     module list 
     115    source $(ccc_home -u igcmg)/MachineEnvironment/irene/env_atlas_irene 
    102116    set -e 
    103117    ;; 
     
    113127    ;; 
    114128esac 
    115 set -o verbose 
    116 set -o xtrace 
    117 set -e 
    118  
    119 Nperio="" 
    120  
    121 while [[ ${1} = -* ]] ; do 
     129 
     130Nperio='' 
     131bVerbose='Yes' 
     132bXtrace='Yes' 
     133bError='Yes' 
     134Fill='yes' 
     135 
     136while [[ ${1} = -* || ${1} = +* ]] ; do 
    122137    case ${1} in 
    123138        ( -- ) shift ; break ;; 
     
    132147        ( --nofill          ) Fill="no"  ;; 
    133148        ( --nperio          ) shift ; Nperio="--nperio ${1}" ;; 
    134         ( -v | --verbose    ) set -o verbose   ;; 
    135         ( -x | --xtrace     ) set -o xtrace    ;; 
    136         ( -xv | -vx         ) set -o xtrace verbose ;; 
    137         ( -e                ) set -e           ;; 
    138         ( -V | --noverbose  ) set +o verbose   ;; 
    139         ( -X | --noxtrace   ) set +o xtrace    ;; 
    140         ( -XV | -VX         ) set +o xtrace verbose    ;; 
    141         ( -E                ) set +e           ;; 
    142         ( -* ) echo ${Bold}"Unknown option : ${1}"${Norm} ; exit 1 ;; 
     149        ( -v | --verbose    ) bVerbose='Yes'   ;; 
     150        ( -x | --xtrace     ) bXtrace='Yes'    ;; 
     151        ( -xv | -vx         ) bVerbose='Yes' ; bXtrace='Yes' ;; 
     152        ( -e                ) bError='Yes'     ;; 
     153        ( -V | +v | --noverbose  ) bVerbose='No'  ;; 
     154        ( -X | +x | --noxtrace   ) bXtrace='No'   ;; 
     155        ( -XV | -VX | +vx | +xv  ) bVerbose='No'; bXtrace='No' ;; 
     156        ( -E | +e           ) bError='No'    ;; 
     157        ( -* ) echo ${Bold}${Red}"Unknown option : ${1}"${Norm} ; exit 1 ;; 
    143158    esac 
    144159    shift 
    145160done 
    146161 
     162[[ "X${bVerbose}" = "XYes"  ]] && set -o verbose 
     163[[ "X${bVerbose}" = "XNo"   ]] && set +o verbose 
     164[[ "X${bXtrace}"  = "XYes"  ]] && set -o xtrace 
     165[[ "X${bXtrace}"  = "XNo"   ]] && set +o xtrace 
     166[[ "X${bError}"   = "XYes"  ]] && set -o errexit 
     167[[ "X${bError}"   = "XNo"   ]] && set +o errexit 
    147168# 
    148169# Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits 
     
    180201 
    181202 
    182 echo "Oce sst         - Variable ${OceSst} - File ${OceSstFile}" 
    183 echo "Ice fraction    - Variable ${IceFrc} - File ${IceFrcFile}" 
    184 echo "Ice albedo      - Variable ${IceAlb} - File ${IceAlbFile}" 
    185 echo "Ice temperature - Variable ${IceTem} - File ${IcetemFile}" 
    186  
     203echo ${Blue}"Oce sst         - Variable ${OceSst} - File ${OceSstFile}"${Norm} 
     204echo ${Blue}"Ice fraction    - Variable ${IceFrc} - File ${IceFrcFile}"${Norm} 
     205echo ${Blue}"Ice albedo      - Variable ${IceAlb} - File ${IceAlbFile}"${Norm} 
     206echo ${Blue}"Ice temperature - Variable ${IceTem} - File ${IcetemFile}"${Norm} 
     207 
     208 
     209if [[ ! -f ${OceSstFile} ]] ; then 
     210    echo ${Red}"Not found : ${OceSstFile}"${Norm} 
     211fi 
     212 
     213if [[ ! -f ${IceFrcFile} ]] ; then 
     214    echo ${Red}"Not found : ${IceFrcFile}"${Norm} 
     215fi 
    187216 
    188217## 
    189218## Extract variables 
    190219## =========================================================================== 
    191 ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceFrc} ${IceFrcFile} sstoce_fields.nc 
    192 ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${OceSst} ${OceSstFile} oce_sst.nc 
    193  
    194 ncks --append    --fl_fmt=${FL_FMT} --history oce_sst.nc   sstoce_fields.nc 
     220ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceFrc} ${IceFrcFile} ${TMPDIR}/sstoce_fields.nc 
     221ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${OceSst} ${OceSstFile} ${TMPDIR}/oce_sst.nc 
     222 
     223ncks --append    --fl_fmt=${FL_FMT} --history ${TMPDIR}/oce_sst.nc ${TMPDIR}/sstoce_fields.nc 
    195224if [[ "X${IceAlb}" != "Xnone" ]] ; then 
    196     ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceAlb} ${IceAlbFile} ice_alb.nc 
    197     ncks --append    --fl_fmt=${FL_FMT} --history ice_alb.nc   sstoce_fields.nc 
     225    ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceAlb} ${IceAlbFile} ${TMPDIR}/ice_alb.nc 
     226    ncks --append    --fl_fmt=${FL_FMT} --history ${TMPDIR}/ice_alb.nc ${TMPDIR}/sstoce_fields.nc 
    198227fi 
    199228if [[ "X${IceTem}" != "Xnone" ]] ; then 
    200     ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceTem} ${IceTemFile} ice_tem.nc 
    201     ncks --append    --fl_fmt=${FL_FMT} --history ice_tem.nc   sstoce_fields.nc 
    202 fi 
    203 ncwa --overwrite --fl_fmt=${FL_FMT} --history --average time_counter sstoce_fields.nc sstoce_fields_notime.nc # Remove time dimension 
    204 ncatted --history --attribute history,global,d,c,""  sstoce_fields_notime.nc           # Clean attributes 
     229    ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceTem} ${IceTemFile} ${TMPDIR}/ice_tem.nc 
     230    ncks --append    --fl_fmt=${FL_FMT} --history ${TMPDIR}/ice_tem.nc ${TMPDIR}/sstoce_fields.nc 
     231fi 
     232 
     233# 
     234## Remove time dimension 
     235## =========================================================================== 
     236 
     237ncwa --overwrite --fl_fmt=${FL_FMT} --history --average time_counter ${TMPDIR}/sstoce_fields.nc ${TMPDIR}/sstoce_fields_notime.nc 
     238 
     239# Clean attributes 
     240ncatted --history --attribute history,global,d,c,"" ${TMPDIR}/sstoce_fields_notime.nc 
    205241 
    206242## 
    207243## Find ocean name 
    208244## =========================================================================== 
    209 dim_y=$(ncdump -h sstoce_fields_notime.nc | grep "y *=" | grep -v "nvertex" | awk '{print $3}' ) 
    210 dim_x=$(ncdump -h sstoce_fields_notime.nc | grep "x *=" | grep -v "nvertex" | awk '{print $3}' ) 
     245dim_y=$(ncdump -h ${TMPDIR}/sstoce_fields_notime.nc | grep "y *=" | grep -v "nvertex" | awk '{print $3}' ) 
     246dim_x=$(ncdump -h ${TMPDIR}/sstoce_fields_notime.nc | grep "x *=" | grep -v "nvertex" | awk '{print $3}' ) 
    211247echo ${dim_x} ${dim_y} 
    212248 
     
    219255## Creates sstoce file 
    220256## =========================================================================== 
    221 cat <<EOF > create_sstoce.nco 
     257cat <<EOF > ${TMPDIR}/create_sstoce.nco 
    222258*OceSst[y,x] = double ( ${OceSst}(:,:) + 273.15d ) ; 
    223259OIceFrc[y,x] = double ( ${IceFrc}(:,:) ) ;  
     
    226262 
    227263if [[ "X${IceAlb}" != "Xnone" ]] ; then 
    228     cat <<EOF >> create_sstoce.nco 
     264    cat <<EOF >> ${TMPDIR}/create_sstoce.nco 
    229265*IceAlb[y,x] = double ( ${IceAlb}(:,:) ) ; 
    230266// 
    231267EOF 
    232268else 
    233      cat <<EOF >> create_sstoce.nco 
     269     cat <<EOF >> ${TMPDIR}/create_sstoce.nco 
    234270*IceAlb[y,x] = double ( ${DefaultIceAlb}d ) ; 
    235271// 
     
    238274 
    239275if [[ "X${IceTem}" != "Xnone" ]] ; then 
    240     cat <<EOF >> create_sstoce.nco 
     276    cat <<EOF >> ${TMPDIR}/create_sstoce.nco 
    241277*IceTem[y,x] = double ( ${IceTem}(:,:) + 273.15d ) ; 
    242278// 
    243279EOF 
    244280else 
    245      cat <<EOF >> create_sstoce.nco 
     281     cat <<EOF >> ${TMPDIR}/create_sstoce.nco 
    246282*IceTem[y,x] = double ( ${DefaultIceTem}d + 273.15d ) ; 
    247283// 
     
    249285fi 
    250286 
    251 cat <<EOF >>  create_sstoce.nco 
     287cat <<EOF >>  ${TMPDIR}/create_sstoce.nco 
    252288O_SSTSST[y,x] = OceSst (:,:) * (1.0d-OIceFrc(:,:)) ; 
    253289O_AlbIce[y,x] = IceAlb (:,:)       * OIceFrc(:,:)  ; 
     
    258294EOF 
    259295 
    260 ncap2 --overwrite --fl_fmt=${FL_FMT} --history --script-file create_sstoce.nco sstoce_fields_notime.nc tmp_sstoc.nc 
    261 ncks --fl_fmt=${FL_FMT} --overwrite --history --variable OIceFrc,O_SSTSST,O_AlbIce,O_TepIce,O_OCurx1,O_OCury1,O_OCurz1 tmp_sstoc.nc sstoc.nc 
    262 ncatted --history --attribute long_name,O_SSTSST,o,c,"SST weighted by fraction of open ocean"          sstoc.nc 
    263 ncatted --history --attribute long_name,O_AlbIce,o,c,"Albedo weighted by fraction of sea ice"          sstoc.nc 
    264 ncatted --history --attribute long_name,O_TepIce,o,c,"Ice temperature weighted by fraction of sea ice" sstoc.nc 
    265  
    266 ncatted --history --attribute comment,O_SSTSST,o,c,"Variable ${OceSst} taken in ${OceSstFile}"  sstoc.nc 
    267 ncatted --history --attribute comment,OIceFrc,o,c,"Variable ${IceFrc} taken in ${IceFrcFile}"   sstoc.nc 
    268  
    269 if [[ ${IceAlb} = none ]] ; then  ncatted --history --attribute comment,O_AlbIce,o,c,"Set to ${DefaultIceAlb}"  sstoc.nc 
    270 else                              ncatted --history --attribute comment,O_AlbIce,o,c,"Variable ${IceAlb} taken in ${IceAlbFile}"  sstoc.nc 
    271 fi 
    272 if [[ ${IceTem} = none ]] ; then  ncatted --history --attribute comment,O_TepIce,o,c,"Set to ${DefaultIceTem}"  sstoc.nc 
    273 else                              ncatted --history --attribute comment,O_TepIce,o,c,"Variable ${IceTem} taken in ${IceTemFile}"  sstoc.nc 
     296ncap2 --overwrite --fl_fmt=${FL_FMT} --history --script-file ${TMPDIR}/create_sstoce.nco ${TMPDIR}/sstoce_fields_notime.nc ${TMPDIR}/tmp_sstoc.nc 
     297ncks --fl_fmt=${FL_FMT} --overwrite --history --variable OIceFrc,O_SSTSST,O_AlbIce,O_TepIce,O_OCurx1,O_OCury1,O_OCurz1 ${TMPDIR}/tmp_sstoc.nc ${TMPDIR}/sstoc.nc 
     298ncatted --history --attribute long_name,O_SSTSST,o,c,"SST weighted by fraction of open ocean"          ${TMPDIR}/sstoc.nc 
     299ncatted --history --attribute long_name,O_AlbIce,o,c,"Albedo weighted by fraction of sea ice"          ${TMPDIR}/sstoc.nc 
     300ncatted --history --attribute long_name,O_TepIce,o,c,"Ice temperature weighted by fraction of sea ice" ${TMPDIR}/sstoc.nc 
     301 
     302ncatted --history --attribute comment,O_SSTSST,o,c,"Variable ${OceSst} taken in ${OceSstFile}"  ${TMPDIR}/sstoc.nc 
     303ncatted --history --attribute comment,OIceFrc,o,c,"Variable ${IceFrc} taken in ${IceFrcFile}"   ${TMPDIR}/sstoc.nc 
     304 
     305if [[ ${IceAlb} = none ]] ; then 
     306    ncatted --history --attribute comment,O_AlbIce,o,c,"Set to ${DefaultIceAlb}"  ${TMPDIR}/sstoc.nc 
     307else 
     308    ncatted --history --attribute comment,O_AlbIce,o,c,"Variable ${IceAlb} taken in ${IceAlbFile}"  ${TMPDIR}/sstoc.nc 
     309fi 
     310 
     311if [[ ${IceTem} = none ]] ; then 
     312    ncatted --history --attribute comment,O_TepIce,o,c,"Set to ${DefaultIceTem}"  ${TMPDIR}/sstoc.nc 
     313else 
     314    ncatted --history --attribute comment,O_TepIce,o,c,"Variable ${IceTem} taken in ${IceTemFile}" ${TMPDIR}/sstoc.nc 
    274315fi 
    275316 
     
    278319## =========================================================================== 
    279320if [[ ${Fill} = yes ]] ; then 
    280     mv sstoc.nc sstoc_nofilled.nc 
    281     python3 FillOceRestart.py --input sstoc_nofilled.nc --output sstoc.nc ${Nperio} 
     321    mv  ${TMPDIR}/sstoc.nc  ${TMPDIR}/sstoc_nofilled.nc 
     322    python3 FillOceRestart.py --input ${TMPDIR}/sstoc_nofilled.nc --output ${TMPDIR}/sstoc.nc ${Nperio} 
    282323fi 
    283324 
     
    294335        --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr"         \ 
    295336        --attribute Model,global,o,c,"${OCE} https://www.nemo-ocean.eu"       \ 
    296         --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}')" \ 
    297337        --attribute originalFiles,global,o,c,"${OceFile} ${IceFile}"          \ 
    298338        --attribute directory,global,o,c,"$(pwd)"                             \ 
     
    313353        --attribute SVN_Revision,global,o,c,"$Revision$"               \ 
    314354        --attribute SVN_Id,global,o,c,"$Id$" \ 
    315         sstoc.nc 
     355         ${TMPDIR}/sstoc.nc 
    316356 
    317357## 
     
    320360#rm -f sstoce_fields.nc sstoce_fields_notime.nc tmp_sstoce.nc oce_fields.nc 
    321361 
    322 mv sstoc.nc sstoc_${OCE}.nc 
    323  
    324 ## 
    325  
    326 echo "TMPDIR : ${TMPDIR}" 
     362mv ${TMPDIR}/sstoc.nc ${TMPDIR}/sstoc_${OCE}.nc 
     363 
     364## 
     365 
     366echo ${Blue}"TMPDIR : ${TMPDIR}"${Norm} 
    327367## =========================================================================== 
    328368## 
Note: See TracChangeset for help on using the changeset viewer.