Template:CMI Example get grid values CXX: Difference between revisions

From CSDMS
Automated import of articles
 
Automated import of articles *** existing text overwritten ***
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
   sidl::array<double> vals;
   sidl::array<double> vals;


   std::cout << "val_string = " + long_var_name << std::endl;
   this->log.info ("Getting values.");
   {
   {
     int len = 0;
     int len = 0;
Line 10: Line 10:
     int stride[1] = {1};
     int stride[1] = {1};


    fprintf (stderr, "%s: Call BMI_Get_double.
", CMI_COMPONENT_NAME);
     data = this->state.get_double (long_var_name, len);
     data = this->state.get_double (long_var_name, len);
    fprintf (stderr, "%s: n_vals=%d.
", CMI_COMPONENT_NAME, len);
    fprintf (stderr, "%s: vals[0]=%f.
", CMI_COMPONENT_NAME, data[0]);
    fprintf (stderr, "%s: vals[1]=%f.
", CMI_COMPONENT_NAME, data[0]);
    fprintf (stderr, "%s: vals[2]=%f.
", CMI_COMPONENT_NAME, data[0]);
    fprintf (stderr, "%s: vals[len-1]=%f.
", CMI_COMPONENT_NAME, data[len-1]);


     upper[0] = len-1;
     upper[0] = len-1;
Line 30: Line 17:


   }
   }
  this->log.info ("Got values.");


   return vals;
   return vals;
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 12:01, 6 February 2012

  sidl::array<double> vals;

  this->log.info ("Getting values.");
  {
    int len = 0;
    double * data;
    int lower[1] = {0};
    int upper[1];
    int stride[1] = {1};

    data = this->state.get_double (long_var_name, len);

    upper[0] = len-1;

    vals.borrow (data, 1, lower, upper, stride);

  }
  this->log.info ("Got values.");

  return vals;