Пример #1
0
VIOAPI Status  mni_input_keyword_and_equal_sign(
    FILE         *file,
    const char   keyword[],
    BOOLEAN     print_error_message )
{
    Status     status;
    STRING     str;

    status = mni_input_string( file, &str, (char) '=', (char) 0 );

    if( status == END_OF_FILE )
        return( status );

    if( status != OK || !equal_strings( str, (STRING) keyword ) ||
        mni_skip_expected_character( file, (char) '=' ) != OK )
    {
        if( print_error_message )
            print_error( "Expected \"%s =\"\n", keyword );
        status = ERROR;
    }

    delete_string( str );

    return( status );
}
Пример #2
0
VIOAPI  VIO_Status  initialize_tag_file_input(
    FILE      *file,
    int       *n_volumes_ptr )
{
    VIO_STR  line;
    int     n_volumes;

    /* parameter checking */

    if( file == NULL )
    {
        print_error( "initialize_tag_file_input(): passed NULL FILE ptr.\n");
        return( VIO_ERROR );
    }

    /* okay read the header */

    if( mni_input_string( file, &line, (char) 0, (char) 0 ) != VIO_OK ||
        !equal_strings( line, (VIO_STR) TAG_FILE_HEADER ) )
    {
        print_error( "input_tag_points(): invalid header in file.\n");
        delete_string( line );
        return( VIO_ERROR );
    }

    delete_string( line );

    /* now read the number of volumes */

    if( mni_input_keyword_and_equal_sign( file, VOLUMES_STRING, TRUE ) != VIO_OK )
        return( VIO_ERROR );

    if( mni_input_int( file, &n_volumes ) != VIO_OK )
    {
        print_error( "input_tag_points(): expected # volumes after %s.\n",
                     VOLUMES_STRING );
        return( VIO_ERROR );
    }

    if( mni_skip_expected_character( file, (char) ';' ) != VIO_OK )
        return( VIO_ERROR );

    if( n_volumes != 1 && n_volumes != 2 )
    {
        print_error( "input_tag_points(): invalid # volumes: %d \n",
                     n_volumes );
        return( VIO_ERROR );
    }

    /* now read the tag points header */

    if( mni_input_keyword_and_equal_sign( file, TAG_POINTS_STRING, TRUE ) != VIO_OK)
        return( VIO_ERROR );

    if( n_volumes_ptr != NULL )
        *n_volumes_ptr = n_volumes;

    return( VIO_OK );
}
Пример #3
0
VIOAPI Status  mni_input_int(
    FILE    *file,
    int     *i )
{
    Status status;
    STRING   str;

    status = mni_input_string( file, &str, (char) ' ', (char) ';' );

    if( status == OK && sscanf( str, "%d", i ) != 1 )
    {
        unget_string( file, str );
        status = ERROR;
    }

    delete_string( str );

    return( status );
}
Пример #4
0
VIOAPI Status  mni_input_real(
    FILE    *file,
    Real    *d )
{
    Status   status;
    STRING   str;

    status = mni_input_string( file, &str, (char) ' ', (char) ';' );

    if( status == OK && sscanf( str, "%lf", d ) != 1 )
    {
        unget_string( file, str );
        status = ERROR;
    }

    delete_string( str );

    return( status );
}
Пример #5
0
/* reads in a Kernel from a file                        */
VIO_Status input_kernel(const char *kernel_file, Kernel * kernel)
{
   int      i, j;

   VIO_STR   line;
   VIO_STR   type_name;
   VIO_STR   str;
   VIO_Real     tmp_real;
   FILE    *file;

   /* parameter checking */
   if(kernel_file == NULL){
      print_error("input_kernel(): passed NULL FILE.\n");
      return (VIO_ERROR);
      }

   file = fopen(kernel_file, "r");
   if(file == NULL){
      print_error("input_kernel(): error opening Kernel file.\n");
      return (VIO_ERROR);
      }

   /* okay read the header */
   if(mni_input_string(file, &line, (char)0, (char)0) != VIO_OK){
      delete_string(line);
      print_error("input_kernel(): could not read header in file.\n");
      return (VIO_ERROR);
      }

   if(!equal_strings(line, KERNEL_FILE_HEADER)){
      delete_string(line);
      print_error("input_kernel(): invalid header in file.\n");
      return (VIO_ERROR);
      }

   /* --- read the type of Kernel */
   if(mni_input_keyword_and_equal_sign(file, KERNEL_TYPE, FALSE) != VIO_OK){
      return (VIO_ERROR);
      }

   if(mni_input_string(file, &type_name, (char)';', (char)0) != VIO_OK){
      print_error("input_kernel(): missing kernel type.\n");
      return (VIO_ERROR);
      }

   if(mni_skip_expected_character(file, (char)';') != VIO_OK){
      return (VIO_ERROR);
      }

   if(!equal_strings(type_name, NORMAL_KERNEL)){
      print_error("input_kernel(): invalid kernel type.\n");
      delete_string(type_name);
      return (VIO_ERROR);
      }
   delete_string(type_name);

   /* --- read the next string */
   if(mni_input_string(file, &str, (char)'=', (char)0) != VIO_OK)
      return (VIO_ERROR);

   if(!equal_strings(str, KERNEL)){
      print_error("Expected %s =\n", KERNEL);
      delete_string(str);
      return (VIO_ERROR);
      }
   delete_string(str);

   if(mni_skip_expected_character(file, (char)'=') != VIO_OK){
      return (VIO_ERROR);
      }

   /* now read the elements (lines) of the kernel */
   if(verbose){
      fprintf(stderr, "Reading [%s]", kernel_file);
      }
   for(i = 0; i < MAX_KERNEL_ELEMS; i++){

      /* allocate a bit of memory */
      SET_ARRAY_SIZE(kernel->K, kernel->nelems, kernel->nelems + 1, 10);
      ALLOC(kernel->K[i], KERNEL_DIMS + 1);

      /* get the 5 dimension vectors and the coefficient */
      for(j = 0; j < 6; j++){
         if(mni_input_real(file, &tmp_real) == VIO_OK){
            kernel->K[i][j] = tmp_real;
            }
         else {
            /* check for end */
            if(mni_skip_expected_character(file, (char)';') == VIO_OK){
               kernel->nelems = i;
               if(verbose){
                  fprintf(stderr, " %dx%d Kernel elements read\n", i, kernel->nelems);
                  }
               return (VIO_OK);
               }
            else {
               print_error("input_kernel(): error reading kernel [%d,%d]\n", i + 1,
                           j + 1);
               return (VIO_ERROR);
               }
            }
         }
      kernel->nelems++;

      if(verbose){
         fprintf(stderr, ".");
         fflush(stderr);
         }
      }

   /* SHOLDN'T BE REACHED */
   print_error("input_kernel(): Glark! Something is amiss in the State of Kansas\n");
   return (VIO_ERROR);
   }