-
Notifications
You must be signed in to change notification settings - Fork 3
/
_skysub.c
6786 lines (5898 loc) · 214 KB
/
_skysub.c
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
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <stdarg.h>
#include <string.h>
#include "skysub.h"
#include <time.h>
/* elements of K&R hp calculator, basis of commands */
char getch() /* get a (possibly pushed back) character */
{
return((bufp > 0) ? buf[--bufp] : getchar());
}
void ungetch(int c) /* push character back on input */
{
if(bufp > BUFSIZE)
printf("Ungetch -- too many characters.\n");
else
buf[bufp++] = c;
}
/* some functions for getting well-tested input. */
int legal_num_part(char c)
{
if((c != '.') && (c != '-') && (c != '+') && (c < '0' || c > '9'))
return(-1); /* not a legal number part */
else return(0);
}
int legal_int_part(char c)
{
if((c != '-') && (c < '0' || c > '9'))
return(-1); /* not a legal number part */
else return(0);
}
int legal_command_char(char c)
{
/* Allows more sophisticated argument checking by seeing if
a character appended to an argument is actually a
legal commmand. */
switch(c) {
case '?': return(1);
break;
case 'i': return(1);
break;
case 'f': return(1);
break;
case 'w': return(1);
break;
case 'r': return(1);
break;
case 'd': return(1);
break;
case 'y': return(1);
break;
case 't': return(1);
break;
case 'T': return(1);
break;
case 'n': return(1);
break;
case 'g': return(1);
break;
case 'e': return(1);
break;
case 'p': return(1);
break;
case 's': return(1);
break;
case 'l': return(1);
break;
case '=': return(1);
break;
case 'a': return(1);
break;
case 'h': return(1);
break;
case 'o': return(1);
break;
case 'm': return(1);
break;
case 'c': return(1);
break;
case 'x': return(1);
break;
/* let's not allow 'Q' here! */
default: return(0);
}
}
int parsedouble(char *s, double *d)
/* return values 0 = ok, with number, 1 = found a valid command,
but no number, and -1 = an error of some sort (unexpected char)*/
{
int i=0, legal = 0;
while((*(s+i) != '\0') && (legal == 0)) {
if(legal_num_part(*(s+i)) == 0) i++;
else if(legal_command_char(*(s+i)) == 1) {
/* to allow command to follow argument without blanks */
ungetch(s[i]);
*(s+i) = '\0'; /* will terminate on next pass. */
}
else legal = -1;
}
if(legal == 0) {
if(i > 0) {
sscanf(s,"%lf",d);
return(0);
}
else if (i == 0) { /* ran into a command character -- no input */
*d = 0.;
return(1); /* ok, actually */
}
}
else {
printf("%s is not a legal number!! Try again!\n",s);
return(-1);
}
}
int getdouble(double *d, double least, double most,
char *errprompt)
{
char s[30], bufin[200], c;
int success = -1, ndiscard = 0;
scanf("%s",s);
while(success < 0) {
success = parsedouble(s,d);
if((success == 0) && ((*d < least) || (*d > most))) {
printf("%g is out of range; allowed %g to %g -- \n",
*d,least,most);
success = -1;
}
if(success < 0) {
/* if there's error on input, clean out the rest of the line */
ndiscard = 0;
while((c = getchar()) != '\n') {
bufin[ndiscard] = c;
ndiscard++;
}
if(ndiscard > 0) {
bufin[ndiscard] = '\0'; /* terminate the string */
printf("Rest of input (%s) has been discarded.\n",bufin);
}
printf("%s",errprompt);
printf("\nTry again:");
scanf("%s",s);
}
}
return((int) success);
}
int parseint(char *s, int *d)
{
int i=0, legal = 0;
while((*(s+i) != '\0') && (legal == 0)) {
if(legal_int_part(*(s+i)) == 0) i++;
else if(legal_command_char(*(s+i)) == 1) {
/* to allow command to follow argument without blanks */
ungetch(s[i]);
*(s+i) = '\0'; /* will terminate on next pass. */
}
else legal = -1;
}
if(legal == 0) {
if(i > 0) {
sscanf(s,"%d",d);
return(0);
}
else if (i == 0) { /* ran into a command character -- no input */
*d = 0.;
return(1); /* didn't get a number, but something else legal */
}
}
else {
printf("%s is not a legal integer number!! Try again!\n",s);
return(-1);
}
}
int getint(int *d, int least, int most, char *errprompt)
{
char s[30];
int success = -1, ndiscard = 0;
char c, bufin[200];
scanf("%s",s);
while(success < 0) {
success = parseint(s,d);
if((success == 0) && ((*d < least) || (*d > most))) {
printf("%d is out of range; allowed %d to %d -- try again.\n",
*d,least,most);
success = -1;
}
if(success < 0) {
/* if there's error on input, clean out the rest of the line */
ndiscard = 0;
while((c = getchar()) != '\n') {
bufin[ndiscard] = c;
ndiscard++;
}
if(ndiscard > 0) {
bufin[ndiscard] = '\0'; /* cap the string */
printf("Rest of input (%s) has been discarded.\n",bufin);
}
printf("%s",errprompt);
printf("Try again:");
scanf("%s",s);
}
}
return( (int) success);
}
double bab_to_dec(struct coord bab)
/* converts a "babylonian" (sexigesimal) structure into
double-precision floating point ("decimal") number. */
{
double x;
x = bab.sign * (bab.hh + bab.mm / 60. + bab.ss / 3600.);
return(x);
}
void dec_to_bab (double deci, struct coord *bab)
/* function for converting decimal to babylonian hh mm ss.ss */
{
int hr_int, min_int;
if (deci >= 0.) bab->sign = 1;
else {
bab->sign = -1;
deci = -1. * deci;
}
hr_int = deci; /* use conversion conventions to truncate */
bab->hh = hr_int;
min_int = 60. * (deci - bab->hh);
bab->mm = min_int;
bab->ss = 3600. * (deci - bab->hh - bab->mm / 60.);
}
int get_line(char *s)
/* gets a line terminated by end-of-line and returns number of characters. */
{
char c;
int i = 0;
c = getchar(); /* get the first character */
/* chew through until you hit non white space */
while((c == '\n') || (c == ' ') || (c == '\t')) c = getchar();
s[i]=c;
i++;
/* keep going til the next newline */
while((c=getchar()) != '\n') {
s[i]=c;
i++;
}
s[i]='\0'; /* terminate with null */
return(i);
}
double get_coord()
/* Reads a string from the terminal and converts it into
a double-precision coordinate. This is trickier than
it appeared at first, since a -00 tests as non-negative;
the sign has to be picked out and handled explicitly. */
/* Prompt for input in the calling routine.*/
{
int sign;
double hrs, mins, secs;
char hh_string[6]; /* string with the first coord (hh) */
char hh1[1];
char errprompt[80];
int i = 0;
int end_in = 0;
/* read and handle the hour (or degree) part with sign */
scanf("%s",hh_string);
hh1[0] = hh_string[i];
while(hh1[0] == ' ') {
/* discard leading blanks */
i++;
hh1[0] = hh_string[i];
}
if(hh1[0] == '-') sign = -1;
else sign = 1;
if((end_in = parsedouble(hh_string,&hrs)) < 0) {
printf("Didn't parse correctly -- set parameter to zero!!\n");
return(0.);
}
if(sign == -1) hrs = -1. * hrs;
/* read in the minutes and seconds normally */
if(end_in == 0)
end_in = getdouble(&mins,0.,60.,
"Give minutes again, then seconds; no further prompts.\n");
else return(sign * hrs);
if(end_in == 0) end_in = getdouble(&secs,0.,60.,
"Give seconds again, no further prompts.\n");
else if(end_in == 1) secs = 0.;
return(sign * (hrs + mins / 60. + secs / 3600.));
}
/* begin put coords patch */
double myround(double x, int places)
/* rounds argument x to places places, e.g. 2.32839,1 -> 2.3. */
{
double tmp, base = 1.;
int i, ip;
for(i = 1; i <= places; i++) { /* bet this is faster than pow ... */
base *= 10.;
}
tmp = x * base;
if(tmp >= 0.)
tmp += 0.5;
else tmp -= 0.5;
ip = (int) tmp;
tmp = ((double) ip) / base;
return(tmp);
}
void round_coord(struct coord *incoord, struct coord *outcoord, int prec)
/* Rounds the seconds of a struct coord to a specified precision;
if they turn out to be sixty, does the carry to the other fields.
precision 0 -- whole minutes (seconds set to zero)
1 -- tenths of a minute (seconds set to zero)
2 -- whole seconds
3 -- tenths of a second
4 -- hundredths ...
etc.
*/
{
outcoord->sign = incoord->sign;
/* initialize */
outcoord->ss = incoord->ss,prec;
outcoord->mm = incoord->mm;
outcoord->hh = incoord->hh;
if(prec <= 1) {
outcoord->mm = myround((outcoord->mm + outcoord->ss / 60.),prec);
outcoord->ss = 0.;
if(outcoord->mm >= 59.99) { /* permissible because of limit
on prec */
outcoord->mm -= 60.;
outcoord->hh += 1.;
}
}
else {
outcoord->ss = myround(outcoord->ss,(prec-2));
if( outcoord->ss >= 59.999999999) { /* as many digits as
one would ever want ... */
outcoord->ss -= 60.;
outcoord->mm += 1.;
if(outcoord->mm >= 59.999999999) {
outcoord->mm -= 60.;
outcoord->hh += 1.;
}
}
}
}
void put_hrs(double hrs, int sign, int width, int showpos, int alignsign)
/* Puts out the hours (or decimal degrees) with the
following format information:
-- Allows "width" digits of space for hours;
e.g. -20 would be width 2.
-- if showpos == 1, prints a + sign if result is
positive.
-- if alignsign == 1, prints sign before the field;
otherwise places sign flush with digit.
*/
{
int i, digitsout, leadblanks;
char outform[20];
double tmp;
if(alignsign == 1) {
if(sign < 0) printf("-");
else if(showpos == 1) printf("+");
sprintf(outform,"%%%d.0f",width);
printf(outform,hrs);
}
else {
tmp = fabs(hrs);
digitsout = 1;
while(tmp >= 10.) {
digitsout++;
tmp /= 10.;
}
if(digitsout >= width) {
if(sign < 0) printf("-");
else if (showpos == 1) printf("+");
printf("%.0f",hrs);
}
else {
for(i = 1; i < width - digitsout; i++)
printf(" ");
if(sign < 0) printf("-");
else if (showpos == 1) printf("+");
else printf(" ");
sprintf(outform,"%%%d.0f",digitsout);
printf(outform,hrs);
}
}
}
void put_coords(double deci, int prec, int showsign)
{
struct coord bab, babout;
char formstr[20];
int outstringlen;
dec_to_bab(deci,&bab);
round_coord(&bab,&babout,prec);
if(prec == 0) {
put_hrs(babout.hh, babout.sign, 3, showsign, 0);
printf(" %02.0f",babout.mm);
}
else if (prec == 1) {
put_hrs(babout.hh, babout.sign, 3, showsign, 0);
printf(" %04.1f",babout.mm);
}
else {
if(prec == 2) {
put_hrs(babout.hh, babout.sign, 3, showsign, 0);
printf(" %02.0f %02.0f",
babout.mm,babout.ss);
}
else {
put_hrs(babout.hh, babout.sign, 3, showsign, 0);
sprintf(formstr," %%02.0f %%0%d.%df",
prec+1,prec-2);
printf(formstr,babout.mm,babout.ss);
}
}
}
void put_colon_coords(double deci, int prec, int showsign)
{
struct coord bab, babout;
char formstr[20];
int outstringlen;
dec_to_bab(deci,&bab);
round_coord(&bab,&babout,prec);
if(prec == 0) {
put_hrs(babout.hh, babout.sign, 3, showsign, 0);
printf(":%02.0f",babout.mm);
}
else if (prec == 1) {
put_hrs(babout.hh, babout.sign, 3, showsign, 0);
printf(":%04.1f",babout.mm);
}
else {
if(prec == 2) {
put_hrs(babout.hh, babout.sign, 3, showsign, 0);
printf(":%02.0f:%02.0f",
babout.mm,babout.ss);
}
else {
put_hrs(babout.hh, babout.sign, 3, showsign, 0);
sprintf(formstr,":%%02.0f:%%0%d.%df",
prec+1,prec-2);
printf(formstr,babout.mm,babout.ss);
}
}
}
void fput_hrs(FILE *outf, double hrs, int sign, int width,
int showpos, int alignsign)
/* Puts out the hours (or decimal degrees) with the
following format information:
-- Allows "width" digits of space for hours;
e.g. -20 would be width 2.
-- if showpos == 1, prints a + sign if result is
positive.
-- if alignsign == 1, prints sign before the field;
otherwise places sign flush with digit.
*/
{
int i, digitsout, leadblanks;
char outform[20];
double tmp;
if(alignsign == 1) {
if(sign < 0) fprintf(outf,"-");
else if(showpos == 1) fprintf(outf,"+");
sprintf(outform,"%%%d.0f",width);
fprintf(outf,outform,hrs);
}
else {
tmp = fabs(hrs);
digitsout = 1;
while(tmp >= 10.) {
digitsout++;
tmp /= 10.;
}
if(digitsout >= width) {
if(sign < 0) fprintf(outf,"-");
else if (showpos == 1) fprintf(outf,"+");
fprintf(outf,"%.0f",hrs);
}
else {
for(i = 1; i < width - digitsout; i++)
fprintf(outf," ");
if(sign < 0) fprintf(outf,"-");
else if (showpos == 1) fprintf(outf,"+");
else fprintf(outf," ");
sprintf(outform,"%%%d.0f",digitsout);
fprintf(outf,outform,hrs);
}
}
}
void fput_coords(FILE *outf, double deci, int prec, int showsign)
{
struct coord bab, babout;
char formstr[20];
int outstringlen;
dec_to_bab(deci,&bab);
round_coord(&bab,&babout,prec);
if(prec == 0) {
fput_hrs(outf,babout.hh, babout.sign, 3, showsign, 0);
fprintf(outf," %02.0f",babout.mm);
}
else if (prec == 1) {
fput_hrs(outf,babout.hh, babout.sign, 3, showsign, 0);
fprintf(outf," %04.1f",babout.mm);
}
else {
if(prec == 2) {
fput_hrs(outf,babout.hh, babout.sign, 3, showsign, 0);
fprintf(outf," %02.0f %02.0f",
babout.mm,babout.ss);
}
else {
fput_hrs(outf,babout.hh, babout.sign, 3, showsign, 0);
sprintf(formstr," %%02.0f %%0%d.%df",
prec+1,prec-2);
fprintf(outf,formstr,babout.mm,babout.ss);
}
}
}
void load_site(char *instring,
double *longit,double *lat,double *stdz,int *use_dst,
char *zone_name,char *zabr,double *elevsea, double *elev,
double *horiz, char *site_name)
/* This venerable routine is being changed to be more
script-friendly. If it's handed "?" it prompts, otherwise
it assumes that it's a site. Note that from Python one needs
to hand it three pre-allocated character strings *of different
lengths* so they refer to distinct memory locations -- Python is
odd that way -- example:
a = " "
b = " "
c = " "
x = load_site(sys.argv[1],a,b,c)
as presently wrapped, x will be a Python list with longit,
lat, etc., a, b, and c will be strings containing zone_name,
zabr, and site_name. */
/* sets the site-specific quantities; these are
longit = W longitude in decimal hours
lat = N latitude in decimal degrees
stdz = standard time zone offset, hours
elevsea = elevation above sea level (for absolute location)
elev = observatory elevation above horizon, meters
horiz = (derived) added zenith distance for rise/set due
to elevation
use_dst = 0 don't use it
1 use USA convention
2 use Spanish convention
< 0 Southern hemisphere (reserved, unimplimented)
zone_name = name of time zone, e. g. Eastern
zabr = single-character abbreviation of time zone
site_name = name of site. */
{
int nch;
char obs_code[3]; /* need only one char, but why not? */
char errprompt[50];
char legalobs[30];
strcpy(legalobs,"nkseahpctrbdoml");
if(instring[0] != '?' && index(legalobs,instring[0]) == NULL)
printf("%c is not a legal site code. So you're being prompted.\n");
if(instring[0] == '?' || index(legalobs,instring[0]) == NULL) {
printf("*SELECT SITE* - Enter single-character code:\n");
printf(" n .. NEW SITE, prompts for all parameters.\n");
printf(" k .. Kitt Peak [MDM Obs.]\n");
printf(" s .. Shattuck Observatory, Dartmouth College, Hanover NH\n");
printf(" e .. European Southern Obs, La Silla\n");
printf(" a .. Anglo-Australian Telelescope, Siding Spring\n");
printf(" h .. Mt. Hopkins, AZ (MMT, FLWO)\n");
printf(" p .. Palomar Observatory\n");
printf(" c .. Las Campanas Observatory \n");
printf(" t .. Cerro Tololo \n");
printf(" r .. Roque de los Muchachos, La Palma, Canary Is.\n");
printf(" b .. Black Moshannon Obs., Penn State U.\n");
printf(" d .. Dominion Astrophysical Obs., Victoria, BC\n");
printf(" o .. McDonald Observatory, Mt. Locke, Texas\n");
printf(" m .. Mauna Kea, Hawaii\n");
printf(" l .. Lick Observatory\n");
printf("Your answer --> ");
scanf("%s",obs_code);
}
else strcpy(obs_code,instring);
/*
if(obs_code[0] == 'x') {
printf("No action taken. Current site = %s.\n",site_name);
return;
}
*/
if(obs_code[0] == 'k') {
strcpy(site_name,"Kitt Peak [MDM Obs.]");
strcpy(zone_name, "Mountain");
*zabr = 'M';
*use_dst = 0;
*longit = 7.44111; /* decimal hours */
*lat = 31.9533; /* decimal degrees */
*stdz = 7.;
*elevsea = 1925.; /* for MDM observatory, strictly */
*elev = 700.; /* approximate -- to match KPNO tables */
}
else if (obs_code[0] == 's') {
strcpy(site_name, "Shattuck Observatory");
strcpy(zone_name,"Eastern");
*zabr = 'E';
*use_dst = 1;
*longit = 4.81907; /* from GPS */
*lat = 43.705;
*stdz = 5.;
*elevsea = 183.;
*elev = 0.; /* below surrouding horizon */
}
else if (obs_code[0] == 'e') {
strcpy(site_name, "ESO, Cerro La Silla");
strcpy(zone_name, "Chilean");
*zabr = 'C';
*use_dst = -1;
*longit = 4.7153;
*lat = -29.257;
*stdz = 4.;
*elevsea = 2347.;
*elev = 2347.; /* for ocean horizon, not Andes! */
printf("\n\n** Will use daylght time, Chilean date conventions. \n\n");
}
else if (obs_code[0] == 'p') {
strcpy(site_name, "Palomar Observatory");
strcpy(zone_name, "Pacific");
*zabr = 'P';
*use_dst = 1;
*longit = 7.79089;
*lat = 33.35667;
*elevsea = 1706.;
*elev = 1706.; /* not clear if it's appropriate ... */
*stdz = 8.;
}
else if (obs_code[0] == 't') {
strcpy(site_name, "Cerro Tololo");
strcpy(zone_name, "Chilean");
*zabr = 'C';
*use_dst = -1;
*longit = 4.721;
*lat = -30.165;
*stdz = 4.;
*elevsea = 2215.;
*elev = 2215.; /* for ocean horizon, not Andes! */
printf("\n\n** Will use daylght time, Chilean date conventions. \n\n");
}
else if (obs_code[0] == 'c') {
strcpy(site_name, "Las Campanas Observatory");
strcpy(zone_name, "Chilean");
*zabr = 'C';
*use_dst = -1;
*longit = 4.71333;
*lat = -29.00833;
*stdz = 4.;
*elevsea = 2282.;
*elev = 2282.; /* for ocean horizon, not Andes! */
printf("\n\n** Will use daylght time, Chilean date conventions. \n\n");
}
else if (obs_code[0] == 'h') {
strcpy(site_name, "Mount Hopkins, Arizona");
strcpy(zone_name, "Mountain");
*zabr = 'M';
*use_dst = 0;
*longit = 7.39233;
*lat = 31.6883;
*elevsea = 2608.;
*elev = 500.; /* approximate elevation above horizon mtns */
*stdz = 7.;
}
/* else if (obs_code[0] == 'c') {
strcpy(site_name,"Harvard College Observatory");
strcpy(zone_name,"Eastern");
*zabr = 'E';
*use_dst = 1;
*longit = 4.742;
*lat = 42.38;
*elevsea = 0.; /* small, anyhow *?
*elev = 0.;
*stdz = 5.;
} --- COMMENTED OUT */
else if (obs_code[0] == 'o') {
strcpy(site_name,"McDonald Observatory");
strcpy(zone_name,"Central");
*zabr = 'C';
*use_dst = 1;
*longit = 6.93478;
*lat = 30.6717;
*elevsea = 2075;
*elev = 1000.; /* who knows? */
*stdz = 6.;
}
else if (obs_code[0] == 'a') {
strcpy(site_name, "Anglo-Australian Tel., Siding Spring");
strcpy(zone_name, "Australian");
*zabr = 'A';
*use_dst = -2;
*longit = -9.937739;
*lat = -31.277039;
*elevsea = 1149.;
*elev = 670.;
*stdz = -10.;
}
else if (obs_code[0] == 'b') {
strcpy(site_name, "Black Moshannon Observatory");
strcpy(zone_name, "Eastern");
*zabr = 'E';
*use_dst = 1;
*longit = 5.20033;
*lat = 40.92167;
*elevsea = 738.;
*elev = 0.; /* not set */
*stdz = 5.;
}
else if (obs_code[0] == 'd') {
strcpy(site_name, "DAO, Victoria, BC");
strcpy(zone_name, "Pacific");
*zabr = 'P';
*use_dst = 1;
printf("\n\nWARNING: United States conventions for DST assumed.\n\n");
*longit = 8.22778;
*lat = 48.52;
*elevsea = 74.;
*elev = 74.; /* not that it makes much difference */
*stdz = 8.;
}
else if (obs_code[0] == 'm') {
strcpy(site_name, "Mauna Kea, Hawaii");
strcpy(zone_name, "Hawaiian");
*zabr = 'H';
*use_dst = 0;
*longit = 10.36478;
*lat = 19.8267;
*elevsea = 4215.;
*elev = 4215.; /* yow! */
*stdz = 10.;
}
else if (obs_code[0] == 'l') {
strcpy(site_name, "Lick Observatory");
strcpy(zone_name, "Pacific");
*zabr = 'P';
*use_dst = 1;
*longit = 8.10911;
*lat = 37.3433;
*elevsea = 1290.;
*elev = 1290.; /* for those nice Pacific sunsets */
*stdz = 8.;
}
else if (obs_code[0] == 'r') {
strcpy(site_name, "Roque de los Muchachos");
strcpy(zone_name, "pseudo-Greenwich");
*zabr = 'G';
*use_dst = 2;
*longit = 1.192;
*lat = 28.75833;
*elevsea = 2326.;
*elev = 2326.;
*stdz = 0.;
}
else if (obs_code[0] == 'n') {
printf("Enter new site parameters; the prompts give current values.\n");
printf("(Even if current value is correct you must re-enter explicitly.)\n");
printf("WEST longitude, (HOURS min sec); current value ");
put_coords(*longit,3,1);
printf(": ");
*longit = get_coord();
printf("Latitude, (d m s); current value ");
put_coords(*lat,2,1);
printf(": ");
*lat = get_coord();
printf("Actual elevation (meters) above sea level,");
printf(" currently %5.0f:",*elevsea);
strcpy(errprompt,"Because of error,");
/* situation is uncomplicated, so simple errprompt */
getdouble(elevsea,-1000.,100000.,errprompt);
printf("Effective elevation, meters (for rise/set),");
printf(" currently %5.0f:",*elev);
getdouble(elev,-1000.,20000.,errprompt); /* limits of approx. ... */
printf("Site name (< 30 char): ");
nch=get_line(site_name);
printf("Std time zone, hours W; currently %3.0f :",*stdz);
getdouble(stdz,-13.,13.,errprompt);
printf("Time zone name, e. g., Central: ");
nch = get_line(zone_name);
printf("Single-character zone abbreviation, currently %c : ",*zabr);
scanf("%c",zabr);
printf("Type daylight savings time option --- \n");
printf(" 0 ... don't use it, \n");
printf(" 1 ... use United States convention for clock change.\n");
printf(" 2 ... use Spanish (Continental?) convention.\n");
printf(" -1 ... use Chilean convention.\n");
printf(" -2 ... use Australian convention.\n");
printf("(Other options would require new code). Answer: --> ");
getint(use_dst,-100,100,errprompt);
}
else {
printf("UNKNOWN SITE '%c' -- left as %s. Note input is case-sensitive.\n",
obs_code[0],site_name);
}
/* now compute derived quantity "horiz" = depression of horizon.*/
*horiz = sqrt(2. * *elev / EQUAT_RAD) * DEG_IN_RADIAN;
}
double atan_circ(double x, double y)
{
/* returns radian angle 0 to 2pi for coords x, y --
get that quadrant right !! */
double theta;
if((x == 0.) && (y == 0.)) return(0.); /* guard ... */
theta = atan2(y,x); /* turns out there is such a thing in math.h */
while(theta < 0.) theta += TWOPI;
return(theta);
}
void min_max_alt(double lat,double dec,double *min, double *max)
{
/* computes minimum and maximum altitude for a given dec and
latitude. */
double x;
lat = lat / DEG_IN_RADIAN; /* pass by value! */
dec = dec / DEG_IN_RADIAN;
x = cos(dec)*cos(lat) + sin(dec)*sin(lat);
if(fabs(x) <= 1.) {
*max = asin(x) * DEG_IN_RADIAN;
}
else printf("Error in min_max_alt -- arcsin(>1)\n");
x = sin(dec)*sin(lat) - cos(dec)*cos(lat);
if(fabs(x) <= 1.) {
*min = asin(x) * DEG_IN_RADIAN;
}
else printf("Error in min_max_alt -- arcsin(>1)\n");
}
double altit(double dec,double ha,double lat,double *az,double *parang)
/* returns altitude(degr) for dec, ha, lat (decimal degr, hr, degr);
also computes and returns azimuth through pointer argument,
and as an extra added bonus returns parallactic angle (decimal degr)
through another pointer argument. */
{
double x,y,z;
double sinp, cosp; /* sin and cos of parallactic angle */
double cosdec, sindec, cosha, sinha, coslat, sinlat;
/* time-savers ... */
dec = dec / DEG_IN_RADIAN;
ha = ha / HRS_IN_RADIAN;
lat = lat / DEG_IN_RADIAN; /* thank heavens for pass-by-value */
cosdec = cos(dec); sindec = sin(dec);
cosha = cos(ha); sinha = sin(ha);
coslat = cos(lat); sinlat = sin(lat);
x = DEG_IN_RADIAN * asin(cosdec*cosha*coslat + sindec*sinlat);
y = sindec*coslat - cosdec*cosha*sinlat; /* due N comp. */
z = -1. * cosdec*sinha; /* due east comp. */
*az = atan2(z,y);
/* as it turns out, having knowledge of the altitude and
azimuth makes the spherical trig of the parallactic angle
less ambiguous ... so do it here! Method uses the
"astronomical triangle" connecting celestial pole, object,
and zenith ... now know all the other sides and angles,
so we can crush it ... */
if(cosdec != 0.) { /* protect divide by zero ... */
sinp = -1. * sin(*az) * coslat / cosdec;
/* spherical law of sines .. note cosdec = sin of codec,
coslat = sin of colat .... */
cosp = -1. * cos(*az) * cosha - sin(*az) * sinha * sinlat;
/* spherical law of cosines ... also transformed to local
available variables. */
*parang = atan2(sinp,cosp) * DEG_IN_RADIAN;
/* let the library function find the quadrant ... */
}
else { /* you're on the pole */
if(lat >= 0.) *parang = 180.;
else *parang = 0.;
}
*az *= DEG_IN_RADIAN; /* done with taking trig functions of it ... */
while(*az < 0.) *az += 360.; /* force 0 -> 360 */
while(*az >= 360.) *az -= 360.;
return(x);
}
double secant_z(double alt)
{
/* Computes the secant of z, assuming the object is not
too low to the horizon; returns 100. if the object is
low but above the horizon, -100. if the object is just
below the horizon. */
double secz;
if(alt != 0) secz = 1. / sin(alt / DEG_IN_RADIAN);
else secz = 100.;
if(secz > 100.) secz = 100.;
if(secz < -100.) secz = -100.;
return(secz);
}
double true_airmass(double secz)
{
/* returns the true airmass for a given secant z. */
/* The expression used is based on a tabulation of the mean KPNO
atmosphere given by C. M. Snell & A. M. Heiser, 1968,
PASP, 80, 336. They tabulated the airmass at 5 degr