コード例 #1
0
ファイル: merge-index.c プロジェクト: blackball/an-test6
int merge_index_open_files(const char* quadfn, const char* ckdtfn, const char* skdtfn,
						   quadfile** quad, codetree** code, startree_t** star) {
	logmsg("Reading code tree from %s ...\n", ckdtfn);
	*code = codetree_open(ckdtfn);
	if (!*code) {
		ERROR("Failed to read code kdtree from %s", ckdtfn);
		return -1;
	}
    logmsg("Ok.\n");

	logmsg("Reading star tree from %s ...\n", skdtfn);
	*star = startree_open(skdtfn);
	if (!*star) {
		ERROR("Failed to read star kdtree from %s", skdtfn);
		return -1;
	}
    logmsg("Ok.\n");

	logmsg("Reading quads from %s ...\n", quadfn);
	*quad = quadfile_open(quadfn);
	if (!*quad) {
		ERROR("Failed to read quads from %s", quadfn);
		return -1;
	}
    logmsg("Ok.\n");
	return 0;
}
コード例 #2
0
int hpquads_files(const char* skdtfn,
				  const char* codefn,
				  const char* quadfn,
				  int Nside,
				  double scale_min_arcmin,
				  double scale_max_arcmin,
				  int dimquads,
				  int passes,
				  int Nreuses,
				  int Nloosen,
				  int id,
				  anbool scanoccupied,

				  void* sort_data,
				  int (*sort_func)(const void*, const void*),
				  int sort_size,

				  char** args, int argc) {
	quadfile_t* quads;
	codefile_t* codes;
	startree_t* starkd;
	int rtn;

	logmsg("Reading star kdtree %s ...\n", skdtfn);
	starkd = startree_open(skdtfn);
	if (!starkd) {
		ERROR("Failed to open star kdtree %s\n", skdtfn);
		return -1;
	}

	logmsg("Will write to quad file %s and code file %s\n", quadfn, codefn);
    quads = quadfile_open_for_writing(quadfn);
	if (!quads) {
		ERROR("Couldn't open file %s to write quads.\n", quadfn);
		return -1;
	}
    codes = codefile_open_for_writing(codefn);
	if (!codes) {
		ERROR("Couldn't open file %s to write codes.\n", codefn);
		return -1;
	}

	rtn = hpquads(starkd, codes, quads, Nside,
				  scale_min_arcmin, scale_max_arcmin,
				  dimquads, passes, Nreuses, Nloosen, id,
				  scanoccupied, 
				  sort_data, sort_func, sort_size,
				  args, argc);
	if (rtn)
		return rtn;

	if (quadfile_close(quads)) {
		ERROR("Couldn't write quad output file");
		return -1;
	}
	if (codefile_close(codes)) {
		ERROR("Couldn't write code output file");
		return -1;
	}
	startree_close(starkd);

	return rtn;
}
コード例 #3
0
ファイル: startree2rdls.c プロジェクト: Carl4/astrometry.net
int main(int argc, char** args) {
    int argchar;
	char* outfn = NULL;
	char* fn;
    rdlist_t* rdls;
	startree_t* skdt = NULL;
	int i;
	int loglvl = LOG_MSG;

    while ((argchar = getopt (argc, args, OPTIONS)) != -1)
        switch (argchar) {
		case 'v':
			loglvl++;
			break;
		case 'r':
			outfn = optarg;
			break;
		case 'h':
			print_help(args[0]);
			exit(0);
		}

	log_init(loglvl);
	if (!outfn || (optind == argc)) {
		print_help(args[0]);
		exit(-1);
	}

    rdls = rdlist_open_for_writing(outfn);
    if (!rdls) {
        ERROR("Failed to open RDLS file %s for output", outfn);
        exit(-1);
    }
    if (rdlist_write_primary_header(rdls)) {
        ERROR("Failed to write RDLS header");
        exit(-1);
    }

	for (; optind<argc; optind++) {
		int Nstars;
        fn = args[optind];
        logmsg("Opening star kdtree %s...\n", fn);
        skdt = startree_open(fn);
        if (!skdt) {
            ERROR("Failed to read star kdtree %s", fn);
            exit(-1);
        }
        Nstars = startree_N(skdt);

        if (rdlist_write_header(rdls)) {
            ERROR("Failed to write new RDLS field header");
            exit(-1);
        }

		logmsg("Reading stars...\n");
		for (i=0; i<Nstars; i++) {
            double xyz[3];
            double radec[2];
			if (!(i % 200000)) {
				printf(".");
				fflush(stdout);
			}
            startree_get(skdt, i, xyz);
            xyzarr2radecdegarr(xyz, radec);
            if (rdlist_write_one_radec(rdls, radec[0], radec[1])) {
                ERROR("Failed to write a RA,Dec entry");
                exit(-1);
            }
		}
		printf("\n");

        startree_close(skdt);

        if (rdlist_fix_header(rdls)) {
            ERROR("Failed to fix RDLS field header");
            exit(-1);
        }
	}

    if (rdlist_fix_primary_header(rdls) ||
        rdlist_close(rdls)) {
        ERROR("Failed to close RDLS file");
        exit(-1);
    }

	return 0;
}
コード例 #4
0
int unpermute_stars_files(const char* skdtinfn, const char* quadinfn,
						  const char* skdtoutfn, const char* quadoutfn,
						  anbool dosweeps, anbool check,
						  char** args, int argc) {
    quadfile_t* qfin;
	quadfile_t* qfout;
	startree_t* treein;
	startree_t* treeout;
	fitstable_t* tagout = NULL;
	fitstable_t* tagin;
	int rtn;

	logmsg("Reading star tree from %s ...\n", skdtinfn);
	treein = startree_open(skdtinfn);
	if (!treein) {
		ERROR("Failed to read star kdtree from %s.\n", skdtinfn);
		return -1;
	}

	logmsg("Reading quadfile from %s ...\n", quadinfn);
	qfin = quadfile_open(quadinfn);
	if (!qfin) {
		ERROR("Failed to read quadfile from %s.\n", quadinfn);
		return -1;
	}

	logmsg("Writing quadfile to %s ...\n", quadoutfn);
	qfout = quadfile_open_for_writing(quadoutfn);
	if (!qfout) {
		ERROR("Failed to write quadfile to %s.\n", quadoutfn);
		return -1;
	}

	rtn = unpermute_stars(treein, qfin, &treeout, qfout,
						  dosweeps, check, args, argc);
	if (rtn)
		return rtn;

	if (quadfile_close(qfout)) {
		ERROR("Failed to close output quadfile.\n");
		return -1;
	}

	logmsg("Writing star kdtree to %s ...\n", skdtoutfn);
	if (startree_write_to_file(treeout, skdtoutfn)) {
		ERROR("Failed to write star kdtree.\n");
		return -1;
	}

	if (startree_has_tagalong(treein)) {
		logmsg("Permuting tag-along table...\n");
		tagin = startree_get_tagalong(treein);
		if (tagin) {
			tagout = fitstable_open_for_appending(skdtoutfn);
			tagout->table = fits_copy_table(tagin->table);
			tagout->table->nr = 0;
			if (unpermute_stars_tagalong(treein, tagout)) {
				ERROR("Failed to permute tag-along table");
				return -1;
			}
			if (fitstable_close(tagout)) {
				ERROR("Failed to close tag-along data");
				return -1;
			}
		}
	}

	quadfile_close(qfin);
	startree_close(treein);
	free(treeout->sweep);
    free(treeout->tree);
    treeout->tree = NULL;
	startree_close(treeout);

	return 0;
}
コード例 #5
0
ファイル: allquads.c プロジェクト: ecarrillo85/astrometry.net
int allquads_open_outputs(allquads_t* aq) {
	int hp, hpnside;
	qfits_header* hdr;

	printf("Reading star kdtree %s ...\n", aq->skdtfn);
	aq->starkd = startree_open(aq->skdtfn);
	if (!aq->starkd) {
		ERROR("Failed to open star kdtree %s\n", aq->skdtfn);
		return -1;
	}
	printf("Star tree contains %i objects.\n", startree_N(aq->starkd));

	printf("Will write to quad file %s and code file %s\n", aq->quadfn, aq->codefn);
    aq->quads = quadfile_open_for_writing(aq->quadfn);
	if (!aq->quads) {
		ERROR("Couldn't open file %s to write quads.\n", aq->quadfn);
		return -1;
	}
    aq->codes = codefile_open_for_writing(aq->codefn);
	if (!aq->codes) {
		ERROR("Couldn't open file %s to write codes.\n", aq->quadfn);
		return -1;
	}

	aq->quads->dimquads = aq->dimquads;
	aq->codes->dimcodes = aq->dimcodes;

	if (aq->id) {
		aq->quads->indexid = aq->id;
		aq->codes->indexid = aq->id;
	}

	// get the "HEALPIX" header from the skdt and put it in the code and quad headers.
	hp = qfits_header_getint(startree_header(aq->starkd), "HEALPIX", -1);
	if (hp == -1) {
		logmsg("Warning: skdt does not contain \"HEALPIX\" header.  Code and quad files will not contain this header either.\n");
	}
	aq->quads->healpix = hp;
	aq->codes->healpix = hp;
    // likewise "HPNSIDE"
	hpnside = qfits_header_getint(startree_header(aq->starkd), "HPNSIDE", 1);
	aq->quads->hpnside = hpnside;
	aq->codes->hpnside = hpnside;

	hdr = quadfile_get_header(aq->quads);
	qfits_header_add(hdr, "CXDX", "T", "All codes have the property cx<=dx.", NULL);
	qfits_header_add(hdr, "CXDXLT1", "T", "All codes have the property cx+dx<=1.", NULL);
	qfits_header_add(hdr, "MIDHALF", "T", "All codes have the property cx+dx<=1.", NULL);
	qfits_header_add(hdr, "CIRCLE", "T", "Codes live in the circle, not the box.", NULL);

	hdr = codefile_get_header(aq->codes);
	qfits_header_add(hdr, "CXDX", "T", "All codes have the property cx<=dx.", NULL);
	qfits_header_add(hdr, "CXDXLT1", "T", "All codes have the property cx+dx<=1.", NULL);
	qfits_header_add(hdr, "MIDHALF", "T", "All codes have the property cx+dx<=1.", NULL);
	qfits_header_add(hdr, "CIRCLE", "T", "Codes live in the circle, not the box.", NULL);

    if (quadfile_write_header(aq->quads)) {
        ERROR("Couldn't write headers to quads file %s\n", aq->quadfn);
		return -1;
    }
    if (codefile_write_header(aq->codes)) {
        ERROR("Couldn't write headers to code file %s\n", aq->codefn);
		return -1;
    }

	if (!aq->use_d2_lower)
		aq->quad_d2_lower = 0.0;
	if (!aq->use_d2_upper)
		aq->quad_d2_upper = 10.0;

    aq->codes->numstars = startree_N(aq->starkd);
    aq->codes->index_scale_upper = distsq2rad(aq->quad_d2_upper);
    aq->codes->index_scale_lower = distsq2rad(aq->quad_d2_lower);

	aq->quads->numstars = aq->codes->numstars;
    aq->quads->index_scale_upper = aq->codes->index_scale_upper;
    aq->quads->index_scale_lower = aq->codes->index_scale_lower;
	return 0;
}
コード例 #6
0
ファイル: query-starkd.c プロジェクト: blackball/an-test6
int main(int argc, char **argv) {
    int argchar;
	startree_t* starkd;
	double ra=0.0, dec=0.0, radius=0.0;
	sl* tag = sl_new(4);
	anbool tagall = FALSE;
	char* starfn = NULL;
	int loglvl = LOG_MSG;
	char** myargs;
	int nmyargs;
	anbool getinds = FALSE;
	double* radec;
	int* inds;
	int N;
	int i;
	char* rdfn = NULL;
	pl* tagdata = pl_new(16);
	il* tagsizes = il_new(16);
	fitstable_t* tagalong = NULL;

    while ((argchar = getopt (argc, argv, OPTIONS)) != -1)
        switch (argchar) {
		case 'o':
			rdfn = optarg;
			break;
		case 'I':
			getinds = TRUE;
			break;
		case 'r':
			ra = atof(optarg);
			break;
		case 'd':
			dec = atof(optarg);
			break;
		case 'R':
			radius = atof(optarg);
			break;
		case 't':
			sl_append(tag, optarg);
			break;
		case 'T':
			tagall = TRUE;
			break;
		case 'v':
			loglvl++;
			break;
        case '?':
            fprintf(stderr, "Unknown option `-%c'.\n", optopt);
		case 'h':
			printHelp(argv[0]);
			break;
		default:
			return -1;
		}

	nmyargs = argc - optind;
	myargs = argv + optind;

	if (nmyargs != 1) {
		ERROR("Got %i arguments; expected 1.\n", nmyargs);
		printHelp(argv[0]);
		exit(-1);
	}
	starfn = myargs[0];

	log_init(loglvl);

	starkd = startree_open(starfn);
	if (!starkd) {
		ERROR("Failed to open star kdtree");
		exit(-1);
	}

	logmsg("Searching kdtree %s at RA,Dec = (%g,%g), radius %g deg.\n",
		   starfn, ra, dec, radius);

	startree_search_for_radec(starkd, ra, dec, radius,
							  NULL, &radec, &inds, &N);

	logmsg("Got %i results.\n", N);

	if (!N)
		goto done;

	if (tagall) {
		int j, M;
		M = startree_get_tagalong_N_columns(starkd); 
		for (j=0; j<M; j++)
			sl_append(tag, startree_get_tagalong_column_name(starkd, j));
	}

	if (sl_size(tag)) {
		tagalong = startree_get_tagalong(starkd);
		if (!tagalong) {
			ERROR("Failed to find tag-along table in index");
			exit(-1);
		}
	}

	if (rdfn) {
		rdlist_t* rd = rdlist_open_for_writing(rdfn);
		il* colnums = il_new(16);

		if (!rd) {
			ERROR("Failed to open output file %s", rdfn);
			exit(-1);
		}
		if (rdlist_write_primary_header(rd)) {
			ERROR("Failed to write header to output file %s", rdfn);
			exit(-1);
		}

		for (i=0; i<sl_size(tag); i++) {
			const char* col = sl_get(tag, i);
			char* units;
			tfits_type type;
			int arraysize;
			void* data;
			int colnum;
			int itemsize;

			if (fitstable_find_fits_column(tagalong, col, &units, &type, &arraysize)) {
				ERROR("Failed to find column \"%s\" in index", col);
				exit(-1);
			}
			itemsize = fits_get_atom_size(type) * arraysize;
			data = fitstable_read_column_array_inds(tagalong, col, type, inds, N, NULL);
			if (!data) {
				ERROR("Failed to read data for column \"%s\" in index", col);
				exit(-1);
			}
			colnum = rdlist_add_tagalong_column(rd, type, arraysize, type, col, NULL);

			il_append(colnums, colnum);
			il_append(tagsizes, itemsize);
			pl_append(tagdata, data);
		}
		if (rdlist_write_header(rd)) {
			ERROR("Failed to write header to output file %s", rdfn);
			exit(-1);
		}

		for (i=0; i<N; i++) {
			if (rdlist_write_one_radec(rd, radec[i*2+0], radec[i*2+1])) {
				ERROR("Failed to write RA,Dec to output file %s", rdfn);
				exit(-1);
			}
		}
		for (i=0; i<sl_size(tag); i++) {
			int col = il_get(colnums, i);
			void* data = pl_get(tagdata, i);
			int itemsize = il_get(tagsizes, i);

			if (rdlist_write_tagalong_column(rd, col, 0, N, data, itemsize)) {
				ERROR("Failed to write tag-along data column %s", sl_get(tag, i));
				exit(-1);
			}
		}
		if (rdlist_fix_header(rd) ||
			rdlist_fix_primary_header(rd) ||
			rdlist_close(rd)) {
			ERROR("Failed to close output file %s", rdfn);
			exit(-1);
		}
		il_free(colnums);

	} else {
		// Header
		printf("# RA, Dec");
		if (getinds)
			printf(", index");
		for (i=0; i<sl_size(tag); i++)
			printf(", %s", sl_get(tag, i));
		printf("\n");

		for (i=0; i<sl_size(tag); i++) {
			const char* col = sl_get(tag, i);
			char* units;
			tfits_type type;
			int arraysize;
			void* data;
			int itemsize;

			if (fitstable_find_fits_column(tagalong, col, &units, &type, &arraysize)) {
				ERROR("Failed to find column \"%s\" in index", col);
				exit(-1);
			}
			itemsize = fits_get_atom_size(type) * arraysize;
			data = fitstable_read_column_array_inds(tagalong, col, type, inds, N, NULL);
			if (!data) {
				ERROR("Failed to read data for column \"%s\" in index", col);
				exit(-1);
			}
			il_append(tagsizes, itemsize);
			pl_append(tagdata, data);
		}

		for (i=0; i<N; i++) {
			//int j;
			printf("%g, %g", radec[i*2+0], radec[i*2+1]);
			if (getinds)
				printf(", %i", inds[i]);

			//// FIXME -- print tag-along data of generic type.
			/*
			 for (j=0; j<pl_size(tagdata); j++) {
			 double* data = pl_get(tagdata, j);
			 printf(", %g", data[i]);
			 }
			 */

			printf("\n");
		}
	}

 done:
	free(radec);
	free(inds);
	for (i=0; i<pl_size(tagdata); i++)
		free(pl_get(tagdata, i));
	pl_free(tagdata);
	il_free(tagsizes);

	return 0;
}