deps/kb_meme/meme-5.0.1/src/prior-dist.c
/***********************************************************************
 * Read an array of unknown length from a file.
 * Caller is resposbile for freeing array.
 ***********************************************************************/
Read an array of unknown length from a file.
Caller is resposbile for freeing array.
Read an array of unknown length from a file . Caller is resposbile for freeing array .
ARRAY_T *read_priors_from_file(
  const char* filename, 
  double *min,
  double *max,
  double *median
) {
  FILE *array_file = fopen(filename, "r");
  if (array_file == NULL) {
    die(
      "Unable to open file: %s.\nError message: %s.\n", 
      filename, 
      strerror(errno)
    );
  }
  int num_read = 0;
  num_read = fscanf(array_file, "#min %lf\n", min);
  if (num_read != 1) {
    die("Minimum prior not found in file %s\n", filename);
  }
  num_read = fscanf(array_file, "#max %lf\n", max);
  if (num_read != 1) {
    die("Maximum prior not found in file %s\n", filename);
  }
  num_read = fscanf(array_file, "#median %lf\n", median);
  if (num_read != 1) {
    die("Median prior not found in file %s\n", filename);
  }
  ATYPE value;
  int array_size = 100;
  ARRAY_T *array = allocate_array(array_size);
  int i_item = 0;
  while ((num_read = fscanf(array_file, ASCAN, &value)) == 1) {
    set_array_item(i_item, value, array);
    ++i_item;
    if (i_item >= array_size) {
      resize_array(array, 2 * array_size);
      array_size = 2 *array_size;
    }
  }
  if (num_read == 0) {
    die("Error reading array at position %d.\n", i_item);
  }
  fclose(array_file);
  resize_array(array, i_item);
  return array;
}
ARRAY_T * read_priors_from_file ( const char * filename , double * min , double * max , double * median ) { FILE * array_file = fopen ( filename , " " ) ; if ( array_file == NULL ) { die ( " \n \n " , filename , strerror ( errno ) ) ; } int num_read = 0 ; num_read = fscanf ( array_file , " \n " , min ) ; if ( num_read != 1 ) { die ( " \n " , filename ) ; } num_read = fscanf ( array_file , " \n " , max ) ; if ( num_read != 1 ) { die ( " \n " , filename ) ; } num_read = fscanf ( array_file , " \n " , median ) ; if ( num_read != 1 ) { die ( " \n " , filename ) ; } ATYPE value ; int array_size = 100 ; ARRAY_T * array = allocate_array ( array_size ) ; int i_item = 0 ; while ( ( num_read = fscanf ( array_file , ASCAN , & value ) ) == 1 ) { set_array_item ( i_item , value , array ) ; ++ i_item ; if ( i_item >= array_size ) { resize_array ( array , 2 * array_size ) ; array_size = 2 * array_size ; } } if ( num_read == 0 ) { die ( " \n " , i_item ) ; } fclose ( array_file ) ; resize_array ( array , i_item ) ; return array ; }
Read an array of unknown length from a file.
Read an array of unknown length from a file .
// Prior dist files being with min, max, and median // The remaining values are the frequencies for each bin.