File: s_util.h

package info (click to toggle)
boinc-app-seti 7.28~svn2633-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,328 kB
  • ctags: 5,600
  • sloc: cpp: 47,571; asm: 4,426; ansic: 980; sql: 882; awk: 745; sh: 743; makefile: 602; xml: 463; perl: 280; csh: 204; python: 101
file content (155 lines) | stat: -rw-r--r-- 5,146 bytes parent folder | download
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2003 Regents of the University of California

// SETI_BOINC is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2, or (at your option) any later
// version.

// SETI_BOINC is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
// more details.

// You should have received a copy of the GNU General Public License along
// with SETI_BOINC; see the file COPYING.  If not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

// In addition, as a special exception, the Regents of the University of
// California give permission to link the code of this program with libraries
// that provide specific optimized fast Fourier transform (FFT) functions and
// distribute a linked executable.  You must obey the GNU General Public 
// License in all respects for all of the code used other than the FFT library
// itself.  Any modification required to support these libraries must be
// distributed in source code form.  If you modify this file, you may extend 
// this exception to your version of the file, but you are not obligated to 
// do so. If you do not wish to do so, delete this exception statement from 
// your version.

// $Id: s_util.h,v 1.12.2.10 2006/09/07 00:26:51 korpela Exp $
#ifndef _UTIL_H
#define _UTIL_H

#include <cstdio>
#include <sys/types.h>
#include <string>
#include "track_mem.h"

typedef float sah_complex[2];

// The following is a complete list of #defines used in the code:
// TEXT_UI
// textual UI using printf, scanf
// NOTE: the above are not mutually exclusive
// _WIN32
// windows environment.  does not imply GUI
// _WIN_NT_98
// Win NT or 98 environment
// TEST_VERSION
// include extra command-line options
// HAVE_*
// (POSIX only) presence or absence of functions, .h files
// as generated by configure script

// client file names
#define OUTFILE_FILENAME "result.sah"
#define STATE_FILENAME  "state.sah"
#define WU_FILENAME  "work_unit.sah"
#define CFFT_FILENAME  "cfft.sah"

#define INF 0x7fffffff
#define ROUND(a) ((a) - (long)(a) > .5 ? (long)(a) + 1 : (long)(a))

#define TASK_SETI 2

class seti_error {
  public:
    typedef enum {
      success=0,
      cant_create_file,
      read_failed,
      write_failed,
      malloc_failed,
      fopen_failed,
      bad_header,
      bad_decode,
      bad_bin_read,
      result_overflow,
      unhandled_signal,
      atexit_failure,
      unsupported_function,
      floating_point_fail,
    } errors;
    static const char * const message[];
    seti_error(int e, const char *s=0) : value(-e), data(s) {};
    seti_error(int e, const char *f, int l, const char *s=0) : value(-e), file(f), line(l), data(s) {};
    seti_error(const seti_error &e) : value(e.value), file(e.file), line(e.line), data(e.data) {};
    operator int() const { return -value; };
    void print() const;  
  private:
    int value;
    std::string file;
    int line;
    std::string data;
};
  
   

// error codes
#define SUCCESS				0
#define CANT_CREATE_FILE	(-seti_error::cant_create_file)
#define READ_FAILED 		(-seti_error::read_failed)
#define WRITE_FAILED		(-seti_error::write_failed)
#define MALLOC_FAILED		(-seti_error::malloc_failed)
#define FOPEN_FAILED		(-seti_error::fopen_failed)
#define BAD_HEADER			(-seti_error::bad_header)
#define BAD_DECODE			(-seti_error::bad_decode)
#define BAD_BIN_READ		(-seti_error::bad_bin_read)
#define RESULT_OVERFLOW		(-seti_error::result_overflow)
#define UNHANDLED_SIGNAL	(-seti_error::unhandled_signal)
#define UNSUPPORTED_FUNCTION    (-seti_error::unsupported_function)
#define FP_ERROR         	(-seti_error::floating_point_fail)
#define ATEXIT_FAILURE         	(-seti_error::atexit_failure)

#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif

// The MS & intel compilers don't allow alloca in try/catch blocks
#ifndef FORCE_FRAME_POINTER
#if ( defined(HAVE_ALLOCA) || defined(HAVE_ALLOCA_H) || defined(_WIN32) ) && !( defined(__INTEL_COMPILER) || defined (_MSC_VER) ) 
#define FORCE_FRAME_POINTER alloca(16)
#else
#define FORCE_FRAME_POINTER (0)
#endif
#endif


// macro so we can get file and line info.
#define SETIERROR( err, errmsg ) do { \
        FORCE_FRAME_POINTER; \
	throw seti_error( err, __FILE__, __LINE__, errmsg  ); \
} while (0)

#define CHECKPOINT_SKIPPED	(0)

//#include "seti_header.h"

extern void strip_cr(char*p );

extern void encode(unsigned char* bin, int nbytes, FILE* f);
extern int decode(unsigned char* bin, int nbytes, FILE* f);
extern int read_bin_data(unsigned char* bin, int nbytes, FILE* f);
extern void bits_to_floats(unsigned char* raw, sah_complex *data, int nsamples);
extern int float_to_uchar(
    float float_element[], unsigned char char_element[],
    long num_elements, float scale_factor
  );
extern const char* error_string(int);

#endif