Fcheck_config.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. ######################################################
  3. # Author : Rachid Benshila for NEMO
  4. # Contact : rblod@locean-ipsl.upmc.fr
  5. #
  6. # Some functions called from makenemo
  7. # Fcheck_config : config checking
  8. ######################################################
  9. #set -x
  10. set -o posix
  11. #set -u
  12. #set -e
  13. #+
  14. #
  15. # ================
  16. # Fcheck_config.sh
  17. # ================
  18. #
  19. # --------------------------
  20. # Check the configuration
  21. # --------------------------
  22. #
  23. # SYNOPSIS
  24. # ========
  25. #
  26. # ::
  27. #
  28. # $ Fcheck_config.sh FILENAME CONFNAME
  29. #
  30. #
  31. # DESCRIPTION
  32. # ===========
  33. #
  34. #
  35. # Check the choice of the configuration:
  36. #
  37. # - Two cases
  38. # - One is explicitely set
  39. # - Nothing set, use the previous in use
  40. #
  41. # We use TOOLS/CONFIG_DIR/cfg.txt to check if the configuration exists.
  42. #
  43. # EXAMPLES
  44. # ========
  45. #
  46. # ::
  47. #
  48. # $ ./Fcheck_config.sh
  49. #
  50. #
  51. # TODO
  52. # ====
  53. #
  54. # option debug
  55. #
  56. #
  57. # EVOLUTIONS
  58. # ==========
  59. #
  60. # $Id: Fcheck_config.sh 4990 2014-12-15 16:42:49Z timgraham $
  61. #
  62. #
  63. #
  64. # * creation
  65. #
  66. #-
  67. declare -a ZTAB
  68. if [ ${#2} -eq 0 ]; then
  69. tail -1 ${CONFIG_DIR}/$1 > ${CONFIG_DIR}/cfg.tmp
  70. read -a ZTAB < ${CONFIG_DIR}/cfg.tmp
  71. NEW_CONF=${ZTAB[0]} ; TAB=( ${ZTAB[@]:1} )
  72. \rm ${CONFIG_DIR}/cfg.tmp
  73. echo "Warning !!!"
  74. echo "No configuration specified"
  75. echo "Use makenemo -n MYCONFIG"
  76. echo "or makenemo -h for help"
  77. echo "Using default configuration : ${NEW_CONF}"
  78. fi
  79. if [ "$1" == cfg.txt ]; then
  80. cat ${CONFIG_DIR}/$1 | grep "${NEW_CONF} " > ${CONFIG_DIR}/cfg.tmp
  81. read -a ZTAB < ${CONFIG_DIR}/cfg.tmp
  82. NEW_CONF=${ZTAB[0]} ; TAB=( ${ZTAB[@]:1} )
  83. \rm ${CONFIG_DIR}/cfg.tmp
  84. fi
  85. unset -v ZTAB