[Mistat-cvs] mistat/src cmdline.c,1.7,1.8 error.c,1.8,1.9 error.h,1.6,1.7 file_ops.c,1.10,1.11 file_
Status: Pre-Alpha
Brought to you by:
bikepunk005
|
From: Mike H. B. <bik...@us...> - 2004-05-29 18:22:37
|
Update of /cvsroot/mistat/mistat/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14891/src Modified Files: cmdline.c error.c error.h file_ops.c file_ops.h main.c main.h menu.c menu.h output.c statistics.c statistics.h Log Message: Added ability to read files that have float and int or just one. Not 100% on printing variable number. Some cleanup of function calls, and other housekeeping. Index: file_ops.h =================================================================== RCS file: /cvsroot/mistat/mistat/src/file_ops.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** file_ops.h 30 Mar 2004 15:49:48 -0000 1.9 --- file_ops.h 29 May 2004 18:22:23 -0000 1.10 *************** *** 31,34 **** --- 31,38 ---- #define MAXROWS 131073 #define MAXCOLS 400 /*Current limit of max. data file cols (variables) */ + /* Defines used for Data_Type. */ + #define INT_DATA 1 + #define FLOAT_DATA 2 + #define CHAR_DATA 3 /* *************** *** 41,47 **** int getwords (char *line, char *words[], int maxwords); int fgetline (FILE * fp, char line[], int max); ! void view_log_file (); void update_logfile (char *message); ! int getit (FILE * file_name, int element, int t[]); /* --- 45,51 ---- int getwords (char *line, char *words[], int maxwords); int fgetline (FILE * fp, char line[], int max); ! void view_log_file (void); void update_logfile (char *message); ! int getit (FILE * file_name, int element, long double t[]); /* *************** *** 50,53 **** --- 54,62 ---- extern int nrows; /*number of rows in data file */ extern int columns; /*number of columns in a data file */ + /* + * Data_Type is an array containing the type of data for each respective variable. + * 1 is int, 2 is float, 3 is character. + */ + extern int Data_Type[]; #endif Index: error.h =================================================================== RCS file: /cvsroot/mistat/mistat/src/error.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** error.h 30 Mar 2004 15:49:48 -0000 1.6 --- error.h 29 May 2004 18:22:23 -0000 1.7 *************** *** 26,30 **** * Prototypes */ ! void set_signals (); void signal_abrt (int sig_value); void signal_fpe (int sig_value); --- 26,30 ---- * Prototypes */ ! void set_signals (void); void signal_abrt (int sig_value); void signal_fpe (int sig_value); Index: file_ops.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/file_ops.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** file_ops.c 30 Mar 2004 15:49:48 -0000 1.10 --- file_ops.c 29 May 2004 18:22:23 -0000 1.11 *************** *** 1,20 **** ! /* File operatins for mistat. ! Copyright (C) 2003, 2004 Mike H. Benton ! Mike H. Benton <bik...@us...>, 2003. ! 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. */ --- 1,20 ---- ! /* File operations for mistat. ! Copyright (C) 2003, 2004 Mike H. Benton ! Mike H. Benton <bik...@us...>, 2003. ! 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. */ *************** *** 24,28 **** #include <stdio.h> #include <stdlib.h> ! #include <ctype.h> #include <string.h> --- 24,28 ---- #include <stdio.h> #include <stdlib.h> ! #include <ctype.h> /* Conversions and class testing. */ #include <string.h> *************** *** 34,37 **** --- 34,39 ---- int nrows; /*The number of rows in the data file */ int columns; /*The number of columns in the data file */ + int Data_Type[MAXCOLS]; /* The type of data for each variable. */ + void printline (FILE * fp); *************** *** 45,56 **** if (fclose (fp) == 0) ! printf ("\t\t%s closed succesfully!\n", file_name); else printf ("\t\t%s did not close\n", file_name); - return; - - } --- 47,55 ---- if (fclose (fp) == 0) ! printf ("\t\t%s closed successfully!\n", file_name); else printf ("\t\t%s did not close\n", file_name); } *************** *** 58,62 **** * Opens file_name as a file. * Returns a file pointer. ! * need to add type of flag input */ FILE * --- 57,61 ---- * Opens file_name as a file. * Returns a file pointer. ! * FIXME: need to add type of flag input */ FILE * *************** *** 74,77 **** --- 73,82 ---- fp = fopen (file_name, "w+"); + else + { + printf ("ERROR: invalid open_mode in open_file!\n"); + exit (EXIT_FAILURE); + } + if (fp == NULL) fprintf (stderr, "\t\tCannot open %s!\n\t\tERROR: %s!\n", file_name, *************** *** 82,101 **** return fp; } /* * Returns void. ! * Just count rows, and columns for now. ! * Add file type (tab or , delimiting, tab default). ! * Add variable label. ! * Add auto input type, now just numbers. * Calls fgetline () and getwords(). ! * Need to set blank to missing. ! * Need to define missing! ! * Reads data that is not there, as above ! * Reads . as a line!!!!! */ - - /*needs lots o work*/ void read_data_file (FILE * file_name) --- 87,101 ---- return fp; + } /* * Returns void. ! * Counts the number of cases, and sets VARIABLE_TYPE. * Calls fgetline () and getwords(). ! * ! * FIXME: Need to set blank to missing. Need to define missing! Reads data that is not there, as above ! * FIXME: Reads . as a line!!!!! */ void read_data_file (FILE * file_name) *************** *** 115,119 **** "\n\nDatafile is not open for some reason?\n\nFatal ERROR: %s\n\n", strerror (errno)); ! exit (EXIT_FAILURE); } --- 115,119 ---- "\n\nDatafile is not open for some reason?\n\nFatal ERROR: %s\n\n", strerror (errno)); ! nrows = columns = -1; /* Set to -1 for error checks elsewhere. */ } *************** *** 139,145 **** --- 139,147 ---- } } + printf ("\nThere are %d rows (cases)\n\tand %d columns (variables) in the data set\n", nrows, columns); + } *************** *** 154,181 **** { char *p = line; ! int nwords = 0; while (1) { while (isspace (*p)) p++; if (*p == '\0') return nwords; words[nwords++] = p; while (!isspace (*p) && *p != '\0') ! p++; if (*p == '\0') return nwords; ! *p++ = '\0'; ! if (nwords >= maxwords) return nwords; } } --- 156,246 ---- { + bool is_int, is_float, is_char; char *p = line; ! int nwords, testing, location; ! ! nwords = 0; + /* Infinite. Break within. */ while (1) { + /* Set to false for first run of word. */ + is_int = is_float = is_char = false; + + /* If a space, go until not. */ while (isspace (*p)) p++; + /* If end of line, go home with results. */ if (*p == '\0') return nwords; + location = nwords; words[nwords++] = p; + /* + * Cycle through until end or separator. + * Test to determine type of data. + */ while (!isspace (*p) && *p != '\0') ! { ! testing = isdigit (*p); ! ! if (is_int == true && *p == '.' && is_float == false) ! { ! is_float = true; ! is_int = false; ! } ! ! else if (is_float == false && is_int == false && is_char == false ! && testing != 0) ! { ! is_int = true; ! } + else if (is_float == false && is_char == false && *p == '.') + is_float = true; + + else if (testing == 0) + { + is_char = true; + is_int = false; + is_float = false; + } + + p++; + + } + + /* Set the Data_Type. */ + if (is_float == true && Data_Type[location] != CHAR_DATA) + { + Data_Type[location] = FLOAT_DATA; + } + + if (is_int == true + && (Data_Type[location] != CHAR_DATA + || Data_Type[location] != FLOAT_DATA)) + { + Data_Type[location] = INT_DATA; + } + + if (is_char == true) + { + Data_Type[location] = CHAR_DATA; + } + + /* If end, go back. */ if (*p == '\0') return nwords; ! /* Need and error here. */ if (nwords >= maxwords) return nwords; + + /*We need to go back look at next word. */ + p++; } + } *************** *** 214,217 **** --- 279,283 ---- line[nch] = '\0'; return nch; + } *************** *** 223,227 **** void ! view_log_file () { --- 289,293 ---- void ! view_log_file (void) { *************** *** 233,237 **** /* ! * Currenly print a file. */ --- 299,303 ---- /* ! * Currently print a file. */ *************** *** 244,248 **** printf ("%s", s); - } --- 310,313 ---- *************** *** 284,288 **** int ! getit (FILE * file_name, int element, int t[]) { static FILE *temp_fp; /*used for passing between read functions */ --- 349,353 ---- int ! getit (FILE * file_name, int element, long double t[]) { static FILE *temp_fp; /*used for passing between read functions */ *************** *** 332,334 **** --- 397,400 ---- return 1; + } Index: error.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/error.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** error.c 17 May 2004 17:22:20 -0000 1.8 --- error.c 29 May 2004 18:22:23 -0000 1.9 *************** *** 33,37 **** void ! set_signals () { signal (SIGABRT, signal_abrt); --- 33,37 ---- void ! set_signals (void) { signal (SIGABRT, signal_abrt); Index: cmdline.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/cmdline.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** cmdline.c 25 Apr 2004 22:30:43 -0000 1.7 --- cmdline.c 29 May 2004 18:22:23 -0000 1.8 *************** *** 94,98 **** { ! int i; for (i = 0; i < args_info->inputs_num; ++i) --- 94,98 ---- { ! unsigned i; for (i = 0; i < args_info->inputs_num; ++i) Index: statistics.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/statistics.c,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** statistics.c 22 May 2004 06:33:02 -0000 1.31 --- statistics.c 29 May 2004 18:22:23 -0000 1.32 *************** *** 34,38 **** #include "error.h" /*Calls to error routines (so called custom). */ ! #include "file_ops.h" /*Calls to data file for matrix or vector building. */ #include "statistics.h" --- 34,38 ---- #include "error.h" /*Calls to error routines (so called custom). */ ! #include "file_ops.h" /*Calls to data file for matrix or vector building, and Data_Type. */ #include "statistics.h" *************** *** 47,51 **** bool make_vector (int row); /* Create vector of variable row. */ ! bool make_matrix (int x[]); /* Create matrix of variables stored in x. */ /* --- 47,51 ---- bool make_vector (int row); /* Create vector of variable row. */ ! bool make_matrix (int x[], bool type, int how_much); /* Create matrix of variables stored in x. */ /* *************** *** 55,63 **** */ bool ! stats_main (int x[], bool vector) { int variable; /* Only used in vector. */ bool verified; /* Status of making vector or matrix. */ ! verified = false; /* Set as false, called proceures will change to true if succesful. */ if (vector) /* Make a vector. */ --- 55,63 ---- */ bool ! stats_main (int x[], bool vector, bool type, int how_much) { int variable; /* Only used in vector. */ bool verified; /* Status of making vector or matrix. */ ! verified = false; /* Set as false, called proceures will change to true if succesful. */ if (vector) /* Make a vector. */ *************** *** 69,73 **** else /* Make a matrix. */ { ! verified = make_matrix (x); } --- 69,73 ---- else /* Make a matrix. */ { ! verified = make_matrix (x, type, how_much); } *************** *** 86,121 **** */ bool ! get_mean (bool is_vector, int index, long double results[]) { int sum; if (is_vector) /*Just get moments for one variable. */ { - results[0] = mean_int_vector (vta, index, nrows, &sum); - results[1] = var_int_vector (vta, &results[0], index, nrows); - results[2] = skewness_int_vector (vta, &results[1], &results[0], nrows); - results[3] = kurtosis_int_vector (vta, &results[1], &results[0], nrows); } else /*Get moments from matrix. */ { ! results[0] = mean_int_matrix (mta, index, nrows, &sum); ! results[1] = var_int_matrix (mta, &results[0], index, nrows); ! results[2] = skewness_int_matrix (mta, index, &results[1], &results[0], nrows); ! results[3] = kurtosis_int_matrix (mta, index, &results[1], &results[0], nrows); ! } ! results[4] = sum; ! return true; } /* ! * Sorted type statistics and tails. ! */ bool ! get_sorted_stats (bool is_vector, int index, long double results[]) { if (is_vector) /*Process vector data. */ --- 86,173 ---- */ bool ! get_mean (bool is_vector, int for_type, int index, long double results[]) { int sum; + long double ld_sum; if (is_vector) /*Just get moments for one variable. */ { + if (Data_Type[for_type] == INT_DATA) + { + results[0] = mean_int_vector (vta, index, nrows, &sum); + results[1] = var_int_vector (vta, &results[0], index, nrows); + results[2] = + skewness_int_vector (vta, &results[1], &results[0], nrows); + results[3] = + kurtosis_int_vector (vta, &results[1], &results[0], nrows); + results[4] = sum; + results[1] = sqrt (results[1]); + } + + else if (Data_Type[for_type] == FLOAT_DATA) + { + results[0] = mean_ld_vector (vldta, index, nrows, &ld_sum); + results[1] = var_ld_vector (vldta, &results[0], index, nrows); + results[2] = + skewness_ld_vector (vldta, &results[1], &results[0], nrows); + results[3] = + kurtosis_ld_vector (vldta, &results[1], &results[0], nrows); + results[4] = ld_sum; + results[1] = sqrt (results[1]); + } + + else + { + printf ("ERROR: wrong data type for vector in get_mean.\n"); + return false; + } } else /*Get moments from matrix. */ { ! if (Data_Type[for_type] == INT_DATA) ! { ! results[0] = mean_int_matrix (mta, index, nrows, &sum); ! results[1] = var_int_matrix (mta, &results[0], index, nrows); ! results[2] = ! skewness_int_matrix (mta, index, &results[1], &results[0], nrows); ! results[3] = ! kurtosis_int_matrix (mta, index, &results[1], &results[0], nrows); ! results[4] = sum; ! results[1] = sqrt (results[1]); ! } ! else if (Data_Type[for_type] == FLOAT_DATA) ! { ! results[0] = mean_ld_matrix (mldta, index, nrows, &ld_sum); ! results[1] = var_ld_matrix (mldta, &results[0], index, nrows); ! results[2] = ! skewness_ld_matrix (mldta, index, &results[1], &results[0], ! nrows); ! results[3] = ! kurtosis_ld_matrix (mldta, index, &results[1], &results[0], ! nrows); ! results[4] = ld_sum; ! results[1] = sqrt (results[1]); ! } ! else ! { ! printf ("ERROR: wrong data type for matrix in get_mean.\n"); ! return false; ! } ! } ! ! return true; } /* ! * Sorted type statistics and tails. ! */ bool ! get_sorted_stats (bool is_vector, int for_type, int index, ! long double results[]) { if (is_vector) /*Process vector data. */ *************** *** 125,129 **** q_sort_int_vector (vta, 1, nrows); results[7] = median_int_vector (vta, nrows); ! quartiles_int_vector (vta, nrows, &results[8], &results[9]); } --- 177,181 ---- q_sort_int_vector (vta, 1, nrows); results[7] = median_int_vector (vta, nrows); ! quartiles_int_vector (vta, nrows, &results[8], &results[9]); } *************** *** 145,175 **** /* ! ** Fill up vector for analysis. ! ** Use var_column is for the particular variable. ! ** Returns false if not enough calloc fails. ! */ bool make_vector (int var_column) { int i; ! int t[MAXROWS]; ! i = 0; ! vta = vector_int_calloc (nrows); ! if (vta == NULL) { ! printf ! ("Cannot allocate memory in make_vector\n Free memory, reboot, or report file size in a bug report.\n"); ! return false; } ! /*Fill t with data. */ getit (data_file, var_column, t); /*Put t into a vector. */ while (i < nrows) { ! vector_int_set (vta, i, t[i]); i++; } --- 197,258 ---- /* ! ** Fill up vector for analysis. ! ** Use var_column is for the particular variable. ! ** Returns false if not enough calloc fails. ! */ bool make_vector (int var_column) { int i; ! long double t[MAXROWS]; ! i = 0; ! if (Data_Type[var_column] == INT_DATA) { ! vta = vector_int_calloc (nrows); ! ! if (vta == NULL) ! { ! printf ! ("Cannot allocate memory in make_vector\n Free memory, reboot, or report file size in a bug report.\n"); ! return false; ! } } ! else if (Data_Type[var_column] == FLOAT_DATA) ! { ! vldta = vector_ld_calloc (nrows); ! ! if (vldta == NULL) ! { ! printf ! ("Cannot allocate memory in make_vector\n Free memory, reboot, or report file size in a bug report.\n"); ! return false; ! } ! } ! ! else ! { ! printf ("ERROR: unknown data type in make_vector!\n"); ! exit (EXIT_FAILURE); ! } ! ! /*Fill t with data. */ getit (data_file, var_column, t); /*Put t into a vector. */ + while (i < nrows) { ! if (Data_Type[var_column] == INT_DATA) ! vector_int_set (vta, i, t[i]); ! else if (Data_Type[var_column] == FLOAT_DATA) ! vector_ld_set (vldta, i, t[i]); ! else ! { ! printf ("ERROR: unknown data type in make_vector!\n"); ! exit (EXIT_FAILURE); ! } i++; } *************** *** 180,203 **** bool ! make_matrix (int x[]) { int i, c, temp; ! int t[MAXROWS]; ! i = 1; /*Allocate matrix */ ! mta = matrix_int_calloc (nrows, NUM_VARS); ! if (mta == NULL) { ! printf ! ("Cannot allocate memory in make_matrix\n Free memory, reboot, or report file size in a bug report.\n"); ! return false; } /*Read data into matrix */ ! while (i <= NUM_VARS) { ! temp = x[i - 1]; getit (data_file, temp, t); --- 263,303 ---- bool ! make_matrix (int x[], bool type, int how_much) { int i, c, temp; ! long double t[MAXROWS]; ! i = 0; /*Allocate matrix */ ! ! if (type == true) { ! mta = matrix_int_calloc (nrows, how_much); ! ! if (mta == NULL) ! { ! printf ! ("Cannot allocate memory in make_vector\n Free memory, reboot, or report file size in a bug report.\n"); ! return false; ! } ! } ! ! else ! { ! mldta = matrix_ld_calloc (nrows, how_much); ! ! if (mldta == NULL) ! { ! printf ! ("Cannot allocate memory in make_vector\n Free memory, reboot, or report file size in a bug report.\n"); ! return false; ! } } /*Read data into matrix */ ! while (i < how_much) { ! temp = x[i]; getit (data_file, temp, t); *************** *** 206,210 **** while (c < nrows) { ! matrix_int_set (mta, c, i - 1, t[c]); c++; } --- 306,316 ---- while (c < nrows) { ! if (type == true) ! matrix_int_set (mta, c, i, t[c]); ! ! else ! matrix_ld_set (mldta, c, i, t[c]); ! ! c++; } *************** *** 224,239 **** free_data (int what_to_free) { ! assert (what_to_free >= 0 && what_to_free <= 3); ! if (what_to_free == 0) vector_int_free (vta); ! else if (what_to_free == 1) matrix_int_free (mta); ! else if (what_to_free == 2) vector_ld_free (vldta); ! else if (what_to_free == 3) matrix_ld_free (mldta); else ! printf ("NOT a valid what_to_free!\n"); } --- 330,345 ---- free_data (int what_to_free) { ! assert (what_to_free >= 0 && what_to_free <= 3); ! if (what_to_free == FREE_VECTOR_INT) vector_int_free (vta); ! else if (what_to_free == FREE_MATRIX_INT) matrix_int_free (mta); ! else if (what_to_free == FREE_VECTOR_LD) vector_ld_free (vldta); ! else if (what_to_free == FREE_MATRIX_LD) matrix_ld_free (mldta); else ! printf ("NOT a valid what_to_free!\n"); } Index: output.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/output.c,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** output.c 22 May 2004 06:33:02 -0000 1.27 --- output.c 29 May 2004 18:22:23 -0000 1.28 *************** *** 31,43 **** #include <string.h> /* Various uses of string functions. */ #include <assert.h> /* The error checks. */ ! #include <math.h> /* The log function is used in desc to determine v lenght. */ ! /*Use -ltecla for linking*/ - #include <libtecla.h> /* Use for input. */ #include "output.h" #include "statistics.h" /* Calls to statistical routines. */ #include "main.h" /* Flag variables (print_digits). */ ! #include "menu.h" /* Enumeration values. */ #include "file_ops.h" /* Sending data to the logfile. */ /* --- 31,52 ---- #include <string.h> /* Various uses of string functions. */ #include <assert.h> /* The error checks. */ ! #include <math.h> /* The log function is used in desc to determine v length. */ ! ! ! #include "output.h" #include "statistics.h" /* Calls to statistical routines. */ #include "main.h" /* Flag variables (print_digits). */ ! #include "menu.h" /* Enumeration values, and MAX_VAR_INPUT. */ #include "file_ops.h" /* Sending data to the logfile. */ + #include "system.h" /* Bool and config.h calls. */ + + /*FIXME: Need alternate for MSDOS or w/o libtecla. */ + #ifndef MSDOS + #ifdef HAVE_LIBTECLA + #include <libtecla.h> /* Use for input. Use -ltecla for linking. */ + #endif /* #elif include"myinput.h" */ + #endif /* *************** *** 47,82 **** int NUM_VARS; /* Number of variables for analysis. */ extern GetLine *gl; /* The getline variable for libtecla. */ /* * Functions */ ! void desc (bool vector_flag, bool all_stats, int v[]); /* Print descriptive tables. */ void format_output (char *input, double value); /* Adjust for number of sig digits. */ bool output_main (int v[], int routine, int stats_to_do) { bool verify; ! int i; assert (routine >= 100 && routine <= 103); ! FLAG_VECTOR = true; ! NUM_VARS = 0; ! /*Double check to make sure we have something. */ i = 0; if (v[i] == -1) return true; ! /*See if we have one, or more than one variable. */ while (v[i] >= 0) { i++; NUM_VARS++; } ! /*Lets make a vector or matrix. */ ! if (NUM_VARS == 1) { ! verify = stats_main (v, true); if (verify == false) --- 56,117 ---- int NUM_VARS; /* Number of variables for analysis. */ extern GetLine *gl; /* The getline variable for libtecla. */ + int count_int, count_ld; /* Counts of respective types for making a matrix. */ + /* * Functions */ ! bool desc (bool all_stats, int v[], int matrix_int_vars[], int matrix_ld_vars[]); /* Print descriptive tables. */ void format_output (char *input, double value); /* Adjust for number of sig digits. */ + void free_which_data (int v[]); /* Frees up the build vector/matrix. */ + /*FIXME: break this up a bit. */ bool output_main (int v[], int routine, int stats_to_do) { bool verify; ! int i, ct_int[MAX_VAR_INPUT], ct_ld[MAX_VAR_INPUT]; ! assert (routine >= 100 && routine <= 103); ! FLAG_VECTOR = true; /* Default is just true because most people will just look at one variable:D */ ! NUM_VARS = count_int = count_ld = 0; ! /* FIXME: do something with stats_to_do! */ ! i = stats_to_do; ! ! /* Double check to make sure we have something. */ i = 0; if (v[i] == -1) return true; ! /* ! * See if we have one, or more than one variable. ! * Also, setups number of variable types. ! * An alternate to v is made for printing variable names. This is to accomdated for different types. ! * Basically, and index for cross-reference will be made for makeing output. ! */ while (v[i] >= 0) { + if (Data_Type[v[i]] == INT_DATA) + { + ct_int[count_int] = v[i]; + count_int++; + } + else if (Data_Type[v[i]] == FLOAT_DATA) + { + ct_ld[count_ld] = v[i]; + count_ld++; + } + i++; NUM_VARS++; } ! ct_int[count_int] = ct_ld[count_ld] = -1; /* Last value set to -1 for checks. */ ! ! /* Lets make a vector or matrix. */ ! if (NUM_VARS == 1) /* Vector is simple! Just up and go. */ { ! verify = stats_main (v, true, true, count_int); if (verify == false) *************** *** 87,100 **** } ! else { FLAG_VECTOR = false; - verify = stats_main (v, false); ! if (verify == false) { ! printf ("ERROR: Failed to make a matrix!\n\n"); ! return false; } } --- 122,149 ---- } ! else /* A bit complicated (too complicated?). But, make relevant matrix/vectors. */ { FLAG_VECTOR = false; ! if (count_int >= 1) { ! verify = stats_main (ct_int, false, true, count_int); ! if (verify == false) ! { ! printf ("ERROR: Failed to make a matrix!\n\n"); ! return false; ! } } + + if (count_ld >= 1) + { + verify = stats_main (ct_ld, false, false, count_ld); + if (verify == false) + { + printf ("ERROR: Failed to make a matrix!\n\n"); + return false; + } + } + } *************** *** 103,111 **** { case descriptives: ! desc (FLAG_VECTOR, false, v); break; case more_descriptives: ! desc (FLAG_VECTOR, true, v); break; --- 152,160 ---- { case descriptives: ! verify = desc (false, v, ct_int, ct_ld); break; case more_descriptives: ! verify = desc (true, v, ct_int, ct_ld); break; *************** *** 115,134 **** } ! /*Clear matrix or vector. */ ! if (FLAG_VECTOR) ! free_data (0); ! else ! free_data (1); return true; } ! void ! desc (bool is_vector, bool all_stats, int v[]) { bool stat_test; char results_col[11][MROW]; char *p_output; ! int i, im, output_size, stop_me; long double results[11]; size_t j, k; --- 164,180 ---- } ! /* All finished so free up the matrix/vector. */ ! free_which_data (v); return true; } ! bool ! desc (bool all_stats, int v[], int matrix_int_vars[], int matrix_ld_vars[]) { bool stat_test; char results_col[11][MROW]; char *p_output; ! int i, im, output_size, stop_me, offset, num_int, num_ld; long double results[11]; size_t j, k; *************** *** 139,143 **** char stats_label[11][20] = { {"Mean\t\t"}, ! {"Variance\t"}, {"Skewness\t"}, {"Kurtosis\t"}, --- 185,189 ---- char stats_label[11][20] = { {"Mean\t\t"}, ! {"SD\t\t"}, {"Skewness\t"}, {"Kurtosis\t"}, *************** *** 150,154 **** {"IQR\t\t"} }; ! char table_header[] = "\nDescriptive Statistis for"; char table_subheader[] = "Statistics\tValue\n"; stop_me = 4; /* That is, only do until Sum. */ --- 196,200 ---- {"IQR\t\t"} }; ! char table_header[] = "\nDescriptive Statistics for"; char table_subheader[] = "Statistics\tValue\n"; stop_me = 4; /* That is, only do until Sum. */ *************** *** 158,161 **** --- 204,208 ---- /* Populate the first row with title. */ output_size = sizeof (table_header); + num_int = num_ld = offset = 0; /* *************** *** 165,183 **** { /* Get the stats. */ ! stat_test = get_mean (is_vector, im, results); ! if (stat_test == false) ! break; ! ! if (all_stats == true) { ! stat_test = get_sorted_stats (is_vector, im, results); if (stat_test == false) ! break; ! stop_me = 10; } /* Lets get the title in. Determing how big the variable name is! */ /* Pad for log, space, and \n. */ ! output_size += sizeof (table_subheader) + log (v[im] + 1) + 3; /* --- 212,279 ---- { /* Get the stats. */ ! if (FLAG_VECTOR) /* Vector for analysis. */ { ! stat_test = get_mean (FLAG_VECTOR, im, im, results); if (stat_test == false) ! return false; ! ! if (all_stats == true) ! { ! stat_test = get_sorted_stats (FLAG_VECTOR, im, im, results); ! if (stat_test == false) ! return false; ! stop_me = 10; ! } ! ! offset = im; ! } ! ! else /* We have a matrix! Off to fun land! */ ! { ! if (num_ld < count_ld) ! { ! stat_test = get_mean (FLAG_VECTOR, matrix_ld_vars[num_ld], num_ld, results); ! if (stat_test == false) ! return false; ! if (all_stats == true) ! { ! stat_test = ! get_sorted_stats (FLAG_VECTOR, matrix_ld_vars[num_ld], num_ld, results); ! ! if (stat_test == false) ! return false; ! ! stop_me = 10; ! } ! ! offset = matrix_ld_vars[num_ld]; ! num_ld++; ! } ! ! else if (num_int < count_int) ! { ! stat_test = get_mean (FLAG_VECTOR, matrix_int_vars[num_int], num_int, results); ! if (stat_test == false) ! return false; ! ! if (all_stats == true) ! { ! stat_test = ! get_sorted_stats (FLAG_VECTOR, matrix_int_vars[num_int], num_int, results); ! ! if (stat_test == false) ! return false; ! ! stop_me = 10; ! } ! ! offset = matrix_int_vars[num_int]; ! num_int++; ! } } /* Lets get the title in. Determing how big the variable name is! */ /* Pad for log, space, and \n. */ ! output_size += sizeof (table_subheader) + log (offset + 1) + 3; /* *************** *** 222,225 **** --- 318,322 ---- } + return true; } *************** *** 275,278 **** --- 372,406 ---- } + /*Clear matrix or vector. */ + void + free_which_data (int v[]) + { + int i; + if (FLAG_VECTOR) + { + i = v[0]; + if (Data_Type[i] == INT_DATA) + free_data (FREE_VECTOR_INT); + else if (Data_Type[i] == FLOAT_DATA) + free_data (FREE_VECTOR_LD); + else + { + printf ("ERROR: bad what to free in output_main for vector.\n"); + exit (EXIT_FAILURE); + } + + } + + else + { + if (count_int >= 1) + free_data (FREE_MATRIX_INT); + + if (count_ld >= 1) + free_data (FREE_MATRIX_LD); + + } + } + /*Main output structure Index: menu.h =================================================================== RCS file: /cvsroot/mistat/mistat/src/menu.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** menu.h 15 Mar 2004 15:07:26 -0000 1.11 --- menu.h 29 May 2004 18:22:23 -0000 1.12 *************** *** 46,50 **** * Prototypes */ ! void menu_main (); /*FIXME: move?*/ void do_file_menu (int not_read); --- 46,50 ---- * Prototypes */ ! void menu_main (void); /*FIXME: move?*/ void do_file_menu (int not_read); Index: main.h =================================================================== RCS file: /cvsroot/mistat/mistat/src/main.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** main.h 5 May 2004 08:05:43 -0000 1.10 --- main.h 29 May 2004 18:22:23 -0000 1.11 *************** *** 33,37 **** * Prototypes */ ! void exit_mistat (); /* --- 33,37 ---- * Prototypes */ ! void exit_mistat (void); /* Index: statistics.h =================================================================== RCS file: /cvsroot/mistat/mistat/src/statistics.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** statistics.h 9 May 2004 15:06:33 -0000 1.18 --- statistics.h 29 May 2004 18:22:23 -0000 1.19 *************** *** 1,17 **** /* Header for statistics.c in mistat. ! Copyright (C) 2003, 2004 Mike H. Benton Mike H. Benton <bik...@us...>, 2003. ! 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 --- 1,17 ---- /* Header for statistics.c in mistat. ! Copyright (C) 2003, 2004 Mike H. Benton Mike H. Benton <bik...@us...>, 2003. ! 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 *************** *** 23,27 **** #define STATS_H ! #include "system.h" /* For bool. */ /* --- 23,32 ---- #define STATS_H ! #include "system.h" /* For bool. */ ! ! #define FREE_VECTOR_INT 0 ! #define FREE_VECTOR_LD 1 ! #define FREE_MATRIX_INT 2 ! #define FREE_MATRIX_LD 3 /* *************** *** 35,41 **** */ ! bool stats_main (int x[], bool is_vector); ! bool get_mean (bool is_vector, int index, long double results []); ! bool get_sorted_stats (bool is_vector, int index, long double results []); void free_data (int what_to_free); --- 40,48 ---- */ ! bool stats_main (int x[], bool is_vector, bool type, int how_much); ! bool get_mean (bool is_vector, int for_type, int index, ! long double results[]); ! bool get_sorted_stats (bool is_vector, int for_type, int index, ! long double results[]); void free_data (int what_to_free); Index: main.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/main.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** main.c 9 May 2004 15:06:33 -0000 1.13 --- main.c 29 May 2004 18:22:23 -0000 1.14 *************** *** 1,17 **** /* Entry point for mistat. ! Copyright (C) 2003, 2004 Mike H. Benton Mike H. Benton <bik...@us...>, 2003. ! 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 --- 1,17 ---- /* Entry point for mistat. ! Copyright (C) 2003, 2004 Mike H. Benton Mike H. Benton <bik...@us...>, 2003. ! 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 *************** *** 55,60 **** */ int do_args (int argc, char **argv); ! bool get_data_file (int num); ! void process_data_file (int argc, char **argv); --- 55,60 ---- */ int do_args (int argc, char **argv); ! bool get_data_file (void); ! void process_data_file (void); *************** *** 173,177 **** else ! process_data_file (argc, argv); --- 173,177 ---- else ! process_data_file (); *************** *** 185,194 **** */ void ! process_data_file (int argc, char **argv) { /*Handle the input file */ /*data_file_exist gets set */ ! data_file_exist = get_data_file (1); /*read data file and close */ --- 185,194 ---- */ void ! process_data_file (void) { /*Handle the input file */ /*data_file_exist gets set */ ! data_file_exist = get_data_file (); /*read data file and close */ *************** *** 206,210 **** */ bool ! get_data_file (int num) { --- 206,210 ---- */ bool ! get_data_file (void) { *************** *** 242,246 **** */ void ! exit_mistat () { printf ("\n\n\t\tExiting mistat\n"); --- 242,246 ---- */ void ! exit_mistat (void) { printf ("\n\n\t\tExiting mistat\n"); Index: menu.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/menu.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** menu.c 22 May 2004 06:33:02 -0000 1.24 --- menu.c 29 May 2004 18:22:23 -0000 1.25 *************** *** 57,61 **** void ! menu_main () { int choice; --- 57,61 ---- void ! menu_main (void) { int choice; *************** *** 143,146 **** --- 143,147 ---- free (msg); + } *************** *** 150,154 **** void ! do_stats_choice (choice) { int v[MAX_VAR_INPUT]; --- 151,155 ---- void ! do_stats_choice (int choice) { int v[MAX_VAR_INPUT]; *************** *** 156,159 **** --- 157,169 ---- int i; + verify = false; + + if (nrows <= 0 || columns <= 0) /* We need data and variables. */ + { + printf + ("No data or cases are avilable for analysis.\nOpen a new data file!\n"); + return; + } + /* Get the variables for input. */ i = 0; |