fixing warnings

This commit is contained in:
Erik Frojdh 2023-10-27 09:24:52 +02:00
parent 9eaa163e4e
commit 916ec20a1c
5 changed files with 34 additions and 32 deletions

View File

@ -6,7 +6,7 @@
//clang-format off
typedef struct {
PyObject_HEAD FILE *fp;
int n_left;
size_t n_left;
Py_ssize_t chunk;
} ClusterFileReader;
//clang-format on
@ -18,7 +18,7 @@ static int ClusterFileReader_init(ClusterFileReader *self, PyObject *args,
PyObject *kwds) {
// Parse file name, accepts string or pathlike objects
const char *fname = NULL;
char *fname = NULL;
self->n_left = 0;
self->chunk = 0;
PyObject *fname_obj = NULL;
@ -27,9 +27,6 @@ static int ClusterFileReader_init(ClusterFileReader *self, PyObject *args,
static char *kwlist[] = {"fname", "chunk", NULL};
// if (!PyArg_ParseTuple(args, "O&", PyUnicode_FSConverter, &buf))
// return -1;
// PyBytes_AsStringAndSize(buf, &fname, &len);
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n", kwlist, &fname_obj,
&self->chunk)) {
@ -45,7 +42,7 @@ static int ClusterFileReader_init(ClusterFileReader *self, PyObject *args,
printf("Opening: %s\n chunk: %lu\n", fname, self->chunk);
#endif
self->fp = fopen(fname, "rb");
self->fp = fopen((const char*)fname, "rb");
// Keep the return code to not return before releasing buffer

View File

@ -22,7 +22,7 @@ static int RawFileReader_init(RawFileReader *self, PyObject *args,
PyObject *kwds) {
// Parse file name, accepts string or pathlike objects
const char *fname = NULL;
char *fname = NULL;
PyObject *fname_obj = NULL;
PyObject *fname_bytes = NULL;
Py_ssize_t len;
@ -48,7 +48,7 @@ static int RawFileReader_init(RawFileReader *self, PyObject *args,
printf("fname: %s\n read_header: %d detector type: %d\n", fname,
self->read_header, self->detector);
#endif
self->fp = fopen(fname, "rb");
self->fp = fopen((const char*)fname, "rb");
// Keep the return code to not return before releasing buffer
int rc = 0;
@ -110,12 +110,12 @@ static PyObject *RawFileReader_read(RawFileReader *self, PyObject *args) {
switch (self->detector) {
case DT_MOENCH_03:
n_read = read_raw_m03(self->fp, n_frames, out_buf, header_out);
n_read = read_raw_m03(self->fp, n_frames, out_buf, (Header*)header_out);
break;
case DT_MOENCH_04_A:
case DT_MOENCH_04_AD:
n_read =
read_raw_m04(self->fp, n_frames, out_buf, digital_out, header_out);
read_raw_m04(self->fp, n_frames, out_buf, digital_out, (Header*)header_out);
break;
default:
break;

View File

@ -1,9 +1,9 @@
#include "cluster_reader.h"
#include <assert.h>
int read_clusters(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_left) {
size_t read_clusters(FILE *fp, size_t n_clusters, Cluster *buf, size_t *n_left) {
int iframe = 0;
int nph = *n_left;
size_t nph = *n_left;
size_t nph_read = 0;
size_t nn = *n_left;
@ -44,23 +44,27 @@ int read_clusters(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_left) {
return nph_read;
}
int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf,
int *n_left, double *noise_map, int nx, int ny) {
size_t read_clusters_with_cut(FILE *fp, size_t n_clusters, Cluster *buf,
size_t *n_left, double *noise_map, int nx, int ny) {
int iframe = 0;
int nph = *n_left;
size_t nph = *n_left;
size_t nph_read = 0;
int32_t tot2[4], t2max, tot1;
int32_t val, tot3;
int32_t t2max, tot1;
int32_t tot3;
Cluster *ptr = buf;
int good = 1;
double noise;
// read photons left from previous frame
if (nph) {
for (int iph = 0; iph < nph; iph++) {
for (size_t iph = 0; iph < nph; iph++) {
// read photons 1 by 1
fread((void *)(ptr), sizeof(Cluster), 1, fp);
size_t n_read = fread((void *)(ptr), sizeof(Cluster), 1, fp);
if (n_read != 1) {
return nph_read;
}
//TODO! error handling on read
good = 1;
if (noise_map) {
if (ptr->x >= 0 && ptr->x < nx && ptr->y >= 0 && ptr->y < ny) {
@ -95,9 +99,12 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf,
if (fread(&nph, sizeof(nph), 1, fp)) {
//printf("** %d\n",nph);
*n_left = nph;
for (int iph=0; iph<nph; iph++) {
for (size_t iph=0; iph<nph; iph++) {
// read photons 1 by 1
fread((void *)(ptr), sizeof(Cluster), 1, fp);
size_t n_read = fread((void *)(ptr), sizeof(Cluster), 1, fp);
if (n_read != 1) {
return nph_read;
}
good=1;
if (noise_map) {
if (ptr->x>=0 && ptr->x<nx && ptr->y>=0 && ptr->y<ny) {
@ -140,10 +147,8 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf,
int analyze_clusters(int64_t n_clusters, int32_t *cin, ClusterAnalysis *co, int csize) {
int32_t tot2[4], t2max;
char quad;
int32_t val, tot;
int32_t tot;
double etax, etay;
int nc=0;
//printf("csize is %d\n",csize);
@ -186,16 +191,16 @@ int analyze_data(int32_t *data, int32_t *t2, int32_t *t3, char *quad, double *et
int ok=1;
int32_t tot2[4], t2max;
int32_t tot2[4];
int32_t t2max=0;
char c;
int32_t val, tot3;
tot3 = 0;
for (int i = 0; i < 4; i++)
tot2[i] = 0;
// t2max=0;
for (int ix = 0; ix < 3; ix++) {
for (int ix = 0; ix < 3; ix++) {
for (int iy = 0; iy < 3; iy++) {
val = data[iy * 3 + ix];
// printf ("%d ",data[iy * 3 + ix]);

View File

@ -5,9 +5,9 @@
#include "data_types.h"
//Pure C implementation to read a cluster file
int read_clusters(FILE* fp, int64_t n_clusters, Cluster* buf, int *n_left);
size_t read_clusters(FILE* fp, size_t n_clusters, Cluster* buf, size_t *n_left);
int read_clusters_with_cut(FILE* fp, int64_t n_clusters, Cluster* buf, int *n_left, double *noise_map, int nx, int ny);
size_t read_clusters_with_cut(FILE* fp, size_t n_clusters, Cluster* buf, size_t *n_left, double *noise_map, int nx, int ny);
int analyze_clusters(int64_t n_clusters, int32_t* cin, ClusterAnalysis *cout, int csize);

View File

@ -44,8 +44,8 @@ int64_t read_raw_m04(FILE *fp, int64_t n_frames, char *frame_out,
const size_t frame_size = 400 * 400 * 2;
const size_t digital_frame_size = 5000 * 8;
char *tmp = malloc(frame_size);
char *digital_tmp = malloc(digital_frame_size);
void *tmp = malloc(frame_size);
void *digital_tmp = malloc(digital_frame_size);
Header h;
int64_t frames_read = 0;
@ -75,7 +75,7 @@ int64_t read_raw_m04(FILE *fp, int64_t n_frames, char *frame_out,
// Decode frame and write to numpy output array
// decode_moench03((uint16_t *)tmp, (uint16_t *)frame_out);
decode_moench04(tmp, digital_tmp, frame_out, digital_out);
decode_moench04(tmp, digital_tmp, (uint16_t*)frame_out, (uint8_t*)digital_out);
frame_out += frame_size;
if (digital_out)