#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <conio.h>


double nag_dmc_rng(long seed[]);

void nag_dmc_srs(long iseed, long seed[]);

void nag_dmc_rints(long wrps, long n, long l, long u, long ints[], long seed[],
				   long info[1]);
void nag_rank(double data[], long n, long start, long step, long rank[]);

void nag_rank_int(long idata[], long n, long start, long step, long rank[]);

int nag_index(long rank[], long n);

void nag_order(double data[],long n, long start, long step, long rank[]);

void calc_ss(long n, long m, long *sx, double *data, double *wt, double *mean, double *ssc, 
             double *sum_wts, long info[2]);

void tsolve(long trans, long n, double *ap, double *x);

void chol_p(long n, double *c, long info[2]);

void gam_prob(double a, double x, double tol, double *p, double *q, 
            long info[2]);

double gam_ppt(double p, double a, double b, double tol, long info[2]);

double normal_ppt(double p, long info[2]);

int get_prec(double x);

long near_int(double x);

void list_names(long *ptr, long n, long i, char *i_name);

void free_list(long *ptr, long n);

void get_names(long *ptr, long i, char i_name[250]);

void alloc_names(long *ptr, long n, long i, long m);

void data_conv(char *dname, char *ifname, char *xmlfname,char *xlsfname, char *xdrfname, 
              long n, long m, long del_type, double v_bound,
			  long head, char **v_name, long v_type[], long n_cat[], 
			  long cat_val[], long max_cat, long info[2]);

void summ_stats(long n, long m, double miss_val, double *data, long * n_cat, 
                long *cat_vals, long max_cat, double *mean, double *sd, 
                double *vmin, double *vmax, long *n_valid, double *mid_pts, long *counts, 
                long info[2]);

void bar_chart(char *gname, long m, char **v_name, long *n_cat, long *cat_val, long *counts, 
              long max_cat, double *scale, long *height, long info[2]);

long rmqd(char *stng, long delchar);

void read_rep(char *report_name, long mode, long *nrecs, long *nerrors, long *irow, 
                long *icol, long info[2]);

void xml_read(char *xmlfname,char *xdrfname,double miss_val,long n, long m, 
              double *data, char **v_name, long *n_cat, long *cat_val, long maxcat, 
              long mset, long *nmiss, long info[2]);

void xml_data_size(char *xdrfname, long *n_obs, long *n_var, long *max_name,
              long info[2]);

void gemimp(long srtype[3], long rand_select, long n_match, long match_all, long reuse, 
            double min_wt, double *wts, double *R, long *dist_type, double *user_dist, 
            long num_obs, long m, double *data, long *n_cat, long *cat_val, long maxcat, 
            double miss_val, long *num_imp, long *obs_num, long *var_num, 
            double *rep_val, long info[5]);

void simp(long n, long m, double *data, long *n_cat, long *cat_val, long maxcat, 
          double miss_val, long *nimp, long *irow, long *icol, double *rval, long info[2]);

void bacon(long n, long m, long *sx, double *data, double miss_val, long c, double alpha, 
           long method, double *indwt, double *swts, long info[2]);

void xml_update(char *xmlfname,char *xdrfname, char *xslfname, double miss_val,long n, 
                long m, long u_date, long nrepl, long *irow, long *icol, double *rval, long info[2]);

void xml_read_s(char *xmlfname,char *xdrfname,double miss_val,long n, long m, 
              double *data, long *st, long info[2]);

void em(long num, long m, long *sx, double *x, double miss_val, double tol, long max_cycle, 
        double *swts, long *nrepl, long *missing_row, long *missing_col, 
        double *repl_val, long info[2]);

void chol_2(long n, double *a, long tda, double *p, double *detf, 
            long *dete, long info[2]);

void ssolve_2(long n, long nrhs, double *a, long tda, double *p, 
            double *b, long tdb, double *x, long tdx, long info[2]);

#define MAXK 250

#define MAXT 33

union miss_type	{
			int fromrtoi[4];
			double amiss;
		} ; 


/* Max record width */

#define MAX_REC 10000

#define FILE_NAME_WDTH 120
