1. Obtain list of files to be pinned

2. Create a working cdbs area:
mkdir /eng/ssb/syn_pysyn/cdbs_pinned
cp -r /grp/hst/cdbs/comp/  /eng/ssb/syn_pysyn/cdbs_pinned
cp -r /grp/hst/cdbs/mtab  /eng/ssb/syn_pysyn/cdbs_pinned
ln -s /grp/hst/cdbs/grid/ /eng/ssb/syn_pysyn/cdbs_pinned
ln -s /grp/hst/cdbs/extinction/ /eng/ssb/syn_pysyn/cdbs_pinned
ln -s /grp/hst/cdbs/calspec/ /eng/ssb/syn_pysyn/cdbs_pinned

3. Loop over the pinlist from within the shell
flist=open('combined_pinlist.txt')
bluelist=open('combined_bluelist.txt')
out=open('combined_pinlist.log','w')
outb=open('combined_bluelist.log','w')
import extrap,os
os.chdir('/eng/ssb/syn_pysyn/cdbs_pinned')
for fname in flist:
    x=extrap.run(fname.strip())
    out.write("%s\n"%x)
flist.close()
out.close()

4. Loop over the blueside-only list

for fname in bluelist:
    x=extrap.blue(fname.strip())
    outb.write("%s\n"%x)
bluelist.close
outb.close()

5. Create the new TMC file
os.chdir('/eng/ssb/syn_pysyn/cdbs_pinned/')
extrap.buildtmc('mtab/s8i22541m_tmc.fits')
mv mtab/s8i22541m_tmc_new.fits mtab/zzz_s8i22541m_tmc.fits
