funkalicious 0.1

grid1.h File Reference

#include <glib-2.0/glib.h>
#include <gio/gio.h>
#include <libdotcode/dotcode_generic.h>
#include <libdotcode/matdb.h>
#include <libdotcode/matdb-dotcode.h>
#include <libdotcode/matdb-dotcode.h>
Include dependency graph for grid1.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dotcode_grid1

Enumerations

enum  dotcode_grid1_errors { DOTCODE_GRID1_ERROR_NOSUCHPROPERTY = DOTCODE_ERROR_LAST, DOTCODE_GRID1_ERROR_LAST }

Functions

struct dotcode_grid1dotcode_grid1_get_from_gfile (GFile *f, GError **error)
GError * dotcode_grid1_write_to_gfile (GFile *f, const struct dotcode_grid1 *grid)
void dotcode_grid1_free (struct dotcode_grid1 *grid)
double * dotcode_grid1_get_property_cache (const struct dotcode_grid1 *grid, const struct matdb *mdb, const char *property_name, GError **err)
double * dotcode_grid1_get_property_grid (const struct dotcode_grid1 *grid, const struct matdb *mdb, const char *property, GError **err)
double dotcode_grid1_get_property_at_site (const struct dotcode_grid1 *grid, const struct matdb *mdb, const char *property, const int *index, GError **err)
double dotcode_grid1_get_property_at_site_cached (const struct dotcode_grid1 *grid, const double *propcache, const int *index)
void dotcode_grid1_write_assignments_slice_text (const struct dotcode_grid1 *grid, GFile *base, enum dotcode_coord coord, int index, GError **err)
void dotcode_grid1_write_property_slice_text (const struct dotcode_grid1 *grid, const double *property_array, const char *property_name, GFile *base, enum dotcode_coord coord, int index, GError **err)
long unsigned int dotcode_grid1_get_assignment_index (int x, int y, int z, int Nx, int Ny)

Enumeration Type Documentation

Enumerator:
DOTCODE_GRID1_ERROR_NOSUCHPROPERTY 
DOTCODE_GRID1_ERROR_LAST 

Definition at line 48 of file grid1.h.


Function Documentation

void dotcode_grid1_free ( struct dotcode_grid1 grid)

Definition at line 51 of file grid1.c.

References dotcode_grid1::assignments, and dotcode_grid1::materials.

Referenced by main().

                                                    {
  g_strfreev(grid->materials);
  if(grid->assignments != NULL) free(grid->assignments);
  free(grid);
}

Here is the caller graph for this function:

long unsigned int dotcode_grid1_get_assignment_index ( int  x,
int  y,
int  z,
int  Nx,
int  Ny 
)

Definition at line 43 of file grid1.c.

References get_assignment_index().

                                                                                          {
  return get_assignment_index(x, y, z, Nx, Ny);
}

Here is the call graph for this function:

struct dotcode_grid1* dotcode_grid1_get_from_gfile ( GFile *  f,
GError **  error 
) [read]

Definition at line 59 of file grid1.c.

References dotcode_grid1::assignments, DOTCODE_ERROR_MALLOCFAIL, DOTCODE_GRID1_GERROR_DOMAIN, dotcode_read_float8(), dotcode_read_int(), dotcode_read_sstring(), dotcode_grid1::dx, e, dotcode_grid1::materials, dotcode_grid1::N, and str.

