scidoc0321 — Document

DECFIX - Repair declination conversion in WHIRC data before June 2009

October 1, 2013

# DECFIX - Repair declination conversion in WHIRC data before June 2009
# 13APR2010: Adapted from Mike Merrill's SQCORR script
# Carries out the following: conversion from sexigecimal to decimal
# (DEC to CRVAL2) with proper handling of negative declination
# No problem if used on data after June 2009.
# Add header flag DECFIX = 1

procedure decfix (input, output)

string input {prompt="Input raw images"}
string output {prompt="Output image descriptor: @list||.ext||%in%out%"}

bool verbose {yes,prompt="Verbose output?"}
file logfile {"STDOUT",prompt="logfile name"}

struct *inlist,*outlist,*l_list

begin

int nin, irootlen, orootlen, stat, pos1b, pos1e, pos2b, pos2e,nex
string in,in1,in2,out,iroot,oroot,uniq,sopt,img,sname,sout,sbuff,sjunk,
smean, smedian, smode, front, srcsub, color, sexpr
file blank, nflat, infile, outfile, im1, tmp1, tmp2, l_log,
colorlist
bool found
string gimextn, imextn, imname, imroot, dec, fowler
real rr, crval2, ff

struct line = ""

# Make sure that correct packages are loaded
noao.imred.irred
noao.astutil

# Assign positional parameters to local variables
in = input
out = output

# get IRAF global image extension
show("imtype") | translit ("",","," ",delete-) | scan (gimextn)
nex = strlen(gimextn)

uniq = mktemp ("_Tirp")
infile = mktemp ("tmp$irp")
outfile = mktemp ("tmp$irp")
tmp1 = mktemp ("tmp$irp")
tmp2 = mktemp ("tmp$irp")
l_log = mktemp ("tmp$irp")
im1 = uniq // ".im1"

l_list = l_log
# check whether input stuff exists
if ((stridx("@%.",out) != 1) && (stridx(",",out) <= 1)) {
# Verify format of output descriptor
print ("Improper output descriptor format: ",out)
print (" Use @list or comma delimited list for fully named output")
print (" Use .extension for appending extension to input list")
print (" Use %inroot%outroot% to substitute string within input list")
goto skip
}

# check whether input stuff exists
l_list = l_log
print (in) | translit ("", "@:", " ") | scan(in1,in2)

if ((stridx("@",in) == 1) && (! access(in1))) { # check input @file
print ("Input file ",in1," does not exist!")
goto skip
}

print (in) | translit ("", ":", " ") | scan(in1,in2)
sections (in1,option="nolist")
if (sections.nimages == 0) { # check input images
print ("Input images in file ",in, " do not exist!")
goto skip
}

# Expand input file name list
sections (in1, option="root",> infile)

# Expand output image list
if (stridx("@,",out) != 0) { # @-list
# Output descriptor is @-list or comma delimited list
sections (out, option="root",> outfile)
} else { # namelist/substitution/append
inlist = infile
for (nin = 0; fscan (inlist,img) !=EOF; nin += 1) {
# Get past any directory info
if (stridx("$/",img) != 0) {
print (img) | translit ("", "$/", " ", >> l_log)
stat = fscan(l_list,img,img,img,img,img,img,img,img)
}
i = strlen(img)
if (substr(img,i-nex,i) == "."//gimextn) # Strip off imextn
img = substr(img,1,i-nex-1)
# Output descriptor indicates append or substitution based on input list
if (stridx("%",out) > 0) { # substitution
print (out) | translit ("", "%", " ") | scan(iroot,oroot)
if (nscan() == 1) oroot = ""
irootlen = strlen(iroot)
while (strlen(img) >= irootlen) {
found = no
pos2b = stridx(substr(iroot,1,1),img) # match first char
pos2e = pos2b + irootlen - 1 # presumed match end
pos1e = strlen(img)
if ((pos2b > 0) && (substr(img,pos2b,pos2e) == iroot)) {
if ((pos2b-1) > 0)
sjunk = substr(img,1,pos2b-1)
else
sjunk = ""
print(sjunk//oroot//
substr(img,min(pos2e+1,pos1e),pos1e), >> outfile)
found = yes
break
} else if (pos2b > 0) {
img = substr(img,pos2b+1,pos1e) # move past first match
} else { # no match
found = no
break
}
}
if (! found) { # no match
print ("root ",iroot," not found in ",img)
goto skip
}
} else # name/append
print(img//out,>> outfile)
}
}

count(infile) | scan (pos1b); count(outfile) | scan (pos2b)
if (pos1b != pos2b) {
print ("Mismatch between input and output lists: ",pos1b,pos2b)
join (tmp1,outfile)
goto skip
}
nin = pos1b
inlist = ""

# send newline if appending to existing logfile
if (access(logfile)) print("\n",>> logfile)

# Loop through data
inlist = infile; outlist = outfile
while ((fscan (inlist,sname) != EOF) && (fscan(outlist,sout) != EOF)) {

# Recalculate decimal degrees in declination
dec = "DEC"
imgets(sname,dec)
rr = real(imgets.value)
imcopy (sname, sout)

hedit(sout,"CRVAL2",rr,add=no,verify=no,show=no,update=yes)

hedit(sout,"DECFIX", "1", add=yes,verify=no,show=no,update=yes)

}


skip:

# Finish up
inlist = ""; outlist = ""; l_list = ""
delete (im1//","//tmp1//","//tmp2//","//l_log, verify-,>& "dev$null")
delete (infile//","//outfile//","//colorlist, verify-,>& "dev$null")

end

About the Document

Intranet Id: scidoc0321
Upload date: October 1, 2013, 4:11 pm

Document Formats