source: branches/libIGCM_CESMEP/libIGCM_check/libIGCM_check.ksh

Last change on this file was 1059, checked in by sdipsl, 10 years ago
  • Attach the licence when it is not the case
  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Date Author Rev
File size: 14.1 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sonia Labetoulle, Sébastien Denvil
5# Contact: Sonia.Labetoulle__at__ipsl.jussieu.fr Sebastien.Denvil_at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#D-#==================================================
15#D-function IGCM_check_CommonDef
16#D-* Purpose:
17#D-* Examples:
18#D-
19function IGCM_check_CommonDef
20{
21  IGCM_debug_PushStack "IGCM_check_CommonDef" $@
22
23  # Define colors
24  # -------------
25  ColEsc="\033["
26  ColNon="${ColEsc}0m"       # Return to normal
27  ColExp="${ColEsc}1m"       # Blanc - gras
28  ColFat="${ColEsc}1;31m"    # Fatal
29  ColCpl="${ColEsc}1;32m"    # Completed
30  ColAtt="${ColEsc}1;30m"    # Waiting
31  ColDef="${ColEsc}1;34m"    # Default
32  ColRbl="${ColEsc}31m"      # Rebuild
33
34  # Define date format
35  # ------------------
36  DateFormat="%d/%m/%y %R:%S"
37
38
39  # What kind of rebuild ?
40  # ----------------------
41  RebuildJob="rebuild_fromWorkdir"
42  IGCM_sys_TestDir ${REBUILD_DIR}
43  RebuildExists=$?
44
45  # Are packs activated or not ?
46  # ----------------------------
47  if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && \
48       [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
49    Pack=true
50  else
51    Pack=false
52  fi
53
54
55  # Define input parameters
56  # -----------------------
57  set -A JobType_list "${RebuildJob}" "pack_output" "pack_restart" "pack_debug"
58
59  for JobType in ${JobType_list[*]} ; do
60    typeset    name1="${JobType}_String"
61    typeset    name2="${JobType}_Field"
62    typeset    name3="${JobType}_Activ"
63    if [ X${JobType} == X${RebuildJob} ] ; then
64      if ( ${Pack} ) ; then
65        eval ${name1}=IGCM_sys_PutBuffer_Out
66      else
67        eval ${name1}=IGCM_sys_Put_Out
68      fi
69      eval ${name2}=4
70      eval ${name3}=true
71    else
72      eval ${name1}=IGCM_sys_Put_Out
73      eval ${name2}=3
74      if ( ${Pack} ) ; then
75        eval ${name3}=true
76      else
77        eval ${name3}=false
78      fi
79    fi
80  done
81
82  IGCM_debug_PopStack "IGCM_check_CommonDef"
83}
84
85#D-#==================================================
86#D-function IGCM_check_ChangeUsr
87#D-* Purpose:
88#D-* Examples:
89#D-
90function IGCM_check_ChangeUsr
91{
92  IGCM_debug_PushStack "IGCM_check_ChangeUsr" $@
93
94  CurrentGrp=$( groups $CurrentUsr | gawk '{print $3}' )
95  TargetGrp=$( groups $TargetUsr | gawk '{print $3}' )
96
97  echo $1 | sed -e "s/${CurrentUsr}/${TargetUsr}/" \
98                -e "s/${CurrentGrp}/${TargetGrp}/"
99
100  IGCM_debug_PopStack "IGCM_check_ChangeUsr"
101}
102
103#D-#==================================================
104#D-function IGCM_check_SearchCatalog
105#D-* Purpose:
106#D-* Examples:
107#D-
108function IGCM_check_SearchCatalog
109{
110  IGCM_debug_PushStack "IGCM_check_SearchCatalog" $@
111
112  typeset num
113  unset SUBMIT_DIR
114
115  fg_new=false
116
117  if [ ! X${JobName} == X ] ; then
118    NbOcc=$( gawk -v JobName=${JobName} \
119             'BEGIN {x=0}  $1 ~ JobName {++x} END {print x}' ${SimuCatalog} )
120  else
121    NbOcc=0
122  fi
123
124  if ( [ ${NbOcc} -eq 0 ] && ( ${fg_path} ) ) ; then
125
126    if [ ! "$( echo ${ConfigPath} | cut -c 1 )" == "/" ] ; then
127      ConfigPath="${PWD}/${ConfigPath}"
128    fi
129
130    set -A FileList $( ls ${ConfigPath}/Job_* )
131    if [ X$FileList == X ] ; then
132      NbOcc=0
133    else
134      NbOcc=${#FileList[@]}
135      fg_new=true
136    fi
137  fi
138
139  if ( [ ${NbOcc} -eq 0 ] && ( ${fg_search} ) ) ; then
140    SEARCH_DIR=${WORKDIR}
141    if [ ${TargetUsr} != ${CurrentUsr} ] ; then
142      SEARCH_DIR=$( IGCM_check_ChangeUsr ${SEARCH_DIR} )
143    fi
144    echo "${JobName} not in Catalog, we'll try to find it in ${SEARCH_DIR}"
145
146    set -A FileList $( find ${SEARCH_DIR}/ \
147                            -path ${SEARCH_DIR}/IGCM_OUT -prune -o \
148                            -name Job_${JobName} -print )
149    if [ X$FileList == X ] ; then
150      NbOcc=0
151    else
152      NbOcc=${#FileList[@]}
153      fg_new=true
154    fi
155  fi
156
157  if [ ${NbOcc} -gt 1 ] ; then
158    echo "More than one job"
159    ind=0
160    while [ ${ind} -lt ${NbOcc} ] ; do
161      printf '%2i) %-30s\n' ${ind} ${FileList[${ind}]}
162      (( ind = ind + 1 ))
163    done
164    echo "Give your choice number or 'q' to quit : "
165    read Choice
166    if [ X${Choice} == Xq ] ; then
167      return 1
168    else
169      fg_new=true
170      FileList=${FileList[${Choice}]}
171      NbOcc=1
172    fi
173  fi
174
175  case ${NbOcc} in
176    0)
177      if ( ${fg_search} ) ; then
178        echo "${JobName} not found, neither in catalog nor in \$WORKDIR."
179      else
180        echo "${JobName} not found in catalog."
181      fi
182      echo "You can try : *) '-s' option to automatically search your \$WORKDIR ; "
183      echo "              *) '-p' option to provide the directory (absolute path) "
184      echo "                      containing the config.card ; "
185      echo "              *)  manually editing your ${SimuCatalog}."
186      return 1 ;;
187    1)
188      if ( ${fg_new} ) ; then
189#        JobName=${JobName:=$( basename ${FileList} | gawk -F"_" '{ print $2 }' )}
190        JobName=$( basename ${FileList} | gawk -F"_" '{ print $2 }' )
191        SUBMIT_DIR=$( dirname ${FileList} )
192        echo "${JobName} ${TargetUsr} ${HostName} ${SUBMIT_DIR}"
193        echo "${JobName} ${TargetUsr} ${HostName} ${SUBMIT_DIR}" >> ${SimuCatalog}
194        sort -u ${SimuCatalog} > ${SimuCatalog}.tmp
195        mv ${SimuCatalog}.tmp ${SimuCatalog}
196      elif ( [ ${TargetUsr} == $( gawk -v JobName=${JobName} \
197                                      '$1 ~ JobName {print $2}' \
198                                      ${SimuCatalog} ) ] \
199          && [ ${HostName}  == $( gawk -v JobName=${JobName} \
200                                      '$1 ~ JobName {print $3}' \
201                                      ${SimuCatalog} ) ] ) ; then
202        JobName=$( gawk -v JobName=${JobName} '$1 ~ JobName {print $1}' ${SimuCatalog} )
203        SUBMIT_DIR=$( gawk -v JobName=${JobName} '$1 ~ JobName {print $4}' ${SimuCatalog} )
204      else
205        echo "${JobName} not in Catalog."
206        return 1
207      fi
208      ;;
209    *)
210      break ;;
211  esac
212
213  IGCM_debug_PopStack "IGCM_check_SearchCatalog"
214}
215
216#D-#==================================================
217#D-function IGCM_check_PrintHeader
218#D-* Purpose:
219#D-* Examples:
220#D-
221function IGCM_check_PrintHeader
222{
223  IGCM_debug_PushStack "IGCM_check_PrintHeader" $@
224
225  echo "|===========================================================================================================|"
226  printf "| JobName = ${ColExp}%-26.26s${ColNon} JobID = ${ColExp}%-36.36s${ColNon}date : ${ColExp}%-18s${ColNon}|\n" \
227         ${JobName} ${JobID} "$( date +"${DateFormat}" )"
228
229  printf "| User    = ${ColExp}%-56.56s${ColNon}last run.card write : ${ColExp}%-18s${ColNon}|\n" \
230         ${TargetUsr} "${LastWrite}"
231
232  printf "|-----------------------------------------------------------------------------------------------------------|\n"
233
234  printf "| Submit  | ${ColExp}%-95.95s${ColNon} |\n" ${SUBMIT_DIR}
235  printf "| Data    | ${ColExp}%-95.95s${ColNon} |\n" ${DATA_DIR}
236  printf "| Rebuild | ${ColExp}%-95.95s${ColNon} |\n" ${REBUILD_DIR}
237  printf "| Post    | ${ColExp}%-95.95s${ColNon} |\n" ${POST_DIR}
238  printf "| Work    | ${ColExp}%-95.95s${ColNon} |\n" ${CWORK_DIR}
239
240  echo "|-------------------------|-------------|-------------------------|-------------|-----:----------:----------|"
241  echo "|                         |             |                         |             |     Pending Rebuilds      |"
242  echo "| Date Begin - DateEnd    | PeriodState | Current Period          | CumulPeriod | Nb  : from     : to       |"
243  echo "|-------------------------|-------------|-------------------------|-------------|-----:----------:----------|"
244
245  printf "| %-10s - %-10s | " \
246         $DateBegin $DateEnd
247
248  case $PeriodState in
249    Fatal)
250      Color=${ColFat}
251      ;;
252    Completed)
253      Color=${ColCpl}
254      ;;
255    Waiting|OnQueue)
256      Color=${ColAtt}
257      ;;
258    *)
259      Color=${ColDef}
260      ;;
261  esac
262  printf "${Color}%-11s${ColNon} | " $PeriodState
263
264  printf "%-10s - %-10s | %11s | " \
265         $PeriodDateBegin $PeriodDateEnd $CumulPeriod
266
267  if ( [ X${NbRebuild} != X. ] && [ X${NbRebuild} != X0 ] ) ; then
268    printf "${ColRbl}%3s : %-8s : %-8s${ColNon} |\n" \
269           $NbRebuild $FirstRebuild $LastRebuild
270  else
271    printf "%3s : %-8s : %-8s |\n" \
272           $NbRebuild $FirstRebuild $LastRebuild
273  fi
274
275  if [ ${NbLines} -gt 0 ] ; then
276    printf "|-----------------------------------------------------------------------------------------------------------|\n"
277    printf "|                                                      Last                                                 |\n"
278    printf "|     Rebuild      |   Pack_Output    |   Pack_Restart   |    Pack_Debug    |  Monitoring  |     Atlas      |\n"
279    printf "|------------------|------------------|------------------|------------------|--------------|----------------|\n"
280  fi
281
282  IGCM_debug_PopStack "IGCM_check_PrintHeader"
283}
284
285#D-#==================================================
286#D-function IGCM_check_PrintJob
287#D-* Purpose:
288#D-* Examples:
289#D-
290function IGCM_check_PrintJob
291{
292  IGCM_debug_PushStack "IGCM_check_PrintJob" $@
293
294  printf "|"
295
296  # Print rebuild and pack jobs
297  # ---------------------------
298  for JobType in ${JobType_list[*]} ; do
299    eval Date=\${${JobType}_Date[${ind}]}
300    eval Status=\${${JobType}_Status[${ind}]}
301    eval Nb=\${${JobType}_Nb[${ind}]}
302
303    if [ X${Status} == XOK  ] ; then
304      Color=${ColCpl}
305    else
306      Color=${ColFat}
307    fi
308    printf "  ${Color}%-8s${ColNon} : %3s  |" ${Date} ${Nb}
309  done
310
311  Color=${ColExp}
312
313  # Print monitoring jobs
314  # ---------------------
315  JobType=monitoring
316  if [ $ind -eq 0 ] ; then
317    eval Date=\${${JobType}_Date}
318  else
319    Date=""
320  fi
321  printf "     ${Color}%-4s${ColNon}     |" ${Date}
322
323  # Print atlas jobs
324  # ----------------
325  JobType=atlas
326  eval Date=\${${JobType}_Date[${ind}]}
327  printf "  ${Color}%-12s${ColNon}  |" ${Date}
328
329  printf "\n"
330
331  IGCM_debug_PopStack "IGCM_check_PrintJob"
332}
333
334#D-#==================================================
335#D-function IGCM_check_PrintFooter
336#D-* Purpose:
337#D-* Examples:
338#D-
339function IGCM_check_PrintFooter
340{
341  IGCM_debug_PushStack "IGCM_check_PrintFooter" $@
342
343  printf "|===========================================================================================================|\n"
344  #date +"${DateFormat}"
345
346  IGCM_debug_PopStack "IGCM_check_PrintFooter"
347}
348
349#D-#==================================================
350#D-function IGCM_check_CheckPendingRebuild
351#D-* Purpose:
352#D-* Examples:
353#D-
354function IGCM_check_CheckPendingRebuild
355{
356  IGCM_debug_PushStack "IGCM_check_PendingRebuild" $@
357
358  NbRebuild="."
359  FirstRebuild="."
360  LastRebuild="."
361
362  if [ ${RebuildExists} == 0 ] ; then
363    set -A RebuildList $( find ${REBUILD_DIR}/ -name "REBUILD_*" | sort )
364    if [ ${#RebuildList[*]} -gt 0 ] ; then
365      NbRebuild=$( IGCM_sys_CountFileArchive ${REBUILD_DIR} )
366
367      FirstRebuild=$( basename ${RebuildList[0]} | cut -f2 -d\_ )
368      LastRebuild=$( basename ${RebuildList[ (( NbRebuild=${NbRebuild}-1 )) ]} | cut -f2 -d\_ )
369    fi
370  fi
371
372  IGCM_debug_PopStack "IGCM_check_PendingRebuild"
373}
374
375#D-#==================================================
376#D-function IGCM_check_CheckRebPackJobs
377#D-* Purpose:
378#D-* Examples:
379#D-
380function IGCM_check_CheckRebPackJobs
381{
382  IGCM_debug_PushStack "IGCM_check_CheckRebPackJobs" $@
383
384  NbLines=0
385  for JobType in ${JobType_list[*]} ; do
386    eval String=\${${JobType}_String}
387    eval Field=\${${JobType}_Field}
388    eval Activ=\${${JobType}_Activ}
389
390    if ( ${Activ} ) ; then
391
392      set -A FileList $( ls ${POST_DIR}/${JobType}.*.out | tail -n ${NbHisto} )
393
394      if [ ${#FileList[*]} -gt ${NbLines} ] ; then
395        NbLines=${#FileList[*]}
396      fi
397
398      (( ind = 0 ))
399      for FileName in ${FileList[*]} ; do
400        LastDate=""
401        LastDate=$( basename ${FileName} | gawk -F"." '{ print $(NF-1) }' )
402
403        set -- $( gawk -v String=${String} \
404                       'BEGIN { nb_ok = 0 ; nb_ko = 0 } \
405                       ($1 ~ String) { \
406                         if ($3 !~ /error./) { \
407                           nb_ok = nb_ok + 1 \
408                         } else { \
409                           nb_ko = nb_ko + 1 \
410                         } \
411                       } \
412                       END { print nb_ok " " nb_ko }' \
413                       ${POST_DIR}/${JobType}.${LastDate}.out )
414        Match=$1
415        Error=$2
416
417        (( Nb = ${Match} - ${Error} ))
418
419        if ( [ ${Error} -eq 0 ] && [ ${Nb} -gt 0 ] ) ; then
420          Status=OK
421        else
422          Status=KO
423        fi
424
425        eval ${JobType}_Date[$ind]=${LastDate}
426        eval ${JobType}_Status[$ind]=${Status}
427        eval ${JobType}_Nb[$ind]=${Nb}
428
429        (( ind = ind + 1 ))
430      done
431
432    else
433
434        eval ${JobType}_Date[0]=""
435        eval ${JobType}_Status[0]=""
436        eval ${JobType}_Nb[0]=""
437
438    fi
439
440  done
441
442  IGCM_debug_PopStack "IGCM_check_CheckRebPackJobs"
443}
444
445#D-#==================================================
446#D-function IGCM_check_CheckMonitoring
447#D-* Purpose:
448#D-* Examples:
449#D-
450function IGCM_check_CheckMonitoring
451{
452  IGCM_debug_PushStack "IGCM_check_CheckMonitoring" $@
453
454    LastDate=""
455    JobType=monitoring
456    IGCM_sys_TestDirArchive ${CWORK_DIR}/MONITORING
457    RC=$?
458    if [ $RC == 0 ] ; then
459      FileTmp=$( IGCM_sys_RshArchive "ls ${CWORK_DIR}/MONITORING/files/*.nc | head -n 1" )
460      IGCM_sys_GetDate_Monitoring ${FileTmp} LastDate
461      eval ${JobType}_Date=${LastDate}
462    fi
463
464  IGCM_debug_PopStack "IGCM_check_CheckMonitoring"
465}
466
467#D-#==================================================
468#D-function IGCM_check_CheckAtlas
469#D-* Purpose:
470#D-* Examples:
471#D-
472function IGCM_check_CheckAtlas
473{
474  IGCM_debug_PushStack "IGCM_check_CheckAtlas" $@
475
476  JobType=atlas
477  IGCM_sys_TestDirArchive ${CWORK_DIR}/ATLAS
478  RC=$?
479  if [ $RC == 0 ] ; then
480    set -A FileList $( IGCM_sys_RshArchive "ls ${CWORK_DIR}/ATLAS | tail -n ${NbHisto}" )
481
482    if [ ${#FileList[*]} -gt ${NbLines} ] ; then
483      NbLines=${#FileList[*]}
484    fi
485
486    (( ind = 0 ))
487    for FileName in ${FileList[*]} ; do
488      eval ${JobType}_Date[$ind]=${FileName}
489      (( ind = ind + 1 ))
490    done
491  fi
492
493  IGCM_debug_PopStack "IGCM_check_CheckAtlas"
494}
Note: See TracBrowser for help on using the repository browser.