Referenced by dotcode_displ_get_grid1(), and main().

                                                                             {
  struct dotcode_grid1* grid = (struct dotcode_grid1*)malloc(sizeof(struct dotcode_grid1));
  if(grid == NULL) {
    *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_MALLOCFAIL, "dotcode::grid1::get_from_GFile: Failed to allocate a new struct dotcode_grid1");
    return NULL;
  }
  GError *e = NULL;
  GFileInputStream *fis = g_file_read(f, NULL, &e);
  if((e != NULL) || (fis == NULL)) {
    if(e == NULL) {
      char* str = g_file_get_uri(f);
      *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to open the grid file (%s), but no further error was given.\n", str);
      g_free(str);
    }else{
      *error = e;
    }
    free(grid);
    return NULL;
  }
  /*The file is now open.*/
  char endian;
  gsize sz;
  if((!g_input_stream_read_all((GInputStream*)fis, &endian, 1, &sz, NULL, &e)) || (sz != 1)) {
    if(e == NULL) {
      *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read endianness from the stream: didn't get a single byte; got %lu", (long unsigned int)sz);
    }else{
      *error = e;
    }
    free(grid);
    return NULL;
  }
  gboolean little_endian;
  switch(endian) {
  case 'l':
    little_endian = TRUE;
    break;
  case 'b':
    little_endian = FALSE;
    break;
  default:
    *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read endianness from the stream: got invalid character (%d)", (int)endian);
    free(grid);
    return NULL;
  }
  e = NULL;
  char *grid1_string = dotcode_read_sstring(little_endian, (GInputStream*)fis, &e);
  if((grid1_string == NULL) || (e != NULL)) {
    if(e == NULL) {
    *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read \"Grid1\" sstring from input stream.\n");
    }else{
      *error = e;
    }
    free(grid);
    return NULL;
  }
  if(g_strcmp0(grid1_string, "Grid1")) {
    *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failure reading grid1 stream: string (%s) did not match expected string (%s)\n", grid1_string, "Grid1");
    free(grid);
    return NULL;
  }
  e = NULL;
  free(grid1_string);
  grid1_string = dotcode_read_sstring(little_endian, (GInputStream*)fis, &e);
  if((grid1_string == NULL) || (e != NULL)) {
    if(e == NULL) {
    *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read \"1\" sstring from input stream.\n");
    }else{
      *error = e;
    }
    free(grid);
    return NULL;
  }
  if(g_strcmp0(grid1_string, "1")) {
    *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failure reading grid1 stream: string (%s) did not match expected string (%s)\n", grid1_string, "1");
    free(grid);
    return NULL;
  }
  free(grid1_string);
  /*Read in ignored int, Nxyz, and number of materials*/
  int N_materials = -1;
  for(int i=0; i<5; i++) {
    e = NULL;
    int j =  dotcode_read_int(little_endian, (GInputStream*)fis, &e);
    if(e != NULL) {
      *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read header int %d from input stream. (error=%s)", i, e->message);
      g_error_free(e);
      free(grid);
      return NULL;
    }
    if((i > 0) && (i < 4)) {
      grid->N[i-1]=j;
    }else if(i==4) {
      N_materials = j;
    }
  }
  /*Set up the materials storage.*/
  grid->materials = (char**)malloc((N_materials+1)*sizeof(char*));
  if(grid->materials == NULL) {
    *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_MALLOCFAIL, "dotcode::grid1::get_from_GFile: Failed to allocate material name storage.\n");
    free(grid);
    return NULL;
  }
  /*allocate storage for the unsigned chars.*/
  grid->assignments = (unsigned char*)malloc(sizeof(unsigned char)*(grid->N[0])*(grid->N[1])*(grid->N[2]));
  if(grid->assignments == NULL) {
    *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_MALLOCFAIL, "dotcode::grid1::get_from_GFile: Failed to allocate material assignment storage.\n");
    free(grid->materials);
    free(grid);
    return NULL;
  }
  /*Set the last pointer to NULL to indicate the last one.*/
  (grid->materials)[N_materials] = NULL;
  /*Now read in N_materials materials*/
  #ifdef DEBUG3
  fprintf(stderr, "N_materials=%d:", N_materials);
  #endif
  for(int i=0; i<N_materials; i++) {
    e = NULL;
    (grid->materials)[i] = dotcode_read_sstring(little_endian, (GInputStream*)fis, &e);
    if(e != NULL) {
      *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read %d-th material sstring in header (error=%s)", i, e->message);
      g_error_free(e);
      for(int j=0; j<i; j++) {
  free(grid->materials[j]);
      }
      free(grid->assignments);
      free(grid);
      return NULL;
    }
    #ifdef DEBUG3
    fprintf(stderr, "%s, ", grid->materials[i]);
    #endif
  }
  #ifdef DEBUG3
  fprintf(stderr, "\n");
  #endif
  /*We read in another, identical-number-of-sstrings section that's ignored.*/
  for(int i=0; i<N_materials; i++) {
    e = NULL;
    free(dotcode_read_sstring(little_endian, (GInputStream*)fis, &e));
    if(e != NULL) {
      *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read %d-th ignored sstring in header (error=%s)", i, e->message);
      g_error_free(e);
      g_strfreev(grid->materials);
      free(grid->assignments);
      free(grid);
      return NULL;
    }
  }
  /*We now read in 3 ignored ints*/
  for(int i=0; i<3; i++) {
    e = NULL;
    dotcode_read_int(little_endian, (GInputStream*)fis, &e);
    if(e != NULL) {
      *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read ignored header int %d from input stream (error=%s)", i, e->message);
      g_error_free(e);
      g_strfreev(grid->materials);
      free(grid->assignments);
      free(grid);
      return NULL;
    }
  }
  /*And 15 float8s, which starts with 12 ignored ones and then 3 that have the grid spacings*/
  for(int i=0; i<15; i++) {
    double j =  dotcode_read_float8(little_endian, (GInputStream*)fis, &e);
    #ifdef DEBUG3
    fprintf(stderr, "%d=%g\n", i, j);
    #else
    j=j;
    #endif
    if(e != NULL) {
      *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read header double %d from input stream (error=%s)", i, e->message);
      g_error_free(e);
      g_strfreev(grid->materials);
      free(grid->assignments);
      free(grid);
      return NULL;
    }
  }
  for(int j=0; j<3; j++) {
    for(int i=0; i<grid->N[j]; i++) {
      double val =  dotcode_read_float8(little_endian, (GInputStream*)fis, &e);
      if(e != NULL) {
        *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read header double %d from input stream (error=%s)", i, e->message);
  g_error_free(e);
  g_strfreev(grid->materials);
  free(grid->assignments);
  free(grid);
  return NULL;
      }
      /*There are a sequence of floats which we assume will be the
       *same (same grid spacing for each grid site along a given
       *direction; otherwise, we'd need a list of dx[3][N[i]] to store
       *the grid site lengths
       */
      if(i != 0) {
  /*Precision is irrelevant; we put the bits in there, and they
    should be the same for every point along the axis*/
  if(grid->dx[j] != val) {
    *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Error while processing dx[%d]: set value is %g, but the %dth value is %g", j, grid->dx[j], i, val);
    g_error_free(e);
    g_strfreev(grid->materials);
    free(grid->assignments);
    free(grid);
    return NULL;
  }
      }else{
  grid->dx[j] = val;
      }
      #ifdef DEBUG3
      fprintf(stderr, "dx[%d](%d/%d)=%g(%g)\n", j, i, grid->N[j], grid->dx[j], val);
      #endif
    }
  }

  /*We now have a giant array of unsigned chars, but we can just read them in all at once.*/

  e = NULL;
  if((!g_input_stream_read_all((GInputStream*)fis, grid->assignments, (grid->N[0])*(grid->N[1])*(grid->N[2]), &sz, NULL, &e)) || (sz != (grid->N[0])*(grid->N[1])*(grid->N[2]))) {
    if(e == NULL) {
      *error = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, 12, "dotcode::grid1::get_from_GFile: Failed to read material assignments (%lu bytes) from the stream: got %lu bytes", (long unsigned int)(grid->N[0])*(grid->N[1])*(grid->N[2]), (long unsigned int)sz );
    }else{
      *error = e;
    }
    g_strfreev(grid->materials);
    free(grid->assignments);
    free(grid);
    return NULL;
  }

  /*Close the file; we're done*/
  g_input_stream_close((GInputStream*)fis, NULL, &e);
  /*Be paranoid. An error here means we have corrupted data somewhere.
    It seems likely to me that this will be true. And paranoia when it comes
    to data integrity is Good. In fact, I should probably look into HDF
    checksumming.*/
  if(e != NULL) {
    g_strfreev(grid->materials);
    free(grid->assignments);
    free(grid);
    *error = e;
    return NULL;
  }
  return grid;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double dotcode_grid1_get_property_at_site ( const struct dotcode_grid1 grid,
const struct matdb mdb,
const char *  property,
const int *  index,
GError **  err 
)

