#!/bin/bash

# S.Parkin 161219:  One line of bash that extracts the header from Bruker *.sfrm 
# files. The header length of 8240 characters was taken from Paul Boyle's python 
# script (read_sfrm_header.py) that does the same job as sfrmhead. The length of  
# the headers is actually HDRBLKS*512, where HDRBLKS is a parameter given in the 
# header.  Headers for *.sfrm files seen in the UKy X-ray lab. all seem to be 15 
# or 16 blocks.  A string of dots after "CFR: HDR: IMG:" pads each header to the 
# proper number of bytes. All useful information is above this point in any case 
# so it does not matter if we take a few more characters than necessary and chop 
# them after.  Note: We don't even need to do that: because we know the starting 
# and ending strings, 'grep -o' will pull just the header (see the commented out 
# command below). Nevertheless, it is marginally faster to first discard most of 
# the binary stuff using head, presumably because 'grep -o' would otherwise have 
# to grind through the whole .sfrm file rather than just the first 8240 bytes.

head -c 8240 $1.sfrm | grep -o 'FORMAT.*CFR: HDR: IMG:' | fold -w80 > $1.header

#grep -o 'FORMAT.*CFR: HDR: IMG:' $1.sfrm | fold -w80 > $1.header

