cctw  0.2.1
cctw-dummies.cpp
Go to the documentation of this file.
1 
2 #include <stdbool.h>
3 #include <stdlib.h>
4 
5 #include "cctw-dummies.h"
6 
7 #define UNUSED __attribute__((unused))
8 
9 static bool initialized;
10 
11 static unsigned int seedp;
12 
13 static void initialize(void)
14 {
15  seedp = 4;
16  rand_r(&seedp);
17 }
18 
19 static int random_output_count(void)
20 {
21  if (!initialized) initialize();
22 
23  int r = rand_r(&seedp);
24  int count = r % 6;
25  if (count == 6) count = 20;
26  return count;
27 }
28 
30 {
31  output_entry** result =
32  (output_entry**) malloc(count*sizeof(output_entry*));
33  return result;
34 }
35 
36 bool read_hdf_fragment(UNUSED const char* filename,
37  void** output, int* output_length)
38 {
39  int count = 1024;
40  int length = count * sizeof(double);
41  *output = calloc(count, sizeof(double));
42  *output_length = length;
43  return true;
44 }
45 
46 bool unpack_fragment(void* fragment, UNUSED void* fragment_length,
47  double** intensity, int* intensity_count,
48  double** weight, int* weight_count)
49 {
50  double* p = (double*) fragment;
51  *intensity = p + 0;
52  *weight = p + 512;
53  *intensity_count = 512;
54  *weight_count = 512;
55  return true;
56 }
57 
58 static void random_indices(int max_i, int max_j, int max_k,
59  int* i, int* j, int* k);
60 
61 bool forward_transform(int max_i, int max_j, int max_k,
62  UNUSED int i, UNUSED int j, UNUSED int k,
63  UNUSED double* intensity, int UNUSED intensity_count,
64  UNUSED double* weight, UNUSED int weight_count,
65  output_entry** output, int* output_count)
66 {
67  int count = random_output_count();
68  for (int c = 0; c < count; c++)
69  {
70  output_entry* entry = (output_entry*) malloc(sizeof(output_entry));
71  random_indices(max_i, max_j, max_k,
72  &entry->i, &entry->j, &entry->k);
73  entry->intensity_count = 10;
74  entry->intensity =
75  (double*) calloc(entry->intensity_count, sizeof(double));
76  entry->weight_count = 10;
77  entry->weight =
78  (double*) calloc(entry->weight_count, sizeof(double));
79  output[c] = entry;
80  }
81  *output_count = count;
82  return true;
83 }
84 
85 static void random_indices(int max_i, int max_j, int max_k,
86  int* i, int* j, int* k)
87 {
88  int r;
89  r = rand_r(&seedp);
90  *i = r % max_i;
91  r = rand_r(&seedp);
92  *j = r % max_j;
93  r = rand_r(&seedp);
94  *k = r % max_k;
95 }
96 
98 {
99  void* buffer = malloc(5 * sizeof(int) +
100  output->intensity_count * sizeof(double) +
101  output->weight_count * sizeof(double));
102  if (!buffer) return false;
103  return true;
104 }
105 
106 void free_output_entries(output_entry** outputs, int output_count)
107 {
108  for (int i = 0; i < output_count; i++)
109  {
110  free(outputs[i]->intensity);
111  free(outputs[i]->weight);
112  free(outputs[i]);
113  }
114  free(outputs);
115 }
static void initialize(void)
bool forward_transform(int max_i, int max_j, int max_k, UNUSED int i, UNUSED int j, UNUSED int k, UNUSED double *intensity, int UNUSED intensity_count, UNUSED double *weight, UNUSED int weight_count, output_entry **output, int *output_count)
static unsigned int seedp
int k
Definition: cctw-dummies.h:8
#define UNUSED
Definition: cctw-dummies.cpp:7
bool serialize_output_entries(output_entry *output)
output_entry ** allocate_output_entries(int count)
int intensity_count
Definition: cctw-dummies.h:10
static int random_output_count(void)
int weight_count
Definition: cctw-dummies.h:12
static bool initialized
Definition: cctw-dummies.cpp:9
double * intensity
Definition: cctw-dummies.h:9
int j
Definition: cctw-dummies.h:7
double * weight
Definition: cctw-dummies.h:11
bool read_hdf_fragment(UNUSED const char *filename, void **output, int *output_length)
bool unpack_fragment(void *fragment, UNUSED void *fragment_length, double **intensity, int *intensity_count, double **weight, int *weight_count)
void free_output_entries(output_entry **outputs, int output_count)
Definition: cctw-dummies.h:4
static void random_indices(int max_i, int max_j, int max_k, int *i, int *j, int *k)
int i
Definition: cctw-dummies.h:6