MIDI Pipeline Reference Manual  2.8.3
memoryHandling.c
1 /******************************************************************************
2 *******************************************************************************
3 * European Southern Observatory
4 * MIDI Data Reduction Software
5 *
6 * File name: memoryHandling.c
7 * Description: Contains the routines for dynamic memory allocation
8 * and freeing
9 *
10 *
11 * History:
12 * 25-Sep-03 (csabet) Created
13 *******************************************************************************
14 ******************************************************************************/
15 
16 /******************************************************************************
17 * Compiler directives
18 ******************************************************************************/
19 
20 /******************************************************************************
21 * Include files
22 ******************************************************************************/
23 #include <stdio.h>
24 #include <cpl.h>
25 #include <string.h>
26 #include <time.h>
27 #include <stdlib.h>
28 #include "midiGlobal.h"
29 #include "midiLib.h"
30 #include "memoryHandling.h"
31 #include "errorHandling.h"
32 
33 /******************************************************************************
34 * Global Variables
35 ******************************************************************************/
36 
37 /*============================ C O D E A R E A ===========================*/
38 
39 
40 /******************************************************************************
41 * European Southern Observatory
42 * MIDI Data Reduction Software
43 *
44 * Module name: callocKappaCoefficients
45 * Input/Output: See function arguments to avoid duplication
46 * Description: Allocates memory for the Kappa Coefficients
47 *
48 * History:
49 * 01-Feb-06 (csabet) Created
50 ******************************************************************************/
51 KappaCoefficients *callocKappaCoefficients (
52  int numOfChannels)
53 {
54  // Local Declarations
55  // ------------------
56  KappaCoefficients *array=NULL;
57 
58  // Algorithm
59  // ---------
60  array = (KappaCoefficients *) calloc (1, sizeof (KappaCoefficients));
61 
62  array->k11 = (float *) calloc (numOfChannels, sizeof (float));
63  array->k21 = (float *) calloc (numOfChannels, sizeof (float));
64  array->k31 = (float *) calloc (numOfChannels, sizeof (float));
65  array->k22 = (float *) calloc (numOfChannels, sizeof (float));
66  array->k32 = (float *) calloc (numOfChannels, sizeof (float));
67  array->k42 = (float *) calloc (numOfChannels, sizeof (float));
68  array->sig11 = (float *) calloc (numOfChannels, sizeof (float));
69  array->sig21 = (float *) calloc (numOfChannels, sizeof (float));
70  array->sig31 = (float *) calloc (numOfChannels, sizeof (float));
71  array->sig22 = (float *) calloc (numOfChannels, sizeof (float));
72  array->sig32 = (float *) calloc (numOfChannels, sizeof (float));
73  array->sig42 = (float *) calloc (numOfChannels, sizeof (float));
74 
75  return (array);
76 }
77 /*****************************************************************************/
78 
79 
80 
81 /******************************************************************************
82 * European Southern Observatory
83 * MIDI Data Reduction Software
84 *
85 * Module name: freeKappaCoefficients
86 * Input/Output: See function arguments to avoid duplication
87 * Description: Releases memory for the Kappa coefficients
88 *
89 * History:
90 * 01-Feb-06 (csabet) Created
91 ******************************************************************************/
92 void freeKappaCoefficients (
93  KappaCoefficients *array)
94 {
95  // Local Declarations
96  //--------------------
97 
98  // Algorithm
99  // ---------
100  free (array->k11);
101  free (array->sig11);
102  free (array->k21);
103  free (array->sig21);
104  free (array->k31);
105  free (array->sig31);
106  free (array->k22);
107  free (array->sig22);
108  free (array->k32);
109  free (array->sig32);
110  free (array->k42);
111  free (array->sig42);
112 
113  free (array);
114  array = NULL;
115 
116  return;
117 }
118 /*****************************************************************************/
119 
120 
121 
122 /******************************************************************************
123 * European Southern Observatory
124 * MIDI Data Reduction Software
125 *
126 * Module name: callocTransferRatios
127 * Input/Output: See function arguments to avoid duplication
128 * Description: Allocates memory for the Transfer Ratios
129 *
130 * History:
131 * 01-Feb-06 (csabet) Created
132 ******************************************************************************/
133 TransferRatios *callocTransferRatios (
134  int numOfChannels)
135 {
136  // Local Declarations
137  // ------------------
138  TransferRatios *array=NULL;
139 
140  // Algorithm
141  // ---------
142  array = (TransferRatios *) calloc (1, sizeof (TransferRatios));
143 
144  array->ka1 = (float *) calloc (numOfChannels, sizeof (float));
145  array->siga1 = (float *) calloc (numOfChannels, sizeof (float));
146  array->ka2 = (float *) calloc (numOfChannels, sizeof (float));
147  array->siga2 = (float *) calloc (numOfChannels, sizeof (float));
148  array->kb1 = (float *) calloc (numOfChannels, sizeof (float));
149  array->sigb1 = (float *) calloc (numOfChannels, sizeof (float));
150  array->kb2 = (float *) calloc (numOfChannels, sizeof (float));
151  array->sigb2 = (float *) calloc (numOfChannels, sizeof (float));
152 
153  return (array);
154 }
155 /*****************************************************************************/
156 
157 
158 
159 /******************************************************************************
160 * European Southern Observatory
161 * MIDI Data Reduction Software
162 *
163 * Module name: freeTransferRatios
164 * Input/Output: See function arguments to avoid duplication
165 * Description: Releases memory for the Transfer Ratios
166 *
167 * History:
168 * 01-Feb-06 (csabet) Created
169 ******************************************************************************/
170 void freeTransferRatios (
171  TransferRatios *array)
172 {
173  // Local Declarations
174  //--------------------
175 
176  // Algorithm
177  // ---------
178  free (array->ka1);
179  free (array->siga1);
180  free (array->ka2);
181  free (array->siga2);
182  free (array->kb1);
183  free (array->sigb1);
184  free (array->kb2);
185  free (array->sigb2);
186 
187  free (array);
188  array = NULL;
189 
190  return;
191 }
192 /*****************************************************************************/
193 
194 
195 /******************************************************************************
196 * European Southern Observatory
197 * MIDI Data Reduction Software
198 *
199 * Module name: callocWaveCalibration
200 * Input/Output: See function arguments to avoid duplication
201 * Description: Allocates memory for an array of 2D float
202 *
203 * History:
204 * 08-Feb-05 (csabet) Created
205 ******************************************************************************/
206 float **callocWaveCalibration (
207  int regions,
208  ImageFormat *format)
209 {
210  /* Local Declarations
211  --------------------*/
212  float **array=NULL;
213  int i;
214 
215  /* Algorithm
216  -----------*/
217  array = (float **) calloc (regions, sizeof (float *));
218  for (i = 0; i < regions; i++)
219  array[i] = (float *) calloc (format->iXWidth, sizeof (float));
220 
221  return (array);
222 }
223 /*****************************************************************************/
224 
225 
226 
227 /******************************************************************************
228 * European Southern Observatory
229 * MIDI Data Reduction Software
230 *
231 * Module name: freeWaveCalibration
232 * Input/Output: See function arguments to avoid duplication
233 * Description: Releases memory for a 2D array of float
234 *
235 * History:
236 * 08-Feb-05 (csabet) Created
237 ******************************************************************************/
238 void freeWaveCalibration (
239  int regions,
240  float **array)
241 {
242  /* Local Declarations
243  --------------------*/
244  int i;
245 
246  /* Algorithm
247  -----------*/
248  for (i = 0; i < regions; i++)
249  free (array[i]);
250 
251  free (array);
252  array = NULL;
253 
254  return;
255 }
256 /*****************************************************************************/
257 
258 
259 
260 /******************************************************************************
261 * European Southern Observatory
262 * MIDI Data Reduction Software
263 *
264 * Module name: callocDispResult
265 * Input/Output: See function arguments to avoid duplication
266 * Description: Allocates memory for the dispResult array
267 *
268 * History:
269 * 08-Feb-05 (csabet) Created
270 ******************************************************************************/
271 DispersedResult *callocDispResult (
272  int numOfChannels)
273 {
274  /* Local Declarations
275  --------------------*/
276  DispersedResult *array=NULL;
277  int region;
278 
279  /* Algorithm
280  -----------*/
281  array = (DispersedResult *) calloc (1, sizeof (DispersedResult));
282 
283  array->photomA = (float **) calloc (2, sizeof (float *));
284  array->photomB = (float **) calloc (2, sizeof (float *));
285  array->photomI = (float **) calloc (2, sizeof (float *));
286  array->photomAErr = (float **) calloc (2, sizeof (float *));
287  array->photomBErr = (float **) calloc (2, sizeof (float *));
288  array->photomIErr = (float **) calloc (2, sizeof (float *));
289 
290  for (region = 0; region < 2; region++)
291  {
292  (array->photomA)[region] = (float *) calloc (numOfChannels, sizeof (float));
293  (array->photomB)[region] = (float *) calloc (numOfChannels, sizeof (float));
294  (array->photomI)[region] = (float *) calloc (numOfChannels, sizeof (float));
295  (array->photomAErr)[region] = (float *) calloc (numOfChannels, sizeof (float));
296  (array->photomBErr)[region] = (float *) calloc (numOfChannels, sizeof (float));
297  (array->photomIErr)[region] = (float *) calloc (numOfChannels, sizeof (float));
298  }
299 
300  array->trf = (float *) calloc (numOfChannels, sizeof (float));
301  array->trfErr = (float *) calloc (numOfChannels, sizeof (float));
302  array->normVis2 = (float *) calloc (numOfChannels, sizeof (float));
303  array->normVis2Err = (float *) calloc (numOfChannels, sizeof (float));
304  array->rawVis2 = (float *) calloc (numOfChannels, sizeof (float));
305  array->rawVis2Err = (float *) calloc (numOfChannels, sizeof (float));
306  array->calibVis2 = (float *) calloc (numOfChannels, sizeof (float));
307  array->calibVis2Err = (float *) calloc (numOfChannels, sizeof (float));
308  array->photomNet2 = (float *) calloc (numOfChannels, sizeof (float));
309  array->photomNet2Err = (float *) calloc (numOfChannels, sizeof (float));
310 
311  return (array);
312 }
313 /*****************************************************************************/
314 
315 
316 
317 /******************************************************************************
318 * European Southern Observatory
319 * MIDI Data Reduction Software
320 *
321 * Module name: freeDispResult
322 * Input/Output: See function arguments to avoid duplication
323 * Description: Releases memory for the dispResult array
324 *
325 * History:
326 * 08-Feb-05 (csabet) Created
327 ******************************************************************************/
328 void freeDispResult (
329  DispersedResult *array)
330 {
331  // Local Declarations
332  // ------------------
333  int region;
334 
335  // Algorithm
336  // ---------
337  for (region = 0; region < 2; region++)
338  {
339  free (array->photomA[region]);
340  free (array->photomB[region]);
341  free (array->photomI[region]);
342  free (array->photomAErr[region]);
343  free (array->photomBErr[region]);
344  free (array->photomIErr[region]);
345  }
346 
347 
348  free (array->trf);
349  free (array->trfErr);
350  free (array->normVis2);
351  free (array->normVis2Err);
352  free (array->rawVis2);
353  free (array->rawVis2Err);
354  free (array->calibVis2);
355  free (array->calibVis2Err);
356 
357  free (array->photomA);
358  free (array->photomB);
359  free (array->photomI);
360  free (array->photomAErr);
361  free (array->photomBErr);
362  free (array->photomIErr);
363  free (array->photomNet2);
364  free (array->photomNet2Err);
365 
366  free (array);
367  array = NULL;
368 
369  return;
370 }
371 /*****************************************************************************/
372 
373 
374 
375 /******************************************************************************
376 * European Southern Observatory
377 * MIDI Data Reduction Software
378 *
379 * Module name: callocImageFormat
380 * Input/Output: See function arguments to avoid duplication
381 * Description: Allocates memory for the array image format
382 *
383 * History:
384 * 29-Mar-04 (csabet) Created
385 ******************************************************************************/
386 ImageFormat *callocImageFormat (void)
387 {
388  /* Local Declarations
389  --------------------*/
390  ImageFormat *array=NULL;
391 
392  /* Algorithm
393  -----------*/
394  array = (ImageFormat *) calloc (1, sizeof(ImageFormat));
395  array->shutterId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
396  array->grismId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
397  array->slitName = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
398  array->targetName = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
399  array->cameraId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
400  array->filterName = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
401  array->tplStart = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
402  array->beamCombiner = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
403  array->tplName = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
404  array->obsTech = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
405  array->obsCatg = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
406  array->obsType = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
407 
408  return (array);
409 }
410 /*****************************************************************************/
411 
412 
413 /******************************************************************************
414 * European Southern Observatory
415 * MIDI Data Reduction Software
416 *
417 * Module name: freeImageFormat
418 * Input/Output: See function arguments to avoid duplication
419 * Description: Releases memory for the array image format
420 *
421 * History:
422 * 29-Mar-04 (csabet) Created
423 ******************************************************************************/
424 void freeImageFormat (
425  ImageFormat *array)
426 {
427  /* Local Declarations
428  --------------------*/
429 
430  /* Algorithm
431  -----------*/
432  free (array->shutterId);
433  free (array->grismId);
434  free (array->slitName);
435  free (array->targetName);
436  free (array->tplStart);
437  free (array->beamCombiner);
438  free (array->cameraId);
439  free (array->filterName);
440  free (array->tplName);
441  free (array->obsTech);
442  free (array->obsCatg);
443  free (array->obsType);
444  free (array);
445  array = NULL;
446 
447  return;
448 }
449 /*****************************************************************************/
450 
451 
452 
453 /******************************************************************************
454 * European Southern Observatory
455 * MIDI Data Reduction Software
456 *
457 * Module name: callocFilterInfo
458 * Input/Output: See function arguments to avoid duplication
459 * Description: Allocates memory for the filterInfo array
460 *
461 * History:
462 * 29-Mar-04 (csabet) Created
463 ******************************************************************************/
464 FilterData *callocFilterInfo (void)
465 {
466  /* Local Declarations
467  --------------------*/
468  FilterData *array=NULL;
469 
470  /* Algorithm
471  -----------*/
472  array = (FilterData *) calloc (1, sizeof(FilterData));
473  array->filterName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
474 
475  return (array);
476 }
477 /*****************************************************************************/
478 
479 
480 /******************************************************************************
481 * European Southern Observatory
482 * MIDI Data Reduction Software
483 *
484 * Module name: freeFilterInfo
485 * Input/Output: See function arguments to avoid duplication
486 * Description: Releases memory for the filterInfo array
487 *
488 * History:
489 * 29-Mar-04 (csabet) Created
490 ******************************************************************************/
491 void freeFilterInfo (
492  FilterData *array)
493 {
494  /* Local Declarations
495  --------------------*/
496 
497  /* Algorithm
498  -----------*/
499  free (array->filterName);
500  free (array);
501  array = NULL;
502 
503  return;
504 }
505 /*****************************************************************************/
506 
507 
508 /******************************************************************************
509 * European Southern Observatory
510 * MIDI Data Reduction Software
511 *
512 * Module name: callocCalibVis
513 * Input/Output: See function arguments to avoid duplication
514 * Description: Allocates memory for the trf array
515 *
516 * History:
517 * 29-Mar-04 (csabet) Created
518 ******************************************************************************/
519 CalibratedVisibility *callocCalibVis (void)
520 {
521  /* Local Declarations
522  --------------------*/
523  CalibratedVisibility *array=NULL;
524 
525  /* Algorithm
526  -----------*/
527  array = (CalibratedVisibility *) calloc (1, sizeof (CalibratedVisibility));
528  array->vis = (float *) calloc (REGIONS_UNDISPERSED, sizeof (float));
529  array->visErr = (float *) calloc (REGIONS_UNDISPERSED, sizeof (float));
530  array->visSqrd = (float *) calloc (REGIONS_UNDISPERSED, sizeof (float));
531  array->visSqrdErr = (float *) calloc (REGIONS_UNDISPERSED, sizeof (float));
532 
533 
534  return (array);
535 }
536 /*****************************************************************************/
537 
538 
539 /******************************************************************************
540 * European Southern Observatory
541 * MIDI Data Reduction Software
542 *
543 * Module name: freeCalibVis
544 * Input/Output: See function arguments to avoid duplication
545 * Description: Releases memory for the calibratedVis array
546 *
547 * History:
548 * 29-Mar-04 (csabet) Created
549 ******************************************************************************/
550 void freeCalibVis (
551  CalibratedVisibility *array)
552 {
553  /* Local Declarations
554  --------------------*/
555 
556  /* Algorithm
557  -----------*/
558  free (array->vis);
559  free (array->visErr);
560  free (array->visSqrd);
561  free (array->visSqrdErr);
562  free (array);
563  array = NULL;
564 
565  return;
566 }
567 /*****************************************************************************/
568 
569 
570 
571 /******************************************************************************
572 * European Southern Observatory
573 * MIDI Data Reduction Software
574 *
575 * Module name: callocTrFunction
576 * Input/Output: See function arguments to avoid duplication
577 * Description: Allocates memory for the trf array
578 *
579 * History:
580 * 29-Mar-04 (csabet) Created
581 ******************************************************************************/
582 TransferFunction *callocTrFunction (
583  int size)
584 {
585  /* Local Declarations
586  --------------------*/
587  TransferFunction *array=NULL;
588 
589  /* Algorithm
590  -----------*/
591  array = (TransferFunction *) calloc (1, sizeof (TransferFunction));
592  array->trf = (float *) calloc (size , sizeof (float));
593  array->trfErr = (float *) calloc (size , sizeof (float));
594 
595  return (array);
596 }
597 /*****************************************************************************/
598 
599 
600 /******************************************************************************
601 * European Southern Observatory
602 * MIDI Data Reduction Software
603 *
604 * Module name: freeTrFunction
605 * Input/Output: See function arguments to avoid duplication
606 * Description: Releases memory for the trf array
607 *
608 * History:
609 * 29-Mar-04 (csabet) Created
610 ******************************************************************************/
611 void freeTrFunction (
612  TransferFunction *array)
613 {
614  /* Local Declarations
615  --------------------*/
616 
617  /* Algorithm
618  -----------*/
619  free (array->trfErr);
620  free (array->trf);
621  free (array);
622  array = NULL;
623 
624  return;
625 }
626 /*****************************************************************************/
627 
628 
629 /******************************************************************************
630 * European Southern Observatory
631 * MIDI Data Reduction Software
632 *
633 * Module name: callocCalibrator
634 * Input/Output: See function arguments to avoid duplication
635 * Description: Allocates memory for the Calibrator array
636 *
637 * History:
638 * 29-Mar-04 (csabet) Created
639 ******************************************************************************/
640 CalibratorParam *callocCalibrator (void)
641 {
642  /* Local Declarations
643  --------------------*/
644  CalibratorParam *array=NULL;
645 
646  /* Algorithm
647  -----------*/
648  array = (CalibratorParam *) calloc (1, sizeof (CalibratorParam));
649  array->calibName = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
650 
651  return (array);
652 }
653 /*****************************************************************************/
654 
655 
656 /******************************************************************************
657 * European Southern Observatory
658 * MIDI Data Reduction Software
659 *
660 * Module name: freeCalibrator
661 * Input/Output: See function arguments to avoid duplication
662 * Description: Releases memory for the calibrator array
663 *
664 * History:
665 * 29-Mar-04 (csabet) Created
666 ******************************************************************************/
667 void freeCalibrator (
668  CalibratorParam *array)
669 {
670  /* Local Declarations
671  --------------------*/
672 
673  /* Algorithm
674  -----------*/
675  free (array->calibName);
676  free (array);
677  array = NULL;
678 
679  return;
680 }
681 /*****************************************************************************/
682 
683 
684 /******************************************************************************
685 * European Southern Observatory
686 * MIDI Data Reduction Software
687 *
688 * Module name: callocIauExchange
689 * Input/Output: See function arguments to avoid duplication
690 * Description: Allocates memory for the IAU data structure
691 *
692 * History:
693 * 09-Feb-05 (csabet) Created
694 ******************************************************************************/
695 IauExchange *callocIauExchange (
696  int numOfTelescopes,
697  int numOfChannels)
698 {
699  // Local Declarations
700  // ------------------
701  IauExchange *iauArray=NULL;
702  int i;
703 
704  // Algorithm
705  // ---------
706  iauArray = (IauExchange *) calloc (1, sizeof (IauExchange));
707 
708  // OI_ARRAY
709  iauArray->array = (OiArray *) calloc (1, sizeof (OiArray));
710  iauArray->array->revision = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
711  iauArray->array->arrname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
712  iauArray->array->frame = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
713  iauArray->array->nelement = numOfTelescopes;
714  iauArray->array->elem = (Element *) calloc (iauArray->array->nelement, sizeof(Element));
715  for (i = 0; i < iauArray->array->nelement; i++)
716  {
717  iauArray->array->elem[i].tel_name = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
718  iauArray->array->elem[i].sta_name = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
719  iauArray->array->elem[i].staxyz = (double *) calloc (3, sizeof (double));
720 
721  }
722 
723  // OI_TARGET
724  iauArray->targets = (OiTarget *) calloc (1, sizeof (OiTarget));
725  iauArray->targets->revision = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
726  iauArray->targets->ntarget = 1;
727  iauArray->targets->targ = (Target *) calloc (iauArray->targets->ntarget, sizeof(Target));
728  iauArray->targets->targ->spectyp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
729  iauArray->targets->targ->veldef = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
730  iauArray->targets->targ->veltyp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
731  iauArray->targets->targ->target = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
732 
733  // OI_WAVELENGTH
734  iauArray->wavelength = (OiWavelength *) calloc (1, sizeof (OiWavelength));
735  iauArray->wavelength->revision = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
736  iauArray->wavelength->insname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
737  iauArray->wavelength->nwave = numOfChannels;
738  iauArray->wavelength->eff_wave = (float *) calloc (iauArray->wavelength->nwave, sizeof(float));
739  iauArray->wavelength->eff_band = (float *) calloc (iauArray->wavelength->nwave, sizeof(float));
740 
741  // OI_VIS
742  iauArray->vis = (OiVis *) calloc (1, sizeof (OiVis));
743  iauArray->vis->revision = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
744  iauArray->vis->date_obs = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
745  iauArray->vis->arrname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
746  iauArray->vis->insname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
747  iauArray->vis->numrec = 1;
748  iauArray->vis->record = (OiVisRecord *) calloc (iauArray->vis->numrec, sizeof(OiVisRecord));
749  for (i = 0; i < iauArray->vis->numrec; i++)
750  {
751  iauArray->vis->record[i].sta_index = (int *) calloc (2, sizeof(int));
752  iauArray->vis->record[i].visamp = (double *) calloc (iauArray->wavelength->nwave, sizeof(double));
753  iauArray->vis->record[i].visamperr = (double *) calloc (iauArray->wavelength->nwave, sizeof(double));
754  iauArray->vis->record[i].visphi = (double *) calloc (iauArray->wavelength->nwave, sizeof(double));
755  iauArray->vis->record[i].visphierr = (double *) calloc (iauArray->wavelength->nwave, sizeof(double));
756  iauArray->vis->record[i].flag = (char *) calloc (MIN_STRING_LENGTH, sizeof(char));
757  }
758 
759  // OI_VIS2
760  iauArray->vis2 = (OiVis2 *) calloc (1, sizeof (OiVis2));
761  iauArray->vis2->revision = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
762  iauArray->vis2->date_obs = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
763  iauArray->vis2->arrname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
764  iauArray->vis2->insname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
765  iauArray->vis2->numrec = 1;
766  iauArray->vis2->record = (OiVis2Record *) calloc (iauArray->vis2->numrec, sizeof (OiVis2Record));
767  for(i = 0; i < iauArray->vis2->numrec; i++)
768  {
769  iauArray->vis2->record[i].vis2data = (double *) calloc (iauArray->wavelength->nwave, sizeof (double));
770  iauArray->vis2->record[i].vis2err = (double *) calloc (iauArray->wavelength->nwave, sizeof (double));
771  iauArray->vis2->record[i].flag = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
772  iauArray->vis2->record[i].sta_index = (int *) calloc (2, sizeof (int));
773  }
774 
775  return (iauArray);
776 }
777 /*****************************************************************************/
778 
779 
780 /******************************************************************************
781 * European Southern Observatory
782 * MIDI Data Reduction Software
783 *
784 * Module name: freeIauExchange
785 * Input/Output: See function arguments to avoid duplication
786 * Description: Releases memory for the IAU data structure
787 *
788 * History:
789 * 23-Feb-04 (csabet) Created
790 ******************************************************************************/
791 void freeIauExchange (
792  IauExchange *iauArray)
793 {
794  // Local Declarations
795  // ------------------
796  int i;
797 
798  // Algorithm
799  // ---------
800 
801  // Release OI_ARRAY
802  free (iauArray->array->frame);
803  free (iauArray->array->arrname);
804  free (iauArray->array->revision);
805  for (i = 0; i < iauArray->array->nelement; i++)
806  {
807  free (iauArray->array->elem[i].tel_name);
808  free (iauArray->array->elem[i].sta_name);
809  free (iauArray->array->elem[i].staxyz);
810  }
811  free (iauArray->array->elem);
812  free (iauArray->array);
813 
814  // Release OI_TARGET
815  free (iauArray->targets->revision);
816  free (iauArray->targets->targ->spectyp);
817  free (iauArray->targets->targ->veldef);
818  free (iauArray->targets->targ->veltyp);
819  free (iauArray->targets->targ->target);
820  free (iauArray->targets->targ);
821  free (iauArray->targets);
822 
823  // Release OI_WAVELENGTH
824  free (iauArray->wavelength->eff_wave);
825  free (iauArray->wavelength->eff_band);
826  free (iauArray->wavelength->revision);
827  free (iauArray->wavelength->insname);
828  free (iauArray->wavelength);
829 
830  // Release OI_VIS
831  free (iauArray->vis->revision);
832  free (iauArray->vis->date_obs);
833  free (iauArray->vis->arrname);
834  free (iauArray->vis->insname);
835  for (i = 0; i < iauArray->vis->numrec; i++)
836  {
837  free (iauArray->vis->record[i].visamp);
838  free (iauArray->vis->record[i].visamperr);
839  free (iauArray->vis->record[i].visphi);
840  free (iauArray->vis->record[i].visphierr);
841  free (iauArray->vis->record[i].sta_index);
842  free (iauArray->vis->record[i].flag);
843  }
844  free (iauArray->vis->record);
845  free (iauArray->vis);
846 
847  // Release OI_VIS2
848  free (iauArray->vis2->revision);
849  free (iauArray->vis2->date_obs);
850  free (iauArray->vis2->arrname);
851  free (iauArray->vis2->insname);
852  for(i = 0; i < iauArray->vis2->numrec; i++)
853  {
854  free (iauArray->vis2->record[i].vis2data);
855  free (iauArray->vis2->record[i].vis2err);;
856  free (iauArray->vis2->record[i].sta_index);
857  free (iauArray->vis2->record[i].flag);
858  }
859  free (iauArray->vis2->record);
860  free (iauArray->vis2);
861 
862  free (iauArray);
863  iauArray = NULL;
864 
865  return;
866 }
867 /*****************************************************************************/
868 
869 
870 
871 /******************************************************************************
872 * European Southern Observatory
873 * MIDI Data Reduction Software
874 *
875 * Module name: callocPhotometry
876 * Input/Output: See function arguments to avoid duplication
877 * Description: Allocates memory for the photometry result
878 *
879 * History:
880 * 16-Jan-04 (csabet) Created
881 ******************************************************************************/
882 PhotometryResult *callocPhotometry (void)
883 {
884  /* Local Declarations
885  --------------------*/
886  PhotometryResult *array=NULL;
887 
888  /* Algorithm
889  -----------*/
890  array = (PhotometryResult *) calloc (1, sizeof (PhotometryResult));
891 
892  array->photomA = (float *) calloc (2, sizeof (float));
893  array->photomAErr = (float *) calloc (2, sizeof (float));
894 
895  array->photomB = (float *) calloc (2, sizeof (float));
896  array->photomBErr = (float *) calloc (2, sizeof (float));
897 
898  array->chop2ChopAErr = (float *) calloc (2, sizeof (float));
899  array->chop2ChopBErr = (float *) calloc (2, sizeof (float));
900 
901  return (array);
902 }
903 /*****************************************************************************/
904 
905 
906 /******************************************************************************
907 * European Southern Observatory
908 * MIDI Data Reduction Software
909 *
910 * Module name: freePhotometry
911 * Input/Output: See function arguments to avoid duplication
912 * Description: Releases memory for the photometry result
913 *
914 * History:
915 * 16-Jan-04 (csabet) Created
916 ******************************************************************************/
917 void freePhotometry (
918  PhotometryResult *array)
919 {
920  /* Local Declarations
921  --------------------*/
922 
923  /* Algorithm
924  -----------*/
925  free (array->photomA);
926  free (array->photomAErr);
927 
928  free (array->photomB);
929  free (array->photomBErr);
930 
931  free (array->chop2ChopAErr);
932  free (array->chop2ChopBErr);
933 
934  free (array);
935  array = NULL;
936 
937  return;
938 }
939 /*****************************************************************************/
940 
941 
942 /******************************************************************************
943 * European Southern Observatory
944 * MIDI Data Reduction Software
945 *
946 * Module name: callocRawVis
947 * Input/Output: See function arguments to avoid duplication
948 * Description: Allocates memory for the interferometry result
949 *
950 * History:
951 * 15-Jan-04 (csabet) Created
952 ******************************************************************************/
953 RawVisibility *callocRawVis (void)
954 {
955  /* Local Declarations
956  --------------------*/
957  RawVisibility *array=NULL;
958 
959  /* Algorithm
960  -----------*/
961  array = (RawVisibility *) calloc (1, sizeof (RawVisibility));
962 
963  return (array);
964 }
965 /*****************************************************************************/
966 
967 
968 
969 /******************************************************************************
970 * European Southern Observatory
971 * MIDI Data Reduction Software
972 *
973 * Module name: freeRawVis
974 * Input/Output: See function arguments to avoid duplication
975 * Description: Releases memory for the interferometry result data
976 *
977 * History:
978 * 15-Jan-04 (csabet) Created
979 ******************************************************************************/
980 void freeRawVis (
981  RawVisibility *array)
982 {
983  /* Local Declarations
984  --------------------*/
985 
986  /* Algorithm
987  -----------*/
988  free (array);
989  array = NULL;
990 
991  return;
992 }
993 /*****************************************************************************/
994 
995 
996 
997 /******************************************************************************
998 * European Southern Observatory
999 * MIDI Data Reduction Software
1000 *
1001 * Module name: callocMidiCompressed
1002 * Input/Output: See function arguments to avoid duplication
1003 * Description: Allocates memory for the compressed data
1004 *
1005 * History:
1006 * 05-Nov-03 (csabet) Created
1007 ******************************************************************************/
1008 CompressedData *callocMidiCompressed (
1009  ImageFormat *format)
1010 {
1011  // Local Declarations
1012  // ------------------
1013  CompressedData *array=NULL;
1014  int i, X;
1015 
1016  // Algorithm
1017  // ---------
1018  array = (CompressedData *) calloc (1, sizeof (CompressedData));
1019 
1020  array->iDispFringe = (float ***) calloc (format->numOfRegionsToProcess, sizeof(float **));
1021  for (i = 0; i < format->numOfRegionsToProcess; i++)
1022  {
1023  (array->iDispFringe)[i] = (float **) calloc (format->iXWidth, sizeof(float *));
1024  for (X = 0; X < format->iXWidth; X++)
1025  (array->iDispFringe)[i][X] = (float *) calloc (format->numOfFrames, sizeof(float));
1026  }
1027 
1028  array->rejectList = (int **) calloc (format->iXWidth, sizeof (int *));
1029  for (i = 0; i < format->iXWidth; i++)
1030  array->rejectList[i] = (int *) calloc (format->numOfFrames, sizeof (int));
1031 
1032  array->badScanList = (int *) calloc (format->numOfScans, sizeof (int));
1033 
1034  array->image = (float **) calloc (format->numOfRegionsToProcess, sizeof(float *));
1035  for (i = 0; i < format->numOfRegionsToProcess; i++)
1036  array->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
1037 
1038  array->iFringe1 = (double *) calloc (format->numOfFrames, sizeof(double));
1039  array->iFringe2 = (double *) calloc (format->numOfFrames, sizeof(double));
1040  array->iFringe = (double *) calloc (format->numOfFrames, sizeof(double));
1041  array->allSpectrum = (float *) calloc (format->allSpectrumLength, sizeof(float));
1042  array->dcLevels = (float *) calloc (REGIONS_UNDISPERSED * format->numOfScans, sizeof (float));
1043  array->tarType = (char *) calloc(format->numOfFrames, sizeof(char));
1044  array->time = (float *) calloc(format->numOfFrames, sizeof(float));
1045  array->localOPD = (float *) calloc(format->numOfFrames, sizeof(float));
1046  array->bigDL = (float *) calloc(format->numOfFrames, sizeof(float));
1047 
1048  return (array);
1049 }
1050 /*****************************************************************************/
1051 
1052 
1053 
1054 /******************************************************************************
1055 * European Southern Observatory
1056 * MIDI Data Reduction Software
1057 *
1058 * Module name: freeCompressedData
1059 * Input/Output: See function arguments to avoid duplication
1060 * Description: Releases all the memory related to the
1061 * compressed data
1062 *
1063 * History:
1064 * 05-Nov-03 (csabet) Created
1065 ******************************************************************************/
1066 void freeCompressedData (
1067  ImageFormat *format,
1068  CompressedData *array)
1069 {
1070  // Local Declarations
1071  // ------------------
1072  int i, j;
1073 
1074  // Algorithm
1075  // ---------
1076  for (i = 0; i < format->numOfRegionsToProcess; i++)
1077  {
1078  for (j = 0; j < format->iXWidth; j++)
1079  free ((array->iDispFringe)[i][j]);
1080 
1081  free ((array->iDispFringe)[i]);
1082  }
1083  free (array->iDispFringe);
1084 
1085  for (i = 0; i < format->numOfRegionsToProcess; i++)
1086  {
1087  free (array->image[i]);
1088  }
1089  free (array->image);
1090 
1091  for (i = 0; i < format->iXWidth; i++)
1092  free (array->rejectList[i]);
1093  free (array->rejectList);
1094 
1095  free (array->badScanList);
1096  free (array->iFringe1);
1097  free (array->iFringe2);
1098  free (array->iFringe);
1099  free (array->allSpectrum);
1100  free (array->dcLevels);
1101  free (array->tarType);
1102  free (array->time);
1103  free (array->localOPD);
1104  free (array->bigDL);
1105 
1106  free (array);
1107  array = NULL;
1108 
1109  return;
1110 }
1111 /*****************************************************************************/
1112 
1113 
1114 
1115 
1116 /******************************************************************************
1117 * European Southern Observatory
1118 * MIDI Data Reduction Software
1119 *
1120 * Module name: callocMidiFiles
1121 * Input/Output: See function arguments to avoid duplication
1122 * Description: Allocates memory for the MIDI file Structure
1123 *
1124 * History:
1125 * 05-Nov-03 (csabet) Created
1126 ******************************************************************************/
1127 MidiFiles *callocMidiFiles (
1128  int stringLength)
1129 {
1130  /* Local Declarations
1131  --------------------*/
1132  MidiFiles *fileNames=NULL;
1133 
1134  /* Algorithm
1135  -----------*/
1136  fileNames = (MidiFiles *) calloc (1, sizeof (MidiFiles));
1137  fileNames->inFitsList = (char *) calloc (stringLength, sizeof (char));
1138  fileNames->inFitsClassified = (char *) calloc (stringLength, sizeof (char));
1139  fileNames->inFitsBatch = (char *) calloc (stringLength, sizeof (char));
1140  fileNames->inFileDir = (char *) calloc (stringLength, sizeof (char));
1141  fileNames->maskFileDir = (char *) calloc (stringLength, sizeof (char));
1142  fileNames->maskFileName = (char *) calloc (stringLength, sizeof (char));
1143  fileNames->inFitsName = (char *) calloc (stringLength, sizeof (char));
1144  fileNames->outFitsName = (char *) calloc (stringLength, sizeof (char));
1145  fileNames->outWaterfallName = (char *) calloc (stringLength, sizeof (char));
1146  fileNames->outWaterpowerName = (char *) calloc (stringLength, sizeof (char));
1147  fileNames->outAveImageName = (char *) calloc (stringLength, sizeof (char));
1148  fileNames->outChSpectrumName = (char *) calloc (stringLength, sizeof (char));
1149  fileNames->calibDbName = (char *) calloc (stringLength, sizeof (char));
1150  fileNames->grismFoilName = (char *) calloc (stringLength, sizeof (char));
1151  fileNames->prismFoilName = (char *) calloc (stringLength, sizeof (char));
1152  fileNames->calibDbDir = (char *) calloc (stringLength, sizeof (char));
1153  fileNames->trfNameRead = (char *) calloc (stringLength, sizeof (char));
1154  fileNames->trfNameWrite = (char *) calloc (stringLength, sizeof (char));
1155  fileNames->trfHistoryName = (char *) calloc (stringLength, sizeof (char));
1156  fileNames->trrNameRead = (char *) calloc (stringLength, sizeof (char));
1157  fileNames->trrNameWrite = (char *) calloc (stringLength, sizeof (char));
1158  fileNames->trrHistoryName = (char *) calloc (stringLength, sizeof (char));
1159  fileNames->wclNameRead = (char *) calloc (stringLength, sizeof (char));
1160  fileNames->wclNameWrite = (char *) calloc (stringLength, sizeof (char));
1161  fileNames->transferRatiosName = (char *) calloc (stringLength, sizeof (char));
1162  fileNames->wclHistoryName = (char *) calloc (stringLength, sizeof (char));
1163  fileNames->archFileName = (char *) calloc (stringLength, sizeof (char));
1164  fileNames->pipeFileName = (char *) calloc (stringLength, sizeof (char));
1165  fileNames->waveCalibName = (char *) calloc (stringLength, sizeof (char));
1166 
1167  return (fileNames);
1168 }
1169 /*****************************************************************************/
1170 
1171 
1172 
1173 /******************************************************************************
1174 * European Southern Observatory
1175 * MIDI Data Reduction Software
1176 *
1177 * Module name: freeMidiFiles
1178 * Input/Output: See function arguments to avoid duplication
1179 * Description: Releases all MIDI file structures
1180 *
1181 * History:
1182 * 05-Nov-03 (csabet) Created
1183 ******************************************************************************/
1184 void freeMidiFiles (
1185  MidiFiles *fileNames)
1186 {
1187  /* Local Declarations
1188  --------------------*/
1189 
1190  /* Algorithm
1191  -----------*/
1192  free (fileNames->inFitsList);
1193  free (fileNames->inFitsClassified);
1194  free (fileNames->inFitsBatch);
1195  free (fileNames->inFileDir);
1196  free (fileNames->maskFileDir);
1197  free (fileNames->maskFileName);
1198  free (fileNames->inFitsName);
1199  free (fileNames->outFitsName);
1200  free (fileNames->outWaterfallName);
1201  free (fileNames->outWaterpowerName);
1202  free (fileNames->outAveImageName);
1203  free (fileNames->outChSpectrumName);
1204  free (fileNames->calibDbName);
1205  free (fileNames->grismFoilName);
1206  free (fileNames->prismFoilName);
1207  free (fileNames->calibDbDir);
1208  free (fileNames->trfNameRead);
1209  free (fileNames->trfNameWrite);
1210  free (fileNames->trfHistoryName);
1211  free (fileNames->trrNameRead);
1212  free (fileNames->trrNameWrite);
1213  free (fileNames->trrHistoryName);
1214  free (fileNames->wclNameRead);
1215  free (fileNames->wclNameWrite);
1216  free (fileNames->wclHistoryName);
1217  free (fileNames->archFileName);
1218  free (fileNames->transferRatiosName);
1219  free (fileNames->pipeFileName);
1220  free (fileNames->waveCalibName);
1221  free (fileNames);
1222  fileNames = NULL;
1223 
1224  return;
1225 }
1226 /*****************************************************************************/
1227 
1228 /******************************************************************************
1229 * European Southern Observatory
1230 * MIDI Data Reduction Software
1231 *
1232 * Module name: callocDspTrn
1233 * Input/Output: See function arguments to avoid duplication
1234 * Description: Allocates memory for the Dispersive Transmission data structure
1235 *
1236 * History:
1237 * 26-Aug-04 (csabet) Created
1238 ******************************************************************************/
1239 DispersiveTrans *callocDspTrn (
1240  int numOfFiles)
1241 {
1242  /* Local Declarations
1243  --------------------*/
1244  DispersiveTrans *array=NULL;
1245  int i;
1246 
1247  /* Algorithm
1248  -----------*/
1249  array = (DispersiveTrans *) calloc (1, sizeof (DispersiveTrans));
1250  array->numOfFiles = numOfFiles;
1251  array->target = (MidiCoords *) calloc (numOfFiles, sizeof (MidiCoords));
1252 
1253  array->integTime = (float *) calloc (numOfFiles, sizeof (float));
1254  array->integFlux = (float *) calloc (numOfFiles, sizeof (float));
1255  array->meanFlux = (float *) calloc (numOfFiles, sizeof (float));
1256  array->transmission = (float *) calloc (numOfFiles/2, sizeof (float));
1257 
1258  array->beamCombiner = (char **) calloc (numOfFiles, sizeof (char *));
1259  array->shutterId = (char **) calloc (numOfFiles, sizeof (char *));
1260  array->cameraId = (char **) calloc (numOfFiles, sizeof (char *));
1261  array->grismId = (char **) calloc (numOfFiles, sizeof (char *));
1262  array->filterName = (char **) calloc (numOfFiles, sizeof (char *));
1263  for (i = 0; i < array->numOfFiles; i++)
1264  {
1265  array->beamCombiner[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1266  array->shutterId[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1267  array->cameraId[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1268  array->grismId[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1269  array->filterName[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1270  }
1271 
1272  return (array);
1273 }
1274 /*****************************************************************************/
1275 
1276 
1277 
1278 /******************************************************************************
1279 * European Southern Observatory
1280 * MIDI Data Reduction Software
1281 *
1282 * Module name: freeDspTrn
1283 * Input/Output: See function arguments to avoid duplication
1284 * Description: Releases all the memory related to the dspTrn data structure
1285 *
1286 * History:
1287 * 26-Aug-04 (csabet) Created
1288 ******************************************************************************/
1289 void freeDspTrn (
1290  DispersiveTrans *array)
1291 {
1292  /* Local Declarations
1293  --------------------*/
1294  int i;
1295 
1296  /* Algorithm
1297  -----------*/
1298  free (array->integTime);
1299  free (array->integFlux);
1300  free (array->meanFlux);
1301  free (array->transmission);
1302  free (array->target);
1303  for (i = 0; i < array->numOfFiles; i++)
1304  {
1305  free (array->beamCombiner[i]);
1306  free (array->shutterId[i]);
1307  free (array->cameraId[i]);
1308  free (array->grismId[i]);
1309  free (array->filterName[i]);
1310  }
1311  free (array->beamCombiner);
1312  free (array->shutterId);
1313  free (array->cameraId);
1314  free (array->grismId);
1315  free (array->filterName);
1316 
1317  free (array);
1318  array = NULL;
1319 
1320  return;
1321 }
1322 /*****************************************************************************/
1323 
1324 
1325 
1326 /******************************************************************************
1327 * European Southern Observatory
1328 * MIDI Data Reduction Software
1329 *
1330 * Module name: callocRefPix
1331 * Input/Output: See function arguments to avoid duplication
1332 * Description: Allocates memory for the Reference Pixel alignment data structure
1333 *
1334 * History:
1335 * 11-Aug-04 (csabet) Created
1336 * 28-Aug-06 (csabet) Modified
1337 ******************************************************************************/
1338 ReferencePixel *callocRefPix (
1339  int numOfFiles,
1340  int numOfBeams)
1341 {
1342  // Local Declarations
1343  // ------------------
1344  ReferencePixel *array=NULL;
1345  int i;
1346 
1347  // Algorithm
1348  // ---------
1349  array = (ReferencePixel *) calloc (1, sizeof (ReferencePixel));
1350  array->numOfExposures = numOfFiles;
1351  array->exposure = (RefPixExposure *) calloc (array->numOfExposures, sizeof (RefPixExposure));
1352 
1353  for (i = 0; i < array->numOfExposures; i++)
1354  {
1355  array->exposure[i].shutterId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1356  array->exposure[i].beamCombiner = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1357  array->exposure[i].numOfBeams = numOfBeams;
1358  array->exposure[i].centroid = (MidiCoords *) calloc (array->exposure[i].numOfBeams, sizeof (MidiCoords));
1359  }
1360 
1361  return (array);
1362 }
1363 /*****************************************************************************/
1364 
1365 
1366 
1367 /******************************************************************************
1368 * European Southern Observatory
1369 * MIDI Data Reduction Software
1370 *
1371 * Module name: freeRefPix
1372 * Input/Output: See function arguments to avoid duplication
1373 * Description: Releases all the memory related to the refPix data structure
1374 *
1375 * History:
1376 * 11-Aug-04 (csabet) Created
1377 * 28-Aug-06 (csabet) Modified
1378 ******************************************************************************/
1379 void freeRefPix (
1380  ReferencePixel *array)
1381 {
1382  // Local Declarations
1383  // ------------------
1384  int i;
1385 
1386  // Algorithm
1387  // ---------
1388  for (i = 0; i < array->numOfExposures; i++)
1389  {
1390  free (array->exposure[i].beamCombiner);
1391  free (array->exposure[i].shutterId);
1392  free (array->exposure[i].centroid);
1393  }
1394  free (array->exposure);
1395  free (array);
1396  array = NULL;
1397 
1398  return;
1399 }
1400 /*****************************************************************************/
1401 
1402 
1403 
1404 /******************************************************************************
1405 * European Southern Observatory
1406 * MIDI Data Reduction Software
1407 *
1408 * Module name: callocDetLin
1409 * Input/Output: See function arguments to avoid duplication
1410 * Description: Allocates memory for the detector linearity data structure
1411 *
1412 * History:
1413 * 06-Aug-04 (csabet) Created
1414 ******************************************************************************/
1415 DetLinearity *callocDetLin (
1416  int numOfFiles,
1417  ImageFormat *format)
1418 {
1419  /* Local Declarations
1420  --------------------*/
1421  DetLinearity *array=NULL;
1422  int i;
1423 
1424  /* Algorithm
1425  -----------*/
1426  array = (DetLinearity *) calloc (1, sizeof (DetLinearity));
1427  array->size = numOfFiles;
1428 
1429  array->mean = (float *) calloc (array->size, sizeof(float));
1430  array->grismId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1431  array->saturated = (int *) calloc (array->size, sizeof (int));
1432  array->integTime = (float *) calloc (array->size, sizeof(float));
1433  array->deviation = (float *) calloc (format->iXWidth * format->iYWidth, sizeof (float));
1434  array->aveImage = (float **) calloc (array->size, sizeof (float *));
1435  for (i = 0; i < array->size; i++)
1436  array->aveImage[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof (float));
1437 
1438  return (array);
1439 }
1440 /*****************************************************************************/
1441 
1442 
1443 
1444 /******************************************************************************
1445 * European Southern Observatory
1446 * MIDI Data Reduction Software
1447 *
1448 * Module name: freeDetLin
1449 * Input/Output: See function arguments to avoid duplication
1450 * Description: Releases all the memory related to the DetLinearity data structure
1451 *
1452 * History:
1453 * 06-Aug-04 (csabet) Created
1454 ******************************************************************************/
1455 void freeDetLin (
1456  DetLinearity *array)
1457 {
1458  /* Local Declarations
1459  --------------------*/
1460  int i;
1461 
1462  /* Algorithm
1463  -----------*/
1464  free (array->grismId);
1465  free (array->saturated);
1466  free (array->integTime);
1467  free (array->mean);
1468  free (array->deviation);
1469 
1470  for (i = 0; i < array->size; i++)
1471  free (array->aveImage[i]);
1472  free (array->aveImage);
1473 
1474  free (array);
1475  array = NULL;
1476 
1477  return;
1478 }
1479 /*****************************************************************************/
1480 
1481 
1482 
1483 /******************************************************************************
1484 * European Southern Observatory
1485 * MIDI Data Reduction Software
1486 *
1487 * Module name: callocDetRon
1488 * Input/Output: See function arguments to avoid duplication
1489 * Description: Allocates memory for the noise pattern data structure
1490 *
1491 * History:
1492 * 04-Aug-04 (csabet) Created
1493 ******************************************************************************/
1494 DetRonNoise *callocDetRon (
1495  ImageFormat *imageSize)
1496 {
1497  /* Local Declarations
1498  --------------------*/
1499  DetRonNoise *array=NULL;
1500 
1501  /* Algorithm
1502  -----------*/
1503  array = (DetRonNoise *) calloc (1, sizeof (DetRonNoise));
1504 
1505  array->pattern = (float *) calloc (imageSize->iXWidth * imageSize->iYWidth, sizeof(float));
1506  array->aveImage = (float *) calloc (imageSize->iXWidth * imageSize->iYWidth, sizeof(float));
1507 
1508  return (array);
1509 }
1510 /*****************************************************************************/
1511 
1512 
1513 
1514 /******************************************************************************
1515 * European Southern Observatory
1516 * MIDI Data Reduction Software
1517 *
1518 * Module name: freeDetRon
1519 * Input/Output: See function arguments to avoid duplication
1520 * Description: Releases all the memory related to the DetRonNoise data structure
1521 *
1522 * History:
1523 * 04-Aug-04 (csabet) Created
1524 ******************************************************************************/
1525 void freeDetRon (
1526  DetRonNoise *array)
1527 {
1528  /* Local Declarations
1529  --------------------*/
1530 
1531  /* Algorithm
1532  -----------*/
1533  free (array->pattern);
1534  free (array->aveImage);
1535  free (array);
1536  array = NULL;
1537 
1538  return;
1539 }
1540 /*****************************************************************************/
1541 
1542 
1543 /******************************************************************************
1544 * European Southern Observatory
1545 * MIDI Data Reduction Software
1546 *
1547 * Module name: callocImageQuality
1548 * Input/Output: See function arguments to avoid duplication
1549 * Description: Allocates memory for the ImageQuality data structure
1550 *
1551 * History:
1552 * 26-Apr-05 (csabet) Created
1553 ******************************************************************************/
1554 ImageQuality *callocImageQuality (
1555  ImageFormat *format)
1556 {
1557  // Local Declarations
1558  // ------------------
1559  ImageQuality *image=NULL;
1560  int i;
1561 
1562  // Algorithm
1563  // ---------
1564  image = (ImageQuality *) calloc (1, sizeof (ImageQuality));
1565 
1566  image->aveImage = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
1567  image->aveImageSky = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
1568  for (i = 0; i < format->numOfDetectorRegions; i++)
1569  {
1570  image->aveImage[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
1571  image->aveImageSky[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
1572  }
1573 
1574  image->targetFlux = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1575  image->targetPixelCount = (int *) calloc (format->numOfDetectorRegions, sizeof (int));
1576  image->coordX = (double *) calloc (format->numOfDetectorRegions, sizeof (double));
1577  image->coordY = (double *) calloc (format->numOfDetectorRegions, sizeof (double));
1578  image->sizeX = (double *) calloc (format->numOfDetectorRegions, sizeof (double));
1579  image->sizeY = (double *) calloc (format->numOfDetectorRegions, sizeof (double));
1580  image->tarType = (char *) calloc (format->numOfFrames, sizeof(char));
1581 
1582  return (image);
1583 }
1584 /*****************************************************************************/
1585 
1586 
1587 
1588 /******************************************************************************
1589 * European Southern Observatory
1590 * MIDI Data Reduction Software
1591 *
1592 * Module name: freeImageQuality
1593 * Input/Output: See function arguments to avoid duplication
1594 * Description: Releases all the memory related to the mageQuality data structure
1595 *
1596 * History:
1597 * 26-Apr-05 (csabet) Created
1598 ******************************************************************************/
1599 void freeImageQuality (
1600  ImageFormat *format,
1601  ImageQuality *image)
1602 {
1603  // Local Declarations
1604  // ------------------
1605  int i;
1606 
1607  // Algorithm
1608  // ---------
1609  for (i = 0; i < format->numOfDetectorRegions; i++)
1610  {
1611  free (image->aveImage[i]);
1612  free (image->aveImageSky[i]);
1613  }
1614 
1615  free (image->tarType);
1616  free (image->aveImage);
1617  free (image->aveImageSky);
1618  free (image->targetFlux);
1619  free (image->targetPixelCount);
1620  free (image->coordX);
1621  free (image->coordY);
1622  free (image->sizeX);
1623  free (image->sizeY);
1624 
1625  free (image);
1626  image = NULL;
1627 
1628  return;
1629 }
1630 /*****************************************************************************/
1631 
1632 
1633 /******************************************************************************
1634 * European Southern Observatory
1635 * MIDI Data Reduction Software
1636 *
1637 * Module name: callocWavCal
1638 * Input/Output: See function arguments to avoid duplication
1639 * Description: Allocates memory for the WavCalibration data structure
1640 *
1641 * History:
1642 * 10-Jun-05 (csabet) Created
1643 ******************************************************************************/
1644 WaveCalibration *callocWaveCal (
1645  int numOfFiles,
1646  int numOfRecords,
1647  ImageFormat *format)
1648 {
1649  // Local Declarations
1650  // ------------------
1651  WaveCalibration *array=NULL;
1652  int i;
1653 
1654  // Algorithm
1655  // ---------
1656  array = (WaveCalibration *) calloc (1, sizeof (WaveCalibration));
1657 
1658  array->numOfFiles = numOfFiles;
1659  array->tarType = (char *) calloc (format->numOfFrames, sizeof(char));
1660  array->variance = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1661  array->calibratedWave = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
1662  for (i = 0; i < format->numOfDetectorRegions; i++)
1663  array->calibratedWave[i] = (float *) calloc (format->iXWidth, sizeof(float));
1664 
1665  array->filterName = (char **) calloc (numOfFiles, sizeof (char *));
1666  array->shutterId = (char **) calloc (numOfFiles, sizeof (char *));
1667  for (i = 0; i < array->numOfFiles; i++)
1668  {
1669  array->filterName[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1670  array->shutterId[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1671  }
1672 
1673  // ArIII memory
1674  array->ArIII = (NarrowBandInfo *) calloc (1, sizeof (NarrowBandInfo));
1675  array->ArIII->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
1676  array->ArIII->wavelength = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1677  array->ArIII->xCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1678  array->ArIII->yCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1679  array->ArIII->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
1680  for (i = 0; i < format->numOfDetectorRegions; i++)
1681  array->ArIII->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
1682 
1683  // NeII memory
1684  array->NeII = (NarrowBandInfo *) calloc (1, sizeof (NarrowBandInfo));
1685  array->NeII->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
1686  array->NeII->wavelength = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1687  array->NeII->xCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1688  array->NeII->yCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1689  array->NeII->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
1690  for (i = 0; i < format->numOfDetectorRegions; i++)
1691  array->NeII->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
1692 
1693  // SIV memory
1694  array->SIV = (NarrowBandInfo *) calloc (1, sizeof (NarrowBandInfo));
1695  array->SIV->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
1696  array->SIV->wavelength = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1697  array->SIV->xCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1698  array->SIV->yCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
1699  array->SIV->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
1700  for (i = 0; i < format->numOfDetectorRegions; i++)
1701  array->SIV->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
1702 
1703  // Foil memory
1704  array->foil = (FoilInfo *) calloc (1, sizeof (FoilInfo));
1705  array->foil->actualWavelength = (float *) calloc (numOfRecords, sizeof (float));
1706  array->foil->actualTransmission = (float *) calloc (numOfRecords, sizeof (float));
1707  array->foil->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
1708  array->foil->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
1709  for (i = 0; i < format->numOfDetectorRegions; i++)
1710  array->foil->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
1711 
1712  // OPEN memory
1713  array->open = (OpenInfo *) calloc (1, sizeof (OpenInfo));
1714  array->open->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
1715  array->open->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
1716  for (i = 0; i < format->numOfDetectorRegions; i++)
1717  array->open->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
1718 
1719  // DARK memory
1720  array->dark = (DarkInfo *) calloc (1, sizeof (DarkInfo));
1721  array->dark->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
1722  array->dark->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
1723  for (i = 0; i < format->numOfDetectorRegions; i++)
1724  array->dark->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
1725 
1726  return (array);
1727 }
1728 /*****************************************************************************/
1729 
1730 
1731 /******************************************************************************
1732 * European Southern Observatory
1733 * MIDI Data Reduction Software
1734 *
1735 * Module name: freeWavCal
1736 * Input/Output: See function arguments to avoid duplication
1737 * Description: Releases all the memory related to the WavCalibration data structure
1738 *
1739 * History:
1740 * 10-Jun-05 (csabet) Created
1741 ******************************************************************************/
1742 void freeWaveCal (
1743  ImageFormat *format,
1744  WaveCalibration *array)
1745 {
1746  // Local Declarations
1747  // ------------------
1748  int i;
1749 
1750  // Algorithm
1751  // ---------
1752  for (i = 0; i < array->numOfFiles; i++)
1753  {
1754  free (array->filterName[i]);
1755  free (array->shutterId[i]);
1756  }
1757  free (array->filterName);
1758  free (array->shutterId);
1759  free (array->tarType);
1760  free (array->variance);
1761 
1762  for (i = 0; i < format->numOfDetectorRegions; i++) free (array->calibratedWave[i]);
1763  free (array->calibratedWave);
1764 
1765  for (i = 0; i < format->numOfDetectorRegions; i++) free (array->ArIII->image[i]);
1766  free (array->ArIII->image);
1767  free (array->ArIII->wavelength);
1768  free (array->ArIII->xCoord);
1769  free (array->ArIII->yCoord);
1770  free (array->ArIII->fileName);
1771  free (array->ArIII);
1772 
1773  for (i = 0; i < format->numOfDetectorRegions; i++) free (array->NeII->image[i]);
1774  free (array->NeII->image);
1775  free (array->NeII->wavelength);
1776  free (array->NeII->xCoord);
1777  free (array->NeII->yCoord);
1778  free (array->NeII->fileName);
1779  free (array->NeII);
1780 
1781  for (i = 0; i < format->numOfDetectorRegions; i++) free (array->SIV->image[i]);
1782  free (array->SIV->image);
1783  free (array->SIV->wavelength);
1784  free (array->SIV->xCoord);
1785  free (array->SIV->yCoord);
1786  free (array->SIV->fileName);
1787  free (array->SIV);
1788 
1789  for (i = 0; i < format->numOfDetectorRegions; i++) free (array->foil->image[i]);
1790  free (array->foil->image);
1791  free (array->foil->fileName);
1792  free (array->foil->actualWavelength);
1793  free (array->foil->actualTransmission);
1794  free (array->foil);
1795 
1796  for (i = 0; i < format->numOfDetectorRegions; i++) free (array->open->image[i]);
1797  free (array->open->image);
1798  free (array->open->fileName);
1799  free (array->open);
1800 
1801  for (i = 0; i < format->numOfDetectorRegions; i++) free (array->dark->image[i]);
1802  free (array->dark->image);
1803  free (array->dark->fileName);
1804  free (array->dark);
1805 
1806  free (array);
1807  array = NULL;
1808 
1809  return;
1810 }
1811 /*****************************************************************************/
1812 
1813