00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "globals.hh"
00033 #include <fstream>
00034 #include "G4Tokenizer.hh"
00035 #include "G3toG4.hh"
00036 #include "G3EleTable.hh"
00037 #include "G3VolTable.hh"
00038 #include "G3MatTable.hh"
00039 #include "G3MedTable.hh"
00040 #include "G3RotTable.hh"
00041 #include "G3PartTable.hh"
00042 #include "G3DetTable.hh"
00043 #include "G3SensVolVector.hh"
00044
00045 std::ofstream ofile;
00046
00047 extern "C"
00048 {
00049 #include <stdlib.h>
00050 }
00051
00052 extern std::ofstream ofile;
00053
00054 G3VolTable G3Vol;
00055 G3MatTable G3Mat;
00056 G3MedTable G3Med;
00057 G3RotTable G3Rot;
00058 G3PartTable G3Part;
00059 G3DetTable G3Det;
00060 G3EleTable G3Ele;
00061 G3SensVolVector G3SensVol;
00062 char gSeparator('_');
00063
00064 G4int narray;
00065
00066 G4int Ipar[1000];
00067 G4double Rpar[1000];
00068 G4String Spar[1000];
00069
00070 G4int G3CLTokens(G4String *line, G4String *tokens);
00071 void G3CLEval(G4String *tokens, char *select);
00072
00073
00074
00075 void PG4gsvolu(G4String *tokens);
00076 void PG4gspos (G4String *tokens);
00077 void PG4gsposp(G4String *tokens);
00078 void PG4gsatt (G4String *tokens);
00079 void PG4gsrotm(G4String *tokens);
00080 void PG4gsdvn (G4String *tokens);
00081 void PG4gsdvt (G4String *tokens);
00082 void PG4gsdvx (G4String *tokens);
00083 void PG4gsdvn2(G4String *tokens);
00084 void PG4gsdvt2(G4String *tokens);
00085 void PG4gsmate(G4String *tokens);
00086 void PG4gsmixt(G4String *tokens);
00087 void PG4gstmed(G4String *tokens);
00088 void PG4gstpar(G4String *tokens);
00089 void PG4gspart(G4String *tokens);
00090 void PG4gsdk (G4String *tokens);
00091 void PG4gsdet (G4String *tokens);
00092 void PG4gsdetv(G4String *tokens);
00093 void PG4gsdeta(G4String *tokens);
00094 void PG4gsdeth(G4String *tokens);
00095 void PG4gsdetd(G4String *tokens);
00096 void PG4gsdetu(G4String *tokens);
00097 void PG4ggclos();
00098
00099 void G3CLRead(G4String & fname, char *select = 0)
00100 {
00101
00102
00103
00104
00105
00106
00107
00108 G4String line;
00109 G4String tokens[1000];
00110
00111 const char* ofname = "clparse.out";
00112 ofile.open(ofname);
00113 ofile << "Output file open\n";
00114
00115 G4int count = 0;
00116 G4int ntokens = 0;
00117 std::ifstream istr(fname);
00118
00119 while (line.readLine(istr) && ! istr.eof())
00120 {
00121 count++;
00122 ntokens = G3CLTokens(&line,tokens);
00123 for (G4int i=0; i < ntokens; i++)
00124 {
00125 ofile << tokens[i] << G4endl;
00126 }
00127
00128
00129
00130 G3CLEval(tokens, select);
00131 }
00132 }
00133
00134
00135 G4int G3CLTokens(G4String *line, G4String tokens[])
00136 {
00137
00138
00139
00140
00141
00142
00143 G4Tokenizer next(*line);
00144
00145
00146
00147 G4int itok = 0;
00148 G4int ntokens = 0;
00149 G4String token1, token2;
00150 while (!(token1=next("\"")).isNull())
00151 {
00152 itok++;
00153 if (itok%2 == 0 )
00154 {
00155 tokens[ntokens++] = token1;
00156 }
00157 else
00158 {
00159 G4Tokenizer lev2(token1);
00160 while (!(token2=lev2()).isNull())
00161 {
00162 tokens[ntokens] = token2;
00163 ntokens++;
00164 }
00165 }
00166 }
00167 return ntokens;
00168 }
00169
00170
00171 void G3CLEval(G4String tokens[], char *select)
00172 {
00173
00174
00175
00176
00177
00178
00179 const char* context = tokens[0];
00180 const char* routine = tokens[1];
00181 const char* wcard = "*";
00182
00183
00184
00185 if ((select != 0) && (select != wcard))
00186 {
00187 if ( strcmp(select,context) ) { return; }
00188 }
00189
00190
00191
00192 ofile << "Do routine " << routine << " in context " << context << G4endl;
00193
00194 if ( !strcmp(routine,"GSVOLU") ) { PG4gsvolu(&tokens[2]); return;}
00195 if ( !strcmp(routine,"GSPOS") ) { PG4gspos (&tokens[2]); return;}
00196 if ( !strcmp(routine,"GSPOSP") ) { PG4gsposp(&tokens[2]); return;}
00197 if ( !strcmp(routine,"GSATT") ) { PG4gsatt (&tokens[2]); return;}
00198 if ( !strcmp(routine,"GSROTM") ) { PG4gsrotm(&tokens[2]); return;}
00199 if ( !strcmp(routine,"GSDVN") ) { PG4gsdvn (&tokens[2]); return;}
00200 if ( !strcmp(routine,"GSDVT") ) { PG4gsdvt (&tokens[2]); return;}
00201 if ( !strcmp(routine,"GSDVX") ) { PG4gsdvx (&tokens[2]); return;}
00202 if ( !strcmp(routine,"GSDVN2") ) { PG4gsdvn2(&tokens[2]); return;}
00203 if ( !strcmp(routine,"GSDVT2") ) { PG4gsdvt2(&tokens[2]); return;}
00204 if ( !strcmp(routine,"GSMATE") ) { PG4gsmate(&tokens[2]); return;}
00205 if ( !strcmp(routine,"GSMIXT") ) { PG4gsmixt(&tokens[2]); return;}
00206 if ( !strcmp(routine,"GSTMED") ) { PG4gstmed(&tokens[2]); return;}
00207 if ( !strcmp(routine,"GSTPAR") ) { PG4gstpar(&tokens[2]); return;}
00208 if ( !strcmp(routine,"GSPART") ) { PG4gspart(&tokens[2]); return;}
00209 if ( !strcmp(routine,"GSDK") ) { PG4gsdk (&tokens[2]); return;}
00210 if ( !strcmp(routine,"GSDET") ) { PG4gsdet (&tokens[2]); return;}
00211 if ( !strcmp(routine,"GSDETV") ) { PG4gsdetv(&tokens[2]); return;}
00212 if ( !strcmp(routine,"GSDETA") ) { PG4gsdeta(&tokens[2]); return;}
00213 if ( !strcmp(routine,"GSDETH") ) { PG4gsdeth(&tokens[2]); return;}
00214 if ( !strcmp(routine,"GSDETD") ) { PG4gsdetd(&tokens[2]); return;}
00215 if ( !strcmp(routine,"GSDETU") ) { PG4gsdetu(&tokens[2]); return;}
00216 if ( !strcmp(routine,"GGCLOS") ) { PG4ggclos(); return;}
00217 }
00218
00219 void G3fillParams(G4String *tokens, const char *ptypes)
00220 {
00221
00222
00223
00224
00225
00226
00227
00228 G4int i =0, ipt = 0, k = 0;
00229 G4int ni =0, nr = 0, nq = 0;
00230 while (ptypes[i] != '\0')
00231 {
00232 switch (ptypes[i])
00233 {
00234 case 'i':
00235 Ipar[ni] = atoi(tokens[ipt].data());
00236 narray = Ipar[ni];
00237 ni++; ipt++;
00238 break;
00239 case 'r':
00240 Rpar[nr] = atof(tokens[ipt].data());
00241 nr++; ipt++;
00242 break;
00243 case 's':
00244 Spar[nq] = tokens[ipt];
00245 nq++; ipt++;
00246 break;
00247 case 'I':
00248 for (k=0; k < narray; k++)
00249 {
00250 Ipar[ni] = atoi(tokens[ipt].data());
00251 ni++; ipt++;
00252 }
00253 break;
00254 case 'R':
00255 for (k=0; k < narray; k++)
00256 {
00257 Rpar[nr] = atof(tokens[ipt].data());
00258 nr++; ipt++;
00259 }
00260 break;
00261 case 'Q':
00262
00263
00264
00265 narray = 3 * std::abs(narray);
00266 for (k=0; k < narray; k++)
00267 {
00268 Rpar[nr] = atof(tokens[ipt].data());
00269 nr++; ipt++;
00270 }
00271 break;
00272 case 'S':
00273 for (k=0; k < narray; k++)
00274 {
00275 Spar[nq] = tokens[ipt];
00276 nq++; ipt++;
00277 }
00278 break;
00279 default:
00280 ofile << "unidentified ptype '" << ptypes[i] << G4endl;
00281 };
00282 i++;
00283 }
00284 }