
#!/usr/bin/env bash
# Source root and destination root
SRC="/home/lisa_nlddpc-lsperi/GitHub/DataAnalysisWithSFT/tdi_search"
DEST="./tdi_search"   # or any other path you want

mkdir -p "$DEST"

for d in "$SRC"/tdi_search_*snr25.0; do
  src_best="$d/best_results.h5"
  src_log="$d/search_log.h5"
  if [[ -f "$src_best" ]]; then
    # Relative path under SRC (strip the prefix SRC/)
    rel="${d#"$SRC/"}"
    # Full destination folder path preserving structure
    dest_dir="$DEST/$rel"

    echo "Creating: $dest_dir"
    mkdir -p "$dest_dir"

    echo "Copy: $src_best -> $dest_dir/best_results.h5"
    cp -v "$src_best" "$dest_dir/best_results.h5"

    echo "Copy: $src_log -> $dest_dir/search_log.h5"
    cp -v "$src_log" "$dest_dir/search_log.h5"
  fi
done

for d in "$SRC"/tdi_search_*snr35.0; do
  src_best="$d/best_results.h5"
  src_log="$d/search_log.h5"
  if [[ -f "$src_best" ]]; then
    # Relative path under SRC (strip the prefix SRC/)
    rel="${d#"$SRC/"}"
    # Full destination folder path preserving structure
    dest_dir="$DEST/$rel"

    echo "Creating: $dest_dir"
    mkdir -p "$dest_dir"

    echo "Copy: $src_best -> $dest_dir/best_results.h5"
    cp -v "$src_best" "$dest_dir/best_results.h5"

    echo "Copy: $src_log -> $dest_dir/search_log.h5"
    cp -v "$src_log" "$dest_dir/search_log.h5"
  fi
done

for d in "$SRC"/tdi_search_*snr40.0; do
  src_best="$d/best_results.h5"
  src_log="$d/search_log.h5"
  if [[ -f "$src_best" ]]; then
    # Relative path under SRC (strip the prefix SRC/)
    rel="${d#"$SRC/"}"
    # Full destination folder path preserving structure
    dest_dir="$DEST/$rel"

    echo "Creating: $dest_dir"
    mkdir -p "$dest_dir"

    echo "Copy: $src_best -> $dest_dir/best_results.h5"
    cp -v "$src_best" "$dest_dir/best_results.h5"

    echo "Copy: $src_log -> $dest_dir/search_log.h5"
    cp -v "$src_log" "$dest_dir/search_log.h5"
  fi
done

# rm -rf "$SRC"

# rm *.pkl 
# rm *.h5
# rm *.pdf