public static double[] r8mat_data_read(string input_filename, int m, int n) { string[] lines; try { lines = File.ReadLines(input_filename).ToArray(); } catch (Exception) { Console.WriteLine(); Console.WriteLine("R8MAT_DATA_READ - Fatal error!"); Console.WriteLine(" Could not open the input file: \"" + input_filename + "\""); throw; } double[] table = new double[m * n]; int j = 0; int l = 0; while (j < n) { string line = lines[l]; l++; if (line[0] == '#' || s_len_trim(line) == 0) { continue; } r8vec res = s_to_r8vec(line, m); bool error = res.error; double[] x = res.rvec; switch (error) { case false: { int i; for (i = 0; i < m; i++) { table[i + j * m] = x[i]; } break; } } j += 1; } return(table); }
public static void xy_data_read(string input_filename, int point_num, ref double[] xy) //****************************************************************************80 // // Purpose: // // XY_DATA_READ reads the data in an XY file. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 25 October 2010 // // Author: // // John Burkardt // // Parameters: // // Input, string INPUT_FILENAME, the name of the input file. // // Input, int POINT_NUM, the number of points. // // Output, double XY[2*POINT_NUM], the point coordinates. // { string[] input; try { input = File.ReadAllLines(input_filename); } catch (Exception) { Console.WriteLine(""); Console.WriteLine("XY_DATA_READ - Fatal error!"); Console.WriteLine(" Cannot open the input file \"" + input_filename + "\"."); return; } int j = 0; int index = 0; while (j < point_num) { string text; try { text = input[index]; index++; } catch (Exception) { break; } if (text[0] == '#' || typeMethods.s_len_trim(text) == 0) { continue; } // // Extract two real numbers. // r8vec r = typeMethods.s_to_r8vec(text, 2); switch (r.error) { case true: Console.WriteLine(""); Console.WriteLine("XY_DATA_READ - Fatal error!"); Console.WriteLine(" S_TO_R8VEC returned error flag."); return; } xy[0 + j * 2] = r.rvec[0]; xy[1 + j * 2] = r.rvec[1]; j += 1; } }
public static double[] dtable_data_read(string input_filename, int m, int n) //****************************************************************************80 // // Purpose: // // DTABLE_DATA_READ reads the data from a real TABLE file. // // Discussion: // // The file is assumed to contain one record per line. // // Records beginning with the '#' character are comments, and are ignored. // Blank lines are also ignored. // // Each line that is not ignored is assumed to contain exactly (or at least) // M real numbers, representing the coordinates of a point. // // There are assumed to be exactly (or at least) N such records. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 11 October 2003 // // Author: // // John Burkardt // // Parameters: // // Input, char *INPUT_FILENAME, the name of the input file. // // Input, int M, the number of spatial dimensions. // // Input, int N, the number of points. The program // will stop reading data once N values have been read. // // Output, double DTABLE_DATA_READ[M*N], the table data. // { string[] input; try { input = File.ReadAllLines(input_filename); } catch (Exception) { Console.WriteLine(""); Console.WriteLine("DTABLE_DATA_READ - Fatal error!"); Console.WriteLine(" Could not open the input file: \"" + input_filename + "\""); return(null); } double[] table = new double[m * n]; double[] x = new double[m]; int j = 0; int index = 0; while (j < n) { string line; try { line = input[index]; index++; } catch (Exception) { break; } if (line[0] == '#' || s_len_trim(line) == 0) { continue; } r8vec res = s_to_r8vec(line, m); switch (res.error) { case true: continue; } x = res.rvec; int i; for (i = 0; i < m; i++) { table[i + j * m] = x[i]; } j += 1; } return(table); }
public static void data_read(string file_in_name, int dim_num, int n, ref double[] r) //****************************************************************************80 // // Purpose: // // DATA_READ reads generator coordinate data from a file. // // Discussion: // // The file is assumed to contain one record per line. // // Records beginning with the '#' character are comments, and are ignored. // Blank lines are also ignored. // // Each line that is not ignored is assumed to contain exactly (or at least) // M real numbers, representing the coordinates of a point. // // There are assumed to be exactly (or at least) N such records. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 03 August 2004 // // Author: // // John Burkardt // // Parameters: // // Input, char *FILE_IN_NAME, the name of the input file. // // Input, int DIM_NUM, the number of spatial dimensions. // // Input, int N, the number of points. The program // will stop reading data once N values have been read. // // Output, double R[DIM_NUM*N], the point coordinates. // { try { string[] file_in = File.ReadAllLines(file_in_name); int j = 0; foreach (string line in file_in) { if (line[0] == '#' || typeMethods.s_len_trim(line) == 0) { continue; } r8vec t = typeMethods.s_to_r8vec(line, dim_num); double[] x = t.rvec; bool error = t.error; switch (error) { case true: continue; } int i; for (i = 0; i < dim_num; i++) { r[i + j * dim_num] = x[i]; } j += 1; } Console.WriteLine(""); Console.WriteLine("DATA_READ:"); Console.WriteLine(" Read coordinate data from file."); } catch (Exception) { Console.WriteLine(""); Console.WriteLine("DATA_READ - Fatal error!"); Console.WriteLine(" Could not open the input file: \"" + file_in_name + "\""); } }