1
2
3
4
5
6
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# MKAPFILE -- Create an aperture corrections file suitable for input to the
# PHOTCAL preprocessor tasks MKNOBSFILE, MKOBSFILE, and OBSFILE from a list of
# APPHOT/DAOPHOT text or ST table photometry files.
procedure mkapfile (photfiles, naperts, apercors)
file photfiles {prompt="The input list of APPHOT/DAOPHOT databases"}
int naperts {prompt="The number of apertures to extract"}
file apercors {prompt="The output aperture corrections file"}
int smallap {1, prompt="The first aperture for the correction"}
int largeap {0, prompt="The last aperture for the correction"}
file magfile {"", prompt="The optional output best magnitudes file"}
file logfile {"", prompt="The optional output log file"}
file plotfile {"", prompt="The optional output plot file"}
file obsparams {"", prompt="The observing parameters file"}
string obscolumns {"2 3 4 5", prompt="The observing parameters file format"}
bool append {no, prompt="Open log and plot files in append mode"}
real maglim {.10, prompt="The maximum permitted magnitude error"}
int nparams {3, prompt="Number of cog model parameters to fit"}
real swings {1.2, prompt="The power law slope of the stellar wings"}
real pwings {0.1,
prompt="The fraction of the total power in the stellar wings"}
real pgauss {0.5,
prompt="The fraction of the core power in the gaussian core"}
real rgescale {0.9, prompt="The exponential / gaussian radial scales"}
real xwings {0.0, prompt="The extinction coefficient"}
bool interactive {yes, prompt="Do the fit interactively ?"}
bool verify {no, prompt="Verify interactive user input ?"}
gcur gcommands {"", prompt="The graphics cursor"}
string graphics {"stdgraph", prompt="The graphics device"}
begin
# Declare local variables.
bool tappend
int tnaperts, tsmallap, tlargeap, td2, tr2, tpwidth, tpagwidth
string tfiles, tapercors, tmagfile, tlogfile, tplotfile
string tobsparams, tobscolumns, tmplist, tdatafile
string tainfields, tsinfields, trstr, tmstr, testr, fname
# Get the parameters and test for the existence of various files.
tfiles = photfiles
tnaperts = naperts
if (tnaperts < 2) {
error (0, "Naperts must be > 1")
}
tapercors = apercors
if (access (tapercors)) {
error (0,
"The output aperture corrections file " // tapercors //
" already exists")
}
tsmallap = smallap
tlargeap = largeap
tsmallap = max (1, min (tsmallap, tnaperts))
if (tlargeap == 0) {
tlargeap = tnaperts
} else {
tlargeap = max (1, min (tlargeap, tnaperts))
}
if (tsmallap > tlargeap) {
error (0, "Lastap must be > tsmallap")
}
tmagfile = magfile
if (tmagfile != "" && access (tmagfile)) {
error (0,
"The output magfile file " // tmagfile // " already exists")
}
tappend = append
tlogfile = logfile
if (tlogfile != "" && ! tappend) {
if (access (tlogfile))
error (0,
"The output logfile " // tlogfile // " already exists")
}
tplotfile = plotfile
if (tplotfile != "" && ! tappend) {
if (access (tplotfile))
error (0,
"The output plotfile " // tplotfile // " already exists")
}
tobsparams = obsparams
if (tobsparams == "") {
tobscolumns = ""
} else {
tobscolumns = obscolumns
if (! access (tobsparams))
error (0,
"The obsparmas file " // tobsparams // " does not exist")
}
# Change columns named "RAPERT", "MAG" and "MERR" to "RAPERT[1]",
# "MAG[1]" and "MERR[1]" in any ST tables files. Non-ST format files
# are skipped.
tbcrename (tfiles, "RAPERT,MAG,MERR", "RAPERT\[1],MAG\[1],MERR\[1]")
# Add the image, scale, ifilter, itime and xairmass columns to any
# files in ST tables format. Non-ST format files are skipped.
tbkeycol (tfiles, "IMAGE,XAIRMASS")
# Construct the string describing the fields to be extracted
# making sure to specify the correct aperture number. Extract
# the data and store the results in the temporary file tdatafile.
tainfields = "IM,XC,YC,IF,IT,XA,OT,RAPERT[1-" // tnaperts // "]" //
",MAG[1-" // tnaperts // "]" // ",MERR[1-" // tnaperts // "]"
tsinfields = "IM*,XC*,YC*,IF*,IT*,XA*,OT*"
td2 = tnaperts / 10
tr2 = mod (tnaperts, 10)
for (i = 0; i <= td2; i = i + 1) {
if (td2 == 0) {
trstr = ",RA*\[[1-" // tr2 // "]]"
tmstr = ",MAG\[[1-" // tr2 // "]]"
testr = ",MERR\[[1-" // tr2 // "]]"
} else if (i == 0) {
trstr = ",RA*\[[1-9]]"
tmstr = ",MAG\[[1-9]]"
testr = ",MERR\[[1-9]]"
} else if (i == td2) {
trstr = trstr // ",RA*\[" // td2 // "[0-" // tr2 // "]]"
tmstr = tmstr // ",MAG\[" // td2 // "[0-" // tr2 // "]]"
testr = testr // ",MERR\[" // td2 // "[0-" // tr2 // "]]"
} else if (i == 1) {
trstr = trstr // ",RA*\[[1-" // td2-1 // "][1-9]]"
tmstr = tmstr // ",MAG\[[1-" // td2-1 // "][1-9]]"
testr = testr // ",MERR\[[1-" // td2-1 // "][1-9]]"
}
}
tsinfields = tsinfields // trstr // "," // tmstr // "," // testr
# Create input file list.
tmplist = mktemp ("tmp$")
files (tfiles, sort=no, > tmplist)
# Create temporary file names to store the intermediate image list.
tdatafile = mktemp ("tmp$")
list = tmplist
while (fscan (list, fname) != EOF) {
istable (fname)
if (istable.table) {
tpagwidth = tbdump.pagwidth
#tpwidth = tdump.pwidth.p_max
tdump.pwidth.p_max = 5000
tbdump (fname, tsinfields, "yes", cdfile="", pfile="",
datafile="STDOUT", rows="-", pagwidth=5000,
>> tdatafile)
#tdump.pwidth.p_max = tpwidth
tbdump.pagwidth = tpagwidth
} else if (istable.text) {
txdump (fname, tainfields, "yes", headers=no, parameters=yes,
>> tdatafile)
} else {
print ("ERROR: Cannot run MKAPFILE on file: " // fname)
}
}
# Run APFILE.
tainfields = "1,2,3,4,5,6,7,8," // 8+tnaperts // "," // 8+2*tnaperts
apfile (tdatafile, tainfields, tnaperts, tapercors,
smallap=tsmallap, largeap=tlargeap, magfile=tmagfile,
logfile=tlogfile, plotfile=tplotfile, append=tappend,
obsparams=tobsparams,obscolumns=tobscolumns,maglim=maglim,
nparams=nparams,swings=swings,pwings=pwings, pgauss=pgauss,
rgescale=rgescale, xwings=xwings, interactive=interactive,
verify=verify, gcommands=gcommands, graphics=graphics)
# Delete the temporary files.
delete (tdatafile, go_ahead+, verify-, default_action+,
allversions+, subfiles+, > "dev$null")
delete (tmplist, go_ahead+, verify-, default_action+,
allversions+, subfiles+, > "dev$null")
end
|