[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] | 10 | function rebuild_Usage |
---|
| 11 | { |
---|
| 12 | print - " |
---|
| 13 | \"${b_n}\" |
---|
| 14 | rebuild a model_file from several input files. |
---|
| 15 | Each input file contains the model_data for a domain. |
---|
| 16 | |
---|
| 17 | Usage : |
---|
| 18 | ${b_n} [-h] |
---|
| 19 | ${b_n} [-v level] [-f] -o output_file_name input_file_names |
---|
| 20 | |
---|
| 21 | Options : |
---|
| 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] | 34 | d_n=${0%/*}; b_n=${0##*/}; |
---|
[15] | 35 | #- |
---|
[257] | 36 | # Retrieving the options |
---|
[15] | 37 | #- |
---|
[257] | 38 | r_v='0'; r_f='noforce'; r_o=""; |
---|
| 39 | while 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 |
---|
| 50 | shift $(($OPTIND-1)); |
---|
| 51 | #- |
---|
[257] | 52 | # Validate the -v option |
---|
| 53 | #- |
---|
| 54 | case ${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;; |
---|
| 62 | esac |
---|
| 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 | #- |
---|
| 84 | for 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 | #- |
---|
| 91 | echo ${r_v} > tmp.$$; |
---|
| 92 | echo ${r_f} >> tmp.$$; |
---|
[257] | 93 | echo $((${#}+1)) >> tmp.$$; |
---|
[15] | 94 | for i in $*; |
---|
| 95 | do echo ${i} >> tmp.$$; |
---|
| 96 | done |
---|
| 97 | echo ${r_o} >> tmp.$$; |
---|
| 98 | #- |
---|
| 99 | # Create the output file |
---|
| 100 | #- |
---|
| 101 | ${d_n}/flio_rbld < tmp.$$ |
---|
[761] | 102 | r_c=$? |
---|
[15] | 103 | #- |
---|
| 104 | # Clear |
---|
| 105 | #- |
---|
| 106 | rm -f tmp.$$ |
---|
| 107 | #- |
---|
| 108 | # End |
---|
| 109 | #- |
---|
[761] | 110 | exit ${r_c}; |
---|