Commit 51dc54ab authored by Claes Sjofors's avatar Claes Sjofors

GeCurve, read of csv file added

parent 7efec626
...@@ -1611,6 +1611,10 @@ int GeCurve::read_file(char* filename) ...@@ -1611,6 +1611,10 @@ int GeCurve::read_file(char* filename)
pwr_tFileName fname; pwr_tFileName fname;
int i, j; int i, j;
int skip_line; int skip_line;
int pyformat = 0;
pwr_tTime time, start_time;
pwr_tDeltaTime dt;
pwr_tStatus sts;
dcli_translate_filename(fname, filename); dcli_translate_filename(fname, filename);
...@@ -1626,8 +1630,15 @@ int GeCurve::read_file(char* filename) ...@@ -1626,8 +1630,15 @@ int GeCurve::read_file(char* filename)
fprintf(stderr, "Error! Cannot read curve file: '%s'!\n", fname); fprintf(stderr, "Error! Cannot read curve file: '%s'!\n", fname);
return 0; return 0;
} }
nr = dcli_parse(line, " ", "", (char*)item_str, if (strncmp(line, "Time,", 5) == 0)
sizeof(item_str) / sizeof(item_str[0]), sizeof(item_str[0]), 0); pyformat = 1;
if (pyformat)
nr = dcli_parse(line, ",", "", (char*)item_str,
sizeof(item_str) / sizeof(item_str[0]), sizeof(item_str[0]), 0);
else
nr = dcli_parse(line, " ", "", (char*)item_str,
sizeof(item_str) / sizeof(item_str[0]), sizeof(item_str[0]), 0);
if (nr == 0) { if (nr == 0) {
fclose(fp); fclose(fp);
fprintf(stderr, "Error! Cannot parse curve file: '%s'!\n", fname); fprintf(stderr, "Error! Cannot parse curve file: '%s'!\n", fname);
...@@ -1667,22 +1678,56 @@ int GeCurve::read_file(char* filename) ...@@ -1667,22 +1678,56 @@ int GeCurve::read_file(char* filename)
j = 0; j = 0;
while (dcli_read_line(line, sizeof(line), fp)) { while (dcli_read_line(line, sizeof(line), fp)) {
dcli_parse(line, " ", "", (char*)item_str, if (pyformat) {
sizeof(item_str) / sizeof(item_str[0]), sizeof(item_str[0]), 0); dcli_parse(line, ",", "", (char*)item_str,
skip_line = 0; sizeof(item_str) / sizeof(item_str[0]), sizeof(item_str[0]), 0);
for (i = 0; i < cd->cols + 1; i++) { skip_line = 0;
if (i == 0) for (i = 0; i < cd->cols + 1; i++) {
nr = sscanf(item_str[i], "%lf", &cd->x_data[i][j]); if (i == 0) {
else sts = time_FormAsciiToA(item_str[i], HUNDRED, 0, &time);
nr = sscanf(item_str[i], "%lf", &cd->y_data[i - 1][j]); if (ODD(sts)) {
if (nr != 1) { if (j == 0) {
if (i == 0) { start_time = time;
printf("Unreadble line %d\n", j); cd->x_data[i][j] = 0;
skip_line = 1; } else {
cd->rows[0]--; time_Adiff(&dt, &time, &start_time);
break; time_DToFloat64(&cd->x_data[i][j], &dt);
} else }
cd->y_data[i - 1][j] = 0; nr = 1;
}
else
nr = 0;
}
else
nr = sscanf(item_str[i], "%lf", &cd->y_data[i - 1][j]);
if (nr != 1) {
if (i == 0) {
printf("Unreadble line %d\n", j);
skip_line = 1;
cd->rows[0]--;
break;
} else
cd->y_data[i - 1][j] = 0;
}
}
} else {
dcli_parse(line, " ", "", (char*)item_str,
sizeof(item_str) / sizeof(item_str[0]), sizeof(item_str[0]), 0);
skip_line = 0;
for (i = 0; i < cd->cols + 1; i++) {
if (i == 0)
nr = sscanf(item_str[i], "%lf", &cd->x_data[i][j]);
else
nr = sscanf(item_str[i], "%lf", &cd->y_data[i - 1][j]);
if (nr != 1) {
if (i == 0) {
printf("Unreadble line %d\n", j);
skip_line = 1;
cd->rows[0]--;
break;
} else
cd->y_data[i - 1][j] = 0;
}
} }
} }
if (skip_line) if (skip_line)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment