forked from lxm1117/pDE_codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjLib.h
161 lines (130 loc) · 5.69 KB
/
jLib.h
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
156
157
158
159
160
161
/* ========================================================================
pDE: Parallel version of Storn and Price's Differential evolution
applied to NEURON modeling
c2005 Jose Ambros-Ingerson jose@kiubo.net
$Date: 2006/10/07 00:39:28 $ $Log: jLib.h,v $
$Date: 2006/10/07 00:39:28 $ Revision 1.5 2006/10/07 00:39:28 jose
$Date: 2006/10/07 00:39:28 $ Added code to include a population of the best in the run for
$Date: 2006/10/07 00:39:28 $ Sensitivity Analysis
$Date: 2006/10/07 00:39:28 $
$Date: 2006/10/07 00:39:28 $ Revision 1.4 2006/07/20 15:28:54 jose
$Date: 2006/10/07 00:39:28 $ Added save_random_state and restore_random_state
$Date: 2006/10/07 00:39:28 $
$Date: 2006/10/07 00:39:28 $ Revision 1.3 2006/07/06 15:17:35 jose
$Date: 2006/10/07 00:39:28 $ added random.h
$Date: 2006/10/07 00:39:28 $
$Date: 2006/10/07 00:39:28 $ Revision 1.2 2005/06/01 20:54:31 jose
$Date: 2006/10/07 00:39:28 $ worked out most warnings in biowulf.biosci.ohiou.edu
$Date: 2006/10/07 00:39:28 $
$Date: 2006/10/07 00:39:28 $ Revision 1.1.1.1 2005/05/20 19:49:14 jose
$Date: 2006/10/07 00:39:28 $ Parallel Differential Evolution
$Date: 2006/10/07 00:39:28 $
======================================================================== */
#ifndef _I_jLib1
#define _I_jLib1 1
#include <stdio.h>
#include <string.h>
/* ================================================================================
jBasic.h
================================================================================ */
#define strEQ(A,B) (! strcmp((A),(B)))
#define strNE(A,B) ( strcmp((A),(B)))
#define DIGIT(s) ((int)(s) >= '0' && (int)(s) <= '9' )
typedef char* AnyPointer;
/* ================================================================================
xmalloc.h
================================================================================ */
char *xmalloc( int n );
char *xrealloc( char *ptr, int n );
void xfree( char *ptr );
/* ================================================================================
random.h
================================================================================ */
typedef struct JRANDOM {
int seed;
long n_count;
} jRandom;
void set_seed( int new_seed );
int see_seed( void );
void save_random_state( jRandom *jR );
void restore_random_state( jRandom *jR );
double du_dev0( void );
double du_dev( double min, double max );
int iu_dev( int min, int max );
double dexp_dev0( void );
double dexp_dev( double lambda );
double dgauss_dev0( void );
double dgauss_dev( double mean, double sdev );
/* ================================================================================
jTime
================================================================================ */
void jTime_now( char *buf, int bufsz, char *strftimeFormat );
/* ================================================================================
jString.h
================================================================================ */
typedef struct JSTRING {
int sz;
char *s;
} jString;
jString* jString_new( void );
void jString_free( jString* jS );
int jLine_read( FILE *fp, jString *Ln );
int str2int( char *s, int *i );
int str2short( char *s, short *si );
int str2double( char *s, double *d );
int str2float( char *s, float *f );
int strtoken( char *str, char *delims, int s, char *tok );
int fp_token( FILE *fp, char *delims, char *tok, int *end_del );
int xfp_token( FILE *fp, char *delims, char **tokp, int *end_del );
/* ================================================================================
ParseArgs.h
================================================================================ */
extern char pa_err_msg[];
/* ================================================================================
betai.c
================================================================================ */
void nerror( char *msg );
double betai( double a, double b, double x );
double betacf( double a, double b, double x );
/* ================================================================================
gammq.c
================================================================================ */
double gammp( double a, double x );
double gammq( double a, double x );
void gser( double *gamser, double a, double x, double *gln );
void gcf( double *gammcf, double a, double x, double *gln );
double gammln( double xx );
double erf( double x );
double erfc( double x );
double erfcc( double x );
/* ================================================================================
jSort.c
================================================================================ */
void shell_sort( int n, double a[] );
void shell_sort_i( int n, double a[], int b[] );
/* ================================================================================
Macros to swap bytes between machines of different endian-ness
swaping is done in place.
USAGE
char *cA;
short *sA;
int *iA;
float *fA;
cA = (char *) xmalloc( SIZE * sizeof(char));
sA = (short *) cA;
iA = (int *) cA;
fA = (float *) cA;
read( fd, cA, SIZE );
FIX_SHORT( sA[0] );
FIX_INT( iA[2] );
FIX_FLOAT( fA[3] );
================================================================================ */
#define SWAP_2(x) ( (((x) & 0xff) << 8) | ((unsigned short)(x) >> 8) )
#define SWAP_4(x) ( ((x) << 24) | \
(((x) << 8) & 0x00ff0000) | \
(((x) >> 8) & 0x0000ff00) | \
((x) >> 24) )
#define FIX_SHORT(x) (*(unsigned short *)&(x) = SWAP_2(*(unsigned short *)&(x)))
#define FIX_INT(x) (*(unsigned int *)&(x) = SWAP_4(*(unsigned int *)&(x)))
#define FIX_FLOAT(x) FIX_INT(x)
#endif /* _I_jLib1 */