output.sc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #! /bin/sh
  2. # exit on error
  3. set -e
  4. # --- init -----------------------------------------------
  5. # set program name and location:
  6. case $0 in
  7. /* ) script=$0 ;;
  8. * ) script="`/bin/pwd`/$0" ;;
  9. esac
  10. bindir=`/usr/bin/dirname ${script}`
  11. prog=`/bin/basename ${script}`
  12. # --- help ---
  13. DisplayHelp ()
  14. {
  15. ${PAGER:-less} << EOF
  16. NAME
  17. $prog - store output
  18. USAGE
  19. #$prog <rcfile> <outputdir> <runname> <compdir>
  20. $prog <rcfile> <outputdir> <compdir>
  21. Post process output files.
  22. The script is called with this arguments from the 'run-tm5.jb' script.
  23. Arguments have the following meaning:
  24. <rcfile> : settings
  25. <outputdir> : main directory for output ('outputdir' in rcfile), e.g.
  26. \$TEMP/run.TM5-OUTPUT
  27. #<runname> : subdirectory created by 'run-tm5.jb' within <outputdir>
  28. # with a name including start and end time, e.g.
  29. # TM5_2002110100_2002110300
  30. <compdir> : directory with sources and scripts for this run, e.g.
  31. \$TEMP/run.TM5/xlf90-fast-R64
  32. $prog -h,--help
  33. Display this help text.
  34. RCFILE
  35. The following settings are read from the rcfile :
  36. ! current implementation creates a tar file of <runname> directory
  37. ! and stores this in one or more destination directories (gss descriptions)
  38. output.store.destdirs : \${TEMP}/archive/ ecfs:/klm/archive
  39. ! gzip files before storage (T|F) ?
  40. output.store.compress : F
  41. ! remove files after store (T|F) ?
  42. output.store.clean : F
  43. EOF
  44. exit 0
  45. }
  46. # err 'help text'
  47. err ()
  48. {
  49. echo "$1" 1>&2
  50. }
  51. # errit <exit-status>
  52. errit ()
  53. {
  54. err "$prog - ERROR - Use '$prog --help' for more info."
  55. exit $1
  56. }
  57. # --- arguments ------------------------
  58. # set empty values
  59. rcfile=''
  60. outputdir=''
  61. #runname=''
  62. compdir=''
  63. # extract settings
  64. for arg in "$@" ; do
  65. case ${arg} in
  66. --help | -h ) DisplayHelp ;;
  67. * ) if [ -z "${rcfile}" ]; then
  68. rcfile=${arg}
  69. elif [ -z "${outputdir}" ]; then
  70. outputdir=${arg}
  71. #elif [ -z "${runname}" ]; then
  72. # runname=${arg}
  73. elif [ -z "${compdir}" ]; then
  74. compdir=${arg}
  75. else
  76. err "$prog - ERROR - unknown argument '${arg}'"
  77. errit 1
  78. fi
  79. esac
  80. done
  81. if [ -z "${compdir}" ]; then
  82. err "$prog - ERROR - missing arguments ..."
  83. errit 1
  84. fi
  85. # --- settings -----------------------------------------------------------
  86. # read list with destinations:
  87. destdirs=`${bindir}/go_readrc ${rcfile} 'output.store.destdirs'`
  88. # compress ?
  89. compress=`${bindir}/go_readrc ${rcfile} 'output.store.compress' 'F'`
  90. # clean ?
  91. clean=`${bindir}/go_readrc ${rcfile} 'output.store.clean' 'F'`
  92. # extern:
  93. tar='/usr/bin/tar'
  94. gzip='/usr/bin/gzip'
  95. # --- begin -----------------------------------------------------------
  96. echo "$prog - store output ..."
  97. # name of output directory includes time range:
  98. #outdir="${outputdir}/${runname}"
  99. outdir="${outputdir}"
  100. # tar file to contain sources:
  101. src_tar="${outdir}/src.tar"
  102. # tar sources:
  103. echo "$prog - tar sources ..."
  104. /bin/rm -f ${src_tar} ${src_tar}.gz
  105. ( cd ${compdir}/src ; ${tar} cf ${src_tar} *.[Ff]* *.h Makefile* )
  106. ${gzip} -f ${src_tar}
  107. # goto main output directory:
  108. cd ${outputdir}
  109. ## tar output files:
  110. #tarfile="${runname}.tar"
  111. #echo "$prog - tar run output :"
  112. #${tar} cvf ${tarfile} ${runname}
  113. # compress ?
  114. if [ "${compress}" = "T" ]; then
  115. echo "$prog - compress ..."
  116. # loop over output files:
  117. for outfile in `/bin/ls` ; do
  118. case ${outfile} in
  119. *.gz ) ;;
  120. * ) ${gzip} -f ${outfile} ;;
  121. esac
  122. done
  123. fi
  124. # loop over all destinations:
  125. for destdir in ${destdirs} ; do
  126. echo "$prog - store in ${destdir} ..."
  127. #${bindir}/gss copy --mkdir ${tarfile} ${destdir}/${tarfile}
  128. # loop over output files:
  129. for outfile in `/bin/ls` ; do
  130. # skip some files ...
  131. skip=''
  132. case ${destdir}/${outfile} in
  133. ecfs:*/regions_*.hdf.gz ) skip='true' ;;
  134. ecfs:*/budget_*_glb3x2.hdf.gz ) skip='true' ;;
  135. esac
  136. if [ "${skip}" ]; then
  137. echo "$prog - ${outfile} (skip)"
  138. continue
  139. fi
  140. echo "$prog - ${outfile} ..."
  141. ${bindir}/gss copy --mkdir --force ${outfile} ${destdir}/${outfile}
  142. done
  143. done
  144. # clean
  145. if [ "${clean}" == "T" ]; then
  146. echo "$prog - clean ..."
  147. /bin/rm -f *
  148. #/bin/rm -f ${tarfile}
  149. fi
  150. # --- end --------------------------------------------------------------
  151. echo "$prog - end"