ASCOT5
Loading...
Searching...
No Matches
hdf5_efield.c
Go to the documentation of this file.
1
17#include <stdio.h>
18#include <stdlib.h>
19#include <hdf5.h>
20#include <hdf5_hl.h>
21#include "../ascot5.h"
22#include "../E_field.h"
23#include "../Efield/E_TC.h"
24#include "../Efield/E_1DS.h"
25#include "../print.h"
26#include "hdf5_helpers.h"
27#include "hdf5_efield.h"
28
29#define EPATH
31int hdf5_efield_read_1DS(hid_t f, E_1DS_data* data, char* qid);
32int hdf5_efield_read_TC(hid_t f, E_TC_data* data, char* qid);
33
53int hdf5_efield_init(hid_t f, E_field_data* data, char* qid) {
54 char path[256];
55 int err = 1;
56
57 /* Read data the QID corresponds to */
58 hdf5_gen_path("/efield/E_TC_XXXXXXXXXX", qid, path);
59 if( !hdf5_find_group(f, path) ) {
60 data->type = E_field_type_TC;
61 err = hdf5_efield_read_TC(f, &data->ETC, qid);
62 }
63 hdf5_gen_path("/efield/E_1DS_XXXXXXXXXX", qid, path);
64 if(hdf5_find_group(f, path) == 0) {
65 data->type = E_field_type_1DS;
66 err = hdf5_efield_read_1DS(f, &data->E1DS, qid);
67 }
68 return err;
69}
70
80int hdf5_efield_read_1DS(hid_t f, E_1DS_data* data, char* qid) {
81 #undef EPATH
82 #define EPATH "/efield/E_1DS_XXXXXXXXXX/"
83
84 int nrho;
85 real rhomin, rhomax, reff;
86 if( hdf5_read_int(EPATH "nrho", &nrho,
87 f, qid, __FILE__, __LINE__) ) {return 1;}
88 if( hdf5_read_double(EPATH "rhomin", &rhomin,
89 f, qid, __FILE__, __LINE__) ) {return 1;}
90 if( hdf5_read_double(EPATH "rhomax", &rhomax,
91 f, qid, __FILE__, __LINE__) ) {return 1;}
92 if( hdf5_read_double(EPATH "reff", &reff,
93 f, qid, __FILE__, __LINE__) ) {return 1;}
94
95 real* dvdrho = (real*) malloc( nrho*sizeof(real) );
96 if( hdf5_read_double(EPATH "dvdrho", dvdrho,
97 f, qid, __FILE__, __LINE__) ) {return 1;}
98 int err = E_1DS_init(data, nrho, rhomin, rhomax, reff, dvdrho);
99 free(dvdrho);
100 return err;
101}
102
120int hdf5_efield_read_TC(hid_t f, E_TC_data* data, char* qid) {
121 #undef EPATH
122 #define EPATH "/efield/E_TC_XXXXXXXXXX/"
123
124 real exyz[3];
125 if( hdf5_read_double(EPATH "exyz", exyz,
126 f, qid, __FILE__, __LINE__) ) {return 1;}
127 int err = E_TC_init(data, exyz);
128 return err;
129}
int E_1DS_init(E_1DS_data *data, int nrho, real rhomin, real rhomax, real reff, real *dvdrho)
Initialize 1DS electric field data.
Definition E_1DS.c:29
Header file for E_1DS.c.
int E_TC_init(E_TC_data *data, real exyz[3])
Initialize electric field data and check inputs.
Definition E_TC.c:25
Header file for E_TC.c.
Header file for E_field.c.
@ E_field_type_TC
Definition E_field.h:26
@ E_field_type_1DS
Definition E_field.h:27
Main header file for ASCOT5.
double real
Definition ascot5.h:85
int hdf5_efield_init(hid_t f, E_field_data *data, char *qid)
Read electric field data from HDF5 file.
Definition hdf5_efield.c:53
int hdf5_efield_read_TC(hid_t f, E_TC_data *data, char *qid)
Read magnetic field data of type E_TC.
int hdf5_efield_read_1DS(hid_t f, E_1DS_data *data, char *qid)
Read E1DS electric field data from HDF5 file.
Definition hdf5_efield.c:80
#define EPATH
Definition hdf5_efield.c:29
Header file for hdf5_efielc.c.
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.
Macros for printing console output.
1D spline electric field parameters on the target
Definition E_1DS.h:20
Trivial Cartesian electric field simulation data.
Definition E_TC.h:18
Electric field simulation data.
Definition E_field.h:36
E_TC_data ETC
Definition E_field.h:38
E_field_type type
Definition E_field.h:37
E_1DS_data E1DS
Definition E_field.h:39