PIPS
tools.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <complex.h>
+ Include dependency graph for tools.c:

Go to the source code of this file.

Macros

#define _print_array(name, ptr, n, format, stype)
 

Functions

int _init_data (char *ptr, const ssize_t n)
 
void init_data_file (const char *data_file)
 
void close_data_file ()
 
void print_array_float (const char *name, const float *arr, const unsigned int n)
 
void print_array_int (const char *name, const int *arr, const unsigned int n)
 
void print_array_double (const char *name, const float *arr, const unsigned int n)
 
void print_array_long (const char *name, const long *arr, const unsigned int n)
 
void print_array_cplx (const char *name, const float complex *arr, const unsigned int n)
 
int init_data_gen (void *ptr, const unsigned int n, const ssize_t stype)
 
int init_data_float (float *ptr, const unsigned int n)
 
int init_data_double (double *ptr, const unsigned int n)
 
int init_data_long (long *ptr, const unsigned int n)
 
int init_data_int (int *ptr, const unsigned int n)
 
int init_data_cplx (float complex *ptr, const unsigned int n)
 
void init_args (int argc, char **argv)
 

Variables

static FILE * _f_data_file = 0
 

Macro Definition Documentation

◆ _print_array

#define _print_array (   name,
  ptr,
  n,
  format,
  stype 
)
Value:
int i; \
char formatnl[10]; \
printf("%s :\n", name); \
printf("----\n"); \
formatnl[7] = 0; \
strncpy(formatnl, format, 7); \
strncat(formatnl, "\n", 2); \
for (i = 0; i < n; i++) \
printf(formatnl, *(ptr+i)); \
printf("----\n");
int printf()

Definition at line 19 of file tools.c.

Function Documentation

◆ _init_data()

int _init_data ( char *  ptr,
const ssize_t  n 
)

Definition at line 83 of file tools.c.

84 {
85  ssize_t nr;
86  ssize_t ntoread;
87 
88  ntoread = n;
89  if (_f_data_file == 0)
90  {
91  fprintf(stderr, "Data file must be initialized !\n");
92  exit(1);
93  }
94  while (ntoread > 0)
95  {
96  nr = fread(ptr, 1, ntoread, _f_data_file);
97  if (nr == 0 && ferror(_f_data_file))
98  {
99  perror("read data file");
100  clearerr(_f_data_file);
101  return errno;
102  }
103  if (nr < ntoread)
104  {
105  // fprintf(stderr, "%d bytes remaining...\n", ntoread-nr);
106  fseek(_f_data_file, 0L, SEEK_SET);
107  fflush(_f_data_file);
108  }
109  ntoread -= nr;
110  ptr += nr;
111  }
112 
113  // Old implementation... :
114  //fprintf(stderr, "Warning: missing %d bytes in data file ! Filling with zeros...\n", n-nr);
115  // This makes pips crashes... !!
116  //memset(ptr + nr, 0, n-nr);
117  return nr;
118 }
#define exit(code)
Definition: misc-local.h:54
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
Definition: pip__tab.h:30
static FILE * _f_data_file
Definition: tools.c:32

References _f_data_file, exit, and fprintf().

Referenced by init_data_gen().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ close_data_file()

void close_data_file ( )

Definition at line 48 of file tools.c.

49 {
50  if (_f_data_file != 0)
51  fclose(_f_data_file);
52 }

References _f_data_file.

Referenced by main().

+ Here is the caller graph for this function:

◆ init_args()

void init_args ( int  argc,
char **  argv 
)

Definition at line 151 of file tools.c.

152 {
153  if (argc < 3)
154  {
155  fprintf(stderr, "Usage: %s kernel_size data_file\n", argv[0]);
156  exit(1);
157  }
158  init_data_file(argv[2]);
159 }
void init_data_file(const char *data_file)
Definition: tools.c:36

References exit, fprintf(), and init_data_file().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_data_cplx()

