コード例 #1
0
ファイル: cluster.c プロジェクト: H2Lib/H2Lib
static void
write_cdf(pccluster t,
	  size_t clusters, size_t coeffs,
	  size_t * clusteridx, size_t * coeffidx,
	  int nc_file, int nc_sons, int nc_size, int nc_coeff)
{
  size_t    start, count;
  ptrdiff_t stride;
  int       val, result;
  uint      i;

  assert(*clusteridx <= clusters);

  /* Write number of sons to nc_sons[*clusteridx] */
  start = *clusteridx;
  count = 1;
  stride = 1;
  val = t->sons;
  result = nc_put_vars(nc_file, nc_sons, &start, &count, &stride, &val);
  assert(result == NC_NOERR);

  /* Write size of cluster to nc_size[*clusteridx] */
  val = t->size;
  result = nc_put_vars(nc_file, nc_size, &start, &count, &stride, &val);
  assert(result == NC_NOERR);

  /* Increase cluster index */
  (*clusteridx)++;

  /* Handle sons */
  for (i = 0; i < t->sons; i++)
    write_cdf(t->son[i], clusters, coeffs, clusteridx, coeffidx,
	      nc_file, nc_sons, nc_size, nc_coeff);

  /* Write bounding box */
  start = *coeffidx;
  assert(start + 2 * t->dim <= coeffs);
  count = t->dim;
  result = nc_put_vars(nc_file, nc_coeff, &start, &count, &stride, t->bmin);
  assert(result == NC_NOERR);
  start += t->dim;

  result = nc_put_vars(nc_file, nc_coeff, &start, &count, &stride, t->bmax);
  assert(result == NC_NOERR);
  start += t->dim;
  (*coeffidx) = start;
}
コード例 #2
0
ファイル: fg_io.C プロジェクト: jfhbrook/Puff-UAF
int Grid::write(std::string *file)
{
  return write_cdf((char*)file->c_str());
}
コード例 #3
0
ファイル: fg_io.C プロジェクト: jfhbrook/Puff-UAF
/////////////////////////////////////////////////////////////////////
//
// WRITE SWITCH:
// This the public call, routes to the appropriate type 
// private subroutine
//
/////////////////////////////////////////////////////////////////////
int Grid::write(char *file) {

//  type = CDF;
  return write_cdf(file);
  }