Gets a specified property at a grid site

Parameters:
gridthe grid to pull the information from
propertystring containing the property to pull
indexponter to an array containing 3 ints indicating the site

Definition at line 342 of file grid1.c.

References dotcode_grid1::assignments, DOTCODE_GRID1_ERROR_NOSUCHPROPERTY, DOTCODE_GRID1_GERROR_DOMAIN, get_assignment_index(), get_property(), dotcode_grid1::materials, and dotcode_grid1::N.

Referenced by main().

                                                                                                                                                           {
  int mat =  grid->assignments[get_assignment_index(index[0], index[1], index[2], grid->N[0], grid->N[1])];
  int ierror=0;
  double ppt = get_property(mdb, property, grid->materials[mat], &ierror);
  if(ierror != 0) {
    *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_GRID1_ERROR_NOSUCHPROPERTY, "libdotcode::grid1::dotcode_grid1_get_property_at_site: ERROR: got error %d (probably couldn't find property %s in for material %s in the material database).", ierror, property, grid->materials[mat]);
  }
  return ppt;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double dotcode_grid1_get_property_at_site_cached ( const struct dotcode_grid1 grid,
const double *  propcache,
const int *  index 
)

same as dotcode_grdi1_get_property_at_site, but uses property cache instead of matdb and property string.

