maxMinMap.c

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *   M3:  maxMinMap.c                                                           *
00003 *                                                                              *
00004 *   Version 2.0.2 May 2007                                                     *
00005 *                                                                              *
00006 *   Copyright (C) 2004-2007  C.M. Cantalupo                                    *
00007 *                                                                              *
00008 *   This program is free software; you can redistribute it and/or modify       *
00009 *   it under the terms of the GNU General Public License as published by       *
00010 *   the Free Software Foundation; either version 2 of the License, or          *
00011 *   (at your option) any later version.                                        *
00012 *                                                                              *
00013 *   This program is distributed in the hope that it will be useful,            *
00014 *   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00015 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
00016 *   GNU General Public License for more details.                               *
00017 *                                                                              *
00018 *   You should have received a copy of the GNU General Public License          *
00019 *   along with this program; if not, write to the Free Software                *
00020 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  *
00021 *                                                                              *
00022 *******************************************************************************/
00023 
00024 
00059 /* Christopher M. Cantalupo November 2007 */
00060 
00061 #include <stdlib.h>
00062 #include <math.h>
00063 #include "M3.h"
00064 
00065 #define STRING_LENGTH 256
00066 
00067 int main( int argc, char **argv )
00068 {
00069   M3_RunConfigStruct *runConfig;
00070   M3_PixelClassLL *pixelClass;
00071   int notDone;
00072   int32_t numPixel;
00073   int64_t i, j, k, l, n;
00074   M3_Interval interval;
00075   M3_MapEl *map = NULL;
00076   double maxVal = -HUGE_VAL, minVal = HUGE_VAL;
00077   char className[STRING_LENGTH];
00078 
00079   /* Read run config from disk */
00080   M3_RunConfigStruct_Read(&runConfig, argv[1], M3_MADSPEC_RUN_TYPE );
00081 
00082   /* Go through the pixel classes.  */
00083   notDone = M3_RunConfigStruct_GetPixelClassRoot( runConfig, &pixelClass );
00084   while( notDone )
00085   {
00086     /* Allocate the full maps */
00087     M3_PixelClassLL_GetNumPixelInClass( pixelClass, &numPixel );
00088     if( map )
00089       map = (M3_MapEl *)realloc( map, sizeof(M3_MapEl)*numPixel );
00090     else
00091       map = (M3_MapEl *)malloc( sizeof(M3_MapEl)*numPixel );
00092 
00093     /* Set the index values */
00094     for( i = 0; i < numPixel; i++ )
00095       map[i].pixel = i;
00096 
00097     /* Get the map from disk */
00098     M3_PixelClassLL_GetIndexedMap(pixelClass, numPixel, map );
00099 
00100     /* Look for maximum and minimum values */
00101     for( i = 0; i < numPixel; i++ )
00102     {
00103       if( !isnan(map[i].value) && map[i].value > maxVal )
00104         maxVal = map[i].value;
00105       if( !isnan(map[i].value) && map[i].value < minVal )
00106         minVal = map[i].value;
00107     }
00108 
00109     /* Print to standard out.  */
00110     M3_PixelClassLL_GetClassName( pixelClass, className, STRING_LENGTH);
00111     fprintf( stdout, "Pixel class %s maximum map value:  %.8e\n", className, maxVal );
00112     fprintf( stdout, "Pixel class %s minimum map value:  %.8e\n", className, minVal );
00113 
00114     notDone = M3_PixelClassLL_GetNextNodeInList( &pixelClass );
00115   }
00116 
00117   free(map);
00118   return 0;
00119 }
00120 
00121 

Generated on Mon Nov 24 10:05:12 2008 for M3 by  doxygen 1.5.3-20071008