EnKF_assemble.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. usage="####################################################################\n\
  3. This routine collects the analysed fields from the EnKF, and assembles \n\
  4. them into files of name analysisXXX.[ab] analysisICE.uf - these files can be \n\
  5. used as restart files by HYCOM. The unassembled fields have names of type\n\
  6. analysisXXX_procXX.[ab] \n\n\
  7. Usage: $(basename $0) restart_template ice_template ensemble_member nproc \n\
  8. Where: \n\
  9. \t\"restart_template\" is an already working restart file \n\
  10. \t\"ice_template\" is an already working ice restart file \n\
  11. \t\"ensemble member\" is the ensemble member number of this restart file \n\
  12. \t\"nproc\" is the number of MPI threads used when running the EnKF \n\
  13. \n\
  14. Example:\n\
  15. \t EnKF_assemble.sh Forecast/ENSrestart2007_289_00.a Forecast/ENSrestart2007_289_00ICE.uf 3 4
  16. \n\n\
  17. NB:\n\
  18. Note that the templates are needed to \"fill in\" what hasn't been updated by the \n\
  19. EnKF in the final analysis file. \n\
  20. ####################################################################\n"
  21. prog="$(dirname $0)/EnKF_assemble"
  22. [ $# -ne 4 ] && { echo -e $usage ; exit 1 ; }
  23. # Run EnKF postprocess -- This processes the analysis files,
  24. # puts the files a final analyzed file, having the correct
  25. # order of the restart fields
  26. $prog $@
  27. [ $? -ne 0 ] && { echo EnKF_assemble failed ; exit 1 ; }
  28. restartbase=$(echo $1 | sed "s/\.[ab]$//")
  29. # The above only reorders the analysis fields into correct order, but
  30. # the ".b" file will lack a header. This copies the header from the
  31. # template file
  32. cmem=$(echo 00$3 | tail -c4)
  33. ppfile=analysis$cmem
  34. myrandom="$RANDOM_$RANDOM"
  35. head -n2 ${restartbase}.b > tmp$myrandom.b
  36. cat ${ppfile}.b >> tmp$myrandom.b
  37. mv tmp$myrandom.b ${ppfile}.b
  38. # We should now have a analysis file named "analysisXXX.[ab]" and analysisICE.uf
  39. echo $?