Parameters:

Definition at line 352 of file grid1.c.

References dotcode_grid1::assignments, get_assignment_index(), and dotcode_grid1::N.

Referenced by main().

                                                                                                                              {
  return propcache[grid->assignments[get_assignment_index(index[0], index[1], index[2], grid->N[0], grid->N[1])]];
}

Here is the call graph for this function:

Here is the caller graph for this function:

double* dotcode_grid1_get_property_cache ( const struct dotcode_grid1 grid,
const struct matdb mdb,
const char *  property_name,
GError **  err 
)

Sets up an array containing the property, by material index

Parameters:
gridthe grid to use
mdbthe material database
property_namethe name of the property to be cached

Definition at line 573 of file grid1.c.

References DOTCODE_ERROR_MALLOCFAIL, DOTCODE_GRID1_ERROR_NOSUCHPROPERTY, DOTCODE_GRID1_GERROR_DOMAIN, get_property(), and dotcode_grid1::materials.

Referenced by dotcode_grid1_get_property_grid(), and main().

                                                                                                                                             {
  int N_mats;
  for(N_mats=0; grid->materials[N_mats]!=NULL; N_mats++);
  double* cache = (double*)malloc(N_mats*sizeof(double));
  if(cache == NULL) {
    *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_MALLOCFAIL, "libdotcode::grid1::dotcode_grid1_get_property_cache: ERROR: unable to allocate memory for the property cache (property=%s)", property_name);
    return NULL;
  }
  int ierror=0;
  for(int i=0; i<N_mats; i++) {
    cache[i] = get_property(mdb, property_name, grid->materials[i], &ierror);
    if(ierror != 0) {
      *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_GRID1_ERROR_NOSUCHPROPERTY, "libdotcode::grid1::dotcode_grid1_get_property_cache: ERROR: %d; probably unable to find property %s in for material %s in the material database.", ierror, property_name, grid->materials[i]);
      free(cache);
      return NULL;
    }
  }
  return cache;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double* dotcode_grid1_get_property_grid ( const struct dotcode_grid1 grid,
const struct matdb mdb,
const char *  property,
GError **  err 
)

Gets a grid with the respective property.

Definition at line 306 of file grid1.c.

References dotcode_grid1::assignments, DOTCODE_ERROR_MALLOCFAIL, DOTCODE_GRID1_ERROR_NOSUCHPROPERTY, DOTCODE_GRID1_GERROR_DOMAIN, dotcode_grid1_get_property_cache(), e, get_assignment_index(), get_property(), dotcode_grid1::materials, and dotcode_grid1::N.

