// colorDrawings.cpp  P. Conrad for CISC181, proj1, 03/20/2007
// define functions to add color to gnuplot drawings

string gnuplotLineStyle(string color)
{
  if (	color == "red")
    return "lt 1";
  else if (color == "green")
    return "lt 2";
  else if (color == "blue")
    return "lt 3";
  else
    {
      cerr << "Error: Illegal color: " << color 
 	   << " in gnuplotLineStyle" << endl;
      exit(2);	
    }
  
}

void writeGnuplotFileWithMultipleColors
(
 const char * const gnuplotFileName, 
 const int numFiles,
 const string * const dataFileNames, 
 const string * const colors,
 const char * const pngFileName,
 const double height, 
 const double width)
{
  ofstream gnpfile(gnuplotFileName,ios::out); 
  
  if (!gnpfile)
    {
      cerr << "Couldn't open file " << gnuplotFileName << " sorry!" << endl;
      exit(3);
    }
  
  gnpfile << "set xrange [-1:" << width << "]\n"
 	  << "set yrange [-1:" << height  << "]\n"
 	  << "set output \"" << pngFileName << "\" \n"
 	  << "set terminal png large color\n"
 	  << "set size ratio -1\n" // negative preserves even aspect ratio
 	  << "set nokey\n"
 	  << "plot \"" << dataFileNames[0] << "\" with lines "
 	  << gnuplotLineStyle(colors[0]);
  
  for (int i=1; i<numFiles; i++)
    {
      gnpfile << ", \"" << dataFileNames[i] << "\" with lines " 
 	      << gnuplotLineStyle(colors[i]);
      
    }
  gnpfile << endl;
  gnpfile.close();
  return;  
  
}


