////////////////////////////////////////////////////////////////
//
// utilities.h
// Copyright (c) 2002 by Wesley H. Huang.  All rights reserved.
// 
////////////////////////////////////////////////////////////////
#ifndef UTILITIES_H
#define UTILITIES_H

#include <fstream>
#include <string>
using namespace std;

// utilities for reading files
void skipComments(std::ifstream& f);
string getWord(char *parameter, char *description, std::ifstream &inpFile, 
	       bool verbose=false);
double getNumber(char *parameter, char *description, std::ifstream &inpFile,
		 bool verbose=false);

// Get a list of numbers (space separated) for a declaration.  The
// pointer "results" must have enough memory to store all the numbers.
//
template<class T> void getNumbers(char *parameter, char *description, 
				  ifstream &inpFile,
				  int numNumbers, T *results,
				  bool verbose=false)
{
  string tmp;
  if (verbose) cout << "Looking for " << description << " declaration..." 
		    << endl;
  skipComments(inpFile);
  if (inpFile.eof())
    cerr << "Hey, we've reached the end of the file!" << endl;
  inpFile >> tmp;
  if (tmp != parameter) {
    cerr << "Didn't find the " << description << " declaration;"  <<
      "Instead found \"" << tmp << "\"." << endl;
    exit(1);
  }
  for (int k = 0; k < numNumbers; k++) {
    inpFile >> results[k];
  }
  if (verbose) {
    cout << "The " << description << " is: ";
    for (int k=0; k<numNumbers; k++) 
      cout << results[k] << " ";
    cout << endl;
  }
}



#endif

