17 #define LINEBUF_SIZE 1023
25 static int output_result_header(FILE *fp) {
44 static int output_result_global(FILE *fp) {
45 int i,j,k,n,rc,ng_comp;
49 rc = fprintf(fp,
"*comment\n");
61 rc = fprintf(fp,
"*global\n");
77 rc = fprintf(fp,
"%d%c", p->
n_dof, (n+1)%
COL_INT ?
' ' :
'\n');
85 rc = fprintf(fp,
"\n");
94 rc = fprintf(fp,
"%s\n", p->
label);
103 if(ng_comp == 0)
return 0;
114 for(j=0; j < ng_comp; j++) {
116 for(k=0; k < p->
n_dof; k++) {
117 rc = fprintf(fp,
"%.16E%c", p->
ptr[k], (n+1)%
COL_DOUBLE ?
' ' :
'\n');
126 rc = fprintf(fp,
"\n");
138 static int output_result_dataheader(FILE *fp) {
159 static int output_result_node(FILE *fp) {
160 int i,j,k,n,rc,nn_comp;
166 rc = fprintf(fp,
"%d%c", p->
n_dof, (n+1)%
COL_INT ?
' ' :
'\n');
174 rc = fprintf(fp,
"\n");
183 rc = fprintf(fp,
"%s\n", p->
label);
192 if(nn_comp == 0)
return 0;
209 for(j=0; j < nn_comp; j++) {
211 for(k=0; k < p->
n_dof; k++) {
221 rc = fprintf(fp,
"\n");
234 static int output_result_elem(FILE *fp) {
235 int i,j,k,n,rc,ne_comp;
241 rc = fprintf(fp,
"%d%c", p->
n_dof, (n+1)%
COL_INT ?
' ' :
'\n');
249 rc = fprintf(fp,
"\n");
258 rc = fprintf(fp,
"%s\n", p->
label);
267 if(ne_comp == 0)
return 0;
284 for(j=0; j < ne_comp; j++) {
286 for(k=0; k < p->
n_dof; k++) {
296 rc = fprintf(fp,
"\n");
309 static int output_result_data(FILE *fp) {
313 if(output_result_header(fp)) {
317 if(output_result_global(fp)) {
321 rc = fprintf(fp,
"*data\n");
327 if(output_result_dataheader(fp)) {
330 if(output_result_node(fp)) {
333 if(output_result_elem(fp)) {
353 if ((fp = fopen(filename,
"w")) ==
NULL) {
359 if (output_result_data(fp)) {
381 static int output_result_header_ST(
struct hecmwST_result_data *result,
char *header, FILE *fp) {
393 while(len <
sizeof(head)-1 && *p && *p !=
'\n') {
404 memcpy(head, tmp,
sizeof(head));
406 rc = fprintf(fp,
"%s\n", head);
416 static int output_result_global_ST(
struct hecmwST_result_data *result,
char *comment, FILE *fp) {
422 if(comment ==
NULL) {
423 comment_line[0] =
'\0';
428 while(len <
sizeof(comment_line)-1 && *p && *p !=
'\n') {
436 rc = fprintf(fp,
"*comment\n");
441 rc = fprintf(fp,
"%s\n", comment);
449 rc = fprintf(fp,
"*global\n");
465 rc = fprintf(fp,
"%d%c", result->
ng_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
473 rc = fprintf(fp,
"\n");
493 for(k=0; k < result->
ng_dof[j]; k++) {
503 rc = fprintf(fp,
"\n");
511 rc = fprintf(fp,
"*data\n");
522 int n_node,
int n_elem, FILE *fp) {
526 rc = fprintf(fp,
"%d %d\n", n_node, n_elem);
543 static int output_result_node_ST(
struct hecmwST_result_data *result,
int n_node, FILE *fp) {
549 rc = fprintf(fp,
"%d%c", result->
nn_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
557 rc = fprintf(fp,
"\n");
566 rc = fprintf(fp,
"%s\n", result->
node_label[i]);
576 for(i=0; i < n_node; i++) {
584 for(k=0; k < result->
nn_dof[j]; k++) {
595 rc = fprintf(fp,
"\n");
607 static int output_result_elem_ST(
struct hecmwST_result_data *result,
int n_elem, FILE *fp) {
613 rc = fprintf(fp,
"%d%c", result->
ne_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
621 rc = fprintf(fp,
"\n");
630 rc = fprintf(fp,
"%s\n", result->
elem_label[i]);
640 for(i=0; i < n_elem; i++) {
648 for(k=0; k < result->
ne_dof[j]; k++) {
659 rc = fprintf(fp,
"\n");
671 static int output_result_data_ST(
struct hecmwST_result_data *result,
int n_node,
int n_elem,
672 char *header,
char *comment, FILE *fp) {
675 if(output_result_header_ST(result, header, fp)) {
679 if(output_result_global_ST(result, comment, fp)) {
683 if(output_result_dataheader_ST(result, n_node, n_elem, fp)) {
686 if(output_result_node_ST(result, n_node, fp)) {
689 if(output_result_elem_ST(result, n_elem, fp)) {
700 int n_node,
int n_elem,
char *header,
char *comment) {
711 if ((fp = fopen(filename,
"w")) ==
NULL) {
717 if (output_result_data_ST(result, n_node, n_elem, header, comment, fp)) {
739 static int get_line(
char *buf,
int bufsize, FILE *fp) {
740 if(fgets(buf, bufsize, fp) ==
NULL) {
744 return strlen(Line_Buf);
752 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
755 Line_Buf[ strlen(Line_Buf)-1 ] = 0;
757 ptr = strtok(Line_Buf,
" ");
758 if(
ptr != Line_Buf) {
759 size_t len = strlen(
ptr);
760 memmove(Line_Buf,
ptr, len + 1);
777 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
780 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
783 Line_Buf[ strlen(Line_Buf)-1 ] = 0;
788 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
793 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
796 if(sscanf(Line_Buf,
"%d", &result->
ng_component) != 1) {
812 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
817 while(i < result->ng_component) {
818 p = strtok(buf,
DELIM);
820 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
827 rc = sscanf(p,
"%d", &result->
ng_dof[i]);
849 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
852 rc = sscanf(Line_Buf,
"%63s",
label);
874 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
880 p = strtok(buf,
DELIM);
882 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
902 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
911 int *n_node,
int *n_elem, FILE *fp) {
914 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
917 if(sscanf(Line_Buf,
"%d%d", n_node, n_elem) != 2) {
923 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
952 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
957 while(i < result->nn_component) {
958 p = strtok(buf,
DELIM);
960 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
967 rc = sscanf(p,
"%d", &result->
nn_dof[i]);
989 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
992 rc = sscanf(Line_Buf,
"%63s",
label);
1019 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1026 while(i < n*n_node) {
1027 p = strtok(buf,
DELIM);
1029 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1040 rc = sscanf(p,
"%lf", &result->
node_val_item[i-label_counter]);
1074 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1079 while(i < result->ne_component) {
1081 p = strtok(buf,
DELIM);
1083 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1090 rc = sscanf(p,
"%d", &result->
ne_dof[i]);
1112 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1115 rc = sscanf(Line_Buf,
"%63s",
label);
1143 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1150 while(i < n*n_elem) {
1151 p = strtok(buf,
DELIM);
1153 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1164 rc = sscanf(p,
"%lf", &result->
elem_val_item[i-label_counter]);
1188 if(result ==
NULL) {
1192 if(input_result_header(result, fp)) {
1196 if(input_result_global(result, fp)) {
1200 if(input_result_dataheader(result, &n_node, &n_elem, fp)) {
1205 if(input_result_node(result, n_node, fp)) {
1208 if(input_result_elem(result, n_elem, fp)) {
1221 if((fp = fopen(filename,
"r")) ==
NULL) {
1226 result = input_result_data(fp);
1227 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