Skip to content
Snippets Groups Projects
Commit c5e7ea31 authored by mnb's avatar mnb Committed by afarrell
Browse files

Modified the FitsOps:ValidFitsFile not to open the specified fits file for...

Modified the FitsOps:ValidFitsFile not to open the specified fits file for validity testing as failures caused memory leaks
	Modified the FitsOps:ValidFitsFile not to open the specified
        fits file for validity testing as failures caused memory leaks
parent b60b3b15
No related branches found
Tags 1.109
No related merge requests found
......@@ -21,23 +21,36 @@
# Returns 0 if invalid (0= false)
# 1 if valid (1= true)
#
proc FitsOps:ValidFitsFile {filename} {
proc FitsOps:ValidFitsFile {filename {time_stamp_check 1}} {
# first check if file exists
if {![file exists $filename]} {
return 0
}
# now check if opening file (in read mode) results in error
set err_flag [catch {set fob [fits open $filename 0]}]
set ret [ChkFile $filename]
if {$ret==0 || !$time_stamp_check } {return $ret}
# --------------------------
# Now make a time step check
# --------------------------
# Calculate the age in seconds since this file was last modified
set age_in_secs [expr [clock seconds] - [ file mtime $filename ]]
# Check that it has been at least 3 seconds since this file was last
# modified
if {$age_in_secs<3} {return 0}
# Everything is good so return 1.
return 1
if {$err_flag} {
return 0
} else {
$fob close
return 1
}
}
proc ChkFile {file} {
if {![file exists $file]} {return 0}
if {![file readable $file]} {return 0}
if {[file extension $file]!=".fits"} {return 0}
return 1
}
#******************************************************************************
#
......@@ -762,7 +775,10 @@ proc FitsOps:FluxEx {fitsfile outfile} {
proc FitsOps:ListExtensions {fitsfile} {
# open file
set fob [fits open $fitsfile 0] ;# read only
set err_flag [catch {
set fob [fits open $fitsfile 0] ;# read only
}]
if {$err_flag} {puts "e1";catch {$fob close}; return ""}
# go through each HDU
set n_hdu [$fob info nhdu]
......@@ -770,8 +786,11 @@ proc FitsOps:ListExtensions {fitsfile} {
for {set idx 1} {$idx<=$n_hdu} {incr idx 1} {
# make this CHDU
$fob move $idx
set err_flag [catch {
$fob move $idx
}]
if {$err_flag} {puts "e2"; catch {$fob close}; return ""}
# Get keyword definition list for EXTNAME
# Some 2dfdr old combined files don't have EXTNAME for primary HDU
# If error assume keyword does not exist and skip this HDU
......@@ -1001,8 +1020,20 @@ proc FitsOps:TableDump {fitsfile tablename arrayname} {
upvar $arrayname dataA
# Open the fits file, but in the event of an error
# return some dummy values
set fob [fits open $fitsfile 0] ;# read only
set err_flag {
puts "Table Dump error ${err_msg}"
set col_names "?"
set dataA(col_names) $col_names
set dataA(n_cols) 1
set dataA(n_rows) 1
set dataA(1,1) "???"
return $col_names
}
# find HDU with extension name that matches table name
set hdu [FitsFobOps:FindExtensionHDU $fob $tablename]
if {$hdu==-1} {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment