chk_wrk_alloc.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. #
  3. # purpose:
  4. # small script to check in all *90 files of the current directory and subdirectories
  5. # if all lines with wrk_alloc have their corresponding lines with wrk_dealloc
  6. #
  7. # use:
  8. # call chk_wrk_alloc.sh from the directory you want to check
  9. #
  10. # example:
  11. # cd ~/dev_NEMO_MERGE_2011/NEMOGCM/NEMO
  12. # ../TOOLS/MISCELLANEOUS/chk_wrk_alloc.sh
  13. #
  14. set -u
  15. #
  16. echo "check for all *90 files contained in "$( pwd )" and its subdirectories"
  17. #
  18. for ff in $( grep -il "^ *use *wrk_nemo" $( find . -name "*90" ) $( find . -name "*h90" ) )
  19. do
  20. ierr=0
  21. # number of lines with wrk_alloc
  22. n1=$( grep -ic "call *wrk_alloc *(" $ff )
  23. # number of lines with wrk_dealloc
  24. nn1=$( grep -ic "call *wrk_dealloc *(" $ff )
  25. if [ $(( $n1 + $nn1 )) -ne 0 ]
  26. then
  27. # replace wrk_alloc with wrk_dealloc and count the lines
  28. n2=$( sed -e "s/wrk_alloc/wrk_dealloc/" $ff | grep -ic "call *wrk_dealloc *(" )
  29. # we should get n2 = 2 * n1...
  30. if [ $(( 2 * $n1 )) -ne $n2 ]
  31. then
  32. ierr=1
  33. echo "problem with wrk_alloc in $ff"
  34. fi
  35. # same story but for wrk_dealloc
  36. nn2=$( sed -e "s/wrk_dealloc/wrk_alloc/" $ff | grep -ic "call *wrk_alloc *(" )
  37. if [ $(( 2 * $nn1 )) -ne $nn2 ]
  38. then
  39. ierr=1
  40. echo "problem with wrk_dealloc in $ff"
  41. fi
  42. if [ $ierr -eq 0 ] # check that wrk_alloc block is the same as wrk_dealloc block
  43. then
  44. grep -i "call *wrk_alloc *(" $ff | sed -e "s/ //g" | sed -e "s/!.*//g" > txt1$$
  45. grep -i "call *wrk_dealloc *(" $ff | sed -e "s/wrk_dealloc/wrk_alloc/" | sed -e "s/ //g" | sed -e "s/!.*//g" > txt2$$
  46. cmp txt1$$ txt2$$
  47. if [ $? -ne 0 ]
  48. then
  49. echo "different syntax in wrk_alloc and wrk_dealloc in $ff"
  50. echo
  51. for ll in $( seq 1 $n1 ) # compare each line
  52. do
  53. sed -n ${ll}p txt1$$ > ll1$$
  54. sed -n ${ll}p txt2$$ > ll2$$
  55. cmp ll1$$ ll2$$ > /dev/null
  56. if [ $? -ne 0 ]
  57. then
  58. grep -i "call *wrk_alloc *(" $ff | sed -n ${ll}p
  59. grep -i "call *wrk_dealloc *(" $ff | sed -n ${ll}p
  60. echo
  61. fi
  62. rm -f ll1$$ ll2$$
  63. done
  64. fi
  65. rm -f txt1$$ txt2$$
  66. else
  67. grep -i "call *wrk_alloc *(" $ff
  68. echo
  69. grep -i "call *wrk_dealloc *(" $ff
  70. echo
  71. fi
  72. fi
  73. done