header.c 5.8 KB

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