Diploma Thesis Percolation Simulation C++ Sourcecode Documentation |
00001 // little_helpers.h 00002 // Andreas Krueger first implementation: 2.2.2000 00003 // version 1.1, last change: 4/2000 00004 00005 // #include <math.h> // for floor() 00006 // #include <iostream> 00007 00008 #ifndef LOADED_LITTLE_HELPERS 00009 #define LOADED_LITTLE_HELPERS 00010 #endif 00011 00012 00013 #include <string> 00014 using std::string; 00015 00016 void waitanykey(){ 00017 char input; 00018 cout << "Please press any key and <return>"; 00019 cin >> input; 00020 cout << endl; 00021 cout <<"******************************************"<<endl; 00022 } 00023 00024 void errorout(char* text){ 00025 cout <<"ERROR: "<<text<<endl; 00026 } 00027 00028 #ifndef EXIT_OUTOFMEMORY 00029 #define EXIT_OUTOFMEMORY -1 00030 #endif 00031 00032 void exit_out_of_memory(char* where){ 00033 cout <<"\nOut of memory! \nAt position:\n "; 00034 cout <<where<<endl; 00035 cout <<"I will stop here..."<<endl; 00036 waitanykey(); 00037 exit(EXIT_OUTOFMEMORY); 00038 } 00039 00040 00041 long rounded(double floating) { 00042 return ((long)floor(floating+0.5)); 00043 } 00044 00045 00046 #if defined(_WIN32) //////////////////////////////////////////////////// 00047 00048 // <sys/timeb.h> is needed for: 00049 // struct _timeb tstruct; 00050 // _ftime( &tstruct ); 00051 // milliseconds=tstruct.millitm; 00052 #include <sys/timeb.h> 00053 00054 void give_ms(char* milliseconds){ 00055 // TODO: Unix? ANSI? 00056 struct _timeb tstruct; 00057 _ftime( &tstruct ); 00058 if (tstruct.millitm<100) strcat (milliseconds, "0"); 00059 if (tstruct.millitm<10) strcat (milliseconds, "0"); 00060 char ms[4]; strcpy (ms, ""); 00061 sprintf(ms, "%d", tstruct.millitm); 00062 strcat (milliseconds, ms); 00063 } 00064 00065 #else //////////////////////////////////////////////////// 00066 void give_ms(char* milliseconds){ 00067 sprintf(milliseconds, "%s", "000"); 00068 } 00069 00070 #endif //////////////////////////////////////////////////// 00071 00072 const int TIMESTAMP_LENGTH=18; 00073 const int SHORT_TIMESTAMP_LENGTH=16; 00074 00075 #ifndef _INC_TIMEB 00076 #include <sys/timeb.h> 00077 #endif 00078 00079 #ifndef _INC_TIME 00080 #include <time.h> 00081 #endif 00082 00083 00084 void give_timestamp(char* timestamp){ 00085 time_t utctime; 00086 time (& utctime); 00087 struct tm * todaylocal; 00088 todaylocal=localtime(&utctime); 00089 00090 strcpy (timestamp, ""); 00091 char localtime[TIMESTAMP_LENGTH-3]; 00092 strftime(localtime, TIMESTAMP_LENGTH-3,"%Y%m%d%H%M%S", todaylocal); 00093 strcat (timestamp, localtime); 00094 00095 char ms[4];strcpy (ms, ""); 00096 give_ms(ms); strcat (timestamp, ms); 00097 } 00098 00099 void give_short_timestamp(char* timestamp){ 00100 time_t utctime; 00101 time (& utctime); 00102 struct tm * todaylocal; 00103 todaylocal=localtime(&utctime); 00104 00105 strcpy (timestamp, ""); 00106 char localtime[TIMESTAMP_LENGTH-3]; 00107 strftime(localtime, TIMESTAMP_LENGTH-3,"%y%m%d%H%M%S", todaylocal); 00108 strcat (timestamp, localtime); 00109 00110 char ms[4];strcpy (ms, ""); 00111 give_ms(ms); strcat (timestamp, ms); 00112 } 00113 00114 string give_short_timestamp(void){ 00115 string temp; 00116 char buffer[SHORT_TIMESTAMP_LENGTH]; 00117 give_short_timestamp(buffer); 00118 temp=buffer; 00119 return temp; 00120 } 00121 00122 string give_timestamp(void){ 00123 string temp; 00124 char buffer[TIMESTAMP_LENGTH]; 00125 give_timestamp(buffer); 00126 temp=buffer; 00127 return temp; 00128 } 00129 00130 string timestamp_fullyear(){ 00131 string temp; 00132 char buffer[TIMESTAMP_LENGTH]; 00133 give_timestamp(buffer); 00134 temp=buffer; 00135 temp=temp.substr(0,TIMESTAMP_LENGTH-4); 00136 return temp; 00137 } 00138 00139 void test_timestamp(){ 00140 char timestamp[TIMESTAMP_LENGTH]; 00141 strcpy (timestamp, ""); 00142 for (;;){ 00143 give_timestamp(timestamp); 00144 cout <<timestamp<<endl; 00145 } 00146 } 00147 00148 00149 00150 void waitreturnkey() { 00151 for (;!cin.get();) {}; 00152 } 00153 00154 REAL ms(clock_t clockticks){ 00155 return (REAL)clockticks/(REAL)CLOCKS_PER_SEC*1000; 00156 } 00157 00158 00159 REAL ms(REAL clockticks){ 00160 return clockticks/(REAL)CLOCKS_PER_SEC*1000; 00161 } 00162 00163 #ifndef NUMLIST 00164 typedef std::list<NUMBER> NUMLIST; 00165 #endif 00166 00167 00168 bool is_in_list(NUMLIST &list1, NUMBER element){ 00169 NUMLIST::iterator e; 00170 bool temp=false; 00171 for (e=list1.begin();e!=list1.end();e++){ 00172 if (*e==element) temp=true; 00173 } 00174 return temp; 00175 } 00176 00177 void write_the_list_into_file(char* fn, NUMLIST& li){ 00178 FILE* outFile=fopen(fn, "w"); 00179 NUMLIST::iterator e; 00180 for (e=li.begin();e!=li.end();e++){ 00181 fprintf(outFile, "%d",*e); fprintf(outFile, "%s","\n"); 00182 } 00183 fprintf(outFile, "%s","\n"); 00184 fclose(outFile); 00185 } 00186 00187 void show_ascii_table (){ 00188 for (int c=0;c<=256;c++){ 00189 cout <<c<<":"<< (char)c<<"\t"; 00190 } 00191 cout <<endl; 00192 } 00193 00194 void heat_random_generator(){ 00195 cout <<"heat the random generator by 10^7 runs..."<<endl; 00196 long i; 00197 for (long j=9;j>=0;j--){ 00198 cout <<j<<flush; 00199 for (i=1;i<=pow(10,6);i++){rand();}; 00200 } 00201 } 00202 00203
Diploma Thesis Sourcecode
Documentation check out the text and the executable binaries |