/************************************************************************/ /* Routines for formating catalogs in a machine adaptable format. */ /* */ /* The format consists of 4, 16, and 32 bit integers. The first */ /* short integer after the catalog type (the first byte) is used */ /* to determine whether the bytes must be swapped. The default */ /* for creating a new catalog is no swapping. Floating point */ /* numbers are scaled in powers of 10 to the integer 1000000 to */ /* 999999 so that all numbers have 6 significant digits. The */ /* scale factor is coded as one bite. A machine adaptable */ /* catalog is transparent to the FOCAS routines and is handled */ /* automatically by the catalog I/O. */ /************************************************************************/ #include "focas1.h" #include "miformat.h" static int miswap = 0; static float scales[] = {0.000001, 0.00001, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0}; /* MIWTCATHDR -- Write catalog header in machine independent format */ miwtcathdr (fd) FILE *fd; { short i, j; long sz, tempval, tempval1, *temp, *temp1; char *miscale; float xfrm; struct misgparm mi; struct micrule micrules; struct miflmcv miflmcv; temp = &tempval; temp1 = &tempval1; if (miswap) { miscale = mi.miscale; strcpy (mi.pltnm, sp.pltnm); strcpy (mi.pltepoch, sp.pltepoch); mi.band[0] = sp.band[0]; mi.band[1] = sp.band[1]; micode (sp.pltra, temp, miscale++); swapl (temp, &mi.pltra); micode (sp.pltdec, temp, miscale++); swapl (temp, &mi.pltdec); swaps (&sp.pltexp, &mi.pltexp); strcpy (mi.observer, sp.observer); strcpy (mi.origin, sp.origin); for (i=0; i<3; i++) for (j=0; j<3; j++) { xfrm = sp.xfrm[i][j]; micode (xfrm, temp, miscale++); swapl (temp, &mi.xfrm[i][j]); } swapl (&sp.comment, &mi.comment); swapl (&sp.xs, &mi.xs); swapl (&sp.ys, &mi.ys); swapl (&sp.kpts, &mi.kpts); swapl (&sp.kscan, &mi.kscan); strcpy (mi.dtestr, sp.dtestr); swapl (&sp.pflags, &mi.pflags); strcpy (mi.ptfl, sp.ptfl); strcpy (mi.arfl, sp.arfl); swapl (&sp.minudt, &mi.minudt); swapl (&sp.nupdte, &mi.nupdte); micode (sp.sa, temp, miscale++); swapl (temp, &mi.sa); micode (sp.sb, temp, miscale++); swapl (temp, &mi.sb); micode (sp.thrln0, temp, miscale++); swapl (temp, &mi.thrln0); micode (sp.thrln1, temp, miscale++); swapl (temp, &mi.thrln1); swapl (&sp.minarea, &mi.minarea); micode (sp.magfst, temp, miscale++); swapl (temp, &mi.magfst); micode (sp.maglim, temp, miscale++); swapl (temp, &mi.maglim); swapl (&sp.skwdth, &mi.skwdth); swapl (&sp.satr, &mi.satr); swapl (&sp.buf, &mi.buf); micode (sp.grow, temp, miscale++); swapl (temp, &mi.grow); micode (sp.skyhw, temp, miscale++); swapl (temp, &mi.skyhw); micode (sp.skybw, temp, miscale++); swapl (temp, &mi.skybw); micode (sp.sptbw, temp, miscale++); swapl (temp, &mi.sptbw); micode (sp.rfca, temp, miscale++); swapl (temp, &mi.rfca); micode (sp.sig, temp, miscale++); swapl (temp, &mi.sig); swapl (&sp.fx, &mi.fx); swapl (&sp.fy, &mi.fy); swapl (&sp.nden, &mi.nden); swapl (&sp.nx, &mi.nx); swapl (&sp.ny, &mi.ny); swapl (&sp.nrules, &mi.nrules); i = 1; swaps (&i, &j); if (fwrite (&j, 2, 1, fd) != 1) return (1); sz = sizeof (mi); if (fwrite (&mi, sz, 1, fd) != 1) return (1); swaps (&ncmmnts, &i); if (fwrite (&i, 2, 1, fd) != 1) return (1); for (i = 0; i < ncmmnts; i++) if (fwrite (comments[i], COLEN, 1, fd) != 1) return (1); sz = sizeof (miflmcv); for (i = 0; i < sp.nden; i++) { miscale = miflmcv.miscale; swapl (&flmcv[i].d, &miflmcv.d); micode (flmcv[i].i, temp, miscale++); swapl (temp, &miflmcv.i); micode (flmcv[i].slope, temp, miscale++); swapl (temp, &miflmcv.slope); if (fwrite (&miflmcv, sz, 1, fd) != 1) return(1); } sz = sizeof (float); miscale = mi.miscale; for (i = 0; i < sp.fy; i++) for (j = 0; j < sp.fx; j++) { micode (dfltr[i][j], temp, miscale); swapl (temp, temp1); fwrite (temp1, sz, 1, fd); if (cattype == 3) fwrite (miscale, 1, 1, fd); else fwrite (miscale, 2, 1, fd); } sz = sizeof (float); miscale = mi.miscale; for (i = 0; i < sp.ny; i++) for (j = 0; j < sp.nx; j++) { micode (template[i][j], temp, miscale); swapl (temp, temp1); fwrite (temp1, sz, 1, fd); if (cattype == 3) fwrite (miscale, 1, 1, fd); else fwrite (miscale, 2, 1, fd); } sz = sizeof (micrules); for (i = 0; i < sp.nrules; i++) { miscale = micrules.miscale; micode (crules[i].mag1, temp, miscale++); swapl (temp, &micrules.mag1); micode (crules[i].mag2, temp, miscale++); swapl (temp, &micrules.mag2); micode (crules[i].scl1, temp, miscale++); swapl (temp, &micrules.scl1); micode (crules[i].scl2, temp, miscale++); swapl (temp, &micrules.scl2); micode (crules[i].frc1, temp, miscale++); swapl (temp, &micrules.frc1); micode (crules[i].frc2, temp, miscale++); swapl (temp, &micrules.frc2); strcpy (micrules.class, crules[i].class); if (fwrite (&micrules, sz, 1, fd) != 1) return(1); } } else { miscale = mi.miscale; strcpy (mi.pltnm, sp.pltnm); strcpy (mi.pltepoch, sp.pltepoch); mi.band[0] = sp.band[0]; mi.band[1] = sp.band[1]; micode (sp.pltra, &mi.pltra, miscale++); micode (sp.pltdec, &mi.pltdec, miscale++); mi.pltexp = sp.pltexp; strcpy (mi.observer, sp.observer); strcpy (mi.origin, sp.origin); for (i=0; i<3; i++) for (j=0; j<3; j++) { xfrm = sp.xfrm[i][j]; micode (xfrm, &mi.xfrm[i][j], miscale++); } mi.comment = sp.comment; mi.xs = sp.xs; mi.ys = sp.ys; mi.kpts = sp.kpts; mi.kscan = sp.kscan; strcpy (mi.dtestr, sp.dtestr); mi.pflags = sp.pflags; strcpy (mi.ptfl, sp.ptfl); strcpy (mi.arfl, sp.arfl); mi.minudt = sp.minudt; mi.nupdte = sp.nupdte; micode (sp.sa, &mi.sa, miscale++); micode (sp.sb, &mi.sb, miscale++); micode (sp.thrln0, &mi.thrln0, miscale++); micode (sp.thrln1, &mi.thrln1, miscale++); mi.minarea = sp.minarea; micode (sp.magfst, &mi.magfst, miscale++); micode (sp.maglim, &mi.maglim, miscale++); mi.skwdth = sp.skwdth; mi.satr = sp.satr; mi.buf = sp.buf; micode (sp.grow, &mi.grow, miscale++); micode (sp.skyhw, &mi.skyhw, miscale++); micode (sp.skybw, &mi.skybw, miscale++); micode (sp.sptbw, &mi.sptbw, miscale++); micode (sp.rfca, &mi.rfca, miscale++); micode (sp.sig, &mi.sig, miscale++); mi.fx = sp.fx; mi.fy = sp.fy; mi.nden = sp.nden; mi.nx = sp.nx; mi.ny = sp.ny; mi.nrules = sp.nrules; i = 1; if (fwrite (&i, 2, 1, fd) != 1) return (1); sz = sizeof (mi); if (fwrite (&mi, sz, 1, fd) != 1) return (1); if (fwrite (&ncmmnts, 2, 1, fd) != 1) return (1); for (i = 0; i < ncmmnts; i++) if (fwrite (comments[i], COLEN, 1, fd) != 1) return (1); sz = sizeof (miflmcv); for (i = 0; i < sp.nden; i++) { miscale = miflmcv.miscale; miflmcv.d = flmcv[i].d; micode (flmcv[i].i, &miflmcv.i, miscale++); micode (flmcv[i].slope, &miflmcv.slope, miscale++); if (fwrite (&miflmcv, sz, 1, fd) != 1) return(1); } sz = sizeof (float); miscale = mi.miscale; for (i = 0; i < sp.fy; i++) for (j = 0; j < sp.fx; j++) { micode (dfltr[i][j], temp, miscale); fwrite (temp, sz, 1, fd); if (cattype == 3) fwrite (miscale, 1, 1, fd); else fwrite (miscale, 2, 1, fd); } sz = sizeof (float); miscale = mi.miscale; for (i = 0; i < sp.ny; i++) for (j = 0; j < sp.nx; j++) { micode (template[i][j], temp, miscale); fwrite (temp, sz, 1, fd); if (cattype == 3) fwrite (miscale, 1, 1, fd); else fwrite (miscale, 2, 1, fd); } sz = sizeof (micrules); for (i = 0; i < sp.nrules; i++) { miscale = micrules.miscale; micode (crules[i].mag1, &micrules.mag1, miscale++); micode (crules[i].mag2, &micrules.mag2, miscale++); micode (crules[i].scl1, &micrules.scl1, miscale++); micode (crules[i].scl2, &micrules.scl2, miscale++); micode (crules[i].frc1, &micrules.frc1, miscale++); micode (crules[i].frc2, &micrules.frc2, miscale++); strcpy (micrules.class, crules[i].class); if (fwrite (&micrules, sz, 1, fd) != 1) return(1); } } return (0); } /* MIRDCATHDR -- Read catalog header in machine independent format */ mirdcathdr (fd) FILE *fd; { short i, j; long sz, tempval, tempval1, *temp, *temp1; char *miscale; float xfrm; struct misgparm mi; struct micrule micrules; struct miflmcv miflmcv; if (fread (&i, 2, 1, fd) != 1) return (1); if (i == 1) miswap = 0; else { swaps (&i, &j); if (j != 1) return (1); miswap = 1; } temp = &tempval; temp1 = &tempval1; if (miswap) { sz = sizeof (mi); if (fread (&mi, sz, 1, fd) != 1) return (1); miscale = mi.miscale; strcpy (sp.pltnm, mi.pltnm); strcpy (sp.pltepoch, mi.pltepoch); sp.band[0] = mi.band[0]; sp.band[1] = mi.band[1]; swapl (&mi.pltra, temp); midecode (tempval, miscale++, &sp.pltra); swapl (&mi.pltdec, temp); midecode (tempval, miscale++, &sp.pltdec); swaps (&mi.pltexp, &sp.pltexp); strcpy (sp.observer, mi.observer); strcpy (sp.origin, mi.origin); for (i=0; i<3; i++) for (j=0; j<3; j++) { swapl (&mi.xfrm[i][j], temp); midecode (tempval, miscale++, &xfrm); sp.xfrm[i][j] = xfrm; } swapl (&mi.comment, &sp.comment); swapl (&mi.xs, &sp.xs); swapl (&mi.ys, &sp.ys); swapl (&mi.kpts, &sp.kpts); swapl (&mi.kscan, &sp.kscan); strcpy (sp.dtestr, mi.dtestr); swapl (&mi.pflags, &sp.pflags); strcpy (sp.ptfl, mi.ptfl); strcpy (sp.arfl, mi.arfl); swapl (&mi.minudt, &sp.minudt); swapl (&mi.nupdte, &sp.nupdte); swapl (&mi.sa, temp); midecode (tempval, miscale++, &sp.sa); swapl (&mi.sb, temp); midecode (tempval, miscale++, &sp.sb); swapl (&mi.thrln0, temp); midecode (tempval, miscale++, &sp.thrln0); swapl (&mi.thrln1, temp); midecode (tempval, miscale++, &sp.thrln1); swapl (&mi.minarea, &sp.minarea); swapl (&mi.magfst, temp); midecode (tempval, miscale++, &sp.magfst); swapl (&mi.maglim, temp); midecode (tempval, miscale++, &sp.maglim); swapl (&mi.skwdth, &sp.skwdth); swapl (&mi.satr, &sp.satr); swapl (&mi.buf, &sp.buf); swapl (&mi.grow, temp); midecode (tempval, miscale++, &sp.grow); swapl (&mi.skyhw, temp); midecode (tempval, miscale++, &sp.skyhw); swapl (&mi.skybw, temp); midecode (tempval, miscale++, &sp.skybw); swapl (&mi.sptbw, temp); midecode (tempval, miscale++, &sp.sptbw); swapl (&mi.rfca, temp); midecode (tempval, miscale++, &sp.rfca); swapl (&mi.sig, temp); midecode (tempval, miscale++, &sp.sig); swapl (&mi.fx, &sp.fx); swapl (&mi.fy, &sp.fy); swapl (&mi.nden, &sp.nden); swapl (&mi.nx, &sp.nx); swapl (&mi.ny, &sp.ny); swapl (&mi.nrules, &sp.nrules); if (fread (&i, 2, 1, fd) != 1) return (1); swaps (&i, &ncmmnts); for (i = 0; i < ncmmnts; i++) if (fread (comments[i], COLEN, 1, fd) != 1) return (1); sz = sizeof (miflmcv); for (i = 0; i < sp.nden; i++) { if (fread (&miflmcv, sz, 1, fd) != 1) return(1); miscale = miflmcv.miscale; swapl (&miflmcv.d, &flmcv[i].d); swapl (&miflmcv.i, temp); midecode (tempval, miscale++, &flmcv[i].i); swapl (&miflmcv.slope, temp); midecode (tempval, miscale++, &flmcv[i].slope); } sz = sizeof (float); miscale = mi.miscale; for (i = 0; i < sp.fy; i++) for (j = 0; j < sp.fx; j++) { fread (temp1, sz, 1, fd); if (cattype == 3) fread (miscale, 1, 1, fd); else fread (miscale, 2, 1, fd); swapl (temp1, temp); midecode (tempval, miscale, &dfltr[i][j]); } sz = sizeof (float); miscale = mi.miscale; for (i = 0; i < sp.ny; i++) for (j = 0; j < sp.nx; j++) { fread (temp1, sz, 1, fd); if (cattype == 3) fread (miscale, 1, 1, fd); else fread (miscale, 2, 1, fd); swapl (temp1, temp); midecode (tempval, miscale, &template[i][j]); } sz = sizeof (micrules); for (i = 0; i < sp.nrules; i++) { if (fread (&micrules, sz, 1, fd) != 1) return(1); miscale = micrules.miscale; swapl (&micrules.mag1, temp); midecode (tempval, miscale++, &crules[i].mag1); swapl (&micrules.mag2, temp); midecode (tempval, miscale++, &crules[i].mag2); swapl (&micrules.scl1, temp); midecode (tempval, miscale++, &crules[i].scl1); swapl (&micrules.scl2, temp); midecode (tempval, miscale++, &crules[i].scl2); swapl (&micrules.frc1, temp); midecode (tempval, miscale++, &crules[i].frc1); swapl (&micrules.frc2, temp); midecode (tempval, miscale++, &crules[i].frc2); strcpy (crules[i].class, micrules.class); } } else { sz = sizeof (mi); if (fread (&mi, sz, 1, fd) != 1) return (1); miscale = mi.miscale; strcpy (sp.pltnm, mi.pltnm); strcpy (sp.pltepoch, mi.pltepoch); sp.band[0] = mi.band[0]; sp.band[1] = mi.band[1]; midecode (mi.pltra, miscale++, &sp.pltra); midecode (mi.pltdec, miscale++, &sp.pltdec); sp.pltexp = mi.pltexp; strcpy (sp.observer, mi.observer); strcpy (sp.origin, mi.origin); for (i=0; i<3; i++) for (j=0; j<3; j++) { midecode (mi.xfrm[i][j], miscale++, &xfrm); sp.xfrm[i][j] = xfrm; } sp.comment = mi.comment; sp.xs = mi.xs; sp.ys = mi.ys; sp.kpts = mi.kpts; sp.kscan = mi.kscan; strcpy (sp.dtestr, mi.dtestr); sp.pflags = mi.pflags; strcpy (sp.ptfl, mi.ptfl); strcpy (sp.arfl, mi.arfl); sp.minudt = mi.minudt; sp.nupdte = mi.nupdte; midecode (mi.sa, miscale++, &sp.sa); midecode (mi.sb, miscale++, &sp.sb); midecode (mi.thrln0, miscale++, &sp.thrln0); midecode (mi.thrln1, miscale++, &sp.thrln1); sp.minarea = mi.minarea; midecode (mi.magfst, miscale++, &sp.magfst); midecode (mi.maglim, miscale++, &sp.maglim); sp.skwdth = mi.skwdth; sp.satr = mi.satr; sp.buf = mi.buf; midecode (mi.grow, miscale++, &sp.grow); midecode (mi.skyhw, miscale++, &sp.skyhw); midecode (mi.skybw, miscale++, &sp.skybw); midecode (mi.sptbw, miscale++, &sp.sptbw); midecode (mi.rfca, miscale++, &sp.rfca); midecode (mi.sig, miscale++, &sp.sig); sp.fx = mi.fx; sp.fy = mi.fy; sp.nden = mi.nden; sp.nx = mi.nx; sp.ny = mi.ny; sp.nrules = mi.nrules; if (fread (&ncmmnts, 2, 1, fd) != 1) return (1); for (i = 0; i < ncmmnts; i++) if (fread (comments[i], COLEN, 1, fd) != 1) return (1); sz = sizeof (miflmcv); for (i = 0; i < sp.nden; i++) { if (fread (&miflmcv, sz, 1, fd) != 1) return(1); miscale = miflmcv.miscale; flmcv[i].d = miflmcv.d; midecode (miflmcv.i, miscale++, &flmcv[i].i); midecode (miflmcv.slope, miscale++, &flmcv[i].slope); } sz = sizeof (float); miscale = mi.miscale; for (i = 0; i < sp.fy; i++) for (j = 0; j < sp.fx; j++) { fread (temp, sz, 1, fd); if (cattype == 3) fread (miscale, 1, 1, fd); else fread (miscale, 2, 1, fd); midecode (tempval, miscale, &dfltr[i][j]); } sz = sizeof (float); miscale = mi.miscale; for (i = 0; i < sp.ny; i++) for (j = 0; j < sp.nx; j++) { fread (temp, sz, 1, fd); if (cattype == 3) fread (miscale, 1, 1, fd); else fread (miscale, 2, 1, fd); midecode (tempval, miscale, &template[i][j]); } sz = sizeof (micrules); for (i = 0; i < sp.nrules; i++) { if (fread (&micrules, sz, 1, fd) != 1) return(1); miscale = micrules.miscale; midecode (micrules.mag1, miscale++, &crules[i].mag1); midecode (micrules.mag2, miscale++, &crules[i].mag2); midecode (micrules.scl1, miscale++, &crules[i].scl1); midecode (micrules.scl2, miscale++, &crules[i].scl2); midecode (micrules.frc1, miscale++, &crules[i].frc1); midecode (micrules.frc2, miscale++, &crules[i].frc2); strcpy (crules[i].class, micrules.class); } } return (0); } /* MIWTCAT -- Write object record in machine independent format */ miwtcat (fd, ob) FILE *fd; struct objrec *ob; { long sz, tempval, *temp; char *miscale; struct mirec mi; miscale = mi.miscale; if (miswap) { temp = &tempval; swaps (&ob->entnum, &mi.entnum); swapl (&ob->subent, &mi.subent); mi.class[0] = ob->class[0]; mi.class[1] = ob->class[1]; mi.class[2] = ob->class[2]; mi.class[3] = ob->class[3]; mi.class[4] = ob->class[4]; swaps (&ob->eflgs, &mi.eflgs); swaps (&ob->nsbr, &mi.nsbr); swapl (&ob->area, &mi.area); swapl (&ob->tarea, &mi.tarea); swapl (&ob->arpos, &mi.arpos); micode (ob->sbr, temp, miscale++); swapl (temp, &mi.sbr); micode (ob->ssbr, temp, miscale++); swapl (temp, &mi.ssbr); micode (ob->ispht, temp, miscale++); swapl (temp, &mi.ispht); micode (ob->xavg, temp, miscale++); swapl (temp, &mi.xavg); micode (ob->yavg, temp, miscale++); swapl (temp, &mi.yavg); micode (ob->xc, temp, miscale++); swapl (temp, &mi.xc); micode (ob->yc, temp, miscale++); swapl (temp, &mi.yc); micode (ob->ra, temp, miscale++); swapl (temp, &mi.ra); micode (ob->dec, temp, miscale++); swapl (temp, &mi.dec); micode (ob->Li, temp, miscale++); swapl (temp, &mi.Li); micode (ob->sLi, temp, miscale++); swapl (temp, &mi.sLi); micode (ob->Lc, temp, miscale++); swapl (temp, &mi.Lc); micode (ob->Lfca, temp, miscale++); swapl (temp, &mi.Lfca); micode (ob->Ltotal, temp, miscale++); swapl (temp, &mi.Ltotal); micode (ob->mag, temp, miscale++); swapl (temp, &mi.mag); micode (ob->icx, temp, miscale++); swapl (temp, &mi.icx); micode (ob->icy, temp, miscale++); swapl (temp, &mi.icy); micode (ob->ixx, temp, miscale++); swapl (temp, &mi.ixx); micode (ob->iyy, temp, miscale++); swapl (temp, &mi.iyy); micode (ob->ixy, temp, miscale++); swapl (temp, &mi.ixy); micode (ob->ir1, temp, miscale++); swapl (temp, &mi.ir1); micode (ob->ir3, temp, miscale++); swapl (temp, &mi.ir3); micode (ob->ir4, temp, miscale++); swapl (temp, &mi.ir4); micode (ob->cx, temp, miscale++); swapl (temp, &mi.cx); micode (ob->cy, temp, miscale++); swapl (temp, &mi.cy); micode (ob->xx, temp, miscale++); swapl (temp, &mi.xx); micode (ob->yy, temp, miscale++); swapl (temp, &mi.yy); micode (ob->xy, temp, miscale++); swapl (temp, &mi.xy); micode (ob->r1, temp, miscale++); swapl (temp, &mi.r1); micode (ob->fitxc, temp, miscale++); swapl (temp, &mi.fitxc); micode (ob->fityc, temp, miscale++); swapl (temp, &mi.fityc); micode (ob->scale, temp, miscale++); swapl (temp, &mi.scale); micode (ob->frac, temp, miscale++); swapl (temp, &mi.frac); micode (ob->prob, temp, miscale++); swapl (temp, &mi.prob); } else { mi.entnum = ob->entnum; mi.subent = ob->subent; mi.class[0] = ob->class[0]; mi.class[1] = ob->class[1]; mi.class[2] = ob->class[2]; mi.class[3] = ob->class[3]; mi.class[4] = ob->class[4]; mi.eflgs = ob->eflgs; mi.nsbr = ob->nsbr; mi.area = ob->area; mi.tarea = ob->tarea; mi.arpos = ob->arpos; micode (ob->sbr, &mi.sbr, miscale++); micode (ob->ssbr, &mi.ssbr, miscale++); micode (ob->ispht, &mi.ispht, miscale++); micode (ob->xavg, &mi.xavg, miscale++); micode (ob->yavg, &mi.yavg, miscale++); micode (ob->xc, &mi.xc, miscale++); micode (ob->yc, &mi.yc, miscale++); micode (ob->ra, &mi.ra, miscale++); micode (ob->dec, &mi.dec, miscale++); micode (ob->Li, &mi.Li, miscale++); micode (ob->sLi, &mi.sLi, miscale++); micode (ob->Lc, &mi.Lc, miscale++); micode (ob->Lfca, &mi.Lfca, miscale++); micode (ob->Ltotal, &mi.Ltotal, miscale++); micode (ob->mag, &mi.mag, miscale++); micode (ob->icx, &mi.icx, miscale++); micode (ob->icy, &mi.icy, miscale++); micode (ob->ixx, &mi.ixx, miscale++); micode (ob->iyy, &mi.iyy, miscale++); micode (ob->ixy, &mi.ixy, miscale++); micode (ob->ir1, &mi.ir1, miscale++); micode (ob->ir3, &mi.ir3, miscale++); micode (ob->ir4, &mi.ir4, miscale++); micode (ob->cx, &mi.cx, miscale++); micode (ob->cy, &mi.cy, miscale++); micode (ob->xx, &mi.xx, miscale++); micode (ob->yy, &mi.yy, miscale++); micode (ob->xy, &mi.xy, miscale++); micode (ob->r1, &mi.r1, miscale++); micode (ob->fitxc, &mi.fitxc, miscale++); micode (ob->fityc, &mi.fityc, miscale++); micode (ob->scale, &mi.scale, miscale++); micode (ob->frac, &mi.frac, miscale++); micode (ob->prob, &mi.prob, miscale++); } sz = sizeof (mi); if (fwrite (&mi, sz, 1, fd) != 1) return (1); return (0); } /* MIRDCATOB -- Read object record in machine independent format */ mirdcatob (fd, offset, ob) FILE *fd; long offset; struct objrec *ob; { long pos, sz, tempval, *temp; char *miscale; struct mirec mi; sz = sizeof (mi); pos = ftell (fd); offset *= sz; if (offset > 0) { if (pos + offset >= szcat (fd)) return (1); fseek (fd, offset, 1); } else if (offset < 0) { if (pos + offset < miszcathdr ()) return (-1); fseek (fd, offset, 1); } if (fread (&mi, sz, 1, fd) < 1) return (1); miscale = mi.miscale; if (miswap) { temp = &tempval; swaps (&mi.entnum, &ob->entnum); swapl (&mi.subent, &ob->subent); ob->class[0] = mi.class[0]; ob->class[1] = mi.class[1]; ob->class[2] = mi.class[2]; ob->class[3] = mi.class[3]; ob->class[4] = mi.class[4]; swaps (&mi.eflgs, &ob->eflgs); swaps (&mi.nsbr, &ob->nsbr); swapl (&mi.area, &ob->area); swapl (&mi.tarea, &ob->tarea); swapl (&mi.arpos, &ob->arpos); swapl (&mi.sbr, temp); midecode (tempval, miscale++, &ob->sbr); swapl (&mi.ssbr, temp); midecode (tempval, miscale++, &ob->ssbr); swapl (&mi.ispht, temp); midecode (tempval, miscale++, &ob->ispht); swapl (&mi.xavg, temp); midecode (tempval, miscale++, &ob->xavg); swapl (&mi.yavg, temp); midecode (tempval, miscale++, &ob->yavg); swapl (&mi.xc, temp); midecode (tempval, miscale++, &ob->xc); swapl (&mi.yc, temp); midecode (tempval, miscale++, &ob->yc); swapl (&mi.ra, temp); midecode (tempval, miscale++, &ob->ra); swapl (&mi.dec, temp); midecode (tempval, miscale++, &ob->dec); swapl (&mi.Li, temp); midecode (tempval, miscale++, &ob->Li); swapl (&mi.sLi, temp); midecode (tempval, miscale++, &ob->sLi); swapl (&mi.Lc, temp); midecode (tempval, miscale++, &ob->Lc); swapl (&mi.Lfca, temp); midecode (tempval, miscale++, &ob->Lfca); swapl (&mi.Ltotal, temp); midecode (tempval, miscale++, &ob->Ltotal); swapl (&mi.mag, temp); midecode (tempval, miscale++, &ob->mag); swapl (&mi.icx, temp); midecode (tempval, miscale++, &ob->icx); swapl (&mi.icy, temp); midecode (tempval, miscale++, &ob->icy); swapl (&mi.ixx, temp); midecode (tempval, miscale++, &ob->ixx); swapl (&mi.iyy, temp); midecode (tempval, miscale++, &ob->iyy); swapl (&mi.ixy, temp); midecode (tempval, miscale++, &ob->ixy); swapl (&mi.ir1, temp); midecode (tempval, miscale++, &ob->ir1); swapl (&mi.ir3, temp); midecode (tempval, miscale++, &ob->ir3); swapl (&mi.ir4, temp); midecode (tempval, miscale++, &ob->ir4); swapl (&mi.cx, temp); midecode (tempval, miscale++, &ob->cx); swapl (&mi.cy, temp); midecode (tempval, miscale++, &ob->cy); swapl (&mi.xx, temp); midecode (tempval, miscale++, &ob->xx); swapl (&mi.yy, temp); midecode (tempval, miscale++, &ob->yy); swapl (&mi.xy, temp); midecode (tempval, miscale++, &ob->xy); swapl (&mi.r1, temp); midecode (tempval, miscale++, &ob->r1); swapl (&mi.fitxc, temp); midecode (tempval, miscale++, &ob->fitxc); swapl (&mi.fityc, temp); midecode (tempval, miscale++, &ob->fityc); swapl (&mi.scale, temp); midecode (tempval, miscale++, &ob->scale); swapl (&mi.frac, temp); midecode (tempval, miscale++, &ob->frac); swapl (&mi.prob, temp); midecode (tempval, miscale++, &ob->prob); } else { ob->entnum = mi.entnum; ob->subent = mi.subent; ob->class[0] = mi.class[0]; ob->class[1] = mi.class[1]; ob->class[2] = mi.class[2]; ob->class[3] = mi.class[3]; ob->class[4] = mi.class[4]; ob->eflgs = mi.eflgs; ob->nsbr = mi.nsbr; ob->area = mi.area; ob->tarea = mi.tarea; ob->arpos = mi.arpos; midecode (mi.sbr, miscale++, &ob->sbr); midecode (mi.ssbr, miscale++, &ob->ssbr); midecode (mi.ispht, miscale++, &ob->ispht); midecode (mi.xavg, miscale++, &ob->xavg); midecode (mi.yavg, miscale++, &ob->yavg); midecode (mi.xc, miscale++, &ob->xc); midecode (mi.yc, miscale++, &ob->yc); midecode (mi.ra, miscale++, &ob->ra); midecode (mi.dec, miscale++, &ob->dec); midecode (mi.Li, miscale++, &ob->Li); midecode (mi.sLi, miscale++, &ob->sLi); midecode (mi.Lc, miscale++, &ob->Lc); midecode (mi.Lfca, miscale++, &ob->Lfca); midecode (mi.Ltotal, miscale++, &ob->Ltotal); midecode (mi.mag, miscale++, &ob->mag); midecode (mi.icx, miscale++, &ob->icx); midecode (mi.icy, miscale++, &ob->icy); midecode (mi.ixx, miscale++, &ob->ixx); midecode (mi.iyy, miscale++, &ob->iyy); midecode (mi.ixy, miscale++, &ob->ixy); midecode (mi.ir1, miscale++, &ob->ir1); midecode (mi.ir3, miscale++, &ob->ir3); midecode (mi.ir4, miscale++, &ob->ir4); midecode (mi.cx, miscale++, &ob->cx); midecode (mi.cy, miscale++, &ob->cy); midecode (mi.xx, miscale++, &ob->xx); midecode (mi.yy, miscale++, &ob->yy); midecode (mi.xy, miscale++, &ob->xy); midecode (mi.r1, miscale++, &ob->r1); midecode (mi.fitxc, miscale++, &ob->fitxc); midecode (mi.fityc, miscale++, &ob->fityc); midecode (mi.scale, miscale++, &ob->scale); midecode (mi.frac, miscale++, &ob->frac); midecode (mi.prob, miscale++, &ob->prob); } } /* MISZCATHDR -- Return size of machine independent header */ long miszcathdr () { long sz, size; if (cattype == 3) size = sizeof (char); else size = 2 * sizeof (char); size += sizeof (short); size += sizeof (struct misgparm); size += sizeof (ncmmnts); size += ncmmnts * sizeof (char) * COLEN; size += sizeof (struct miflmcv) * sp.nden; if (cattype == 3) sz = sizeof (float) + sizeof (char); else sz = sizeof (float) + 2 * sizeof (char); size += sz * sp.fx * sp.fy; size += sz * sp.nx * sp.ny; sz = sizeof (struct micrule); size += sp.nrules * sz; return (size); } /* MINOBJS -- Return number of machine independent object records */ long minobjs (fd) FILE *fd; { return ((long) (szcat (fd) - miszcathdr ()) / (miszobjrec ())); } /* MISZOBJREC -- Return the size of an object record */ long miszobjrec () { return (sizeof (struct mirec)); } /* MICODE -- Code a floating point number as a long integer and byte scale */ micode (x, i, j) float x; long *i; char *j; { register int k; register float y; if (x > 0.) { if (x < 10.) for (y = x * 1000000., k = 94; y < 1000000.; y *= 10., k--); else if (x < 1000000.) for (y = x, k = 100; y < 1000000.; y *= 10., k--); else for (y = x, k = 100; y >= 10000000.; y /= 10., k++); } else if (x < 0.) { if (x > -10.) for (y = x * 1000000., k = 94; y > -1000000.; y *= 10., k--); else if (x > -1000000.) for (y = x, k = 100; y > -1000000.; y *= 10., k--); else for (y = x, k = 100; y <= -10000000.; y /= 10., k++); } else { y = x; k = 100; } *i = y; *j = k; } /* MIDECODE -- Decode the machine independent floating point number */ midecode (i, j, x) long i; char *j; float *x; { register int k; register float y; if (i == 0) { *x = 0.; return; } y = i * 0.000001; k = *j - 88; if (k < 0) for (; k < 0; k += 6) y *= 0.000001; else if (k > 12) for (; k > 12; k -= 6) y *= 1000000.; *x = y * scales[k]; } /* SWAPS -- Swap bytes in a short word */ swaps (s1, s2) char *s1, *s2; { s2[0] = s1[1]; s2[1] = s1[0]; } /* SWAPL -- Swap bytes in a long word */ swapl (l1, l2) char *l1, *l2; { l2[0] = l1[3]; l2[1] = l1[2]; l2[2] = l1[1]; l2[3] = l1[0]; }