DLL_API ZON_zone_t * get_zone_from_list( ZON_zone_list_t * zones, int i) { if (zones == NULL) return NULL; else return ZON_zone_list_get (zones, i); }
/** * Responds to a last day event by computing output variables that are only * needed on the last day. * * @param self the model. * @param zones a list of zones. * @param event a last day event. */ void handle_last_day_event (struct ergadm_model_t_ *self, ZON_zone_list_t * zones, EVT_new_day_event_t * event) { local_data_t *local_data; gboolean skip_shape, skip_area, skip_num_areas, skip_num_units; int i; ZON_zone_t *zone, *next_smaller_zone; GString *s; double area; #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- ENTER handle_last_day_event (%s)", MODEL_NAME); #endif local_data = (local_data_t *) (self->model_data); /* Some of the output variables are computationally intensive. If they're * reported "never", or if they were already computed today by * handle_new_day_event, don't bother to compute them. */ skip_shape = local_data->shape->frequency == RPT_never || RPT_reporting_due (local_data->shape, event->day); skip_area = local_data->area->frequency == RPT_never || RPT_reporting_due (local_data->area, event->day); skip_num_areas = local_data->num_separate_areas->frequency == RPT_never || RPT_reporting_due (local_data->num_separate_areas, event->day); skip_num_units = local_data->num_units->frequency == RPT_never || RPT_reporting_due (local_data->num_units, event->day); /* We don't have to worry about num_animal_days_by_prodtype because, unless * it's set to be reported "never", it will be updated every day by * handle_new_day_event. */ for (i = 0; i < local_data->nzones; i++) { zone = ZON_zone_list_get (zones, i); if (!skip_shape) { s = polygon_to_wkt (zone->poly); RPT_reporting_set_text1 (local_data->shape, s->str, zone->name); /* The string was copied so it can be freed. */ g_string_free (s, TRUE); } if (!skip_area) { area = ZON_update_area (zone); RPT_reporting_set_real1 (local_data->area, area, zone->name); } if (!skip_num_areas) RPT_reporting_set_integer1 (local_data->num_separate_areas, zone->poly->num_contours, zone->name); } if (!skip_area) { /* Start with the next-to-last zone, because the last one is the * "background" zone. */ for (i = local_data->nzones - 2; i > 0; i--) { zone = ZON_zone_list_get (zones, i); next_smaller_zone = ZON_zone_list_get (zones, i - 1); zone->area -= next_smaller_zone->area; RPT_reporting_set_real1 (local_data->area, zone->area, zone->name); } } if (!skip_num_units) { for (i = 0; i < local_data->nzones; i++) { zone = ZON_zone_list_get (zones, i); RPT_reporting_set_integer1 (local_data->num_units, 0, zone->name); } for (i = 0; i < zones->membership_length; i++) { zone = zones->membership[i]->parent; RPT_reporting_add_integer1 (local_data->num_units, 1, zone->name); } } #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT handle_last_day_event (%s)", MODEL_NAME); #endif }
/** * Responds to a new day event by updating the reporting variables. * * @param self the model. * @param herds a list of herds. * @param zones a list of zones. * @param event a new day event. */ void handle_new_day_event (struct ergadm_model_t_ *self, HRD_herd_list_t * herds, ZON_zone_list_t * zones, EVT_new_day_event_t * event) { local_data_t *local_data; gboolean shape_due, area_due, num_areas_due, num_units_due; int i; ZON_zone_t *zone, *next_smaller_zone; GString *s; double area; unsigned int nherds; HRD_herd_t *herd; char *drill_down_list[3] = { NULL, NULL, NULL }; #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- ENTER handle_new_day_event (%s)", MODEL_NAME); #endif local_data = (local_data_t *) (self->model_data); shape_due = RPT_reporting_due (local_data->shape, event->day); area_due = RPT_reporting_due (local_data->area, event->day); num_areas_due = RPT_reporting_due (local_data->num_separate_areas, event->day); num_units_due = RPT_reporting_due (local_data->num_units, event->day); for (i = 0; i < local_data->nzones; i++) { zone = ZON_zone_list_get (zones, i); if (shape_due) { s = polygon_to_wkt (zone->poly); RPT_reporting_set_text1 (local_data->shape, s->str, zone->name); /* The string was copied so it can be freed. */ g_string_free (s, TRUE); } if (area_due) { area = ZON_update_area (zone); RPT_reporting_set_real1 (local_data->area, area, zone->name); } if (num_areas_due) RPT_reporting_set_integer1 (local_data->num_separate_areas, zone->poly->num_contours, zone->name); } /* In the loop above, the area of each zone polygon was computed. But since * zones are nested inside of each other, that's not exactly what we want: * we want the area displayed for an "outer" zone to exclude the area of the * smaller "inner" zones. So we do that computation here. */ if (area_due) { /* Start with the next-to-last zone, because the last one is the * "background" zone. */ for (i = local_data->nzones - 2; i > 0; i--) { zone = ZON_zone_list_get (zones, i); next_smaller_zone = ZON_zone_list_get (zones, i - 1); zone->area -= next_smaller_zone->area; RPT_reporting_set_real1 (local_data->area, zone->area, zone->name); if (NULL != guilib_record_zone_area) guilib_record_zone_area (zone->level, zone->area); } /* Don't forget to report the smallest zone to the GUI! */ if (NULL != guilib_record_zone_area) { zone = ZON_zone_list_get (zones, 0); guilib_record_zone_area (zone->level, zone->area); } } if (local_data->num_animal_days_by_prodtype->frequency != RPT_never || num_units_due) { nherds = zones->membership_length; for (i = 0; i < local_data->nzones; i++) { zone = ZON_zone_list_get (zones, i); RPT_reporting_set_integer1 (local_data->num_units, 0, zone->name); } for (i = 0; i < nherds; i++) { zone = zones->membership[i]->parent; RPT_reporting_add_integer1 (local_data->num_units, 1, zone->name); herd = HRD_herd_list_get (herds, i); if (herd->status != Destroyed) { drill_down_list[0] = herd->production_type_name; drill_down_list[1] = zone->name; RPT_reporting_add_integer (local_data->num_animal_days_by_prodtype, herd->size, drill_down_list); } } } #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT handle_new_day_event (%s)", MODEL_NAME); #endif }
/** * Returns a text representation of this model. * * @param self the model. * @return a string. */ char * to_string (struct naadsm_model_t_ *self) { GString *s; unsigned int i, j; char *chararray; local_data_t *local_data = (local_data_t *) (self->model_data); unsigned int nzones = ZON_zone_list_length (local_data->zones); unsigned int nprod_types = local_data->production_types->len; destruction_cost_data_t **destruction_cost_params = local_data->destruction_cost_params; vaccination_cost_data_t **vaccination_cost_params = local_data->vaccination_cost_params; double **surveillance_cost_param = local_data->surveillance_cost_param; s = g_string_new (NULL); g_string_sprintf (s, "<%s", MODEL_NAME); for (i = 0; i < nprod_types; i++) { if ((destruction_cost_params && destruction_cost_params[i]) || (vaccination_cost_params && vaccination_cost_params[i])) { g_string_append_printf (s, "\n for %s", (char *) g_ptr_array_index (local_data->production_types, i)); if (destruction_cost_params && destruction_cost_params[i]) { destruction_cost_data_t *params = local_data->destruction_cost_params[i]; g_string_sprintfa (s, "\n appraisal (per unit)=%g\n", params->appraisal); g_string_sprintfa (s, " euthanasia (per animal)=%g\n", params->euthanasia); g_string_sprintfa (s, " indemnification (per animal)=%g\n", params->indemnification); g_string_sprintfa (s, " carcass-disposal (per animal)=%g\n", params->carcass_disposal); g_string_sprintfa (s, " cleaning-disinfecting (per unit)=%g", params->cleaning_disinfecting); } if (vaccination_cost_params && vaccination_cost_params[i]) { vaccination_cost_data_t *params = local_data->vaccination_cost_params[i]; g_string_sprintfa (s, "\n vaccination-fixed (per unit)=%g\n", params->vaccination_fixed); g_string_sprintfa (s, " vaccination (per animal)=%g\n", params->vaccination); g_string_sprintfa (s, " baseline-capacity=%u\n", params->baseline_capacity); g_string_sprintfa (s, " additional-vaccination (per animal)=%g", params->extra_vaccination); } } } if (surveillance_cost_param) { for (i = 0; i < nzones; i++) { if (surveillance_cost_param[i]) { for (j = 0; j < nprod_types; j++) { if (surveillance_cost_param[i][j] != 0) { g_string_append_printf (s, "\n for %s in %s", (char *) g_ptr_array_index (local_data->production_types, j), ZON_zone_list_get (local_data->zones, i)->name); g_string_sprintfa (s, "\n surveillance (per animal, per day)=%g", surveillance_cost_param[i][j]); } } } } } g_string_append_c (s, '>'); /* don't return the wrapper object */ chararray = s->str; g_string_free (s, FALSE); return chararray; }