DSQSS
1.1
|
00001 #ifndef PARAMETER_H 00002 #define PARAMETER_H 00003 00004 #include <stdio.h> 00005 #include <string> 00006 00007 #include <string.h> 00008 #include <algorithm> 00009 #include <iostream> 00010 #include <fstream> 00011 00012 #include <cctype> 00013 #include <cstdio> 00014 00015 #include <dsqss_read.hpp> 00016 00017 //###################################################################### 00018 00019 class Parameter 00020 { 00021 private: 00022 int num_para ;//= 17; 00023 bool wcount[17]; 00024 string para[17]; 00025 public: 00026 Parameter(int, char**); 00027 ~Parameter(); 00028 void dump(FILE*); 00029 void dump(); 00030 void openfile(){ FOUT = fopen(OUTFILE,"w"); }; 00031 void closefile(){ fclose(FOUT); }; 00032 00033 void init(); 00034 void set_value(int,int,double,string); 00035 00036 int numcheck(const string& ); 00037 string trim(const string& ); 00038 00039 struct ToLower{char operator()(char c) { return tolower(c);}}; 00040 // 00041 // total number of sweeps executed in the whole simulation is 00042 // NMCSE + NSET * ( NMCSD + NMCS ) 00043 00044 // ++++ edit sakakura ++++ 00045 int NREP; // number of replica 00046 // int MXVIC; // max number of Vertexinitialconfiguration 00047 // ++++ edit sakakura ++++ 00048 int RUNTYPE; // runtype number 00049 int NSET; // number of sets 00050 int NMCSE; // number of sweeps for determining NCYC 00051 int NMCSD; // number of sweeps for decorrelating two subsequent sets 00052 int NMCS; // number of sweeps for measurement in a set 00053 int SEED; // seed for the random number generator 00054 int NSEGMAX; // maximum allowed number of segments 00055 int NVERMAX; // maximum allowed number of vertices 00056 00057 //kota edit // 00058 double VF; //value of VF 00059 double DF; //delta F 00060 double VB; //delta B 00061 double DB; //delta B 00062 //kota edit // 00063 00064 // int NRVIMAX; // maximum allowed number of registered vertex informations (used at ONESTEP()) 00065 char ALGFILE[24]; // algorithm file name 00066 char LATFILE[24]; // lattice file name 00067 char OUTFILE[24]; // output file name 00068 int NCYC; // number of cycles in a sweep (not provided from the file) 00069 //FILE* FALG; // file handler for the algorithm file 00070 //FILE* FLAT; // file handler for the lattice file 00071 FILE* FOUT; // file handler for the output file 00072 // int num_para = 11; 00073 Input inp; 00074 }; 00075 00076 //###################################################################### 00077 00078 inline Parameter::Parameter(int NP, char** PLIST) 00079 { 00080 if (DEBUG) printf("\nParameter::Parameter> Start.\n"); 00081 double val; 00082 // init(); 00083 // read(); 00084 // set(); 00085 inp.init(); 00086 00087 init(); // == set default values == 00088 00089 ifstream ifs(PLIST[1]); 00090 00091 if (NP < 2) 00092 { 00093 printf("error on Open: inputfile\n"); 00094 exit(1) ; // inputfileの指定なし 00095 } 00096 00097 if (ifs.fail()) 00098 { 00099 printf("no such File: %s\n",PLIST[1]); 00100 exit (1); //ファイルIOエラー 00101 } 00102 00103 string buf0; 00104 string buf1; 00105 string buf2; 00106 string buf2a,buf2b; 00107 00108 while(ifs && getline(ifs, buf0)) 00109 { 00110 buf1 = trim(buf0); 00111 00112 //===== コメントの処理 ==== 00113 string::size_type index=buf1.find("#"); 00114 00115 if ( index == string::npos ) 00116 { 00117 buf2=buf1; 00118 } 00119 else 00120 buf2=buf1.substr(0,index); 00121 00122 if (buf2.empty()) continue; 00123 //===== コメントの処理 ==== 00124 00125 //===== 構文解析 ==== 00126 string :: size_type index1=buf2.find("="); 00127 00128 if ( index1 == string::npos ) 00129 { 00130 printf("input struct miss 1: %s\n",buf0.c_str()); 00131 exit(1); //"="が未記述 00132 } 00133 00134 // buf2a=ToLower(trim(buf2.substr(0,index1))); 00135 buf2a=trim(buf2.substr(0,index1));//"="の左側 00136 transform(buf2a.begin(), buf2a.end(), buf2a.begin(),ToLower()); 00137 00138 buf2b=trim(buf2.substr(index1+1,buf2.length()));//"="の右側 00139 00140 int i,nval; 00141 00142 int ikey = -1; 00143 for (i=0; i<num_para; i++) 00144 { 00145 if (buf2a == para[i]) ikey = i; //どのパラメータか? 00146 continue; 00147 } 00148 if (ikey==-1) 00149 { 00150 printf("input struct miss 2:\n %s\n",buf0.c_str()); 00151 exit(1); //パラメータ名がただしくない 00152 00153 } 00154 00155 index1=buf2b.find(" "); 00156 if ( index1 != string::npos ) 00157 { 00158 printf("input struct miss 3:\n %s\n",buf0.c_str()); 00159 exit(1); //右端に複数の文字列が存在 00160 00161 } 00162 00163 if (ikey < 9) 00164 { 00165 if (numcheck(buf2b)) 00166 { 00167 printf("must be integer value :\n %s\n",buf0.c_str()); 00168 exit(1); //整数指定必須 00169 } 00170 nval = atoi(buf2b.c_str()); 00171 if(ikey == 8 ){ 00172 if (nval != N_PROC){ 00173 printf("NREP must be equal with NPROC :\n %s\n",buf0.c_str()); 00174 exit(1); //レプリカ数=NPROC必須(要検討) 00175 } 00176 } 00177 00178 // cout << ikey<<nval <<endl; 00179 } 00180 00181 00182 if (ikey < 16 && ikey > 11) { 00183 val = atof(buf2b.c_str()); 00184 // cout <<ikey<<" "<<val << endl; 00185 } 00186 00187 00188 if (wcount[ikey]){ 00189 printf("dual definition error :\n %s\n",buf0.c_str()); 00190 exit(1);//2重定義 00191 } 00192 00193 wcount[ikey] = true; 00194 00195 // cout << ikey<<nval <<endl; 00196 set_value(ikey,nval,val,buf2b); 00197 00198 } 00199 if (!wcount[0]) cout << "error: must set runtype" << endl; 00200 00201 dump(); 00202 00203 00204 #ifdef MULTI 00205 if (RUNTYPE==0)SEED += I_PROC; 00206 char* IPSTR = new char[8]; 00207 sprintf( IPSTR, ".%03d", I_PROC); 00208 strcat ( OUTFILE , IPSTR); 00209 delete [] IPSTR; 00210 #endif 00211 00212 if (DEBUG) printf("Parameter::Parameter> End.\n"); 00213 NCYC = 0; 00214 } 00215 00216 //====================================================================== 00217 00218 inline Parameter::~Parameter() 00219 { 00220 // printf("*** Destroying Parameter\n"); 00221 } 00222 00223 int Parameter::numcheck(const string& s) 00224 { 00225 int i; 00226 for (i=0; i<s.length(); i++) 00227 { 00228 if (isdigit(s[i])==0) 00229 { 00230 return 1; 00231 } 00232 } 00233 return 0; 00234 } 00235 00236 string Parameter::trim(const string& s) 00237 { 00238 string::const_iterator left = s.begin(); 00239 string::const_iterator right = s.end(); 00240 while(isspace(*left)) 00241 { 00242 ++left; 00243 } 00244 if(left != right) 00245 { // 右端から非空白文字を検索 00246 do { --right; } 00247 while(isspace(*right)); 00248 ++right; 00249 } 00250 return string(left, right); 00251 } 00252 00253 void Parameter::init(){ 00254 NREP = 1 ; 00255 VF = 0.0; 00256 DF = 0.1; 00257 VB = 0.0; 00258 DB = 0.1; 00259 RUNTYPE = 0 ; 00260 NSET = 10 ; 00261 NMCSE = 1000 ; 00262 NMCSD = 1000 ; 00263 NMCS = 1000 ; 00264 SEED = 198212240 ; 00265 NSEGMAX = 10000 ; 00266 NVERMAX = 10000 ; 00267 // +++ edit sakakura +++ 00268 stringstream ss; 00269 ss << I_PROC << ".xml"; 00270 strcpy(ALGFILE,ss.str().c_str()); 00271 // 00272 // strcpy(ALGFILE,"algorithm.xml"); 00273 // +++ edit sakakura +++ 00274 00275 strcpy(ALGFILE,"algorithm.xml"); 00276 strcpy(LATFILE,"lattice.xml"); 00277 strcpy(OUTFILE,"res.dat"); 00278 num_para = 17; 00279 00280 for (int i=0;i<num_para; i++) wcount[i]=false; 00281 00282 para[0] = "runtype"; 00283 para[1] = "nset"; 00284 para[2] = "nmcse"; 00285 para[3] = "nmcsd"; 00286 para[4] = "nmcs"; 00287 para[5] = "seed"; 00288 para[6] = "nsegmax"; 00289 para[7] = "nvermax"; 00290 para[8] = "nrep"; 00291 para[9] = "algfile"; 00292 para[10] = "latfile"; 00293 para[11] = "outfile"; 00294 para[12] = "vf"; 00295 para[13] = "df"; 00296 para[14] = "vb"; 00297 para[15] = "db"; 00298 // para[15] = "db"; 00299 // para[16] = "db"; 00300 00301 } 00302 00303 void Parameter::set_value(int i,int nx,double val, string buf){ 00304 switch(i) 00305 { 00306 case 0: 00307 RUNTYPE=nx; 00308 break; 00309 case 1: 00310 NSET=nx; 00311 break; 00312 case 2: 00313 NMCSE=nx;; 00314 break; 00315 case 3: 00316 NMCSD=nx; 00317 break; 00318 case 4: 00319 NMCS=nx; 00320 break; 00321 case 5: 00322 SEED=nx; 00323 break; 00324 case 6: 00325 NSEGMAX=nx; 00326 break; 00327 case 7: 00328 NVERMAX=nx; 00329 break; 00330 case 8: 00331 NREP=nx; 00332 break; 00333 case 9: 00334 strcpy(ALGFILE,buf.c_str()); 00335 break; 00336 case 10: 00337 strcpy(LATFILE,buf.c_str()); 00338 break; 00339 case 11: 00340 strcpy(OUTFILE,buf.c_str()); 00341 break; 00342 case 12: 00343 VF=val; 00344 break; 00345 case 13: 00346 DF=val; 00347 break; 00348 case 14: 00349 VB=val; 00350 break; 00351 case 15: 00352 DB=val; 00353 break; 00354 } 00355 } 00356 00357 //====================================================================== 00358 00359 inline void Parameter::dump() 00360 { 00361 cout << endl<<"+++++++++ input data +++++++++" << endl; 00362 cout << "RUNTYPE = " << RUNTYPE << endl<<endl; 00363 cout << "NREP = " << NREP << endl; 00364 cout << "NSET = " << NSET << endl; 00365 cout << "NMCSD = " << NMCSD << endl; 00366 cout << "NMCS = " << NMCS << endl; 00367 cout << "SEED = " << SEED << endl; 00368 cout << "NVERMAX = " << NVERMAX << endl; 00369 cout << "NSEGMAX = " << NSEGMAX << endl<<endl; 00370 cout << "ALGFILE = " << ALGFILE << endl; 00371 cout << "LATFILE = " << LATFILE << endl; 00372 cout << "OUTFILE = " << OUTFILE << endl; 00373 cout << "+++++++++ input data +++++++++" << endl; 00374 } 00375 inline void Parameter::dump(FILE* F) 00376 { 00377 fprintf(F,"P NSET = %12d\n",NSET); 00378 fprintf(F,"P NMCSE = %12d\n",NMCSE); 00379 fprintf(F,"P NMCSD = %12d\n",NMCSD); 00380 fprintf(F,"P NMCS = %12d\n",NMCS); 00381 fprintf(F,"P SEED = %12d\n",SEED); 00382 fprintf(F,"P NSEGMAX = %12d\n",NSEGMAX); 00383 fprintf(F,"P NVERMAX = %12d\n",NVERMAX); 00384 fprintf(F,"P NCYC = %12d\n",NCYC); 00385 fprintf(F,"P ALGFILE = %s\n", ALGFILE); 00386 fprintf(F,"P LATFILE = %s\n", LATFILE); 00387 fprintf(F,"P OUTFILE = %s\n", OUTFILE); 00388 } 00389 #endif 00390 00391 //inline void Parameter::numcheck(int s){cout << s << endl;;} 00392 //int Parameter::numcheck(const string& s) 00393 //{ 00394 // int i; 00395 // for (i=0; i<s.length(); i++) 00396 // { 00397 // if (isdigit(s[i])==0) 00398 // { 00399 // return 1; 00400 // } 00401 // } 00402 // return 0; 00403 //}