00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00058
00059
00060 #include <stdlib.h>
00061 #include <M3.h>
00062
00063 #define STRING_LENGTH 256
00064
00065 int main( int argc, char **argv )
00066 {
00067 M3_RunConfigStruct *runConfig;
00068 M3_DataSetLL *dataSet;
00069 M3_IntervalLL *intervalNode;
00070 int notDone;
00071 M3_PointingEl *pointing = NULL;
00072 M3_PixelClassLL *pixelClass;
00073 M3_PointingClassLL *pointingClass;
00074 int32_t numNZ, numClassNZ, numPixelClass, mapSize;
00075 M3_MapEl **mapArray;
00076 double **weightArray;
00077 int32_t *nnzArray;
00078 int32_t numPixel;
00079 int64_t i, j, k, l, n;
00080 M3_Interval interval;
00081 double *tod = NULL;
00082 char mapName[STRING_LENGTH];
00083 FILE *fid;
00084 M3_MapHeader mapHeader;
00085 char temp = 0;
00086
00087
00088 M3_RunConfigStruct_Read(&runConfig, argv[1], M3_SPRINGTIDE_RUN_TYPE );
00089
00090
00091 numPixelClass = 0;
00092 for( notDone = M3_RunConfigStruct_GetPixelClassRoot(runConfig, &pixelClass); notDone; notDone = M3_PixelClassLL_GetNextNodeInList(&pixelClass) )
00093 numPixelClass++;
00094
00095
00096 mapArray = (M3_MapEl **)calloc(numPixelClass, sizeof(M3_MapEl *));
00097 weightArray = (double **)calloc(numPixelClass*numPixelClass, sizeof(double *));
00098 nnzArray = (int32_t *)malloc(numPixelClass*sizeof(int32_t));
00099
00100
00101 for( i = 0, notDone = M3_RunConfigStruct_GetPixelClassRoot(runConfig, &pixelClass);
00102 notDone;
00103 i++, notDone = M3_PixelClassLL_GetNextNodeInList(&pixelClass) )
00104 {
00105 M3_PixelClassLL_GetNumPixelInClass( pixelClass, &mapSize);
00106 mapArray[i] = (M3_MapEl *)calloc(mapSize,sizeof(M3_MapEl));
00107
00108 for( j = 0; j < mapSize; j++ )
00109 {
00110 mapArray[i][j].pixel = j;
00111 mapArray[i][j].value = nan(&temp);
00112 }
00113 weightArray[i] = calloc(mapSize,sizeof(double));
00114 }
00115
00116
00117
00118 for ( notDone = M3_RunConfigStruct_GetDataSetRoot( runConfig, &dataSet );
00119 notDone;
00120 M3_DataSetLL_GetNextNodeInList( &dataSet ))
00121 {
00122
00123 M3_DataSetLL_GetNumNZ(dataSet, &numNZ);
00124
00125
00126 for( notDone = M3_DataSetLL_GetCoveredIntervalRoot( dataSet, &intervalNode);
00127 notDone;
00128 notDone = M3_IntervalLL_GetNextNodeInList( &intervalNode ) )
00129 {
00130
00131 M3_IntervalLL_GetInterval( intervalNode, &interval );
00132
00133 n = interval.lastSample - interval.firstSample + 1;
00134
00135
00136 if( tod && pointing )
00137 {
00138 tod = (double*)realloc( tod, sizeof(double)*n);
00139 pointing = (M3_PointingEl*)realloc( pointing, numNZ*sizeof(M3_PointingEl)*n );
00140 }
00141
00142 else
00143 {
00144 tod = (double*)malloc( sizeof(double)*n);
00145 pointing = (M3_PointingEl*)malloc( numNZ*sizeof(M3_PointingEl)*n );
00146 }
00147
00148
00149 M3_DataSetLL_GetPointing(dataSet, interval, pointing );
00150 M3_DataSetLL_GetTOD( dataSet, interval, tod );
00151
00152
00153
00154 l = 0;
00155
00156 for( i = 0; i < n; i++ )
00157 {
00158
00159 j = 0;
00160
00161 notDone = M3_DataSetLL_GetPointingClassRoot( dataSet, &pointingClass );
00162
00163 while( notDone )
00164 {
00165
00166 M3_PointingClassLL_GetNumNZ( pointingClass, &numClassNZ );
00167
00168 for( k = 0; k < numClassNZ; k++ )
00169 {
00170
00171 if(!isnan(mapArray[j][pointing[l].pixel].value))
00172 {
00173
00174 mapArray[j][pointing[l].pixel].value += tod[i]*pointing[l].weight;
00175
00176 weightArray[j][pointing[l].pixel] += pointing[l].weight*pointing[l].weight;
00177 }
00178
00179 else
00180 {
00181
00182 mapArray[j][pointing[l].pixel].value = tod[i]*pointing[l].weight;
00183
00184 weightArray[j][pointing[l].pixel] = pointing[l].weight*pointing[l].weight;
00185 }
00186 l++;
00187 }
00188 j++;
00189
00190 notDone = M3_PointingClassLL_GetNextNodeInList( &pointingClass );
00191 }
00192 }
00193 }
00194
00195
00196 M3_RunConfigStruct_GetPixelClassRoot( runConfig, &pixelClass );
00197 for( i = 0; i < numPixelClass; i++ )
00198 {
00199
00200
00201
00202 M3_PixelClassLL_GetNumPixelInClass( pixelClass, &numPixel );
00203 k = 0;
00204 for( j = 0 ; j < numPixel; j++)
00205 {
00206 if( !isnan(mapArray[i][j].value) && weightArray[i][j] )
00207 {
00208 mapArray[i][k].value = mapArray[i][j].value/sqrt(weightArray[i][j]);
00209 mapArray[i][k].pixel = mapArray[i][j].pixel;
00210 k++;
00211 }
00212 }
00213
00214 M3_PixelClassLL_GetMapName( pixelClass, mapName, STRING_LENGTH );
00215
00216 fid = fopen( mapName, "w");
00217 mapHeader.numPixelInClass = numPixel;
00218 mapHeader.numPixelInMap = k;
00219 fwrite( &mapHeader, 1, sizeof(M3_MapHeader), fid);
00220 fwrite( mapArray[i], sizeof(M3_MapEl), k, fid);
00221 fclose(fid);
00222
00223 M3_PixelClassLL_GetNextNodeInList( &pixelClass );
00224 }
00225 }
00226
00227 free(tod);
00228 free(pointing);
00229 return 0;
00230 }
00231