2 #include <athena/athena_arrays.hpp>
11 FILE *fp = fopen(fname,
"r");
14 fscanf(fp,
"%d%d", rows, cols);
21 while (fgets(buf, 256, fp) != NULL) {
22 p = std::strtok(buf,
" ,");
25 sscanf(
p,
"%lf", &
data[irow][icol]);
26 p = std::strtok(NULL,
" ,");
27 assert(icol++ < *cols);
29 assert(irow++ < *rows);
40 std::stringstream inp(str_file);
43 std::getline(inp, line);
44 int rows = 0, cols = 0;
47 cols = line[0] == c ? 0 : 1;
48 for (
int i = 1; i < line.length(); ++i)
49 if (line[i - 1] == c && line[i] != c) cols++;
51 while (std::getline(inp, line)) ++rows;
58 data->NewAthenaArray(rows, cols);
59 std::stringstream inp2(str_file);
62 for (
int i = 0; i < rows; ++i)
63 for (
int j = 0; j < cols; ++j) inp2 >> (*data)(i,
j);
std::string DecommentFile(std::string fname)
decomment a file
void NewCArray(T **&a, int n1, int n2)
void ReadDataTable(AthenaArray< Real > *data, std::string fname, char c)
void read_data_table(char const *fname, double **data, int *rows, int *cols)