aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/photcal/mkobsfile/phimtable.x
blob: dbbadb9ed66f8040af5eb9de6a68f97a8641d8f8 (plain) (blame)
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
include <fset.h>
include "../lib/obsfile.h"

# PH_ESETIMTABLE -- Read in the image set name and image names from the
# standard input and initialize the table fields.

int procedure ph_esetimtable (imtable, nfilters, verify)

pointer	imtable			# pointer to the image symbol table
int	nfilters		# the number of filters in the filter set
int	verify			# verify the user input

int	setno, nsymbols, field, stat
pointer	sp, name, image, str, sym
bool	streq()
int	scan(), nscan(), strlen()
pointer	stenter()

begin
	# Allocate working space.
	call smark (sp)
	call salloc (name, SZ_FNAME, TY_CHAR)
	call salloc (image, SZ_FNAME, TY_CHAR)
	call salloc (str, SZ_FNAME, TY_CHAR)

	# Initialize the set and image counters.
	setno = 0
	nsymbols = 0
	field = 1
	call printf ("\n")

	# Loop over the user defined image sets.
	repeat {

	    if (field == 1) {

		# Print the prompt for the image set name.
		call printf (
		    "Enter name of image set %d (name, <EOF>=quit entry): ")
		    call pargi (setno + 1)
		call flush (STDOUT)

		# Read the image set name.
		stat = scan()
		if (stat == EOF) {
		    call printf ("\n")
		    break
		} else {
		    call gargwrd (Memc[name], SZ_FNAME)
		    if (nscan() != 1)
		        next
		}

		# Verify the image set name.
		if (verify == YES) {
		    call printf ("    Verify name (name, <CR>=%s): ")
			call pargstr (Memc[name])
		    call flush (STDOUT)
		    stat = scan()
		    if (stat == EOF)
		        call printf ("\n")
		    else {
		        call gargwrd (Memc[str], SZ_FNAME)
		        if (nscan() == 1)
			    call strcpy (Memc[str], Memc[name], SZ_FNAME)
		    }
		}

		# Prepare for the next image set field.
		field = field + 1
		setno = setno + 1
		next

	    } else if (field <= (nfilters + 1)) {

		# Prompt for the image name.
		call printf (
		    "    Enter image name %d (name, <CR>=INDEF): ")
		    call pargi (field - 1)
		call flush (STDOUT)

		# Get the next image name.
		stat = scan ()
		if (stat == EOF) {
		    call printf ("\n")
		    next
		} else {
		    call gargwrd (Memc[image], SZ_FNAME)
		    if (nscan() != 1)
		        call strcpy ("INDEF", Memc[image], SZ_FNAME)
		}

		# Verify
		if (verify == YES) {
		    call printf (
		    "        Verify name (name,  <CR>=%s): ")
		        call pargstr (Memc[image])
		    call flush (STDOUT)
		    stat = scan ()
		    if (stat == EOF)
		        call printf ("\n")
		    else {
		        call gargwrd (Memc[str], SZ_FNAME)
		        if (nscan() == 1)
			    call strcpy (Memc[str], Memc[image], SZ_FNAME)
		    }
		}

		nsymbols = nsymbols + 1
		field = field + 1

		# Enter the new symbol name.
		if (streq (Memc[image], "INDEF")) {
		    call sprintf (Memc[image+strlen(Memc[image])], SZ_FNAME,
			"%d")
			call pargi (nsymbols)
		}
		sym = stenter (imtable, Memc[image], LEN_IMT_STRUCT)

		IMT_IMSETNO(sym) = setno
		IMT_IMNO(sym) = nsymbols
		IMT_OFFSET(sym) = 0
		IMT_NENTRIES(sym) = 0

		IMT_XSHIFT(sym) = 0.0
		IMT_YSHIFT(sym) = 0.0
		IMT_APERCOR(sym) = 0.0
		IMT_ITIME(sym) = INDEFR
		IMT_OTIME(sym) = INDEFR
		IMT_XAIRMASS(sym) = INDEFR
		call strcpy ("INDEF",  IMT_IFILTER(sym), SZ_FNAME)

		call strcpy (Memc[name], IMT_LABEL(sym), SZ_FNAME)
		call strcpy (Memc[image], IMT_IMNAME(sym), SZ_FNAME)

		next

	    } else {
		field = 1
	    }
	}

	# Print a newline.
	call printf ("\n")

	call sfree (sp)

	return (nsymbols)
