maxMinMap.c

This simple M3 example application of map processing which derives the maximum and minumum value from all of the maps in a Run Config.

/*******************************************************************************
*   M3:  maxMinMap.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_PixelClassLL *pixelClass;
  int notDone;
  int32_t numPixel;
  int64_t i, j, k, l, n;
  M3_Interval interval;
  M3_MapEl *map = NULL;
  double maxVal = -HUGE_VAL, minVal = HUGE_VAL;
  char className[STRING_LENGTH];

  /* Read run config from disk */
  M3_RunConfigStruct_Read(&runConfig, argv[1], M3_MADSPEC_RUN_TYPE );

  /* Go through the pixel classes.  */
  notDone = M3_RunConfigStruct_GetPixelClassRoot( runConfig, &pixelClass );
  while( notDone )
  {
    /* Allocate the full maps */
    M3_PixelClassLL_GetNumPixelInClass( pixelClass, &numPixel );
    if( map )
      map = (M3_MapEl *)realloc( map, sizeof(M3_MapEl)*numPixel );
    else
      map = (M3_MapEl *)malloc( sizeof(M3_MapEl)*numPixel );

    /* Set the index values */
    for( i = 0; i < numPixel; i++ )
      map[i].pixel = i;

    /* Get the map from disk */
    M3_PixelClassLL_GetIndexedMap(pixelClass, numPixel, map );

    /* Look for maximum and minimum values */
    for( i = 0; i < numPixel; i++ )
    {
      if( !isnan(map[i].value) && map[i].value > maxVal )
        maxVal = map[i].value;
      if( !isnan(map[i].value) && map[i].value < minVal )
        minVal = map[i].value;
    }

    /* Print to standard out.  */
    M3_PixelClassLL_GetClassName( pixelClass, className, STRING_LENGTH);
    fprintf( stdout, "Pixel class %s maximum map value:  %.8e\n", className, maxVal );
    fprintf( stdout, "Pixel class %s minimum map value:  %.8e\n", className, minVal );

    notDone = M3_PixelClassLL_GetNextNodeInList( &pixelClass );
  }

  free(map);
  return 0;
}



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