ASCOT5
Loading...
Searching...
No Matches
hdf5_interface.c
Go to the documentation of this file.
1
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <time.h>
12#include <hdf5.h>
13#include <hdf5_hl.h>
14#include "ascot5.h"
15#include "simulate.h"
16#include "print.h"
17#include "gitver.h"
18#include "compiler_flags.h"
19#include "hdf5_interface.h"
20#include "hdf5io/hdf5_helpers.h"
21#include "hdf5io/hdf5_options.h"
22#include "hdf5io/hdf5_bfield.h"
23#include "hdf5io/hdf5_plasma.h"
24#include "hdf5io/hdf5_neutral.h"
25#include "hdf5io/hdf5_efield.h"
26#include "hdf5io/hdf5_wall.h"
27#include "hdf5io/hdf5_boozer.h"
28#include "hdf5io/hdf5_mhd.h"
29#include "hdf5io/hdf5_marker.h"
30#include "hdf5io/hdf5_state.h"
31#include "hdf5io/hdf5_dist.h"
32#include "hdf5io/hdf5_orbit.h"
34#include "hdf5io/hdf5_asigma.h"
35#include "hdf5io/hdf5_nbi.h"
36
37int hdf5_get_active_qid(hid_t f, const char* group, char qid[11]);
38
63 int input_active,
64 real** B_offload_array,
65 real** E_offload_array,
66 real** plasma_offload_array,
67 real** neutral_offload_array,
68 real** wall_offload_array,
69 int** wall_int_offload_array,
70 real** boozer_offload_array,
71 real** mhd_offload_array,
72 real** asigma_offload_array,
73 real** nbi_offload_array,
75 int* n_markers){
76
77 print_out(VERBOSE_IO, "\nReading and initializing input.\n");
78
79 /* This init disables automatic error messages.
80 * We want to generate our own that are more informative.*/
81 hdf5_init();
82
83 /* Check if requested HDF5 file exists and open it */
84 print_out(VERBOSE_IO, "\nInput file is %s.\n", sim->hdf5_in);
85 hid_t f = hdf5_open_ro(sim->hdf5_in);
86 if(f < 0) {
87 print_err("Error: File not found.");
88 return 1;
89 }
90
91 /* Read active input from hdf5 and initialize */
92 char qid[11];
93
94 if(input_active & hdf5_input_options) {
95 if(hdf5_find_group(f, "/options/")) {
96 print_err("Error: No options in input file.");
97 return 1;
98 }
99 print_out(VERBOSE_IO, "\nReading options input.\n");
100 if(sim->qid_options[0] != '\0') {
101 strcpy(qid, sim->qid_options);
102 }
103 else if( hdf5_get_active_qid(f, "/options/", qid) ) {
104 print_err("Error: Active QID not declared.");
105 return 1;
106 }
107 strcpy(sim->qid_options, qid);
108 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
109 if( hdf5_options_read(f, sim, qid) ) {
110 print_err("Error: Failed to initialize options.\n");
111 return 1;
112 }
113 print_out(VERBOSE_IO, "Options read and initialized.\n");
114 }
115
116 if(input_active & hdf5_input_bfield) {
117 if(hdf5_find_group(f, "/bfield/")) {
118 print_err("Error: No magnetic field in input file.");
119 return 1;
120 }
121 print_out(VERBOSE_IO, "\nReading magnetic field input.\n");
122 if(sim->qid_bfield[0] != '\0') {
123 strcpy(qid, sim->qid_bfield);
124 }
125 else if( hdf5_get_active_qid(f, "/bfield/", qid) ) {
126 print_err("Error: Active QID not declared.");
127 return 1;
128 }
129 strcpy(sim->qid_bfield, qid);
130 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
132 B_offload_array, qid) ) {
133 print_err("Error: Failed to initialize magnetic field.\n");
134 return 1;
135 }
136 print_out(VERBOSE_IO, "Magnetic field read and initialized.\n");
137 }
138
139 if(input_active & hdf5_input_efield) {
140 if(hdf5_find_group(f, "/efield/")) {
141 print_err("Error: No electric field in input file.");
142 return 1;
143 }
144 print_out(VERBOSE_IO, "\nReading electric field input.\n");
145 if(sim->qid_efield[0] != '\0') {
146 strcpy(qid, sim->qid_efield);
147 }
148 else if( hdf5_get_active_qid(f, "/efield/", qid) ) {
149 print_err("Error: Active QID not declared.");
150 return 1;
151 }
152 strcpy(sim->qid_efield, qid);
153 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
155 E_offload_array, qid) ) {
156 print_err("Error: Failed to initialize electric field.\n");
157 return 1;
158 }
159 print_out(VERBOSE_IO, "Electric field read and initialized.\n");
160 }
161
162 if(input_active & hdf5_input_plasma) {
163 if(hdf5_find_group(f, "/plasma/")) {
164 print_err("Error: No plasma data in input file.");
165 return 1;
166 }
167 print_out(VERBOSE_IO, "\nReading plasma input.\n");
168 if(sim->qid_plasma[0] != '\0') {
169 strcpy(qid, sim->qid_plasma);
170 }
171 else if( hdf5_get_active_qid(f, "/plasma/", qid) ) {
172 print_err("Error: Active QID not declared.");
173 return 1;
174 }
175 strcpy(sim->qid_plasma, qid);
176 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
178 plasma_offload_array, qid) ) {
179 print_err("Error: Failed to initialize plasma data.\n");
180 return 1;
181 }
182 print_out(VERBOSE_IO, "Plasma data read and initialized.\n");
183 }
184
185 if(input_active & hdf5_input_neutral) {
186 if(hdf5_find_group(f, "/neutral/")) {
187 print_err("Error: No neutral data in input file.");
188 return 1;
189 }
190 print_out(VERBOSE_IO, "\nReading neutral input.\n");
191 if(sim->qid_neutral[0] != '\0') {
192 strcpy(qid, sim->qid_neutral);
193 }
194 else if( hdf5_get_active_qid(f, "/neutral/", qid) ) {
195 print_err("Error: Active QID not declared.");
196 return 1;
197 }
198 strcpy(sim->qid_neutral, qid);
199 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
201 neutral_offload_array, qid) ) {
202 print_err("Error: Failed to initialize neutral data.\n");
203 return 1;
204 }
205 print_out(VERBOSE_IO, "Neutral data read and initialized.\n");
206 }
207
208 if(input_active & hdf5_input_wall) {
209 if(hdf5_find_group(f, "/wall/")) {
210 print_err("Error: No wall data in input file.");
211 return 1;
212 }
213 print_out(VERBOSE_IO, "\nReading wall input.\n");
214 if(sim->qid_wall[0] != '\0') {
215 strcpy(qid, sim->qid_wall);
216 }
217 else if( hdf5_get_active_qid(f, "/wall/", qid) ) {
218 print_err("Error: Active QID not declared.");
219 return 1;
220 }
221 strcpy(sim->qid_wall, qid);
222 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
224 wall_offload_array, wall_int_offload_array,
225 qid) ) {
226 print_err("Error: Failed to initialize wall.\n");
227 return 1;
228 }
229 print_out(VERBOSE_IO, "Wall data read and initialized.\n");
230 }
231
232 if(input_active & hdf5_input_boozer) {
233 if(hdf5_find_group(f, "/boozer/")) {
234 print_err("Error: No boozer data in input file.");
235 return 1;
236 }
237 print_out(VERBOSE_IO, "\nReading boozer input.\n");
238 if(sim->qid_boozer[0] != '\0') {
239 strcpy(qid, sim->qid_boozer);
240 }
241 else if( hdf5_get_active_qid(f, "/boozer/", qid) ) {
242 print_err("Error: Active QID not declared.");
243 return 1;
244 }
245 strcpy(sim->qid_boozer, qid);
246 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
248 boozer_offload_array, qid) ) {
249 print_err("Error: Failed to read boozer input.\n");
250 return 1;
251 }
252 print_out(VERBOSE_IO, "Boozer data read and initialized.\n");
253 }
254
255 if(input_active & hdf5_input_mhd) {
256 if(hdf5_find_group(f, "/mhd/")) {
257 print_err("Error: No MHD data in input file.");
258 return 1;
259 }
260 print_out(VERBOSE_IO, "\nReading MHD input.\n");
261 if(sim->qid_mhd[0] != '\0') {
262 strcpy(qid, sim->qid_mhd);
263 }
264 else if( hdf5_get_active_qid(f, "/mhd/", qid) ) {
265 print_err("Error: Active QID not declared.");
266 return 1;
267 }
268 strcpy(sim->qid_mhd, qid);
269 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
271 mhd_offload_array, qid) ) {
272 print_err("Error: Failed to read MHD input.\n");
273 return 1;
274 }
275 print_out(VERBOSE_IO, "MHD data read and initialized.\n");
276 }
277
278 if(input_active & hdf5_input_asigma) {
279 if(hdf5_find_group(f, "/asigma/")) {
280 print_err("Error: No atomic reaction data in input file.");
281 return 1;
282 }
283 print_out(VERBOSE_IO, "\nReading atomic reaction input.\n");
284 if(sim->qid_asigma[0] != '\0') {
285 strcpy(qid, sim->qid_asigma);
286 }
287 else if( hdf5_get_active_qid(f, "/asigma/", qid) ) {
288 print_err("Error: Active QID not declared.");
289 return 1;
290 }
291 strcpy(sim->qid_asigma, qid);
292 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
294 asigma_offload_array, qid) ) {
295 print_err("Error: Failed to initialize atomic reaction data.\n");
296 return 1;
297 }
298 print_out(VERBOSE_IO, "Atomic reaction data read and initialized.\n");
299 }
300
301 if(input_active & hdf5_input_nbi) {
302 if(hdf5_find_group(f, "/nbi/")) {
303 print_err("Error: No NBI data in input file.");
304 return 1;
305 }
306 print_out(VERBOSE_IO, "\nReading NBI input.\n");
307 if(sim->qid_nbi[0] != '\0') {
308 strcpy(qid, sim->qid_nbi);
309 }
310 else if( hdf5_get_active_qid(f, "/nbi/", qid) ) {
311 print_err("Error: Active QID not declared.");
312 return 1;
313 }
314 strcpy(sim->qid_nbi, qid);
315 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
317 nbi_offload_array, qid) ) {
318 print_err("Error: Failed to initialize NBI data.\n");
319 return 1;
320 }
321 print_out(VERBOSE_IO, "NBI data read and initialized.\n");
322 }
323
324 if(input_active & hdf5_input_marker) {
325 if(hdf5_find_group(f, "/marker/")) {
326 print_err("Error: No marker data in input file.");
327 return 1;
328 }
329 print_out(VERBOSE_IO, "\nReading marker input.\n");
330 if(sim->qid_marker[0] != '\0') {
331 strcpy(qid, sim->qid_marker);
332 }
333 else if( hdf5_get_active_qid(f, "/marker/", qid) ) {
334 print_err("Error: Active QID not declared.");
335 return 1;
336 }
337 strcpy(sim->qid_marker, qid);
338 print_out(VERBOSE_IO, "Active QID is %s\n", qid);
339 if( hdf5_marker_read(f, n_markers, p, qid) ) {
340 print_err("Error: Failed to read markers.\n");
341 return 1;
342 }
343 print_out(VERBOSE_IO, "Marker data read and initialized.\n");
344 }
345
346 /* Close the hdf5 file */
347 if( hdf5_close(f) ) {
348 print_err("Error: Could not close the file.\n");
349 return 1;
350 }
351
352 print_out(VERBOSE_IO, "\nAll input read and initialized.\n");
353 return 0;
354}
355
374int hdf5_interface_init_results(sim_offload_data* sim, char* qid, char* run) {
375
376 /* Create new file for the output if one does not yet exist. */
377 hid_t fout = hdf5_create(sim->hdf5_out);
378 if(fout < 0) {
379 print_out(VERBOSE_IO, "Note: Output file %s is already present.\n",
380 sim->hdf5_out);
381 }
382 else {
383 hdf5_close(fout);
384 }
385
386 /* Open output file. */
387 fout = hdf5_open(sim->hdf5_out);
388 if(fout < 0) {
389 print_err("Error: Output file %s doesn't exists.\n", sim->hdf5_out);
390 return 1;
391 }
392
393 /* Create a run group for this specific run (and results group if one */
394 /* doesn't exist already. */
395 char runpath[200], path[256];
396 sprintf(runpath, "/results/%s_XXXXXXXXXX", run);
397 hdf5_gen_path(runpath, qid, path);
398 hid_t newgroup = hdf5_create_group(fout, path);
399
400 /* If a run with identical qid exists, abort. */
401 print_out(VERBOSE_IO, "\nThe qid of this run is %s\n", qid);
402 if(newgroup < 0) {
403 print_err("Error: A run with qid %s already exists.\n", qid);
404 hdf5_close(fout);
405 return 1;
406 }
407 H5Gclose(newgroup);
408
409 /* Set this run as the active run. */
410 hdf5_write_string_attribute(fout, "/results", "active", qid);
411
412 /* Open input file (if different file than the output) */
413 hid_t fin = fout;
414 if( strcmp(sim->hdf5_in, sim->hdf5_out) != 0 ) {
415 fin = hdf5_open(sim->hdf5_in);
416 }
417
418 /* Record input QIDs from sim struct to output group. */
419 if(sim->qid_options[0] != '\0') {
421 fout, path, "qid_options", sim->qid_options);
422 }
423
424 if(sim->qid_bfield[0] != '\0') {
426 fout, path, "qid_bfield", sim->qid_bfield);
427 }
428
429 if(sim->qid_efield[0] != '\0') {
431 fout, path, "qid_efield", sim->qid_efield);
432 }
433
434 if(sim->qid_plasma[0] != '\0') {
436 fout, path, "qid_plasma", sim->qid_plasma);
437 }
438
439 if(sim->qid_neutral[0] != '\0') {
441 fout, path, "qid_neutral", sim->qid_neutral);
442 }
443
444 if(sim->qid_wall[0] != '\0') {
446 fout, path, "qid_wall", sim->qid_wall);
447 }
448
449 if(sim->qid_marker[0] != '\0') {
451 fout, path, "qid_marker", sim->qid_marker);
452 }
453
454 if(sim->qid_boozer[0] != '\0') {
456 fout, path, "qid_boozer", sim->qid_boozer);
457 }
458
459 if(sim->qid_mhd[0] != '\0') {
461 fout, path, "qid_mhd", sim->qid_mhd);
462 }
463
464 if(sim->qid_asigma[0] != '\0') {
466 fout, path, "qid_asigma", sim->qid_asigma);
467 }
468
469 if(sim->qid_nbi[0] != '\0') {
471 fout, path, "qid_nbi", sim->qid_nbi);
472 }
473
474 /* If input and output are different files, close input */
475 if( strcmp(sim->hdf5_in, sim->hdf5_out) != 0 ) {
476 hdf5_close(fin);
477 }
478
479 /* Set a description, repository status, and date; close the file. */
480 hdf5_write_string_attribute(fout, path, "description", sim->description);
481
482#ifdef GIT_VERSION
483 char git[256];
484 sprintf(git, "Tag %s Branch %s", GIT_VERSION, GIT_BRANCH);
485 hdf5_write_string_attribute(fout, path, "repository", git);
486#else
487 hdf5_write_string_attribute(fout, path, "repository",
488 "Not under version control");
489#endif
490
491 time_t t = time(NULL);
492 struct tm tm = *localtime(&t);
493 char date[21];
494 sprintf(date, "%04hu-%02hu-%02hu %02hu:%02hu:%02hu.", tm.tm_year + 1900,
495 tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
496 hdf5_write_string_attribute(fout, path, "date", date);
497
498 /* Write compiler flags from stringified macros */
499 hdf5_write_string_attribute(fout, path, "CFLAGS", str_macro(CFLAGS));
500 hdf5_write_string_attribute(fout, path, "CC", str_macro(CC));
501
502 hdf5_close(fout);
503
504 return 0;
505}
506
517int hdf5_interface_write_state(char* fn, char* state, integer n,
518 particle_state* p) {
519 hid_t f = hdf5_open(fn);
520 if(f < 0) {
521 print_err("Error: File not found.\n");
522 return 1;
523 }
524
525 char qid[11];
526 if( hdf5_get_active_qid(f, "/results/", qid) ) {
527 print_err("Error: Active QID was not written to results group.\n");
528 hdf5_close(f);
529 return 1;
530 }
531 char run[256];
532 run[0] = '\0';
533 if(run[0] == '\0') {
534 /* Check if this an ascot5_main run */
535 sprintf(run, "/results/run_%s/", qid);
536 if( hdf5_find_group(f, run) < 0 ) {
537 run[0] = '\0';
538 }
539 }
540 if(run[0] == '\0') {
541 /* Check if this an bbnbi5 run */
542 sprintf(run, "/results/bbnbi_%s/", qid);
543 if( hdf5_find_group(f, run) < 0 ) {
544 run[0] = '\0';
545 }
546 }
547 if(run[0] == '\0') {
548 /* Check if this an afsi5 run */
549 sprintf(run, "/results/afsi_%s/", qid);
550 if( hdf5_find_group(f, run) < 0 ) {
551 run[0] = '\0';
552 }
553 }
554 if(run[0] == '\0') {
555 print_err("Error: Run group not found.\n");
556 }
557
558 if( hdf5_state_write(f, run, state, n, p) ) {
559 print_err("Error: State could not be written.\n");
560 hdf5_close(f);
561 return 1;
562 }
563
564 hdf5_close(f);
565 return 0;
566}
567
578 real* diag_offload_array, char* out) {
579 char path[256]; /* For storing dataset names */
580 print_out(VERBOSE_IO, "\nWriting diagnostics output.\n");
581
582 hid_t f = hdf5_open(out);
583 if(f < 0) {
584 print_err("Error: File not found.\n");
585 return 1;
586 }
587
588 char qid[11];
589 if( hdf5_get_active_qid(f, "/results/", qid) ) {
590 print_err("Error: Active QID was not written to results group.\n");
591 hdf5_close(f);
592 return 1;
593 }
594 char run[256];
595 run[0] = '\0';
596 if(run[0] == '\0') {
597 /* Check if this an ascot5_main run */
598 sprintf(run, "/results/run_%s/", qid);
599 if( hdf5_find_group(f, run) < 0 ) {
600 run[0] = '\0';
601 }
602 }
603 if(run[0] == '\0') {
604 /* Check if this an bbnbi5 run */
605 sprintf(run, "/results/bbnbi_%s/", qid);
606 if( hdf5_find_group(f, run) < 0 ) {
607 run[0] = '\0';
608 }
609 }
610 if(run[0] == '\0') {
611 /* Check if this an afsi5 run */
612 sprintf(run, "/results/afsi_%s/", qid);
613 if( hdf5_find_group(f, run) < 0 ) {
614 run[0] = '\0';
615 }
616 }
617 if(run[0] == '\0') {
618 print_err("Error: Run group not found.\n");
619 }
620
622 print_out(VERBOSE_IO, "\nWriting 5D distribution.\n");
624 sprintf(path, "%sdist5d", run);
626 &diag_offload_array[idx]) ) {
627 print_err("Warning: 5D distribution could not be written.\n");
628 }
629 }
630
632 print_out(VERBOSE_IO, "\nWriting 6D distribution.\n");
634 sprintf(path, "%sdist6d", run);
636 &diag_offload_array[idx]) ) {
637 print_err("Warning: 6D distribution could not be written.\n");
638 }
639 }
641 print_out(VERBOSE_IO, "\nWriting rho 5D distribution.\n");
643 sprintf(path, "%sdistrho5d", run);
645 &diag_offload_array[idx]) ) {
646 print_err("Warning: rho 5D distribution could not be written.\n");
647 }
648 }
649
651 print_out(VERBOSE_IO, "\nWriting rho 6D distribution.\n");
653 sprintf(path, "%sdistrho6d", run);
655 &diag_offload_array[idx]) ) {
656 print_err("Warning: rho 6D distribution could not be written.\n");
657 }
658 }
659
661 print_out(VERBOSE_IO, "\nWriting COM distribution.\n");
663 sprintf(path, "%sdistcom", run);
665 &diag_offload_array[idx]) ) {
666 print_err("Warning: COM distribution could not be written.\n");
667 }
668 }
669
671 print_out(VERBOSE_IO, "Writing orbit diagnostics.\n");
673 sprintf(path, "%sorbit", run);
674 if( hdf5_orbit_write(f, path, &sim->diag_offload_data.diagorb,
675 &diag_offload_array[idx]) ) {
676 print_err("Warning: Orbit diagnostics could not be written.\n");
677 }
678 }
679
681 print_out(VERBOSE_IO, "Writing transport coefficient diagnostics.\n");
683 sprintf(path, "%stranscoef", run);
685 &diag_offload_array[idx]) ) {
686 print_err("Warning: Coefficients could not be written.\n");
687 }
688 }
689
690 hdf5_close(f);
691
692 print_out(VERBOSE_IO, "\nDiagnostics output written.\n");
693
694 return 0;
695}
696
712int hdf5_get_active_qid(hid_t f, const char* group, char qid[11]) {
713 if( H5LTget_attribute_string(f, group, "active", qid) ) {
714 return 1;
715 }
716 qid[10] = '\0';
717
718 return 0;
719}
720
730void hdf5_generate_qid(char* qid) {
731
732 /* Seed random number generator with current time */
733 struct timespec ts;
734#ifdef __MACH__
735 clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
736#else
737 clock_gettime(CLOCK_REALTIME, &ts);
738#endif
739 srand48( ts.tv_nsec );
740
741 /* Generate a 32 bit random integer by generating signed 32 bit random
742 * integers with mrand48() and choosing the first one that is positive */
743 long int qint = -1;
744 while(qint < 0) {
745 qint = mrand48();
746 }
747
748 /* Convert the random number to a string format */
749 sprintf(qid, "%010lu", (long unsigned int)qint);
750}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
#define str_macro(c)
Definition ascot5.h:69
long integer
Definition ascot5.h:84
int hdf5_asigma_init_offload(hid_t f, asigma_offload_data *offload_data, real **offload_array, char *qid)
Read atomic data from HDF5 file.
Definition hdf5_asigma.c:36
Header file for hdf5_asigma.c.
int hdf5_bfield_init_offload(hid_t f, B_field_offload_data *offload_data, real **offload_array, char *qid)
Initialize magnetic field offload data from HDF5 file.
Definition hdf5_bfield.c:69
Header file for hdf5_bfield.c.
int hdf5_boozer_init_offload(hid_t f, boozer_offload_data *offload_data, real **offload_array, char *qid)
Initialize Boozer offload data from HDF5 file.
Definition hdf5_boozer.c:28
Header file for hdf5_boozer.c.
int hdf5_dist_write_6D(hid_t f, char *path, dist_6D_offload_data *dist, real *hist)
Write 6D distribution to an existing result group.
Definition hdf5_dist.c:82
int hdf5_dist_write_rho5D(hid_t f, char *path, dist_rho5D_offload_data *dist, real *hist)
Write rho 5D distribution to an existing result group.
Definition hdf5_dist.c:141
int hdf5_dist_write_COM(hid_t f, char *path, dist_COM_offload_data *dist, real *hist)
Write constants-of-motion distribution to an existing result group.
Definition hdf5_dist.c:256
int hdf5_dist_write_rho6D(hid_t f, char *path, dist_rho6D_offload_data *dist, real *hist)
Write rho 6D distribution to an existing result group.
Definition hdf5_dist.c:197
int hdf5_dist_write_5D(hid_t f, char *path, dist_5D_offload_data *dist, real *hist)
Write 5D distribution to an existing result group.
Definition hdf5_dist.c:27
int hdf5_efield_init_offload(hid_t f, E_field_offload_data *offload_data, real **offload_array, char *qid)
Read electric field data from HDF5 file.
Definition hdf5_efield.c:57
Header file for hdf5_efielc.c.
hid_t hdf5_create_group(hid_t loc, const char *path)
Create a group (with parent groups if necessary). Returns a handle to the group. Negative on failure.
herr_t hdf5_write_string_attribute(hid_t loc, const char *path, const char *attrname, const char *string)
Write string attribute with null-padding.
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 ...
hid_t hdf5_create(const char *filename)
Create an hdf5 file, fail if file exists. A negative value is returned on failure.
herr_t hdf5_close(hid_t file_id)
Close access to given hdf5 file identifier. A negative value is returned on failure.
char * hdf5_gen_path(const char *original, char *qid, char *path)
Generate a valid path from a given template and qid.
void hdf5_init(void)
Initialize hdf5, right now just disables automatic error messages.
hid_t hdf5_open_ro(const char *filename)
Open a hdf5 file for read only. A negative value is returned on failure.
hid_t hdf5_open(const char *filename)
Open a hdf5 file for reading and writing. A negative value is returned on failure.
Header file for hdf5_helpers.h.
int hdf5_interface_init_results(sim_offload_data *sim, char *qid, char *run)
Initialize run group.
int hdf5_interface_read_input(sim_offload_data *sim, int input_active, real **B_offload_array, real **E_offload_array, real **plasma_offload_array, real **neutral_offload_array, real **wall_offload_array, int **wall_int_offload_array, real **boozer_offload_array, real **mhd_offload_array, real **asigma_offload_array, real **nbi_offload_array, input_particle **p, int *n_markers)
Read and initialize input data.
int hdf5_interface_write_state(char *fn, char *state, integer n, particle_state *p)
Write marker state to HDF5 output.
int hdf5_get_active_qid(hid_t f, const char *group, char qid[11])
Fetch active qid within the given group.
int hdf5_interface_write_diagnostics(sim_offload_data *sim, real *diag_offload_array, char *out)
Write diagnostics to HDF5 output.
void hdf5_generate_qid(char *qid)
Generate an identification number for a run.
Header file for hdf5_interface.c.
@ hdf5_input_marker
@ hdf5_input_plasma
@ hdf5_input_options
@ hdf5_input_wall
@ hdf5_input_neutral
@ hdf5_input_bfield
@ hdf5_input_efield
@ hdf5_input_boozer
@ hdf5_input_mhd
@ hdf5_input_nbi
@ hdf5_input_asigma
int hdf5_marker_read(hid_t f, int *n, input_particle **p, char *qid)
Read marker input.
Definition hdf5_marker.c:41
Header file for hdf5_marker.c.
int hdf5_mhd_init_offload(hid_t f, mhd_offload_data *offload_data, real **offload_array, char *qid)
Initialize MHD offload data from HDF5 file.
Definition hdf5_mhd.c:35
Header file for hdf5_mhd.c.
int hdf5_nbi_init_offload(hid_t f, nbi_offload_data *offload_data, real **offload_array, char *qid)
Initialize NBI offload data from HDF5 file.
Definition hdf5_nbi.c:27
Header file for hdf5_nbi.c.
int hdf5_neutral_init_offload(hid_t f, neutral_offload_data *offload_data, real **offload_array, char *qid)
Initialize neutral data from HDF5 file.
Header file for hdf5_neutral.c.
int hdf5_options_read(hid_t file, sim_offload_data *sim, char *qid)
Read options and diagnostics settings from HDF5 file.
Header file for hdf5_options.c.
int hdf5_orbit_write(hid_t f, char *path, diag_orb_offload_data *data, real *orbits)
Write orbit diagnostics data to a HDF5 file.
Definition hdf5_orbit.c:34
Header file for hdf5_orbit.c.
int hdf5_plasma_init_offload(hid_t f, plasma_offload_data *offload_data, real **offload_array, char *qid)
Read plasma data from HDF5 file.
Definition hdf5_plasma.c:44
Header file for hdf5_plasma.c.
int hdf5_state_write(hid_t f, char *run, char *state, integer n, particle_state *p)
Writes marker state to an ASCOT5 HDF5 file.
Definition hdf5_state.c:36
Header file for hdf5_state.c.
int hdf5_transcoef_write(hid_t f, char *path, diag_transcoef_offload_data *data, real *coefarr)
Write transport coefficients to a HDF5 file.
Header file for hdf5_transcoef.c.
int hdf5_wall_init_offload(hid_t f, wall_offload_data *offload_data, real **offload_array, int **int_offload_array, char *qid)
Read wall data from HDF5 file.
Definition hdf5_wall.c:42
Header file for hdf5_wall.c.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Definition print.h:31
@ VERBOSE_IO
Definition print.h:20
#define print_err(...)
Print to standard error.
Definition print.h:42
Header file for simulate.c.
dist_rho5D_offload_data distrho5D
Definition diag.h:33
size_t offload_distCOM_index
Definition diag.h:42
int distrho6D_collect
Definition diag.h:26
int diagtrcof_collect
Definition diag.h:28
diag_transcoef_offload_data diagtrcof
Definition diag.h:36
int distCOM_collect
Definition diag.h:27
dist_5D_offload_data dist5D
Definition diag.h:31
size_t offload_distrho6D_index
Definition diag.h:41
size_t offload_distrho5D_index
Definition diag.h:40
size_t offload_dist6D_index
Definition diag.h:39
size_t offload_diagtrcof_index
Definition diag.h:44
int distrho5D_collect
Definition diag.h:25
dist_6D_offload_data dist6D
Definition diag.h:32
int dist5D_collect
Definition diag.h:23
dist_rho6D_offload_data distrho6D
Definition diag.h:34
size_t offload_dist5D_index
Definition diag.h:38
int diagorb_collect
Definition diag.h:22
int dist6D_collect
Definition diag.h:24
dist_COM_offload_data distCOM
Definition diag.h:35
size_t offload_diagorb_index
Definition diag.h:43
diag_orb_offload_data diagorb
Definition diag.h:30
Wrapper for marker structs.
Definition particle.h:186
General representation of a marker.
Definition particle.h:40
Simulation offload struct.
Definition simulate.h:55
char qid_wall[256]
Definition simulate.h:134
char qid_options[256]
Definition simulate.h:130
char qid_boozer[256]
Definition simulate.h:137
B_field_offload_data B_offload_data
Definition simulate.h:57
char hdf5_in[256]
Definition simulate.h:120
plasma_offload_data plasma_offload_data
Definition simulate.h:59
neutral_offload_data neutral_offload_data
Definition simulate.h:60
mhd_offload_data mhd_offload_data
Definition simulate.h:63
char qid_nbi[256]
Definition simulate.h:140
char qid_marker[256]
Definition simulate.h:133
char qid_mhd[256]
Definition simulate.h:138
asigma_offload_data asigma_offload_data
Definition simulate.h:64
boozer_offload_data boozer_offload_data
Definition simulate.h:62
wall_offload_data wall_offload_data
Definition simulate.h:61
nbi_offload_data nbi_offload_data
Definition simulate.h:65
char qid_neutral[256]
Definition simulate.h:136
char qid_bfield[256]
Definition simulate.h:131
E_field_offload_data E_offload_data
Definition simulate.h:58
char qid_plasma[256]
Definition simulate.h:135
char qid_efield[256]
Definition simulate.h:132
char qid_asigma[256]
Definition simulate.h:139
char hdf5_out[256]
Definition simulate.h:121
char description[256]
Definition simulate.h:123
diag_offload_data diag_offload_data
Definition simulate.h:66