/* cdflib.h: header file for cdflib.c

Copyright (C) 2003 Allen B. Downey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

typedef struct {
  int rows, cols;
  double **m;
} Matrix;

typedef struct vector {
  int n, size;
  float *x;
} Vector;

typedef struct cdf {
  int n, size;
  float *x, *y;
} Cdf;

Matrix *make_matrix (int rows, int cols);
void print_matrix (Matrix *matrix);
Vector *read_file (char *file_name);
Vector *make_vector (int size);
void clear_vector (Vector *vector);
void free_vector (Vector *vector);
void add_to_vector (Vector *vector, double x);
double random_from_vector (Vector *vector);
Vector *subtract_vector (Vector *a, Vector *b);
void sort_vector (Vector *vector);
Vector *copy_vector (Vector *v);
Vector *difference_vector (Vector *v);
void print_vector_fp (Vector *vector, FILE *fp);
void print_vector (Vector *vector);
void print_vectori_fp (Vector *vector, FILE *fp);
void print_vectori (Vector *vector);
Cdf *make_cdf (int size);
void free_cdf (Cdf *cdf);
void print_cdf (Cdf *cdf);
void print_cdf_fp (Cdf *cdf, FILE *fp);
Cdf *calc_cdf (Vector *vector);
void round_cdf (Cdf *cdf, int n);
void uniq_cdf (Cdf *cdf);
void transform_cdf_logx (Cdf *cdf);
void transform_cdf_logy (Cdf *cdf);
void transform_cdf_norm (Cdf *cdf);
void multiply_cdf (Cdf *cdf, double x, double y);
double percentile_to_value (double y, Cdf *cdf);
int value_to_percentile (double x, Cdf *cdf, double *interval);
double value_to_rand_percentile (double x, Cdf *cdf);
int compar (const void *px, const void *py);
void sort_array (float x[], int n);
Cdf *qqplot (Cdf *cdf, Cdf *dist);
Cdf *ppplot (Cdf *cdf, Cdf *dist);
double calc_avg (float x[], int n);
double calc_var (float x[], int n, double mean);
double log2 (double x);
