15 #define RES_BIN_HEADER "HECMW_BINARY_RESULT"
17 #define LINEBUF_SIZE 1023
26 static int write_bin_header(FILE* fp) {
32 if( fwrite( s,
sizeof(
char), n, fp) != n )
return -1;
34 snprintf( nbyte,
sizeof(nbyte),
"%2zd", n );
35 if( fwrite( nbyte,
sizeof(
char), 2, fp) != 2 )
return -1;
40 static int check_bin_header(FILE* fp) {
43 char buff[256], nbyte[3];
45 if( fread( buff,
sizeof(
char), n, fp) != n )
return 0;
46 if( fread( nbyte,
sizeof(
char), 2, fp) != 2 )
return 0;
49 return ( strcmp( buff, s ) == 0 );
57 if((fp = fopen(filename,
"rb")) ==
NULL) {
63 rcode = check_bin_header(fp);
75 static int bin_output_result_header(FILE *fp) {
94 static int bin_output_result_global(FILE *fp) {
95 int i,j,k,n,rc,ng_comp;
146 if(ng_comp == 0)
return 0;
156 for(j=0; j < ng_comp; j++) {
158 for(k=0; k < p->
n_dof; k++) {
172 static int bin_output_result_dataheader(FILE *fp) {
193 static int bin_output_result_node(FILE *fp) {
194 int i,j,k,n,rc,nn_comp;
219 if(nn_comp == 0)
return 0;
235 for(j=0; j < nn_comp; j++) {
237 for(k=0; k < p->
n_dof; k++) {
252 static int bin_output_result_elem(FILE *fp) {
253 int i,j,k,n,rc,ne_comp;
278 if(ne_comp == 0)
return 0;
294 for(j=0; j < ne_comp; j++) {
296 for(k=0; k < p->
n_dof; k++) {
311 static int bin_output_result_data(FILE *fp) {
315 if(bin_output_result_header(fp)) {
319 if(bin_output_result_global(fp)) {
329 if(bin_output_result_dataheader(fp)) {
332 if(bin_output_result_node(fp)) {
335 if(bin_output_result_elem(fp)) {
355 if ((fp = fopen(filename,
"wb")) ==
NULL) {
362 if (write_bin_header(fp))
goto error;
363 if (bin_output_result_data(fp))
goto error;
384 char *header, FILE *fp) {
396 while(len <
sizeof(head)-1 && *p && *p !=
'\n') {
407 memcpy(head, tmp,
sizeof(head));
420 char *comment, FILE *fp) {
426 if(comment ==
NULL) {
427 comment_line[0] =
'\0';
432 while(len <
sizeof(comment_line)-1 && *p && *p !=
'\n') {
489 for(k=0; k < result->
ng_dof[j]; k++) {
511 int n_node,
int n_elem, FILE *fp) {
533 int n_node, FILE *fp) {
559 for(i=0; i < n_node; i++) {
566 for(k=0; k < result->
nn_dof[j]; k++) {
582 int n_elem, FILE *fp) {
608 for(i=0; i < n_elem; i++) {
615 for(k=0; k < result->
ne_dof[j]; k++) {
631 int n_node,
int n_elem,
char *header,
632 char *comment, FILE *fp) {
635 if(bin_output_result_header_ST(result, header, fp)) {
639 if(bin_output_result_global_ST(result, comment, fp)) {
643 if(bin_output_result_dataheader_ST(result, n_node, n_elem, fp)) {
646 if(bin_output_result_node_ST(result, n_node, fp)) {
649 if(bin_output_result_elem_ST(result, n_elem, fp)) {
660 int n_node,
int n_elem,
char *header,
char *comment) {
671 if ((fp = fopen(filename,
"wb")) ==
NULL) {
678 if (write_bin_header(fp))
goto error;
679 if (bin_output_result_data_ST(result, n_node, n_elem, header, comment, fp))
goto error;
708 ptr = strtok(Line_Buf,
" ");
709 if(
ptr != Line_Buf) {
710 size_t len = strlen(
ptr);
711 memmove(Line_Buf,
ptr, len + 1);
796 for(k=0; k < result->
ng_dof[j]; k++) {
816 int *n_node,
int *n_elem, FILE *fp) {
837 static int bin_input_result_node(
struct hecmwST_result_data *result,
int n_node, FILE *fp) {
893 for(i=0; i < n_node; i++) {
899 for(k=0; k < result->
nn_dof[j]; k++) {
914 static int bin_input_result_elem(
struct hecmwST_result_data *result,
int n_elem, FILE *fp) {
970 for(i=0; i < n_elem; i++) {
976 for(k=0; k < result->
ne_dof[j]; k++) {
1003 if(bin_input_result_header(result, fp)) {
1008 if(bin_input_result_global(result, fp)) {
1012 if(bin_input_result_dataheader(result, &n_node, &n_elem, fp)) {
1018 if(bin_input_result_node(result, n_node, fp)) {
1022 if(bin_input_result_elem(result, n_elem, fp)) {
1037 if((fp = fopen(filename,
"rb")) ==
NULL) {
1044 if(!check_bin_header(fp)) {
1049 result = bin_input_result_data(fp);
1050 if(result ==
NULL) {
void hecmw_set_endian_info(void)
int hecmw_write_bin(FILE *fp, const char *fmt,...)
int hecmw_read_bin(FILE *fp, const char *fmt,...)
int HECMW_ctrl_is_subdir(void)
int HECMW_ctrl_make_subdir(char *filename)
int HECMW_set_error(int errorno, const char *fmt,...)
#define HECMW_calloc(nmemb, size)
#define HECMW_malloc(size)
char * HECMW_strmsg(int msgno)
int HECMW_result_io_count_ng_comp(void)
int HECMW_result_io_count_ne_comp(void)
int HECMW_result_io_count_nn_comp(void)
struct hecmwST_result_io_data ResIO
#define HECMW_RESULT_FILEVER_MINOR
#define HECMW_RESULT_FILEVER_MAJOR
int HECMW_result_io_bin_judge_file(char *filename)
struct hecmwST_result_data * HECMW_result_io_bin_read_by_fname(char *filename)
int HECMW_result_io_bin_write_ST_by_fname(char *filename, struct hecmwST_result_data *result, int n_node, int n_elem, char *header, char *comment)
int HECMW_result_io_bin_write_by_fname(char *filename)
#define HECMW_assert(cond)
char comment_line[HECMW_MSG_LEN+1]
struct result_list * global_list
struct result_list * node_list
char head[HECMW_HEADER_LEN+1]
struct result_list * elem_list
struct result_list * next