50 file =
xfopen(filename,
"w+");
51 vtk_file->
file = file;
57 fprintf(file,
"# vtk DataFile Version 2.0\n");
58 fprintf(file,
"%s\n", title);
60 fprintf(file,
"ASCII\n");
62 fprintf(file,
"BINARY\n");
64 fprintf(file,
"DATASET UNSTRUCTURED_GRID\n");
72 FILE * file = vtk_file->
file;
78 fprintf(file,
"POINTS %u double\n",
num_points);
81 fprintf(file,
"%f %f %f\n", point_data[i*3+0], point_data[i*3+1], point_data[i*3+2]);
83 fwrite(point_data,
sizeof(*point_data), 3 *
num_points, file);
90 unsigned * num_points_per_cell,
unsigned num_cells) {
92 FILE * file = vtk_file->
file;
97 unsigned total_num_cell_corners = 0;
99 for (i = 0; i < num_cells; ++i)
100 total_num_cell_corners += num_points_per_cell[i];
102 fprintf(file,
"CELLS %u %u\n", num_cells, total_num_cell_corners + num_cells);
104 for (i = 0, k = 0; i < num_cells; ++i) {
107 fprintf(file,
"%u", num_points_per_cell[i]);
108 for (j = 0; j < num_points_per_cell[i]; ++j)
109 fprintf(file,
" %u", cell_corners[k++]);
112 fwrite(num_points_per_cell+i,
sizeof(*num_points_per_cell), 1, file);
113 fwrite(cell_corners+k,
sizeof(*cell_corners), num_points_per_cell[i], file);
114 k += num_points_per_cell[i];
121 fprintf(file,
"CELL_TYPES %u\n", num_cells);
122 for (i = 0; i < num_cells; ++i) {
126 switch(num_points_per_cell[i]) {
138 fprintf(file,
"%u\n",
type);
140 fwrite(&
type,
sizeof(
type), 1, file);
150 YAC_VTK_FILE * vtk_file,
double * point_data_lon,
double * point_data_lat,
153 double * point_data =
158 point_data_lon[i], point_data_lat[i], point_data + (
size_t)(3 * i));
171 "ERROR: yac_vtk_write_cell_scalars number of cells does not match")
179 size_t data_size = num_cells;
184 data_size *=
sizeof(int);
187 data_size *=
sizeof(unsigned);
190 data_size *=
sizeof(float);
193 data_size *=
sizeof(double);
210 "ERROR: yac_vtk_write_point_scalars number of points does not match")
223 data_size *=
sizeof(int);
226 data_size *=
sizeof(unsigned);
229 data_size *=
sizeof(float);
232 data_size *=
sizeof(double);
245 unsigned num_cells,
char *
name) {
252 unsigned num_cells,
char *
name) {
259 unsigned num_cells,
char *
name) {
266 unsigned num_cells,
char *
name) {
300 unsigned num_scalars_data,
301 unsigned num_data_points) {
304 for (
unsigned i = 0; i < num_scalars_data; ++i) {
306 fprintf(file,
"SCALARS %s %s 1\n",
data[i].
name,
308 fprintf(file,
"LOOKUP_TABLE default\n");
310 for (
unsigned j = 0; j < num_data_points; ++j) {
316 fprintf(file,
"%d\n", ((
int*)(
data[i].
data))[j]);
319 fprintf(file,
"%u\n", ((
unsigned*)(
data[i].
data))[j]);
322 fprintf(file,
"%.8f\n", ((
float*)(
data[i].
data))[j]);
326 fprintf(file,
"%.18lf\n", ((
double*)(
data[i].
data))[j]);
335 fwrite(
data[i].
data,
sizeof(
int), 1, file);
338 fwrite(
data[i].
data,
sizeof(
unsigned), 1, file);
341 fwrite(
data[i].
data,
sizeof(
float), 1, file);
344 fwrite(
data[i].
data,
sizeof(
double), 1, file);
357 FILE * file = vtk_file->
file;
359 fprintf(file,
"CELL_DATA %u\n", vtk_file->
num_cells);
361 fprintf(file,
"SCALARS cell_ids int 1\n");
362 fprintf(file,
"LOOKUP_TABLE default\n");
363 for (
unsigned i = 0; i < vtk_file->
num_cells; ++i) {
365 fprintf(file,
"%u\n", i);
367 fwrite(&i,
sizeof(i), 1, file);
381 FILE * file = vtk_file->
file;
383 fprintf(file,
"POINT_DATA %u\n", vtk_file->
num_points);
385 fprintf(file,
"SCALARS point_ids int 1\n");
386 fprintf(file,
"LOOKUP_TABLE default\n");
387 for (
unsigned i = 0; i < vtk_file->
num_points; ++i) {
389 fprintf(file,
"%u\n", i);
391 fwrite(&i,
sizeof(i), 1, file);
405 FILE * file = vtk_file->
file;
static void LLtoXYZ(double lon, double lat, double p_out[])
#define xrealloc(ptr, size)
#define xfopen(path, mode)
struct scalars_data * scalars_cell_data
struct scalars_data * scalars_point_data
unsigned num_scalars_cell_data
unsigned num_scalars_point_data
void yac_vtk_write_cell_scalars_uint(YAC_VTK_FILE *vtk_file, unsigned *scalars, unsigned num_cells, char *name)
void yac_vtk_write_cell_scalars_float(YAC_VTK_FILE *vtk_file, float *scalars, unsigned num_cells, char *name)
void yac_vtk_write_cell_scalars_double(YAC_VTK_FILE *vtk_file, double *scalars, unsigned num_cells, char *name)
void yac_vtk_write_cell_scalars_int(YAC_VTK_FILE *vtk_file, int *scalars, unsigned num_cells, char *name)
void yac_vtk_write_point_scalars_uint(YAC_VTK_FILE *vtk_file, unsigned *scalars, unsigned num_points, char *name)
void yac_vtk_write_point_data_ll(YAC_VTK_FILE *vtk_file, double *point_data_lon, double *point_data_lat, unsigned num_points)
static void vtk_flush_scalar_point_data(YAC_VTK_FILE *vtk_file)
void yac_vtk_write_point_scalars_double(YAC_VTK_FILE *vtk_file, double *scalars, unsigned num_points, char *name)
void yac_vtk_write_point_data(YAC_VTK_FILE *vtk_file, double *point_data, unsigned num_points)
static void yac_vtk_write_cell_scalars(YAC_VTK_FILE *vtk_file, void *scalars, unsigned num_cells, char *name, enum scalars_dt dt)
void yac_vtk_write_point_scalars_int(YAC_VTK_FILE *vtk_file, int *scalars, unsigned num_points, char *name)
const char * scalars_dt_names[4]
void yac_vtk_close(YAC_VTK_FILE *vtk_file)
static void vtk_flush_scalar_data(FILE *file, struct scalars_data *data, unsigned num_scalars_data, unsigned num_data_points)
static void vtk_flush_scalar_cell_data(YAC_VTK_FILE *vtk_file)
static void yac_vtk_write_point_scalars(YAC_VTK_FILE *vtk_file, void *scalars, unsigned num_points, char *name, enum scalars_dt dt)
void yac_vtk_write_cell_data(YAC_VTK_FILE *vtk_file, unsigned *cell_corners, unsigned *num_points_per_cell, unsigned num_cells)
YAC_VTK_FILE * yac_vtk_open(const char *filename, const char *title)
void yac_vtk_write_point_scalars_float(YAC_VTK_FILE *vtk_file, float *scalars, unsigned num_points, char *name)
general routines for writing vtk files
#define YAC_ASSERT(exp, msg)