[go: up one dir, main page]

Menu

[r81]: / tags / xmd-2.5.38 / src / cdhouse.h  Maximize  Restore  History

Download this file

255 lines (224 with data), 6.8 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
 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
xmd - molecular dynamics for metals and ceramics
By Jonathan Rifkin <jon.rifkin@uconn.edu>
Copyright 1995-2004 Jonathan Rifkin
This program 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
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __CDHOUSE_H
#define __CDHOUSE_H
/*
************************************************************************
Function Prototypes
************************************************************************
*/
void StartProgramTimer(void);
void CleanAfterError(void);
void CleanBeforeEnd(void);
char *GetCurrentTimeStr (void);
/*
************************************************************************
Debugging Macros
************************************************************************
*/
/*
Debugging Macro: Print current file and line number
*/
#define WRITEMSG \
{ \
if (Debug_g) \
printf ("In file %s at line %i.\n", __FILE__, __LINE__); \
fflush (stdin); \
}
/*
Debugging Macro: Test assertion, if failed list file and line number
*/
#define ASSERT(TEST) if (!(TEST)) \
printf ("INTERNAL ERROR: Failed assertion (%s) in file %s line %i.\n", \
#TEST, __FILE__, __LINE__);
/*
Debugging Macro: Print out variable name and value
*/
#define WRITEVAR(VAR_NAME,VAR_TYPE) \
if (Debug_g) \
{ \
printf ("FILE %s LINE %i :", __FILE__, __LINE__); \
printf ("%s = ", #VAR_NAME); \
printf (#VAR_TYPE, (VAR_NAME) ); \
printf ("\n"); \
fflush (stdin); \
}
/*
Debugging Macro: Print out debugging note
*/
#define WRITENOT(MSG) \
if (Debug_g) \
{ \
printf ("FILE %s LINE %i :", __FILE__, __LINE__); \
printf (" (%s)\n", MSG); \
}
/*
Debugging Macro: Use BORLAND C++ DOS routine for checking memory heap
*/
#if 0
#define CHECK_HEAP \
if (heapcheck()<0) \
{ \
printf ("*** INTERNAL ERROR in %s line %i. ", __FILE__, __LINE__); \
printf ("Memory heap is corrupted.\n"); \
}
#else
#define CHECK_HEAP
#endif
/*
************************************************************************
Utility Macros
************************************************************************
*/
/*
NOTE:
The following macro replaces the standard C for(;;) construct
If you prefer to replace all occurances of this macro with
the corresponding for(;;) statement, copy the following
4 line perl script to the file fixLOOP.pl, run as follows.
chmod u+x fixLOOP.pl
fixLOOP.pl *.c
rm *.bak (to remove backup files)
This will edit in place all the *.c files and replace
LOOP with for().
------ start of script ------------------------------
#!/usr/bin/perl -pi.bak
if (!m/^#define/) {
s/LOOP\s*\(\s*([^,]*?)\s*,\s*([^)]*?)\s*\)/for ( $1=0; $1<$2; $1++ )/;
}
------ end of script --------------------------------
*/
/* Simple loop (this macro helps reduce typos) */
#define LOOP(INDEX,LIMIT) \
for (INDEX=0; INDEX<(LIMIT); INDEX++)
/*
Allocate array and test for NULL allocations
If NULL allocation then print error and call CleanAfterError()
*/
#define ALLOCATE(VAR,TYPE,NUM) \
{ \
if (VAR != NULL) \
{ \
printf ("FILE %s LINE %i: ALLOCATE is freeing variable %s\n", \
__FILE__, __LINE__, #VAR); \
if (CheckMem_g) \
printf ("CHECK MEM FREE %s %p %s %i\n", \
#VAR, VAR, __FILE__, __LINE__); \
free (VAR); \
VAR = NULL; \
} \
if (NUM!=0) \
{ \
VAR = (TYPE *) calloc ( (NUM), sizeof ( TYPE ) ); \
if (CheckMem_g) \
printf ("CHECK MEM ALLO %s %p %s %i %li\n", \
#VAR, VAR, __FILE__, __LINE__, \
( (long) (NUM) ) * sizeof(TYPE) ); \
if ((VAR) == NULL) \
{ \
printf ("ERROR: FILE %s LINE %i\n", __FILE__, __LINE__); \
printf (" Cannot allocate variable %s.\n", #VAR); \
printf (" Number of Elements %li\n", (long) NUM); \
printf (" Size of Elements %li\n", sizeof(TYPE)); \
CleanAfterError(); \
} \
} \
}
/*
Reallocate storage
- if new storage is zero, call free() and set pointer to NULL
- if old storage was zero, call calloc()
- if new storage > old, call realloc() and initialize new storage
- if new storage < old, call realloc()
*/
#define REALLOC(VAR,TYPE,OLD_NUM,NEW_NUM) \
{ \
/* Free existing pointer */ \
if ((NEW_NUM)==0) \
{ \
if ((VAR)!=NULL) \
{ \
if (CheckMem_g) \
printf ("CHECK MEM FREE(R0) %s %p %s %i\n", \
#VAR, VAR, __FILE__, __LINE__); \
free (VAR); \
(VAR) = NULL; \
} \
} \
/* Get new storage */ \
else \
{ \
if ((VAR)==NULL) \
{ \
(VAR) = (TYPE *) calloc ( (NEW_NUM), sizeof (TYPE) ); \
if (CheckMem_g) \
printf ("CHECK MEM ALLO(R) %s %p %s %i %li\n", \
#VAR, VAR, __FILE__, __LINE__, \
( (long) (NEW_NUM) ) * sizeof(TYPE) ); \
} \
else \
{ \
if (CheckMem_g) \
printf ("CHECK MEM FREE(R1) %s %p %s %i\n", \
#VAR, VAR, __FILE__, __LINE__); \
(VAR) = (TYPE *) realloc ( (VAR), (NEW_NUM) * sizeof (TYPE) ) ; \
if (CheckMem_g) \
printf ("CHECK MEM REALLO %s %p %s %i %li\n", \
#VAR, VAR, __FILE__, __LINE__, \
( (long) (NEW_NUM) ) * sizeof(TYPE) ); \
} \
if ((VAR) == NULL) \
{ \
printf ("ERROR\n"); \
printf (" Cannot allocate variable %s.\n", #VAR); \
printf (" Number of Elements %i\n", (NEW_NUM)); \
printf (" Size of Elements %li\n", sizeof(TYPE)); \
CleanAfterError(); \
} \
if ((NEW_NUM)>(OLD_NUM)) \
memset ( (VAR)+(OLD_NUM), 0, ((NEW_NUM)-(OLD_NUM)) * sizeof(TYPE)); \
} \
}
#define FREE(VAR) \
if ((VAR)!=NULL) \
{ \
if (CheckMem_g) \
printf ("CHECK MEM FREE %s %p %s %i\n", \
#VAR, VAR, __FILE__, __LINE__); \
free (VAR); \
(VAR) = NULL; \
}
/* Error Message Prefix */
#define ERROR_PREFIX printf("\nERROR xmd:%s:%i: ", __FILE__, __LINE__);
/* Square a token */
#define SQR(X) ((X)*(X))
/* Get combined type */
#define COMBINED_TYPE(T1,T2) \
((T1) > (T2) ? ((T1)*((T1)+1)/2 + (T2)) : ((T2)*((T2)+1)/2 + (T1)))
/*
************************************************************************
Global Variables
************************************************************************
*/
/*
Do not define Debug_g if header is called from cdhouse.c
*/
#ifndef IS_CDHOUSE_H
extern int Debug_g;
extern int CheckMem_g;
#endif
#endif