define_table_126.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. # This script defines grib table 126 for EC-Earth usage.
  3. # The new grib definitions are put in the source dir of EC-Earth 3.
  4. set -e
  5. # --- Path to "grib_api/definitions"
  6. GRIBAPI_BASE_DIR=$(EBROOTGRIB_API)
  7. errmess="*ERROR*: Could not find the path to grib_info or codes_info
  8. commands. Please set GRIBAPI_BASE_DIR manually, or load the
  9. GRIB_API or ECCODES module if you rely on module to set your
  10. env, and run this script again."
  11. if [ -z "${GRIBAPI_BASE_DIR}" ]
  12. then
  13. echo Your GRIBAPI_BASE_DIR is empty
  14. echo Trying to retrieve '<your-grib_api-root-dir>/share/[grib_api|eccodes]/definitions'
  15. echo from environment instead...
  16. echo Note that if both grib_info and codes_info are found in your path,
  17. echo GRIB_API takes precedence over ECCODES
  18. info=($(which grib_info codes_info 2>/dev/null || true))
  19. if [ -x "${info[0]}" ]
  20. then
  21. grib_def_dir=$(${info[0]} | sed -n "s|Default definition files path is used: ||p")
  22. else
  23. echo "$errmess"
  24. exit 1
  25. fi
  26. if [ -z "${grib_def_dir}" ]
  27. then
  28. echo "$errmess"
  29. exit 1
  30. else
  31. echo Found it.
  32. fi
  33. elif [ -e ${GRIBAPI_BASE_DIR}/share/grib_api/definitions ]
  34. then
  35. grib_def_dir=${GRIBAPI_BASE_DIR}/share/grib_api/definitions
  36. elif [ -e ${GRIBAPI_BASE_DIR}/share/eccodes/definitions ]
  37. then
  38. grib_def_dir=${GRIBAPI_BASE_DIR}/share/eccodes/definitions
  39. else
  40. echo "ERROR: Path ${GRIBAPI_BASE_DIR}/share/[grib_api|eccodes]/definitions does not exist"
  41. exit 1
  42. fi
  43. # --- Create target and populate
  44. target_dir=${HOME}/models/ecearth_3.3.3.2/sources/util/grib_table_126/grib1/localConcepts/ecmf
  45. mkdir -p ${target_dir}
  46. cp ${grib_def_dir}/grib1/localConcepts/ecmf/* ${target_dir}
  47. # --- additions to grib definitions for EC-Earth table 126
  48. cd $target_dir
  49. for ((i=1;i<=255;i++))
  50. do
  51. #cfVarname
  52. cat >> cfVarName.def <<EOF
  53. # EC-Earth product $i
  54. 'ece${i}.126' = {
  55. table2Version = 126 ;
  56. indicatorOfParameter = $i ;
  57. }
  58. EOF
  59. # paramId
  60. str=126${i}
  61. lim=100
  62. if [ $i -lt $lim ]; then
  63. str=1260${i}
  64. fi
  65. lim=10
  66. if [ $i -lt $lim ]; then
  67. str=12600${i}
  68. fi
  69. cat >> paramId.def <<EOF
  70. # EC-Earth product $i
  71. '${str}' = {
  72. table2Version = 126 ;
  73. indicatorOfParameter = $i ;
  74. }
  75. EOF
  76. #name
  77. cat >> name.def <<EOF
  78. # EC-Earth product $i
  79. 'EC-Earth product $i' = {
  80. table2Version = 126 ;
  81. indicatorOfParameter = $i ;
  82. }
  83. EOF
  84. #shortName
  85. cat >> shortName.def <<EOF
  86. # EC-Earth product $i
  87. '~' = {
  88. table2Version = 126 ;
  89. indicatorOfParameter = $i ;
  90. }
  91. EOF
  92. #units
  93. cat >> units.def <<EOF
  94. # EC-Earth product $i
  95. '~' = {
  96. table2Version = 126 ;
  97. indicatorOfParameter = $i ;
  98. }
  99. EOF
  100. done