Skip to content

Commit

Permalink
DEV: identify dup fmap
Browse files Browse the repository at this point in the history
  • Loading branch information
jungheejung committed Mar 15, 2024
1 parent af34812 commit e096fc1
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions spacetop_prep/datalad/remove_dups_anatfmap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ LOG_FILE="fmap_error_log.txt"
if [ -f "$LOG_FILE" ]; then
rm "$LOG_FILE"
fi

SUMMARYLOG_FILE="fmap_summary_log.txt"
if [ -f "$SUMMARYLOG_FILE" ]; then
rm "$SUMMARYLOG_FILE"
fi
# mapfile -t dup_files < <(find . -type f -name '*__dup-*')

dup_files=()
Expand All @@ -31,25 +36,38 @@ PRIMARYJSON_NODEC=${PRIMARYJSON_TR%%.*}
DUPJSON_NODEC=${DUPJSON_TR%%.*}
PRIMARYJSON_SEC=$(echo $PRIMARYJSON_NODEC | tr -d '"'| awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
DUPJSON_SEC=$(echo $DUPJSON_NODEC | tr -d '"' | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
#PRIMARYJSON_SEC=$(echo $PRIMARYJSON_TR | awk -F: '{ split($3, a, "."); print ($1 * 3600) + ($2 * 60) + a[1] }')
#DUPJSON_SEC=$(echo $DUPJSON_TR | awk -F: '{ split($3, a, "."); print ($1 * 3600) + ($2 * 60) + a[1] }')

# Compare the numeric values
#if (( $(echo "$PRIMARYJSON_SEC < $DUPJSON_SEC" |bc -l) )); then
if [ "$PRIMARYJSON_SEC" -lt "$DUPJSON_SEC" ]; then
echo -e "\n${DUPJSON}\nPRIMARYJSON acquisition time is earlier." >> $LOG_FILE
echo -e "Error: PRIMARYJSON ${PRIMARYJSON_NODEC} ${PRIMARYJSON_SEC} has an earlier time than DUPJSON ${DUPJSON_NODEC} ${DUPJSON_SEC}\n\n" >> $LOG_FILE
echo -e "\n>>>>> ERROR: PRIMARYJSON ${PRIMARYJSON_NODEC} ${PRIMARYJSON_SEC} has an earlier time than DUPJSON ${DUPJSON_NODEC} ${DUPJSON_SEC}\n\n" >> $LOG_FILE

# SWAP DUP AND PRIMARY, THEN DELETED
PRIMARYGZ=${PRIMARYJSON}
DUPGZ=${DUPJSON} #TODO remove file extension
# RENAME JSON primary is crap, keep dup
# ../../../code/rename_file "${PRIMARYJSON}" CRAPJSON;
# ../../../code/rename_file "${DUPJSON}" "${PRIMARYJSON}";
# ../../../code/rename_file CRAPJSON "${DUPJSON}"
# # RENAME fmap
# ../../../code/rename_file "${PRIMARYGZ}" CRAPNII;
# ../../../code/rename_file "${DUPGZ}" "${PRIMARYGZ}";
# ../../../code/rename_file CRAPNII "${DUPGZ}"
# DELETE files
# git rm "${DUPGZ}"
# git rm "${DUPJSON}"
elif [ "$PRIMARYJSON_SEC" -gt "$DUPJSON_SEC" ]; then
#elif (( $(echo "$PRIMARYJSON_SEC > $DUPJSON_SEC" |bc -l) )); then
echo -e "\nDUPJSON acquisition time is earlier." >> $LOG_FILE
echo -e "Info: DUPJSON is identified as the correct file due to earlier acquisition time." >> $LOG_FILE
echo -e "Info: DUPJSON is identified as the correct file due to earlier acquisition time." >> $SUMMARYLOG_FILE
generic_filename=$(echo "$DUPJSON" | sed -E 's/(run-[0-9]+_).+(__dup-[0-9]+).*/\1*\2.*/')
read -a files_to_remove <<< "$generic_filename"
echo -e "removed files: ${generic_filename}\n\n" >> $LOG_FILE
# Loop through the array and remove each file
for rm_file in "${files_to_remove[@]}"; do
echo "remove!"
# git rm "$rm_file"
git rm "$rm_file"
done
else
echo -e "\n${DUPJSON}\nAcquisition times are the same." >> $LOG_FILE
Expand Down

0 comments on commit e096fc1

Please sign in to comment.