/* utility functions */ #include "stdafx.h" #include "util.h" /* generic error handling function */ /*void CVera_samDlg::die (int error_code) { char usage_bmo[600], usage_sig[600]; char usage_sig2[300]; /* core dump may result if these are too large */ /* sprintf(usage_bmo, "%s%s%s%s%s", "Usage: VERA \n", "Options: -init Use an input model to initiate optimization\n", " -crit Optimization ceases when all changes are less than (Default=0.0005)\n", " -evol Output file showing model approach to optimum\n", " -iter Display iterations (Use for debugging only)\n" ); sprintf(usage_sig, "%s%s", "Usage: SAM \n", " -iter Display iterations (Use for debugging only)\n"); sprintf(usage_sig2, "%s%s", "Usage: SAM2 \n", " -iter Display iterations (Use for debugging only)\n"); */ /*switch (error_code) { case 0: UpdateUI("Memory allocation failure."); break; case 1: UpdateUI("Command line error"); //fprintf(stderr, "\nCommand line error.\n\n%s\n\n", usage_bmo); break; case 2: UpdateUI("Cannot read input file."); //fprintf(stderr, "\nCannot read input file.\n"); break; case 3: UpdateUI("Number out of range"); //fprintf(stderr, "\nNumber out of range.\n"); break; case 5: UpdateUI("Command line error"); //fprintf(stderr, "\nCommand line error.\n\n%s\n\n", usage_sig); break; case 6: UpdateUI("Command Line error"); //fprintf(stderr, "\nCommand line error.\n\n%s\n\n", usage_sig2); break; default: UpdateUI("Unknown error."); //fprintf(stderr, "\nUnknown error.\n"); break; } UpdateUI("Aborting pogram execution."); //fprintf(stderr, "Aborting program execution.\n"); exit(1); }*/ /* timing functions */ void start_time (void) { tk.begin_clock = tk.save_clock = clock(); tk.begin_time = tk.save_time = time(NULL); } double prn_time (FILE *fp) { char s1[MAXSTRING], s2[MAXSTRING]; int field_width, n1, n2; double clocks_per_second = (double) CLOCKS_PER_SEC, user_time, real_time; user_time = ( clock() - tk.save_clock ) / clocks_per_second; real_time = difftime( time(NULL), tk.save_time ); tk.save_clock = clock(); tk.save_time = time(NULL); /* print values found, and do it neatly */ n1 = sprintf(s1, "%.1f", user_time); n2 = sprintf(s2, "%.1f", real_time); field_width = (n1 > n2) ? n1 : n2; fprintf(fp, "%s%*.1f%s\n%s%*.1f%s\n\n", "user_time ", field_width, user_time, " seconds", "real_time ", field_width, real_time, " seconds"); return user_time; } double stdout_prn_time (void) { char s1[MAXSTRING], s2[MAXSTRING]; int field_width, n1, n2; double clocks_per_second = (double) CLOCKS_PER_SEC, user_time, real_time; user_time = ( clock() - tk.save_clock ) / clocks_per_second; real_time = difftime( time(NULL), tk.save_time ); tk.save_clock = clock(); tk.save_time = time(NULL); /* print values found, and do it neatly */ //mj modified 10-11-01 /*mj n1 = sprintf(s1, "%.1f", user_time); n2 = sprintf(s2, "%.1f", real_time); field_width = (n1 > n2) ? n1 : n2; printf( "%s%*.1f%s\n%s%*.1f%s\n\n", "user_time ", field_width, user_time, " seconds", "real_time ", field_width, real_time, " seconds");*/ return real_time; }