source: trunk/libIGCM/AA_RunChecker @ 953

Last change on this file since 953 was 953, checked in by labetoulle, 11 years ago

RunChecker? : use getopts built-in function to parse command line options.

  • Property svn:keywords set to Revision Author Date
File size: 6.1 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sonia Labetoulle
5# Contact: sonia.labetoulle__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2012)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#======================================================================#
15# Display a report on how a simulation is faring.
16
17
18
19#======================================================================#
20
21#D- Task type (computing, post-processing or checking)
22TaskType=checking
23typeset -i Verbosity=0
24
25CurrentUsr=$( whoami )
26
27if ( [ $# -eq 0 ] ) ; then
28  $0 -h
29  exit
30fi
31
32# Arguments
33# =========
34# Default argument values
35# -----------------------
36TargetUsr=${CurrentUsr}
37HostName=$( hostname | sed -e "s/[0-9].*//" )
38
39fg_color=true
40fg_search=false
41fg_quiet=false
42fg_path=false
43NbHisto=20
44
45# Get arguments from command line
46# -------------------------------
47while getopts :hj:p:qsu: Opt ; do
48  case $Opt in
49    h)
50      echo "usage: $0 [-u user] [-q] [-j n] [-s] job_name"
51      echo "       $0 [-u user] [-q] [-j n] -p config.card_path"
52      echo "       $0 [-u user] [-q] [-j n] -r"
53      echo ""
54      echo "options :"
55      echo "  -h : print this help and exit"
56      echo "  -u : owner of the job"
57      echo "  -q : quiet"
58      echo "  -j : print n post-processing jobs (default is 20)"
59      echo "  -s : search for a new job in \$WORKDIR and fill in "
60      echo "       the catalog before printing information"
61      echo "  -p : give the directory (absolute path) containing "
62      echo "       the config.card instead of the job name."
63      exit 0 ;;
64    j)
65      NbHisto=${OPTARG}
66      ;;
67    p)
68      fg_path=true
69      ConfigPath=${OPTARG}
70      ;;
71    q)
72      fg_quiet=true
73      ;;
74    s)
75      fg_search=true
76      ;;
77    u)
78      TargetUsr=${OPTARG}
79      ;;
80    :)
81      echo "$0: -"${OPTARG}" option: missing value"
82      exit 1
83      ;;
84    \?)
85      echo "$0: -"${OPTARG}" option: not supported"
86      exit 1
87      ;;
88  esac
89done
90shift $(($OPTIND-1))
91
92if ( ( ! ${fg_path} ) && ( ! ${fg_running} ) && [ $# -lt 1 ] ) ; then
93  $0 -h
94  exit
95fi
96
97if ( ( ${fg_path} ) && ( ${fg_search} ) ) ; then
98  echo "You cannot use -s and -p at the same time"
99  exit
100fi
101
102
103# Load libIGCM library
104# ====================
105libIGCM=${libIGCM:=::modipsl::/libIGCM}
106
107DEBUG_debug=false
108DEBUG_sys=false
109
110. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
111. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
112. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
113#-------
114. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
115. ${libIGCM}/libIGCM_check/libIGCM_check.ksh
116. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
117#-------
118( ${DEBUG_debug} ) && IGCM_debug_Check
119( ${DEBUG_debug} ) && IGCM_card_Check
120( ${DEBUG_debug} ) && IGCM_date_Check
121
122
123JobName=$1
124
125if ( ${fg_quiet} ) ; then
126  NbHisto=1
127fi
128
129# Define the catalog in which the known simulations are stored
130# ============================================================
131SimuCatalog="${HOME}/.simucatalog.dat"
132if [ ! -s ${SimuCatalog} ] ; then
133  touch ${SimuCatalog}
134fi
135
136# Find SUBMIT_DIR in catalog
137# ==========================
138IGCM_check_SearchCatalog
139
140if [ ! X${SUBMIT_DIR} == X ] ; then
141
142  IGCM_sys_Cd $SUBMIT_DIR
143
144
145  # Extract usefull information from run.card and config.card
146  # =========================================================
147
148  RunFile="${SUBMIT_DIR}/run.card"
149  ConfFile="${SUBMIT_DIR}/config.card"
150
151  IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card
152  IGCM_check_CommonDef
153
154
155  if [ -s ${RunFile} ] ; then
156    IGCM_card_DefineVariableFromOption ${RunFile} Configuration PeriodState
157    PeriodState=${run_Configuration_PeriodState}
158  else
159    PeriodState="Waiting"
160  fi
161
162  if ( [ X${PeriodState} == XRunning ] || [ X${PeriodState} == XOnQueue ] ) ; then
163    #NbRun=$( ccc_mstat -f | grep -c ${JobName} )
164    IGCM_sys_CountJobInQueue ${JobName} NbRun
165
166    if [ ${NbRun} -eq 0 ] ; then
167      PeriodState="Fatal"
168    fi
169  fi
170
171  DateBegin=${config_UserChoices_DateBegin}
172  DateEnd=${config_UserChoices_DateEnd}
173  TagName=${config_UserChoices_TagName}
174  ExperimentName=${config_UserChoices_ExperimentName}
175  SpaceName=${config_UserChoices_SpaceName}
176
177
178  if ( [ ! X${PeriodState} == XWaiting ] && [ ! X${PeriodState} == XCompleted ] ) ; then
179    IGCM_card_DefineVariableFromOption ${RunFile} Configuration PeriodDateBegin
180    IGCM_card_DefineVariableFromOption ${RunFile} Configuration PeriodDateEnd
181    IGCM_card_DefineVariableFromOption ${RunFile} Configuration CumulPeriod
182    PeriodDateBegin=${run_Configuration_PeriodDateBegin}
183    PeriodDateEnd=${run_Configuration_PeriodDateEnd}
184    CumulPeriod=${run_Configuration_CumulPeriod}
185  else
186    PeriodDateBegin="."
187    PeriodDateEnd="."
188    CumulPeriod="."
189  fi
190
191  DATA_DIR=${R_SAVE}
192  POST_DIR=${R_BUFR}/Out
193  CWORK_DIR=${R_FIGR}
194
195  if [ ${TargetUsr} != ${CurrentUsr} ] ; then
196    DATA_DIR=$( IGCM_check_ChangeUsr ${DATA_DIR} )
197    POST_DIR=$( IGCM_check_ChangeUsr ${POST_DIR} )
198    CWORK_DIR=$( IGCM_check_ChangeUsr ${CWORK_DIR} )
199    REBUILD_DIR=$( IGCM_check_ChangeUsr ${REBUILD_DIR} )
200  fi
201
202  if [ $PeriodState != "Waiting" ] ; then
203    # Check pending REBUILDS
204    # ======================
205    IGCM_check_CheckPendingRebuild
206
207    # Check last REBUILD and PACK* jobs
208    # =================================
209    IGCM_check_CheckRebPackJobs
210
211    # Check last MONITORING jobs
212    # ==========================
213    IGCM_check_CheckMonitoring
214
215    # Check last ATLAS jobs
216    # =====================
217    IGCM_check_CheckAtlas
218
219    # Time of last write on run.card
220    # ==============================
221    LastWrite=$( ls -l --time-style=+"${DateFormat}" ${SUBMIT_DIR}/run.card | gawk '{print $6 " " $7}' )
222
223  else
224
225    NbRebuild="."
226    FirstRebuild="."
227    LastRebuild="."
228
229    NbLines=0
230
231  fi
232
233
234  # Print results
235  # =============
236  IGCM_check_PrintHeader
237  ind=0
238  while [ $ind -lt $NbLines ] ; do
239    IGCM_check_PrintJob
240    (( ind = ind + 1 ))
241  done
242  IGCM_check_PrintFooter
243
244fi
Note: See TracBrowser for help on using the repository browser.