STScI logoSTSDAS Help Pages
checkfiles checkfiles


# CHECKFILES -- Check for the existence of GHRS files
#
# Version 1.0  Sep95  S. Hulbert
# Version 1.1 Oct95  L.E.Sherbert
#

procedure checkfiles (input)

file   input = "*" {prompt=">input filenames"}

begin

file  temp0, temp1, tempx, tempC
string temp3, temp4, temp5, temp6, temp7
string temp8, temp9 		# files for storing filenames or Complaints
string obsmode, aper, grat		# variables for header keyword info
int	len, i, j, iext, num
char	ext[33], exist[33]

# define the GHRS extensions
num = 33
ext[01] = "jih"
ext[02] = "jid"
ext[03] = "jit"
ext[04] = "pdq"
ext[05] = "d1h"
ext[06] = "d1d"
ext[07] = "shh"
ext[08] = "shd"
ext[09] = "ulh"
ext[10] = "uld"
ext[11] = "trl"
ext[12] = "d0h"
ext[13] = "d0d"
ext[14] = "q0h"
ext[15] = "q0d"
ext[16] = "x0h"
ext[17] = "x0d"
ext[18] = "xqh"
ext[19] = "xqd"
ext[20] = "c0h"
ext[21] = "c0d"
ext[22] = "c1h"
ext[23] = "c1d"
ext[24] = "c2h"
ext[25] = "c2d"
ext[26] = "cqh"
ext[27] = "cqd"
ext[28] = "c3h"
ext[29] = "c3d"
ext[30] = "c4h"
ext[31] = "c4d"
ext[32] = "c5h"
ext[33] = "c5d"

temp0 = mktemp("tmp$chkfls0_")
tempx = mktemp("tmp$chkflsx_")
temp1 = mktemp("tmp$chkfls1_")
tempC = mktemp("tmp$chkflsC_")


# make a list of rootnames from the input filenames 
# and delete redundant entries

files (input, sort+, > temp0)

#set up header
printf ("#rootname obsmode ")
for (i=1; i <= num; i += 1) 
    printf ("%s ",ext[i])
printf ("\n")

# loop through the list of files
list = temp0
while (fscan (list, temp3) != EOF) {

    # Build file name
    len = strlen (temp3)
    iext = 0

## BUG encountered when filenames start with ".", eg ../z2u908*
## checkfiles only spits out list of files; doesn't get rootname
    # look for an extension
## JDE says to use fparse to avoid the bug encountered when filenames start with "."
    for (i = 1; i <= len-3; i += 1) {
        if (substr(temp3, i, i) == ".") {
           iext = i-1
           break
        }
    }
    # if we don't find an extension assume we have a rootname
    if (iext == 0) iext = len 

    # make the rootname
    temp4 = substr (temp3, 1, iext) 
    printf ("%s\n", temp4, >> tempx)

}
# end loop through the list of files

# make a unique list of rootnames
tproject (tempx, temp1, "*", uniq+)

# fake existence of tempC to avoid stupid error...
print(" ", > tempC)
# tempC will record list of missing extensions until I 
# find a better place for it

