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> | |||
fprintf (stderr, "%s: Setting %s. | |||
", CMI_COMPONENT_NAME, | |||
long_var_name.c_str ()); | |||
{ // 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 (); | |||
fprintf (stderr, "%s: Calling BMI_Set_double. | |||
", CMI_COMPONENT_NAME); | |||
shape[0] = len; | |||
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; | |||
} | |||
fprintf (stderr, "%s: Values are set. | |||
", CMI_COMPONENT_NAME); | |||
return; | |||
</syntaxhighlight> |
Revision as of 18:33, 1 February 2012
fprintf (stderr, "%s: Setting %s.
", CMI_COMPONENT_NAME,
long_var_name.c_str ());
{ // 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 ();
fprintf (stderr, "%s: Calling BMI_Set_double.
", CMI_COMPONENT_NAME);
shape[0] = len;
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;
}
fprintf (stderr, "%s: Values are set.
", CMI_COMPONENT_NAME);
return;