[15] | 1 | #!/bin/ksh |
---|
[82] | 2 | #$Id$ |
---|
[15] | 3 | #--------------------------------------------------------------------- |
---|
| 4 | # @(#)Rebuild IOIPSL domains |
---|
| 5 | #--------------------------------------------------------------------- |
---|
[257] | 6 | function rebuild_Usage |
---|
| 7 | { |
---|
| 8 | print - " |
---|
| 9 | \"${b_n}\" |
---|
| 10 | rebuild a model_file from several input files. |
---|
| 11 | Each input file contains the model_data for a domain. |
---|
| 12 | |
---|
| 13 | Usage : |
---|
| 14 | ${b_n} [-h] |
---|
| 15 | ${b_n} [-v level] [-f] -o output_file_name input_file_names |
---|
| 16 | |
---|
| 17 | Options : |
---|
| 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 | } |
---|
[15] | 25 | #- |
---|
| 26 | #set -xv |
---|
| 27 | #- |
---|
[257] | 28 | # Extract the calling sequence of the script (d_n/b_n) |
---|
[15] | 29 | #- |
---|
[257] | 30 | d_n=${0%/*}; b_n=${0##*/}; |
---|
[15] | 31 | #- |
---|
[257] | 32 | # Retrieving the options |
---|
[15] | 33 | #- |
---|
[257] | 34 | r_v='0'; r_f='noforce'; r_o=""; |
---|
| 35 | while getopts :hv:fo: V |
---|
[15] | 36 | do |
---|
| 37 | case $V in |
---|
[257] | 38 | (h) rebuild_Usage; exit 0;; |
---|
| 39 | (v) r_v=${OPTARG};; |
---|
[15] | 40 | (f) r_f='force';; |
---|
| 41 | (o) r_o=${OPTARG};; |
---|
[257] | 42 | (:) print -u2 "${b_n} : missing value for option $OPTARG"; exit 2;; |
---|
| 43 | (\?) print -u2 "${b_n} : option $OPTARG not supported"; exit 2;; |
---|
[15] | 44 | esac |
---|
| 45 | done |
---|
| 46 | shift $(($OPTIND-1)); |
---|
| 47 | #- |
---|
[257] | 48 | # Validate the -v option |
---|
| 49 | #- |
---|
| 50 | case ${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;; |
---|
| 58 | esac |
---|
| 59 | #- |
---|
[15] | 60 | # Validate the number of arguments |
---|
| 61 | #- |
---|
[257] | 62 | [[ ${#} < 1 ]] && \ |
---|
| 63 | { |
---|
| 64 | print -u2 "${b_n} : Too few arguments have been specified. (Use -h)"; |
---|
[15] | 65 | exit 3; |
---|
[257] | 66 | } |
---|
[15] | 67 | #- |
---|
| 68 | # Check for the output file name |
---|
| 69 | #- |
---|
[257] | 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 | } |
---|
[15] | 77 | #- |
---|
| 78 | # Validate the names of the input files |
---|
| 79 | #- |
---|
| 80 | for i in $*; |
---|
[257] | 81 | do |
---|
| 82 | [[ ! -f ${i} ]] && { echo "${i} unreachable ..."; exit 3;} |
---|
[15] | 83 | done |
---|
| 84 | #- |
---|
| 85 | # Create the information file for the program |
---|
| 86 | #- |
---|
| 87 | echo ${r_v} > tmp.$$; |
---|
| 88 | echo ${r_f} >> tmp.$$; |
---|
[257] | 89 | echo $((${#}+1)) >> tmp.$$; |
---|
[15] | 90 | for i in $*; |
---|
| 91 | do echo ${i} >> tmp.$$; |
---|
| 92 | done |
---|
| 93 | echo ${r_o} >> tmp.$$; |
---|
| 94 | #- |
---|
| 95 | # Create the output file |
---|
| 96 | #- |
---|
| 97 | ${d_n}/flio_rbld < tmp.$$ |
---|
| 98 | #- |
---|
| 99 | # Clear |
---|
| 100 | #- |
---|
| 101 | rm -f tmp.$$ |
---|
| 102 | #- |
---|
| 103 | # End |
---|
| 104 | #- |
---|
| 105 | exit 0; |
---|