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
27 real* coefarr) {
28 hid_t group = H5Gcreate2(f, path, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
29 if(group < 0) {
30 return 1;
31 }
32
33 /* Find number of (valid) data points in the coefarray */
34 int arrlen = data->Nmrk;
35 int datasize = 0;
36 integer* mask = malloc(arrlen*sizeof(real));
37 for(integer i=0; i < arrlen; i++) {
38 mask[i] = coefarr[i] > 0;
39 if(mask[i]) {
40 datasize++;
41 }
42 }
43
44 /* Write IDs*/
45 integer j = 0;
46 integer* idarr = (integer*) malloc(datasize * sizeof(integer));
47 for(integer i = 0; i < arrlen; i++) {
48 if(mask[i]) {
49 idarr[j] = coefarr[i];
50 j++;
51 }
52 }
53 hdf5_write_extendible_dataset_long(group, "ids", datasize, idarr);
54 free(idarr);
55
56 /* Write K and D */
57 j = 0;
58 real* dataarr = (real*) malloc(datasize * sizeof(real));
59 for(integer i = 0; i < arrlen; i++) {
60 if(mask[i]) {
61 dataarr[j] = coefarr[i + arrlen];
62 j++;
63 }
64 }
65 hdf5_write_extendible_dataset_double(group, "k", datasize, dataarr);
66
67 j = 0;
68 for(integer i = 0; i < arrlen; i++) {
69 if(mask[i]) {
70 dataarr[j] = coefarr[i + 2*arrlen];
71 j++;
72 }
73 }
74 hdf5_write_extendible_dataset_double(group, "d", datasize, dataarr);
75 free(dataarr);
76 free(mask);
77
78 /* Write units */
79 H5LTset_attribute_string(group, "ids", "unit", "1");
80 if( data->recordrho ) {
81 H5LTset_attribute_string(group, "k", "unit", "1/s");
82 H5LTset_attribute_string(group, "d", "unit", "1/s");
83 }
84 else {
85 H5LTset_attribute_string(group, "k", "unit", "m/s");
86 H5LTset_attribute_string(group, "d", "unit", "m^2/s");
87 }
88
89 H5Gclose (group);
90
91 return 0;
92}
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_offload_data *data, real *coefarr)
Write transport coefficients to a HDF5 file.
Header file for hdf5_transcoef.c.
Header file for math.c.
Transport coefficient diagnostics offload data struct.