-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeerkat_output_thread.c
More file actions
90 lines (78 loc) · 2.28 KB
/
meerkat_output_thread.c
File metadata and controls
90 lines (78 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* meerkat_output_thread.c
*/
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include "hashpipe.h"
#include "meerkat_databuf.h"
static void *run(hashpipe_thread_args_t * args)
{
// Local aliases to shorten access to args fields
output_databuf_t *db = (output_databuf_t *)args->ibuf;
hashpipe_status_t st = args->st;
const char * status_key = args->thread_desc->skey;
int c,rv;
int block_idx = 0;
uint64_t mcnt=0;
int nbeams=65;
int nchans=4; //2**19;
int nsamps=8;
int npols=2;
int output_len = nbeams*nchans*nsamps;
FILE * file;
file=fopen("./file.txt","w");
/* Main loop */
while (run_threads()) {
hashpipe_status_lock_safe(&st);
hputi4(st.buf, "OUTBLKIN", block_idx);
hputi8(st.buf, "OUTMCNT",mcnt);
hputs(st.buf, status_key, "waiting");
hashpipe_status_unlock_safe(&st);
sleep(1);
// get new data
while ((rv=output_databuf_wait_filled(db, block_idx))
!= HASHPIPE_OK) {
if (rv==HASHPIPE_TIMEOUT) {
hashpipe_status_lock_safe(&st);
hputs(st.buf, status_key, "blocked");
hashpipe_status_unlock_safe(&st);
continue;
} else {
hashpipe_error(__FUNCTION__, "error waiting for filled databuf");
pthread_exit(NULL);
break;
}
}
hashpipe_status_lock_safe(&st);
hputs(st.buf, status_key, "processing");
hashpipe_status_unlock_safe(&st);
// TODO check mcnt
fwrite(db->block[block_idx].output,sizeof(float),output_len,file);
sleep(1);
hashpipe_status_lock_safe(&st);
//hputi4(st.buf, "DONE");
hashpipe_status_unlock_safe(&st);
output_databuf_set_free(db,block_idx);
block_idx = (block_idx + 1) % db->header.n_block;
mcnt++;
}
fclose(file);
printf("Closing file");
return NULL;
}
static hashpipe_thread_desc_t meerkat_output_thread = {
name: "meerkat_output_thread",
skey: "OUTSTAT",
init: NULL,
run: run,
ibuf_desc: {output_databuf_create},
obuf_desc: {NULL}
};
static __attribute__((constructor)) void ctor()
{
register_hashpipe_thread(&meerkat_output_thread);
}