end


# PH_SETIMTABLE -- Read in the image names from the image sets file
# and initialize the fields.

int procedure ph_setimtable (imtable, fd, nfilters, verbose)

pointer	imtable			# pointer to the symbol table
int	fd			# file descriptor of the input text file
int	nfilters		# the number of filters in the set
int	verbose			# verbose mode

char	colon
int	field, setno, nsymbols, nimages
pointer	sp, name, image, sym
bool	streq()
int	fscan(), nscan(), strlen(), itoc()
pointer	stenter()

begin
	call smark (sp)
	call salloc (name, SZ_FNAME, TY_CHAR)
	call salloc (image, SZ_FNAME, TY_CHAR)

	setno = 0
	nsymbols = 0

	while (fscan (fd) != EOF) {

	    # Initialize.
	    nimages = 0
	    field = 1
	    colon = ' '

	    # Decode the image set name and the image names for each set.
	    # Skip blank lines and lines beginning with a pound sign.

	    repeat {

		if (field == 1) {
	            call gargwrd (Memc[name], SZ_FNAME)
	            if (Memc[name] == EOS || Memc[name] == '#')
		        break
		    field = field + 1
		    if (Memc[name] == ':') {
			Memc[name] = EOS
			colon = ':'
		    } else
			call gargc (colon)
		    if ((nscan() != field) || (colon != ':')) 
			break
		    field = field  + 1
		    setno = setno + 1
		    if (Memc[name] == EOS) {
			if (itoc (setno, Memc[name], SZ_FNAME) <= 0)
			    Memc[name] = EOS
		    }
		    next
		} else {
		    call gargwrd (Memc[image], SZ_FNAME)
		    if (nscan() != field)
			break
		    field = field + 1
		}

		nimages = nimages + 1
		nsymbols = nsymbols + 1

		if (streq (Memc[image], "INDEF")) {
		    call sprintf (Memc[image+strlen(Memc[image])], SZ_FNAME,
			"%d")
			call pargi (nsymbols)
		}

		# Enter the new symbol name.
		sym = stenter (imtable, Memc[image], LEN_IMT_STRUCT)

		IMT_IMSETNO(sym) = setno
		IMT_IMNO(sym) = nsymbols
		IMT_OFFSET(sym) = 0
		IMT_NENTRIES(sym) = 0

		IMT_XSHIFT(sym) = 0.0
		IMT_YSHIFT(sym) = 0.0
		IMT_APERCOR(sym) = 0.0
		IMT_ITIME(sym) = INDEFR
		IMT_XAIRMASS(sym) = INDEFR
		IMT_OTIME(sym) = INDEFR
		call strcpy ("INDEF",  IMT_IFILTER(sym), SZ_FNAME)

		call strcpy (Memc[name], IMT_LABEL(sym), SZ_FNAME)
		call strcpy (Memc[image], IMT_IMNAME(sym), SZ_FNAME)
	    }

	    # Test for error conditions.
	    if (verbose == NO)
		next
	    if (Memc[name] == EOS || Memc[name] == '#') {
		# blank lines and comment lines are skipped
	    } else if (colon != ':') {
		call eprintf ("Warning: Error decoding image set %s\n")
		    call pargstr (Memc[name])
	    } else if (nimages == 0) {
		call eprintf ("Warning: Image set %d name %s is empty\n")
		    call pargi (setno)
		    call pargstr (Memc[name])
	    } else if (nimages < nfilters) {
		call eprintf ("Warning: Image set %d name  %s is incomplete\n")
		    call pargi (setno)
		    call pargstr (Memc[name])
	    } else if (nimages > nfilters) {
		call eprintf ("Warning: Image set %d name  %s ")
		    call pargi (setno)
		    call pargstr (Memc[name])
		call eprintf ("has more than %d images\n")
		    call pargi (nimages)
	    }
	}

	call sfree (sp)

	return (nsymbols)
end


# PH_ESHIMTABLE -- Enter the correct values of the x-y coordinate shifts
# the image symbol table from the standard input.

procedure ph_eshimtable (imtable, nimages, verify)

pointer	imtable			# pointer to the symbol table
int	nimages			# number of images
int	verify			# verify the user input

