rebuild 2.3 KB

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