Referenced by main().

                                                                                                                                       {
  double* props = (double*)malloc((grid->N[0])*(grid->N[1])*(grid->N[2])*sizeof(double));
  if(props == NULL) {
    *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_MALLOCFAIL, "libdotcode::grid1::dotcode_grid1_get_property_grid: ERROR: failed to allocate memory for the property grid");
    return NULL;
  }
  GError *e = NULL;
  double *propcache = dotcode_grid1_get_property_cache(grid, mdb, property, &e);
  if((propcache == NULL) || (e != NULL)) {
    g_propagate_prefixed_error(err, e, "libdotcode::grid1::get_property_grid: Unable to set up the property cache!");
    free(props);
    return NULL;
  }
  int N_mats;
  for(N_mats=0; grid->materials[N_mats]!=NULL; N_mats++);
  int ierror;
  for(int i=0; i<N_mats; i++) {
    propcache[i] = get_property(mdb, property, grid->materials[i], &ierror);
    if(ierror != 0) {
      *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_GRID1_ERROR_NOSUCHPROPERTY, "libdotcode::grid1::dotcode_grid1_get_property_grid: ERROR: unable to find property %s in for material %s in the material database.", property, grid->materials[i]);
      free(propcache);
      free(props);
      return NULL;
    }
  }
  for(int k=0; k<(grid->N[2]); k++) {
    for(int j=0; j<(grid->N[1]); j++) {
      for(int i=0; i<(grid->N[0]); i++) {
  props[get_assignment_index(i, j, k, grid->N[0], grid->N[1])] = propcache[grid->assignments[get_assignment_index(i, j, k, grid->N[0], grid->N[1])]];
      }
    }
  }
  free(propcache);
  return props;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dotcode_grid1_write_assignments_slice_text ( const struct dotcode_grid1 grid,
GFile *  base,
enum dotcode_coord  coord,
int  index,
GError **  err 
)

Writes the a slice of the grid material assignments out to a file in human-readalbe format

Parameters:
gridthe grid to write out
basethe directory into which to write the file
coordwhich coordinate to write a slice out
xthe value of the coordinate to write out
errpointer to a pointer in which to store the GError, if any.

Definition at line 356 of file grid1.c.

References dotcode_grid1::assignments, DOTCODE_COORD_X, DOTCODE_COORD_Y, DOTCODE_COORD_Z, DOTCODE_ERROR_ERRORED_THEN_CLOSED_ERROR, DOTCODE_GRID1_GERROR_DOMAIN, e, get_assignment_index(), dotcode_grid1::materials, dotcode_grid1::N, and str.

