ASCOT5
Loading...
Searching...
No Matches
hdf5_wall.c
Go to the documentation of this file.
1
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12#include <hdf5.h>
13#include <hdf5_hl.h>
14#include "../wall.h"
15#include "../wall/wall_2d.h"
16#include "../wall/wall_3d.h"
17#include "hdf5_wall.h"
18#include "hdf5_helpers.h"
19
20#define WPATH
22int hdf5_wall_read_2D(hid_t f, wall_2d_data* data, char* qid);
23int hdf5_wall_read_3D(hid_t f, wall_3d_data* data, char* qid);
24
40int hdf5_wall_init(hid_t f, wall_data* data, char* qid) {
41
42 char path[256];
43 int err = 1;
44
45 /* Read data the QID corresponds to */
46 hdf5_gen_path("/wall/wall_2D_XXXXXXXXXX", qid, path);
47 if(hdf5_find_group(f, path) == 0) {
48 data->type = wall_type_2D;
49 err = hdf5_wall_read_2D(f, &(data->w2d), qid);
50 }
51 hdf5_gen_path("/wall/wall_3D_XXXXXXXXXX", qid, path);
52 if(hdf5_find_group(f, path) == 0) {
53 data->type = wall_type_3D;
54 err = hdf5_wall_read_3D(f, &(data->w3d), qid);
55 }
56 return err;
57}
58
69int hdf5_wall_read_2D(hid_t f, wall_2d_data* data, char* qid) {
70 #undef WPATH
71 #define WPATH "/wall/wall_2D_XXXXXXXXXX/"
72
73 int nelements;
74 if( hdf5_read_int(WPATH "nelements", &nelements,
75 f, qid, __FILE__, __LINE__) ) {return 1;}
76
77 real* r = (real*) malloc(nelements * sizeof(real));
78 real* z = (real*) malloc(nelements * sizeof(real));
79 if( hdf5_read_double(WPATH "r", r, f, qid, __FILE__, __LINE__) ) {return 1;}
80 if( hdf5_read_double(WPATH "z", z, f, qid, __FILE__, __LINE__) ) {return 1;}
81
82 int err = wall_2d_init(data, nelements, r, z);
83 free(r);
84 free(z);
85 return err;
86}
87
98int hdf5_wall_read_3D(hid_t f, wall_3d_data* data, char* qid) {
99 #undef WPATH
100 #define WPATH "/wall/wall_3D_XXXXXXXXXX/"
101
102 int nelements;
103 if( hdf5_read_int(WPATH "nelements", &nelements,
104 f, qid, __FILE__, __LINE__) ) {return 1;}
105
106 /* Allocate temporary arrays for x1x2x3, y1y2y3, z1z2z3 for each triangle */
107 real* x1x2x3 = (real*)malloc(3 * nelements * sizeof(real));
108 real* y1y2y3 = (real*)malloc(3 * nelements * sizeof(real));
109 real* z1z2z3 = (real*)malloc(3 * nelements * sizeof(real));
110
111 if( hdf5_read_double(WPATH "x1x2x3", x1x2x3,
112 f, qid, __FILE__, __LINE__) ) {return 1;}
113 if( hdf5_read_double(WPATH "y1y2y3", y1y2y3,
114 f, qid, __FILE__, __LINE__) ) {return 1;}
115 if( hdf5_read_double(WPATH "z1z2z3", z1z2z3,
116 f, qid, __FILE__, __LINE__) ) {return 1;}
117
118 int err = wall_3d_init(data, nelements, x1x2x3, y1y2y3, z1z2z3);
119 free(x1x2x3);
120 free(y1y2y3);
121 free(z1z2z3);
122 return err;
123}
double real
Definition ascot5.h:85
herr_t hdf5_find_group(hid_t loc, const char *path)
Checks if given group exists within given hdf5 file. Negative value is returned if the group doesn't ...
int hdf5_read_double(const char *var, real *ptr, hid_t file, char *qid, const char *errfile, int errline)
Read double-valued data from ASCOT5 HDF5 file.
char * hdf5_gen_path(const char *original, char *qid, char *path)
Generate a valid path from a given template and qid.
int hdf5_read_int(const char *var, int *ptr, hid_t file, char *qid, const char *errfile, int errline)
Read int-valued data from ASCOT5 HDF5 file.
Header file for hdf5_helpers.h.
int hdf5_wall_init(hid_t f, wall_data *data, char *qid)
Read wall data from HDF5 file.
Definition hdf5_wall.c:40
int hdf5_wall_read_3D(hid_t f, wall_3d_data *data, char *qid)
Read 3D wall data from HDF5 file.
Definition hdf5_wall.c:98
int hdf5_wall_read_2D(hid_t f, wall_2d_data *data, char *qid)
Read 2D wall data from HDF5 file.
Definition hdf5_wall.c:69
#define WPATH
Definition hdf5_wall.c:20
Header file for hdf5_wall.c.
2D wall data parameters
Definition wall_2d.h:15
3D wall data parameters
Definition wall_3d.h:16
Wall model simulation data.
Definition wall.h:31
wall_type type
Definition wall.h:32
wall_3d_data w3d
Definition wall.h:34
wall_2d_data w2d
Definition wall.h:33
Header file for wall.c.
@ wall_type_2D
Definition wall.h:21
@ wall_type_3D
Definition wall.h:22
int wall_2d_init(wall_2d_data *data, int nelements, real *r, real *z)
Load 2D wall data and prepare parameters.
Definition wall_2d.c:22
Header file for wall_2d.c.
int wall_3d_init(wall_3d_data *data, int nelements, real *x1x2x3, real *y1y2y3, real *z1z2z3)
Initialize 3D wall data and check inputs.
Definition wall_3d.c:46
Header file for wall_3d.c.