#!/opt/tcl803/bin/tcl # load /opt/tcl803/lib/libfitstcl.so # loadlibindex /opt/share/tcl/lib/ucodb/ucodb.tlib # set LogFileP [open fits.log w] set Debug 0 # # for sanity checking, you need to know what to expect. # this surely ought to be a config file. # set Expect(hdus) 6 keylset Expect(1) type "Image extension" keylset Expect(2) type "ASCII Table" name ObjectCat keylset Expect(3) type "ASCII Table" name CatFiles keylset Expect(4) type "ASCII Table" name MaskSlits keylset Expect(5) type "ASCII Table" name SlitObjMap keylset Expect(6) type "ASCII Table" name BluSlits # set Translate(DesDate) ISOtoSybDate set Translate(BluDate) ISOtoSybDate set Translate(email) stripEmailID # loadlibindex ./mask.tlib # source procs # global env # # our synthetic test file is afile.fits set file $argv # set file afile.fits # set err [catch {set ff [fits open $file]} res] if $err { puts stderr "ERROR cannot read FITS file $file" exit 1 } # eatFits $ff # # Having eaten FITS, we spit out a complete summary of the FITS file # in the form of ASCII human-readable files. # One master file describes all the HDUs. # each table extension file then contains the data for a tblext hdu. # the extension files are TSV. # set Target [file root [file tail $file]] if [file isdirectory $Target] { puts stderr "Directory $Target already exists" } else { set err [catch {mkdir $Target} res] if {$err} { puts stderr "SORRY I need to create the dir $Target in [pwd]" puts stderr "ERROR $res" exit 1 } } # set mfp [open $file.txt w] # set ct [llength [array names HDU]] puts $mfp "ANALYSIS of FITS file $file" puts $mfp "\n$file contains $ct FITS HDU:" # foreach h [lsort -integer [array names HDU]] { set hn {} catch {set hn [keylget HDU($h) name]} if {$hn == ""} { set hn "$Target.MASTER" } set ht [keylget HDU($h) type] puts $mfp "\nHDU [format %2.2d $h] : $hn ($ht)" set dfile $Target/$hn.tsv set cfile $Target/$hn.col set kfile $Target/$hn.hdr set kfp [open $kfile w] puts $mfp " kwds : $kfile" foreach k [lsort [keylkeys Kwds($h)]] { puts $kfp "[format "%8.8s = %s" $k [keylget Kwds($h) $k]]" } set cols "" catch {set cols $Cols($h)} if {$cols == ""} {continue} set dfp [open $dfile w] set cfp [open $cfile w] puts $mfp " data : $dfile" puts $mfp " cols : $cfile" set i 1 foreach c $cols { foreach k [keylkeys Cols($h,$i)] { set $k [keylget Cols($h,$i) $k] } puts $cfp "COLUMN: $nam" puts $cfp " type: $typ" puts $cfp " size: $size" puts $cfp "" incr i } set i 1 while {$i >= 0} { if ![info exists Data($h,$i)] {break} set row "" set d $Data($h,$i) foreach c $cols { lappend row [keylget d $c] } set row [join $row \t] puts $dfp $row incr i } close $cfp close $dfp close $kfp }