// elastic_genTerm - A linear solver for elastic problems using FEM
// Copyright (C) 2010-2026 Eric Bechet
//
// See the LICENSE file for license information and contributions.
// Please report all bugs and problems to <bechet@cadxfem.org>.

#ifndef _LECTURE_DATA_H
#define _LECTURE_DATA_H

#include <complex>
#include <vector>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include "genDataIO.h"

class lectureData
{
public :
  std::string filename;
  std::vector<std::vector<std::complex<double> > > vector;
  int row, column;
  double kp, ks, kp_int, ks_int;
public :
  lectureData(std::string filename_) : filename(filename_) {readData(filename);}
  
  ~lectureData() {}
  inline void readComment(std::istream &is, std::string &token) {
    is >> token;
    if(token == "#"){
      is >> token;
      if(token == "rows:"){
	is >> token;
	row = atoi(token.c_str());
      }
      else if(token == "columns:"){
	is >> token;
	column = atoi(token.c_str());
	vector.resize(row);
	for(int i=0; i<row; i++)
	  vector[i].resize(column);
      }
      else if(token=="kp:"){
	is >> token;
	kp = atof(token.c_str());
      }
      else if(token=="ks:"){
	is >> token;
	ks = atof(token.c_str());
      }
      else if(token=="kp_int:"){
	is >> token;
	kp_int = atof(token.c_str());
      }
      else if(token=="ks_int:"){
	is >> token;
	ks_int = atof(token.c_str());
      }
      else
	getline(is,token);
    }
  }
  
  inline void readValue(std::istream &is, std::complex<double> &s){
    for(int i=0; i<row; i++){
      for(int j=0; j<column; j++){
	readScalar(is, s);
	vector[i][j] = s;
      }
    }
  }
  
  inline void readData(std::string &filename){
    std::ifstream myfile(filename.c_str());
    if(myfile.is_open()){
      std::string token;
      while(!myfile.eof()){
	while(vector.empty()){
	  readComment(myfile,token);
	}
	std::complex<double> x;
	readValue(myfile,x);
	myfile >> token;
      }
      myfile.close();
    }
    else{
      std::cout << "unable to open file" << std::endl;
      exit(0);
    }    
  }

};



#endif
 