/*++++++++++++++ .IDENTIFICATION nomad22.c .LANGUAGE C .AUTHOR Francois Ochsenbein [CDS] .ENVIRONMENT NOMAD-1.0 Catalogue .KEYWORDS CDS Catalogue Server .VERSION 1.0 09-Nov-2005: Read one of the 22-int file .COMMENTS List one of the files containing the > 1,000,000,000 stars. ---------------*/ #include #include /* Malloc */ #include #include #include /* O_BINARY */ #include #include #define ITEMS(s) sizeof(s)/sizeof(s[0]) #ifndef O_BINARY /* Required for MS-DOS */ #define O_BINARY 0 #endif #include static char verbop = 0; /* Verbose Option */ static int swapping ; /* Set to 1 or 2 (swap) */ static char usage[] = "\ Usage: nomad22 [-o binfile] input_file\n\ "; static char help[] = "\ -o: write a binary copy\n\ input: a \"mXXXX.cat\" original file\n\ "; #if 0 /* Histogrammes */ static int hepo[1000]; /* Epoch Values */ static int hpos[1000]; /* Sigmas Position */ static int hpm[10000]; /* Proper Motions */ static int hspm[1000]; /* Sigmas */ static int xmag[32]; /* Existence */ static int hgal[20]; /* star/gal */ static int hgal15[6]; /* star/gal>11 */ static char *hgal15tit[6] = { "blu#1", "red#1", "blu#2", "red#2", "ir(N)" }; static int hclass[10000]; /* Star/gal class function of Survey */ static int hmag[10000]; /* Magnitudes */ static int hfld[1000]; /* Field */ static int hxie[10000]; /* xi-eta */ #endif /*================================================================== Internal Utilities *==================================================================*/ static void swap1 (array, nshort) /*++++++++++++++++ .PURPOSE Swap the bytes in the array of shorts if necessary .RETURNS 0/1/2 (type of swap) .REMARKS Useful for big-endian machines -----------------*/ short *array ; /* IN: The array to convert */ int nshort ; /* IN: The number of integers */ { register int m, n ; register short *p, *e ; for (p=array, e=p+nshort; p>8) & 0xff ; m |= (n<<8) ; *p = m ; } } static void swap (array, nint) /*++++++++++++++++ .PURPOSE Swap the bytes in the array of integers if necessary .RETURNS 0/1/2 (type of swap) .REMARKS Useful for big-endian machines -----------------*/ int *array ; /* IN: The array to convert */ int nint ; /* IN: The number of integers */ { char *p, *e ; int n ; p = (char *)array ; e = p + 4*nint ; if (swapping == 1) swap1((short *)array, 2*nint) ; else if (swapping == 2) while (p < e) { n = p[0] ; p[0] = p[3] ; p[3] = n ; n = p[1] ; p[1] = p[2] ; p[2] = n ; p += 4 ; } } #if 0 /*================================================================== Histogram Summary *==================================================================*/ static void show_histo(char *title, int *freq, int size) /*++++++++++++++++ .PURPOSE Histogram Summary .RETURNS --- .REMARKS -----------------*/ { int *p, *e, *bounds[2], *bound1[2]; long val1[2], tot = 0; int bins = 0; e = freq + size; /* Compute the Total */ for(p=freq; p=freq) && (*e == 0); e--) ; bounds[1] = e; fprintf(stderr, " Range %5d'%-5d", bounds[0]-freq, bounds[1]-bounds[0]); /* Find the 1%-99% Range */ bound1[0] = bounds[0]; val1[0] = tot/100; /* 1% */ bound1[1] = bounds[1]; val1[1] = tot - val1[0]; /* 99% */ for (p=bounds[0], tot=0, bins=0; pval1[1]) break; bound1[1] = p; } while (pflags = USNOB_TYC; /* Zero the errors */ prec->e_ra = prec->e_sd = 0; prec->epoch = 20000; prec->fit_ra = prec->fit_sd = 0; prec->e_pmra = prec->e_pmsd = 0; /* Tycho Number */ val = rec[3]; if (val == 21) prec->flags |= USNOB_TS1; else if (val == 22) prec->flags |= USNOB_TS2; prec->fileno = rec[3]; prec->recno = rec[4]; val = rec[10]; prec->TYC1 = val; val = rec[11]; prec->TYC3 = val%10; val /= 10; prec->TYC2 = val; return(0); } #endif int nomad1_ori(long *rec, NOMADrec *prec) /*++++++++++++++++ .PURPOSE Interpret the original NOMADcatalog .RETURNS 0 (OK) .REMARKS We assume that "zone" and "id" are already filled. Histograms computed. -----------------*/ { long word; int i, m, x, val; /* Install RA, SD ... */ prec->flags = rec[21]>>12; prec->ra = rec[0]; prec->sd = rec[1]; prec->e_ra = rec[2]; prec->e_sd = rec[3]; prec->pmra = rec[4]; prec->pmsd = rec[5]; prec->e_pmra = rec[6]; prec->e_pmsd = rec[7]; prec->epra = (rec[8]+50)/100; prec->epsd = (rec[9]+50)/100; for (i=0; i<6; i++) prec->mag[i] = rec[10+i]; if (rec[17]) prec->flags |= NOMAD_2MASS; if (rec[18]) prec->flags |= NOMAD_YB6; return(0); } /*================================================================== Main Program *==================================================================*/ main (argc, argv) int argc; char **argv; { long in[22], counts[10]; NOMADrec rec; FILE *f, *of ; char *p, *oname ; int i; of = (FILE *)0; oname = (char *)0; while (argc > 2) { p = *++argv; --argc; if (*p != '-') break; if (p[1] != 'o') break; p = *++argv; argc--; of = fopen(p, "w"); if (!of) perror(p); oname = p; } if (argc != 2) { fprintf(stderr, "%s%s", usage, help) ; exit(1) ; } /* Verify the Swapping ! */ { static int value ; char *v ; value = 0x010203 ; v = (char *)(&value) ; if ((v[0] == 0) && (v[1] == 1) && (v[2] == 2)) swapping = 0 ; /* No swap necessary */ else if ((v[0] == 1) && (v[1] == 0) && (v[2] == 3)) swapping = 1 ; /* Half-word swap */ else if ((v[0] == 3) && (v[1] == 2) && (v[2] == 1)) swapping = 2 ; /* Full-word swap */ else { fprintf(stderr, "****Irrationnal Byte Swap %02x%02x%02X%02x\n", v[0]&0xff, v[1]&0xff, v[2]&0xff, v[3]&0xff) ; exit(2) ; } } swapping ^= 2; /* ASSUME THIS TYPE OF SWAPPING */ fprintf(stderr, "#...swapping type=%d\n", swapping) ; memset(&rec, 0, sizeof(rec)) ; while (--argc > 0) { fprintf(stderr, "----Dealing with file: %s", *++argv) ; if (!(f = fopen(*argv, "rb"))) { perror(*argv) ; exit(1) ; } fflush(stderr) ; /* Get the Zone Number (from file xxxx.cat) */ p = *argv; p += strlen(p) -8 ; rec.zone = atoi(p); #if 0 /* Zero all histogram values */ memset(counts, 0, sizeof(counts)); memset(hepo, 0, sizeof(hepo)); /* Epoch Values */ memset(hpos, 0, sizeof(hpos)); /* Sigmas Position */ memset(hpm, 0, sizeof(hpm)); /* Proper Motions */ memset(hspm, 0, sizeof(hspm)); /* Sigmas */ memset(xmag, 0, sizeof(xmag)); /* Existence */ memset(hgal, 0, sizeof(hgal)); /* star/gal */ memset(hgal15, 0, sizeof(hgal15)); /* star/gal */ memset(hmag, 0, sizeof(hmag)); /* Magnitudes */ memset(hfld, 0, sizeof(hfld)); /* Field */ memset(hxie, 0, sizeof(hxie)); /* xi-eta */ #endif for (rec.id=0; fread(in, sizeof(long), ITEMS(in), f) > 0 ; ) { rec.id++ ; swap(in, ITEMS(in)); nomad1_ori(in, &rec); if(of) fwrite(&rec, sizeof(rec), 1, of); /* counts[rec.ndet] += 1; */ } fprintf(stderr, " => %d objects.\n", rec.id); close(f) ; /* Existence of Magnitudes */ fprintf(stderr, " ndet:"); for (i=0; i<=5; i++) fprintf(stderr, " %d=%-7d", i, counts[i]); fprintf(stderr, "\n"); #if 0 show_histo(" ErrPos:", hpos, ITEMS(hpos)); show_histo(" Epoch:", hepo, ITEMS(hepo)); show_histo(" pm:", hpm, ITEMS(hpm)); show_histo(" spm:", hspm, ITEMS(hspm)); show_histo(" Field:", hmag, ITEMS(hfld)); show_histo(" mag:", hmag, ITEMS(hmag)); show_histo(" xi-eta:", hxie, ITEMS(hxie)); show_histo("stargal:", hgal, ITEMS(hgal)); /* star/gal */ for (i=0; i11:") ; for (i=0; i11:") ; for (i=0; i