[Mistat-cvs] mistat/src output.c,1.29,1.30 output.h,1.14,1.15 statistics.c,1.33,1.34
Status: Pre-Alpha
Brought to you by:
bikepunk005
|
From: Mike H. B. <bik...@us...> - 2004-05-30 16:36:25
|
Update of /cvsroot/mistat/mistat/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26132/src Modified Files: output.c output.h statistics.c Log Message: Continue overhaul of output! Refined current functions. In statistics.c, put error message in the command of stats_main. Index: statistics.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/statistics.c,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** statistics.c 29 May 2004 19:59:23 -0000 1.33 --- statistics.c 30 May 2004 16:36:15 -0000 1.34 *************** *** 64,67 **** --- 64,69 ---- variable = x[0]; verified = make_vector (variable); + if (verified == false) + printf ("ERROR: Failed to make a vector!\n\n"); } *************** *** 69,72 **** --- 71,76 ---- { verified = make_matrix (x, type, how_much); + if (verified == false) + printf ("ERROR: Failed to make a matrix!\n\n"); } Index: output.h =================================================================== RCS file: /cvsroot/mistat/mistat/src/output.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** output.h 29 May 2004 19:59:23 -0000 1.14 --- output.h 30 May 2004 16:36:15 -0000 1.15 *************** *** 1,17 **** /* functions in output.c 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 ---- /* functions in output.c 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 *************** *** 30,33 **** --- 30,34 ---- #define MCOL 60 /* Maximum columin width is 60. */ #define MROW 100 /* Maximum number of rows is 100. */ + #define MLABEL 30 /* Maximum statistics label. */ /* Index: output.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/output.c,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** output.c 29 May 2004 19:59:23 -0000 1.29 --- output.c 30 May 2004 16:36:15 -0000 1.30 *************** *** 56,69 **** extern GetLine *gl; /* The getline variable for libtecla. */ int count_int, count_ld; /* Counts of respective types for making a matrix. */ /* * Functions */ bool setup_data (int vect_var[], int int_vars[], int ld_vars[]); /* Determine what to make (matrix/vector) and ask to make. */ 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) --- 56,74 ---- extern GetLine *gl; /* The getline variable for libtecla. */ int count_int, count_ld; /* Counts of respective types for making a matrix. */ + int Stop_Me; /* When to stop printing. */ + int Output_Size; /* Size of output string. */ + long double Results[11]; /* Results of analysis. */ + /* * Functions */ + void build_data_list (int v[], int int_count[], int ld_count[]); /* Fill the count vectors. */ bool setup_data (int vect_var[], int int_vars[], int ld_vars[]); /* Determine what to make (matrix/vector) and ask to make. */ bool desc (bool all_stats, int v[], int matrix_int_vars[], int matrix_ld_vars[]); /* Print descriptive tables. */ + void print_handler (int v[], int im, char stats_label[][MLABEL], char table_subheader[], char table_header[]); /* All printing is sent here. */ 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. */ bool output_main (int v[], int routine, int stats_to_do) *************** *** 82,109 **** 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 accommodate for different types. ! * Basically, and index for cross-reference will be made for making 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. */ --- 87,92 ---- return true; ! /* Use v to fill ct_int and ct_ld. */ ! build_data_list (v, ct_int, ct_ld); /* Lets make a vector or matrix. */ *************** *** 130,134 **** /* All finished so free up the matrix/vector. */ free_which_data (v); ! return true; } --- 113,145 ---- /* All finished so free up the matrix/vector. */ free_which_data (v); ! return verify; ! ! } ! ! void ! build_data_list (int v[], int ct_int[], int ct_ld[]) ! { ! int i; ! ! i = 0; ! 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. */ } *************** *** 142,154 **** { verify = stats_main (vect_var, true, true, count_int); - - if (verify == false) - { - printf ("ERROR: Failed to make a vector!\n\n"); - return false; - } } ! else /* A bit complicated (too complicated?). But, make relevant matrix/vectors. */ { Flag_Vector = false; --- 153,159 ---- { verify = stats_main (vect_var, true, true, count_int); } ! else /* Make relevant matrix/vectors. */ { Flag_Vector = false; *************** *** 158,165 **** verify = stats_main (int_vars, false, true, count_int); if (verify == false) ! { ! printf ("ERROR: Failed to make a matrix!\n\n"); ! return false; ! } } --- 163,167 ---- verify = stats_main (int_vars, false, true, count_int); if (verify == false) ! return verify; } *************** *** 168,179 **** verify = stats_main (ld_vars, false, false, count_ld); if (verify == false) ! { ! printf ("ERROR: Failed to make a matrix!\n\n"); ! return false; ! } } } ! return true; } --- 170,178 ---- verify = stats_main (ld_vars, false, false, count_ld); if (verify == false) ! return verify; } } ! return verify; } *************** *** 183,216 **** { 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; /* * Set up the hard table values. */ ! char stats_label[11][20] = { ! {"Mean\t\t"}, ! {"SD\t\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 Statistics for"; char table_subheader[] = "Statistics\tValue\n"; ! stop_me = 4; /* That is, only do until Sum. */ ! ! j = 6; /* Minimum length of results, or can fit "value". */ /* Populate the first row with title. */ ! output_size = sizeof (table_header); num_int = num_ld = offset = 0; --- 182,209 ---- { bool stat_test; ! int im, offset, num_int, num_ld; /* * Set up the hard table values. */ ! char stats_label[11][MLABEL] = { ! {"Mean\t\t"}, ! {"SD\t\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 Statistics for"; char table_subheader[] = "Statistics\tValue\n"; ! Stop_Me = 4; /* That is, only do until Sum. */ /* Populate the first row with title. */ ! Output_Size = sizeof (table_header); num_int = num_ld = offset = 0; *************** *** 223,227 **** if (Flag_Vector) /* Vector for analysis. */ { ! stat_test = get_mean (Flag_Vector, im, im, results); if (stat_test == false) return false; --- 216,220 ---- if (Flag_Vector) /* Vector for analysis. */ { ! stat_test = get_mean (Flag_Vector, im, im, Results); if (stat_test == false) return false; *************** *** 229,236 **** if (all_stats == true) { ! stat_test = get_sorted_stats (Flag_Vector, im, im, results); if (stat_test == false) return false; ! stop_me = 10; } --- 222,229 ---- if (all_stats == true) { ! stat_test = get_sorted_stats (Flag_Vector, im, im, Results); if (stat_test == false) return false; ! Stop_Me = 10; } *************** *** 244,248 **** stat_test = get_mean (Flag_Vector, matrix_ld_vars[num_ld], num_ld, ! results); if (stat_test == false) return false; --- 237,241 ---- stat_test = get_mean (Flag_Vector, matrix_ld_vars[num_ld], num_ld, ! Results); if (stat_test == false) return false; *************** *** 251,260 **** stat_test = get_sorted_stats (Flag_Vector, matrix_ld_vars[num_ld], ! num_ld, results); if (stat_test == false) return false; ! stop_me = 10; } --- 244,253 ---- stat_test = get_sorted_stats (Flag_Vector, matrix_ld_vars[num_ld], ! num_ld, Results); if (stat_test == false) return false; ! Stop_Me = 10; } *************** *** 267,271 **** stat_test = get_mean (Flag_Vector, matrix_int_vars[num_int], num_int, ! results); if (stat_test == false) return false; --- 260,264 ---- stat_test = get_mean (Flag_Vector, matrix_int_vars[num_int], num_int, ! Results); if (stat_test == false) return false; *************** *** 275,284 **** stat_test = get_sorted_stats (Flag_Vector, matrix_int_vars[num_int], ! num_int, results); if (stat_test == false) return false; ! stop_me = 10; } --- 268,277 ---- stat_test = get_sorted_stats (Flag_Vector, matrix_int_vars[num_int], ! num_int, Results); if (stat_test == false) return false; ! Stop_Me = 10; } *************** *** 290,337 **** /* Lets get the title in. Determine how big the variable name is! */ /* Pad for log, space, and \n. */ ! output_size += sizeof (table_subheader) + log (offset + 1) + 3; - /* - * Populate the results_col for sig digits. Also, - * raise the value of output_size to match results_col. - */ - for (i = 0; i <= stop_me; i++) - { - format_output (results_col[i], results[i]); - if ((k = strlen (results_col[i])) > j) - { - j = k; - } - output_size += j + strlen (stats_label[i]); - } - p_output = (char *) malloc (output_size * sizeof (char)); - if (p_output == NULL) - { - printf ("ERROR: cannot allocate memory for output\n"); - break; - } ! /* ! * Make the table. ! */ ! sprintf (p_output, "%s %d\n", table_header, v[im] + 1); ! strcat (p_output, table_subheader); ! for (i = 0; i <= stop_me; i++) { ! strcat (p_output, stats_label[i]); ! strcat (p_output, results_col[i]); } ! /* Finally, print and free. */ ! printf ("%s", p_output); ! update_logfile (p_output); ! free (p_output); ! ! /*FIXME: This needs upped. */ ! gl_get_line (gl, "Hit Enter to Continue", NULL, -1); } ! return true; } --- 283,340 ---- /* Lets get the title in. Determine how big the variable name is! */ /* Pad for log, space, and \n. */ ! Output_Size += sizeof (table_subheader) + log (offset + 1) + 3; ! /* Print output. */ ! print_handler (v, im, stats_label, table_subheader, table_header); ! } ! ! return true; ! ! } ! ! void ! print_handler (int v[], int im, char stats_label[][MLABEL], ! char table_subheader[], char table_header[]) ! { ! char results_col[MROW][MCOL]; ! char *p_output; ! int i; ! size_t j, k; ! ! j = 6; /* Minimum length of Results, or can fit "value". */ ! for (i = 0; i <= Stop_Me; i++) ! { ! format_output (results_col[i], Results[i]); ! if ((k = strlen (results_col[i])) > j) { ! j = k; } + Output_Size += j + strlen (stats_label[i]); + } ! p_output = (char *) malloc (Output_Size * sizeof (char)); ! if (p_output == NULL) ! { ! printf ("ERROR: cannot allocate memory for output\n"); ! exit (EXIT_FAILURE); ! } + sprintf (p_output, "%s %d\n", table_header, v[im] + 1); + strcat (p_output, table_subheader); + for (i = 0; i <= Stop_Me; i++) + { + strcat (p_output, stats_label[i]); + strcat (p_output, results_col[i]); } ! printf ("%s", p_output); ! update_logfile (p_output); ! ! /* Finally, print and free. */ ! free (p_output); ! ! /*FIXME: This needs upped. */ ! gl_get_line (gl, "Hit Enter to Continue", NULL, -1); } *************** *** 400,407 **** free_data (FREE_VECTOR_LD); else ! { ! printf ("ERROR: bad what to free in output_main for vector.\n"); ! exit (EXIT_FAILURE); ! } } --- 403,407 ---- free_data (FREE_VECTOR_LD); else ! printf ("ERROR: bad what to free in output_main for vector.\n"); } *************** *** 418,437 **** } - /*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 - 2. top bar - 3. labels - 4. sub bar - 5. results - 7. bottom bars - 8. again for other tables--e.g. regression - output - */ - /*Here ends output.c. */ --- 418,420 ---- |