next up previous
Next: Libraries for Accessing Up: No Title Previous: Simple Data Access

Simple Data Access Example in C

The following program reads through the first lane of a mapping data set, and reports the largest pixel value found. It assumes the dataset has the charactersitics listed in the above example header file, and that the program is to be compiled and run on a DEC ALPHA.

#include <stdio.h>
#include <string.h>

int main()
{
   short buffer[1280];
   short maxval;
   size_t status;
   int j;
   FILE *fd;

   fd = fopen ( "l1", "rb" );

   if ( fd != 0 )
   {
      maxval = -32767;

/*   Read one row of pixels at a time updating the maximum transmission
     value */

      for ( ; ; )
      {
         status = fread ( buffer, (size_t)2, (size_t)1280, fd );
         if ( feof ( fd ) )
         {
            break;
         }
         else if ( ferror ( fd ) )
         {
            printf ( "error on reading data file\n" );
            break;
         }
         else
         {
            for ( j=0; j<1280; j++ )
            {
               if ( buffer[j] > maxval )
               {
                  maxval = buffer[j];
               }
            }
         }
      }

      printf ( "Maximum transmission found was %d\n", (int)maxval );

      fclose ( fd );
      return 0;
   }
   else
   {
      printf ( "failed to open data file\n" );
   }
}



SuperCOSMOS development
Tue Aug 20 12:02:13 BST 1996