コード例 #1
0
int main(int ac, char** av)
{
  if (strcmp(av[1], "index") == 0)
  {
    do_index("../pic/india/trekearth.new/trekearth");
  }
  else if (strcmp(av[1], "tile") == 0)
  {
    struct mozaic_info mi;
    struct index_info ii;

    mi.tile_im = NULL;

    index_load(&ii, "../pic/india/trekearth.new/trekearth");
    /* index_load(&ii, "../pic/kiosked"); */

    /* do_tile("../pic/roland_15/main.jpg", &ii, &mi); */
    do_tile("../pic/roland_14/main_gimped.jpg", &ii, &mi);
    /* do_tile("../pic/face_1/main.jpg", &ii, &mi); */
    do_make(&ii, &mi);
    do_edit(&ii, &mi);

    cvSaveImage("/tmp/tile.jpg", mi.tile_im, NULL);
    do_save_mozaic(&mi, "/tmp/mozaic.til");

    cvReleaseImage(&mi.tile_im);
    cvReleaseImage(&mi.ycc_im);

    free(mi.tile_arr);
    index_free(&ii);
  }

  return 0;
}
コード例 #2
0
ファイル: trecrun.c プロジェクト: eckucukoglu/zettair
/* internal function to load an index from a parameters file */
static struct index *load_index(const char *prefix, unsigned int memory,
  int lopts, struct index_load_opt * lopt) {
    char filename[FILENAME_MAX + 1];
    struct index *idx;

    if ((idx = index_load((const char *) prefix, memory, lopts, lopt)) 
      || ((snprintf((char *) filename, FILENAME_MAX, "%s.%s", prefix, 
          INDSUF))
        && (idx = index_load((const char *) filename, memory, INDEX_LOAD_NOOPT, 
            NULL)))) {

        return idx;
    } else {
        return NULL;
    }
}
コード例 #3
0
int plot_index_add_file(plotindex_t* args, const char* fn) {
	index_t* index = index_load(fn, 0, NULL);
	if (!index) {
		ERROR("Failed to open index \"%s\"", fn);
		return -1;
	}
	pl_append(args->indexes, index);
	return 0;
}
コード例 #4
0
ファイル: relation.c プロジェクト: 1uk3/contiki
attribute_t *
relation_attribute_add(relation_t *rel, db_direction_t dir, char *name,
		       domain_t domain, size_t element_size)
{
  attribute_t *attribute;
  tuple_id_t cardinality;

  cardinality = relation_cardinality(rel);
  if(cardinality != INVALID_TUPLE && cardinality > 0) {
    PRINTF("DB: Attempt to create an attribute in a non-empty relation\n");
    return NULL;
  }

  if(element_size == 0 || element_size > DB_MAX_ELEMENT_SIZE) {
    PRINTF("DB: Unacceptable element size: %u\n", element_size);
    return NULL;
  }

  attribute = memb_alloc(&attributes_memb);
  if(attribute == NULL) {
    PRINTF("DB: Failed to allocate attribute \"%s\"!\n", name);
    return NULL;
  }

  strncpy(attribute->name, name, sizeof(attribute->name) - 1);
  attribute->name[sizeof(attribute->name) - 1] = '\0';
  attribute->domain = domain;
  attribute->element_size = element_size;
  attribute->aggregator = 0;
  attribute->index = NULL;
  attribute->flags = 0 /*ATTRIBUTE_FLAG_UNIQUE*/;

  rel->row_length += element_size;

  list_add(rel->attributes, attribute);
  rel->attribute_count++;

  if(dir == DB_STORAGE) {
    if(DB_ERROR(storage_put_attribute(rel, attribute))) {
       PRINTF("DB: Failed to store attribute %s\n", attribute->name);
       memb_free(&attributes_memb, attribute);
       return NULL;
    }
  } else {
    index_load(rel, attribute);
  }

  return attribute;
}
コード例 #5
0
ファイル: hfile.c プロジェクト: pipul/lab
hfile_t *hfile_load(const int8_t *filename)
{
	int32_t fd;
	hfile_t *fp;
	meta_t *o;
	htail_t *ht;
	hinfo_t *hi;
	
	if (!filename)
		return(NULL);
	if ((fp = hfile_new()) == NULL)
		return(NULL);
	memcpy(fp->name,filename,strlen(filename));
	if ((fd = open(fp->name,O_RDONLY)) < 0)
		__ERROR_LOG(H_ERROR);

	fp->trailer = htail_load(fd,-sizeof(htail_t),sizeof(htail_t));
	if (fp->trailer == NULL)
		__ERROR_LOG(H_ERROR);
	else
		ht = fp->trailer;

	fp->fileinfo = hinfo_load(fd,ht->infooffset,ht->infosize);
	if (fp->fileinfo == NULL)
		__ERROR_LOG(H_ERROR);
	else
		hi = fp->fileinfo;

	fp->metas = index_load(fd,ht->indexoffset,ht->indexsize);
	if (fp->metas == NULL)
		__ERROR_LOG(H_ERROR);
	
	fp->bloom = bloom_load(fd,ht->bloomoffset,ht->bloomsize);
	if (fp->bloom == NULL)
		__ERROR_LOG(H_ERROR);

	fp->blocks = malloc(hi->blockcount*sizeof(block_t *));
	if (fp->blocks == NULL)
		__ERROR_LOG(H_ERROR);
	memset(fp->blocks,0,hi->blockcount*sizeof(block_t *));

	close(fd);
	return(fp);

H_ERROR:
	close(fd);
	hfile_destroy(fp);
	return(NULL);
}
コード例 #6
0
ファイル: search-index.c プロジェクト: NGTS/astrometry.net
int main(int argc, char **argv) {
    int argchar;
	double ra=HUGE_VAL, dec=HUGE_VAL, radius=HUGE_VAL;
	int loglvl = LOG_MSG;
	char** myargs;
	int nmyargs;
	int i;
	char* outfn = NULL;
	fitstable_t* table = NULL;

    while ((argchar = getopt (argc, argv, OPTIONS)) != -1)
        switch (argchar) {
		case 'o':
			outfn = optarg;
			break;
		case 'r':
			ra = atof(optarg);
			break;
		case 'd':
			dec = atof(optarg);
			break;
		case 'R':
			radius = atof(optarg);
			break;
		case 'v':
			loglvl++;
			break;
        case '?':
            fprintf(stderr, "Unknown option `-%c'.\n", optopt);
		case 'h':
		default:
			printHelp(argv[0]);
			return -1;
		}
	log_init(loglvl);
	nmyargs = argc - optind;
	myargs = argv + optind;

	if (nmyargs < 1) {
		printHelp(argv[0]);
		exit(-1);
	}
	if (ra == HUGE_VAL || dec == HUGE_VAL || radius == HUGE_VAL) {
		printHelp(argv[0]);
		exit(-1);
	}

	if (outfn) {
		table = fitstable_open_for_writing(outfn);
		if (!table) {
			ERROR("Failed to open output table");
			exit(-1);
		}
		if (fitstable_write_primary_header(table)) {
			ERROR("Failed to write primary header of output table");
			exit(-1);
		}
	}

	for (i=0; i<nmyargs; i++) {
		char* indexfn = myargs[i];
		index_t index;
		sl* cols;
		int* inds;
		double* radecs;
		int N;
		int j;
		fitstable_t* tagtable = NULL;

		logmsg("Reading index \"%s\"...\n", indexfn);
		if (!index_load(indexfn, 0, &index)) {
			ERROR("Failed to read index \"%s\"", indexfn);
			continue;
		}

		logmsg("Index %s: id %i, healpix %i (nside %i), %i stars, %i quads, dimquads=%i, scales %g to %g arcmin.\n",
			   index.indexname, index.indexid, index.healpix, index.hpnside,
			   index.nstars, index.nquads, index.dimquads,
			   arcsec2arcmin(index.index_scale_lower),
			   arcsec2arcmin(index.index_scale_upper));

		cols = startree_get_tagalong_column_names(index.starkd, NULL);
		{
			char* colstr = sl_join(cols, ", ");
			logmsg("Tag-along columns: %s\n", colstr);
			free(colstr);
		}

		logmsg("Searching for stars around RA,Dec (%g, %g), radius %g deg.\n",
			   ra, dec, radius);
		startree_search_for_radec(index.starkd, ra, dec, radius,
								  NULL, &radecs, &inds, &N);
		logmsg("Found %i stars\n", N);

		if (table) {
			int tagsize;
			int rowsize;
			char* rowbuf = NULL;

			if (i > 0) {
				fitstable_next_extension(table);
				fitstable_clear_table(table);
			}

			tagtable = startree_get_tagalong(index.starkd);
			if (tagtable) {
				fitstable_add_fits_columns_as_struct(tagtable);
				logverb("Input tag-along table:\n");
				if (log_get_level() >= LOG_VERB)
					fitstable_print_columns(tagtable);
				fitstable_copy_columns(tagtable, table);
			}
			tagsize = fitstable_get_struct_size(table);
			debug("tagsize=%i\n", tagsize);
			// Add RA,Dec at the end of the row...
			fitstable_add_write_column_struct(table, fitscolumn_double_type(), 1, tagsize, fitscolumn_double_type(), "RA", "degrees");
			fitstable_add_write_column_struct(table, fitscolumn_double_type(), 1, tagsize + sizeof(double), fitscolumn_double_type(), "DEC", "degrees");
			rowsize = fitstable_get_struct_size(table);
			assert(rowsize == tagsize + 2*sizeof(double));
			debug("rowsize=%i\n", rowsize);
			rowbuf = malloc(rowsize);

			logverb("Output table:\n");
			if (log_get_level() >= LOG_VERB)
				fitstable_print_columns(table);

			if (fitstable_write_header(table)) {
				ERROR("Failed to write header of output table");
				exit(-1);
			}

			for (j=0; j<N; j++) {
				if (tagtable) {
					if (fitstable_read_struct(tagtable, inds[j], rowbuf)) {
						ERROR("Failed to read row %i of tag-along table", inds[j]);
						exit(-1);
					}
				}
				// Add RA,Dec to end of struct...
				memcpy(rowbuf + tagsize, radecs+2*j+0, sizeof(double));
				memcpy(rowbuf + tagsize + sizeof(double), radecs+2*j+1, sizeof(double));
				if (fitstable_write_struct(table, rowbuf)) {
					ERROR("Failed to write row %i of output", j);
					exit(-1);
				}
			}
			free(rowbuf);

			if (fitstable_fix_header(table)) {
				ERROR("Failed to fix header of output table");
				exit(-1);
			}

		}

		sl_free2(cols);
		free(radecs);
		free(inds);

		index_close(&index);
	}

	if (table) {
		if (fitstable_close(table)) {
			ERROR("Failed to close output table");
			exit(-1);
		}
	}

	return 0;
}
コード例 #7
0
int main(int argc, char** args) {
    int argchar;
	char* basename;
	char* outfn = NULL;
	index_t* index;
	quadfile* qf;
    rdlist_t* rdls;
	startree_t* skdt = NULL;
    anbool addradius = FALSE;
	int i;
    int radcolumn = -1;

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

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

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

    if (addradius) {
        radcolumn = rdlist_add_tagalong_column(rdls, fitscolumn_double_type(),
                                               1, fitscolumn_double_type(),
                                               "QUADRADIUS", "deg");
    }

	for (; optind<argc; optind++) {
		//int Nstars;
        int dimquads;

		basename = args[optind];
		printf("Reading files with basename %s\n", basename);

		index = index_load(basename, 0, NULL);
		if (!index) {
			fprintf(stderr, "Failed to read index with base name \"%s\"\n", basename);
			exit(-1);
		}

		qf = index->quads;
        skdt = index->starkd;
        //Nstars = startree_N(skdt);
        
        if (rdlist_write_header(rdls)) {
            fprintf(stderr, "Failed to write new RDLS field header.\n");
            exit(-1);
        }

        dimquads = quadfile_dimquads(qf);

		printf("Reading quads...\n");
		for (i=0; i<qf->numquads; i++) {
			unsigned int stars[dimquads];
            double axyz[3], bxyz[3];
            double midab[3];
            double radec[2];
			if (!(i % 200000)) {
				printf(".");
				fflush(stdout);
			}
			quadfile_get_stars(qf, i, stars);
            startree_get(skdt, stars[0], axyz);
            startree_get(skdt, stars[1], bxyz);
            star_midpoint(midab, axyz, bxyz);
            xyzarr2radecdegarr(midab, radec);

            if (rdlist_write_one_radec(rdls, radec[0], radec[1])) {
                fprintf(stderr, "Failed to write a RA,Dec entry.\n");
                exit(-1);
            }

            if (addradius) {
                double rad = arcsec2deg(distsq2arcsec(distsq(midab, axyz, 3)));
                if (rdlist_write_tagalong_column(rdls, radcolumn, i, 1, &rad, 0)) {
                    fprintf(stderr, "Failed to write quad radius.\n");
                    exit(-1);
                }
            }
		}
		printf("\n");

		index_close(index);

        if (rdlist_fix_header(rdls)) {
            fprintf(stderr, "Failed to fix RDLS field header.\n");
            exit(-1);
        }

		rdlist_next_field(rdls);
	}

    if (rdlist_fix_primary_header(rdls) ||
        rdlist_close(rdls)) {
        fprintf(stderr, "Failed to close RDLS file.\n");
        exit(-1);
    }

	return 0;
}
コード例 #8
0
ファイル: index-to-table.c プロジェクト: blackball/an-test6
int main(int argc, char *argv[]) {
    int argchar;
	char* progname = argv[0];
    index_t* index;
    fitstable_t* table;
	char* indexfn = NULL;
	char* outfn = NULL;
	int i, D, N;

    while ((argchar = getopt (argc, argv, OPTIONS)) != -1) {
		switch (argchar) {
		case 'i':
			indexfn = optarg;
			break;
		case 'o':
			outfn = optarg;
			break;
		default:
		case 'h':
			printHelp(progname);
			exit(0);
		}
	}

	if (!(indexfn && outfn)) {
		printHelp(progname);
		exit(-1);
	}

    index = index_load(indexfn, 0, NULL);
    if (!index) {
        ERROR("Failed to open index");
        exit(-1);
    }

    table = fitstable_open_for_writing(outfn);
    if (!table) {
        ERROR("Failed to open output file for writing");
        exit(-1);
    }
    D = index_get_quad_dim(index);
    fitstable_add_write_column_array(table, fitscolumn_i32_type(), D,
                                     "quads", "");
    if (fitstable_write_primary_header(table) ||
        fitstable_write_header(table)) {
        ERROR("Failed to write headers");
        exit(-1);
    }

    N = index_nquads(index);
    for (i=0; i<N; i++) {
        unsigned int quad[D];
        quadfile_get_stars(index->quads, i, quad);
        if (fitstable_write_row(table, quad)) {
            ERROR("Failed to write quad %i", i);
            exit(-1);
        }
    }

    if (fitstable_fix_header(table)) {
        ERROR("Failed to fix quad header");
        exit(-1);
    }

    fitstable_next_extension(table);
    fitstable_clear_table(table);

    // write star RA,Dec s.
    fitstable_add_write_column(table, fitscolumn_double_type(), "RA", "deg");
    fitstable_add_write_column(table, fitscolumn_double_type(), "Dec", "deg");

    if (fitstable_write_header(table)) {
        ERROR("Failed to write star header");
        exit(-1);
    }

    N = index_nstars(index);
    for (i=0; i<N; i++) {
        double xyz[3];
        double ra, dec;
        startree_get(index->starkd, i, xyz);
        xyzarr2radecdeg(xyz, &ra, &dec);
        if (fitstable_write_row(table, &ra, &dec)) {
            ERROR("Failed to write star %i", i);
            exit(-1);
        }
    }

    if (fitstable_fix_header(table) ||
        fitstable_close(table)) {
        ERROR("Failed to fix star header and close");
        exit(-1);
    }
    

    index_close(index);

	return 0;
}