char	comma
int	i, osetno, setno
pointer	sp, sym, symbol
real	xshift, yshift
int	scan(), nscan()
pointer	sthead(), stnext()

begin
	if (nimages <= 0)
	    return

	call smark (sp)
	call salloc (sym, nimages, TY_POINTER)

	# Reverse the order of the symbols in the symbol table.

	symbol = sthead (imtable)
	do i = nimages, 1, -1 {
	    Memi[sym+i-1] = symbol
	    symbol = stnext (imtable, symbol)
	}

	call printf ("\n")

	# Loop over the images.
	osetno = 0
	do i = 1, nimages {

	    symbol = Memi[sym+i-1]
	    setno = IMT_IMSETNO(symbol)

	    # Issue the prompt for each set.
	    if (setno != osetno) {
	        call printf ("Image set %d (%s):  ")
	            call pargi (setno)
		    call pargstr (IMT_LABEL(symbol))
		call printf ("Enter the shift in x and y\n")
	    }

	    # Issue the prompt for each image.
	    call printf (
	    "    Image %s (xshift  yshift, <CR>=0.0 0.0, <EOF>=quit entry): " )
		call pargstr (IMT_IMNAME(symbol))
	    call flush (STDOUT)

	    # Initialize
	    osetno = setno

	    # Read a line from STDIN.
	    if (scan() == EOF) {
		call printf ("\n")
		break
	    }

	    # Decode the x and y shifts and update the symbol table.
	    call gargr (xshift)
	    call gargr (yshift)
	    if (nscan() < 1) {
		xshift = 0.0
		yshift = 0.0
	    } else if (nscan() < 2) {
		call reset_scan()
	        call gargr (xshift)
		call gargc (comma)
	        call gargr (yshift)
		if (nscan() < 3 || comma != ',')
		    yshift = 0.0
	    }
	    IMT_XSHIFT(symbol) = xshift
	    IMT_YSHIFT(symbol) = yshift

	    # Verify the input.
	    if (verify == NO)
		next

	    # Issue the verify prompt for each image.
	    call printf (
	        "        Verify (xshift yshift, <CR>=%g %g): " )
		call pargr (IMT_XSHIFT(symbol))
		call pargr (IMT_YSHIFT(symbol))
	    call flush (STDOUT)

	    # Read a line from STDIN.
	    if (scan() == EOF) {
		call printf ("\n")
		next
	    }

	    # Decode the x and y shifts.
	    call gargr (xshift)
	    call gargr (yshift)
	    if (nscan() == 2) {
	        IMT_XSHIFT(symbol) = xshift
	        IMT_YSHIFT(symbol) = yshift
	    } else if (nscan() == 1) {
		call reset_scan()
	        call gargr (xshift)
		call gargc (comma)
	        call gargr (yshift)
	        IMT_XSHIFT(symbol) = xshift
		if (nscan() == 3 && comma == ',')
	            IMT_YSHIFT(symbol) = yshift
	    }
	}

	call printf ("\n")

	call sfree (sp)
end


# PH_SHIMTABLE -- Read in the x and y shifts file and enter the correct
# x and y shifts in the symbol table.

procedure ph_shimtable (imtable, fd, verbose)

pointer	imtable			# pointer to the symbol table
int	fd			# file descriptor of the input text file
int	verbose			# verbose mode

pointer	sp, image, fname, sym
int	fscan(), nscan()
pointer	stfind()
real	xoffset, yoffset

begin
	call smark (sp)
	call salloc (image, SZ_FNAME, TY_CHAR)
	call salloc (fname, SZ_FNAME, TY_CHAR)
	call fstats (fd, F_FILENAME, Memc[fname], SZ_FNAME)

	while (fscan (fd) != EOF) {

	    # Get the image name and the x and y shifts data.
	    call gargwrd (Memc[image], SZ_FNAME)
	    call gargr (xoffset)
	    call gargr (yoffset)
	    if (nscan () != 3)
		next

	    # Locate the image name in the symbol table and enter the shifts.
	    sym = stfind (imtable, Memc[image])
	    if (sym == NULL) {
		if (verbose == YES) {
		    call eprintf (
                	"Warning: File: %s image: %s is ")
		        call pargstr (Memc[fname])
		        call pargstr (Memc[image])
		    call eprintf ("not in the image sets file\n")
		}
		next
	    }

	    IMT_XSHIFT(sym) = xoffset
	    IMT_YSHIFT(sym) = yoffset
	}

	call sfree (sp)
