Exemple #1
0
int main(int argc, char **argv)
{
    parse_args(argc, argv);

    SDSInfo *sds = open_any_sds(opts.infile);
    if (!sds) {
        fesc_bold(stderr);
        fputs(opts.infile, stderr);
        fesc_stop(stderr);
        fputs(": error opening file\n", stderr);
        return -2;
    }

    switch (opts.out_type) {
    case FULL_SUMMARY:
        print_full_summary(sds);
        break;
    case LIST_ATTS:
        print_list_atts(sds);
        break;
    case LIST_DIMS:
        print_list_dims(sds);
        break;
    case LIST_VARS:
        print_list_vars(sds->vars);
        break;
    case LIST_DIM_SIZES:
        if (opts.name)
            print_var_dim_sizes(sds);
        else
            print_dim_sizes(sds);
        break;
    case PRINT_ATTS:
        print_atts_values(sds);
        break;
    case PRINT_VAR:
        print_var_values(sds);
        break;
    default:
        abort();
    }

    sds_close(sds);

    return 0;
}
Exemple #2
0
int
main (void)
{
  int i;
  const int n_steps = 10;
  BMI_Model *self = NULL;
  double *new_vals = NULL;
  int err = 0;

  //self = BMI_Initialize (NULL);
  err = BMI_Initialize (NULL, &self);
  if (err || !self)
    return EXIT_FAILURE;

  {
    char name[BMI_MAX_COMPONENT_NAME];
    BMI_Get_component_name (self, name);
  
    fprintf (stdout, "%s\n", name);
  }

  { /* Get grid information */
    int n_dims;
    int *shape;
    int len = 0;
    int i;

    BMI_Get_var_rank (self, "surface_elevation", &n_dims);
    shape = (int*) malloc (sizeof (int)*n_dims);

    BMI_Get_grid_shape (self, "surface_elevation", shape);
    for (i = 0, len = 1; i < n_dims; i++)
      len *= shape[i];

    new_vals = (double *)malloc (sizeof (double) * len);
    for (i = 0; i < len; i++)
      new_vals[i] = -1;

    free (shape);
  }

  fprintf (stdout, "Values before set\n");
  fprintf (stdout, "=================\n");
  print_var_values (self, "surface_elevation");

  BMI_Set_double (self, "surface_elevation", new_vals);

  fprintf (stdout, "Values after set\n");
  fprintf (stdout, "================\n");
  print_var_values (self, "surface_elevation");

  {
    int inds[5] = {1, 2, 4, 8, 16};
    double vals[5] = {11, 22, 44, 88, 1616};
    double *p;
    int i;

    BMI_Set_double_at_indices (self, "surface_elevation", inds, 5, vals);
    print_var_values (self, "surface_elevation");

    BMI_Get_value_ptr (self, "surface_elevation", &p);
    for (i=0; i<5; i++) {
      fprintf (stdout, "Checking %d...", inds[i]);
      if (p[inds[i]] == vals[i])
        fprintf (stdout, "PASS\n");
    }
  }

  free (new_vals);

  BMI_Finalize (self);

  return EXIT_SUCCESS;
}