1 /*
2   libbpm - BPM signal processing/simulation library
3   Copyright (C) 2006-07 Bino Maiheu (bino@hep.ucl.ac.uk)
4 
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 2 of the License, or
8   (at your option) any later version.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
18 */
19 
20 /**
21     bpm_defs.h
22 
23     Main definitions for libbpm as well as doxygen intro documentation
24 
25     These are a number of definitions to make the code run on various systems
26     ( like e.g. win32... ) and some other general definitions used by the library.
27 
28     @defgroup analysis    Analysis routines
29     @defgroup calib       Calibration routines
30     @defgroup orbit       Beam orbit generation
31     @defgroup interface   Front-end interface
32     @defgroup message     Error/warning messages
33     @defgroup nr          Numerical routines
34     @defgroup rf          RF simulation routines
35     @defgroup sim         BPM signal simulation routines
36 
37     @mainpage libbpm
38 
39     @author  Bino Maiheu, University College London
40     @author  Mark Slater, University of Cambridge
41     @author  Alexey Lyapin, University College London
42     @author  Stewart Boogert, Royal Holloway University of London
43 
44 
45     @section main_intro Introduction
46 
47     libbpm is a C-library which contains low level beam position monitor (BPM)
48     signal processing routines. It's aim is to form a complete set of routines
49     needed to handle RF Cavity BPM data, from digital downmixing, sampling, calibrating
50     analysing and simulating BPM data. This library has been developed in the
51     context of the BPM work done by the accelerator physics groups at University
52     College London, Royal Holloway University of London and the University of
53     Cambridge (UK) (2006-2007)
54 
55     The library consists out of a set of submodules which take care of different parts
56     of the BPM signal handling. There are modules for BPM processing, calibration, simulation,
57     general waveform handling, some numerical routines, memory management etc...
58 
59     The library is licenced under the @ref gpl "GNU General Public License v2."
60 
61     @section main_docu Documentation structure
62     The documentation for this library is generated using doyxygen. For each module
63     the documentation is contained in it's respective header file :
64 
65     - @ref wave       "The waveform handling module"
66     - @ref dsp        "The digital signal processing module"
67     - @ref processing "The BPM processing module"
68 
69 
70     @section main_compile Compilation
71 
72     The compilation of the libbpm structure is defined using the GNU autotools. Therefore
73     making it portable under most unix flavours and MacOS as well as windows ( see futher ).
74 
75     @subsection main_compile_unix Compilation under Linux/Unix/MacOS
76 
77     For compilation under any unix flavour, please execute the standart sequence of
78     \c ./configure , \c make, and \c make install. The default options for the
79     configure script apply.
80 
81     If you have extracted the library from CVS, then you will have to generate the
82     build scripts. the \c autogen.sh script takes care of that. Run it and afterwards
83     you can simply execute the same steps as above.
84 
85 
86     @subsection main_compile_win32 Note on Compilation under Windows
87 
88     This is a remnant from libespec, need to retest this and write proper
89     documentation on it, but for what it's worth... here goes :
90 
91     To compile libbpm under windows, it is best to use the MinGW + MSYS
92     environment which enables one to build native libraries under windows
93     (dll). For this you need to declare some routines during the build process
94     using the dllexport macro that MinGW defines. So when you want to compile
95     this library as a DLL, set the BUILD_DLL define statement active below.
96     Or compile using -DBUILD_DLL.  When you want to use this headerfile to for
97     linking with the bpm.ddl  library, undefine the BUILD_DLL, this will
98     enable the compiler to import routines from libbpm in other programs
99     from the ddl. Under linux  it does not make a difference as the if statement
100     checks first for the existence of the DLL_EXPORT and __WIN32__ macros.
101 
102 
103     @section main_usage Using libbpm in your programs
104 
105     libbpm is a standalone plain C library. Care has been taken to not have to use
106     special compiler options e.g. the library avoids having to be C99 compliant by
107     implementing it's own complex data type, rounding function etc.. So it should
108     be fairly portable to most platforms.
109 
110     To use libbpm in your makefiles for your project, a convenient script has been
111     created which automatically gives you the correct compiler options and library
112     locations. See this makefile example on how to use the script \c libbpm-config
113 
114     @code
115     #Example makefile that uses libbpm and ROOT (hey.. why not :D !)
116 
117     SRC         = main.cpp subroutine.cpp
118 
119     ROOT_LIBS   = $(shell root-config --libs)
120     ROOT_CFLAGS = $(shell root-config --cflags)
121 
122     BPM_LIBS    = $(shell libbpm-config --libs)
123     BPM_CFLAGS  = $(shell libbpm-config --cflags)
124 
125     CPP         = g++
126     CPPFLAGS    = -O3 -Wall -fPIC -fno-strict-aliasing $(BPM_CFLAGS) $(ROOT_CFLAGS)
127     LD          = g++
128     LDFLAGS     = $(BPM_LIBS) $(ROOT_LIBS)
129 
130     OBJ         = $(SRC:.cpp=.o)
131 
132     #suffix rules
133     .SUFFIXES: .cpp .o
134     .cpp.o:
135             $(CPP) $(CPPFLAGS) -c $<
136 
137     #build rules
138     .PHONY: all
139     all: program
140 
141     program: $(OBJ)
142             $(LD) $(LDFLAGS) $^ -o $@
143 
144     @endcode
145 
146     You can use the \c --help option of \c libbpm-config to display it's options :
147 
148     @code
149     [linux] ~/libbpm $ libbpm-config --help
150     Usage: libbpm-config [OPTION]
151 
152     Known values for OPTION are:
153 
154       --prefix              show libbpm installation prefix
155       --libs                print library linking information
156       --cflags              print pre-processor and compiler flags
157       --help                display this help and exit
158       --version             output version information
159     @endcode
160 
161 
162 */
163 
164 /**
165    @page licence GNU General Public License, v2
166    @anchor gpl
167 
168    		    GNU GENERAL PUBLIC LICENSE
169 		       Version 2, June 1991
170 
171  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
172      51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
173  Everyone is permitted to copy and distribute verbatim copies
174  of this license document, but changing it is not allowed.
175 
176 			    Preamble
177 
178   The licenses for most software are designed to take away your
179 freedom to share and change it.  By contrast, the GNU General Public
180 License is intended to guarantee your freedom to share and change free
181 software--to make sure the software is free for all its users.  This
182 General Public License applies to most of the Free Software
183 Foundation's software and to any other program whose authors commit to
184 using it.  (Some other Free Software Foundation software is covered by
185 the GNU Library General Public License instead.)  You can apply it to
186 your programs, too.
187 
188   When we speak of free software, we are referring to freedom, not
189 price.  Our General Public Licenses are designed to make sure that you
190 have the freedom to distribute copies of free software (and charge for
191 this service if you wish), that you receive source code or can get it
192 if you want it, that you can change the software or use pieces of it
193 in new free programs; and that you know you can do these things.
194 
195   To protect your rights, we need to make restrictions that forbid
196 anyone to deny you these rights or to ask you to surrender the rights.
197 These restrictions translate to certain responsibilities for you if you
198 distribute copies of the software, or if you modify it.
199 
200   For example, if you distribute copies of such a program, whether
201 gratis or for a fee, you must give the recipients all the rights that
202 you have.  You must make sure that they, too, receive or can get the
203 source code.  And you must show them these terms so they know their
204 rights.
205 
206   We protect your rights with two steps: (1) copyright the software, and
207 (2) offer you this license which gives you legal permission to copy,
208 distribute and/or modify the software.
209 
210   Also, for each author's protection and ours, we want to make certain
211 that everyone understands that there is no warranty for this free
212 software.  If the software is modified by someone else and passed on, we
213 want its recipients to know that what they have is not the original, so
214 that any problems introduced by others will not reflect on the original
215 authors' reputations.
216 
217   Finally, any free program is threatened constantly by software
218 patents.  We wish to avoid the danger that redistributors of a free
219 program will individually obtain patent licenses, in effect making the
220 program proprietary.  To prevent this, we have made it clear that any
221 patent must be licensed for everyone's free use or not licensed at all.
222 
223   The precise terms and conditions for copying, distribution and
224 modification follow.
225 
226 		    GNU GENERAL PUBLIC LICENSE
227    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
228 
229   0. This License applies to any program or other work which contains
230 a notice placed by the copyright holder saying it may be distributed
231 under the terms of this General Public License.  The "Program", below,
232 refers to any such program or work, and a "work based on the Program"
233 means either the Program or any derivative work under copyright law:
234 that is to say, a work containing the Program or a portion of it,
235 either verbatim or with modifications and/or translated into another
236 language.  (Hereinafter, translation is included without limitation in
237 the term "modification".)  Each licensee is addressed as "you".
238 
239 Activities other than copying, distribution and modification are not
240 covered by this License; they are outside its scope.  The act of
241 running the Program is not restricted, and the output from the Program
242 is covered only if its contents constitute a work based on the
243 Program (independent of having been made by running the Program).
244 Whether that is true depends on what the Program does.
245 
246   1. You may copy and distribute verbatim copies of the Program's
247 source code as you receive it, in any medium, provided that you
248 conspicuously and appropriately publish on each copy an appropriate
249 copyright notice and disclaimer of warranty; keep intact all the
250 notices that refer to this License and to the absence of any warranty;
251 and give any other recipients of the Program a copy of this License
252 along with the Program.
253 
254 You may charge a fee for the physical act of transferring a copy, and
255 you may at your option offer warranty protection in exchange for a fee.
256 
257   2. You may modify your copy or copies of the Program or any portion
258 of it, thus forming a work based on the Program, and copy and
259 distribute such modifications or work under the terms of Section 1
260 above, provided that you also meet all of these conditions:
261 
262     a) You must cause the modified files to carry prominent notices
263     stating that you changed the files and the date of any change.
264 
265     b) You must cause any work that you distribute or publish, that in
266     whole or in part contains or is derived from the Program or any
267     part thereof, to be licensed as a whole at no charge to all third
268     parties under the terms of this License.
269 
270     c) If the modified program normally reads commands interactively
271     when run, you must cause it, when started running for such
272     interactive use in the most ordinary way, to print or display an
273     announcement including an appropriate copyright notice and a
274     notice that there is no warranty (or else, saying that you provide
275     a warranty) and that users may redistribute the program under
276     these conditions, and telling the user how to view a copy of this
277     License.  (Exception: if the Program itself is interactive but
278     does not normally print such an announcement, your work based on
279     the Program is not required to print an announcement.)
280 
281 These requirements apply to the modified work as a whole.  If
282 identifiable sections of that work are not derived from the Program,
283 and can be reasonably considered independent and separate works in
284 themselves, then this License, and its terms, do not apply to those
285 sections when you distribute them as separate works.  But when you
286 distribute the same sections as part of a whole which is a work based
287 on the Program, the distribution of the whole must be on the terms of
288 this License, whose permissions for other licensees extend to the
289 entire whole, and thus to each and every part regardless of who wrote it.
290 
291 Thus, it is not the intent of this section to claim rights or contest
292 your rights to work written entirely by you; rather, the intent is to
293 exercise the right to control the distribution of derivative or
294 collective works based on the Program.
295 
296 In addition, mere aggregation of another work not based on the Program
297 with the Program (or with a work based on the Program) on a volume of
298 a storage or distribution medium does not bring the other work under
299 the scope of this License.
300 
301   3. You may copy and distribute the Program (or a work based on it,
302 under Section 2) in object code or executable form under the terms of
303 Sections 1 and 2 above provided that you also do one of the following:
304 
305     a) Accompany it with the complete corresponding machine-readable
306     source code, which must be distributed under the terms of Sections
307     1 and 2 above on a medium customarily used for software interchange; or,
308 
309     b) Accompany it with a written offer, valid for at least three
310     years, to give any third party, for a charge no more than your
311     cost of physically performing source distribution, a complete
312     machine-readable copy of the corresponding source code, to be
313     distributed under the terms of Sections 1 and 2 above on a medium
314     customarily used for software interchange; or,
315 
316     c) Accompany it with the information you received as to the offer
317     to distribute corresponding source code.  (This alternative is
318     allowed only for noncommercial distribution and only if you
319     received the program in object code or executable form with such
320     an offer, in accord with Subsection b above.)
321 
322 The source code for a work means the preferred form of the work for
323 making modifications to it.  For an executable work, complete source
324 code means all the source code for all modules it contains, plus any
325 associated interface definition files, plus the scripts used to
326 control compilation and installation of the executable.  However, as a
327 special exception, the source code distributed need not include
328 anything that is normally distributed (in either source or binary
329 form) with the major components (compiler, kernel, and so on) of the
330 operating system on which the executable runs, unless that component
331 itself accompanies the executable.
332 
333 If distribution of executable or object code is made by offering
334 access to copy from a designated place, then offering equivalent
335 access to copy the source code from the same place counts as
336 distribution of the source code, even though third parties are not
337 compelled to copy the source along with the object code.
338 
339   4. You may not copy, modify, sublicense, or distribute the Program
340 except as expressly provided under this License.  Any attempt
341 otherwise to copy, modify, sublicense or distribute the Program is
342 void, and will automatically terminate your rights under this License.
343 However, parties who have received copies, or rights, from you under
344 this License will not have their licenses terminated so long as such
345 parties remain in full compliance.
346 
347   5. You are not required to accept this License, since you have not
348 signed it.  However, nothing else grants you permission to modify or
349 distribute the Program or its derivative works.  These actions are
350 prohibited by law if you do not accept this License.  Therefore, by
351 modifying or distributing the Program (or any work based on the
352 Program), you indicate your acceptance of this License to do so, and
353 all its terms and conditions for copying, distributing or modifying
354 the Program or works based on it.
355 
356   6. Each time you redistribute the Program (or any work based on the
357 Program), the recipient automatically receives a license from the
358 original licensor to copy, distribute or modify the Program subject to
359 these terms and conditions.  You may not impose any further
360 restrictions on the recipients' exercise of the rights granted herein.
361 You are not responsible for enforcing compliance by third parties to
362 this License.
363 
364   7. If, as a consequence of a court judgment or allegation of patent
365 infringement or for any other reason (not limited to patent issues),
366 conditions are imposed on you (whether by court order, agreement or
367 otherwise) that contradict the conditions of this License, they do not
368 excuse you from the conditions of this License.  If you cannot
369 distribute so as to satisfy simultaneously your obligations under this
370 License and any other pertinent obligations, then as a consequence you
371 may not distribute the Program at all.  For example, if a patent
372 license would not permit royalty-free redistribution of the Program by
373 all those who receive copies directly or indirectly through you, then
374 the only way you could satisfy both it and this License would be to
375 refrain entirely from distribution of the Program.
376 
377 If any portion of this section is held invalid or unenforceable under
378 any particular circumstance, the balance of the section is intended to
379 apply and the section as a whole is intended to apply in other
380 circumstances.
381 
382 It is not the purpose of this section to induce you to infringe any
383 patents or other property right claims or to contest validity of any
384 such claims; this section has the sole purpose of protecting the
385 integrity of the free software distribution system, which is
386 implemented by public license practices.  Many people have made
387 generous contributions to the wide range of software distributed
388 through that system in reliance on consistent application of that
389 system; it is up to the author/donor to decide if he or she is willing
390 to distribute software through any other system and a licensee cannot
391 impose that choice.
392 
393 This section is intended to make thoroughly clear what is believed to
394 be a consequence of the rest of this License.
395 
396   8. If the distribution and/or use of the Program is restricted in
397 certain countries either by patents or by copyrighted interfaces, the
398 original copyright holder who places the Program under this License
399 may add an explicit geographical distribution limitation excluding
400 those countries, so that distribution is permitted only in or among
401 countries not thus excluded.  In such case, this License incorporates
402 the limitation as if written in the body of this License.
403 
404   9. The Free Software Foundation may publish revised and/or new versions
405 of the General Public License from time to time.  Such new versions will
406 be similar in spirit to the present version, but may differ in detail to
407 address new problems or concerns.
408 
409 Each version is given a distinguishing version number.  If the Program
410 specifies a version number of this License which applies to it and "any
411 later version", you have the option of following the terms and conditions
412 either of that version or of any later version published by the Free
413 Software Foundation.  If the Program does not specify a version number of
414 this License, you may choose any version ever published by the Free Software
415 Foundation.
416 
417   10. If you wish to incorporate parts of the Program into other free
418 programs whose distribution conditions are different, write to the author
419 to ask for permission.  For software which is copyrighted by the Free
420 Software Foundation, write to the Free Software Foundation; we sometimes
421 make exceptions for this.  Our decision will be guided by the two goals
422 of preserving the free status of all derivatives of our free software and
423 of promoting the sharing and reuse of software generally.
424 
425 			    NO WARRANTY
426 
427   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
428 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
429 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
430 PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
431 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
432 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
433 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
434 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
435 REPAIR OR CORRECTION.
436 
437   12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
438 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
439 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
440 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
441 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
442 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
443 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
444 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
445 POSSIBILITY OF SUCH DAMAGES.
446 
447 		     END OF TERMS AND CONDITIONS
448 */
449 
450 
451 #ifndef BPMDEFS_H__
452 #define BPMDEFS_H__
453 
454 /* -----------------------------------------------------------------------------
455    includes
456    -------------------------------------------------------------------------- */
457 
458 
459 /* -----------------------------------------------------------------------------
460    macro definitions
461    -------------------------------------------------------------------------- */
462 
463 /* #define BUILD_DLL */
464 #if defined ( DLL_EXPORT ) && ( defined ( _WIN32 ) || defined ( __WIN32__ ) )
465 #  if defined BUILD_DLL
466 #    define EXTERN __declspec( dllexport )
467 #  else
468 #    define EXTERN __declspec( dllimport )
469 #  endif
470 #else
471 #  define EXTERN extern
472 #endif
473 
474 #ifndef _GNU_SOURCE
475 #define _GNU_SOURCE /* needed for some functions (e.g. like 'round') */
476 #endif
477 
478 #ifndef TRUE
479 #  define TRUE  (1==1)
480 #endif
481 #ifndef FALSE
482 #  define FALSE (0==1)
483 #endif
484 
485 #define MIN(a,b)        (a<=b?a:b)
486 #define MAX(a,b)        (a>=b?a:b)
487 #define SQR( a ) ( (a) * (a) )
488 #define ABS( a ) ( (a) < 0 ? -(a) : (a) )
489 #define SWAP( a, b ) tempr=(a);(a)=(b);(b)=tempr
490 
491 #ifdef PI
492 # undef PI
493 #endif
494 #define PI 3.14159265358979323846264338328 /* echo "scale=100;4*a(1)"|bc -l  ;) */
495 
496 #define BPM_SUCCESS  0
497 #define BPM_FAILURE  1
498 
499 #define Re 0
500 #define Im 1
501 
502 /* -----------------------------------------------------------------------------
503    typedefs, enums and other declarations
504    -------------------------------------------------------------------------- */
505 
506 /* -----------------------------------------------------------------------------
507    function prototypes and declarations
508    -------------------------------------------------------------------------- */
509 
510 #endif /* #ifndef BPMDEFS_H__ */
511 /*@}*/
512 /* ================================ end of file ============================= */
513 
514