// Location: // // http://people.sc.fsu.edu/~jburkardt/freefem_src/io_test/io_test.edp // // Discussion: // // This example illustrates how FreeFem++ can read and write text files. // // Note that a file containing a vector must have an initial record // listing the number of elements in the file. Thus, the file "input.txt" // has the form: // // 11 // 0 1 2 3 4 // 5 6 7 8 9 // 10 // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 04 February 2015 // // Reference: // // John Chrispell, Jason Howell, // Finite Element Approximation of Partial Differential Equations // Using FreeFem++, or, How I Learned to Stop Worrying and Love // Numerical Analysis. // // Frederic Hecht, // New development in FreeFem++, // Journal of Numerical Mathematics, // Volume 20, Number 3-4, 2012, pages 251-265. // cout << "\n"; cout << "io_test:\n"; cout << " FreeFem++ version\n"; cout << " Read values from the file 'input.txt'\n"; cout << " Write their square roots to the file 'output.txt'\n"; // // Declare IN to be an input unit. // ifstream in ( "input.txt" ); // // Declare U to be a real array indexed by integers. // real[int] u(11); // // Read data from "input.txt" into U. // in >> u; // // Declare V to be a real array indexed by integers. // real[int] v(11); // // Manipulate the data and print it to convince us it got here. // for ( int j = 0; j < 11; j++ ) { v[j] = sqrt ( u[j] ); cout << " " << u[j] << " " << v[j] << "\n"; } // // Declare OUT to be an output unit. // ofstream out ( "output.txt" ); // // Write V to the output unit. // out << v; // // Terminate. // cout << "\n"; cout << "io_test\n"; cout << " Normal end of execution.\n"; exit ( 0 );