- Timestamp:
- Mar 8, 2006, 5:14:23 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMP.c
r6545 r6556 1 # include "pmSource.h" 1 /** @file pmSourceIO.c 2 * 3 * @author EAM, IfA 4 * 5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 * 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 9 * 10 */ 11 12 #include <stdio.h> 13 #include <math.h> 14 #include <string.h> 15 #include "pslib.h" 16 #include "psLine.h" 17 #include "psEllipse.h" 18 #include "pmHDU.h" 19 #include "pmFPA.h" 20 #include "pmPeaks.h" 21 #include "pmMoments.h" 22 #include "pmGrowthCurve.h" 23 #include "pmModel.h" 24 #include "pmPSF.h" 25 #include "pmSource.h" 26 #include "pmModelGroup.h" 27 #include "pmSourceIO.h" 2 28 3 29 // elixir-style pseudo FITS table (header + ascii list) … … 10 36 float dmag, lsky; 11 37 bool status; 38 EllipseShape shape; 39 EllipseAxes axes; 12 40 13 41 // find config information for output header … … 19 47 for (i = nSrc = 0; i < sources->n; i++) { 20 48 pmSource *source = (pmSource *) sources->data[i]; 21 pmModel *model = pm ModelSelect(source);49 pmModel *model = pmSourceSelectModel (source); 22 50 if (model == NULL) 23 51 continue; … … 49 77 for (i = 0; i < sources->n; i++) { 50 78 pmSource *source = (pmSource *) sources->data[i]; 51 pmModel *model = pm ModelSelect(source);79 pmModel *model = pmSourceSelectModel (source); 52 80 if (model == NULL) 53 81 continue; … … 56 84 dPAR = model->dparams->data.F32; 57 85 58 dmag = dPAR[1] / PAR[1];59 86 type = pmSourceDophotType (source); 60 87 lsky = (PAR[0] < 1.0) ? 0.0 : log10(PAR[0]); 61 88 89 shape.sx = PAR[4]; 90 shape.sy = PAR[5]; 91 shape.sxy = PAR[6]; 92 axes = EllipseShapeToAxes (shape); 93 62 94 psLineInit (line); 63 psLineAdd (line, "%6.1f ", PAR[2]);64 psLineAdd (line, "%6.1f ", PAR[3]);65 psLineAdd (line, "%6.3f ", PS_MIN (99.999, source->fitMag + ZERO_POINT));66 psLineAdd (line, "%03d ", PS_MIN (999, (int)(1000*dmag)));67 psLineAdd (line, "%2d ", type);68 psLineAdd (line, "%3.1f ", lsky);69 psLineAdd (line, "%6.3f ", 99.999); // should be 'Mgal70 psLineAdd (line, "%6.3f ", PS_MIN (99.999, source->apMag+ ZERO_POINT));71 psLineAdd (line, "%6.2f ", PAR[4]); // should be 'FHWM x'72 psLineAdd (line, "%6.2f ", PAR[5]); // should be 'FHWM y'73 psLineAdd (line, "%5.1f\n", 0); // should be theta95 psLineAdd (line, "%6.1f ", PAR[2]); 96 psLineAdd (line, "%6.1f ", PAR[3]); 97 psLineAdd (line, "%6.3f ", PS_MIN (99.0, source->psfMag + ZERO_POINT)); 98 psLineAdd (line, "%03d ", PS_MIN (999, (int)(1000*dmag))); 99 psLineAdd (line, "%2d ", type); 100 psLineAdd (line, "%3.1f ", lsky); 101 psLineAdd (line, "%6.3f ", PS_MIN (99.0, source->extMag + ZERO_POINT)); 102 psLineAdd (line, "%6.3f ", PS_MIN (99.0, source->apMag + ZERO_POINT)); 103 psLineAdd (line, "%6.2f ", axes.major); 104 psLineAdd (line, "%6.2f ", axes.minor); 105 psLineAdd (line, "%5.1f\n", axes.theta); 74 106 fwrite (line->line, 1, line->Nline, f); 75 107 } … … 82 114 83 115 // elixir-style pseudo FITS table (header + ascii list) 84 psArray * sourcespmSourcesReadCMP (char *filename, psMetadata *header)116 psArray *pmSourcesReadCMP (char *filename, psMetadata *header) 85 117 { 86 118 87 int i, type, nSrc; 88 psMetadataItem *mdi; 119 int Ninstar; 89 120 psF32 *PAR, *dPAR; 90 float dmag, lsky;91 121 bool status; 122 EllipseShape shape; 123 EllipseAxes axes; 124 125 // define PSF model type 126 int modelType = pmModelSetType ("PS_MODEL_GAUSS"); 127 128 char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME"); 129 if (PSF_NAME != NULL) { 130 modelType = pmModelSetType (PSF_NAME); 131 } 92 132 93 133 // find config information for output header … … 113 153 114 154 // prepare array to store data 115 int nStars = psMetadataLookupS32 (&status, myHeader, "NSTARS");155 int nStars = psMetadataLookupS32 (&status, header, "NSTARS"); 116 156 psArray *sources = psArrayAlloc (nStars); 117 157 sources->n = 0; 118 158 119 159 // we have fixed bytes / line : use that info 120 char *buffer = psAlloc ( NBYTES_STAR*nStars);160 char *buffer = psAlloc (BYTES_STAR*nStars); 121 161 122 162 int Nextra = 0; … … 161 201 162 202 /* extract data for stars */ 163 intNinstar = nbytes / BYTES_STAR;203 Ninstar = nbytes / BYTES_STAR; 164 204 Nextra = nbytes % BYTES_STAR; 165 for ( j = 0; j < Ninstar; j++, N++) {166 psString line = psStringNCopy (&buffer[j*BYTES_STAR] );205 for (int j = 0; j < Ninstar; j++) { 206 psString line = psStringNCopy (&buffer[j*BYTES_STAR], BYTES_STAR); 167 207 psList *list = psStringSplit (line, " "); 168 208 psArray *array = psListToArray (list); 169 209 170 210 pmSource *source = pmSourceAlloc (); 171 172 source->x = atof (array->data[0]); 173 source->y = atof (array->data[1]); 174 source->fitMag = atof (array->data[2]); 175 source->dMag = 0.001*atof (array->data[3]); 176 source->type = atof (array->data[4]); 177 source->sky = pow (atof (array->data[5]), 10.0); 178 source->galMag = atof (array->data[6]); 211 pmModel *model = pmModelAlloc (modelType); 212 source->modelPSF = model; 213 214 PAR = model->params->data.F32; 215 dPAR = model->dparams->data.F32; 216 217 PAR[0] = pow (atof (array->data[5]), 10.0); 218 PAR[2] = atof (array->data[0]); 219 PAR[3] = atof (array->data[1]); 220 source->psfMag = atof (array->data[2]); 221 source->extMag = atof (array->data[6]); 222 source->errMag = atof (array->data[3]) / 1000.0; 179 223 source->apMag = atof (array->data[7]); 180 source->sx = atof (array->data[8]); 181 source->sy = atof (array->data[9]); 182 source->theta = atof (array->data[10]); 224 axes.major = atof (array->data[8]); 225 axes.minor = atof (array->data[9]); 226 axes.theta = atof (array->data[10]); 227 228 shape = EllipseAxesToShape (axes); 229 230 PAR[4] = shape.sx; 231 PAR[5] = shape.sy; 232 PAR[6] = shape.sxy; 233 234 // source->type = atof (array->data[4]); 183 235 184 236 psArrayAdd (sources, 100, source);
Note:
See TracChangeset
for help on using the changeset viewer.
