ASCOT5
Loading...
Searching...
No Matches
hdf5_transcoef.c
Go to the documentation of this file.
1
5#include <string.h>
6#include <stdlib.h>
7#include <stdio.h>
8#include <math.h>
9#include <hdf5.h>
10#include <hdf5_hl.h>
11#include "hdf5_helpers.h"
12#include "../ascot5.h"
14#include "hdf5_transcoef.h"
15
26int hdf5_transcoef_write(hid_t f, char* path, diag_transcoef_data* data) {
27 hid_t group = H5Gcreate2(f, path, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
28 if(group < 0) {
29 return 1;
30 }
31
32 /* Find number of (valid) data points in the coefarray */
33 int arrlen = data->Nmrk;
34 int datasize = 0;
35 integer* mask = malloc(arrlen*sizeof(real));
36 for(integer i=0; i < arrlen; i++) {
37 mask[i] = data->id[i] > 0;
38 if(mask[i]) {
39 datasize++;
40 }
41 }
42
43 /* Write IDs*/
44 integer j = 0;
45 integer* idarr = (integer*) malloc(datasize * sizeof(integer));
46 for(integer i = 0; i < arrlen; i++) {
47 if(mask[i]) {
48 idarr[j] = data->id[i];
49 j++;
50 }
51 }
52 hdf5_write_extendible_dataset_long(group, "ids", datasize, idarr);
53 free(idarr);
54
55 /* Write K and D */
56 j = 0;
57 real* dataarr = (real*) malloc(datasize * sizeof(real));
58 for(integer i = 0; i < arrlen; i++) {
59 if(mask[i]) {
60 dataarr[j] = data->Kcoef[i];
61 j++;
62 }
63 }
64 hdf5_write_extendible_dataset_double(group, "k", datasize, dataarr);
65
66 j = 0;
67 for(integer i = 0; i < arrlen; i++) {
68 if(mask[i]) {
69 dataarr[j] = data->Dcoef[i];
70 j++;
71 }
72 }
73 hdf5_write_extendible_dataset_double(group, "d", datasize, dataarr);
74 free(dataarr);
75 free(mask);
76
77 /* Write units */
78 H5LTset_attribute_string(group, "ids", "unit", "1");
79 if( data->recordrho ) {
80 H5LTset_attribute_string(group, "k", "unit", "1/s");
81 H5LTset_attribute_string(group, "d", "unit", "1/s");
82 }
83 else {
84 H5LTset_attribute_string(group, "k", "unit", "m/s");
85 H5LTset_attribute_string(group, "d", "unit", "m^2/s");
86 }
87
88 H5Gclose (group);
89
90 return 0;
91}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
long integer
Definition ascot5.h:84
Header file for diag_transcoef.c.
herr_t hdf5_write_extendible_dataset_long(hid_t group, const char *datasetname, int length, long *data)
Create and write to an extendible dataset for long data.
herr_t hdf5_write_extendible_dataset_double(hid_t group, const char *datasetname, int length, double *data)
Create and write to an extendible dataset for double data.
Header file for hdf5_helpers.h.
int hdf5_transcoef_write(hid_t f, char *path, diag_transcoef_data *data)
Write transport coefficients to a HDF5 file.
Header file for hdf5_transcoef.c.
Header file for math.c.
Transport coefficient diagnostics offload data struct.