memoryHandling.c

00001 /******************************************************************************
00002 *******************************************************************************
00003 *               European Southern Observatory
00004 *               MIDI Data Reduction Software
00005 *
00006 * File name:    memoryHandling.c
00007 * Description:  Contains the routines for dynamic memory allocation
00008 *               and freeing
00009 *
00010 *
00011 * History:
00012 * 25-Sep-03     (csabet) Created
00013 *******************************************************************************
00014 ******************************************************************************/
00015 
00016 /******************************************************************************
00017 *   Compiler directives
00018 ******************************************************************************/
00019 
00020 /******************************************************************************
00021 *   Include files
00022 ******************************************************************************/
00023 #include <stdio.h>
00024 #include <cpl.h>
00025 #include <string.h>
00026 #include <time.h>
00027 #include <stdlib.h>
00028 #include "midiGlobal.h"
00029 #include "midiLib.h"
00030 #include "memoryHandling.h"
00031 #include "errorHandling.h"
00032 
00033 /******************************************************************************
00034 *   Global Variables
00035 ******************************************************************************/
00036 
00037 /*============================ C O D E    A R E A ===========================*/
00038 
00039 
00040 /******************************************************************************
00041 *               European Southern Observatory
00042 *               MIDI Data Reduction Software
00043 *
00044 * Module name:  callocKappaCoefficients
00045 * Input/Output: See function arguments to avoid duplication
00046 * Description:  Allocates memory for the Kappa Coefficients
00047 *
00048 * History:
00049 * 01-Feb-06     (csabet) Created
00050 ******************************************************************************/
00051 KappaCoefficients *callocKappaCoefficients (
00052     int    numOfChannels)
00053 {
00054     //    Local Declarations
00055     //    ------------------
00056     KappaCoefficients    *array=NULL;
00057 
00058     //    Algorithm
00059     //    ---------
00060     array = (KappaCoefficients *) calloc (1, sizeof (KappaCoefficients));
00061 
00062     array->k11 = (float *) calloc (numOfChannels, sizeof (float));
00063     array->k21 = (float *) calloc (numOfChannels, sizeof (float));
00064     array->k31 = (float *) calloc (numOfChannels, sizeof (float));
00065     array->k22 = (float *) calloc (numOfChannels, sizeof (float));
00066     array->k32 = (float *) calloc (numOfChannels, sizeof (float));
00067     array->k42 = (float *) calloc (numOfChannels, sizeof (float));
00068     array->sig11 = (float *) calloc (numOfChannels, sizeof (float));
00069     array->sig21 = (float *) calloc (numOfChannels, sizeof (float));
00070     array->sig31 = (float *) calloc (numOfChannels, sizeof (float));
00071     array->sig22 = (float *) calloc (numOfChannels, sizeof (float));
00072     array->sig32 = (float *) calloc (numOfChannels, sizeof (float));
00073     array->sig42 = (float *) calloc (numOfChannels, sizeof (float));
00074     
00075     return (array);
00076 }
00077 /*****************************************************************************/
00078 
00079 
00080 
00081 /******************************************************************************
00082 *               European Southern Observatory
00083 *               MIDI Data Reduction Software
00084 *
00085 * Module name:  freeKappaCoefficients
00086 * Input/Output: See function arguments to avoid duplication
00087 * Description:  Releases memory for the Kappa coefficients
00088 *
00089 * History:
00090 * 01-Feb-06     (csabet) Created
00091 ******************************************************************************/
00092 void freeKappaCoefficients (
00093     KappaCoefficients    *array)
00094 {
00095     //    Local Declarations
00096     //--------------------
00097 
00098     //    Algorithm
00099     //    ---------
00100     free (array->k11);
00101     free (array->sig11);
00102     free (array->k21);
00103     free (array->sig21);
00104     free (array->k31);
00105     free (array->sig31);
00106     free (array->k22);
00107     free (array->sig22);
00108     free (array->k32);
00109     free (array->sig32);
00110     free (array->k42);
00111     free (array->sig42);
00112     
00113     free (array);
00114     array = NULL;
00115 
00116     return;
00117 }
00118 /*****************************************************************************/
00119 
00120 
00121 
00122 /******************************************************************************
00123 *               European Southern Observatory
00124 *               MIDI Data Reduction Software
00125 *
00126 * Module name:  callocTransferRatios
00127 * Input/Output: See function arguments to avoid duplication
00128 * Description:  Allocates memory for the Transfer Ratios
00129 *
00130 * History:
00131 * 01-Feb-06     (csabet) Created
00132 ******************************************************************************/
00133 TransferRatios *callocTransferRatios (
00134     int    numOfChannels)
00135 {
00136     //    Local Declarations
00137     //    ------------------
00138     TransferRatios    *array=NULL;
00139 
00140     //    Algorithm
00141     //    ---------
00142     array = (TransferRatios *) calloc (1, sizeof (TransferRatios));
00143 
00144     array->ka1 = (float *) calloc (numOfChannels, sizeof (float));
00145     array->siga1 = (float *) calloc (numOfChannels, sizeof (float));
00146     array->ka2 = (float *) calloc (numOfChannels, sizeof (float));
00147     array->siga2 = (float *) calloc (numOfChannels, sizeof (float));
00148     array->kb1 = (float *) calloc (numOfChannels, sizeof (float));
00149     array->sigb1 = (float *) calloc (numOfChannels, sizeof (float));
00150     array->kb2 = (float *) calloc (numOfChannels, sizeof (float));
00151     array->sigb2 = (float *) calloc (numOfChannels, sizeof (float));
00152     
00153     return (array);
00154 }
00155 /*****************************************************************************/
00156 
00157 
00158 
00159 /******************************************************************************
00160 *               European Southern Observatory
00161 *               MIDI Data Reduction Software
00162 *
00163 * Module name:  freeTransferRatios
00164 * Input/Output: See function arguments to avoid duplication
00165 * Description:  Releases memory for the Transfer Ratios
00166 *
00167 * History:
00168 * 01-Feb-06     (csabet) Created
00169 ******************************************************************************/
00170 void freeTransferRatios (
00171     TransferRatios    *array)
00172 {
00173     //    Local Declarations
00174     //--------------------
00175 
00176     //    Algorithm
00177     //    ---------
00178     free (array->ka1);
00179     free (array->siga1);
00180     free (array->ka2);
00181     free (array->siga2);
00182     free (array->kb1);
00183     free (array->sigb1);
00184     free (array->kb2);
00185     free (array->sigb2);
00186     
00187     free (array);
00188     array = NULL;
00189 
00190     return;
00191 }
00192 /*****************************************************************************/
00193 
00194 
00195 /******************************************************************************
00196 *               European Southern Observatory
00197 *               MIDI Data Reduction Software
00198 *
00199 * Module name:  callocWaveCalibration
00200 * Input/Output: See function arguments to avoid duplication
00201 * Description:  Allocates memory for an array of 2D float
00202 *
00203 * History:
00204 * 08-Feb-05     (csabet) Created
00205 ******************************************************************************/
00206 float **callocWaveCalibration (
00207     int            regions,
00208     ImageFormat    *format)
00209 {
00210     /*  Local Declarations
00211     --------------------*/
00212     float    **array=NULL;
00213     int        i;
00214 
00215     /*  Algorithm
00216     -----------*/
00217     array = (float **) calloc (regions, sizeof (float *));
00218     for (i = 0; i < regions; i++)
00219         array[i] = (float *) calloc (format->iXWidth, sizeof (float));
00220 
00221     return (array);
00222 }
00223 /*****************************************************************************/
00224 
00225 
00226 
00227 /******************************************************************************
00228 *               European Southern Observatory
00229 *               MIDI Data Reduction Software
00230 *
00231 * Module name:  freeWaveCalibration
00232 * Input/Output: See function arguments to avoid duplication
00233 * Description:  Releases memory for a 2D array of float
00234 *
00235 * History:
00236 * 08-Feb-05     (csabet) Created
00237 ******************************************************************************/
00238 void freeWaveCalibration (
00239     int        regions,
00240     float    **array)
00241 {
00242     /*  Local Declarations
00243     --------------------*/
00244     int    i;
00245 
00246     /*  Algorithm
00247     -----------*/
00248     for (i = 0; i < regions; i++)
00249         free (array[i]);
00250     
00251     free (array);
00252     array = NULL;
00253 
00254     return;
00255 }
00256 /*****************************************************************************/
00257 
00258 
00259 
00260 /******************************************************************************
00261 *               European Southern Observatory
00262 *               MIDI Data Reduction Software
00263 *
00264 * Module name:  callocDispResult
00265 * Input/Output: See function arguments to avoid duplication
00266 * Description:  Allocates memory for the dispResult array
00267 *
00268 * History:
00269 * 08-Feb-05     (csabet) Created
00270 ******************************************************************************/
00271 DispersedResult *callocDispResult (
00272     int    numOfChannels)
00273 {
00274     /*  Local Declarations
00275     --------------------*/
00276     DispersedResult    *array=NULL;
00277     int                region;
00278 
00279     /*  Algorithm
00280     -----------*/
00281     array = (DispersedResult *) calloc (1, sizeof (DispersedResult));
00282     
00283     array->photomA = (float **) calloc (2, sizeof (float *));
00284     array->photomB = (float **) calloc (2, sizeof (float *));
00285     array->photomI = (float **) calloc (2, sizeof (float *));
00286     array->photomAErr = (float **) calloc (2, sizeof (float *));
00287     array->photomBErr = (float **) calloc (2, sizeof (float *));
00288     array->photomIErr = (float **) calloc (2, sizeof (float *));
00289 
00290     for (region = 0; region < 2; region++)
00291     {
00292         (array->photomA)[region] = (float *) calloc (numOfChannels, sizeof (float));
00293         (array->photomB)[region] = (float *) calloc (numOfChannels, sizeof (float));
00294         (array->photomI)[region] = (float *) calloc (numOfChannels, sizeof (float));
00295         (array->photomAErr)[region] = (float *) calloc (numOfChannels, sizeof (float));
00296         (array->photomBErr)[region] = (float *) calloc (numOfChannels, sizeof (float));
00297         (array->photomIErr)[region] = (float *) calloc (numOfChannels, sizeof (float));
00298     }
00299 
00300     array->trf = (float *) calloc (numOfChannels, sizeof (float));
00301     array->trfErr = (float *) calloc (numOfChannels, sizeof (float));
00302     array->normVis2 = (float *) calloc (numOfChannels, sizeof (float));
00303     array->normVis2Err = (float *) calloc (numOfChannels, sizeof (float));
00304     array->rawVis2 = (float *) calloc (numOfChannels, sizeof (float));
00305     array->rawVis2Err = (float *) calloc (numOfChannels, sizeof (float));
00306     array->calibVis2 = (float *) calloc (numOfChannels, sizeof (float));
00307     array->calibVis2Err = (float *) calloc (numOfChannels, sizeof (float));
00308     array->photomNet2 = (float *) calloc (numOfChannels, sizeof (float));
00309     array->photomNet2Err = (float *) calloc (numOfChannels, sizeof (float));
00310 
00311     return (array);
00312 }
00313 /*****************************************************************************/
00314 
00315 
00316 
00317 /******************************************************************************
00318 *               European Southern Observatory
00319 *               MIDI Data Reduction Software
00320 *
00321 * Module name:  freeDispResult
00322 * Input/Output: See function arguments to avoid duplication
00323 * Description:  Releases memory for the dispResult array
00324 *
00325 * History:
00326 * 08-Feb-05     (csabet) Created
00327 ******************************************************************************/
00328 void freeDispResult (
00329     DispersedResult    *array)
00330 {
00331     //    Local Declarations
00332     //    ------------------
00333     int    region;
00334     
00335     //    Algorithm
00336     //    ---------
00337     for (region = 0; region < 2; region++)
00338     {
00339         free (array->photomA[region]);
00340         free (array->photomB[region]);
00341         free (array->photomI[region]);
00342         free (array->photomAErr[region]);
00343         free (array->photomBErr[region]);
00344         free (array->photomIErr[region]);
00345     }
00346 
00347 
00348     free (array->trf);
00349     free (array->trfErr);
00350     free (array->normVis2);
00351     free (array->normVis2Err);
00352     free (array->rawVis2);
00353     free (array->rawVis2Err);
00354     free (array->calibVis2);
00355     free (array->calibVis2Err);
00356 
00357     free (array->photomA);
00358     free (array->photomB);
00359     free (array->photomI);
00360     free (array->photomAErr);
00361     free (array->photomBErr);
00362     free (array->photomIErr);
00363     free (array->photomNet2);
00364     free (array->photomNet2Err);
00365     
00366     free (array);
00367     array = NULL;
00368 
00369     return;
00370 }
00371 /*****************************************************************************/
00372 
00373 
00374 
00375 /******************************************************************************
00376 *               European Southern Observatory
00377 *               MIDI Data Reduction Software
00378 *
00379 * Module name:    callocImageFormat
00380 * Input/Output:    See function arguments to avoid duplication
00381 * Description:    Allocates memory for the array image format
00382 *
00383 * History:        
00384 * 29-Mar-04        (csabet) Created
00385 ******************************************************************************/
00386 ImageFormat *callocImageFormat (void)
00387 {
00388     /*    Local Declarations
00389     --------------------*/
00390     ImageFormat *array=NULL;
00391 
00392     /*    Algorithm
00393     -----------*/
00394     array = (ImageFormat *) calloc (1, sizeof(ImageFormat));
00395     array->shutterId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00396     array->grismId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00397     array->slitName = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00398     array->targetName = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00399     array->cameraId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00400     array->filterName = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00401     array->tplStart = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00402     array->beamCombiner = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00403     array->tplName = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00404     array->obsTech = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00405     array->obsCatg = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00406     array->obsType = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00407     
00408     return (array);
00409 }
00410 /*****************************************************************************/
00411 
00412 
00413 /******************************************************************************
00414 *                European Southern Observatory
00415 *                MIDI Data Reduction Software
00416 *
00417 * Module name:    freeImageFormat
00418 * Input/Output:    See function arguments to avoid duplication
00419 * Description:    Releases memory for the array image format
00420 *
00421 * History:        
00422 * 29-Mar-04        (csabet) Created
00423 ******************************************************************************/
00424 void freeImageFormat (
00425     ImageFormat *array)
00426 {
00427     /*    Local Declarations
00428     --------------------*/
00429 
00430     /*    Algorithm
00431     -----------*/
00432     free (array->shutterId);
00433     free (array->grismId);
00434     free (array->slitName);
00435     free (array->targetName);
00436     free (array->tplStart);
00437     free (array->beamCombiner);
00438     free (array->cameraId);
00439     free (array->filterName);
00440     free (array->tplName);
00441     free (array->obsTech);
00442     free (array->obsCatg);
00443     free (array->obsType);
00444     free (array);
00445     array = NULL;
00446     
00447     return;
00448 }
00449 /*****************************************************************************/
00450 
00451 
00452 
00453 /******************************************************************************
00454 *                European Southern Observatory
00455 *                MIDI Data Reduction Software
00456 *
00457 * Module name:  callocFilterInfo
00458 * Input/Output: See function arguments to avoid duplication
00459 * Description:  Allocates memory for the filterInfo array
00460 *
00461 * History:
00462 * 29-Mar-04     (csabet) Created
00463 ******************************************************************************/
00464 FilterData *callocFilterInfo (void)
00465 {
00466     /*  Local Declarations
00467     --------------------*/
00468     FilterData *array=NULL;
00469 
00470     /*  Algorithm
00471     -----------*/
00472     array = (FilterData *) calloc (1, sizeof(FilterData));
00473     array->filterName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00474 
00475     return (array);
00476 }
00477 /*****************************************************************************/
00478 
00479 
00480 /******************************************************************************
00481 *               European Southern Observatory
00482 *               MIDI Data Reduction Software
00483 *
00484 * Module name:  freeFilterInfo
00485 * Input/Output: See function arguments to avoid duplication
00486 * Description:  Releases memory for the filterInfo array
00487 *
00488 * History:
00489 * 29-Mar-04     (csabet) Created
00490 ******************************************************************************/
00491 void freeFilterInfo (
00492     FilterData *array)
00493 {
00494     /*  Local Declarations
00495     --------------------*/
00496 
00497     /*  Algorithm
00498     -----------*/
00499     free (array->filterName);
00500     free (array);
00501     array = NULL;
00502 
00503     return;
00504 }
00505 /*****************************************************************************/
00506 
00507 
00508 /******************************************************************************
00509 *               European Southern Observatory
00510 *               MIDI Data Reduction Software
00511 *
00512 * Module name:  callocCalibVis
00513 * Input/Output: See function arguments to avoid duplication
00514 * Description:  Allocates memory for the trf array
00515 *
00516 * History:
00517 * 29-Mar-04     (csabet) Created
00518 ******************************************************************************/
00519 CalibratedVisibility *callocCalibVis (void)
00520 {
00521     /*  Local Declarations
00522     --------------------*/
00523     CalibratedVisibility *array=NULL;
00524 
00525     /*  Algorithm
00526     -----------*/
00527     array = (CalibratedVisibility *) calloc (1, sizeof (CalibratedVisibility));
00528     array->vis = (float *) calloc (REGIONS_UNDISPERSED, sizeof (float));
00529     array->visErr = (float *) calloc (REGIONS_UNDISPERSED, sizeof (float));
00530     array->visSqrd = (float *) calloc (REGIONS_UNDISPERSED, sizeof (float));
00531     array->visSqrdErr = (float *) calloc (REGIONS_UNDISPERSED, sizeof (float));
00532 
00533 
00534     return (array);
00535 }
00536 /*****************************************************************************/
00537 
00538 
00539 /******************************************************************************
00540 *               European Southern Observatory
00541 *               MIDI Data Reduction Software
00542 *
00543 * Module name:  freeCalibVis
00544 * Input/Output: See function arguments to avoid duplication
00545 * Description:  Releases memory for the calibratedVis array
00546 *
00547 * History:
00548 * 29-Mar-04     (csabet) Created
00549 ******************************************************************************/
00550 void freeCalibVis (
00551     CalibratedVisibility *array)
00552 {
00553     /*  Local Declarations
00554     --------------------*/
00555 
00556     /*  Algorithm
00557     -----------*/
00558     free (array->vis);
00559     free (array->visErr);
00560     free (array->visSqrd);
00561     free (array->visSqrdErr);
00562     free (array);
00563     array = NULL;
00564 
00565     return;
00566 }
00567 /*****************************************************************************/
00568 
00569 
00570 
00571 /******************************************************************************
00572 *               European Southern Observatory
00573 *               MIDI Data Reduction Software
00574 *
00575 * Module name:  callocTrFunction
00576 * Input/Output: See function arguments to avoid duplication
00577 * Description:  Allocates memory for the trf array
00578 *
00579 * History:
00580 * 29-Mar-04     (csabet) Created
00581 ******************************************************************************/
00582 TransferFunction *callocTrFunction (
00583     int    size)
00584 {
00585     /*  Local Declarations
00586     --------------------*/
00587     TransferFunction *array=NULL;
00588 
00589     /*  Algorithm
00590     -----------*/
00591     array = (TransferFunction *) calloc (1, sizeof (TransferFunction));
00592     array->trf = (float *) calloc (size , sizeof (float));
00593     array->trfErr = (float *) calloc (size , sizeof (float));
00594 
00595     return (array);
00596 }
00597 /*****************************************************************************/
00598 
00599 
00600 /******************************************************************************
00601 *               European Southern Observatory
00602 *               MIDI Data Reduction Software
00603 *
00604 * Module name:  freeTrFunction
00605 * Input/Output: See function arguments to avoid duplication
00606 * Description:  Releases memory for the trf array
00607 *
00608 * History:
00609 * 29-Mar-04     (csabet) Created
00610 ******************************************************************************/
00611 void freeTrFunction (
00612     TransferFunction *array)
00613 {
00614     /*  Local Declarations
00615     --------------------*/
00616 
00617     /*  Algorithm
00618     -----------*/
00619     free (array->trfErr);
00620     free (array->trf);
00621     free (array);
00622     array = NULL;
00623 
00624     return;
00625 }
00626 /*****************************************************************************/
00627 
00628 
00629 /******************************************************************************
00630 *               European Southern Observatory
00631 *               MIDI Data Reduction Software
00632 *
00633 * Module name:  callocCalibrator
00634 * Input/Output: See function arguments to avoid duplication
00635 * Description:  Allocates memory for the Calibrator array
00636 *
00637 * History:
00638 * 29-Mar-04     (csabet) Created
00639 ******************************************************************************/
00640 CalibratorParam *callocCalibrator (void)
00641 {
00642     /*  Local Declarations
00643     --------------------*/
00644     CalibratorParam *array=NULL;
00645 
00646     /*  Algorithm
00647     -----------*/
00648     array = (CalibratorParam *) calloc (1, sizeof (CalibratorParam));
00649     array->calibName = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00650 
00651     return (array);
00652 }
00653 /*****************************************************************************/
00654 
00655 
00656 /******************************************************************************
00657 *               European Southern Observatory
00658 *               MIDI Data Reduction Software
00659 *
00660 * Module name:  freeCalibrator
00661 * Input/Output: See function arguments to avoid duplication
00662 * Description:  Releases memory for the calibrator array
00663 *
00664 * History:
00665 * 29-Mar-04     (csabet) Created
00666 ******************************************************************************/
00667 void freeCalibrator (
00668     CalibratorParam *array)
00669 {
00670     /*  Local Declarations
00671     --------------------*/
00672 
00673     /*  Algorithm
00674     -----------*/
00675     free (array->calibName);
00676     free (array);
00677     array = NULL;
00678 
00679     return;
00680 }
00681 /*****************************************************************************/
00682 
00683 
00684 /******************************************************************************
00685 *               European Southern Observatory
00686 *               MIDI Data Reduction Software
00687 *
00688 * Module name:  callocIauExchange
00689 * Input/Output: See function arguments to avoid duplication
00690 * Description:  Allocates memory for the IAU data structure
00691 *
00692 * History:
00693 * 09-Feb-05     (csabet) Created
00694 ******************************************************************************/
00695 IauExchange *callocIauExchange (
00696     int numOfTelescopes,
00697     int    numOfChannels)
00698 {
00699     //    Local Declarations
00700     //    ------------------
00701     IauExchange *iauArray=NULL;
00702     int         i;
00703 
00704     //    Algorithm
00705     //    ---------
00706     iauArray = (IauExchange *) calloc (1, sizeof (IauExchange));
00707 
00708     //    OI_ARRAY
00709     iauArray->array = (OiArray *) calloc (1, sizeof (OiArray));
00710     iauArray->array->revision = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00711     iauArray->array->arrname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00712     iauArray->array->frame = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00713     iauArray->array->nelement = numOfTelescopes;
00714     iauArray->array->elem = (Element *) calloc (iauArray->array->nelement, sizeof(Element));
00715     for (i = 0; i < iauArray->array->nelement; i++)
00716     {
00717         iauArray->array->elem[i].tel_name = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00718         iauArray->array->elem[i].sta_name = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00719         iauArray->array->elem[i].staxyz = (double *) calloc (3, sizeof (double));
00720         
00721     }
00722     
00723     //    OI_TARGET
00724     iauArray->targets = (OiTarget *) calloc (1, sizeof (OiTarget));
00725     iauArray->targets->revision = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00726     iauArray->targets->ntarget = 1;
00727     iauArray->targets->targ = (Target *) calloc (iauArray->targets->ntarget, sizeof(Target));
00728     iauArray->targets->targ->spectyp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00729     iauArray->targets->targ->veldef = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00730     iauArray->targets->targ->veltyp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00731     iauArray->targets->targ->target = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00732 
00733     //    OI_WAVELENGTH
00734     iauArray->wavelength = (OiWavelength *) calloc (1, sizeof (OiWavelength));
00735     iauArray->wavelength->revision = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00736     iauArray->wavelength->insname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00737     iauArray->wavelength->nwave = numOfChannels;
00738     iauArray->wavelength->eff_wave = (float *) calloc (iauArray->wavelength->nwave, sizeof(float));
00739     iauArray->wavelength->eff_band = (float *) calloc (iauArray->wavelength->nwave, sizeof(float));
00740 
00741     //    OI_VIS
00742     iauArray->vis = (OiVis *) calloc (1, sizeof (OiVis));
00743     iauArray->vis->revision = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00744     iauArray->vis->date_obs = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00745     iauArray->vis->arrname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00746     iauArray->vis->insname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00747     iauArray->vis->numrec = 1;
00748     iauArray->vis->record = (OiVisRecord *) calloc (iauArray->vis->numrec, sizeof(OiVisRecord));
00749     for (i = 0; i < iauArray->vis->numrec; i++)
00750     {
00751         iauArray->vis->record[i].sta_index = (int *) calloc (2, sizeof(int));
00752         iauArray->vis->record[i].visamp = (double *) calloc (iauArray->wavelength->nwave, sizeof(double));
00753         iauArray->vis->record[i].visamperr = (double *) calloc (iauArray->wavelength->nwave, sizeof(double));
00754         iauArray->vis->record[i].visphi = (double *) calloc (iauArray->wavelength->nwave, sizeof(double));
00755         iauArray->vis->record[i].visphierr = (double *) calloc (iauArray->wavelength->nwave, sizeof(double));
00756         iauArray->vis->record[i].flag = (char *) calloc (MIN_STRING_LENGTH, sizeof(char));
00757     }
00758 
00759     //    OI_VIS2
00760     iauArray->vis2 = (OiVis2 *) calloc (1, sizeof (OiVis2));
00761     iauArray->vis2->revision = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00762     iauArray->vis2->date_obs = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00763     iauArray->vis2->arrname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00764     iauArray->vis2->insname = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00765     iauArray->vis2->numrec = 1;
00766     iauArray->vis2->record = (OiVis2Record *) calloc (iauArray->vis2->numrec, sizeof (OiVis2Record));
00767     for(i = 0; i < iauArray->vis2->numrec; i++)
00768     {
00769         iauArray->vis2->record[i].vis2data = (double *) calloc (iauArray->wavelength->nwave, sizeof (double));
00770         iauArray->vis2->record[i].vis2err = (double *) calloc (iauArray->wavelength->nwave, sizeof (double));
00771         iauArray->vis2->record[i].flag = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00772         iauArray->vis2->record[i].sta_index = (int *) calloc (2, sizeof (int));
00773     }
00774 
00775     return (iauArray);
00776 }
00777 /*****************************************************************************/
00778 
00779 
00780 /******************************************************************************
00781 *               European Southern Observatory
00782 *               MIDI Data Reduction Software
00783 *
00784 * Module name:  freeIauExchange
00785 * Input/Output: See function arguments to avoid duplication
00786 * Description:  Releases memory for the IAU data structure
00787 *
00788 * History:
00789 * 23-Feb-04     (csabet) Created
00790 ******************************************************************************/
00791 void freeIauExchange (
00792     IauExchange *iauArray)
00793 {
00794     //    Local Declarations
00795     //    ------------------
00796     int i;
00797 
00798     //    Algorithm
00799     //    ---------
00800 
00801     //    Release OI_ARRAY
00802     free (iauArray->array->frame);
00803     free (iauArray->array->arrname);
00804     free (iauArray->array->revision);
00805     for (i = 0; i < iauArray->array->nelement; i++)
00806     {
00807         free (iauArray->array->elem[i].tel_name);
00808         free (iauArray->array->elem[i].sta_name);
00809         free (iauArray->array->elem[i].staxyz);
00810     }
00811     free (iauArray->array->elem);
00812     free (iauArray->array);
00813 
00814     //    Release OI_TARGET
00815     free (iauArray->targets->revision);
00816     free (iauArray->targets->targ->spectyp);
00817     free (iauArray->targets->targ->veldef);
00818     free (iauArray->targets->targ->veltyp);
00819     free (iauArray->targets->targ->target);
00820     free (iauArray->targets->targ);
00821     free (iauArray->targets);
00822     
00823     //    Release OI_WAVELENGTH
00824     free (iauArray->wavelength->eff_wave);
00825     free (iauArray->wavelength->eff_band);
00826     free (iauArray->wavelength->revision);
00827     free (iauArray->wavelength->insname);
00828     free (iauArray->wavelength);
00829 
00830     //    Release OI_VIS
00831     free (iauArray->vis->revision);
00832     free (iauArray->vis->date_obs);
00833     free (iauArray->vis->arrname);
00834     free (iauArray->vis->insname);
00835     for (i = 0; i < iauArray->vis->numrec; i++)
00836     {
00837         free (iauArray->vis->record[i].visamp);
00838         free (iauArray->vis->record[i].visamperr);
00839         free (iauArray->vis->record[i].visphi);
00840         free (iauArray->vis->record[i].visphierr);
00841         free (iauArray->vis->record[i].sta_index);
00842         free (iauArray->vis->record[i].flag);
00843     }
00844     free (iauArray->vis->record);
00845     free (iauArray->vis);
00846 
00847     //    Release OI_VIS2
00848     free (iauArray->vis2->revision);
00849     free (iauArray->vis2->date_obs);
00850     free (iauArray->vis2->arrname);
00851     free (iauArray->vis2->insname);
00852     for(i = 0; i < iauArray->vis2->numrec; i++)
00853     {
00854         free (iauArray->vis2->record[i].vis2data);
00855         free (iauArray->vis2->record[i].vis2err);;
00856         free (iauArray->vis2->record[i].sta_index);
00857         free (iauArray->vis2->record[i].flag);
00858     }
00859     free (iauArray->vis2->record);
00860     free (iauArray->vis2);
00861 
00862     free (iauArray);
00863     iauArray = NULL;
00864 
00865     return;
00866 }
00867 /*****************************************************************************/
00868 
00869 
00870 
00871 /******************************************************************************
00872 *               European Southern Observatory
00873 *               MIDI Data Reduction Software
00874 *
00875 * Module name:  callocPhotometry
00876 * Input/Output: See function arguments to avoid duplication
00877 * Description:  Allocates memory for the photometry result
00878 *
00879 * History:
00880 * 16-Jan-04     (csabet) Created
00881 ******************************************************************************/
00882 PhotometryResult *callocPhotometry (void)
00883 {
00884     /*  Local Declarations
00885     --------------------*/
00886     PhotometryResult *array=NULL;
00887 
00888     /*  Algorithm
00889     -----------*/
00890     array = (PhotometryResult *) calloc (1, sizeof (PhotometryResult));
00891 
00892     array->photomA = (float *) calloc (2, sizeof (float));
00893     array->photomAErr = (float *) calloc (2, sizeof (float));
00894 
00895     array->photomB = (float *) calloc (2, sizeof (float));
00896     array->photomBErr = (float *) calloc (2, sizeof (float));
00897 
00898     array->chop2ChopAErr = (float *) calloc (2, sizeof (float));
00899     array->chop2ChopBErr = (float *) calloc (2, sizeof (float));
00900 
00901     return (array);
00902 }
00903 /*****************************************************************************/
00904 
00905 
00906 /******************************************************************************
00907 *               European Southern Observatory
00908 *               MIDI Data Reduction Software
00909 *
00910 * Module name:  freePhotometry
00911 * Input/Output: See function arguments to avoid duplication
00912 * Description:  Releases memory for the photometry result
00913 *
00914 * History:
00915 * 16-Jan-04     (csabet) Created
00916 ******************************************************************************/
00917 void freePhotometry (
00918     PhotometryResult *array)
00919 {
00920     /*  Local Declarations
00921     --------------------*/
00922 
00923     /*  Algorithm
00924     -----------*/
00925     free (array->photomA);
00926     free (array->photomAErr);
00927 
00928     free (array->photomB);
00929     free (array->photomBErr);
00930 
00931     free (array->chop2ChopAErr);
00932     free (array->chop2ChopBErr);
00933 
00934     free (array);
00935     array = NULL;
00936 
00937     return;
00938 }
00939 /*****************************************************************************/
00940 
00941 
00942 /******************************************************************************
00943 *               European Southern Observatory
00944 *               MIDI Data Reduction Software
00945 *
00946 * Module name:  callocRawVis
00947 * Input/Output: See function arguments to avoid duplication
00948 * Description:  Allocates memory for the interferometry result
00949 *
00950 * History:
00951 * 15-Jan-04     (csabet) Created
00952 ******************************************************************************/
00953 RawVisibility *callocRawVis (void)
00954 {
00955     /*  Local Declarations
00956     --------------------*/
00957     RawVisibility *array=NULL;
00958 
00959     /*  Algorithm
00960     -----------*/
00961     array = (RawVisibility *) calloc (1, sizeof (RawVisibility));
00962 
00963     return (array);
00964 }
00965 /*****************************************************************************/
00966 
00967 
00968 
00969 /******************************************************************************
00970 *               European Southern Observatory
00971 *               MIDI Data Reduction Software
00972 *
00973 * Module name:  freeRawVis
00974 * Input/Output: See function arguments to avoid duplication
00975 * Description:  Releases memory for the interferometry result data
00976 *
00977 * History:
00978 * 15-Jan-04     (csabet) Created
00979 ******************************************************************************/
00980 void freeRawVis (
00981     RawVisibility *array)
00982 {
00983     /*  Local Declarations
00984     --------------------*/
00985 
00986     /*  Algorithm
00987     -----------*/
00988     free (array);
00989     array = NULL;
00990 
00991     return;
00992 }
00993 /*****************************************************************************/
00994 
00995 
00996 
00997 /******************************************************************************
00998 *               European Southern Observatory
00999 *               MIDI Data Reduction Software
01000 *
01001 * Module name:  callocMidiCompressed
01002 * Input/Output: See function arguments to avoid duplication
01003 * Description:  Allocates memory for the compressed data
01004 *
01005 * History:
01006 * 05-Nov-03     (csabet) Created
01007 ******************************************************************************/
01008 CompressedData *callocMidiCompressed (
01009     ImageFormat            *format)
01010 {
01011     //    Local Declarations
01012     //    ------------------
01013     CompressedData    *array=NULL;
01014     int                i, X;
01015 
01016     //    Algorithm
01017     //    ---------
01018     array = (CompressedData *) calloc (1, sizeof (CompressedData));
01019 
01020     array->iDispFringe = (float ***) calloc (format->numOfRegionsToProcess, sizeof(float **));
01021     for (i = 0; i < format->numOfRegionsToProcess; i++)
01022     {
01023         (array->iDispFringe)[i] = (float **) calloc (format->iXWidth, sizeof(float *));
01024         for (X = 0; X < format->iXWidth; X++)
01025             (array->iDispFringe)[i][X] = (float *) calloc (format->numOfFrames, sizeof(float));
01026     }
01027 
01028     array->rejectList = (int **) calloc (format->iXWidth, sizeof (int *));
01029     for (i = 0; i < format->iXWidth; i++)
01030         array->rejectList[i] = (int *) calloc (format->numOfFrames, sizeof (int));
01031 
01032     array->badScanList = (int *) calloc (format->numOfScans, sizeof (int));
01033     
01034     array->image = (float **) calloc (format->numOfRegionsToProcess, sizeof(float *));
01035     for (i = 0; i < format->numOfRegionsToProcess; i++)
01036         array->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
01037 
01038     array->iFringe1 = (double *) calloc (format->numOfFrames, sizeof(double));
01039     array->iFringe2 = (double *) calloc (format->numOfFrames, sizeof(double));
01040     array->iFringe = (double *) calloc (format->numOfFrames, sizeof(double));
01041     array->allSpectrum = (float *) calloc (format->allSpectrumLength, sizeof(float));
01042     array->dcLevels = (float *) calloc (REGIONS_UNDISPERSED * format->numOfScans, sizeof (float));
01043     array->tarType = (char *) calloc(format->numOfFrames, sizeof(char));
01044     array->time = (float *) calloc(format->numOfFrames, sizeof(float));
01045     array->localOPD = (float *) calloc(format->numOfFrames, sizeof(float));
01046     array->bigDL = (float *) calloc(format->numOfFrames, sizeof(float));
01047 
01048     return (array);
01049 }
01050 /*****************************************************************************/
01051 
01052 
01053  
01054 /******************************************************************************
01055 *               European Southern Observatory
01056 *               MIDI Data Reduction Software
01057 *
01058 * Module name:  freeCompressedData
01059 * Input/Output: See function arguments to avoid duplication
01060 * Description:  Releases all the memory related to the
01061 *               compressed data
01062 *
01063 * History:
01064 * 05-Nov-03     (csabet) Created
01065 ******************************************************************************/
01066 void freeCompressedData (
01067     ImageFormat            *format,
01068     CompressedData        *array)
01069 {
01070     //    Local Declarations
01071     //    ------------------
01072     int i, j;
01073  
01074     //    Algorithm
01075     //    ---------
01076     for (i = 0; i < format->numOfRegionsToProcess; i++)
01077     {
01078         for (j = 0; j < format->iXWidth; j++)
01079             free ((array->iDispFringe)[i][j]);
01080            
01081         free ((array->iDispFringe)[i]);
01082     }
01083     free (array->iDispFringe);
01084 
01085     for (i = 0; i < format->numOfRegionsToProcess; i++)
01086     {
01087         free (array->image[i]);
01088     }
01089     free (array->image);
01090 
01091     for (i = 0; i < format->iXWidth; i++)
01092         free (array->rejectList[i]);
01093     free (array->rejectList);
01094 
01095     free (array->badScanList);
01096     free (array->iFringe1);
01097     free (array->iFringe2);
01098     free (array->iFringe);
01099     free (array->allSpectrum);
01100     free (array->dcLevels);
01101     free (array->tarType);
01102     free (array->time);
01103     free (array->localOPD);
01104     free (array->bigDL);
01105  
01106     free (array);
01107     array = NULL;
01108     
01109     return;
01110 }
01111 /*****************************************************************************/
01112 
01113 
01114 
01115 
01116 /******************************************************************************
01117 *               European Southern Observatory
01118 *               MIDI Data Reduction Software
01119 *
01120 * Module name:  callocMidiFiles
01121 * Input/Output: See function arguments to avoid duplication
01122 * Description:  Allocates memory for the MIDI file Structure
01123 *
01124 * History:
01125 * 05-Nov-03     (csabet) Created
01126 ******************************************************************************/
01127 MidiFiles *callocMidiFiles (
01128     int stringLength)
01129 {
01130     /*  Local Declarations
01131     --------------------*/
01132     MidiFiles   *fileNames=NULL;
01133 
01134     /*  Algorithm
01135     -----------*/
01136     fileNames = (MidiFiles *)  calloc (1, sizeof (MidiFiles));
01137     fileNames->inFitsList = (char *) calloc (stringLength, sizeof (char));
01138     fileNames->inFitsClassified = (char *) calloc (stringLength, sizeof (char));
01139     fileNames->inFitsBatch = (char *) calloc (stringLength, sizeof (char));
01140     fileNames->inFileDir = (char *) calloc (stringLength, sizeof (char));
01141     fileNames->maskFileDir = (char *) calloc (stringLength, sizeof (char));
01142     fileNames->maskFileName = (char *) calloc (stringLength, sizeof (char));
01143     fileNames->inFitsName = (char *) calloc (stringLength, sizeof (char));
01144     fileNames->outFitsName = (char *) calloc (stringLength, sizeof (char));
01145     fileNames->outWaterfallName = (char *) calloc (stringLength, sizeof (char));
01146     fileNames->outWaterpowerName = (char *) calloc (stringLength, sizeof (char));
01147     fileNames->outAveImageName = (char *) calloc (stringLength, sizeof (char));
01148     fileNames->outChSpectrumName = (char *) calloc (stringLength, sizeof (char));
01149     fileNames->calibDbName = (char *) calloc (stringLength, sizeof (char));
01150     fileNames->grismFoilName = (char *) calloc (stringLength, sizeof (char));
01151     fileNames->prismFoilName = (char *) calloc (stringLength, sizeof (char));
01152     fileNames->calibDbDir = (char *) calloc (stringLength, sizeof (char));
01153     fileNames->trfNameRead = (char *) calloc (stringLength, sizeof (char));
01154     fileNames->trfNameWrite = (char *) calloc (stringLength, sizeof (char));
01155     fileNames->trfHistoryName = (char *) calloc (stringLength, sizeof (char));
01156     fileNames->trrNameRead = (char *) calloc (stringLength, sizeof (char));
01157     fileNames->trrNameWrite = (char *) calloc (stringLength, sizeof (char));
01158     fileNames->trrHistoryName = (char *) calloc (stringLength, sizeof (char));
01159     fileNames->wclNameRead = (char *) calloc (stringLength, sizeof (char));
01160     fileNames->wclNameWrite = (char *) calloc (stringLength, sizeof (char));
01161     fileNames->transferRatiosName = (char *) calloc (stringLength, sizeof (char));
01162     fileNames->wclHistoryName = (char *) calloc (stringLength, sizeof (char));
01163     fileNames->archFileName = (char *) calloc (stringLength, sizeof (char));
01164     fileNames->pipeFileName = (char *) calloc (stringLength, sizeof (char));
01165     fileNames->waveCalibName = (char *) calloc (stringLength, sizeof (char));
01166 
01167     return (fileNames);
01168 }
01169 /*****************************************************************************/
01170 
01171 
01172 
01173 /******************************************************************************
01174 *               European Southern Observatory
01175 *               MIDI Data Reduction Software
01176 *
01177 * Module name:  freeMidiFiles
01178 * Input/Output: See function arguments to avoid duplication
01179 * Description:  Releases all MIDI file structures
01180 *
01181 * History:
01182 * 05-Nov-03     (csabet) Created
01183 ******************************************************************************/
01184 void freeMidiFiles (
01185     MidiFiles   *fileNames)
01186 {
01187     /*  Local Declarations
01188     --------------------*/
01189 
01190     /*  Algorithm
01191     -----------*/
01192     free (fileNames->inFitsList);
01193     free (fileNames->inFitsClassified);
01194     free (fileNames->inFitsBatch);
01195     free (fileNames->inFileDir);
01196     free (fileNames->maskFileDir);
01197     free (fileNames->maskFileName);
01198     free (fileNames->inFitsName);
01199     free (fileNames->outFitsName);
01200     free (fileNames->outWaterfallName);
01201     free (fileNames->outWaterpowerName);
01202     free (fileNames->outAveImageName);
01203     free (fileNames->outChSpectrumName);
01204     free (fileNames->calibDbName);
01205     free (fileNames->grismFoilName);
01206     free (fileNames->prismFoilName);
01207     free (fileNames->calibDbDir);
01208     free (fileNames->trfNameRead);
01209     free (fileNames->trfNameWrite);
01210     free (fileNames->trfHistoryName);
01211     free (fileNames->trrNameRead);
01212     free (fileNames->trrNameWrite);
01213     free (fileNames->trrHistoryName);
01214     free (fileNames->wclNameRead);
01215     free (fileNames->wclNameWrite);
01216     free (fileNames->wclHistoryName);
01217     free (fileNames->archFileName);
01218     free (fileNames->transferRatiosName);
01219     free (fileNames->pipeFileName);
01220     free (fileNames->waveCalibName);
01221     free (fileNames);
01222     fileNames = NULL;
01223 
01224     return;
01225 }
01226 /*****************************************************************************/
01227 
01228 /******************************************************************************
01229 *                European Southern Observatory
01230 *                MIDI Data Reduction Software
01231 *
01232 * Module name:    callocDspTrn
01233 * Input/Output:    See function arguments to avoid duplication
01234 * Description:    Allocates memory for the Dispersive Transmission data structure
01235 *
01236 * History:        
01237 * 26-Aug-04        (csabet) Created
01238 ******************************************************************************/
01239 DispersiveTrans *callocDspTrn (
01240     int            numOfFiles)
01241 {
01242     /*    Local Declarations
01243     --------------------*/
01244     DispersiveTrans    *array=NULL;
01245     int                i;
01246 
01247     /*    Algorithm
01248     -----------*/
01249     array = (DispersiveTrans *) calloc (1, sizeof (DispersiveTrans));
01250     array->numOfFiles = numOfFiles;
01251     array->target = (MidiCoords *) calloc (numOfFiles, sizeof (MidiCoords));
01252     
01253     array->integTime = (float *) calloc (numOfFiles, sizeof (float));
01254     array->integFlux = (float *) calloc (numOfFiles, sizeof (float));
01255     array->meanFlux = (float *) calloc (numOfFiles, sizeof (float));
01256     array->transmission = (float *) calloc (numOfFiles/2, sizeof (float));
01257 
01258     array->beamCombiner = (char **) calloc (numOfFiles, sizeof (char *));
01259     array->shutterId = (char **) calloc (numOfFiles, sizeof (char *));
01260     array->cameraId = (char **) calloc (numOfFiles, sizeof (char *));
01261     array->grismId = (char **) calloc (numOfFiles, sizeof (char *));
01262     array->filterName = (char **) calloc (numOfFiles, sizeof (char *));
01263     for (i = 0; i < array->numOfFiles; i++)
01264     {
01265         array->beamCombiner[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01266         array->shutterId[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01267         array->cameraId[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01268         array->grismId[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01269         array->filterName[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01270     }
01271 
01272     return (array);
01273 }
01274 /*****************************************************************************/
01275 
01276 
01277 
01278 /******************************************************************************
01279 *                European Southern Observatory
01280 *                MIDI Data Reduction Software
01281 *
01282 * Module name:    freeDspTrn
01283 * Input/Output:    See function arguments to avoid duplication
01284 * Description:    Releases all the memory related to the dspTrn data structure
01285 *
01286 * History:        
01287 * 26-Aug-04        (csabet) Created
01288 ******************************************************************************/
01289 void freeDspTrn (
01290     DispersiveTrans    *array)
01291 {
01292     /*    Local Declarations
01293     --------------------*/
01294     int    i;
01295     
01296     /*    Algorithm
01297     -----------*/
01298     free (array->integTime);
01299     free (array->integFlux);
01300     free (array->meanFlux);
01301     free (array->transmission);
01302     free (array->target);
01303     for (i = 0; i < array->numOfFiles; i++)
01304     {
01305         free (array->beamCombiner[i]);
01306         free (array->shutterId[i]);
01307         free (array->cameraId[i]);
01308         free (array->grismId[i]);
01309         free (array->filterName[i]);
01310     }
01311     free (array->beamCombiner);
01312     free (array->shutterId);
01313     free (array->cameraId);
01314     free (array->grismId);
01315     free (array->filterName);
01316 
01317     free (array);
01318     array = NULL;
01319    
01320     return;
01321 }
01322 /*****************************************************************************/
01323 
01324 
01325 
01326 /******************************************************************************
01327 *                European Southern Observatory
01328 *                MIDI Data Reduction Software
01329 *
01330 * Module name:    callocRefPix
01331 * Input/Output:    See function arguments to avoid duplication
01332 * Description:    Allocates memory for the Reference Pixel alignment data structure
01333 *
01334 * History:        
01335 * 11-Aug-04        (csabet) Created
01336 * 28-Aug-06        (csabet) Modified
01337 ******************************************************************************/
01338 ReferencePixel *callocRefPix (
01339     int            numOfFiles,
01340     int            numOfBeams)
01341 {
01342     //    Local Declarations
01343     //    ------------------
01344     ReferencePixel    *array=NULL;
01345     int             i;
01346     
01347     //    Algorithm
01348     //    ---------
01349     array = (ReferencePixel *) calloc (1, sizeof (ReferencePixel));
01350     array->numOfExposures = numOfFiles;
01351     array->exposure = (RefPixExposure *) calloc (array->numOfExposures, sizeof (RefPixExposure));
01352     
01353     for (i = 0; i < array->numOfExposures; i++)
01354     {
01355         array->exposure[i].shutterId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01356         array->exposure[i].beamCombiner = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01357         array->exposure[i].numOfBeams = numOfBeams;
01358         array->exposure[i].centroid = (MidiCoords *) calloc (array->exposure[i].numOfBeams, sizeof (MidiCoords));
01359     }
01360         
01361     return (array);
01362 }
01363 /*****************************************************************************/
01364 
01365 
01366 
01367 /******************************************************************************
01368 *                European Southern Observatory
01369 *                MIDI Data Reduction Software
01370 *
01371 * Module name:    freeRefPix
01372 * Input/Output:    See function arguments to avoid duplication
01373 * Description:    Releases all the memory related to the refPix data structure
01374 *
01375 * History:        
01376 * 11-Aug-04        (csabet) Created
01377 * 28-Aug-06        (csabet) Modified
01378 ******************************************************************************/
01379 void freeRefPix (
01380     ReferencePixel    *array)
01381 {
01382     //    Local Declarations
01383     //    ------------------
01384     int    i;
01385     
01386     //    Algorithm
01387     //    ---------
01388     for (i = 0; i < array->numOfExposures; i++)
01389     {
01390         free (array->exposure[i].beamCombiner);
01391         free (array->exposure[i].shutterId);
01392         free (array->exposure[i].centroid);
01393     }
01394     free (array->exposure);
01395     free (array);
01396     array = NULL;
01397        
01398     return;
01399 }
01400 /*****************************************************************************/
01401 
01402 
01403 
01404 /******************************************************************************
01405 *                European Southern Observatory
01406 *                MIDI Data Reduction Software
01407 *
01408 * Module name:    callocDetLin
01409 * Input/Output:    See function arguments to avoid duplication
01410 * Description:    Allocates memory for the detector linearity data structure
01411 *
01412 * History:        
01413 * 06-Aug-04        (csabet) Created
01414 ******************************************************************************/
01415 DetLinearity *callocDetLin (
01416     int            numOfFiles,
01417     ImageFormat    *format)
01418 {
01419     /*    Local Declarations
01420     --------------------*/
01421     DetLinearity    *array=NULL;
01422     int                i;
01423 
01424     /*    Algorithm
01425     -----------*/
01426     array = (DetLinearity *) calloc (1, sizeof (DetLinearity));
01427     array->size = numOfFiles;
01428 
01429     array->mean = (float *) calloc (array->size, sizeof(float));
01430     array->grismId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01431     array->saturated = (int *) calloc (array->size, sizeof (int));
01432     array->integTime = (float *) calloc (array->size, sizeof(float));
01433     array->deviation = (float *) calloc (format->iXWidth * format->iYWidth, sizeof (float));
01434     array->aveImage = (float **) calloc (array->size, sizeof (float *));
01435     for (i = 0; i < array->size; i++)
01436         array->aveImage[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof (float));
01437 
01438     return (array);
01439 }
01440 /*****************************************************************************/
01441 
01442 
01443 
01444 /******************************************************************************
01445 *                European Southern Observatory
01446 *                MIDI Data Reduction Software
01447 *
01448 * Module name:    freeDetLin
01449 * Input/Output:    See function arguments to avoid duplication
01450 * Description:    Releases all the memory related to the DetLinearity data structure
01451 *
01452 * History:        
01453 * 06-Aug-04        (csabet) Created
01454 ******************************************************************************/
01455 void freeDetLin (
01456     DetLinearity    *array)
01457 {
01458     /*    Local Declarations
01459     --------------------*/
01460     int    i;
01461 
01462     /*    Algorithm
01463     -----------*/
01464     free (array->grismId);
01465     free (array->saturated);
01466     free (array->integTime);
01467     free (array->mean);
01468     free (array->deviation);
01469 
01470     for (i = 0; i < array->size; i++)
01471         free (array->aveImage[i]);
01472     free (array->aveImage);
01473 
01474     free (array);
01475     array = NULL;
01476        
01477     return;
01478 }
01479 /*****************************************************************************/
01480 
01481 
01482 
01483 /******************************************************************************
01484 *                European Southern Observatory
01485 *                MIDI Data Reduction Software
01486 *
01487 * Module name:    callocDetRon
01488 * Input/Output:    See function arguments to avoid duplication
01489 * Description:    Allocates memory for the noise pattern data structure
01490 *
01491 * History:        
01492 * 04-Aug-04        (csabet) Created
01493 ******************************************************************************/
01494 DetRonNoise *callocDetRon (
01495     ImageFormat    *imageSize)
01496 {
01497     /*    Local Declarations
01498     --------------------*/
01499     DetRonNoise    *array=NULL;
01500 
01501     /*    Algorithm
01502     -----------*/
01503     array = (DetRonNoise *) calloc (1, sizeof (DetRonNoise));
01504 
01505     array->pattern = (float *) calloc (imageSize->iXWidth * imageSize->iYWidth, sizeof(float));
01506     array->aveImage = (float *) calloc (imageSize->iXWidth * imageSize->iYWidth, sizeof(float));
01507     
01508     return (array);
01509 }
01510 /*****************************************************************************/
01511 
01512 
01513 
01514 /******************************************************************************
01515 *                European Southern Observatory
01516 *                MIDI Data Reduction Software
01517 *
01518 * Module name:    freeDetRon
01519 * Input/Output:    See function arguments to avoid duplication
01520 * Description:    Releases all the memory related to the DetRonNoise data structure
01521 *
01522 * History:        
01523 * 04-Aug-04        (csabet) Created
01524 ******************************************************************************/
01525 void freeDetRon (
01526     DetRonNoise    *array)
01527 {
01528     /*    Local Declarations
01529     --------------------*/
01530 
01531     /*    Algorithm
01532     -----------*/
01533     free (array->pattern);
01534     free (array->aveImage);
01535     free (array);
01536     array = NULL;
01537        
01538     return;
01539 }
01540 /*****************************************************************************/
01541 
01542 
01543 /******************************************************************************
01544 *                European Southern Observatory
01545 *                MIDI Data Reduction Software
01546 *
01547 * Module name:    callocImageQuality
01548 * Input/Output:    See function arguments to avoid duplication
01549 * Description:    Allocates memory for the ImageQuality data structure
01550 *
01551 * History:        
01552 * 26-Apr-05        (csabet) Created
01553 ******************************************************************************/
01554 ImageQuality *callocImageQuality (
01555     ImageFormat    *format)
01556 {
01557     //    Local Declarations
01558     //    ------------------
01559     ImageQuality    *image=NULL;
01560     int                i;
01561 
01562     //    Algorithm
01563     //    ---------
01564     image = (ImageQuality *) calloc (1, sizeof (ImageQuality));
01565 
01566     image->aveImage = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
01567     image->aveImageSky = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
01568     for (i = 0; i < format->numOfDetectorRegions; i++)
01569     {
01570         image->aveImage[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
01571         image->aveImageSky[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
01572     }
01573 
01574     image->targetFlux = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01575     image->targetPixelCount = (int *) calloc (format->numOfDetectorRegions, sizeof (int));
01576     image->coordX = (double *) calloc (format->numOfDetectorRegions, sizeof (double));
01577     image->coordY = (double *) calloc (format->numOfDetectorRegions, sizeof (double));
01578     image->sizeX = (double *) calloc (format->numOfDetectorRegions, sizeof (double));
01579     image->sizeY = (double *) calloc (format->numOfDetectorRegions, sizeof (double));
01580     image->tarType = (char *) calloc (format->numOfFrames, sizeof(char));
01581     
01582     return (image);
01583 }
01584 /*****************************************************************************/
01585 
01586 
01587 
01588 /******************************************************************************
01589 *                European Southern Observatory
01590 *                MIDI Data Reduction Software
01591 *
01592 * Module name:    freeImageQuality
01593 * Input/Output:    See function arguments to avoid duplication
01594 * Description:    Releases all the memory related to the mageQuality data structure
01595 *
01596 * History:        
01597 * 26-Apr-05        (csabet) Created
01598 ******************************************************************************/
01599 void freeImageQuality (
01600     ImageFormat        *format,
01601     ImageQuality    *image)
01602 {
01603     //    Local Declarations
01604     //    ------------------
01605     int    i;
01606     
01607     //    Algorithm
01608     //    ---------
01609     for (i = 0; i < format->numOfDetectorRegions; i++)
01610     {
01611         free (image->aveImage[i]);
01612         free (image->aveImageSky[i]);
01613     }
01614 
01615     free (image->tarType);
01616     free (image->aveImage);
01617     free (image->aveImageSky);
01618     free (image->targetFlux);
01619     free (image->targetPixelCount);
01620     free (image->coordX);
01621     free (image->coordY);
01622     free (image->sizeX);
01623     free (image->sizeY);
01624 
01625     free (image);
01626     image = NULL;
01627        
01628     return;
01629 }
01630 /*****************************************************************************/
01631 
01632 
01633 /******************************************************************************
01634 *                European Southern Observatory
01635 *                MIDI Data Reduction Software
01636 *
01637 * Module name:    callocWavCal
01638 * Input/Output:    See function arguments to avoid duplication
01639 * Description:    Allocates memory for the WavCalibration data structure
01640 *
01641 * History:        
01642 * 10-Jun-05        (csabet) Created
01643 ******************************************************************************/
01644 WaveCalibration *callocWaveCal (
01645     int            numOfFiles,
01646     int            numOfRecords,
01647     ImageFormat    *format)
01648 {
01649     //    Local Declarations
01650     //    ------------------
01651     WaveCalibration    *array=NULL;
01652     int                i;
01653 
01654     //    Algorithm
01655     //    ---------
01656     array = (WaveCalibration *) calloc (1, sizeof (WaveCalibration));
01657 
01658     array->numOfFiles = numOfFiles;
01659     array->tarType = (char *) calloc (format->numOfFrames, sizeof(char));
01660     array->variance = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01661     array->calibratedWave = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
01662     for (i = 0; i < format->numOfDetectorRegions; i++)
01663         array->calibratedWave[i] = (float *) calloc (format->iXWidth, sizeof(float));
01664 
01665     array->filterName = (char **) calloc (numOfFiles, sizeof (char *));
01666     array->shutterId = (char **) calloc (numOfFiles, sizeof (char *));
01667     for (i = 0; i < array->numOfFiles; i++)
01668     {
01669         array->filterName[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01670         array->shutterId[i] = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01671     }
01672 
01673     //    ArIII memory
01674     array->ArIII = (NarrowBandInfo *) calloc (1, sizeof (NarrowBandInfo));
01675     array->ArIII->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
01676     array->ArIII->wavelength = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01677     array->ArIII->xCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01678     array->ArIII->yCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01679     array->ArIII->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
01680     for (i = 0; i < format->numOfDetectorRegions; i++)
01681         array->ArIII->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
01682 
01683     //    NeII memory
01684     array->NeII = (NarrowBandInfo *) calloc (1, sizeof (NarrowBandInfo));
01685     array->NeII->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
01686     array->NeII->wavelength = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01687     array->NeII->xCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01688     array->NeII->yCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01689     array->NeII->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
01690     for (i = 0; i < format->numOfDetectorRegions; i++)
01691         array->NeII->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
01692 
01693     //    SIV memory
01694     array->SIV = (NarrowBandInfo *) calloc (1, sizeof (NarrowBandInfo));
01695     array->SIV->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
01696     array->SIV->wavelength = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01697     array->SIV->xCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01698     array->SIV->yCoord = (float *) calloc (format->numOfDetectorRegions, sizeof (float));
01699     array->SIV->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
01700     for (i = 0; i < format->numOfDetectorRegions; i++)
01701         array->SIV->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
01702 
01703     //    Foil memory
01704     array->foil = (FoilInfo *) calloc (1, sizeof (FoilInfo));
01705     array->foil->actualWavelength = (float *) calloc (numOfRecords, sizeof (float));
01706     array->foil->actualTransmission = (float *) calloc (numOfRecords, sizeof (float));
01707     array->foil->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
01708     array->foil->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
01709     for (i = 0; i < format->numOfDetectorRegions; i++)
01710         array->foil->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
01711 
01712     //    OPEN memory
01713     array->open = (OpenInfo *) calloc (1, sizeof (OpenInfo));
01714     array->open->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
01715     array->open->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
01716     for (i = 0; i < format->numOfDetectorRegions; i++)
01717         array->open->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
01718 
01719     //    DARK memory
01720     array->dark = (DarkInfo *) calloc (1, sizeof (DarkInfo));
01721     array->dark->fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof(char));
01722     array->dark->image = (float **) calloc (format->numOfDetectorRegions, sizeof (float *));
01723     for (i = 0; i < format->numOfDetectorRegions; i++)
01724         array->dark->image[i] = (float *) calloc (format->iXWidth * format->iYWidth, sizeof(float));
01725     
01726     return (array);
01727 }
01728 /*****************************************************************************/
01729 
01730 
01731 /******************************************************************************
01732 *                European Southern Observatory
01733 *                MIDI Data Reduction Software
01734 *
01735 * Module name:    freeWavCal
01736 * Input/Output:    See function arguments to avoid duplication
01737 * Description:    Releases all the memory related to the WavCalibration data structure
01738 *
01739 * History:        
01740 * 10-Jun-05        (csabet) Created
01741 ******************************************************************************/
01742 void freeWaveCal (
01743     ImageFormat        *format,
01744     WaveCalibration    *array)
01745 {
01746     //    Local Declarations
01747     //    ------------------
01748     int    i;
01749 
01750     //    Algorithm
01751     //    ---------
01752     for (i = 0; i < array->numOfFiles; i++)
01753     {
01754         free (array->filterName[i]);
01755         free (array->shutterId[i]);
01756     }
01757     free (array->filterName);
01758     free (array->shutterId);
01759     free (array->tarType);
01760     free (array->variance);
01761 
01762     for (i = 0; i < format->numOfDetectorRegions; i++) free (array->calibratedWave[i]);
01763     free (array->calibratedWave);
01764 
01765     for (i = 0; i < format->numOfDetectorRegions; i++) free (array->ArIII->image[i]);
01766     free (array->ArIII->image);
01767     free (array->ArIII->wavelength);
01768     free (array->ArIII->xCoord);
01769     free (array->ArIII->yCoord);
01770     free (array->ArIII->fileName);
01771     free (array->ArIII);
01772     
01773     for (i = 0; i < format->numOfDetectorRegions; i++) free (array->NeII->image[i]);
01774     free (array->NeII->image);
01775     free (array->NeII->wavelength);
01776     free (array->NeII->xCoord);
01777     free (array->NeII->yCoord);
01778     free (array->NeII->fileName);
01779     free (array->NeII);
01780     
01781     for (i = 0; i < format->numOfDetectorRegions; i++) free (array->SIV->image[i]);
01782     free (array->SIV->image);
01783     free (array->SIV->wavelength);
01784     free (array->SIV->xCoord);
01785     free (array->SIV->yCoord);
01786     free (array->SIV->fileName);
01787     free (array->SIV);
01788     
01789     for (i = 0; i < format->numOfDetectorRegions; i++) free (array->foil->image[i]);
01790     free (array->foil->image);
01791     free (array->foil->fileName);
01792     free (array->foil->actualWavelength);
01793     free (array->foil->actualTransmission);
01794     free (array->foil);
01795     
01796     for (i = 0; i < format->numOfDetectorRegions; i++) free (array->open->image[i]);
01797     free (array->open->image);
01798     free (array->open->fileName);
01799     free (array->open);
01800     
01801     for (i = 0; i < format->numOfDetectorRegions; i++) free (array->dark->image[i]);
01802     free (array->dark->image);
01803     free (array->dark->fileName);
01804     free (array->dark);
01805     
01806     free (array);
01807     array = NULL;
01808            
01809     return;
01810 }
01811 /*****************************************************************************/
01812 
01813 

Generated on 5 Mar 2013 for MIDI Pipeline Reference Manual by  doxygen 1.6.1