Example #1
0
void fortio_copy_record(fortio_type * src_stream , fortio_type * target_stream , int buffer_size , void * buffer , bool *at_eof) {
  int bytes_read;
  int record_size = fortio_init_read(src_stream); 
  fortio_init_write(target_stream , record_size);

  bytes_read = 0;
  while (bytes_read < record_size) {
    int bytes;
    if (record_size > buffer_size)
      bytes = buffer_size;
    else
      bytes = record_size - bytes_read;

    util_fread(buffer , 1 , bytes , src_stream->stream     , __func__);
    util_fwrite(buffer , 1 , bytes , target_stream->stream , __func__);
    
    bytes_read += bytes;
  }

  fortio_complete_read(src_stream);
  fortio_complete_write(target_stream);

  if (feof(src_stream->stream))
    *at_eof = true;
  else
    *at_eof = false;
}
Example #2
0
static int ecl_util_get_num_parallel_cpu__(parser_type* parser, FILE* stream, const char * data_file) {
  int num_cpu = 1;
  char * buffer;  
  long int start_pos = util_ftell( stream );
  int buffer_size;

  /* Look for terminating '/' */
  if (!parser_fseek_string( parser , stream , "/" , false , true))
    util_abort("%s: sorry - could not find \"/\" termination of PARALLEL keyword in data_file: \n",__func__ , data_file);

  buffer_size = (util_ftell(stream) - start_pos)  ;
  buffer = util_calloc( buffer_size + 1  , sizeof * buffer );
  util_fseek( stream , start_pos , SEEK_SET);
  util_fread( buffer , sizeof * buffer , buffer_size ,stream ,  __func__);
  buffer[buffer_size] = '\0';

  {
    stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true );
    
    if (stringlist_get_size( tokens ) > 0) {
      const char * num_cpu_string = stringlist_iget( tokens , 0 );
      if (!util_sscanf_int( num_cpu_string , &num_cpu))
        fprintf(stderr,"** Warning: failed to interpret:%s as integer - assuming one CPU\n",num_cpu_string);
    } else
      fprintf(stderr,"** Warning: failed to load data for PARALLEL keyword - assuming one CPU\n");

    stringlist_free( tokens );
  }  
  free( buffer );
  return num_cpu; 
}
Example #3
0
void * fortio_fread_alloc_record(fortio_type * fortio) {
  void * buffer;
  fortio_init_read(fortio);
  buffer = util_malloc(fortio->active_header );
  util_fread(buffer , 1 , fortio->active_header , fortio->stream , __func__);
  fortio_complete_read(fortio);
  return buffer;
}
Example #4
0
/*
  Observe that this function will reset the default value. 
*/
void @TYPE@_vector_fread( @TYPE@_vector_type * vector , FILE * stream ) {
  @TYPE@     default_value;
  int size = util_fread_int( stream );
  util_fread( &default_value , sizeof default_value , 1 , stream , __func__);
  {
    @TYPE@_vector_set_default( vector , default_value );
    @TYPE@_vector_fread_data( vector , size , stream );
  }
}
Example #5
0
int fortio_fread_record(fortio_type *fortio, char *buffer) {
  fortio_init_read(fortio);
  {
    int record_size = fortio->active_header; /* This is reset in fortio_complete_read - must store it for the return. */
    util_fread(buffer , 1 , fortio->active_header , fortio->stream , __func__);
    fortio_complete_read(fortio);
    return record_size;
  }
}
Example #6
0
void buffer_stream_fread( buffer_type * buffer , size_t byte_size , FILE * stream) {
  size_t min_size = byte_size + buffer->pos;
  if (buffer->alloc_size < min_size)
    buffer_resize__(buffer , min_size , true);

  util_fread( &buffer->data[buffer->pos] , 1 , byte_size , stream , __func__);

  buffer->content_size += byte_size;
  buffer->pos          += byte_size;
}
Example #7
0
void matrix_fread(matrix_type * matrix , FILE * stream) {
  int rows    = util_fread_int( stream );
  int columns = util_fread_int( stream );

  matrix_resize( matrix , rows , columns , false);
  if (matrix->column_stride == matrix->rows)
    util_fread( matrix->data , sizeof * matrix->data , matrix->columns * matrix->rows , stream , __func__);
  else {
    int column;
    for (column=0; column < matrix->columns; column++) {
      if (matrix->row_stride == 1) {
        double * column_data = &matrix->data[ column * matrix->column_stride ];
        util_fread( column_data , sizeof * column_data , matrix->rows , stream , __func__);
      } else {
        int row;
        for (row=0; row < matrix->rows; row++)
          matrix->data[ GET_INDEX( matrix , row , column )] = util_fread_double( stream );
      }
    }
  }
}
Example #8
0
time_t ecl_util_get_start_date(const char * data_file) { 
  parser_type * parser = parser_alloc(" \t\r\n" , "\"\'" , NULL , NULL , "--" , "\n");
  time_t start_date  = -1;
  FILE * stream      = util_fopen(data_file , "r");
  char * buffer;
  
  if (!parser_fseek_string( parser , stream , "START" , true , true))   /* Seeks case insensitive. */
    util_abort("%s: sorry - could not find START in DATA file %s \n",__func__ , data_file);
  
  {
    long int start_pos = util_ftell( stream );
    int buffer_size;

    /* Look for terminating '/' */
    if (!parser_fseek_string( parser , stream , "/" , false , true))
      util_abort("%s: sorry - could not find \"/\" termination of START keyword in data_file: \n",__func__ , data_file);
    
    buffer_size = (util_ftell(stream) - start_pos)  ;
    buffer = util_calloc( buffer_size + 1 , sizeof * buffer  );
    util_fseek( stream , start_pos , SEEK_SET);
    util_fread( buffer , sizeof * buffer , buffer_size ,stream ,  __func__);
    buffer[buffer_size] = '\0';
  }
  
  
  {
    stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true );
    int day, year, month_nr;
    if ( util_sscanf_int( stringlist_iget( tokens , 0 ) , &day)   &&   util_sscanf_int( stringlist_iget(tokens , 2) , &year)) {
      month_nr   = ecl_util_get_month_nr(stringlist_iget( tokens , 1));
      start_date = ecl_util_make_date(day , month_nr , year );
    } else
      util_abort("%s: failed to parse DAY MONTH YEAR from : \"%s\" \n",__func__ , buffer);
    stringlist_free( tokens );
  }
  
  free( buffer );
  parser_free( parser );
  fclose(stream);
  
  return start_date;
}
Example #9
0
/*
  This function does not consider the default value; it does a
  vector_resize based on the input size.
*/
void @TYPE@_vector_fread_data( @TYPE@_vector_type * vector , int size, FILE * stream) {
  @TYPE@_vector_realloc_data__( vector , size );
  util_fread( vector->data , sizeof * vector->data , size , stream , __func__);
  vector->size = size;
}