end


# PH_EAPIMTABLE -- Enter the correct values of the aperture correction in
# the image symbol table from the standard input.

procedure ph_eapimtable (imtable, nimages, verify)

pointer	imtable			# pointer to the symbol table
int	nimages			# number of images
int	verify			# verify the user input

int	i, osetno, setno
pointer	sp, sym, symbol
real	apercor
int	scan(), nscan()
pointer	sthead(), stnext()

begin
	if (nimages <= 0)
	    return

	call smark (sp)
	call salloc (sym, nimages, TY_POINTER)

	# Reverse the order of the symbols in the symbol table.

	symbol = sthead (imtable)
	do i = nimages, 1, -1 {
	    Memi[sym+i-1] = symbol
	    symbol = stnext (imtable, symbol)
	}

	call printf ("\n")

	# Loop over the images.
	osetno = 0
	do i = 1, nimages {

	    symbol = Memi[sym+i-1]
	    setno = IMT_IMSETNO(symbol)

	    # Issue the prompt for each set.
	    if (setno != osetno) {
	        call printf ("Image set %d (%s):  ")
	            call pargi (setno)
		    call pargstr (IMT_LABEL(symbol))
		call printf ("Enter the aperture correction\n")
	    }

	    # Issue the prompt for each image.
	    call printf (
	     "    Image %s (magnitude, <CR>=0.0, <EOF>=quit entry): " )
		call pargstr (IMT_IMNAME(symbol))
	    call flush (STDOUT)

	    # Initialize
	    osetno = setno

	    # Scan the standard input.
	    if (scan() == EOF) {
		call printf ("\n")
		break
	    }

	    # Decode the aperture correction and update the symbl table.
	    call gargr (apercor)
	    if (nscan() < 1)
		apercor = 0.0
	    IMT_APERCOR(symbol) = apercor

	    # Optionally verify the input.
	    if (verify == NO)
		next

	    # Issue the verify prompt.
	    call printf (
	     "        Verify (magnitude, <CR>=%g): " )
		call pargr (IMT_APERCOR(symbol))
	    call flush (STDOUT)

	    # Scan the standard input.
	    if (scan() == EOF) {
		call printf ("\n")
		next
	    }

	    # Decode the aperture correction.
	    call gargr (apercor)
	    if (nscan() == 1)
	        IMT_APERCOR(symbol) = apercor
	}

	call printf ("\n")

	call sfree (sp)
end


# PH_APIMTABLE -- Read in the aperture corrections file and enter the correct
# aperture correction in the symbol table.

procedure ph_apimtable (imtable, fd, verbose)

pointer	imtable			# pointer to the symbol table
int	fd			# file descriptor of the input text file
int	verbose			# print status, warning and error messages

pointer	sp, image, fname, sym
int	fscan(), nscan()
pointer	stfind()
real	apercor

begin
	call smark (sp)
	call salloc (image, SZ_FNAME, TY_CHAR)
	call salloc (fname, SZ_FNAME, TY_CHAR)
	call fstats (fd, F_FILENAME, Memc[fname], SZ_FNAME)

	while (fscan (fd) != EOF) {

	    # Get the image name and the x and y shifts data.
	    call gargwrd (Memc[image], SZ_FNAME)
	    call gargr (apercor)
	    if (nscan () != 2)
		next

	    # Locate the image name in the symbol table and enter the shifts.
	    sym = stfind (imtable, Memc[image])
	    if (sym == NULL) {
		if (verbose == YES) {
		    call eprintf (
                	"Warning: File: %s image: %s ")
		        call pargstr (Memc[fname])
		        call pargstr (Memc[image])
		    call eprintf ("is not in the image sets file\n")
		}
		next
	    } 

	    IMT_APERCOR(sym) = apercor
	}

	call sfree (sp)
end


# PH_EOBSIMTABLE -- Enter the correct values of the filterid, exposure time and
# and airmass into the image symbol table from the standard input.

procedure ph_eobsimtable (imtable, nimages, verify)

pointer	imtable			# pointer to the symbol table
int	nimages			# number of images
int	verify			# verify the user input

int	i, osetno, setno
pointer	sp, sym, filterid, symbol
real	itime, xairmass, otime
int	scan(), nscan(), strncmp()
pointer	sthead(), stnext()

