/* This function add array of strings (passed as string) to a sentence */
sentence add_strings(sentence& temp_entry, const string l) {
  sentence temp=split(l); 
  s_type mm;
  if (temp.size()!=0)
    for (mm=0;mm!=temp.size();mm++)
      temp_entry.push_back(temp[mm]);
  else 
    return temp_entry;
  return temp_entry;
}
/*This function reads the data from the input files*/
void read_input(int argc, char** argv, sentence& sf,string& analysisfile) {
  filedata a; 
  int success_filecounter=0; 
  int leave_index=0;
  // Read the data into the file.
  for (int i=1; i<argc; ++i) {	
    if (!strcmp(argv[i],"-leave")) {
      leave_index=atoi(argv[i+1]);
      i++;
      continue;
    }

     if (!strcmp(argv[i],"-analysis")) {
      analysisfile=argv[i+1];
      i++;
      continue;
    }

    ifstream in(argv[i]);
    if (in) {
      sf.push_back(argv[i]);
      cout << "Reading file    : " << argv[i] << endl;
      if (a.size())
	a.clear();
      readlogfile_multi(a,in,leave_index);
      f.push_back(a);
      in.close();
      success_filecounter++;
    } else {
      cerr << "Cannot open file: " << argv[i] << endl;  
    }
  }

  if(!success_filecounter)
    exit(1);
  else {
    sentence aa;
    int exists;
    cout << endl;
    cout << "Select parameters to plot from following: --- " << endl;
    for (int i=0;i<success_filecounter;i++) {
      for(int j=0;j<f[i][0].size();j++) {
	exists=0;
	for(int k=0;k!=aa.size();k++)
	  if (!f[i][0][j].compare(aa[k])) {
	    exists=1;
	    break;
	  }       
	if (!exists)
	  aa.push_back(f[i][0][j]);
      }
    }

    for(int k=0;k!=aa.size();k++) {
      if (!aa[k].compare("Temp")) aa[k].replace(0,aa[k].length(),"Temp(t)");
      if (!aa[k].compare("Press")) aa[k].replace(0,aa[k].length(),"Press(p)");
      if (!aa[k].compare("Volume")) aa[k].replace(0,aa[k].length(),"Volume(v)");     
      if (!aa[k].compare("E_vdwl")) aa[k].replace(0,aa[k].length(),"E_vdwl(vd)");     
      if (!aa[k].compare("TotEng")) aa[k].replace(0,aa[k].length(),"TotEng(te)");     
      if (!aa[k].compare("KinEng")) aa[k].replace(0,aa[k].length(),"KinEng(ke)");     
      if (!aa[k].compare("PotEng")) aa[k].replace(0,aa[k].length(),"PotEng(pe)");     
      if (!aa[k].compare("E_bond")) aa[k].replace(0,aa[k].length(),"E_bond(be)");     
      if (!aa[k].compare("E_angle")) aa[k].replace(0,aa[k].length(),"E_angle(ae)");     
      if (!aa[k].compare("E_dihed")) aa[k].replace(0,aa[k].length(),"E_dihed(de)");     
      if (!aa[k].compare("E_coul")) aa[k].replace(0,aa[k].length(),"E_coul(ce)");     
      if (!aa[k].compare("E_long")) aa[k].replace(0,aa[k].length(),"E_long(le)");
      cout << aa[k];
      if (aa[k].size()<8) cout << "\t";
      cout << "\t";
      if (k%6==5) cout << endl;
    }
    cout << "\n--------------\n\n";
    cout << "Please enter your parameters in the following format: --- " << endl;
    cout << "1. First string should be 'p' or 's' for plotting parameters from different files in parallel or series" << endl;
    cout << "2. Please enter one or more parameters listed above after entering the first string." << endl;
    cout << "3. For certain parameters, short forms may be used as listed in bracket above" << endl;
    cout << "   ----- Example: To plot total energy, please type 'p te'." << endl;
    cout << "4. In order to plot one parameter with respect to other, please type 'cross' after p/s followed by two parameters" << endl;
    cout << "5. The independent parameter could be 'Step' as mentioned above." << endl;
    cout << "6. Currently, only two parameters can be plotted with respect to each other." << endl;
    cout << "   ----- Example: To plot temperature vs. pressure p cross t p" << endl ;
    cout << "--------------\n\n";
    cout << "For analysis, please exit and use -analysis flag with filename. The file should contain atleast one of these commands: --- " << endl;
    cout << "1. average     all/single_filename startvalue(start) endvalue(end)" << endl;
    cout << "2. scale       filename property factor" << endl;
    cout << "3. inverse     filename property" << endl;
    cout << "4. write       Under Coding" << endl;
    cout << "5. subtract    property1 property2 filename outputpropertyname" << endl;
    cout << "6. add         Under Coding" << endl;
    cout << "--------------\n\n";
  }
}