[Mistat-cvs] mistat/src menu.c,1.22,1.23 output.c,1.25,1.26 output.h,1.12,1.13
Status: Pre-Alpha
Brought to you by:
bikepunk005
|
From: Mike H. B. <bik...@us...> - 2004-05-20 16:52:33
|
Update of /cvsroot/mistat/mistat/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18592/src Modified Files: menu.c output.c output.h Log Message: I have the basic model for output! Descriptives are in place, and no memory leaks! Index: output.h =================================================================== RCS file: /cvsroot/mistat/mistat/src/output.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** output.h 9 May 2004 15:06:33 -0000 1.12 --- output.h 20 May 2004 16:52:22 -0000 1.13 *************** *** 39,43 **** * RETURN: true if succesful. */ ! bool output_main (int v[], int routine); /* --- 39,43 ---- * RETURN: true if succesful. */ ! bool output_main (int v[], int routine, int stats_to_do); /* Index: output.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/output.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** output.c 17 May 2004 17:22:21 -0000 1.25 --- output.c 20 May 2004 16:52:22 -0000 1.26 *************** *** 50,58 **** * 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) { bool verify; --- 50,58 ---- * 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; *************** *** 103,107 **** { case descriptives: ! desc (FLAG_VECTOR, v); break; --- 103,111 ---- { case descriptives: ! desc (FLAG_VECTOR, false, v); ! break; ! ! case more_descriptives: ! desc (FLAG_VECTOR, true, v); break; *************** *** 120,131 **** } - /*FIXME: do I need to pass v[]? The matrix has the info?. Perhaps for printing variable stuff?. */ void ! 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]; --- 124,133 ---- } 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; long double results[11]; *************** *** 153,176 **** j = 6; /* Minimum length of results, or can fit "value". */ ! if (is_vector) ! { /* 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++) { --- 155,183 ---- j = 6; /* Minimum length of results, or can fit "value". */ ! /* Populate the first row with title. */ ! output_size = sizeof (table_header); + /* + * Loop through the variables, and print output. + */ + for (im = 0; im <= NUM_VARS - 1; im++) + { + /* Get the stats. */ + stat_test = get_mean (is_vector, im, results); if (stat_test == false) ! break; + stat_test = get_sorted_stats (is_vector, im, results); if (stat_test == false) ! break; /* 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; + /* + * Populate the results_col for sig digits. Also, + * rasie the value of output_size to match results_col. + */ for (i = 0; i <= 10; i++) { *************** *** 180,197 **** 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++) { --- 187,205 ---- 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 <= 10; i++) { *************** *** 200,241 **** } printf ("%s", p_output); update_logfile (p_output); free (p_output); - } ! else ! { /*We have a matrix, so handle each varible. */ ! 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); ! 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", stats_label[i], results_col[i]); ! } - if (im % 2) - gl_get_line (gl, "Hit Enter to Continue", NULL, -1); - } } - } --- 208,221 ---- } + /* 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); } } *************** *** 243,246 **** --- 223,228 ---- format_output (char *input, double value) { + assert (print_digit >= 0 && print_digit <= 8); + switch (print_digit) { *************** *** 290,307 **** /*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. */ --- 272,289 ---- /*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. */ Index: menu.c =================================================================== RCS file: /cvsroot/mistat/mistat/src/menu.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** menu.c 9 May 2004 15:06:33 -0000 1.22 --- menu.c 20 May 2004 16:52:22 -0000 1.23 *************** *** 182,186 **** } ! verify = output_main (v, descriptives); if (verify == false) --- 182,186 ---- } ! verify = output_main (v, descriptives, 0); if (verify == false) |