int init_data_cplx ( float complex *  ptr,
const unsigned int  n 
)

Definition at line 146 of file tools.c.

147 {
148  return 0;
149 }

◆ init_data_double()

int init_data_double ( double *  ptr,
const unsigned int  n 
)

Definition at line 131 of file tools.c.

132 {
133  return init_data_gen(ptr, n, sizeof(double));
134 }
int init_data_gen(void *ptr, const unsigned int n, const ssize_t stype)
Definition: tools.c:120

References init_data_gen().

+ Here is the call graph for this function:

◆ init_data_file()

void init_data_file ( const char *  data_file)

Definition at line 36 of file tools.c.

37 {
38  if (_f_data_file != 0)
39  return;
40  _f_data_file = fopen(data_file, "r");
41  if (_f_data_file == 0)
42  {
43  perror("open data file");
44  exit(errno);
45  }
46 }

References _f_data_file, and exit.

Referenced by init_args(), and main().

+ Here is the caller graph for this function:

◆ init_data_float()

int init_data_float ( float *  ptr,
const unsigned int  n 
)

Definition at line 125 of file tools.c.

126 {
127  int r = init_data_gen(ptr, n, sizeof(float));
128  return r;
129 }

References init_data_gen().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_data_gen()

int init_data_gen ( void *  ptr,
const unsigned int  n,
const ssize_t  stype 
)

Definition at line 120 of file tools.c.

121 {
122  return _init_data(ptr, (ssize_t)(n)*stype);
123 }
int _init_data(char *ptr, const ssize_t n)
Definition: tools.c:83

References _init_data().

Referenced by init_data_double(), init_data_float(), init_data_int(), and init_data_long().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_data_int()

int init_data_int ( int ptr,
const unsigned int  n 
)

Definition at line 141 of file tools.c.

142 {
143  return init_data_gen(ptr, n, sizeof(int));
144 }

References init_data_gen().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_data_long()

int init_data_long ( long *  ptr,
const unsigned int  n 
)

Definition at line 136 of file tools.c.

137 {
138  return init_data_gen(ptr, n, sizeof(long));
139 }

References init_data_gen().

+ Here is the call graph for this function:

◆ print_array_cplx()

void print_array_cplx ( const char *  name,
const float complex *  arr,
const unsigned int  n 
)

Definition at line 74 of file tools.c.

75 {
76  int i;
77  for (i=0; i<n;i++)
78  {
79  printf("%f %f\n",crealf(arr[i]),cimagf(arr[i]));
80  }
81 }

References printf().

+ Here is the call graph for this function:

◆ print_array_double()

void print_array_double ( const char *  name,
const float *  arr,
const unsigned int  n 
)

Definition at line 64 of file tools.c.

65 {
66  _print_array(name, arr, n, "%a", sizeof(double));
67 }
#define _print_array(name, ptr, n, format, stype)
Definition: tools.c:19

References _print_array.

◆ print_array_float()

void print_array_float ( const char *  name,
const float *  arr,
const unsigned int  n 
)

Definition at line 54 of file tools.c.

55 {
56  _print_array(name, arr, n, "%f", sizeof(float));
57 }

References _print_array.

Referenced by main().

+ Here is the caller graph for this function:

◆ print_array_int()

void print_array_int ( const char *  name,
const int arr,
const unsigned int  n 
)

Definition at line 59 of file tools.c.

60 {
61  _print_array(name, arr, n, "%d", sizeof(int));
62 }

References _print_array.

◆ print_array_long()

void print_array_long ( const char *  name,
const long *  arr,
const unsigned int  n 
)

Definition at line 69 of file tools.c.

70 {
71  _print_array(name, arr, n, "%a", sizeof(long));
72 }

References _print_array.

Variable Documentation

◆ _f_data_file

FILE* _f_data_file = 0
static

Definition at line 32 of file tools.c.

Referenced by _init_data(), close_data_file(), and init_data_file().