NESSi  v1.0.2
The NonEquilibrium Systems Simulation Library

◆ read_from_file() [2/2]

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

Read the function data from a txt file

Purpose

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

Parameters
nt1

the number of time steps to be read

file

the file name

Definition at line 790 of file cntr_function_impl.hpp.

790  {
791  int i, n, l, size1, sg;
792  double real, imag;
793  std::string s;
794  std::ifstream out;
795  out.open(file, std::ios::in);
796  if (!(out >> s >> n >> size1)) {
797  std::cerr << "read function from file " << file << " error in file"
798  << std::endl;
799  abort();
800  }
801 
802  assert(nt1 >= -1 && nt1 <= nt_);
803  assert(nt1 <= n);
804  assert(size1 == size1_);
805 
806  sg = size1 * size1;
807  for (i = -1; i <= n; i++) {
808  for (l = 0; l < sg; l++) {
809  if (!(out >> real >> imag)) {
810  std::cerr << "read function from file " << file
811  << " error at t= " << i << std::endl;
812  abort();
813  }
814  if (i <= nt1)
815  ptr(i)[l] = std::complex<T>(real, imag);
816  }
817  }
818  out.close();
819 }
int size1(void) const
int size1_
Number of the colums in the Matrix form.
int nt_
Maximum number of the time steps.