# # loop through the list of rootnames
list = temp1
while (fscan (list, temp6) != EOF) {

    # throw out the "j" files, they are a sort of redundancy
    len = strlen (temp6)
    # look for a  "j"
    if (substr(temp6, len, len) =="j") 
       next

    printf ("%s ", temp6)  # print out rootname

    # loop through the non-jitter extensions; verify existence
    for (i=4; i <= num; i += 1) {
        temp5 = temp6 + "." + ext[i]
        if (access(temp5))
           exist[i] = " X "
        else 
           exist[i] = "   "
    }
    # END loop through the non-jitter extensions; verify existence

    # now hack at rootname to get back the "j" ending
    temp7 = substr(temp6, 1, len-1) +"j"

    # loop through the jitter extensions; verify existence
    for (i=1; i <= 3; i += 1) {
        temp5 = temp7 + "." + ext[i]
        if (access(temp5))
           exist[i] = " X "
        else
           exist[i] = "   "
    }  
    # END loop through the jitter extensions; verify existence
    
    # look at the obsmode in prep for complaining about missing items
    temp8 = temp6 // ".ulh"
    temp9 = temp6 // ".shh"
    if (access(temp8) && access(temp9)) {
       hsel(temp8,"obsmode","yes") | scan(obsmode) 
       obsmode = substr(obsmode, 1, 7)
       printf ("%7s ", obsmode)  # print obsmode after rootname
    
       # try to put a value into i to look for missing files
       # loop through all the possible extensions
       for (i=1; i <= num; i += 1) {

         # check to see if extensions exists; complain if not and it is expected
         # do not complain if we would not expect that extension anyway
         if (obsmode == "ACCUM") { 
            if (exist[i] != " X ") {
               switch(i) {
                  case 1,2,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19: {
                     print("Missing ",ext[i]," for ",temp6, >> tempC)
                  }
                  case 20,21,22,23,24,25,26,27,28,29,30,31,32,33: {
                     print("Missing ",ext[i]," for ",temp6, >> tempC)
                  }
               }
            }
         }
         if (obsmode == "ACQ") {
            if (exist[i] != " X ") {
               switch(i) {
                  case 1,2,3,4,7,8,9,10,11: {
                     print("Missing ",ext[i]," for ",temp6, >> tempC)
                  }
                  case 5,6: {
                     # complain that d1h,d1d missing for possible RTB
                     print("Missing ",ext[i]," for ",temp6,".  Can't tell if it is RTB or not.  Please check.", >> tempC)
                  }
               }
            }
         }
         if (obsmode == "ACQ/PEA") {
            if (exist[i] != " X ") {
               switch(i) {
                  case 1,2,3,4,7,8,9,10,11: {
                     print("Missing ",ext[i]," for ",temp6, >> tempC)
                  }
                  case 5,6: {
                     # complain that d1h,d1d missing for SSA PEAKUP
                     hsel(temp9,"aper_1","yes") | scan(aper)
                     if (aper != "2.0") print("Missing ",ext[i]," for SSA PEAKUP ",temp6, >> tempC)
                  }
               }
            }
         }
         if (obsmode == "DEFCAL") {
            if (exist[i] != " X ") {
               switch(i) {
                  case 1,2,3,4,7,8,9,10,11: {
                     print("Missing ",ext[i]," for ",temp6, >> tempC)
                  }
               }
            }
         }
         if (obsmode == "IMAGE") {
            if (exist[i] != " X ") {
               switch(i) {
                  case 1,2,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19: {
                     print("Missing ",ext[i]," for ",temp6, >> tempC)
                  }
               }
            }
         }
         if (obsmode == "PHOTOSC") {
            if (exist[i] != " X ") {
               switch(i) {
                  case 1,2,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,28,29,30,31: {
                     print("Missing ",ext[i]," for ",temp6, >> tempC)
                  }
                  case 20,21: {
                     # Complain if other than grating=SAF missing wavelengths
                     hsel(temp9,"ss_grat","yes") | scan(grat)
                     if (grat != "SAF") print("Missing ",ext[i]," for ",temp6, " grating is ", ss_grat, >> tempC)
                  }
               }
            }
         }
         if (obsmode == "RAPID") {
            if (exist[i] != " X ") {
               switch(i) {
                  case 1,2,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,28,29,30,31: {
                     print("Missing ",ext[i]," for ",temp6, >> tempC)
                  }
                  case 20,21,32,33: {
                     # Complain if other than grating=SAF missing wavelengths
                     hsel(temp9,"ss_grat","yes") | scan(grat)
                     if (grat != "SAF") print("Missing ",ext[i]," for ",temp6, "; grating is ", ss_grat, >> tempC)
                  }
               }
            }
         }
         if (obsmode == "SPYBAL") {
            if (exist[i] != " X ") {
               switch(i) {
                  case 1,2,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31: {
                     print("Missing ",ext[i]," for ",temp6, >> tempC)
                  }
               }
            }      
         }

         # print out which extensions exist for which file names
           printf ("%s ",exist[i])
       }
    }
    printf ("\n")
}  

# END loop through the list of rootnames??????
type (tempC)


# delete the temporary files
delete (files=temp0)
delete ("tmp$chk*")
end

Source Code · Search Form · STSDAS

Maintained by the Science Software Group at STScI
This file last updated on 10 Mar 2011