LAL  7.5.0.1-89842e6
LALMath3DPlotTest.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Chad Hanna, Benjamin Owen
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 /*_______________________________________________________________________________________
21  *
22  * File Name: LALMath3DPlotTest.c
23  *
24  * Author: Hanna C. R.
25  *
26  *_______________________________________________________________________________________
27  */
28 
29 /**
30  * \author Hanna, C.R.
31  * \file
32  * \ingroup LALMathematica_h
33  *
34  * \brief Tests LALMath3DPlot().
35  *
36  * \code
37  * LALMath3DPlotTest
38  * \endcode
39  *
40  * ### Description ###
41  *
42  * This program generates a set of points simulating a template bank and calls
43  * LALMath3DPlot() to generate a MATHEMATICA notebook to display a 3D image of the
44  * bank. Instructions on how to evaluate the notebook appear when it is opened.
45  *
46  * ### Notes ###
47  *
48  * For a more interesting test of LALMath3DPlot() see <tt>InspiralSpinBankTest.c</tt> in
49  * the LALInspiral <tt>bank</tt> package.
50  *
51  */
52 
53 #include <math.h>
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57 #include <sys/types.h>
58 #include <sys/stat.h>
59 #include <lal/AVFactories.h>
60 #include <lal/LALConfig.h>
61 #include <lal/LALMalloc.h>
62 #include <lal/LALStatusMacros.h>
63 #include <lal/LALStdlib.h>
64 #include <lal/LALMathematica.h>
65 
66 /**\name Error Codes */ /** @{ */
67 #define LALMATH3DPLOTTESTC_ENORM 0 /**< Normal exit */
68 #define LALMATH3DPLOTTESTC_EMEM 1 /**< Memory allocation error */
69 #define LALMATH3DPLOTTESTC_ESUB 2 /**< Subroutine error */
70 /** @} */
71 
72 /** \cond DONT_DOXYGEN */
73 #define LALMATH3DPLOTTESTC_MSGENORM "Normal exit"
74 #define LALMATH3DPLOTTESTC_MSGEMEM "Memory allocation error"
75 #define LALMATH3DPLOTTESTC_MSGESUB "Subroutine error"
76 
77 
78 int main(void){
79  static LALStatus status;
80  INT4 loopx = 0; /* loop counters */
81  INT4 loopy = 0;
82  INT4 loopz = 0;
83  INT4 ntiles = 0;
84  Math3DPointList *list = NULL; /* Pointer to structure for mathematica plot */
85  Math3DPointList *first = NULL;
86 
87  if ((list = (Math3DPointList *) LALCalloc(1, sizeof(Math3DPointList))) == NULL){
88  LALError(&status, LALMATH3DPLOTTESTC_MSGEMEM);
89  printf(LALMATH3DPLOTTESTC_MSGEMEM);
91  }
92  first=list;
93 
94  for(loopx=1; loopx <= 20; loopx++){
95  for(loopy=1; loopy <= 20; loopy++){
96  for(loopz=0; loopz <= 1; loopz++){
97  list->x = loopx;
98  list->y = loopy;
99  list->z = loopz;
100  list->grayLevel = 0.0;
101  ntiles++;
102  if ((list = list->next = (Math3DPointList *) LALCalloc(1, sizeof(Math3DPointList))) == NULL){
103  LALError(&status, LALMATH3DPLOTTESTC_MSGEMEM);
104  printf(LALMATH3DPLOTTESTC_MSGEMEM);
106  }
107  }
108  }
109  }
110 
111  for(loopx=1; loopx <= 20; loopx++){
112  for(loopy=1; loopy <= 20; loopy++){
113  list->x = loopx;
114  list->y = loopy;
115  list->z = 2;
116  list->grayLevel = 1.0;
117  ntiles++;
118  if ((list = list->next = (Math3DPointList *) LALCalloc(1, sizeof(Math3DPointList))) == NULL){
119  LALError(&status, LALMATH3DPLOTTESTC_MSGEMEM);
120  printf(LALMATH3DPLOTTESTC_MSGEMEM);
122  }
123  }
124  }
125 
126  /*LAL!*/
127  for(loopx=1; loopx <= 20; loopx++){
128  for(loopy=1; loopy <= 20; loopy++){
129  for(loopz=3; loopz <= 4; loopz++){
130  if( ((loopx==6)||(loopx==19)) && (loopy<16) && (loopy>5)) continue;
131  if((loopy==15)&&(((loopx<20)&&(loopx>14))||((loopx<7)&&(loopx>1)))) continue;
132  if((loopx>9)&&(loopx<12)&&(((loopy>6)&&(loopy<10))||(loopy==12))) continue;
133  if(((loopx==9)||(loopx==12)) && ((loopy>9)&&(loopy<13))) continue;
134  if(((loopx==8)||(loopx==13)) && ((loopy>12)&&(loopy<16))) continue;
135  list->x = loopx;
136  list->y = loopy;
137  list->z = loopz;
138  list->grayLevel = 0.0;
139  ntiles++;
140  if ((list = list->next = (Math3DPointList *) LALCalloc(1, sizeof(Math3DPointList))) == NULL){
141  LALError(&status, LALMATH3DPLOTTESTC_MSGEMEM);
142  printf(LALMATH3DPLOTTESTC_MSGEMEM);
144  }
145  }
146  }
147  }
148 
149 
150  list->next = NULL;
151  printf("\nCalling LALMath3DPlot()......\n");
152  LALMath3DPlot(&status, first, &ntiles, NULL);
154  if (status.statusCode){
155  LALError(&status, LALMATH3DPLOTTESTC_MSGESUB);
156  printf(LALMATH3DPLOTTESTC_MSGESUB);
158  }
159 
160 
161  /* Clean Up the memory from the MathPlot3D structure */
162  list = first;
163  while(list->next){
164  first = list->next;
165  LALFree(list);
166  list = first;
167  }
168 
169 
170  /* free the last (first?) memory allocated for Math3DPlot. */
171  LALFree(list);
172 
173  if (status.statusCode)
175  else
177 
178 }
179 /** \endcond */
void REPORTSTATUS(LALStatus *status)
Definition: LALError.c:322
#define LALError(statusptr, statement)
Definition: LALError.h:95
#define LALCalloc(m, n)
Definition: LALMalloc.h:94
#define LALFree(p)
Definition: LALMalloc.h:96
#define LALMATH3DPLOTTESTC_EMEM
Memory allocation error.
#define LALMATH3DPLOTTESTC_ENORM
Normal exit.
#define LALMATH3DPLOTTESTC_ESUB
Subroutine error.
int main(int argc, char *argv[])
Definition: cache.c:25
int32_t INT4
Four-byte signed integer.
void LALMath3DPlot(LALStatus *stat, Math3DPointList *first, INT4 *ntiles, REAL4 *pointSize)
This function is for plotting 3D template banks by creating a MATHEMATICA notebook.
Definition: LALMath3DPlot.c:59
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
This type is used by LALMath3DPlot.c as an input structure to plot 3-dimensional template banks.
struct tagMath3DPointList * next