source: IOIPSL/trunk/tools/rebuild @ 3510

Last change on this file since 3510 was 761, checked in by bellier, 15 years ago

Added a return code for bad processing

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.2 KB
RevLine 
[15]1#!/bin/ksh
[386]2#
[82]3#$Id$
[386]4#
5# This software is governed by the CeCILL license
6# See IOIPSL/IOIPSL_License_CeCILL.txt
[15]7#---------------------------------------------------------------------
8# @(#)Rebuild IOIPSL domains
9#---------------------------------------------------------------------
[257]10function rebuild_Usage
11{
12print - "
13\"${b_n}\"
14  rebuild a model_file from several input files.
15Each input file contains the model_data for a domain.
16
17Usage :
18  ${b_n} [-h]
19  ${b_n} [-v level] [-f] -o output_file_name input_file_names
20
21Options :
22  -h         : help
23  -v O/1/2/3 : verbose mode (verbosity increasing with level)
24  -f         : executing mode
25               (execute the program even if the number of input files
26                is not equal to the total number of domains)
27"
28}
[15]29#-
30#set -xv
31#-
[257]32# Extract the calling sequence of the script (d_n/b_n)
[15]33#-
[257]34d_n=${0%/*}; b_n=${0##*/};
[15]35#-
[257]36# Retrieving the options
[15]37#-
[257]38r_v='0'; r_f='noforce'; r_o="";
39while getopts :hv:fo: V
[15]40 do
41  case $V in
[257]42   (h) rebuild_Usage; exit 0;;
43   (v) r_v=${OPTARG};;
[15]44   (f) r_f='force';;
45   (o) r_o=${OPTARG};;
[257]46   (:) print -u2 "${b_n} : missing value for option $OPTARG"; exit 2;;
47   (\?) print -u2 "${b_n} : option $OPTARG not supported"; exit 2;;
[15]48  esac
49 done
50shift $(($OPTIND-1));
51#-
[257]52# Validate the -v option
53#-
54case ${r_v} in
55  ( 0 | 1 | 2 | 3 );;
56  ("") r_v='0';;
57  (*)
58    print -u2 "${b_n} :";
59    print -u2 "Invalid verbosity level requested : ${r_v}";
60    print -u2 "(must be 0, 1, 2 or 3)";
61    exit 1;;
62esac
63#-
[15]64# Validate the number of arguments
65#-
[257]66[[ ${#} < 1 ]] && \
67 {
68  print -u2 "${b_n} : Too few arguments have been specified. (Use -h)";
[15]69  exit 3;
[257]70 }
[15]71#-
72# Check for the output file name
73#-
[257]74[[ -z ${r_o} ]] && \
75 {
76  r_o='rebuilt_file.nc';
77  print -u2 - "
78   ${b_n} : output_file_name not specified. (Use -h)
79            rebuilt_file.nc should be created."
80 }
[15]81#-
82# Validate the names of the input files
83#-
84for i in $*;
[257]85 do
86  [[ ! -f ${i} ]] && { echo "${i} unreachable ..."; exit 3;}
[15]87 done
88#-
89# Create the information file for the program
90#-
91echo ${r_v} > tmp.$$;
92echo ${r_f} >> tmp.$$;
[257]93echo $((${#}+1)) >> tmp.$$;
[15]94for i in $*;
95 do echo ${i} >> tmp.$$;
96 done
97echo ${r_o} >> tmp.$$;
98#-
99# Create the output file
100#-
101${d_n}/flio_rbld < tmp.$$
[761]102r_c=$?
[15]103#-
104# Clear
105#-
106rm -f tmp.$$
107#-
108# End
109#-
[761]110exit ${r_c};
Note: See TracBrowser for help on using the repository browser.