Skip to content

Instantly share code, notes, and snippets.

@tony-johnson
Created July 18, 2018 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony-johnson/996ec02b59e4d67859f4d187ad7c7ea4 to your computer and use it in GitHub Desktop.
Save tony-johnson/996ec02b59e4d67859f4d187ad7c7ea4 to your computer and use it in GitHub Desktop.
Example file for compressing .fits files while maintaining modification date and file name
#!/bin/bash
# Compress a FITS file while preserving its name and date
#
# Can be used as follows:
#
# find . -name "*.fits" -mtime +30 -exec fcompress {} \;
#
# Note that fpack will not recompress file already compressed,
# maybe that is good enough, but we also set a file attribute
# in case we need to test that in future for efficiency reasons.
set -e # Exit on error
tstamp=`date -r $1 +%Y%m%d%H%M.%S`
before=`stat -c%s $1`
fpack -F -g2 $1
attr -q -s user.fpack -V true $1
touch -t $tstamp $1
after=`stat -c%s $1`
if (($after < $before)); then
compression=`echo "scale=2; 100*$after/$before" | bc`
echo $1 $compression%
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment