PIDX_return_code PIDX_header_io_write_idx (PIDX_header_io_id header_io, char* data_set_path, int current_time_step) { int l = 0, rank = 0, N, ncores = 1; FILE* idx_file_p; char dirname[1024], basename[1024]; #if PIDX_HAVE_MPI if (header_io->idx_d->parallel_mode == 1) { MPI_Comm_rank(header_io->comm, &rank); MPI_Comm_size(header_io->comm, &ncores); } #endif int nbits_blocknumber = (header_io->idx_d->maxh - header_io->idx->bits_per_block - 1); VisusSplitFilename(data_set_path, dirname, basename); //remove suffix for (N = strlen(basename) - 1; N >= 0; N--) { int ch = basename[N]; basename[N] = 0; if (ch == '.') break; } #if 0 //if i put . as the first character, if I move files VisusOpen can do path remapping sprintf(pidx->filename_template, "./%s", basename); #endif //pidx does not do path remapping strcpy(header_io->filename_template, data_set_path); for (N = strlen(header_io->filename_template) - 1; N >= 0; N--) { int ch = header_io->filename_template[N]; header_io->filename_template[N] = 0; if (ch == '.') break; } //can happen if I have only only one block if (nbits_blocknumber == 0) strcat(header_io->filename_template, "/%01x.bin"); else { //approximate to 4 bits if (nbits_blocknumber % 4) { nbits_blocknumber += (4 - (nbits_blocknumber % 4)); //assert(!(nbits_blocknumber % 4)); } if (nbits_blocknumber <= 8) strcat(header_io->filename_template, "/%02x.bin"); //no directories, 256 files else if (nbits_blocknumber <= 12) strcat(header_io->filename_template, "/%03x.bin"); //no directories, 4096 files else if (nbits_blocknumber <= 16) strcat(header_io->filename_template, "/%04x.bin"); //no directories, 65536 files else { while (nbits_blocknumber > 16) { strcat(header_io->filename_template, "/%02x"); //256 subdirectories nbits_blocknumber -= 8; } strcat(header_io->filename_template, "/%04x.bin"); //max 65536 files nbits_blocknumber -= 16; //assert(nbits_blocknumber <= 0); } } if (strncmp(".idx", &data_set_path[strlen(data_set_path) - 4], 4) != 0) { fprintf(stderr, "[%s] [%d] Bad file name extension.\n", __FILE__, __LINE__); return 1; } if (rank == 0) { //fprintf(stderr, "writing IDX file...\n", __FILE__, __LINE__); if (header_io->idx->compression_type != PIDX_NO_COMPRESSION) { char visus_data_path[PATH_MAX]; char filename_skeleton[PATH_MAX]; strncpy(filename_skeleton, data_set_path, strlen(data_set_path) - 4); filename_skeleton[strlen(filename_skeleton) - 4] = '\0'; sprintf(visus_data_path, "%s_visus.idx", filename_skeleton); idx_file_p = fopen(visus_data_path, "w"); if (!idx_file_p) { fprintf(stderr, " [%s] [%d] idx_dir is corrupt.\n", __FILE__, __LINE__); return -1; } fprintf(idx_file_p, "(version)\n6\n"); fprintf(idx_file_p, "(logic_to_physic)\n%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n", header_io->idx->transform[0], header_io->idx->transform[1], header_io->idx->transform[2], header_io->idx->transform[3], header_io->idx->transform[4], header_io->idx->transform[5], header_io->idx->transform[6], header_io->idx->transform[7], header_io->idx->transform[8], header_io->idx->transform[9], header_io->idx->transform[10], header_io->idx->transform[11], header_io->idx->transform[12], header_io->idx->transform[13], header_io->idx->transform[14], header_io->idx->transform[15]); if (header_io->idx->compression_type != PIDX_NO_COMPRESSION) { fprintf(idx_file_p, "(compression type)\n%d\n", header_io->idx->compression_type); fprintf(idx_file_p, "(box)\n0 %lld 0 %lld 0 %lld 0 %lld 0 %lld\n", (long long)(header_io->idx->chunked_bounds[0] - 1), (long long)(header_io->idx->chunked_bounds[1] - 1), (long long)(header_io->idx->chunked_bounds[2] - 1), (long long)(header_io->idx->chunked_bounds[3] - 1), (long long)(header_io->idx->chunked_bounds[4] - 1)); fprintf(idx_file_p, "(original box)\n0 %lld 0 %lld 0 %lld 0 %lld 0 %lld\n", (long long)(header_io->idx->bounds[0] - 1), (long long)(header_io->idx->bounds[1] - 1), (long long)(header_io->idx->bounds[2] - 1), (long long)(header_io->idx->bounds[3] - 1), (long long)(header_io->idx->bounds[4] - 1)); fprintf(idx_file_p, "(compression bit rate)\n%d\n", header_io->idx->compression_bit_rate); fprintf(idx_file_p, "(fields)\n"); for (l = 0; l < header_io->last_index; l++) { fprintf(idx_file_p, "%s %d*float64", header_io->idx->variable[l]->var_name, header_io->idx->compression_bit_rate); if (l != header_io->last_index - 1) fprintf(idx_file_p, " + \n"); } } fprintf(idx_file_p, "\n(bits)\n%s\n", header_io->idx->bitSequence); fprintf(idx_file_p, "(bitsperblock)\n%d\n(blocksperfile)\n%d\n", header_io->idx->bits_per_block, header_io->idx->blocks_per_file); fprintf(idx_file_p, "(filename_template)\n./%s\n", header_io->filename_template); fprintf(idx_file_p, "(time)\n0 %d time%%09d/"/*note: uintah starts at timestep 1, but we shouldn't assume...*/, header_io->idx->current_time_step); fclose(idx_file_p); } idx_file_p = fopen(data_set_path, "w"); if (!idx_file_p) { fprintf(stderr, " [%s] [%d] idx_dir is corrupt.\n", __FILE__, __LINE__); return -1; } fprintf(idx_file_p, "(version)\n6\n"); fprintf(idx_file_p, "(logic_to_physic)\n%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n", header_io->idx->transform[0], header_io->idx->transform[1], header_io->idx->transform[2], header_io->idx->transform[3], header_io->idx->transform[4], header_io->idx->transform[5], header_io->idx->transform[6], header_io->idx->transform[7], header_io->idx->transform[8], header_io->idx->transform[9], header_io->idx->transform[10], header_io->idx->transform[11], header_io->idx->transform[12], header_io->idx->transform[13], header_io->idx->transform[14], header_io->idx->transform[15]); fprintf(idx_file_p, "(box)\n0 %lld 0 %lld 0 %lld 0 %lld 0 %lld\n", (long long)(header_io->idx->bounds[0] - 1), (long long)(header_io->idx->bounds[1] - 1), (long long)(header_io->idx->bounds[2] - 1), (long long)(header_io->idx->bounds[3] - 1), (long long)(header_io->idx->bounds[4] - 1)); if (header_io->enable_raw_dump == 1) { fprintf(idx_file_p, "(raw_dump)\n%lld %lld %lld\n", (long long)header_io->idx->reg_patch_size[0], (long long)header_io->idx->reg_patch_size[1], (long long)header_io->idx->reg_patch_size[2]); fprintf(idx_file_p, "(cores)\n%d\n", ncores); } if (header_io->idx->compression_type != PIDX_NO_COMPRESSION) { fprintf(idx_file_p, "(compression type)\n%d\n", header_io->idx->compression_type); fprintf(idx_file_p, "(compressed box)\n%lld %lld %lld %lld %lld\n", (long long)(header_io->idx->chunk_size[0]), (long long)(header_io->idx->chunk_size[1]), (long long)(header_io->idx->chunk_size[2]), (long long)(header_io->idx->chunk_size[3]), (long long)(header_io->idx->chunk_size[4])); fprintf(idx_file_p, "(compression bit rate)\n%d\n", header_io->idx->compression_bit_rate); } fprintf(idx_file_p, "(fields)\n"); for (l = 0; l < header_io->last_index; l++) { fprintf(idx_file_p, "%s %s", header_io->idx->variable[l]->var_name, header_io->idx->variable[l]->type_name); if (l != header_io->last_index - 1) fprintf(idx_file_p, " + \n"); } if (header_io->enable_raw_dump != 1) { fprintf(idx_file_p, "\n(bits)\n%s\n", header_io->idx->bitSequence); fprintf(idx_file_p, "(bitsperblock)\n%d\n(blocksperfile)\n%d\n", header_io->idx->bits_per_block, header_io->idx->blocks_per_file); //if (header_io->idx_d->res_to != 0) // fprintf(idx_file_p, "(resolution)\n%d\n", header_io->idx_d->res_to); fprintf(idx_file_p, "(filename_template)\n./%s\n", header_io->filename_template); } fprintf(idx_file_p, "\n(time)\n0 %d time%%09d/"/*note: uintah starts at timestep 1, but we shouldn't assume...*/, header_io->idx->current_time_step); fclose(idx_file_p); } return 0; }
int generate_file_name_template(int maxh, int bits_per_block, char* filename, char* time_template, int current_time_step, char* filename_template) { int N; char dirname[PIDX_FILE_PATH_LENGTH], basename[PIDX_FILE_PATH_LENGTH]; int nbits_blocknumber; char* directory_path; char* data_set_path; data_set_path = malloc(sizeof(*data_set_path) * 1024); memset(data_set_path, 0, sizeof(*data_set_path) * 1024); directory_path = malloc(sizeof(*directory_path) * 1024); memset(directory_path, 0, sizeof(*directory_path) * 1024); strncpy(directory_path, filename, strlen(filename) - 4); char this_time_template[512]; sprintf(this_time_template, "%%s/%s.idx", time_template); sprintf(data_set_path, this_time_template, directory_path, current_time_step); free(directory_path); nbits_blocknumber = (maxh - bits_per_block - 1); VisusSplitFilename(data_set_path, dirname, basename); //fprintf(stderr, "dirname %s basename %s\n", dirname, basename); //remove suffix for (N = strlen(basename) - 1; N >= 0; N--) { int ch = basename[N]; basename[N] = 0; if (ch == '.') break; } #if 0 //if i put . as the first character, if I move files VisusOpen can do path remapping sprintf(pidx->filename_template, "./%s", basename); #endif //pidx does not do path remapping strcpy(filename_template, data_set_path); for (N = strlen(filename_template) - 1; N >= 0; N--) { int ch = filename_template[N]; filename_template[N] = 0; if (ch == '.') break; } //can happen if I have only only one block if (nbits_blocknumber == 0) strcat(filename_template, "/%01x.bin"); else { //approximate to 4 bits if (nbits_blocknumber % 4) { nbits_blocknumber += (4 - (nbits_blocknumber % 4)); //assert(!(nbits_blocknumber % 4)); } if (nbits_blocknumber <= 8) strcat(filename_template, "/%02x.bin"); //no directories, 256 files else if (nbits_blocknumber <= 12) strcat(filename_template, "/%03x.bin"); //no directories, 4096 files else if (nbits_blocknumber <= 16) strcat(filename_template, "/%04x.bin"); //no directories, 65536 files else { while (nbits_blocknumber > 16) { strcat(filename_template, "/%02x"); //256 subdirectories nbits_blocknumber -= 8; } strcat(filename_template, "/%04x.bin"); //max 65536 files nbits_blocknumber -= 16; //assert(nbits_blocknumber <= 0); } } free(data_set_path); return 0; }