コード例 #4
0
ファイル: cluster.c プロジェクト: H2Lib/H2Lib
void
write_cdf_cluster(pccluster t, const char *name)
{
  size_t    clusters, clusteridx;
  size_t    coeffs, coeffidx;
  int       nc_file, nc_sons, nc_size, nc_idx, nc_coeff;
  int       nc_clusters, nc_coeffs, nc_totalsize, nc_dim;
  int       result;

  /* Count number of clusters and coefficients */
  clusters = 0;
  coeffs = 0;
  write_count(t, &clusters, &coeffs);

  /* Create NetCDF file */
  result = nc_create(name, NC_64BIT_OFFSET, &nc_file);
  assert(result == NC_NOERR);

  /* Define "clusters" dimension */
  result = nc_def_dim(nc_file, "clusters", clusters, &nc_clusters);
  assert(result == NC_NOERR);

  /* Define "coeffs" dimension */
  result = nc_def_dim(nc_file, "coeffs", coeffs, &nc_coeffs);
  assert(result == NC_NOERR);

  /* Define "totalsize" dimension */
  result = nc_def_dim(nc_file, "totalsize", t->size, &nc_totalsize);
  assert(result == NC_NOERR);

  /* Define "dim" dimension */
  result = nc_def_dim(nc_file, "dim", t->dim, &nc_dim);
  assert(result == NC_NOERR);

  /* Define "sons" variable */
  result = nc_def_var(nc_file, "sons", NC_INT, 1, &nc_clusters, &nc_sons);
  assert(result == NC_NOERR);

  /* Define "size" variable */
  result = nc_def_var(nc_file, "size", NC_INT, 1, &nc_clusters, &nc_size);
  assert(result == NC_NOERR);

  /* Define "idx" variable */
  result = nc_def_var(nc_file, "idx", NC_INT, 1, &nc_totalsize, &nc_idx);
  assert(result == NC_NOERR);

  /* Define "coeff" variable */
  result = nc_def_var(nc_file, "coeff", NC_DOUBLE, 1, &nc_coeffs, &nc_coeff);
  assert(result == NC_NOERR);

  /* Finish NetCDF define mode */
  result = nc_enddef(nc_file);
  assert(result == NC_NOERR);

  /* Write index to NetCDF variable */
  result = nc_put_var(nc_file, nc_idx, t->idx);

  /* Write coefficiens to NetCDF variables */
  clusteridx = 0;
  coeffidx = 0;
  write_cdf(t, clusters, coeffs, &clusteridx, &coeffidx,
	    nc_file, nc_sons, nc_size, nc_coeff);
  assert(clusteridx == clusters);
  assert(coeffidx == coeffs);

  /* Close file */
  result = nc_close(nc_file);
  assert(result == NC_NOERR);
}
コード例 #5
0
ファイル: cluster.c プロジェクト: H2Lib/H2Lib
void
write_cdfpart_cluster(pccluster t, int nc_file, const char *prefix)
{
  size_t    clusters, clusteridx;
  size_t    coeffs, coeffidx;
  char     *buf;
  int       bufsize;
  int       nc_sons, nc_size, nc_idx, nc_coeff;
  int       nc_clusters, nc_coeffs, nc_totalsize, nc_dim;
  int       result;

  /* Prepare buffer for prefixed names */
  bufsize = strlen(prefix) + 16;
  buf = (char *) allocmem(sizeof(char) * bufsize);

  /* Count number of clusters and coefficients */
  clusters = 0;
  coeffs = 0;
  write_count(t, &clusters, &coeffs);

  /* Switch NetCDF file to define mode */
  result = nc_redef(nc_file);
  assert(result == NC_NOERR || result == NC_EINDEFINE);

  /* Define "clusters" dimension */
  prefix_name(buf, bufsize, prefix, "clusters");
  result = nc_def_dim(nc_file, buf, clusters, &nc_clusters);
  assert(result == NC_NOERR);

  /* Define "coeffs" dimension */
  prefix_name(buf, bufsize, prefix, "coeffs");
  result = nc_def_dim(nc_file, buf, coeffs, &nc_coeffs);
  assert(result == NC_NOERR);

  /* Define "totalsize" dimension */
  prefix_name(buf, bufsize, prefix, "totalsize");
  result = nc_def_dim(nc_file, buf, t->size, &nc_totalsize);
  assert(result == NC_NOERR);

  /* Define "dim" dimension */
  prefix_name(buf, bufsize, prefix, "dim");
  result = nc_def_dim(nc_file, buf, t->dim, &nc_dim);
  assert(result == NC_NOERR);

  /* Define "sons" variable */
  prefix_name(buf, bufsize, prefix, "sons");
  result = nc_def_var(nc_file, buf, NC_INT, 1, &nc_clusters, &nc_sons);
  assert(result == NC_NOERR);

  /* Define "size" variable */
  prefix_name(buf, bufsize, prefix, "size");
  result = nc_def_var(nc_file, buf, NC_INT, 1, &nc_clusters, &nc_size);
  assert(result == NC_NOERR);

  /* Define "idx" variable */
  prefix_name(buf, bufsize, prefix, "idx");
  result = nc_def_var(nc_file, buf, NC_INT, 1, &nc_totalsize, &nc_idx);
  assert(result == NC_NOERR);

  /* Define "coeff" variable */
  prefix_name(buf, bufsize, prefix, "coeff");
  result = nc_def_var(nc_file, buf, NC_DOUBLE, 1, &nc_coeffs, &nc_coeff);
  assert(result == NC_NOERR);

  /* Finish NetCDF define mode */
  result = nc_enddef(nc_file);
  assert(result == NC_NOERR);

  /* Write index to NetCDF variable */
  result = nc_put_var(nc_file, nc_idx, t->idx);

  /* Write coefficiencs to NetCDF variables */
  clusteridx = 0;
  coeffidx = 0;
  write_cdf(t, clusters, coeffs, &clusteridx, &coeffidx,
	    nc_file, nc_sons, nc_size, nc_coeff);
  assert(clusteridx == clusters);
  assert(coeffidx == coeffs);

  /* Clean up */
  nc_sync(nc_file);
  freemem(buf);
}
コード例 #6
0
ファイル: cdf.c プロジェクト: Vaa3D/v3d_external
void Write_CDF(CDF *cdf, FILE *output)
{ write_cdf(((Cdf *) cdf),output); }