subroutine omflatfield read in task parameters open OM OSW Image file determine file type from datamode in primary header read in the science window keywords from the primary header calculate image binning extract window data from MODES binary table extension extract OM OSW Image open OM Tracking History Data Auxiliary file determine file type from datamode in primary header extract tracking history data from OMTHX1 binary table extension check for poor tracking solution and warn extract OM In Orbit Flatfield file calculate maximum drift in x and y extract localised in orbit flatfield oversample localised in orbit flatfield loop over tracking frames to construct oversampled tracking shifted flatfield loop over discretised tracking steps add shifted oversampled localised in orbit flatfield to oversampled tracking shifted flatfield end loop end loop normalise the summed flatfield resize oversampled tracking shifted flatfield divide OM OSW Image by tracking shifted flatfield resize and rebin OM OSW Image with appropriate binning factors create output OM OSW Image file create output OM PPS flatfield end subroutine omflatfield