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 memcpy(head, tmp,
sizeof(head));
407 rc = fprintf(fp,
"%s\n", head);
417 static int output_result_global_ST(
struct hecmwST_result_data *result,
char *comment, FILE *fp) {
423 if(comment ==
NULL) {
424 comment_line[0] =
'\0';
429 while(len <
sizeof(comment_line)-1 && *p && *p !=
'\n') {
437 rc = fprintf(fp,
"*comment\n");
442 rc = fprintf(fp,
"%s\n", comment);
450 rc = fprintf(fp,
"*global\n");
466 rc = fprintf(fp,
"%d%c", result->
ng_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
474 rc = fprintf(fp,
"\n");
494 for(k=0; k < result->
ng_dof[j]; k++) {
504 rc = fprintf(fp,
"\n");
512 rc = fprintf(fp,
"*data\n");
523 int n_node,
int n_elem, FILE *fp) {
527 rc = fprintf(fp,
"%d %d\n", n_node, n_elem);
544 static int output_result_node_ST(
struct hecmwST_result_data *result,
int n_node, FILE *fp) {
550 rc = fprintf(fp,
"%d%c", result->
nn_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
558 rc = fprintf(fp,
"\n");
567 rc = fprintf(fp,
"%s\n", result->
node_label[i]);
577 for(i=0; i < n_node; i++) {
585 for(k=0; k < result->
nn_dof[j]; k++) {
596 rc = fprintf(fp,
"\n");
608 static int output_result_elem_ST(
struct hecmwST_result_data *result,
int n_elem, FILE *fp) {
614 rc = fprintf(fp,
"%d%c", result->
ne_dof[i], (n+1)%
COL_INT ?
' ' :
'\n');
622 rc = fprintf(fp,
"\n");
631 rc = fprintf(fp,
"%s\n", result->
elem_label[i]);
641 for(i=0; i < n_elem; i++) {
649 for(k=0; k < result->
ne_dof[j]; k++) {
660 rc = fprintf(fp,
"\n");
672 static int output_result_data_ST(
struct hecmwST_result_data *result,
int n_node,
int n_elem,
673 char *header,
char *comment, FILE *fp) {
676 if(output_result_header_ST(result, header, fp)) {
680 if(output_result_global_ST(result, comment, fp)) {
684 if(output_result_dataheader_ST(result, n_node, n_elem, fp)) {
687 if(output_result_node_ST(result, n_node, fp)) {
690 if(output_result_elem_ST(result, n_elem, fp)) {
701 int n_node,
int n_elem,
char *header,
char *comment) {
712 if ((fp = fopen(filename,
"w")) ==
NULL) {
718 if (output_result_data_ST(result, n_node, n_elem, header, comment, fp)) {
740 static int get_line(
char *buf,
int bufsize, FILE *fp) {
741 if(fgets(buf, bufsize, fp) ==
NULL) {
745 return strlen(Line_Buf);
753 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
756 Line_Buf[ strlen(Line_Buf)-1 ] = 0;
758 ptr = strtok(Line_Buf,
" ");
759 if(
ptr != Line_Buf) {
760 size_t len = strlen(
ptr);
761 memmove(Line_Buf,
ptr, len + 1);
778 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
781 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
784 Line_Buf[ strlen(Line_Buf)-1 ] = 0;
789 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
794 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
797 if(sscanf(Line_Buf,
"%d", &result->
ng_component) != 1) {
813 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
818 while(i < result->ng_component) {
819 p = strtok(buf,
DELIM);
821 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
828 rc = sscanf(p,
"%d", &result->
ng_dof[i]);
850 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
853 rc = sscanf(Line_Buf,
"%63s",
label);
875 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
881 p = strtok(buf,
DELIM);
883 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
903 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
912 int *n_node,
int *n_elem, FILE *fp) {
915 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
918 if(sscanf(Line_Buf,
"%d%d", n_node, n_elem) != 2) {
924 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
953 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
958 while(i < result->nn_component) {
959 p = strtok(buf,
DELIM);
961 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
968 rc = sscanf(p,
"%d", &result->
nn_dof[i]);
990 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
993 rc = sscanf(Line_Buf,
"%63s",
label);
1020 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1027 while(i < n*n_node) {
1028 p = strtok(buf,
DELIM);
1030 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1041 rc = sscanf(p,
"%lf", &result->
node_val_item[i-label_counter]);
1075 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1080 while(i < result->ne_component) {
1082 p = strtok(buf,
DELIM);
1084 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1091 rc = sscanf(p,
"%d", &result->
ne_dof[i]);
1113 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1116 rc = sscanf(Line_Buf,
"%63s",
label);
1144 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1151 while(i < n*n_elem) {
1152 p = strtok(buf,
DELIM);
1154 if(get_line(Line_Buf,
sizeof(Line_Buf), fp) < 0) {
1165 rc = sscanf(p,
"%lf", &result->
elem_val_item[i-label_counter]);
1189 if(result ==
NULL) {
1193 if(input_result_header(result, fp)) {
1197 if(input_result_global(result, fp)) {
1201 if(input_result_dataheader(result, &n_node, &n_elem, fp)) {
1206 if(input_result_node(result, n_node, fp)) {
1209 if(input_result_elem(result, n_elem, fp)) {
1222 if((fp = fopen(filename,
"r")) ==
NULL) {
1227 result = input_result_data(fp);
1228 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