/******************************************************************************* * M3: maxMinTOD.c * * * * Version 2.0.2 May 2007 * * * * Copyright (C) 2004-2007 C.M. Cantalupo * * * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * *******************************************************************************/ /* Christopher M. Cantalupo November 2007 */ #include <stdlib.h> #include <math.h> #include "M3.h" #define STRING_LENGTH 256 int main( int argc, char **argv ) { M3_RunConfigStruct *runConfig; M3_DataSetLL *dataSet; M3_IntervalLL *intervalNode; int notDone; int64_t i, j, k, l, n; M3_Interval interval; double *tod = NULL; double maxVal = -HUGE_VAL, minVal = HUGE_VAL; /* Read run config from disk */ M3_RunConfigStruct_Read(&runConfig, argv[1], M3_SPRINGTIDE_RUN_TYPE ); /* Go through all of the dataSets (detectors) */ for ( notDone = M3_RunConfigStruct_GetDataSetRoot( runConfig, &dataSet ); notDone; M3_DataSetLL_GetNextNodeInList( &dataSet )) { /* Go through the covered intervals */ for( notDone = M3_DataSetLL_GetCoveredIntervalRoot( dataSet, &intervalNode); notDone; notDone = M3_IntervalLL_GetNextNodeInList( &intervalNode ) ) { /* Retrieve the interval structure from the list node */ M3_IntervalLL_GetInterval( intervalNode, &interval ); /* Count the number of samples in the interval*/ n = interval.lastSample - interval.firstSample + 1; /* If we have alread allocated tod and pointing, call realloc */ if( tod ) { tod = (double*)realloc( tod, sizeof(double)*n); } /* Otherwise allocate memory with malloc */ else { tod = (double*)malloc( sizeof(double)*n); } /* Get the time ordered data*/ M3_DataSetLL_GetTOD( dataSet, interval, tod ); /* Cycle over all of the samples in the interval. */ /* i keeps track of the time index from the beginning of the interval */ for( i = 0; i < n; i++ ) { if( tod[i] > maxVal ) maxVal = tod[i]; if( tod[i] < minVal ) minVal = tod[i]; } } } fprintf(stdout, "maximum = %.8e\n", maxVal); fprintf(stdout, "minimum = %.8e\n", minVal); free(tod); return 0; }