begin
	if (nimages <= 0)
	    return

	call smark (sp)
	call salloc (sym, nimages, TY_POINTER)
	call salloc (filterid, SZ_FNAME, TY_CHAR)

	# Reverse the order of the symbols in the symbol table.

	symbol = sthead (imtable)
	do i = nimages, 1, -1 {
	    Memi[sym+i-1] = symbol
	    symbol = stnext (imtable, symbol)
	}

	call printf ("\n")

	# Loop over the images.
	osetno = 0
	do i = 1, nimages {

	    symbol = Memi[sym+i-1]
	    setno = IMT_IMSETNO(symbol)

	    # Issue the prompt for each set.
	    if (setno != osetno) {
	        call printf ("Image set %d (%s): ")
	            call pargi (setno)
		    call pargstr (IMT_LABEL(symbol))
		call printf (
	        "Enter filter id, exposure time, airmass, observation time\n")
	    }

	    # Issue the prompt for each image.
	    call printf (
            "    Image %s (f t X T, <CR>=4 X (INDEF), <EOF>=quit entry): " )
		    call pargstr (IMT_IMNAME(symbol))
	    call flush (STDOUT)

	    # Initialize.
	    osetno = setno

	    # Scan the standard input.
	    if (scan() == EOF) {
		call printf ("\n")
		break
	    }

	    # Read in the filterid,  exposure time and airmass.
	    call gargwrd (Memc[filterid], SZ_FNAME)
	    call gargr (itime)
	    call gargr (xairmass)
	    call gargr (otime)
	    if (nscan() < 1) {
		call strcpy ("INDEF", Memc[filterid], SZ_FNAME)
		itime = INDEFR
		xairmass = INDEFR
		otime = INDEFR
	    } else if (nscan() < 2) {
		itime = INDEFR
		xairmass = INDEFR
		otime = INDEFR
	    } else if (nscan() < 3) {
		xairmass = INDEFR
		otime = INDEFR
	    } else if (nscan() < 4) {
		otime = INDEFR
	    }

	    # Update the symbol table.
	    if (strncmp (IMT_IFILTER(symbol), "INDEF", 5) == 0)
		call strcpy (Memc[filterid], IMT_IFILTER(symbol), SZ_FNAME)
	    if (! IS_INDEFR(itime))
	        IMT_ITIME(symbol) = itime
	    if (! IS_INDEFR(xairmass))
	        IMT_XAIRMASS(symbol) = xairmass
	    if (! IS_INDEFR(otime))
		IMT_OTIME(symbol) = otime

	    # Verify the input.
	    if (verify == NO)
		next

	    # Issue the verify prompt.
	    call printf (
	        "        Verify (f t X T, <CR>=%s %g %g %0.1h): ")
		call pargstr (IMT_IFILTER(symbol))
		call pargr (IMT_ITIME(symbol))
		call pargr (IMT_XAIRMASS(symbol))
		call pargr (IMT_OTIME(symbol))
	    call flush (STDOUT)

	    # Scan the standard input.
	    if (scan() == EOF) {
		call printf ("\n")
		next
	    }

	    # Read in the filterid,  exposure time and airmass.
	    call gargwrd (Memc[filterid], SZ_FNAME)
	    call gargr (itime)
	    call gargr (xairmass)
	    call gargr (otime)
	    if (nscan() == 4) {
		call strcpy (Memc[filterid], IMT_IFILTER(symbol), SZ_FNAME)
		IMT_ITIME(symbol) = itime
		IMT_XAIRMASS(symbol) = xairmass
		IMT_OTIME(symbol) = otime
	    } else if (nscan() == 3) {
		call strcpy (Memc[filterid], IMT_IFILTER(symbol), SZ_FNAME)
		IMT_ITIME(symbol) = itime
		IMT_XAIRMASS(symbol) = xairmass
	    } else if (nscan() == 2) {
		call strcpy (Memc[filterid], IMT_IFILTER(symbol), SZ_FNAME)
		IMT_ITIME(symbol) = itime
	    } else if (nscan() == 1)
		call strcpy (Memc[filterid], IMT_IFILTER(symbol), SZ_FNAME)
	}

	call printf ("\n")

	call sfree (sp)
end


# PH_OBSIMTABLE -- Enter the correct values of the exposure time, airmass and
# and filter id into the image table. The exposure time entered into the
# image table is the effective exposure time required to convert the
# computed magnitudes to the new exposure time.

