#!/bin/bash
  Version=v1.0.1
  #cdates=`ls /data2/bzhangys/RODATA/missions/SPIRE/UMDSimulated/atmPhs/${Version}/`
	cdates='2022.091'
# export ROPP_ROOT=/home/jundong/work/ROPP/ropp-9.0
  export ROPP_ROOT=/data/bzhangys/SPIRE/Processing/ROPP/ropp-9.0/

for cdate in ${cdates[@]}
do
	echo $cdate
   ##ORGDIR=/local/bzhang/COSMIC2/TempFiles/${Version}/$cdate
   ORGDIR=/data2/bzhangys/RODATA/missions/SPIRE/UMDSimulated/atmPhs/${Version}/$cdate
   tmpdir=/dev/shm/bzhang/temp
   mkdir -p $tmpdir
   rm -rf /dev/shm/bzhang/temp/*

  # OBJDIR=/local/bzhang/COSMIC2/TempFiles/${Version}/atmPrf/$cdate
  # mkdir -p $OBJDIR 
    OBJDIR=${tmpdir}
  ncs=`ls $ORGDIR/ |grep nc `
	echo "ls $ORGDIR/ |grep nc |grep E"
	echo $ncs
  threads=36
  ip=0
  for nc in ${ncs[@]}
  do
    ip=`echo $ip+1 |bc`
         ${ROPP_ROOT}/gfortran/bin/ucar2ropp $ORGDIR/$nc  -o ${tmpdir}/temp_REMOVABAL$nc & 
    if [[ "$ip" == "$threads" ]]; then 
	 ip=0
	 wait
    fi
  done
  wait
  ip=0
  for nc in ${ncs[@]}
  do
    ip=`echo $ip+1 |bc`
    ofile=`echo $nc|sed 's/atmPhs/atmPrf/g'`
    timeout 30  ${ROPP_ROOT}/gfortran/bin/ropp_pp_occ_tool    ${tmpdir}/temp_REMOVABAL$nc  -o ${tmpdir}/$ofile  -c cosmic_pp.cf  -m GMSIS  -d  -full -d -ellipsoid  >/dev/null  &
    if [[ "$ip" == "$threads" ]]; then
         ip=0
         wait
    fi
  done
  wait 
  rm ${tmpdir}/temp_REMOVAL*nc
   mkdir -p /data2/bzhangys/RODATA/missions/SPIRE/UMDSimulated/atmPrf/${Version}/$cdate
   cp $OBJDIR/atmPrf*.nc /data2/bzhangys/RODATA/missions/SPIRE/UMDSimulated/atmPrf/${Version}/$cdate/
done
