NESSi  v1.0.2
The NonEquilibrium Systems Simulation Library

◆ read_from_file() [1/2]

template<typename T >
void cntr::function< T >::read_from_file ( const char *  file)

Read the function data from a txt file

Purpose

Read the function from a txt file. The data file is probably written by print_to_file method, or is assumed to have the same format.

Parameters
file

the file name

Definition at line 745 of file cntr_function_impl.hpp.

745  {
746  int i, n, l, size1, sg;
747  double real, imag;
748  std::string s;
749  std::ifstream out;
750  out.open(file, std::ios::in);
751  if (!(out >> s >> n >> size1)) {
752  std::cerr << "read function from file " << file << " error in file"
753  << std::endl;
754  abort();
755  }
756  if (n > nt_ || size1 != size1_)
757  resize(n, size1);
758  sg = element_size_;
759  for (i = -1; i <= n; i++) {
760  for (l = 0; l < sg; l++) {
761  if (!(out >> real >> imag)) {
762  std::cerr << "read function from file " << file
763  << " error at t= " << i << std::endl;
764  abort();
765  }
766  ptr(i)[l] = std::complex<T>(real, imag);
767  }
768  }
769  out.close();
770 }
int size1(void) const
void resize(int nt, int size1)
Resize the time length and/or matrix dimension of a square-matrix function
int size1_
Number of the colums in the Matrix form.
int nt_
Maximum number of the time steps.