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

From CSDMS
Automated import of articles *** existing text overwritten ***
Automated import of articles *** existing text overwritten ***
 
Line 1: Line 1:
<syntaxhighlight lang=cpp>
<syntaxhighlight lang=cpp>


     fprintf (stderr, "%s: Setting %s.
     this->log.info ("Setting values.");
", CMI_COMPONENT_NAME,
        long_var_name.c_str ());
 
     { // Set values through the c-array
     { // Set values through the c-array
       const int n_dim = 1;
       const int n_dim = 1;
Line 12: Line 9:
       double * vals_ptr = vals.first ();
       double * vals_ptr = vals.first ();


      fprintf (stderr, "%s: Calling BMI_Set_double.
", CMI_COMPONENT_NAME);
       shape[0] =  len;
       shape[0] =  len;
       this->state.set_double (long_var_name, vals_ptr, n_dim, shape);
       this->state.set_double (long_var_name, vals_ptr, n_dim, shape);
      /*
      {
        double * y = this->state.get_grid_y (long_var_name, len);
        for (int i=0; i<len; i++)
          fprintf (stderr, "%f, %f: %f
", x[i], y[i], vals_ptr[i]);
        fflush (stderr);
      }
      */


       delete [] x;
       delete [] x;
     }
     }


     fprintf (stderr, "%s: Values are set.
     this->log.info ("Set values.");
", CMI_COMPONENT_NAME);
     return;
     return;
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 12:02, 6 February 2012

    this->log.info ("Setting values.");
    { // Set values through the c-array
      const int n_dim = 1;
      int shape[1];
      int len;
      double * x = this->state.get_grid_x (long_var_name, len);
      double * vals_ptr = vals.first ();

      shape[0] =  len;
      this->state.set_double (long_var_name, vals_ptr, n_dim, shape);

      delete [] x;
    }

    this->log.info ("Set values.");
    return;