Ignore:
Timestamp:
02/21/08 11:44:35 (14 years ago)
Author:
bellier
Message:

JB :

rebuild

adding the verbosity level
some lifting

flio_rbld

new algorithm (should be faster)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • IOIPSL/trunk/tools/rebuild

    r82 r257  
    44# @(#)Rebuild IOIPSL domains 
    55#--------------------------------------------------------------------- 
     6function rebuild_Usage 
     7{ 
     8print - " 
     9\"${b_n}\" 
     10  rebuild a model_file from several input files. 
     11Each input file contains the model_data for a domain. 
     12 
     13Usage : 
     14  ${b_n} [-h] 
     15  ${b_n} [-v level] [-f] -o output_file_name input_file_names 
     16 
     17Options : 
     18  -h         : help 
     19  -v O/1/2/3 : verbose mode (verbosity increasing with level) 
     20  -f         : executing mode 
     21               (execute the program even if the number of input files 
     22                is not equal to the total number of domains) 
     23" 
     24} 
    625#- 
    726#set -xv 
    827#- 
    9 # Extract the calling sequence for the script (d_n/b_n) 
     28# Extract the calling sequence of the script (d_n/b_n) 
    1029#- 
    11 d_n=$(dirname $0); b_n=$(basename $0); 
     30d_n=${0%/*}; b_n=${0##*/}; 
    1231#- 
    13 # Retrieving and validation of the options 
     32# Retrieving the options 
    1433#- 
    15 r_v='silencious'; r_f='noforce'; r_o=""; 
    16 while getopts :hvfo: V 
     34r_v='0'; r_f='noforce'; r_o=""; 
     35while getopts :hv:fo: V 
    1736 do 
    1837  case $V in 
    19    (h) echo ''; 
    20        echo '"'${b_n}'"'; 
    21        echo '  rebuild a model_file from several input files.'; 
    22        echo 'Each input file contains the model_data for a domain.'; 
    23        echo 'Usage :'; 
    24        echo ${b_n} '[-h]'; 
    25        echo ${b_n} '[-v] [-f] -o output_file_name input_file_names'; 
    26        echo ' -h : this help'; 
    27        echo ' -v : verbose mode'; 
    28        echo ' -f : executing mode'; 
    29        echo '  (execute the program even if the number of input files'; 
    30        echo '   is not equal to the total number of domains)'; 
    31        echo ''; 
    32        exit 0;; 
    33    (v) r_v='verbose';; 
     38   (h) rebuild_Usage; exit 0;; 
     39   (v) r_v=${OPTARG};; 
    3440   (f) r_f='force';; 
    3541   (o) r_o=${OPTARG};; 
    36    (:)  echo ${b_n}" : option $OPTARG : missing value" 1>&2; 
    37         exit 2;; 
    38    (\?) echo ${b_n}" : option $OPTARG : not supported" 1>&2; 
    39         exit 2;; 
     42   (:) print -u2 "${b_n} : missing value for option $OPTARG"; exit 2;; 
     43   (\?) print -u2 "${b_n} : option $OPTARG not supported"; exit 2;; 
    4044  esac 
    4145 done 
    4246shift $(($OPTIND-1)); 
    4347#- 
     48# Validate the -v option 
     49#- 
     50case ${r_v} in 
     51  ( 0 | 1 | 2 | 3 );; 
     52  ("") r_v='0';; 
     53  (*) 
     54    print -u2 "${b_n} :"; 
     55    print -u2 "Invalid verbosity level requested : ${r_v}"; 
     56    print -u2 "(must be 0, 1, 2 or 3)"; 
     57    exit 1;; 
     58esac 
     59#- 
    4460# Validate the number of arguments 
    4561#- 
    46 if   [ ${#} -lt 1 ]; then 
    47   echo ${b_n}' : Too few arguments have been specified. (Use -h)' 1>&2; 
     62[[ ${#} < 1 ]] && \ 
     63 { 
     64  print -u2 "${b_n} : Too few arguments have been specified. (Use -h)"; 
    4865  exit 3; 
    49 fi 
     66 } 
    5067#- 
    5168# Check for the output file name 
    5269#- 
    53 if [ '\?'${r_o} = '\?' ]; then 
    54   echo ' ' 1>&2; 
    55   echo ${b_n}' : output_file_name not specified. (Use -h)' 1>&2; 
    56   echo '          "rebuilt_file.nc" should be created.' 1>&2; 
    57   echo ' ' 1>&2; 
    58   r_o='rebuilt_file.nc' 
    59 fi; 
     70[[ -z ${r_o} ]] && \ 
     71 { 
     72  r_o='rebuilt_file.nc'; 
     73  print -u2 - " 
     74   ${b_n} : output_file_name not specified. (Use -h) 
     75            rebuilt_file.nc should be created." 
     76 } 
    6077#- 
    6178# Validate the names of the input files 
    6279#- 
    63 qi=0; 
    6480for i in $*; 
    65  do ((qi=qi+1)); 
    66   [ ${qi} -le ${#} ] && [ ! -f ${i} ] && \ 
    67     { echo "${i} unreachable ..."; exit 3;} 
     81 do 
     82  [[ ! -f ${i} ]] && { echo "${i} unreachable ..."; exit 3;} 
    6883 done 
    6984#- 
     
    7287echo ${r_v} > tmp.$$; 
    7388echo ${r_f} >> tmp.$$; 
    74 ((qi=$#+1)); 
    75 echo ${qi} >> tmp.$$; 
     89echo $((${#}+1)) >> tmp.$$; 
    7690for i in $*; 
    7791 do echo ${i} >> tmp.$$; 
Note: See TracChangeset for help on using the changeset viewer.