cctw  0.2.1
Macros | Functions | Variables
cctw-dummies.cpp File Reference
#include <stdbool.h>
#include <stdlib.h>
#include "cctw-dummies.h"
Include dependency graph for cctw-dummies.cpp:

Go to the source code of this file.

Macros

#define UNUSED   __attribute__((unused))
 

Functions

static void initialize (void)
 
static int random_output_count (void)
 
output_entry ** allocate_output_entries (int count)
 
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)
 
static void random_indices (int max_i, int max_j, int max_k, int *i, int *j, int *k)
 
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)
 
bool serialize_output_entries (output_entry *output)
 
void free_output_entries (output_entry **outputs, int output_count)
 

Variables

static bool initialized
 
static unsigned int seedp
 

Macro Definition Documentation

#define UNUSED   __attribute__((unused))

Definition at line 7 of file cctw-dummies.cpp.

Function Documentation

output_entry** allocate_output_entries ( int  count)

Definition at line 29 of file cctw-dummies.cpp.

30 {
31  output_entry** result =
32  (output_entry**) malloc(count*sizeof(output_entry*));
33  return result;
34 }
Definition: cctw-dummies.h:4
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 
)

Definition at line 61 of file cctw-dummies.cpp.

References output_entry::i, output_entry::intensity, output_entry::intensity_count, output_entry::j, output_entry::k, random_indices(), random_output_count(), output_entry::weight, and output_entry::weight_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 }
int k
Definition: cctw-dummies.h:8
int intensity_count
Definition: cctw-dummies.h:10
static int random_output_count(void)
int weight_count
Definition: cctw-dummies.h:12
double * intensity
Definition: cctw-dummies.h:9
int j
Definition: cctw-dummies.h:7
double * weight
Definition: cctw-dummies.h:11
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
void free_output_entries ( output_entry **  outputs,
int  output_count 
)

Definition at line 106 of file cctw-dummies.cpp.

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  )
static

Definition at line 13 of file cctw-dummies.cpp.

References seedp.

Referenced by Cctwtcl_Initialize(), and random_output_count().

14 {
15  seedp = 4;
16  rand_r(&seedp);
17 }
static unsigned int seedp
static void random_indices ( int  max_i,
int  max_j,
int  max_k,
int *  i,
int *  j,
int *  k 
)
static

Definition at line 85 of file cctw-dummies.cpp.

References seedp.

Referenced by forward_transform().

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 }
static unsigned int seedp
static int random_output_count ( void  )
static

Definition at line 19 of file cctw-dummies.cpp.

References initialize(), initialized, and seedp.

Referenced by forward_transform().

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 }
static void initialize(void)
static unsigned int seedp
static bool initialized
Definition: cctw-dummies.cpp:9
bool read_hdf_fragment ( UNUSED const char *  filename,
void **  output,
int *  output_length 
)

Definition at line 36 of file cctw-dummies.cpp.

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 }
bool serialize_output_entries ( output_entry output)

Definition at line 97 of file cctw-dummies.cpp.

References output_entry::intensity_count, and output_entry::weight_count.

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 }
int intensity_count
Definition: cctw-dummies.h:10
int weight_count
Definition: cctw-dummies.h:12
bool unpack_fragment ( void *  fragment,
UNUSED void *  fragment_length,
double **  intensity,
int *  intensity_count,
double **  weight,
int *  weight_count 
)

Definition at line 46 of file cctw-dummies.cpp.

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 }

Variable Documentation

bool initialized
static

Definition at line 9 of file cctw-dummies.cpp.

Referenced by random_output_count().

unsigned int seedp
static

Definition at line 11 of file cctw-dummies.cpp.

Referenced by initialize(), random_indices(), and random_output_count().