17 #define LINEBUF_SIZE 1023
25 static int output_result_header(FILE *fp) {
45 static int output_result_global(FILE *fp) {
46 int i,j,k,n,rc,ng_comp;
50 rc = fprintf(fp,
"*comment\n");
62 rc = fprintf(fp,
"*global\n");
78 rc = fprintf(fp,
"%d%c", p->
n_dof, (n+1)%
COL_INT ?
' ' :
'\n');
86 rc = fprintf(fp,
"\n");
95 rc = fprintf(fp,
"%s\n", p->
label);
104 if(ng_comp == 0)
return 0;
115 for(j=0; j < ng_comp; j++) {
117 for(k=0; k < p->
n_dof; k++) {
118 rc = fprintf(fp,
"%.16E%c", p->
ptr[k], (n+1)%
COL_DOUBLE ?
' ' :
'\n');
127 rc = fprintf(fp,
"\n");
139 static int output_result_dataheader(FILE *fp) {
160 static int output_result_node(FILE *fp) {
161 int i,j,k,n,rc,nn_comp;
167 rc = fprintf(fp,
"%d%c", p->
n_dof, (n+1)%
COL_INT ?
' ' :
'\n');
175 rc = fprintf(fp,
"\n");
184 rc = fprintf(fp,
"%s\n", p->
label);
193 if(nn_comp == 0)
return 0;
210 for(j=0; j < nn_comp; j++) {
212 for(k=0; k < p->
n_dof; k++) {
222 rc = fprintf(fp,
"\n");
235 static int output_result_elem(FILE *fp) {
236 int i,j,k,n,rc,ne_comp;
242 rc = fprintf(fp,
"%d%c", p->
n_dof, (n+1)%
COL_INT ?
' ' :
'\n');
250 rc = fprintf(fp,
"\n");
259 rc = fprintf(fp,
"%s\n", p->
label);
268 if(ne_comp == 0)
return 0;
285 for(j=0; j < ne_comp; j++) {
287 for(k=0; k < p->
n_dof; k++) {
297 rc = fprintf(fp,
"\n");
310 static int output_result_data(FILE *fp) {
314 if(output_result_header(fp)) {
318 if(output_result_global(fp)) {
322 rc = fprintf(fp,
"*data\n");
328 if(output_result_dataheader(fp)) {
331 if(output_result_node(fp)) {
334 if(output_result_elem(fp)) {
354 if ((fp = fopen(filename,
"w")) ==
NULL) {
360 if (output_result_data(fp)) {
382 static int output_result_header_ST(
struct hecmwST_result_data *result,
char *header, FILE *fp) {
394 while(len <
sizeof(head)-1 && *p && *p !=
'\n') {
405 rc = fprintf(fp,
"%s\n", head);
415 static int output_result_global_ST(
struct hecmwST_result_data *result,
char *comment, FILE *fp) {
421 if(comment ==
NULL) {
422 comment_line[0] =
'\0';
427 while(len <
sizeof(comment_line)-1 && *p && *p !=
'\n') {
435 rc = fprintf(fp,
"*comment\n");
440 rc = fprintf(fp,
"%s\n", comment);
448 rc = fprintf(fp,
"*global\n");
464 rc = fprintf(fp,
"%d%c", result->
ng_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
472 rc = fprintf(fp,
"\n");
492 for(k=0; k < result->
ng_dof[j]; k++) {
502 rc = fprintf(fp,
"\n");
510 rc = fprintf(fp,
"*data\n");
521 int n_node,
int n_elem, FILE *fp) {
525 rc = fprintf(fp,
"%d %d\n", n_node, n_elem);
542 static int output_result_node_ST(
struct hecmwST_result_data *result,
int n_node, FILE *fp) {
548 rc = fprintf(fp,
"%d%c", result->
nn_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
556 rc = fprintf(fp,
"\n");
565 rc = fprintf(fp,
"%s\n", result->
node_label[i]);
575 for(i=0; i < n_node; i++) {
583 for(k=0; k < result->
nn_dof[j]; k++) {
594 rc = fprintf(fp,
"\n");
606 static int output_result_elem_ST(
struct hecmwST_result_data *result,
int n_elem, FILE *fp) {
612 rc = fprintf(fp,
"%d%c", result->
ne_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
620 rc = fprintf(fp,
"\n");
629 rc = fprintf(fp,
"%s\n", result->
elem_label[i]);
639 for(i=0; i < n_elem; i++) {
647 for(k=0; k < result->
ne_dof[j]; k++) {
658 rc = fprintf(fp,
"\n");
670 static int output_result_data_ST(
struct hecmwST_result_data *result,
int n_node,
int n_elem,
671 char *header,
char *comment, FILE *fp) {
674 if(output_result_header_ST(result, header, fp)) {
678 if(output_result_global_ST(result, comment, fp)) {
682 if(output_result_dataheader_ST(result, n_node, n_elem, fp)) {
685 if(output_result_node_ST(result, n_node, fp)) {
688 if(output_result_elem_ST(result, n_elem, fp)) {
699 int n_node,
int n_elem,
char *header,
char *comment) {
710 if ((fp = fopen(filename,
"w")) ==
NULL) {
716 if (output_result_data_ST(result, n_node, n_elem, header, comment, fp)) {
738 static int get_line(
char *buf,
int bufsize, FILE *fp) {
739 if(fgets(buf, bufsize, fp) ==
NULL) {
743 return strlen(Line_Buf);
751 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
754 Line_Buf[ strlen(Line_Buf)-1 ] = 0;
756 ptr = strtok(Line_Buf,
" ");
757 sprintf(Line_Buf,
"%s",
ptr);
771 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
774 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
777 Line_Buf[ strlen(Line_Buf)-1 ] = 0;
782 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
787 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
790 if(sscanf(Line_Buf,
"%d", &result->
ng_component) != 1) {
806 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
811 while(i < result->ng_component) {
812 p = strtok(buf,
DELIM);
814 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
821 rc = sscanf(p,
"%d", &result->
ng_dof[i]);
843 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
846 rc = sscanf(Line_Buf,
"%s",
label);
868 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
874 p = strtok(buf,
DELIM);
876 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
896 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
905 int *n_node,
int *n_elem, FILE *fp) {
908 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
911 if(sscanf(Line_Buf,
"%d%d", n_node, n_elem) != 2) {
917 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
946 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
951 while(i < result->nn_component) {
952 p = strtok(buf,
DELIM);
954 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
961 rc = sscanf(p,
"%d", &result->
nn_dof[i]);
983 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
986 rc = sscanf(Line_Buf,
"%s",
label);
1013 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1020 while(i < n*n_node) {
1021 p = strtok(buf,
DELIM);
1023 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1034 rc = sscanf(p,
"%lf", &result->
node_val_item[i-label_counter]);
1068 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1073 while(i < result->ne_component) {
1075 p = strtok(buf,
DELIM);
1077 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1084 rc = sscanf(p,
"%d", &result->
ne_dof[i]);
1106 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1109 rc = sscanf(Line_Buf,
"%s",
label);
1137 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1144 while(i < n*n_elem) {
1145 p = strtok(buf,
DELIM);
1147 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1158 rc = sscanf(p,
"%lf", &result->
elem_val_item[i-label_counter]);
1182 if(result ==
NULL) {
1186 if(input_result_header(result, fp)) {
1190 if(input_result_global(result, fp)) {
1194 if(input_result_dataheader(result, &n_node, &n_elem, fp)) {
1199 if(input_result_node(result, n_node, fp)) {
1202 if(input_result_elem(result, n_elem, fp)) {
1215 if((fp = fopen(filename,
"r")) ==
NULL) {
1220 result = input_result_data(fp);
1221 if(result ==
NULL) {
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_txt_write_by_fname(char *filename)
int HECMW_result_io_txt_write_ST_by_fname(char *filename, struct hecmwST_result_data *result, int n_node, int n_elem, char *header, char *comment)
struct hecmwST_result_data * HECMW_result_io_txt_read_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