procedure ph_obsimtable (imtable, fd, columns, verbose)

pointer	imtable			# pointer to the symbol table
int	fd			# file descriptor of the input text file
int	columns[ARB]		# the list of input columns
int	verbose			# print status, warning and error messages

int	stat, lbufsize
pointer	sp, image, fname, filterid, line, sym
real	itime, airmass, otime
bool	streq()
int	ph_nxtimage()
pointer	stfind()

begin
	call smark (sp)
	call salloc (image, SZ_FNAME, TY_CHAR)
	call salloc (fname, SZ_FNAME, TY_CHAR)
	call salloc (filterid, SZ_FNAME, TY_CHAR)

	Memc[image] = EOS
	call fstats (fd, F_FILENAME, Memc[fname], SZ_FNAME)

	line = NULL
	lbufsize = 0
	repeat {

	    # Get the image name.
	    stat = ph_nxtimage (fd, columns, Memc[image], line, lbufsize)
	    if (stat == EOF)
		break

	    # Locate the image name in the symbol table.
	    sym = stfind (imtable, Memc[image])
	    if (sym == NULL) {
		if (verbose == YES) {
		    call eprintf (
      			"Warning: File: %s image: %s ")
		        call pargstr (Memc[fname])
		        call pargstr (Memc[image])
		    call eprintf ("is not in the image sets file\n")
		}
		next
	    }

	    # Decode the data.
	    call ph_obsdata (Memc[line], columns, Memc[filterid], SZ_FNAME,
	        itime, airmass, otime)

	    # Enter the data in the symbol table.
	    if (! IS_INDEFR(itime))
	        IMT_ITIME(sym) = itime
	    if (! IS_INDEFR(airmass))
	        IMT_XAIRMASS(sym) = airmass
	    if (! IS_INDEFR(otime))
		IMT_OTIME(sym) = otime
	    if (! streq (Memc[filterid], "INDEF"))
	        call strcpy (Memc[filterid], IMT_IFILTER(sym), SZ_FNAME)
	}

	if (line != NULL) {
	    call mfree (line, TY_CHAR)
	    line = NULL
	    lbufsize = 0
	}

	call sfree (sp)
end


# PH_MKIMTABLE -- Create the image table using the input text file(s)
# and the list of column numbers defining the fields required by the
# program.

int procedure ph_mkimtable (imtable, fd, columns, objid, x, y, mag, merr,
        imid, id, nptr, normtime, sortimid, verbose)

pointer	imtable			# pointer to the symbol table
int	fd			# file descriptor of the input text file
int	columns[ARB]		# the list of input columns
pointer	objid			# pointer to the id array
pointer	x			# pointer to the x coordinate array
pointer	y			# pointer to the y coordinate array
pointer	mag			# pointer to the magnitude array
pointer	merr			# pointer to the magnitude error array
pointer	imid			# pointer to the image id
pointer	id			# pointer to the image ids
int	nptr			# pointer to the current data point
int	normtime		# normalize exposure times
int	sortimid		# does data need to be sorted on imid or id
int	verbose			# print status, warning and error messages

int	idcol, stat, dbufsize, lbufsize
pointer	sp, fname, image, imname, filterid, objname, line, sym
real	itime, airmass, otime

bool	streq()
int	ph_nxtimage(), ph_stardata(), ph_getimage()
pointer	stfind()

