ASCOT5
Loading...
Searching...
No Matches
hdf5_boozer.c
Go to the documentation of this file.
1
6#include <stdlib.h>
7#include <stdio.h>
8#include <hdf5.h>
9#include <hdf5_hl.h>
10#include "../ascot5.h"
11#include "../boozer.h"
12#include "../consts.h"
13#include "hdf5_helpers.h"
14#include "hdf5_boozer.h"
15
26int hdf5_boozer_init(hid_t f, boozer_data* data, char* qid) {
27
29 #undef BOOZERPATH
30 #define BOOZERPATH "/boozer/Boozer_XXXXXXXXXX/"
32
33 /* Read data the QID corresponds to */
34 char path[256];
35 hdf5_gen_path(BOOZERPATH, qid, path);
36 if( hdf5_find_group(f, path) ) {
37 return 1;
38 }
39
40 /* Read parameters. */
41 int ntheta, nthetag, nrzs, npsi;
42 real psimin, psimax;
43 if( hdf5_read_int(BOOZERPATH "ntheta", &ntheta,
44 f, qid, __FILE__, __LINE__) ) {return 1;}
45 if( hdf5_read_int(BOOZERPATH "nthetag", &nthetag,
46 f, qid, __FILE__, __LINE__) ) {return 1;}
47 if( hdf5_read_int(BOOZERPATH "nrzs", &nrzs,
48 f, qid, __FILE__, __LINE__) ) {return 1;}
49 if( hdf5_read_int(BOOZERPATH "npsi", &npsi,
50 f, qid, __FILE__, __LINE__) ) {return 1;}
51 if( hdf5_read_double(BOOZERPATH "psimin", &psimin,
52 f, qid, __FILE__, __LINE__) ) {return 1;}
53 if( hdf5_read_double(BOOZERPATH "psimax", &psimax,
54 f, qid, __FILE__, __LINE__) ) {return 1;}
55
56 /* Read data to offload array */
57 real* rs = (real*) malloc( npsi * nrzs * sizeof(real) );
58 real* zs = (real*) malloc( npsi * nrzs * sizeof(real) );
59 real* nu = (real*) malloc( npsi * ntheta * sizeof(real) );
60 real* theta = (real*) malloc( npsi * nthetag * sizeof(real) );
61 if( hdf5_read_double(BOOZERPATH "nu_psitheta", nu,
62 f, qid, __FILE__, __LINE__) ) {return 1;}
63 if( hdf5_read_double(BOOZERPATH "theta_psithetageom", theta,
64 f, qid, __FILE__, __LINE__) ) {return 1;}
65 if( hdf5_read_double(BOOZERPATH "rs", rs,
66 f, qid, __FILE__, __LINE__) ) {return 1;}
67 if( hdf5_read_double(BOOZERPATH "zs", zs,
68 f, qid, __FILE__, __LINE__) ) {return 1;}
69
70 int err = boozer_init(data, npsi, psimin, psimax, ntheta, nthetag,
71 nu, theta, nrzs, rs, zs);
72 free(rs);
73 free(zs);
74 free(nu);
75 free(theta);
76 return err;
77}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
int boozer_init(boozer_data *data, int npsi, real psi_min, real psi_max, int ntheta, int nthetag, real *nu, real *theta, int nrzs, real *rs, real *zs)
Initialize boozer coordinate transformation.
Definition boozer.c:38
Header file for boozer.c.
Header file containing physical and mathematical constants.
int hdf5_boozer_init(hid_t f, boozer_data *data, char *qid)
Initialize Boozer data from HDF5 file.
Definition hdf5_boozer.c:26
Header file for hdf5_boozer.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.
Data for mapping between the cylindrical and Boozer coordinates.
Definition boozer.h:16