ASCOT5
Loading...
Searching...
No Matches
hdf5_asigma.c
Go to the documentation of this file.
1
9#include <stdio.h>
10#include <stdlib.h>
11#include <hdf5.h>
12#include <hdf5_hl.h>
13#include "../ascot5.h"
14#include "../asigma.h"
16#include "hdf5_helpers.h"
17#include "hdf5_asigma.h"
18
19int hdf5_asigma_read_loc(hid_t f, asigma_loc_data* data, char* qid);
20
30int hdf5_asigma_init(hid_t f, asigma_data* data, char* qid) {
31
32 char path[256];
33 int err = 1;
34
35 /* Read data the QID corresponds to */
36 hdf5_gen_path("/asigma/asigma_loc_XXXXXXXXXX", qid, path);
37 if(hdf5_find_group(f, path) == 0) {
38 data->type = asigma_type_loc;
39 err = hdf5_asigma_read_loc(f, &data->asigma_loc, qid);
40 }
41
42 return err;
43}
44
55int hdf5_asigma_read_loc(hid_t f, asigma_loc_data* data, char* qid) {
57 #undef ASGMPATH
58 #define ASGMPATH "/asigma/asigma_loc_XXXXXXXXXX/"
60
61 int nreac;
62 if (hdf5_read_int(ASGMPATH "nreac", &nreac,
63 f, qid, __FILE__, __LINE__) ) {return 1;}
64
65 int* ne = (int*) malloc( nreac * sizeof(int) );
66 int* nn = (int*) malloc( nreac * sizeof(int) );
67 int* nT = (int*) malloc( nreac * sizeof(int) );
68 int* z1 = (int*) malloc( nreac * sizeof(int) );
69 int* a1 = (int*) malloc( nreac * sizeof(int) );
70 int* z2 = (int*) malloc( nreac * sizeof(int) );
71 int* a2 = (int*) malloc( nreac * sizeof(int) );
72 int* reactype = (int*) malloc( nreac * sizeof(int) );
73 real* emin = (real*) malloc( nreac * sizeof(real) );
74 real* emax = (real*) malloc( nreac * sizeof(real) );
75 real* nmin = (real*) malloc( nreac * sizeof(real) );
76 real* nmax = (real*) malloc( nreac * sizeof(real) );
77 real* Tmin = (real*) malloc( nreac * sizeof(real) );
78 real* Tmax = (real*) malloc( nreac * sizeof(real) );
79 if (hdf5_read_int(ASGMPATH "nenergy", ne,
80 f, qid, __FILE__, __LINE__) ) {return 1;}
81 if (hdf5_read_int(ASGMPATH "ndensity", nn,
82 f, qid, __FILE__, __LINE__) ) {return 1;}
83 if (hdf5_read_int(ASGMPATH "ntemperature", nT,
84 f, qid, __FILE__, __LINE__) ) {return 1;}
85 if (hdf5_read_int(ASGMPATH "z1", z1,
86 f, qid, __FILE__, __LINE__) ) {return 1;}
87 if (hdf5_read_int(ASGMPATH "a1", a1,
88 f, qid, __FILE__, __LINE__) ) {return 1;}
89 if (hdf5_read_int(ASGMPATH "z2", z2,
90 f, qid, __FILE__, __LINE__) ) {return 1;}
91 if (hdf5_read_int(ASGMPATH "a2", a2,
92 f, qid, __FILE__, __LINE__) ) {return 1;}
93 if (hdf5_read_int(ASGMPATH "reactype", reactype,
94 f, qid, __FILE__, __LINE__) ) {return 1;}
95 if (hdf5_read_double(ASGMPATH "energymin", emin,
96 f, qid, __FILE__, __LINE__) ) {return 1;}
97 if (hdf5_read_double(ASGMPATH "energymax", emax,
98 f, qid, __FILE__, __LINE__) ) {return 1;}
99 if (hdf5_read_double(ASGMPATH "densitymin", nmin,
100 f, qid, __FILE__, __LINE__) ) {return 1;}
101 if (hdf5_read_double(ASGMPATH "densitymax", nmax,
102 f, qid, __FILE__, __LINE__) ) {return 1;}
103 if (hdf5_read_double(ASGMPATH "temperaturemin", Tmin,
104 f, qid, __FILE__, __LINE__) ) {return 1;}
105 if (hdf5_read_double(ASGMPATH "temperaturemax", Tmax,
106 f, qid, __FILE__, __LINE__) ) {return 1;}
107
108 int nsigmadata = 0;
109 for(int i = 0; i < nreac; i++) {
110 nsigmadata += ne[i] * nn[i] * nT[i];
111 }
112 real* sigma = (real*) malloc(nsigmadata * sizeof(real));
113 if( hdf5_read_double(ASGMPATH "sigma", sigma,
114 f, qid, __FILE__, __LINE__) ) {return 1;}
115 int err = asigma_loc_init(data, nreac, z1, a1, z2, a2, reactype,
116 ne, emin, emax, nn, nmin, nmax, nT, Tmin, Tmax,
117 sigma);
118 free(ne);
119 free(nn);
120 free(nT);
121 free(z1);
122 free(a1);
123 free(z2);
124 free(a2);
125 free(reactype);
126 free(emin);
127 free(emax);
128 free(nmin);
129 free(nmax);
130 free(Tmin);
131 free(Tmax);
132 return err;
133}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
Header file for asigma.c.
@ asigma_type_loc
Definition asigma.h:24
int asigma_loc_init(asigma_loc_data *data, int nreac, int *z1, int *a1, int *z2, int *a2, int *reactype, int *ne, real *emin, real *emax, int *nn, real *nmin, real *nmax, int *nT, real *Tmin, real *Tmax, real *sigma)
Initialize local file atomic data and check inputs.
Definition asigma_loc.c:29
Header file for asigma_loc.c.
int hdf5_asigma_read_loc(hid_t f, asigma_loc_data *data, char *qid)
Read atomic sigma data from HDF5 file.
Definition hdf5_asigma.c:55
int hdf5_asigma_init(hid_t f, asigma_data *data, char *qid)
Read atomic data from HDF5 file.
Definition hdf5_asigma.c:30
Header file for hdf5_asigma.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.
Atomic reaction simulation data.
Definition asigma.h:53
asigma_type type
Definition asigma.h:54
asigma_loc_data asigma_loc
Definition asigma.h:55
Local-files atomic reaction simulation data.
Definition asigma_loc.h:15