begin
	call smark (sp)
	call salloc (fname, SZ_FNAME, TY_CHAR)
	call salloc (image, SZ_FNAME, TY_CHAR)
	call salloc (imname, SZ_FNAME, TY_CHAR)
	call salloc (filterid, SZ_FNAME, TY_CHAR)
	call salloc (objname, DEF_LENLABEL, TY_CHAR)

	# Is there id information.
	idcol = columns[CAT_ID]

	# Allocate some initial buffer space.
	if (nptr == 0) {
	    dbufsize = DEF_BUFSIZE
	    if (idcol > 0)
		call malloc (objid, dbufsize * (DEF_LENLABEL+ 1), TY_CHAR)
	    call malloc (x, dbufsize, TY_REAL)
	    call malloc (y, dbufsize, TY_REAL)
	    call malloc (mag, dbufsize, TY_REAL)
	    call malloc (merr, dbufsize, TY_REAL)
	    call malloc (imid, dbufsize, TY_INT)
	    call malloc (id, dbufsize, TY_INT)
	}

	# Initialize.
	Memc[image] = EOS
	call fstats (fd, F_FILENAME, Memc[fname], SZ_FNAME)

	# Find the first image.
	lbufsize = 0
	line = NULL
	stat = ph_nxtimage (fd, columns, Memc[image], line, lbufsize)

	# Read the data.
	while (stat != EOF) {

	    # Locate the image name in the symbol table.
	    sym = stfind (imtable, Memc[image])
	    if (sym == NULL) {
		if (Memc[image] != EOS && verbose == YES) {
		    call eprintf (
			"Warning: File: %s Image: %s ")
		        call pargstr (Memc[fname])
		        call pargstr (Memc[image])
		    call eprintf ("is not in the image sets file\n")
		}
		stat = ph_nxtimage (fd, columns, Memc[image], line, lbufsize)
		next
	    }

	    # Decode the filter, exposure time and airmass information.
	    call ph_imdata (Memc[line], columns, Memc[filterid], SZ_FNAME,
	        itime, airmass, otime)

	    # Enter the new values in the symbol table.
	    if (IS_INDEFR(IMT_ITIME(sym))) {
		if (IS_INDEFR(itime))
		    IMT_ITIME(sym) = 1.0
		else if (normtime == NO)
		    IMT_ITIME(sym) = 1.0
		else
		    IMT_ITIME(sym) = itime
	    } else if (IMT_NENTRIES(sym) > 0) { 
		# do nothing
	    } else if (IS_INDEFR(itime)) {
		if (normtime == NO)
		    IMT_ITIME(sym) = 1.0
	    } else {
	        IMT_ITIME(sym) = IMT_ITIME(sym) / itime
	    }
	    if (IS_INDEFR(IMT_XAIRMASS(sym)))
	        IMT_XAIRMASS(sym) = airmass
	    if (IS_INDEFR(IMT_OTIME(sym)))
	        IMT_OTIME(sym) = otime
	    if (streq (IMT_IFILTER(sym), "INDEF"))
	        call strcpy (Memc[filterid], IMT_IFILTER(sym), SZ_FNAME)

	    # Does the data need to be sorted on image or id. This should
	    # usually not be necessary for most DAOPHOT or APPHOT data
	    # but will be necessary if data from the same images is contained
	    # in more than 1 file.

	    if (IMT_NENTRIES(sym) > 0)
		sortimid = YES
	    else
		IMT_OFFSET(sym) = nptr + 1

	    # Get the data.
	    repeat {

		# Decode x, y, magnitude and error.
		if (ph_stardata (Memc[line], columns, Memc[objname],
		    Memr[x+nptr], Memr[y+nptr], Memr[mag+nptr],
		    Memr[merr+nptr]) == OK) {
		    if (idcol > 0)
			call strcpy (Memc[objname],
			    Memc[objid+nptr*(DEF_LENLABEL+1)],
			    DEF_LENLABEL)
		    Memi[imid+nptr] = IMT_IMNO(sym)
		    IMT_NENTRIES(sym) = IMT_NENTRIES(sym) + 1
		    Memi[id+nptr] = IMT_NENTRIES(sym)
		    nptr = nptr + 1
		}

		# Allocate more buffer space if necessary.
		if (nptr >= dbufsize) {
		    dbufsize = dbufsize + DEF_BUFSIZE
		    if (idcol > 0)
			call realloc (objid, dbufsize * (DEF_LENLABEL + 1),
			    TY_CHAR)
	    	    call realloc (x, dbufsize, TY_REAL)
	            call realloc (y, dbufsize, TY_REAL)
	            call realloc (mag, dbufsize, TY_REAL)
	            call realloc (merr, dbufsize, TY_REAL)
	            call realloc (imid, dbufsize, TY_INT)
	            call realloc (id, dbufsize, TY_INT)
		}

		# Decode the next data.
		stat = ph_getimage (fd, columns, Memc[imname], line, lbufsize)

	    } until ((stat == EOF) || (! streq (Memc[imname], Memc[image])))

	    call strcpy (Memc[imname], Memc[image], SZ_FNAME)

	}

	if (line != NULL) {
	    call mfree (line, TY_CHAR)
	    line = NULL
	    lbufsize = 0
	}

	call sfree (sp)

	return (nptr)
end