?? save_to_disk.c
字號(hào):
#include "save_to_disk.h"/** \brief get a new file descriptor in writting mode */FILE * get_new_file_descriptor_w (char *filename) { FILE *fd; if (!(fd = fopen(filename, "w"))) { perror(filename); exit(1); } return (fd);}char *construct_filename(char *basename, char *ext, int procid, int file_id) { char *filename; filename = (char *) malloc(sizeof(char)*( strlen(basename) + strlen("-p") + RANK_SIZE + strlen("-") + NBFILE_SIZE + strlen(".") + strlen(ext) + 1)); assert(filename); sprintf(filename, "%s-p%.3d-%.4d.%s", basename, procid, file_id, ext); return (filename);}void save_memory_to_disk(char *output_format, char *celldatafilename, struct cell_info_t ****cell_info, struct mesh_t *mesh, int rank, int nbprocs, int nb_save){ if (strchr(output_format,'r')) { char *r2m_file; /* r2m */ /* nbprocs is used but there are only nbprocs-1 sub-domains */ /* rank-1 is the domain_id [0,nbprocs-1[ */ r2m_file = construct_filename(celldatafilename, "r2m", rank, nb_save); fprintf(stdout, "*** [process %d] dumping memory to disk, r2m file %s\n", rank, r2m_file); mesh_add_data_filename(mesh, R2M, r2m_file); make_domain_info_file(r2m_file, cell_info, mesh, /* domain */ 0, /* nbprocs */ 1, /* rank */ 0); } else { char *sco_file; /* sco */ sco_file = construct_filename(celldatafilename, "sco", rank, nb_save); fprintf(stdout, "*** [process %d] dumping memory to disk, sco file %s\n", rank, sco_file); mesh_add_data_filename(mesh, SCO, sco_file); mesh_cellinfo_write_sco (sco_file, cell_info, mesh); }}/** \brief change to next set of files * * construct sparse and res filename and add a SPARSE and RES * sections to the current mesh. * Set the files headers for sparse and res output. * If want_sparse_file is false sparse file is not processed. */void change_to_next_files (struct mesh_t *mesh, char *filename, int size, FILE **sparse_fd, FILE **res_fd, FILE **event_fd, int rank, int save_id, int want_sparse_file) { char *sparse_file; char *res_file; char *event_file; if (want_sparse_file) { if (*sparse_fd) { fclose (*sparse_fd); } sparse_file = construct_filename(filename, "sparse", rank, save_id); *sparse_fd = get_new_file_descriptor_w (sparse_file); mesh_add_data_filename(mesh, SPARSE, sparse_file); free(sparse_file); fprintf(*sparse_fd, "%d %ld\n", size, mesh->ncells); } if (*res_fd) { fclose (*res_fd); } res_file = construct_filename(filename, "res", rank, save_id); *res_fd = get_new_file_descriptor_w (res_file); mesh_add_data_filename(mesh, RES, res_file); free(res_file); fprintf(*res_fd, "%d\n", size); if (*event_fd) { fclose (*event_fd); } event_file = construct_filename(filename, "evt", rank, save_id); *event_fd = get_new_file_descriptor_w (event_file); mesh_add_data_filename(mesh, EVT, event_file); free(event_file);}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -