
# Quick script to extract recipes from FITS headers and write to the folders

import gpidata
import os
import glob



dirs = glob.glob('*')
for d in dirs:
    #files = glob.glob(os.path.join(d, '*spdc*.fits*'))
    files = glob.glob(os.path.join(d, 'direct', '*spdc*.fits*'))
    if len(files) == 0:
        print "No files in "+d
    else:
        print files[0]
        fitsfile = gpidata.read(files[0])
        #f = open(os.path.join(d,  d+"_recipe.xml"), 'w')
        f = open(os.path.join(d, 'direct', d+"_recipe.xml"), 'w')
        recipe = fitsfile.extractRecipe()
        f.write(recipe)
        f.close()
