dispatch.bash 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. #
  3. # Given a tarred restart file, puts in on the local repository
  4. #
  5. # Author: F. Massonnet
  6. # Date : November 2016
  7. set -o nounset
  8. set -o errexit
  9. set -x
  10. if [ $# == 0 ]
  11. then
  12. echo "dispatch.bash restart-file.tar"
  13. echo "EXAMPLE: "
  14. echo "dispatch.bash /esnas/exp/nemo/original_files/a05p/restart_files/a05p/19580101/fc00/restarts/RESTO_a05p_19580101_fc00_32_19890101-19891231.tar"
  15. echo ""
  16. exit
  17. fi
  18. rfile=$1
  19. workdir=/scratch/Earth/$USER/TMP_24881
  20. mkdir -p $workdir
  21. echo "WORKDIR >>>>> $workdir <<<<<<"
  22. if [ ! -f $rfile ]
  23. then
  24. echo "$rfile not found"
  25. exit
  26. fi
  27. # Obtain some information...
  28. fbase=`basename $rfile`
  29. exp=$(echo $fbase | cut -d'_' -f 2)
  30. sdate=$(echo $fbase | cut -d'_' -f 3)
  31. memb=$(echo $fbase | cut -d'_' -f 4)
  32. chunk=$(echo $fbase | cut -d'_' -f 5)
  33. runperiod=$(echo $fbase | cut -d'_' -f 6)
  34. runperiod=${runperiod%.tar} # remove the .tar
  35. endperiod=$(echo $runperiod | cut -d'-' -f 2)
  36. #tar xf $rfile -C $workdir
  37. # Check whether the restarts are rebuilt or not. If not, stop -- not coded yet
  38. nfiles_oce=`ls $workdir/NEMO_Restart_${chunk}/${exp}_????????_restart_oce*.nc | wc -l`
  39. nfiles_ice=`ls $workdir/NEMO_Restart_${chunk}/${exp}_????????_restart_ice*.nc | wc -l`
  40. if [ $nfiles_oce != 1 ] || [ $nfiles_ice != 1 ]
  41. then
  42. echo "Either the ocean or the ice restart files are not rebuilt"
  43. echo "Aborting, for now rebuilding outside HPC is not possible"
  44. exit
  45. fi
  46. fileoce=$workdir/NEMO_Restart_${chunk}/${exp}_????????_restart_oce.nc
  47. fileice=$workdir/NEMO_Restart_${chunk}/${exp}_????????_restart_ice.nc
  48. # Get grid information
  49. nx=`ncdump -h $fileoce | grep "x =" | awk {'print $3'}`
  50. ny=`ncdump -h $fileoce | grep "y =" | awk {'print $3'}`
  51. nz=`ncdump -h $fileoce | grep "z =" | awk {'print $3'}`
  52. if [ $nx = 362 ] && [ $ny = 292 ]
  53. then
  54. grid=ORCA1
  55. else
  56. echo "Not coded yet, to add"
  57. exit
  58. fi
  59. # Get sea ice model information. Looking for variable a_i_htc1 which is LIM3-indicative
  60. if [ `ncdump -h $fileice | grep a_i_htc1 | wc -l` != 0 ]
  61. then
  62. seaicemodel=LIM3
  63. else
  64. echo "sea ice model unknown, or maybe LIM2?"
  65. fi
  66. # Create output directory for ocean and ice
  67. if [ ! -d /esnas/releases/ic/ocean/ORCA1L75 ]
  68. then
  69. echo "Configuration does not exist: ${grid}L${nz}"
  70. echo "There must be an error."
  71. exit
  72. fi
  73. # Do the ocean
  74. mkdir -p /esnas/releases/ic/ocean/${grid}L${nz}/${exp}
  75. fileout=/esnas/releases/ic/ocean/${grid}L${nz}/${exp}/${exp}_${memb}_${endperiod}_restart.nc
  76. cp $fileoce $fileout
  77. chmod 777 $fileout
  78. gzip -v $fileout
  79. # Do the ice
  80. mkdir -p /esnas/releases/ic/ice/${grid}_${seaicemodel}/${exp}
  81. fileout=/esnas/releases/ic/ice/${grid}_${seaicemodel}/${exp}/${exp}_${memb}_${endperiod}_restart_ice.nc
  82. cp $fileice $fileout
  83. chmod 777 $fileout
  84. gzip -v $fileout