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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
include <mach.h>
include <math.h>
include <math/curfit.h>
include <math/iminterp.h>
# ST_MAGUNIFORM -- Compute a set of magnitude values which are uniformly
# distributed between minmag and maxmag.
procedure st_maguniform (mag, nstars, minmag, maxmag, seed)
real mag[ARB] # output array of magnitudes
int nstars # number of stars
real minmag, maxmag # minimum and maximum magnitude values
long seed # seed for random number generator
int i
real urand()
begin
# Get values between 0 and 1.
do i = 1, nstars
mag[i] = urand (seed)
# Map values into data range.
call amapr (mag, mag, nstars, 0.0, 1.0, minmag, maxmag)
end
# ST_POWER -- Compute a set of magnitude values which are power law
# distributed between minmag and maxmag.
procedure st_power (mag, nstars, power, minmag, maxmag, seed)
real mag[ARB] # output array of magnitudes
int nstars # number of stars
real power # power law exponent
real minmag, maxmag # minimum and maximum magnitude values
long seed # seed for random number generator
int i
real a, urand()
begin
# Get values between 0 and 1.
a = 10. ** (power * (maxmag - minmag)) - 1
do i = 1, nstars
mag[i] = minmag + log10 (a * urand (seed) + 1) / power
end
define MIN_BANDS -6.
define MAX_BANDS 19.
define MID_BANDS 15.
# ST_BANDS -- Compute the Bahcall and Soneira luminosity function.
procedure st_bands (mag, nstars, alpha, beta, delta, mstar, minmag, maxmag,
mzero, nsample, order, seed)
real mag[ARB] # array of output magnitudes
int nstars # number of stars
real alpha, beta # Bahcall and Soneira parameters
real delta, mstar # Bahcall and Soneira parameters
real minmag, maxmag # minimum and maximum magnitude values
real mzero # zero point between relative and absolute mags.
int nsample # number of points in sampling function
int order # order of the spline fit
long seed # value of the seed
int i, ier
pointer sp, m, iprob, w, cv, asi
real dmag, magval, mtemp, temp1, temp2, imin, imax
real cveval(), asigrl(), urand()
begin
# Allocate temporary space.
call smark (sp)
call salloc (m, nsample, TY_REAL)
call salloc (iprob, nsample, TY_REAL)
call salloc (w, nsample, TY_REAL)
# Compute the probability function.
magval = max (minmag - mzero, MIN_BANDS)
dmag = (min (maxmag - mzero, MAX_BANDS) - magval) / (nsample - 1)
do i = 1, nsample {
Memr[m+i-1] = magval
if (magval > MID_BANDS)
mtemp = MID_BANDS
else
mtemp = magval - mstar
temp1 = 10.0 ** (beta * mtemp)
temp2 = (1.0 + 10.0 ** ((beta - alpha) * delta * mtemp)) **
(1.0 / delta)
Memr[iprob+i-1] = temp1 / temp2
magval = magval + dmag
}
# Integrate the probablity function.
call asiinit (asi, II_SPLINE3)
call asifit (asi, Memr[iprob], nsample)
Memr[iprob] = 0.0
do i = 2, nsample
Memr[iprob+i-1] = Memr[iprob+i-2] + asigrl (asi, real (i-1),
real (i))
call alimr (Memr[iprob], nsample, imin, imax)
call amapr (Memr[iprob], Memr[iprob], nsample, imin, imax, 0.0, 1.0)
call asifree (asi)
# Fit the inverse of the integral of the probability function.
call cvinit (cv, SPLINE3, order, 0.0, 1.0)
call cvfit (cv, Memr[iprob], Memr[m], Memr[w], nsample, WTS_UNIFORM,
ier)
# Compute the magnitudes.
if (ier == OK) {
do i = 1, nstars
mag[i] = cveval (cv, urand (seed)) + mzero
} else {
call printf ("Error computing the bands luminosity function.\n")
call amovkr ((minmag + maxmag) / 2.0, mag, nstars)
}
call cvfree (cv)
# Free space.
call sfree (sp)
end
define MIN_SALPETER -4.0
define MAX_SALPETER 16.0
# ST_SALPETER -- Compute the Salpter luminosity function.
procedure st_salpeter (mag, nstars, minmag, maxmag, mzero, nsample, order, seed)
real mag[ARB] # array of output magnitudes
int nstars # number of stars
real minmag, maxmag # minimum and maximum magnitude values
real mzero # zero point between relative and absolute mags.
int nsample # number of points in sampling function
int order # order of the spline fit
long seed # value of the seed
int i, ier
pointer sp, m, iprob, w, cv, asi
real dmag, magval, imin, imax
real cveval(), asigrl(), urand()
begin
# Allocate temporary space.
call smark (sp)
call salloc (m, nsample, TY_REAL)
call salloc (iprob, nsample, TY_REAL)
call salloc (w, nsample, TY_REAL)
# Compute the probability function.
magval = max (minmag - mzero, MIN_SALPETER)
dmag = (min (maxmag - mzero, MAX_SALPETER) - magval) / (nsample - 1)
do i = 1, nsample {
Memr[m+i-1] = magval
Memr[iprob+i-1] = 10.0 ** (-3.158375 + 1.550629e-1 * magval -
5.19388e-3 * magval ** 2)
magval = magval + dmag
}
# Integrate the probablity function.
call asiinit (asi, II_SPLINE3)
call asifit (asi, Memr[iprob], nsample)
Memr[iprob] = 0.0
do i = 2, nsample
Memr[iprob+i-1] = Memr[iprob+i-2] + asigrl (asi, real (i-1),
real (i))
call alimr (Memr[iprob], nsample, imin, imax)
call amapr (Memr[iprob], Memr[iprob], nsample, imin, imax, 0.0, 1.0)
call asifree (asi)
# Fit the inverse of the integral of the probability function.
call cvinit (cv, SPLINE3, order, 0.0, 1.0)
call cvfit (cv, Memr[iprob], Memr[m], Memr[w], nsample, WTS_UNIFORM,
ier)
# Compute the magnitudes.
if (ier == OK) {
do i = 1, nstars
mag[i] = cveval (cv, urand (seed)) + mzero
} else {
call printf ("Error computing the Salpeter luminosity function.\n")
call amovkr ((minmag + maxmag) / 2.0, mag, nstars)
}
call cvfree (cv)
# Free space.
call sfree (sp)
end
# ST_SCHECTER -- Compute the Schecter luminosity function.
procedure st_schecter (mag, nstars, alpha, mstar, minmag, maxmag, mzero,
nsample, order, seed)
real mag[ARB] # array of output magnitudes
int nstars # number of stars
real alpha, mstar # Schecter luminosity function parameters
real minmag, maxmag # minimum and maximum magnitude values
real mzero # zero point between relative and absolute mags.
int nsample # number of points in the sampling function
int order # order of the spline fit
long seed # value of the seed
int i, ier
pointer sp, m, iprob, w, cv, asi
real dmag, magval, temp, imin, imax
real cveval(), asigrl(), urand()
begin
# Allocate space for fitting.
call smark (sp)
call salloc (m, nsample, TY_REAL)
call salloc (iprob, nsample, TY_REAL)
call salloc (w, nsample, TY_REAL)
# Sample the luminosity function.
magval = minmag - mzero
dmag = (maxmag - minmag) / (nsample - 1)
do i = 1, nsample {
Memr[m+i-1] = magval
temp = 0.4 * (mstar - magval)
Memr[iprob+i-1] = 10.0 ** ((alpha + 1) * temp) *
exp (- 10.0 ** temp)
magval = magval + dmag
}
# Integrate the sampling function.
call asiinit (asi, II_SPLINE3)
call asifit (asi, Memr[iprob], nsample)
Memr[iprob] = 0.0
do i = 2, nsample
Memr[iprob+i-1] = Memr[iprob+i-2] + asigrl (asi, real (i-1),
real(i))
call alimr (Memr[iprob],nsample, imin, imax)
call amapr (Memr[iprob], Memr[iprob], nsample, imin, imax, 0.0, 1.0)
call asifree (asi)
# Fit the inverse of the integral of the probability function.
call cvinit (cv, SPLINE3, order, 0.0, 1.0)
call cvfit (cv, Memr[iprob], Memr[m], Memr[w], nsample, WTS_UNIFORM,
ier)
if (ier == OK) {
do i = 1, nstars
mag[i] = cveval (cv, urand (seed)) + mzero
} else {
call printf ("Error fitting the Schecter luminosity function.\n")
call amovkr ((minmag + maxmag) / 2.0, mag, nstars)
}
call cvfree (cv)
# Free space.
call sfree (sp)
end
# ST_LFSAMPLE -- Compute the luminosity function using a user supplied
# function.
procedure st_lfsample (smag, mprob, nlf, mag, nstars, minmag, maxmag, nsample,
order, seed)
real smag[ARB] # input array of magnitudes
real mprob[ARB] # input array of relative probabilities
int nlf # number of input points
real mag[ARB] # output magnitude array
int nstars # number of stars
real minmag, maxmag # minimum and maximum magnitude values
int nsample # number of sample points
int order # order of the spline fit
long seed # value of the seed
int npts, i, ier
pointer sp, m, w, iprob, cv, asi
real mval, dm, sfmin, sfmax, imin, imax
real cveval(), asigrl(), urand()
begin
# Allocate space for fitting.
npts = max (nlf, nsample)
call smark (sp)
call salloc (m, nsample, TY_REAL)
call salloc (iprob, nsample, TY_REAL)
call salloc (w, npts, TY_REAL)
# Smooth the relative probability function.
call alimr (smag, nlf, sfmin, sfmax)
call cvinit (cv, SPLINE3, max (1, nlf / 4), sfmin, sfmax)
call cvfit (cv, smag, mprob, Memr[w], nlf, WTS_UNIFORM, ier)
# Evaluate the smoothed function at equal intervals in r.
if (ier == OK) {
mval = max (minmag, sfmin)
dm = (min (maxmag, sfmax) - mval) / (nsample - 1)
do i = 1, nsample {
Memr[m+i-1] = mval
Memr[iprob+i-1] = cveval (cv, mval)
mval = mval + dm
}
call cvfree (cv)
} else {
call printf ("Error smoothing user luminosity function.\n")
call amovkr ((minmag + maxmag) / 2.0, mag, nstars)
call cvfree (cv)
call sfree (sp)
}
# Evaluate the integral.
call asiinit (asi, II_SPLINE3)
call asifit (asi, Memr[iprob], nsample)
Memr[iprob] = 0.0
do i = 2, nsample
Memr[iprob+i-1] = Memr[iprob+i-2] + asigrl (asi, real(i-1), real(i))
call alimr (Memr[iprob], nsample, imin, imax)
call amapr (Memr[iprob], Memr[iprob], nsample, imin, imax, 0.0, 1.0)
call asifree (asi)
# Fit the inverse of the integral of the probability function.
call cvinit (cv, SPLINE3, order, 0.0, 1.0)
call cvfit (cv, Memr[iprob], Memr[m], Memr[w], nsample, WTS_UNIFORM,
ier)
# Sample the computed function.
if (ier == OK) {
do i = 1, nstars
mag[i] = cveval (cv, urand (seed))
} else {
call printf ("Error computing the user luminosity function.\n")
call amovkr ((minmag + maxmag) / 2.0, mag, nstars)
}
call cvfree (cv)
# Free space.
call sfree (sp)
end
|