Geant4_10
g3tog4.F
Go to the documentation of this file.
1 *
2 * ********************************************************************
3 * * License and Disclaimer *
4 * * *
5 * * The Geant4 software is copyright of the Copyright Holders of *
6 * * the Geant4 Collaboration. It is provided under the terms and *
7 * * conditions of the Geant4 Software License, included in the file *
8 * * LICENSE and available at http://cern.ch/geant4/license . These *
9 * * include a list of copyright holders. *
10 * * *
11 * * Neither the authors of this software system, nor their employing *
12 * * institutes,nor the agencies providing financial support for this *
13 * * work make any representation or warranty, express or implied, *
14 * * regarding this software system or assume any liability for its *
15 * * use. Please see the license in the file LICENSE and URL above *
16 * * for the full disclaimer and the limitation of liability. *
17 * * *
18 * * This code implementation is the result of the scientific and *
19 * * technical work of the GEANT4 collaboration. *
20 * * By using, copying, modifying or distributing the software (or *
21 * * any work based on the software) you agree to acknowledge its *
22 * * use in resulting scientific publications, and indicate your *
23 * * acceptance of all terms of the Geant4 Software license. *
24 * ********************************************************************
25 *
26 *
27 * $Id: g3tog4.F 67982 2013-03-13 10:36:03Z gcosmo $
28 *
29 *
30 * G3toG4
31 *
32 * Package to convert Geant3 Fortran geometry code to a call list
33 * file to be interpreted by the Geant4 geometry call list
34 * interpreter, or alternatively, directly to Geant4 code.
35 *
36 * This set of routines is to be linked in front of, so overriding,
37 * the standard Geant library.
38 *
39 * It is possible to execute the Geant calls while at the same
40 * time building the call list/Geant4 code. In order to do this,
41 * these routines must occupy a different name space to that of
42 * the real Geant routines. This is provided by the CALL_GEANT
43 * cpp flag. If these routines are compiled with this flag,
44 * the routine names begin with K rather than G. eg. GSVOLU
45 * becomes KSVOLU. Routine names in your source code must be so
46 * converted; a perl script is provided to do this.
47 * $$$ provide the script
48 * Under normal circumstances it should *not* be necessary to go
49 * through this; it is only necessary if during the geometry
50 * generation process your code extracts information from Geant
51 * about material already generated.
52 *
53 * Torre Wenaus, LLNL 6/95
54 *
55 * To Do
56 * - option to divide generated Geant4 code into separate files/routines
57 * based on context
58 *
59 ************************************************************************
60 *
61  subroutine g3tog4(luni,lunc,chopt)
62 ************************************************************************
63 *
64 * G3toG4
65 *
66 * Initialization/setup routine
67 *
68 * luni (call list), lunc (C++ code) logical unit numbers:
69 * lun>0: Open output file on unit lun. Filenames used:
70 * g3calls.dat Call list file
71 * g4geom.cc Geant4 C++ geometry code
72 * lun<0: File open has been done by the user. Just write to |lun|
73 * lun=0: Don't generate this output.
74 * ie. luni=0: Don't generate the call list
75 * lunc=0: Don't generate the Geant4 code
76 *
77 * chopt options:
78 * 'G' execute the actual Geant calls as well as building the
79 * code/call list. In case users use info obtained from Geant
80 * during the geometry building process. THIS IS THE DEFAULT
81 * at present:
82 #define CALL_GEANT
83 *
84 ************************************************************************
85  implicit none
86  integer luni, lunc
87  character chopt*(*)
88 #include "G3toG4.inc"
89 *
90  print *,'Initializing Geant3 to Geant4 conversion'
91 #ifdef CALL_GEANT
92 c dogeom = index(chopt,'G') + index(chopt,'g') .ne. 0
93  dogeom = .true.
94 #else
95  dogeom = .false.
96 #endif
97  context = '----'
98  if (luni.eq.0.and.lunc.eq.0) then
99  print *,'G3TOG4: No output requested by user. No output'//
100  + ' will be generated.'
101  endif
102  lunlist = abs(luni)
103  luncode = abs(lunc)
104  if (lunlist.ne.0) then
105  doclist = .true.
106  else
107  doclist = .false.
108  endif
109  if (luncode.ne.0) then
110  docode = .true.
111  else
112  docode = .false.
113  endif
114 *** If lun>0, open the file
115  if (lunlist.gt.0) then
116  open(unit=lunlist,file='g3calls.dat',status='unknown')
117  endif
118  if (luncode.gt.0) then
119  nfile = 1
120  call g3source
121  endif
122 *
123  end
124 *
125  subroutine g4init
126 ************************************************************************
127 ************************************************************************
128  implicit none
129 #include "G3toG4.inc"
130 *
131  if (luncode.ne.0) then
132  write(luncode,
133  + '(''//G4GeometryManager* GeoMgr = new G4GeometryManager();'')')
134 * call ctocp('void G3G4init();')
135  endif
136 *
137  end
138 *
139  subroutine g3header
140 ************************************************************************
141 *
142 ************************************************************************
143  implicit none
144  call g4init
145  end
146 
147  subroutine g3source
148 ************************************************************************
149 *
150 ************************************************************************
151  implicit none
152 #include "G3toG4.inc"
153  character fname*30
154  if (luncode.le.0) return
155  if (nfile.gt.1) write(luncode,'(''}'')')
156  close(luncode)
157  write (fname,'(''G3toG4code_'',i2.2,''.cc'')') nfile
158  open(unit=luncode,file=fname,status='unknown')
159  write(luncode,'(''#include "G3toG4.hh"'')')
160  if (nfile.eq.1) call g3header
161  write(luncode,'(/''void G3toG4code_'',i2.2,''()'')') nfile
162  write(luncode,'(''{'')')
163  call ctocp('// init to 0 avoids "unused" warnings')
164  call ctocp('G4int nd=0,nh=0,nv=0,imate=0,itmed=0,nmat=0,')
165  call ctocp(' isvol=0,ifield=0,nwhi=0,nwdi=0,idtyp=0,ipart=0,')
166  call ctocp(' itrtyp=0,nlmat=0,npar=0,ndvmx=0,numed=0,iaxis=0,')
167  call ctocp(
168  + ' ndiv=0,irot=0,ival=0,num=0,nmed=0,nbits[100],mode[6];')
169  call ctocp('G4String chnam[100];')
170  call ctocp('G4String name="",moth="",attr="",only="",shape="";')
171  call ctocp('G4String chset="",chdet="",chali="",chpar="";')
172  call ctocp('G4double amass=0.,charge=0.,tlife=0.,parval=0.;')
173  call ctocp('G4double c0=0.,step=0.,a=0.,dens=0.,radl=0.,x=0.;')
174  call ctocp('G4double y=0.,z=0.,theta1=0.,phi1=0.,theta2=0.;')
175  call ctocp('G4double phi2=0.,theta3=0.,phi3=0.,fieldm=0.;')
176  call ctocp('G4double tmaxfd=0.,stemax=0.,deemax=0.,epsil=0.;')
177  call ctocp('G4double stmin=0.,par[100],fact[100],orig[100];')
178  call ctocp('G4double bratio[6],aa[100],zz[100],wmat[100];')
179  call ctocp('nbits[0]=mode[0]=0;chnam[0]="";par[0]=0.;')
180  call ctocp('fact[0]=orig[0]=bratio[0]=aa[0]=zz[0]=wmat[0]=0.;')
181  call ctocp(' ')
182  if (nfile.eq.1) then
183 * call ctocp('G3G4init();')
184  call ctocp(' ')
185  endif
186  end
187 
188  subroutine g3main
189 ************************************************************************
190 ************************************************************************
191  implicit none
192 #include "G3toG4.inc"
193  integer i
194 *
195  close(luncode)
196  open(unit=luncode,file='G3toG4code.cc',status='unknown')
197  do i=1,nfile
198  write(luncode,'('' void G3toG4code_'',i2.2,''();'')') i
199  enddo
200  call ctocp('void G3toG4code()')
201  call ctocp('{')
202  do i=1,nfile
203  write(luncode,'('' G3toG4code_'',i2.2,''();'')') i
204  enddo
205  call ctocp('}')
206  close(luncode)
207  end
208 
209  subroutine g3context(cntxt)
210 ************************************************************************
211 *
212 * g3context
213 *
214 * Set the current geometry code context. eg. context can be used
215 * to distinguish code for different subdetectors. The Geant4
216 * call list interpreter can then execute the code selectively for
217 * a particular context only, if desired. Spaces not allowed.
218 *
219 ************************************************************************
220  implicit none
221  character*(*) cntxt
222 #include "G3toG4.inc"
223  context = cntxt
224  end
225 *
226  subroutine ctocp(string)
227 ************************************************************************
228 ************************************************************************
229  implicit none
230  character*(*) string
231 #include "G3toG4.inc"
232  write (luncode,*) string
233  end
234 *
235  subroutine rtocp(string,x)
236 ************************************************************************
237 ************************************************************************
238  implicit none
239  character*(*) string
240  real x
241 #include "G3toG4.inc"
242  write(luncode,'(4x,a,'' = '',e14.8,'';'')')
243  + string, x
244  end
245 *
246  subroutine artocp(string,ax,n)
247 ************************************************************************
248 ************************************************************************
249  implicit none
250  character*(*) string
251  real ax(*)
252  integer n,i
253 #include "G3toG4.inc"
254  do i=1,n
255  write(luncode,'('' '',a,''['',i3,''] = '',e14.8,'';'')')
256  + string, i-1, ax(i)
257  enddo
258  end
259 *
260  subroutine aitocp(string,ai,n)
261 ************************************************************************
262 ************************************************************************
263  implicit none
264  character*(*) string
265  integer ai(*)
266  integer n,i
267 #include "G3toG4.inc"
268  do i=1,n
269  write(luncode,'('' '',a,''['',i3,''] = '',i10,'';'')')
270  + string, i-1, ai(i)
271  enddo
272  end
273 *
274  subroutine astocp(string,ac,n)
275 ************************************************************************
276 ************************************************************************
277  implicit none
278  character*(*) string, ac(*)
279  integer n,i
280 #include "G3toG4.inc"
281 c write(luncode,'('' G4String '',a,''['',i3,''];'')') string, n
282  do i=1,n
283  write(luncode,'('' '',a,''['',i3,''] = "'',a,''";'')')
284  + string, i-1, ac(i)
285  enddo
286  end
287 *
288  subroutine g3ldpar(par,npar)
289 ************************************************************************
290 *
291 * g3ldpar
292 *
293 ************************************************************************
294  implicit none
295 *
296  integer npar, i
297  real par(*)
298 #include "G3toG4.inc"
299 *
300  if (npar.gt.0) then
301  write(luncode,'('' par['',i4,''] = '',e14.8,'';'')')
302  + (i-1,par(i),i=1,npar)
303  endif
304  end
305 *
306  subroutine check_lines
307 ************************************************************************
308 ************************************************************************
309  implicit none
310 #include "G3toG4.inc"
311  if (luncode.ne.0) then
312  nlines = nlines +1
313  if (nlines.gt.maxlines) then
314  nfile = nfile +1
315  call g3source
316  nlines = 0
317  endif
318  endif
319  end
subroutine astocp(string, ac, n)
Definition: g3tog4.F:274
BasicVector3D< T > unit() const
subroutine artocp(string, ax, n)
Definition: g3tog4.F:246
TFile * file
subroutine rtocp(string, x)
Definition: g3tog4.F:235
subroutine g3header
Definition: g3tog4.F:139
Char_t n[5]
subroutine aitocp(string, ai, n)
Definition: g3tog4.F:260
subroutine g4init
Definition: g3tog4.F:125
const XML_Char * context
Definition: expat.h:434
Double_t x
Definition: plot.C:279
subroutine g3context(cntxt)
Definition: g3tog4.F:209
int status
Definition: tracer.cxx:24
subroutine check_lines
Definition: g3tog4.F:306
subroutine g3tog4(luni, lunc, chopt)
Definition: g3tog4.F:61
subroutine ctocp(string)
Definition: g3tog4.F:226
subroutine g3source
Definition: g3tog4.F:147
void print(const std::vector< T > &data)
Definition: DicomRun.hh:111
subroutine g3ldpar(par, npar)
Definition: g3tog4.F:288
nlines
subroutine g3main
Definition: g3tog4.F:188