[SCM] Gerris Flow Solver branch, upstream, updated. b3aa46814a06c9cb2912790b23916ffb44f1f203
Stephane Popinet
popinet at users.sf.net
Fri May 15 02:55:52 UTC 2009
The following commit has been merged in the upstream branch:
commit 919a7e5eee134b6dc36b965688c753692c01d049
Author: Stephane Popinet <popinet at users.sf.net>
Date: Fri Nov 7 10:24:53 2008 +1100
ASCII float conversion format option for OutputSimulation
darcs-hash:20081106232453-d4795-1d32d1a6b9ea188217934117fbc0359e0fca80dd.gz
diff --git a/src/output.c b/src/output.c
index f40fec4..bb37084 100644
--- a/src/output.c
+++ b/src/output.c
@@ -1182,11 +1182,15 @@ GfsOutputClass * gfs_output_location_class (void)
/* GfsOutputSimulation: Object */
+static gchar default_precision[] = "%g";
+
static void output_simulation_destroy (GtsObject * object)
{
GfsOutputSimulation * output = GFS_OUTPUT_SIMULATION (object);
g_slist_free (output->var);
+ if (output->precision != default_precision)
+ g_free (output->precision);
(* GTS_OBJECT_CLASS (gfs_output_simulation_class ())->parent_class->destroy) (object);
}
@@ -1199,12 +1203,17 @@ static void write_text (FttCell * cell, GfsOutputSimulation * output)
gfs_cell_cm (cell, &p);
gfs_simulation_map_inverse (gfs_object_simulation (output), &p);
- fprintf (fp, "%.6f %.6f %.6f", p.x, p.y, p.z);
+ gchar * format = g_strdup_printf ("%s %s %s",
+ output->precision, output->precision, output->precision);
+ fprintf (fp, format, p.x, p.y, p.z);
+ g_free (format);
+ format = g_strdup_printf (" %s", output->precision);
while (i) {
if (GFS_VARIABLE1 (i->data)->name)
- fprintf (fp, " %g", GFS_VARIABLE (cell, GFS_VARIABLE1 (i->data)->i));
+ fprintf (fp, format, GFS_VARIABLE (cell, GFS_VARIABLE1 (i->data)->i));
i = i->next;
}
+ g_free (format);
fputc ('\n', fp);
}
@@ -1252,12 +1261,12 @@ static gboolean output_simulation_event (GfsEvent * event, GfsSimulation * sim)
break;
}
case GFS_VTK: {
- gfs_domain_write_vtk (domain, output->max_depth, domain->variables_io,
+ gfs_domain_write_vtk (domain, output->max_depth, domain->variables_io, output->precision,
GFS_OUTPUT (event)->file->fp);
break;
}
case GFS_TECPLOT: {
- gfs_domain_write_tecplot (domain, output->max_depth, domain->variables_io,
+ gfs_domain_write_tecplot (domain, output->max_depth, domain->variables_io, output->precision,
GFS_OUTPUT (event)->file->fp);
break;
}
@@ -1303,6 +1312,8 @@ static void output_simulation_write (GtsObject * o, FILE * fp)
case GFS_TECPLOT: fputs (" format = Tecplot", fp); break;
default: break;
}
+ if (output->precision != default_precision)
+ fprintf (fp, " precision = %s", output->precision);
fputs (" }", fp);
}
@@ -1316,20 +1327,22 @@ static void output_simulation_read (GtsObject ** o, GtsFile * fp)
if (fp->type == '{') {
GtsFileVariable var[] = {
- {GTS_INT, "depth", TRUE},
- {GTS_STRING, "variables",TRUE},
- {GTS_INT, "binary", TRUE},
- {GTS_INT, "solid", TRUE},
- {GTS_STRING, "format", TRUE},
+ {GTS_INT, "depth", TRUE},
+ {GTS_STRING, "variables", TRUE},
+ {GTS_INT, "binary", TRUE},
+ {GTS_INT, "solid", TRUE},
+ {GTS_STRING, "format", TRUE},
+ {GTS_STRING, "precision", TRUE},
{GTS_NONE}
};
- gchar * variables = NULL, * format = NULL;
+ gchar * variables = NULL, * format = NULL, * precision = NULL;
var[0].data = &output->max_depth;
var[1].data = &variables;
var[2].data = &output->binary;
var[3].data = &output->solid;
var[4].data = &format;
+ var[5].data = &precision;
gts_file_assign_variables (fp, var);
if (fp->type == GTS_ERROR) {
g_free (variables);
@@ -1369,6 +1382,12 @@ static void output_simulation_read (GtsObject ** o, GtsFile * fp)
}
g_free (format);
}
+
+ if (precision != NULL) {
+ if (output->precision != default_precision)
+ g_free (output->precision);
+ output->precision = precision;
+ }
}
}
@@ -1387,6 +1406,7 @@ static void gfs_output_simulation_init (GfsOutputSimulation * object)
object->binary = 1;
object->solid = 1;
object->format = GFS;
+ object->precision = default_precision;
}
GfsOutputClass * gfs_output_simulation_class (void)
diff --git a/src/output.h b/src/output.h
index 5385f2b..60482ad 100644
--- a/src/output.h
+++ b/src/output.h
@@ -155,6 +155,7 @@ struct _GfsOutputSimulation {
gint max_depth;
GSList * var;
gboolean binary, solid;
+ gchar * precision;
GfsOutputSimulationFormat format;
};
diff --git a/src/unstructured.c b/src/unstructured.c
index 727e897..926053d 100644
--- a/src/unstructured.c
+++ b/src/unstructured.c
@@ -204,14 +204,17 @@ static guint local_domain_size (GfsDomain * domain, gint max_depth)
* @domain: a #GfsDomain.
* @max_depth: the maximum depth to consider.
* @variables: a list of #GfsVariable to output.
+ * @precision: the formatting string for converting float to ASCII.
* @fp: a file pointer.
*
* Writes in @fp a VTK-formatted representation of @domain and of the
* corresponding variables in the given list.
*/
-void gfs_domain_write_vtk (GfsDomain * domain, gint max_depth, GSList * variables, FILE * fp)
+void gfs_domain_write_vtk (GfsDomain * domain, gint max_depth, GSList * variables,
+ const gchar * precision, FILE * fp)
{
g_return_if_fail (domain != NULL);
+ g_return_if_fail (precision != NULL);
g_return_if_fail (fp != NULL);
GfsVariable * v[NV];
@@ -234,13 +237,15 @@ void gfs_domain_write_vtk (GfsDomain * domain, gint max_depth, GSList * variable
/* vertices */
guint nv = g_slist_length (vertices);
fprintf (fp, "POINTS %d float\n", nv);
+ gchar * format = g_strdup_printf ("%s %s %s\n", precision, precision, precision);
GSList * j = vertices;
while (j) {
FttVector p;
vertex_pos (j->data, &p, GFS_SIMULATION (domain));
- fprintf (fp, "%g %g %g\n", p.x, p.y, p.z);
+ fprintf (fp, format, p.x, p.y, p.z);
j = j->next;
}
+ g_free (format);
fputc ('\n', fp);
/* elements */
@@ -270,6 +275,7 @@ void gfs_domain_write_vtk (GfsDomain * domain, gint max_depth, GSList * variable
/* write scalar fields */
if (variables) {
+ gchar * format = g_strdup_printf ("%s\n", precision);
fprintf (fp, "POINT_DATA %d\n", nv);
GSList * i = variables;
while (i) {
@@ -278,12 +284,13 @@ void gfs_domain_write_vtk (GfsDomain * domain, gint max_depth, GSList * variable
GSList * j = vertices;
while (j) {
Vertex * vertex = j->data;
- fprintf (fp, "%g\n", vertex_value (vertex, v, max_depth));
+ fprintf (fp, format, vertex_value (vertex, v, max_depth));
j = j->next;
}
fputc ('\n', fp);
i = i->next;
}
+ g_free (format);
}
/* cleanup */
@@ -316,14 +323,17 @@ static void write_tecplot_element (FttCell * cell, WriteParams * par)
* @domain: a #GfsDomain.
* @max_depth: the maximum depth to consider.
* @variables: a list of #GfsVariable to output.
+ * @precision: the formatting string for converting float to ASCII.
* @fp: a file pointer.
*
* Writes in @fp a Tecplot-formatted representation of @domain and of the
* corresponding variables in the given list.
*/
-void gfs_domain_write_tecplot (GfsDomain * domain, gint max_depth, GSList * variables, FILE * fp)
+void gfs_domain_write_tecplot (GfsDomain * domain, gint max_depth, GSList * variables,
+ const gchar * precision, FILE * fp)
{
g_return_if_fail (domain != NULL);
+ g_return_if_fail (precision != NULL);
g_return_if_fail (fp != NULL);
GfsVariable * v[NV];
@@ -354,24 +364,29 @@ void gfs_domain_write_tecplot (GfsDomain * domain, gint max_depth, GSList * vari
fputs (FTT_DIMENSION == 2 ? "ET=QUADRILATERAL\n" : "ET=BRICK\n", fp);
/* vertices and scalar data */
+ gchar * xyzformat =
+#if FTT_2D
+ g_strdup_printf ("%s %s", precision, precision);
+#else
+ g_strdup_printf ("%s %s %s", precision, precision, precision);
+#endif
+ gchar * format = g_strdup_printf (" %s", precision);
j = vertices;
while (j) {
Vertex * vertex = j->data;
FttVector p;
vertex_pos (vertex, &p, GFS_SIMULATION (domain));
-#if FTT_2D
- fprintf (fp, "%g %g", p.x, p.y);
-#else
- fprintf (fp, "%g %g %g", p.x, p.y, p.z);
-#endif
+ fprintf (fp, xyzformat, p.x, p.y, p.z);
GSList * k = variables;
while (k) {
- fprintf (fp, " %g", vertex_value (vertex, k->data, max_depth));
+ fprintf (fp, format, vertex_value (vertex, k->data, max_depth));
k = k->next;
}
fputc ('\n', fp);
j = j->next;
}
+ g_free (format);
+ g_free (xyzformat);
/* elements */
WriteParams par;
diff --git a/src/unstructured.h b/src/unstructured.h
index 67f4520..7af76d9 100644
--- a/src/unstructured.h
+++ b/src/unstructured.h
@@ -30,10 +30,12 @@ extern "C" {
void gfs_domain_write_vtk (GfsDomain * domain,
gint max_depth,
GSList * variables,
+ const gchar * precision,
FILE * fp);
void gfs_domain_write_tecplot (GfsDomain * domain,
gint max_depth,
GSList * variables,
+ const gchar * precision,
FILE * fp);
#ifdef __cplusplus
--
Gerris Flow Solver
More information about the debian-science-commits
mailing list