imageprocessing/fileFunctions.c
int readFeatures(FEATURE_T* featureArray[], FILE* pIn, int arraySize)
{
#define FIGURE "-FIGURE"
#define COORDS "-COORDS"
#define END "-END"

  int count = 0;
  POINT_T * pNewPoint = NULL;
  FEATURE_T* pNewLine = NULL;
  double x = 0;
  double y = 0;
  char buffer[128];
  while (fgets(buffer,sizeof(buffer),pIn) != NULL)
    {
    if (strncmp(buffer,FIGURE,strlen(FIGURE)) == 0)  /* start of a new feature */
       {
       if (count >= arraySize)
	  continue;  /* still read but don't store */
       pNewLine = calloc(1,sizeof(FEATURE_T));
       if (pNewLine == NULL)
	  {
	  printf("Error allocating feature %d\n",count);
	  return -1;
	  }
       featureArray[count] = pNewLine;
       count++;
       }  
    else if (strncmp(buffer,COORDS,strlen(COORDS)) == 0)
       {
       if (count > arraySize) /* note pure inequality here */
			      /* want to be sure we read the points for the last feature */
	  continue;  
       sscanf(buffer,"-COORDS %lf %lf",&x,&y);
       pNewPoint = calloc(1,sizeof(POINT_T));
       if (pNewPoint == NULL)
	  {
	  printf("Error allocating point structure (%lf,%lf)\n",x,y);
	  return -1;
	  }
       pNewPoint->x = (int) x;
       pNewPoint->y = (int) y;
       pNewLine->pointCount++;
       /* add to list on the feature */
       if (pNewLine->first == NULL)
	  {
	  pNewLine->first = pNewPoint;
          }
       else
	  {
	  pNewLine->last->next = pNewPoint;
	  pNewPoint->prev = pNewLine->last;
	  }
       pNewLine->last = pNewPoint;
       }
    else if (strncmp(buffer,END,strlen(END)) == 0)
       {
       break;
       }  
    }
    return count;
}
/* Read features from a Dragon vector file into memory, 
 * into a dynamically allocated array that can be sorted.
 * @param featureArray   Dynamically allocated array of FEATURE_T* 
 *                       big enough to hold all features in file
 * @param pIn            Pointer to open input file
 * @param arraySize      Capacity of the featureArray - used for error checks
 * @return number of features successfully read or -1 if an error occurs.
 */
Read features from a Dragon vector file into memory,
into a dynamically allocated array that can be sorted.
@param featureArray   Dynamically allocated array of FEATURE_T
big enough to hold all features in file
@param pIn            Pointer to open input file
@param arraySize      Capacity of the featureArray - used for error checks
@return number of features successfully read or -1 if an error occurs.
Read features from a Dragon vector file into memory into a dynamically allocated array that can be sorted . @param featureArray Dynamically allocated array of FEATURE_T big enough to hold all features in file @param pIn Pointer to open input file @param arraySize Capacity of the featureArray - used for error checks @return number of features successfully read or - 1 if an error occurs .
int readFeatures(FEATURE_T* featureArray[], FILE* pIn, int arraySize)
{
#define FIGURE "-FIGURE"
#define COORDS "-COORDS"
#define END "-END"
  int count = 0;
  POINT_T * pNewPoint = NULL;
  FEATURE_T* pNewLine = NULL;
  double x = 0;
  double y = 0;
  char buffer[128];
  while (fgets(buffer,sizeof(buffer),pIn) != NULL)
    {
    if (strncmp(buffer,FIGURE,strlen(FIGURE)) == 0)  
       {
       if (count >= arraySize)
	  continue;  
       pNewLine = calloc(1,sizeof(FEATURE_T));
       if (pNewLine == NULL)
	  {
	  printf("Error allocating feature %d\n",count);
	  return -1;
	  }
       featureArray[count] = pNewLine;
       count++;
       }  
    else if (strncmp(buffer,COORDS,strlen(COORDS)) == 0)
       {
       if (count > arraySize) 
	  continue;  
       sscanf(buffer,"-COORDS %lf %lf",&x,&y);
       pNewPoint = calloc(1,sizeof(POINT_T));
       if (pNewPoint == NULL)
	  {
	  printf("Error allocating point structure (%lf,%lf)\n",x,y);
	  return -1;
	  }
       pNewPoint->x = (int) x;
       pNewPoint->y = (int) y;
       pNewLine->pointCount++;
       if (pNewLine->first == NULL)
	  {
	  pNewLine->first = pNewPoint;
          }
       else
	  {
	  pNewLine->last->next = pNewPoint;
	  pNewPoint->prev = pNewLine->last;
	  }
       pNewLine->last = pNewPoint;
       }
    else if (strncmp(buffer,END,strlen(END)) == 0)
       {
       break;
       }  
    }
    return count;
}
int readFeatures ( FEATURE_T * featureArray [ ] , FILE * pIn , int arraySize ) { #define FIGURE  "-FIGURE" #define COORDS  "-COORDS" #define END  "-END" int count = 0 ; POINT_T * pNewPoint = NULL ; FEATURE_T * pNewLine = NULL ; double x = 0 ; double y = 0 ; char buffer [ 128 ] ; while ( fgets ( buffer , sizeof ( buffer ) , pIn ) != NULL ) { if ( strncmp ( buffer , FIGURE , strlen ( FIGURE ) ) == 0 ) { if ( count >= arraySize ) continue ; pNewLine = calloc ( 1 , sizeof ( FEATURE_T ) ) ; if ( pNewLine == NULL ) { printf ( " \n " , count ) ; return -1 ; } featureArray [ count ] = pNewLine ; count ++ ; } else if ( strncmp ( buffer , COORDS , strlen ( COORDS ) ) == 0 ) { if ( count > arraySize ) continue ; sscanf ( buffer , " " , & x , & y ) ; pNewPoint = calloc ( 1 , sizeof ( POINT_T ) ) ; if ( pNewPoint == NULL ) { printf ( " \n " , x , y ) ; return -1 ; } pNewPoint -> x = ( int ) x ; pNewPoint -> y = ( int ) y ; pNewLine -> pointCount ++ ; if ( pNewLine -> first == NULL ) { pNewLine -> first = pNewPoint ; } else { pNewLine -> last -> next = pNewPoint ; pNewPoint -> prev = pNewLine -> last ; } pNewLine -> last = pNewPoint ; } else if ( strncmp ( buffer , END , strlen ( END ) ) == 0 ) { break ; } } return count ; }
Read features from a Dragon vector file into memory,
 into a dynamically allocated array that can be sorted.
Read features from a Dragon vector file into memory into a dynamically allocated array that can be sorted .
/* start of a new feature */ /* still read but don't store */ /* note pure inequality here */ /* want to be sure we read the points for the last feature */ /* add to list on the feature */