Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement standard definitions of Set_value & Set_value_at_indices #104

Closed
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/bmi_cfe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ static int Get_value (Bmi *self, const char *name, void *dest)


static int Set_value_at_indices (Bmi *self, const char *name, int * inds, int len, void *src)
{
/*{
if (len < 1)
return BMI_FAILURE;

Expand Down Expand Up @@ -2029,22 +2029,46 @@ static int Set_value_at_indices (Bmi *self, const char *name, int * inds, int le
}

return BMI_SUCCESS;
}*/

// JG: 02.05.2024 - Implementing "standard" BMI definition
{
void * to = NULL;
int itemsize = 0;

if (self->get_value_ptr (self, name, &to) == BMI_FAILURE)
return BMI_FAILURE;

if (self->get_var_itemsize(self, name, &itemsize) == BMI_FAILURE)
return BMI_FAILURE;

{ /* Copy the data */
size_t i;
size_t offset;
char * ptr;
for (i=0, ptr=(char*)src; i<len; i++, ptr+=itemsize) {
offset = inds[i] * itemsize;
memcpy ((char*)to + offset, ptr, itemsize);
}
}
return BMI_SUCCESS;
}


static int Set_value (Bmi *self, const char *name, void *array)
{
// Avoid using set value, call instead set_value_at_index
/* // Avoid using set value, call instead set_value_at_index
// Use nested call to "by index" version

// Here, for now at least, we know all the variables are scalar, so
int inds[] = {0};

// Then we can just ...
return Set_value_at_indices(self, name, inds, 1, array);
return Set_value_at_indices(self, name, inds, 1, array);*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only works for doubles and not for array of doubles, so it will potentially break the coupling with soil_moisture_profile which is used in rootzone-based AET.



/* This is the sample code from read the docs
// This is the sample code from read the docs
// JG: 02.05.2024 - Implementing "standard" BMI definition
void * dest = NULL;
int nbytes = 0;

Expand All @@ -2057,7 +2081,7 @@ static int Set_value (Bmi *self, const char *name, void *array)
memcpy (dest, array, nbytes);

return BMI_SUCCESS;
*/

}


Expand Down
Loading