Referenced by main().

                                                                                                                                                  {
  GError *e;
  GString *s = g_string_new("matslice_");;
  switch(coord) {
  case DOTCODE_COORD_X:
    g_string_append_printf(s, "X=%d.pdata", index);
    break;
  case DOTCODE_COORD_Y:
    g_string_append_printf(s, "Y=%d.pdata", index);
    break;
  case DOTCODE_COORD_Z:
    g_string_append_printf(s, "Z=%d.pdata", index);
    break;
  }
  GFile* f;
  if(base == NULL) {
    f = g_file_new_for_path(s->str);
  }else{
    f = g_file_resolve_relative_path(base, s->str);
  }
  e = NULL;
  GFileIOStream *gfos = g_file_create_readwrite(f, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &e);
  if(e != NULL) {
    *err = e;
    return;
  }
  GOutputStream *os = g_io_stream_get_output_stream((GIOStream*)gfos);
  GDataOutputStream *dos = g_data_output_stream_new(os);
  g_string_printf(s, "#index\tmaterial\n");
  e=NULL;
  char *str;
  g_data_output_stream_put_string(dos, s->str, NULL, &e);
  if(e != NULL) {
    *err = e;
    g_string_free(s, TRUE);
    e=NULL;
    g_io_stream_close((GIOStream*)gfos, NULL, &e);
    if(e != NULL) {
      *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_ERRORED_THEN_CLOSED_ERROR, "libdotcode::grid1::dotcode_grid1_write_assignment_text: had an error (%s) while writing string (%s), but had another error (%s) while closing the file (%s)!\n", (*err)->message, s->str, e->message, str=g_file_get_uri(f));
      g_free(str);
    }
    return;
  }
  for(int i=0; (grid->materials)[i] != NULL; i++) {
    g_string_printf(s, "#%i\t%s\n", i, (grid->materials)[i]);
    e=NULL;
    char *str;
    g_data_output_stream_put_string(dos, s->str, NULL, &e);
    if(e != NULL) {
      *err = e;
      g_string_free(s, TRUE);
      e=NULL;
      g_io_stream_close((GIOStream*)gfos, NULL, &e);
      if(e != NULL) {
  *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_ERRORED_THEN_CLOSED_ERROR, "libdotcode::grid1::dotcode_grid1_write_assignment_text: had an error (%s) while writing string (%s), but had another error (%s) while closing the file (%s)!\n", (*err)->message, s->str, e->message, str=g_file_get_uri(f));
  g_free(str);
      }
      return;
    }
  }
  switch(coord) {
  case DOTCODE_COORD_X:
    g_string_printf(s, "#Y()\tZ(sites)\tmaterial index\n");
    break;
  case DOTCODE_COORD_Y:
    g_string_printf(s, "#X(sites)\tZ(sites)\tmaterial index\n");
    break;
  case DOTCODE_COORD_Z:
    g_string_printf(s, "#X(sites)\tY(sites)\tmaterial index\n");
    break;
  }
  e=NULL;
  g_data_output_stream_put_string(dos, s->str, NULL, &e);
  if(e != NULL) {
    *err = e;
    g_string_free(s, TRUE);
    e=NULL;
    g_io_stream_close((GIOStream*)gfos, NULL, &e);
    if(e != NULL) {
      *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_ERRORED_THEN_CLOSED_ERROR, "libdotcode::grid1::dotcode_grid1_write_assignment_text: had an error (%s) while writing string (%s), but had another error (%s) while closing the file (%s)!\n", (*err)->message, s->str, e->message, str=g_file_get_uri(f));
      g_free(str);
    }
    return;
  }
  for(int k=0; k<grid->N[2]; k++) {
    if((coord == DOTCODE_COORD_Z) && (k != index)) continue;
    for(int j=0; j<grid->N[1]; j++) {
      if((coord == DOTCODE_COORD_Y) && (j != index)) continue;
      for(int i=0; i<grid->N[0]; i++) {
  if((coord == DOTCODE_COORD_X) && (i != index)) continue;
  e=NULL;
  switch(coord) {
  case DOTCODE_COORD_X:
    g_string_printf(s, "%d\t%d\t%d\n", j, k, grid->assignments[get_assignment_index(i, j, k, grid->N[0], grid->N[1])]);
    break;
  case DOTCODE_COORD_Y:
    g_string_printf(s, "%d\t%d\t%d\n", i, k, grid->assignments[get_assignment_index(i, j, k, grid->N[0], grid->N[1])]);
    break;
  case DOTCODE_COORD_Z:
    g_string_printf(s, "%d\t%d\t%d\n", i, j, grid->assignments[get_assignment_index(i, j, k, grid->N[0], grid->N[1])]);
    break;
  }
  g_data_output_stream_put_string(dos, s->str, NULL, &e);
  if(e != NULL) {
    *err = e;
    g_string_free(s, TRUE);
    e=NULL;
    g_io_stream_close((GIOStream*)gfos, NULL, &e);
    if(e != NULL) {
      *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_ERRORED_THEN_CLOSED_ERROR, "libdotcode::grid1::dotcode_grid1_write_assignment_text: had an error (%s) while writing string (%s), but had another error (%s) while closing the file (%s)!\n", (*err)->message, s->str, e->message, str=g_file_get_uri(f));
      g_free(str);
    }
    return;
  }
      }
    }
  }
  g_io_stream_close((GIOStream*)gfos, NULL, &e);
  if(e != NULL) {
    *err = e;
  }
  g_string_free(s, TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dotcode_grid1_write_property_slice_text ( const struct dotcode_grid1 grid,
const double *  property_array,
const char *  property_name,
GFile *  base,
enum dotcode_coord  coord,
int  index,
GError **  err 
)

Definition at line 480 of file grid1.c.

References DOTCODE_COORD_X, DOTCODE_COORD_Y, DOTCODE_COORD_Z, DOTCODE_ERROR_ERRORED_THEN_CLOSED_ERROR, DOTCODE_GRID1_GERROR_DOMAIN, e, get_assignment_index(), dotcode_grid1::N, and str.

Referenced by main().

                                                                                                                                                                                                        {
  GError *e;
  GString *s = g_string_new("propslice_");;
  switch(coord) {
  case DOTCODE_COORD_X:
    g_string_append_printf(s, "X=%d.pdata", index);
    break;
  case DOTCODE_COORD_Y:
    g_string_append_printf(s, "Y=%d.pdata", index);
    break;
  case DOTCODE_COORD_Z:
    g_string_append_printf(s, "Z=%d.pdata", index);
    break;
  }
  GFile* f;
  if(base == NULL) {
    f = g_file_new_for_path(s->str);
  }else{
    f = g_file_resolve_relative_path(base, s->str);
  }
  e = NULL;
  GFileIOStream *gfos = g_file_create_readwrite(f, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &e);
  if(e != NULL) {
    *err = e;
    return;
  }
  GOutputStream *os = g_io_stream_get_output_stream((GIOStream*)gfos);
  GDataOutputStream *dos = g_data_output_stream_new(os);
  switch(coord) {
  case DOTCODE_COORD_X:
    g_string_printf(s, "#Y()\tZ(sites)\t%s\n", property_name);
    break;
  case DOTCODE_COORD_Y:
    g_string_printf(s, "#X(sites)\tZ(sites)\t%s\n", property_name);
    break;
  case DOTCODE_COORD_Z:
    g_string_printf(s, "#X(sites)\tY(sites)\t%s\n", property_name);
    break;
  }
  e=NULL;
  g_data_output_stream_put_string(dos, s->str, NULL, &e);
  char* str;
  if(e != NULL) {
    *err = e;
    g_string_free(s, TRUE);
    e=NULL;
    g_io_stream_close((GIOStream*)gfos, NULL, &e);
    if(e != NULL) {
      *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_ERRORED_THEN_CLOSED_ERROR, "libdotcode::grid1::dotcode_grid1_write_property_text: had an error (%s) while writing string (%s), but had another error (%s) while closing the file (%s)!\n", (*err)->message, s->str, e->message, str=g_file_get_uri(f));
      g_free(str);
    }
    return;
  }
  for(int k=0; k<grid->N[2]; k++) {
    if((coord == DOTCODE_COORD_Z) && (k != index)) continue;
    for(int j=0; j<grid->N[1]; j++) {
      if((coord == DOTCODE_COORD_Y) && (j != index)) continue;
      for(int i=0; i<grid->N[0]; i++) {
  if((coord == DOTCODE_COORD_X) && (i != index)) continue;
  e=NULL;
  switch(coord) {
  case DOTCODE_COORD_X:
    g_string_printf(s, "%d\t%d\t%g\n", j, k, property_array[get_assignment_index(i, j, k, grid->N[0], grid->N[1])]);
    break;
  case DOTCODE_COORD_Y:
    g_string_printf(s, "%d\t%d\t%g\n", i, k, property_array[get_assignment_index(i, j, k, grid->N[0], grid->N[1])]);
    break;
  case DOTCODE_COORD_Z:
    g_string_printf(s, "%d\t%d\t%g\n", i, j, property_array[get_assignment_index(i, j, k, grid->N[0], grid->N[1])]);
    break;
  }
  g_data_output_stream_put_string(dos, s->str, NULL, &e);
  if(e != NULL) {
    *err = e;
    g_string_free(s, TRUE);
    e=NULL;
    g_io_stream_close((GIOStream*)gfos, NULL, &e);
    if(e != NULL) {
      *err = g_error_new(DOTCODE_GRID1_GERROR_DOMAIN, DOTCODE_ERROR_ERRORED_THEN_CLOSED_ERROR, "libdotcode::grid1::dotcode_grid1_write_property_text: had an error (%s) while writing string (%s), but had another error (%s) while closing the file (%s)!\n", (*err)->message, s->str, e->message, str=g_file_get_uri(f));
      g_free(str);
    }
    return;
  }
      }
    }
  }
  g_io_stream_close((GIOStream*)gfos, NULL, &e);
  if(e != NULL) {
    *err = e;
  }
  g_string_free(s, TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

GError* dotcode_grid1_write_to_gfile ( GFile *  f,
const struct dotcode_grid1 grid 
)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines