17 #define LINEBUF_SIZE 1023
25 static int output_result_header(FILE *fp) {
42 static int output_result_global(FILE *fp) {
43 int i,j,k,n,rc,ng_comp;
47 rc = fprintf(fp,
"*comment\n");
59 rc = fprintf(fp,
"*global\n");
75 rc = fprintf(fp,
"%d%c", p->
n_dof, (n+1)%
COL_INT ?
' ' :
'\n');
83 rc = fprintf(fp,
"\n");
92 rc = fprintf(fp,
"%s\n", p->
label);
101 if(ng_comp == 0)
return 0;
112 for(j=0; j < ng_comp; j++) {
114 for(k=0; k < p->
n_dof; k++) {
115 rc = fprintf(fp,
"%.16E%c", p->
ptr[k], (n+1)%
COL_DOUBLE ?
' ' :
'\n');
124 rc = fprintf(fp,
"\n");
136 static int output_result_dataheader(FILE *fp) {
157 static int output_result_node(FILE *fp) {
158 int i,j,k,n,rc,nn_comp;
164 rc = fprintf(fp,
"%d%c", p->
n_dof, (n+1)%
COL_INT ?
' ' :
'\n');
172 rc = fprintf(fp,
"\n");
181 rc = fprintf(fp,
"%s\n", p->
label);
190 if(nn_comp == 0)
return 0;
207 for(j=0; j < nn_comp; j++) {
209 for(k=0; k < p->
n_dof; k++) {
219 rc = fprintf(fp,
"\n");
232 static int output_result_elem(FILE *fp) {
233 int i,j,k,n,rc,ne_comp;
239 rc = fprintf(fp,
"%d%c", p->
n_dof, (n+1)%
COL_INT ?
' ' :
'\n');
247 rc = fprintf(fp,
"\n");
256 rc = fprintf(fp,
"%s\n", p->
label);
265 if(ne_comp == 0)
return 0;
282 for(j=0; j < ne_comp; j++) {
284 for(k=0; k < p->
n_dof; k++) {
294 rc = fprintf(fp,
"\n");
307 static int output_result_data(FILE *fp) {
311 if(output_result_header(fp)) {
315 if(output_result_global(fp)) {
319 rc = fprintf(fp,
"*data\n");
325 if(output_result_dataheader(fp)) {
328 if(output_result_node(fp)) {
331 if(output_result_elem(fp)) {
351 if ((fp = fopen(filename,
"w")) ==
NULL) {
357 if (output_result_data(fp)) {
379 static int output_result_header_ST(
struct hecmwST_result_data *result,
char *header, FILE *fp) {
391 while(len <
sizeof(head)-1 && *p && *p !=
'\n') {
402 rc = fprintf(fp,
"%s\n", head);
412 static int output_result_global_ST(
struct hecmwST_result_data *result,
char *comment, FILE *fp) {
418 if(comment ==
NULL) {
419 comment_line[0] =
'\0';
424 while(len <
sizeof(comment_line)-1 && *p && *p !=
'\n') {
432 rc = fprintf(fp,
"*comment\n");
437 rc = fprintf(fp,
"%s\n", comment);
445 rc = fprintf(fp,
"*global\n");
461 rc = fprintf(fp,
"%d%c", result->
ng_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
469 rc = fprintf(fp,
"\n");
489 for(k=0; k < result->
ng_dof[j]; k++) {
499 rc = fprintf(fp,
"\n");
507 rc = fprintf(fp,
"*data\n");
518 int n_node,
int n_elem, FILE *fp) {
522 rc = fprintf(fp,
"%d %d\n", n_node, n_elem);
539 static int output_result_node_ST(
struct hecmwST_result_data *result,
int n_node, FILE *fp) {
545 rc = fprintf(fp,
"%d%c", result->
nn_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
553 rc = fprintf(fp,
"\n");
562 rc = fprintf(fp,
"%s\n", result->
node_label[i]);
572 for(i=0; i < n_node; i++) {
580 for(k=0; k < result->
nn_dof[j]; k++) {
591 rc = fprintf(fp,
"\n");
603 static int output_result_elem_ST(
struct hecmwST_result_data *result,
int n_elem, FILE *fp) {
609 rc = fprintf(fp,
"%d%c", result->
ne_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
617 rc = fprintf(fp,
"\n");
626 rc = fprintf(fp,
"%s\n", result->
elem_label[i]);
636 for(i=0; i < n_elem; i++) {
644 for(k=0; k < result->
ne_dof[j]; k++) {
655 rc = fprintf(fp,
"\n");
667 static int output_result_data_ST(
struct hecmwST_result_data *result,
int n_node,
int n_elem,
668 char *header,
char *comment, FILE *fp) {
671 if(output_result_header_ST(result, header, fp)) {
675 if(output_result_global_ST(result, comment, fp)) {
679 if(output_result_dataheader_ST(result, n_node, n_elem, fp)) {
682 if(output_result_node_ST(result, n_node, fp)) {
685 if(output_result_elem_ST(result, n_elem, fp)) {
696 int n_node,
int n_elem,
char *header,
char *comment) {
707 if ((fp = fopen(filename,
"w")) ==
NULL) {
713 if (output_result_data_ST(result, n_node, n_elem, header, comment, fp)) {
735 static int get_line(
char *buf,
int bufsize, FILE *fp) {
736 if(fgets(buf, bufsize, fp) ==
NULL) {
740 return strlen(Line_Buf);
748 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
751 Line_Buf[ strlen(Line_Buf)-1 ] = 0;
753 ptr = strtok(Line_Buf,
" ");
754 sprintf(Line_Buf,
"%s",
ptr);
768 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
771 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
774 Line_Buf[ strlen(Line_Buf)-1 ] = 0;
779 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
784 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
787 if(sscanf(Line_Buf,
"%d", &result->
ng_component) != 1) {
803 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
808 while(i < result->ng_component) {
809 p = strtok(buf,
DELIM);
811 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
818 rc = sscanf(p,
"%d", &result->
ng_dof[i]);
840 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
843 rc = sscanf(Line_Buf,
"%s",
label);
865 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
871 p = strtok(buf,
DELIM);
873 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
893 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
902 int *n_node,
int *n_elem, FILE *fp) {
905 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
908 if(sscanf(Line_Buf,
"%d%d", n_node, n_elem) != 2) {
914 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
943 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
948 while(i < result->nn_component) {
949 p = strtok(buf,
DELIM);
951 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
958 rc = sscanf(p,
"%d", &result->
nn_dof[i]);
980 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
983 rc = sscanf(Line_Buf,
"%s",
label);
1010 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1017 while(i < n*n_node) {
1018 p = strtok(buf,
DELIM);
1020 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1031 rc = sscanf(p,
"%lf", &result->
node_val_item[i-label_counter]);
1065 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1070 while(i < result->ne_component) {
1072 p = strtok(buf,
DELIM);
1074 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1081 rc = sscanf(p,
"%d", &result->
ne_dof[i]);
1103 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1106 rc = sscanf(Line_Buf,
"%s",
label);
1134 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1141 while(i < n*n_elem) {
1142 p = strtok(buf,
DELIM);
1144 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1155 rc = sscanf(p,
"%lf", &result->
elem_val_item[i-label_counter]);
1179 if(result ==
NULL) {
1183 if(input_result_header(result, fp)) {
1187 if(input_result_global(result, fp)) {
1191 if(input_result_dataheader(result, &n_node, &n_elem, fp)) {
1196 if(input_result_node(result, n_node, fp)) {
1199 if(input_result_elem(result, n_elem, fp)) {
1212 if((fp = fopen(filename,
"r")) ==
NULL) {
1217 result = input_result_data(fp);
1218 if(result ==
NULL) {