1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
/* $Id: vmcube.c,v 1.2 2013-03-25 11:43:04 cgarcia Exp $
*
* This file is part of the VIMOS Pipeline
* Copyright (C) 2002-2004 European Southern Observatory
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* $Author: cgarcia $
* $Date: 2013-03-25 11:43:04 $
* $Revision: 1.2 $
* $Name: not supported by cvs2svn $
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <pilmemory.h>
#include "vmtypes.h"
#include "vmimage.h"
#include "vmcube.h"
#include "cpl.h"
/*
Create a VimosCube, not allocate space for the data
*/
VimosCube *newCube(int xlen, int ylen, int zlen, float *data)
{
VimosCube *theCube;
theCube = (VimosCube *) cpl_malloc(sizeof(VimosCube));
/* check if space was allocated */
if (theCube == NULL)
{
abort();
}
/* a VimosCube is only an interface to a Fits Image. */
/* The pointer should point to the data of the Fits Image */
theCube->data = data;
theCube->xlen = xlen;
theCube->ylen = ylen;
theCube->zlen = zlen;
theCube->descs = NULL;
theCube->fptr = NULL;
return(theCube);
}
/*
Create a VimosCube, allocate space for the data
*/
VimosCube *newCubeAndAlloc(int xlen, int ylen, int zlen)
{
VimosCube *tmpCube;
tmpCube = newCube(xlen, ylen, zlen, NULL);
tmpCube->data = (float *) cpl_malloc(xlen*ylen*zlen*sizeof(float));
if (tmpCube->data == NULL)
{
/* cleanup */
deleteCube(tmpCube);
abort();
}
return(tmpCube);
}
/*
Delete a VimosCube
*/
void deleteCube(VimosCube *Cube)
{
if (Cube != NULL) {
deleteAllDescriptors(Cube->descs);
if (Cube->data != NULL) {
cpl_free(Cube->data);
}
cpl_free(Cube);
}
}
void deleteCubeAndAlloc(VimosCube *Cube)
{
if (Cube != NULL) {
if (Cube->data != NULL) {
cpl_free(Cube->data);
Cube->data = NULL;
}
}
deleteCube(Cube);
}
/*
Find (L,M) coordinates of the fiber corresponding to an Object
in an objectTable
*/
VimosFloatArray *selectFiberForObject(VimosIfuSlit *ifuSlits,
VimosObjectObject *object,
float *theData, int specLen,
int objNum,int *theL, int *theM)
{
int i;
VimosFloatArray *theSpec = NULL;
VimosIfuFiber *theIfuFibers;
/* loop on IFU slits for this quadrant to find L,M of each object */
while (ifuSlits)
{
/* if this is the "right" slit take fibers */
if (ifuSlits->ifuSlitNo == object->IFUslitNo)
{
theIfuFibers = ifuSlits->fibers;
/* loop on fibers of this slit until find the one */
/* corresponding to the object */
while (theIfuFibers)
{
if (theIfuFibers->fibNo == object->IFUfibNo)
{
/* clean previous allocation */
deleteFloatArray(theSpec);
/* take (L,M) coordinates for the fiber */
*theL = theIfuFibers->fiberL;
*theM = theIfuFibers->fiberM;
/* create working array for this object spectrum */
theSpec = newFloatArray(specLen);
for (i = 0; i < specLen; i++ )
{
theSpec->data[i] = theData[i + objNum*specLen];
}
/* here compute flux or whatever else */
}
theIfuFibers = theIfuFibers->next;
}
}
ifuSlits = ifuSlits->next;
} /* close loop on IFU slits for this object */
return(theSpec);
}
/*
Open a new Fits VimosCube
*/
VimosBool openNewFitsCube(char *cubeName, VimosCube *cube)
{
int naxis;
long npix[3];
int status, bitpix;
npix[0] = cube->xlen;
npix[1] = cube->ylen;
npix[2] = cube->zlen;
naxis = 3;
bitpix = -32;
status = 0;
fits_create_file (&cube->fptr, cubeName, &status);
fits_create_img(cube->fptr, bitpix, naxis, npix, &status);
if (status)
{
return(VM_FALSE);
}
else
{
return(VM_TRUE);
}
}
/*
Close a Fits VimosCube
*/
VimosBool closeFitsCube(VimosCube *cube, int flag)
{
int status;
long fpixel, npixels;
status = 0;
npixels = cube->xlen * cube->ylen * cube->zlen;
fpixel = 1;
if (flag != 0 )
{
if (fits_write_img(cube->fptr, TFLOAT, fpixel, npixels, cube->data,
&status) )
return(VM_FALSE);
}
status = 0;
if ( fits_close_file(cube->fptr, &status) ) return(VM_FALSE);
return(VM_TRUE);
}
|