/**
 * \file ScalarVariable.h
 *
 * $Id$
 */
#ifndef _SCALARVARIABLE_H_
#define _SCALARVARIABLE_H_

#include "Variable.h"
#include "SphericalGrid.h"
#include <assert.h>

//using namespace std;

class ScalarVariable : public Variable
{
 public:
  // c-tors:
  explicit
    ScalarVariable( const SphericalGrid& grid, const char* n=" - ", const char* u="", const char *ln="",
                      // Two optional args to define valid range in the constructor.
                      // If both values are 0.0 this means they are not set,
                      // and thus no range validity check can be made at run time.
                      const double min = -1e10 /*0.0*/, const double max = 1e10 /*-1.0*/ )
    : Variable( grid, n, u, ln, SCALAR, 0, min, max /* , missing_value, timedependent */ )
  {};
 ScalarVariable( const ScalarVariable& nv ) : Variable( nv ) {};
  ~ScalarVariable(void) {};

  void Write(double x) { ISVALIDVAL(x,0); data[0] = x; };
  double Read() const { return data[0]; };

  // Copy data values to/from doubles
  // This is useful for NetCDFInput/Output, and necessary for coupling
  // with FMS/MOM4.

  // Put contents from a ScalarVariable into an F90 array of size 1.
  template <typename T>
    inline void to_F90(T *const sv_out) {
    //printf("%s %s\n", __FILE__, __FUNCTION__);
    sv_out[0] = static_cast<T>(data[0]);
  }

  // Get contents from an F90 array of size 1 into a ScalarVariable.
  template <typename T>
    inline void from_F90(const T *const sv_in) {
    //printf("%s %s\n", __FILE__, __FUNCTION__);
    data[0] = sv_in[0];
    //fflush(stdout);
    ISVALIDTHIS;
  }

};

#endif /* _SCALARVARIABLE_H_ */
