[Mistat-cvs] mistat/src error.c,1.7,1.8 output.c,1.24,1.25
Status: Pre-Alpha
Brought to you by:
bikepunk005
|
From: Mike H. B. <bik...@us...> - 2004-05-17 17:22:30
|
Update of /cvsroot/mistat/mistat/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12368/src Modified Files: error.c output.c Log Message: Contine with output.c work. The memory allocation is fine; but, need to work on matrix. Housekeeping in error.c. Index: output.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/output.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** output.c 9 May 2004 15:06:33 -0000 1.24 --- output.c 17 May 2004 17:22:21 -0000 1.25 *************** *** 27,35 **** */ ! #include <stdio.h> ! #include <stdlib.h> ! #include <string.h> ! #include <assert.h> #include "output.h" #include "statistics.h" /* Calls to statistical routines. */ --- 27,38 ---- */ ! #include <stdio.h> /* Various types of printf. */ ! #include <stdlib.h> /* Allocation calls. */ ! #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. */ *************** *** 41,47 **** * Variables */ ! bool FLAG_VECTOR; /*Vector or matrix (number of variables = 1). */ ! int NUM_VARS; /*Number of variables for analysis. */ ! /* * Functions --- 44,50 ---- * Variables */ ! bool FLAG_VECTOR; /* Vector or matrix (number of variables = 1). */ ! int NUM_VARS; /* Number of variables for analysis. */ ! extern GetLine *gl; /* The getline variable for libtecla. */ /* * Functions *************** *** 121,140 **** 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". */ --- 124,153 ---- desc (bool is_vector, int v[]) { + bool stat_test; char results_col[11][MROW]; ! char *p_output; ! float temp; ! int i, im, output_size; long double results[11]; ! size_t j, k; ! ! /* ! * Set up the hard table values. ! */ ! char stats_label[11][20] = { ! {"Mean\t\t"}, ! {"Variance\t"}, ! {"Skewness\t"}, ! {"Kurtosis\t"}, ! {"Sum\t\t"}, ! {"Min\t\t"}, ! {"Max\t\t"}, ! {"Median\t\t"}, ! {"Lower Quartile\t"}, ! {"Upper Quartile\t"}, ! {"IQR\t\t"} ! }; ! char table_header[] = "\nDescriptive Statistis for"; ! char table_subheader[] = "Statistics\tValue\n"; j = 6; /* Minimum length of results, or can fit "value". */ *************** *** 143,151 **** { /* 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++) --- 156,175 ---- { /* Just one variable. */ ! stat_test = get_mean (is_vector, 1, results); ! if (stat_test == false) ! { ! return; ! } ! stat_test = get_sorted_stats (is_vector, 1, results); ! ! if (stat_test == false) ! { ! return; ! } ! ! /* Lets get the title in. Determing how big the variable name is! */ ! temp = 0.0; ! output_size = sizeof (table_header) + sizeof (table_subheader) + log (*v + 1) + 3; /* Pad for log, space, and \n. */ for (i = 0; i <= 10; i++) *************** *** 156,162 **** j = k; } ! printf ("%s\t%s\n", DESC_TABLE[i], results_col[i]); } } --- 180,206 ---- j = k; } ! output_size = output_size + j + strlen (stats_label[i]) + 10; ! } + p_output = malloc (output_size * sizeof (char)); + if (p_output == NULL) + { + printf ("ERROR: cannot allocate memory for output\n"); + return; + } + + sprintf (p_output, "%s %d\n", table_header, *v + 1); + strcat (p_output, table_subheader); + + for (i = 0; i <= 10; i++) + { + strcat (p_output, stats_label[i]); + strcat (p_output, results_col[i]); + } + + printf ("%s", p_output); + update_logfile (p_output); + free (p_output); } *************** *** 165,170 **** 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); --- 209,221 ---- for (im = 0; im <= NUM_VARS - 1; im++) { ! stat_test = get_mean (is_vector, im, results); ! ! if (stat_test == false) ! return; ! ! stat_test = get_sorted_stats (is_vector, im, results); ! ! if (stat_test == false) ! return; printf ("\nDescriptive Statistics for %d\n", v[im] + 1); *************** *** 178,186 **** j = k; } ! printf ("%s\t%s\n", DESC_TABLE[i], results_col[i]); } } } } --- 229,241 ---- j = k; } ! printf ("%s\t%s\n", stats_label[i], results_col[i]); } + + if (im % 2) + gl_get_line (gl, "Hit Enter to Continue", NULL, -1); } } + } *************** *** 192,228 **** 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; --- 247,283 ---- case 0: ! sprintf (input, "%.0f\n", value); break; case 1: ! sprintf (input, "%.1f\n", value); break; case 2: ! sprintf (input, "%.2f\n", value); break; case 3: ! sprintf (input, "%.3f\n", value); break; case 4: ! sprintf (input, "%.4f\n", value); break; case 5: ! sprintf (input, "%.5f\n", value); break; case 6: ! sprintf (input, "%.6f\n", value); break; case 7: ! sprintf (input, "%.7f\n", value); break; case 8: ! sprintf (input, "%.8f\n", value); break; Index: error.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/error.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** error.c 30 Mar 2004 15:49:48 -0000 1.7 --- error.c 17 May 2004 17:22:20 -0000 1.8 *************** *** 1,22 **** /* Error handling 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. */ - /*error.c*/ --- 1,21 ---- /* Error handling 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. */ /*error.c*/ *************** *** 108,138 **** } ! /*Now we move onto the custom gsl error handlers.*/ ! ! /*int ! my_gsl_error_check (int status) ! { ! switch (status) ! { ! ! case -1: ! printf ("ERROR in gsl."); ! exit (EXIT_FAILURE); ! break; ! ! case 0:*/ ! /*Should not call but just in case. */ ! /*return true; ! break; ! ! ! ! default: ! printf ("ERROR: Invalid status sent to my_gsl_error_check->%d<-\n", ! status); ! exit (EXIT_FAILURE); ! break; ! ! } ! ! }*/ --- 107,109 ---- } ! /* Here ends error.c. */ |