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 sprintf( 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) {
92 static int bin_output_result_global(FILE *fp) {
93 int i,j,k,n,rc,ng_comp;
144 if(ng_comp == 0)
return 0;
154 for(j=0; j < ng_comp; j++) {
156 for(k=0; k < p->
n_dof; k++) {
170 static int bin_output_result_dataheader(FILE *fp) {
191 static int bin_output_result_node(FILE *fp) {
192 int i,j,k,n,rc,nn_comp;
217 if(nn_comp == 0)
return 0;
233 for(j=0; j < nn_comp; j++) {
235 for(k=0; k < p->
n_dof; k++) {
250 static int bin_output_result_elem(FILE *fp) {
251 int i,j,k,n,rc,ne_comp;
276 if(ne_comp == 0)
return 0;
292 for(j=0; j < ne_comp; j++) {
294 for(k=0; k < p->
n_dof; k++) {
309 static int bin_output_result_data(FILE *fp) {
313 if(bin_output_result_header(fp)) {
317 if(bin_output_result_global(fp)) {
327 if(bin_output_result_dataheader(fp)) {
330 if(bin_output_result_node(fp)) {
333 if(bin_output_result_elem(fp)) {
353 if ((fp = fopen(filename,
"wb")) ==
NULL) {
360 if (write_bin_header(fp))
goto error;
361 if (bin_output_result_data(fp))
goto error;
382 char *header, FILE *fp) {
394 while(len <
sizeof(head)-1 && *p && *p !=
'\n') {
416 char *comment, FILE *fp) {
422 if(comment ==
NULL) {
423 comment_line[0] =
'\0';
428 while(len <
sizeof(comment_line)-1 && *p && *p !=
'\n') {
485 for(k=0; k < result->
ng_dof[j]; k++) {
507 int n_node,
int n_elem, FILE *fp) {
529 int n_node, FILE *fp) {
555 for(i=0; i < n_node; i++) {
562 for(k=0; k < result->
nn_dof[j]; k++) {
578 int n_elem, FILE *fp) {
604 for(i=0; i < n_elem; i++) {
611 for(k=0; k < result->
ne_dof[j]; k++) {
627 int n_node,
int n_elem,
char *header,
628 char *comment, FILE *fp) {
631 if(bin_output_result_header_ST(result, header, fp)) {
635 if(bin_output_result_global_ST(result, comment, fp)) {
639 if(bin_output_result_dataheader_ST(result, n_node, n_elem, fp)) {
642 if(bin_output_result_node_ST(result, n_node, fp)) {
645 if(bin_output_result_elem_ST(result, n_elem, fp)) {
656 int n_node,
int n_elem,
char *header,
char *comment) {
667 if ((fp = fopen(filename,
"wb")) ==
NULL) {
674 if (write_bin_header(fp))
goto error;
675 if (bin_output_result_data_ST(result, n_node, n_elem, header, comment, fp))
goto error;
704 ptr = strtok(Line_Buf,
" ");
705 sprintf(Line_Buf,
"%s",
ptr);
787 for(k=0; k < result->
ng_dof[j]; k++) {
807 int *n_node,
int *n_elem, FILE *fp) {
828 static int bin_input_result_node(
struct hecmwST_result_data *result,
int n_node, FILE *fp) {
884 for(i=0; i < n_node; i++) {
890 for(k=0; k < result->
nn_dof[j]; k++) {
905 static int bin_input_result_elem(
struct hecmwST_result_data *result,
int n_elem, FILE *fp) {
961 for(i=0; i < n_elem; i++) {
967 for(k=0; k < result->
ne_dof[j]; k++) {
994 if(bin_input_result_header(result, fp)) {
999 if(bin_input_result_global(result, fp)) {
1003 if(bin_input_result_dataheader(result, &n_node, &n_elem, fp)) {
1009 if(bin_input_result_node(result, n_node, fp)) {
1013 if(bin_input_result_elem(result, n_elem, fp)) {
1028 if((fp = fopen(filename,
"rb")) ==
NULL) {
1035 if(!check_bin_header(fp)) {
1040 result = bin_input_result_data(fp);
1041 if(result ==
NULL) {