[Mistat-cvs] mistat/src main.c,1.12,1.13 menu.c,1.21,1.22 output.c,1.23,1.24 output.h,1.11,1.12 stat
Status: Pre-Alpha
Brought to you by:
bikepunk005
|
From: Mike H. B. <bik...@us...> - 2004-05-09 15:06:44
|
Update of /cvsroot/mistat/mistat/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31552/src Modified Files: main.c menu.c output.c output.h statistics.c statistics.h Log Message: Still working on ouput. Big changes to statistics.c (no more structures). Put the abilit to chage sig digits back in. Some housekeeping in main. Fix typos in ChangeLog Index: statistics.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/statistics.c,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** statistics.c 25 Apr 2004 22:30:44 -0000 1.29 --- statistics.c 9 May 2004 15:06:33 -0000 1.30 *************** *** 19,26 **** */ /* statistics.c */ ! /*USAGE: stats_main must be called to build a vector or matrix. * Then, call the various statistical routines. All routines must be supplied ! * with a boolean value: true for vector, false for matrix. The routines return ! * write to a structure. */ --- 19,26 ---- */ /* statistics.c */ ! /*USAGE: stats_main must be called to build a vector or matrix that is used for analysis. * Then, call the various statistical routines. All routines must be supplied ! * with a boolean value: true for vector, false for matrix. ! * The routines write to supplied array. */ *************** *** 50,56 **** /* ! ** Populate vector or matrix before calling stat functions. ! ** Using as a central call point. ! ** Return false if cannot make a vector or matrix. */ bool --- 50,56 ---- /* ! ** Populate vector or matrix before calling stat functions. ! ** Using as a central call point. ! ** Return false if cannot make a vector or matrix. */ bool *************** *** 61,65 **** verified = false; /* Set as false, called proceures will change to true if succesful. */ ! if (vector) /* Make a vector from variable and index. */ { variable = x[0]; --- 61,65 ---- verified = false; /* Set as false, called proceures will change to true if succesful. */ ! if (vector) /* Make a vector. */ { variable = x[0]; *************** *** 73,76 **** --- 73,77 ---- return verified; + } *************** *** 78,82 **** * Basic statistical functions. * Supply is_vector. ! * Return to structures. */ --- 79,83 ---- * Basic statistical functions. * Supply is_vector. ! * Return to true/false. */ *************** *** 84,120 **** * Calculates all moments. */ ! void ! get_mean (bool is_vector, int index) { - long double temp, temp1; - long double mean, variance, skewness, kurtosis; int sum; - - /*temp is additive, so must be set to 0 before all calculations! */ - temp = temp1 = 0; - if (is_vector) /*Just get moments for one variable. */ { ! mean = mean_int_vector (vta, index, nrows, &sum); ! variance = var_int_vector (vta, &mean, index, nrows); ! skewness = skewness_int_vector (vta, &variance, &mean, nrows); ! kurtosis = kurtosis_int_vector (vta, &variance, &mean, nrows); } else /*Get moments from matrix. */ { ! mean = mean_int_matrix (mta, index, nrows, &sum); ! variance = var_int_matrix (mta, &mean, index, nrows); ! skewness = skewness_int_matrix (mta, index, &variance, &mean, nrows); ! kurtosis = kurtosis_int_matrix (mta, index, &variance, &mean, nrows); } ! D_STATS.mean = mean; ! D_STATS.variance = variance; ! D_STATS.skewness = skewness; ! D_STATS.kurtosis = kurtosis; ! D_STATS.sum = sum; ! } --- 85,114 ---- * Calculates all moments. */ ! 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; ! } *************** *** 122,137 **** * Sorted type statistics and tails. */ ! void ! get_sorted_stats (bool is_vector, int index) { - long double median, min, max, l_quart, u_quart; - if (is_vector) /*Process vector data. */ { ! min = vector_int_min (vta); ! max = vector_int_max (vta); q_sort_int_vector (vta, 1, nrows); ! median = median_int_vector (vta, nrows); ! quartiles_int_vector (vta, nrows, &l_quart, &u_quart); } --- 116,129 ---- * Sorted type statistics and tails. */ ! bool ! get_sorted_stats (bool is_vector, int index, long double results[]) { if (is_vector) /*Process vector data. */ { ! results[5] = vector_int_min (vta); ! results[6] = vector_int_max (vta); q_sort_int_vector (vta, 1, nrows); ! results[7] = median_int_vector (vta, nrows); ! quartiles_int_vector (vta, nrows, &results[8], &results[9]); } *************** *** 139,155 **** { ! min = matrix_int_min (mta, index); ! max = matrix_int_max (mta, index); q_sort_int_matrix (mta, index, 1, nrows); ! median = median_int_matrix (mta, index, nrows); ! quartiles_int_matrix (mta, index, nrows, &l_quart, &u_quart); } ! S_STATS.min = min; ! S_STATS.max = max; ! S_STATS.median = median; ! S_STATS.l_quart = l_quart; ! S_STATS.u_quart = u_quart; ! S_STATS.iqr = (u_quart - l_quart); } --- 131,144 ---- { ! results[5] = matrix_int_min (mta, index); ! results[6] = matrix_int_max (mta, index); q_sort_int_matrix (mta, index, 1, nrows); ! results[7] = median_int_matrix (mta, index, nrows); ! quartiles_int_matrix (mta, index, nrows, &results[8], &results[9]); } ! results[10] = (results[9] - results[8]); ! ! return true; } *************** *** 158,162 **** ** Fill up vector for analysis. ** Use var_column is for the particular variable. ! ** Returns false if not enough calloc fails. */ bool --- 147,151 ---- ** Fill up vector for analysis. ** Use var_column is for the particular variable. ! ** Returns false if not enough calloc fails. */ bool *************** *** 166,179 **** int t[MAXROWS]; vta = vector_int_calloc (nrows); if (vta == NULL) return false; /*Fill t with data. */ getit (data_file, var_column, t); ! ! i = 0; ! /*Put t into a vector. */ while (i < nrows) --- 155,171 ---- 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) *************** *** 182,187 **** i++; } ! return true; } --- 174,180 ---- i++; } ! return true; + } *************** *** 192,210 **** int t[MAXROWS]; ! /*Allocate matrix */ mta = matrix_int_calloc (nrows, NUM_VARS); - - i = 1; - if (mta == NULL) { printf ! ("Cannot allocate memory in make_simple_matrix\n Free memory, reboot, or report file size in a bug report.\n"); return false; } /*Read data into matrix */ - while (i <= NUM_VARS) { --- 185,200 ---- 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) { *************** *** 212,215 **** --- 202,206 ---- getit (data_file, temp, t); + c = 0; while (c < nrows) *************** *** 223,226 **** --- 214,218 ---- return true; + } *************** *** 245,252 **** { printf ("NOT a valid what_to_free!\n"); - exit (EXIT_FAILURE); } - } --- 237,242 ---- Index: output.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/output.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** output.c 25 Apr 2004 22:30:43 -0000 1.23 --- output.c 9 May 2004 15:06:33 -0000 1.24 *************** *** 1,17 **** /* Output formatter and printer 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 ---- /* Output formatter and printer 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 *************** *** 33,63 **** #include "output.h" ! #include "statistics.h" ! ! #include "menu.h" ! /* Output structure. ! * Used to add lines and such for output. */ - struct results - { - char *to_print; - struct results *next; - }; - - - bool FLAG_VECTOR; /*Vector or matrix (number of variables = 1). */ int NUM_VARS; /*Number of variables for analysis. */ - void desc (bool vector_flag, int v[]); /*Print descriptive tables. */ - struct results *addrow (char *text, struct results *previous); - - struct results *clear_struct (struct results *previous); - /* ! * Supply variables to be analyzed, and statistical routine. ! * Returns true if succesful. */ bool output_main (int v[], int routine) --- 33,53 ---- #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. */ ! /* ! * Variables */ bool FLAG_VECTOR; /*Vector or matrix (number of variables = 1). */ int NUM_VARS; /*Number of variables for analysis. */ /* ! * Functions */ + void desc (bool vector_flag, 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) *************** *** 131,237 **** desc (bool is_vector, int v[]) { ! char *row; ! int i; ! struct results *top = NULL; ! struct results *p; ! row = "\nDescriptives\n"; ! top = addrow (row, top); if (is_vector) { /* Just one variable. */ - get_mean (is_vector, 1); - get_sorted_stats (is_vector, 1); ! /*FIXME: temp printing routine. */ ! for (p = top; p != NULL; p = p->next) ! printf ("%s", p->to_print); - printf - (" mean = %f\n skew = %f\n kur = %f\n var = %f\n sum = %f\n median = %f\n min = %f\n max = %f\n lower = %f\n higher = %f\n iqr = %f\n\n", - D_STATS.mean, D_STATS.skewness, D_STATS.kurtosis, - D_STATS.variance, D_STATS.sum, S_STATS.median, S_STATS.min, - S_STATS.max, S_STATS.l_quart, S_STATS.u_quart, S_STATS.iqr); } else { /*We have a matrix, so handle each varible. */ ! /*FIXME: temp printing routines. */ ! for (p = top; p != NULL; p = p->next) ! printf ("%s", p->to_print); ! ! for (i = 0; i <= NUM_VARS - 1; i++) { ! get_mean (is_vector, i); ! get_sorted_stats (is_vector, i); ! printf ! (" mean = %f\n skew = %f\n kur = %f\n var = %f\n sum = %f\n median = %f\n min = %f\n max = %f\n lower = %f\n higher = %f\n iqr = %f\n\n", ! D_STATS.mean, D_STATS.skewness, D_STATS.kurtosis, ! D_STATS.variance, D_STATS.sum, S_STATS.median, ! S_STATS.min, S_STATS.max, S_STATS.l_quart, ! S_STATS.u_quart, S_STATS.iqr); ! } ! } ! while (top != NULL) ! { ! free (top->to_print); ! top = clear_struct (top); } } ! /*FIXME: need to just clear and return if cannot allocate.*/ ! /*FIXME: need to free.*/ ! struct results * ! addrow (char *text, struct results *previous) ! { ! struct results *newrow = previous; ! if (previous != NULL) ! { ! /* Rewind if necessary. */ ! while (previous->next != NULL) ! previous = previous->next; ! previous->next = malloc (sizeof (struct results)); ! previous = previous->next; ! previous->next = NULL; ! previous->to_print = malloc (strlen (text) + 1); ! strcpy (previous->to_print, text); ! return newrow; ! } ! else ! { ! previous = malloc (sizeof (struct results)); ! previous->next = NULL; ! previous->to_print = malloc (strlen (text) + 1); ! strcpy (previous->to_print, text); ! return previous; ! } ! } ! struct results * ! clear_struct (struct results *previous) ! { ! struct results *temp; ! temp = previous->next; ! free (previous); ! return temp; ! } /*Main output structure ! Sequence: get table input: regression, descriptive, and so on get length of results ! generate table (all to the sprintf thing) 1. title --- 121,242 ---- desc (bool is_vector, int v[]) { ! char results_col[11][MROW]; ! int i, im, j, k; ! long double results[11]; ! char DESC_TABLE[11][16] = { ! {"Mean\t"}, ! {"Variance"}, ! {"Skewness"}, ! {"Kurtosis"}, ! {"Sum\t"}, ! {"Min\t"}, ! {"Max\t"}, ! {"Median\t"}, ! {"Lower Quartile"}, ! {"Upper Quartile"}, ! {"IQR\t"} ! }; ! j = 6; /* Minimum length of results, or can fit "value". */ if (is_vector) { /* Just one variable. */ ! get_mean (is_vector, 1, results); ! get_sorted_stats (is_vector, 1, results); ! ! printf ("\nDescriptive Statistics for %d\n", *v + 1); ! printf ("Statistic\tValue\n"); ! ! for (i = 0; i <= 10; i++) ! { ! format_output (results_col[i], results[i]); ! if ((k = strlen (results_col[i])) > j) ! { ! j = k; ! } ! printf ("%s\t%s\n", DESC_TABLE[i], results_col[i]); ! } } else { /*We have a matrix, so handle each varible. */ ! for (im = 0; im <= NUM_VARS - 1; im++) { ! get_mean (is_vector, im, results); ! get_sorted_stats (is_vector, im, results); ! printf ("\nDescriptive Statistics for %d\n", v[im] + 1); ! printf ("Statistic\tValue\n"); ! ! for (i = 0; i <= 10; i++) ! { ! format_output (results_col[i], results[i]); ! if ((k = strlen (results_col[i])) > j) ! { ! j = k; ! } ! printf ("%s\t%s\n", DESC_TABLE[i], results_col[i]); ! } ! } } } ! void ! format_output (char *input, double value) ! { ! switch (print_digit) ! { ! case 0: ! sprintf (input, "%.0f", value); ! break; ! case 1: ! sprintf (input, "%.1f", value); ! break; ! case 2: ! sprintf (input, "%.2f", value); ! break; ! case 3: ! sprintf (input, "%.3f", value); ! break; ! case 4: ! sprintf (input, "%.4f", value); ! break; ! case 5: ! sprintf (input, "%.5f", value); ! break; ! case 6: ! sprintf (input, "%.6f", value); ! break; ! case 7: ! sprintf (input, "%.7f", value); ! break; ! case 8: ! sprintf (input, "%.8f", value); ! break; ! default: ! printf ("ERROR: not a valid print_digit in format_output!\n\n"); ! break; ! } ! } /*Main output structure ! Sequence: get table input: regression, descriptive, and so on get length of results ! generate table (all to the sprintf thing) 1. title Index: output.h =================================================================== RCS file: /cvsroot/mistat/mistat/src/output.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** output.h 15 Mar 2004 15:07:26 -0000 1.11 --- output.h 9 May 2004 15:06:33 -0000 1.12 *************** *** 23,32 **** #define OUTPUT_H ! #include "system.h" /*For bool and c_v variables. */ /* * Defines */ ! #define MCOL 60 /*Maximum columin width is 60. */ /* --- 23,33 ---- #define OUTPUT_H ! #include "system.h" /* For bool and c_v variables. */ /* * Defines */ ! #define MCOL 60 /* Maximum columin width is 60. */ ! #define MROW 100 /* Maximum number of rows is 100. */ /* Index: statistics.h =================================================================== RCS file: /cvsroot/mistat/mistat/src/statistics.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** statistics.h 25 Apr 2004 22:30:44 -0000 1.17 --- statistics.h 9 May 2004 15:06:33 -0000 1.18 *************** *** 23,68 **** #define STATS_H ! #include "system.h" ! ! /* ! * Structures ! */ ! ! struct MOMENTS ! { ! double mean; ! double skewness; ! double kurtosis; ! double variance; ! double sum; ! } ! D_STATS; ! ! struct RANGES ! { ! double min; ! double max; ! double median; ! double upper_tail; ! double lower_tail; ! double l_quart; ! double u_quart; ! double iqr; ! } ! S_STATS; /* * Prototypes */ ! /* Most statistical routines have bool is_vector. Basically, * this determines if a vector or matrix is input for analysis. ! * The variable for analysis is supplied for maxrix only as index. ! * All statistical values write to structures. ! * All data is freed by calling routine. */ bool stats_main (int x[], bool is_vector); ! void get_mean (bool is_vector, int index); ! void get_sorted_stats (bool is_vector, int index); void free_data (int what_to_free); --- 23,41 ---- #define STATS_H ! #include "system.h" /* For bool. */ /* * Prototypes */ ! /* Most statistical routines have is_vector. Basically, * this determines if a vector or matrix is input for analysis. ! * The variable for analysis for a maxrix is index. ! * All statistical values write to supplied array. ! * All return true or false. */ 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); Index: main.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/main.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** main.c 5 May 2004 08:05:43 -0000 1.12 --- main.c 9 May 2004 15:06:33 -0000 1.13 *************** *** 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 *************** *** 76,80 **** main (int argc, char **argv) { - /*Start the error handling */ set_signals (); --- 76,79 ---- *************** *** 104,108 **** exit_mistat (); ! return (0); } --- 103,107 ---- exit_mistat (); ! return 0; } Index: menu.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/menu.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** menu.c 5 May 2004 08:05:43 -0000 1.21 --- menu.c 9 May 2004 15:06:33 -0000 1.22 *************** *** 1,17 **** /* Entry point and handler for the menu system 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 ---- /* Entry point and handler for the menu system 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 *************** *** 25,29 **** #include <stdio.h> /* Various printf and some file stuff (for the moment). */ #include <ctype.h> ! #include <stdlib.h> #include <string.h> /* Some string minipulations. */ --- 25,29 ---- #include <stdio.h> /* Various printf and some file stuff (for the moment). */ #include <ctype.h> ! #include <stdlib.h> /* EXIT_FAILURE and malloc stuff. */ #include <string.h> /* Some string minipulations. */ *************** *** 33,40 **** #include "menu.h" ! #include "file_ops.h" ! #include "output.h" ! #include "main.h" ! #include "system.h" void do_menu_choice (int choice); --- 33,40 ---- #include "menu.h" ! #include "file_ops.h" /* For opening and closing files. */ ! #include "output.h" /* Calls for printing and getting stats. */ ! #include "main.h" /* gl, and flag variables (print_digit,). */ ! #include "system.h" /* Bool use. */ void do_menu_choice (int choice); *************** *** 86,89 **** --- 86,90 ---- { char *msg; + char temp[99]; msg = (char *) calloc (100, sizeof (char)); *************** *** 114,120 **** break; ! case options_menu: ! printf ("The OPTIONS menu\n\n"); ! break; case log_menu: --- 115,129 ---- break; ! case options_menu: ! printf("The OPTIONS menu\n\n"); ! choice = get_choice (options_menu, 0, 8); ! ! /*Only 1 choice right now!*/ ! print_digit = choice; ! sprintf (temp, "\n\nNumber of sig. digits is now %d\n\n", print_digit); ! strncat (msg, temp, strlen (temp)); ! printf ("%s", msg); ! update_logfile (msg); ! break; case log_menu: *************** *** 359,362 **** --- 368,376 ---- * The various switch parts do addition to choice. */ + + /* + * At this point, only options_menu will allow 0. + * FIXME: what to really do! + */ if (digits == 0 && menu_number != options_menu) return digits; /* Return to exit. */ |