示例#1
0
文件: main.c 项目: ICRAR/gridding
int
main(int argc, char** argv)
{
    eid_t e5_file_id;
    estatus_t status;
    
    e5_grid_dataset grid = { 0 };
 
    
    /* Parse the command line options
     */
    options_t options = {0};
    ParseOptions(&options, argc, argv);

    /* Open the E5 file and main group
     */
    if(options.verbose)
        e5_set_notify_func(E5_DEFAULT, notify_func, E5_NOTIFY_LEVEL_MIN, E5_NOTIFY_LEVEL_MAX);
    else
        e5_set_notify_func(E5_DEFAULT, notify_func, E5_NOTIFY_LEVEL_ERROR, E5_NOTIFY_LEVEL_ERROR);
        
    e5_file_id = e5_open_file(options.e5_filename);
    
    /* Read the grid dimensionality and type info
     */
    grid.name = options.location;
    status = e5_read_data_info(e5_file_id, grid.name, grid.dim, &grid.type, &grid.scale);
    E5_EXIT_ON_ERROR(status);
    
    /* Allocate memory and read the grid data
     */
    grid.data = malloc(e5_sizeof(grid.type) * grid.dim[0] * grid.dim[1] * grid.dim[2]);
    status = e5_read_grid(e5_file_id, grid.name, grid.data, grid.dim, &grid.type, &grid.scale);
    E5_EXIT_ON_ERROR(status);

    if(options.output_filename)
        e5_export_bov(options.output_filename, e5_file_id, &grid);
    else
        e5_dump_grid(&grid);

    free(grid.data);

    /* Free the command line options
     */
    free(options.e5_filename);
    free(options.location);
    free(options.output_filename);

    /* Close the group and the file 
     */
    e5_close_file(e5_file_id);
    return 0;
}
示例#2
0
文件: e5.c 项目: voidcycles/void
static void
e5_free(void* ptr)
{
#ifdef E5_DEBUG
    E5_EXIT_ON_ERROR((ptr == NULL) ? (-1) : (E5_SUCCESS));
#endif
    free(ptr);
}
示例#3
0
文件: e5.c 项目: voidcycles/void
static void*
e5_malloc(size_t bytes)
{
    void* ptr = malloc(bytes);
#ifdef E5_DEBUG
    E5_EXIT_ON_ERROR((ptr == NULL) ? (-1) : (E5_SUCCESS));
#endif
    return ptr;
}
示例#4
0
文件: main.c 项目: ICRAR/gridding
int
main(int argc, char** argv)
{
    eid_t e5_file_id;
    eid_t e5_group_id;
    estatus_t status;
    
    /* Parse the command line options
     */
    options_t options = {0};
    ParseOptions(&options, argc, argv);

    /* Open the E5 file and main group
     */
    e5_set_notify_func(E5_DEFAULT, notify_func, E5_NOTIFY_LEVEL_MIN, E5_NOTIFY_LEVEL_MAX);
    e5_file_id = e5_open_file(options.filename);

    /* Read the grid dimensionality and type info
     */
    if(options.type == OPT_GRID)
    {
        e5_grid_dataset grid = { 0 };
        grid.name = options.location;
        status = e5_read_data_info(e5_file_id, grid.name, grid.dim, &grid.type, &grid.scale);
        E5_EXIT_ON_ERROR(status);
        
        /* Allocate memory and read the grid data
         */
        grid.data = malloc(e5_sizeof(grid.type) * grid.dim[0] * grid.dim[1] * grid.dim[2]);
        status = e5_read_grid(e5_file_id, grid.name, grid.data, grid.dim, &grid.type, &grid.scale);
        E5_EXIT_ON_ERROR(status);
        
        e5_dump_grid(&grid);
        free(grid.data);
    }
    else if (options.type == OPT_ATTR)
    {
        int* data = malloc(sizeof(int));

        const char* base_name = e5_basename(options.location);
        size_t offset = base_name - options.location;
        char* group_name = malloc(offset + 2);
        snprintf(group_name, offset, "%s", options.location);
    
        e5_group_id = e5_open_group(e5_file_id, group_name);           
        e5_attr attr[] = { {base_name, data, E5_TYPE_INT, 0}, {0} };
        status = e5_read_attr_list(e5_group_id, attr);
        E5_EXIT_ON_ERROR(status);
        
        printf("ATTR: '%s' -> '%d'\n", options.location, *data);

        free(data);
        free(group_name);
        e5_close_group(e5_group_id);
    }

    /* Close the group and the file 
     */
    status = e5_close_file(e5_file_id);
    E5_EXIT_ON_ERROR(status);
    
    /* Free the command line options
     */
    free(options.filename);
    free(options.location);
    return 0;
}
示例#5
0
文件: main.c 项目: ICRAR/gridding
static void
e5_export_bov(
    const char* bov_file, 
    eid_t e5_file_id, 
    e5_grid_dataset* grid)
{
    static const int min_bricklet = 1;
    static const int max_bricklet = 32;
    
    int i;
    int d;
    
    bov_header_t header;
    e5_bov_attrs_t attrs;
    
    memset(&header, 0, sizeof(bov_header_t));
    memset(&attrs, 0, sizeof(e5_bov_attrs_t));
    
    size_t len = strlen(bov_file) + 8;
    char *data_file = malloc(len);
    snprintf(data_file, len, "%s.data", e5_basename(bov_file));
    
    eid_t e5_group_id = e5_open_group(e5_file_id, "/Emissivity/real scalars");           
    e5_attr real_scalars_attr[] = { {"time", &(attrs.time), E5_TYPE_DOUBLE, 0}, {0} };
    estatus_t status = e5_read_attr_list(e5_group_id, real_scalars_attr);
    E5_EXIT_ON_ERROR(status);
    e5_close_group(e5_group_id);
    
    e5_group_id = e5_open_group(e5_file_id, "/Emissivity/real runtime parameters");           
    e5_attr real_param_attr[] = { 
        {"xmin", &(attrs.xmin), E5_TYPE_DOUBLE, 0}, 
        {"xmax", &(attrs.xmax), E5_TYPE_DOUBLE, 0}, 
        {"ymin", &(attrs.ymin), E5_TYPE_DOUBLE, 0}, 
        {"ymax", &(attrs.ymax), E5_TYPE_DOUBLE, 0}, 
        {"zmin", &(attrs.zmin), E5_TYPE_DOUBLE, 0}, 
        {"zmax", &(attrs.zmax), E5_TYPE_DOUBLE, 0}, 
        {0} 
    };
    
    status = e5_read_attr_list(e5_group_id, real_param_attr);
    E5_EXIT_ON_ERROR(status);
    e5_close_group(e5_group_id);
    
    header.variable = grid->name;
    header.time = (float)attrs.time;
    header.data_file = data_file;
    header.data_size[0] = (int)grid->dim[0];
    header.data_size[1] = (int)grid->dim[1];
    header.data_size[2] = (int)grid->dim[2];
    header.centering = "zonal";
    header.data_components = 1;
    header.brick_origin[0] = (attrs.xmax + attrs.xmin) * 0.5;
    header.brick_origin[1] = (attrs.ymax + attrs.ymin) * 0.5;
    header.brick_origin[2] = (attrs.zmax + attrs.zmin) * 0.5;
    header.brick_size[0] = attrs.xmax - attrs.xmin;
    header.brick_size[1] = attrs.ymax - attrs.ymin;
    header.brick_size[2] = attrs.zmax - attrs.zmin;
    
    for(i=min_bricklet; i <= max_bricklet; i++)
    {
        for(d=0; d<3; d++)
            header.data_bricklets[d] = ((header.data_size[d] % i) == 0) ? i : header.data_bricklets[d];
    }

    if(grid->type == E5_TYPE_FLOAT)
        header.data_format = "FLOAT";
    else if(grid->type == E5_TYPE_DOUBLE)
        header.data_format = "DOUBLE";
    else if(grid->type == E5_TYPE_INT)
        header.data_format = "INT";        
        
    FILE* fd = CreateTextFile(bov_file); 
    if(!fd)
    {
        printf("Failed to create BOV header file '%s'! Exiting...\n", bov_file);
        exit(EXIT_FAILURE);
    }

    printf("Writing header to '%s'...\n", bov_file);
    fprintf(fd, "TIME: %f\n", header.time);
    fprintf(fd, "DATA_FILE: %s\n", header.data_file);
    fprintf(fd, "DATA_SIZE: %d %d %d\n", 
        header.data_size[0], header.data_size[1], header.data_size[2]);
    fprintf(fd, "DATA_FORMAT: %s\n", header.data_format);
    fprintf(fd, "VARIABLE: %s\n", header.variable);
    fprintf(fd, "DATA_ENDIAN: LITTLE\n");
    fprintf(fd, "CENTERING: %s\n", header.centering);
    fprintf(fd, "BRICK_ORIGIN: %f %f %f\n",
        header.brick_origin[0], header.brick_origin[1], header.brick_origin[2]);
    fprintf(fd, "BRICK_SIZE: %f %f %f\n",
        header.brick_size[0], header.brick_size[1], header.brick_size[2]);
    fprintf(fd, "DIVIDE_BRICK: true\n");
    fprintf(fd, "DATA_BRICKLETS: %d %d %d\n",
        header.data_bricklets[0], header.data_bricklets[1], header.data_bricklets[2]);
    fprintf(fd, "DATA_COMPONENTS: %d\n", 1);
    CloseTextFile(fd);

    snprintf(data_file, len, "%s.data", (bov_file));
    fd = CreateRawFile(header.data_file);
    if(!fd)
    {
        printf("Failed to create BOV data file '%s'! Exiting...\n", bov_file);
        exit(EXIT_FAILURE);
    }

    printf("Writing data to '%s'...\n", header.data_file);
    WriteRaw(fd, grid->data, e5_sizeof(grid->type), grid->dim[0] * grid->dim[1] * grid->dim[2]);
    CloseRawFile(fd);
    printf("DONE!\n");
}