xref: /plan9-contrib/sys/src/cmd/scat/header.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #include	<u.h>
2 #include	<libc.h>
3 #include	<bio.h>
4 #include	"sky.h"
5 
6 struct
7 {
8 	char	name[9];
9 	char	offset;
10 } Hproto[] =
11 {
12 	"ppo1",		Pppo1,
13 	"ppo2",		Pppo2,
14 	"ppo3",		Pppo3,
15 	"ppo4",		Pppo4,
16 	"ppo5",		Pppo5,
17 	"ppo6",		Pppo6,
18 
19 	"amdx1",	Pamdx1,
20 	"amdx2",	Pamdx2,
21 	"amdx3",	Pamdx3,
22 	"amdx4",	Pamdx4,
23 	"amdx5",	Pamdx5,
24 	"amdx6",	Pamdx6,
25 	"amdx7",	Pamdx7,
26 	"amdx8",	Pamdx8,
27 	"amdx9",	Pamdx9,
28 	"amdx10",	Pamdx10,
29 	"amdx11",	Pamdx11,
30 	"amdx12",	Pamdx12,
31 	"amdx13",	Pamdx13,
32 	"amdx14",	Pamdx14,
33 	"amdx15",	Pamdx15,
34 	"amdx16",	Pamdx16,
35 	"amdx17",	Pamdx17,
36 	"amdx18",	Pamdx18,
37 	"amdx19",	Pamdx19,
38 	"amdx20",	Pamdx20,
39 
40 	"amdy1",	Pamdy1,
41 	"amdy2",	Pamdy2,
42 	"amdy3",	Pamdy3,
43 	"amdy4",	Pamdy4,
44 	"amdy5",	Pamdy5,
45 	"amdy6",	Pamdy6,
46 	"amdy7",	Pamdy7,
47 	"amdy8",	Pamdy8,
48 	"amdy9",	Pamdy9,
49 	"amdy10",	Pamdy10,
50 	"amdy11",	Pamdy11,
51 	"amdy12",	Pamdy12,
52 	"amdy13",	Pamdy13,
53 	"amdy14",	Pamdy14,
54 	"amdy15",	Pamdy15,
55 	"amdy16",	Pamdy16,
56 	"amdy17",	Pamdy17,
57 	"amdy18",	Pamdy18,
58 	"amdy19",	Pamdy19,
59 	"amdy20",	Pamdy20,
60 
61 	"pltscale",	Ppltscale,
62 	"xpixelsz",	Pxpixelsz,
63 	"ypixelsz",	Pypixelsz,
64 
65 	"pltrah",	Ppltrah,
66 	"pltram",	Ppltram,
67 	"pltras",	Ppltras,
68 	"pltdecd",	Ppltdecd,
69 	"pltdecm",	Ppltdecm,
70 	"pltdecs",	Ppltdecs,
71 
72 };
73 
74 Header*
75 getheader(char *rgn)
76 {
77 	char rec[81], name[81], value[81];
78 	char *p;
79 	Biobuf *bin;
80 	Header hd, *h;
81 	int i, j, decsn, dss;
82 
83 	dss = 0;
84 	sprint(rec, "/lib/sky/dssheaders/%s.hhh", rgn);
85 	bin = Bopen(rec, OREAD);
86 	if(bin == 0) {
87 		dss = 102;
88 		sprint(rec, "/n/juke/dss.102/headers/%s.hhh", rgn);
89 		bin = Bopen(rec, OREAD);
90 	}
91 	if(bin == 0) {
92 		dss = 61;
93 		sprint(rec, "/n/juke/dss.61/headers/%s.hhh", rgn);
94 		bin = Bopen(rec, OREAD);
95 	}
96 	if(bin == 0) {
97 		fprint(2, "cannot open %s\n", rgn);
98 		exits("file");
99 	}
100 	if(debug)
101 		print("reading %s\n", rec);
102 	if(dss)
103 		print("warning: reading %s from jukebox\n, rec");
104 
105 	memset(&hd, 0, sizeof(hd));
106 	j = 0;
107 	decsn = 0;
108 	for(;;) {
109 		if(dss) {
110 			if(Bread(bin, rec, 80) != 80)
111 				break;
112 			rec[80] = 0;
113 		} else {
114 			p = Brdline(bin, '\n');
115 			if(p == 0)
116 				break;
117 			p[Blinelen(bin)-1] = 0;
118 			strcpy(rec, p);
119 		}
120 
121 		p = strchr(rec, '/');
122 		if(p)
123 			*p = 0;
124 		p = strchr(rec, '=');
125 		if(p == 0)
126 			continue;
127 		*p++ = 0;
128 		if(getword(name, rec) == 0)
129 			continue;
130 		if(getword(value, p) == 0)
131 			continue;
132 		if(strcmp(name, "pltdecsn") == 0) {
133 			if(strchr(value, '-'))
134 				decsn = 1;
135 			continue;
136 		}
137 		for(i=0; i<nelem(Hproto); i++) {
138 			j++;
139 			if(j >= nelem(Hproto))
140 				j = 0;
141 			if(strcmp(name, Hproto[j].name) == 0) {
142 				hd.param[Hproto[j].offset] = atof(value);
143 				break;
144 			}
145 		}
146 	}
147 	Bterm(bin);
148 
149 	hd.param[Ppltra] = RAD(hd.param[Ppltrah]*15 +
150 		hd.param[Ppltram]/4 + hd.param[Ppltras]/240);
151 	hd.param[Ppltdec] = RAD(hd.param[Ppltdecd] +
152 		hd.param[Ppltdecm]/60 + hd.param[Ppltdecs]/3600);
153 	if(decsn)
154 		hd.param[Ppltdec] = -hd.param[Ppltdec];
155 	hd.amdflag = 0;
156 	for(i=Pamdx1; i<=Pamdx20; i++)
157 		if(hd.param[i] != 0) {
158 			hd.amdflag = 1;
159 			break;
160 		}
161 	h = malloc(sizeof(*h));
162 	*h = hd;
163 	return h;
164 }
165 
166 void
167 getplates(void)
168 {
169 	char rec[81], *q;
170 	Plate *p;
171 	Biobuf *bin;
172 	int c, i, dss;
173 
174 	dss = 0;
175 	sprint(rec, "/lib/sky/dssheaders/lo_comp.lis");
176 	bin = Bopen(rec, OREAD);
177 	if(bin == 0) {
178 		dss = 102;
179 		sprint(rec, "/n/juke/dss.102/headers/lo_comp.lis");
180 		bin = Bopen(rec, OREAD);
181 	}
182 	if(bin == 0) {
183 		dss = 61;
184 		sprint(rec, "/n/juke/dss.61/headers/lo_comp.lis");
185 		bin = Bopen(rec, OREAD);
186 	}
187 	if(bin == 0) {
188 		fprint(2, "can't open lo_comp.lis; try 9fs juke\n");
189 		exits("open");
190 	}
191 	if(debug)
192 		print("reading %s\n", rec);
193 	if(dss)
194 		print("warning: reading %s from jukebox\n, rec");
195 	for(nplate=0;;) {
196 		if(dss) {
197 			if(Bread(bin, rec, 80) != 80)
198 				break;
199 			rec[80] = 0;
200 		} else {
201 			q = Brdline(bin, '\n');
202 			if(q == 0)
203 				break;
204 			q[Blinelen(bin)-1] = 0;
205 			strcpy(rec, q);
206 		}
207 		if(rec[0] == '#')
208 			continue;
209 		if(nplate < nelem(plate)) {
210 			p = &plate[nplate];
211 			memmove(p->rgn, rec+0, 5);
212 			if(p->rgn[4] == ' ')
213 				p->rgn[4] = 0;
214 			for(i=0; c=p->rgn[i]; i++)
215 				if(c >= 'A' && c <= 'Z')
216 					p->rgn[i] += 'a'-'A';
217 			p->ra = RAD(atof(rec+12)*15 +
218 				atof(rec+15)/4 +
219 				atof(rec+18)/240);
220 			p->dec = RAD(atof(rec+26) +
221 				atof(rec+29)/60 +
222 				atof(rec+32)/3600);
223 			if(rec[25] == '-')
224 				p->dec = -p->dec;
225 			p->disk = atoi(rec+53);
226 			if(p->disk == 0)
227 				continue;
228 		}
229 		nplate++;
230 	}
231 	Bterm(bin);
232 
233 	if(nplate >= nelem(plate))
234 		fprint(2, "nplate too small %d %d\n", nelem(plate), nplate);
235 	if(debug)
236 		print("%d plates\n", nplate);
237 }
238