~maddevelopers/mg5amcnlo/2.7.3_rwgtnlo2lo

« back to all changes in this revision

Viewing changes to models/sm/fortran/lha_read.f

adding the possibility to write the MG4 starting from the UFO input.
-> first working version
-> template for the test
-> need to define how we deal with the param_card.dat
-> need to define how we deal with the HELASGENERATOR

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
c************************************************************************
 
2
c**                                                                    **
 
3
c**           MadGraph/MadEvent Interface to FeynRules                 **
 
4
c**                                                                    **
 
5
c**          C. Duhr (Louvain U.) - M. Herquet (NIKHEF)                **
 
6
c**                                                                    **
 
7
c************************************************************************
 
8
 
 
9
c *************************************************************************
 
10
c **                                                                     **
 
11
c **                    LHA format reading routines                      **
 
12
c **                                                                     **
 
13
c *************************************************************************
 
14
 
 
15
 
 
16
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
17
c ++
 
18
c ++ LHA_islatin -> islatin=true if letter is a latin letter
 
19
c ++
 
20
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
21
 
 
22
      subroutine LHA_islatin(letter,islatin)
 
23
      implicit none
 
24
 
 
25
      logical islatin
 
26
      character letter
 
27
      character*26 ref
 
28
      integer i
 
29
 
 
30
      islatin=.false.
 
31
      ref='abcdefghijklmnopqrstuvwxyz'
 
32
 
 
33
      call LHA_case_trap(letter)
 
34
 
 
35
      do i=1,26
 
36
        if(letter .eq. ref(i:i)) islatin=.true.
 
37
      end do
 
38
 
 
39
      end
 
40
 
 
41
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
42
c ++
 
43
c ++ LHA_isnum -> isnum=true if letter is a number
 
44
c ++
 
45
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
46
 
 
47
      subroutine LHA_isnum(letter,isnum)
 
48
      implicit none
 
49
 
 
50
      logical isnum
 
51
      character letter
 
52
      character*10 ref
 
53
      integer i
 
54
 
 
55
      isnum=.false.
 
56
      ref='1234567890'
 
57
 
 
58
      do i=1,10
 
59
        if(letter .eq. ref(i:i)) isnum=.true.
 
60
      end do
 
61
 
 
62
      end
 
63
 
 
64
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
65
c ++
 
66
c ++ LHA_firststring -> first is the first "word" of string
 
67
c ++ Warning: string is returned with first REMOVED!
 
68
c ++
 
69
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
70
 
 
71
      subroutine LHA_firststring(first,string)
 
72
 
 
73
      implicit none
 
74
      character*(*) string
 
75
      character*(*) first
 
76
      
 
77
      if(len_trim(string).le.0) return
 
78
      
 
79
      do while(string(1:1) .eq. ' ') 
 
80
        string=string(2:len(string))
 
81
      end do
 
82
      if (index(string,' ').gt.1) then
 
83
         first=string(1:index(string,' ')-1)
 
84
         string=string(index(string,' '):len(string))
 
85
      else 
 
86
         first=string
 
87
      end if
 
88
 
 
89
      end
 
90
 
 
91
 
 
92
      subroutine LHA_case_trap(name)
 
93
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
94
c ++
 
95
c ++ LHA_case_trap -> change string to lower case
 
96
c ++
 
97
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
98
      implicit none
 
99
      
 
100
      character*20 name
 
101
      integer i,k
 
102
 
 
103
      do i=1,20
 
104
         k=ichar(name(i:i))
 
105
         if(k.ge.65.and.k.le.90) then  !upper case A-Z
 
106
            k=ichar(name(i:i))+32
 
107
            name(i:i)=char(k)
 
108
         endif
 
109
      enddo
 
110
 
 
111
      return
 
112
      end
 
113
 
 
114
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
115
c ++
 
116
c ++ LHA_blockread -> read a LHA line and return parameter name (evntually found in 
 
117
c ++ a ref file) and value
 
118
c ++
 
119
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
120
 
 
121
      subroutine LHA_blockread(blockname,buff,par,val,found)
 
122
 
 
123
      implicit none
 
124
      character*132 buff,buffer,curr_ref,curr_buff
 
125
      character*20 blockname,val,par,temp,first_ref,first_line
 
126
      logical fopened
 
127
      integer ref_file/20/
 
128
      logical islast,isnum,found
 
129
      character*20 temp_val
 
130
 
 
131
 
 
132
c     *********************************************************************
 
133
c     Try to find a correspondance in ident_card
 
134
c
 
135
 
 
136
      call LHA_open_file(ref_file,'ident_card.dat',fopened)
 
137
      if(.not. fopened) goto 99 ! If the file does not exist -> no matter, use default!
 
138
        
 
139
      islast=.false.
 
140
      found=.false.
 
141
      do while(.not. found)!run over reference file
 
142
      
 
143
 
 
144
        ! read a line
 
145
        read(ref_file,'(a132)',end=99,err=99) buffer
 
146
        
 
147
        ! Seek a corresponding blockname
 
148
        call LHA_firststring(temp,buffer)
 
149
        call LHA_case_trap(temp)
 
150
        
 
151
        if(temp .eq. blockname) then
 
152
             ! Seek for a corresponding LHA code
 
153
             curr_ref=buffer
 
154
             curr_buff=buff
 
155
             first_ref=''
 
156
             first_line=''
 
157
             
 
158
             do while((.not. islast).and.(first_ref .eq. first_line))
 
159
                 call LHA_firststring(first_ref,curr_ref)
 
160
                 call LHA_firststring(first_line,curr_buff)
 
161
                 call LHA_islatin(first_ref(1:1),islast)
 
162
                 if (islast) then
 
163
                   par=first_ref
 
164
                   val=first_line ! If found set param name & value
 
165
                   found=.true.
 
166
                 end if
 
167
             end do
 
168
        end if
 
169
                     
 
170
      end do
 
171
      close(ref_file)
 
172
99    return    
 
173
      end
 
174
 
 
175
 
 
176
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
177
c ++
 
178
c ++ LHA_loadcard -> Open a LHA file and load all model param in a table
 
179
c ++
 
180
c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
181
 
 
182
      subroutine LHA_loadcard(param_name,npara,param,value)
 
183
 
 
184
      implicit none
 
185
 
 
186
      integer maxpara
 
187
      parameter (maxpara=1000)
 
188
      character*20 param(maxpara),value(maxpara),val,par
 
189
      character*20 blockname
 
190
      integer npara
 
191
      logical fopened,found
 
192
      integer iunit,GL,logfile
 
193
      character*20 ctemp
 
194
      character*132 buff
 
195
      character*5 tag
 
196
      character*132 temp
 
197
      character*(*) param_name
 
198
      data iunit/21/
 
199
      data logfile/22/
 
200
      GL=0
 
201
      npara=1
 
202
 
 
203
      param(1)=' '
 
204
      value(1)=' '
 
205
 
 
206
      ! Try to open param-card file
 
207
      call LHA_open_file(iunit,param_name,fopened)
 
208
      if(.not.fopened) then
 
209
         print *,'Error: Could not open file',param_name
 
210
         print *,'Exiting'
 
211
         stop
 
212
      endif
 
213
      
 
214
      ! Try to open log file
 
215
      open (unit = logfile, file = "param.log")
 
216
      
 
217
      ! Scan the data file
 
218
      do while(.true.)  
 
219
      
 
220
         read(iunit,'(a132)',end=99,err=99) buff
 
221
         
 
222
         if(buff(1:1) .ne.'#') then ! Skip comments and empty lines
 
223
 
 
224
             tag=buff(1:5)
 
225
             call LHA_case_trap(tag) ! Select decay/block tag
 
226
             if(tag .eq. 'block') then ! If we are in a block, get the blockname
 
227
                 temp=buff(7:132)
 
228
                 call LHA_firststring(blockname,temp)
 
229
                 call LHA_case_trap(blockname)
 
230
             else if (tag .eq. 'decay') then ! If we are in a decay, directly try to get back the correct name/value pair
 
231
                 blockname='decay'
 
232
                 temp=buff(7:132)
 
233
                 call LHA_blockread(blockname,temp,par,val,found)
 
234
                 if(found) GL=1
 
235
             else if ((tag .eq. 'qnumbers').or.(tag.eq.'')) then! if qnumbers or empty tag do nothing
 
236
                 temp=buff(7:132)
 
237
             else ! If we are in valid block, try to get back a name/value pair
 
238
                 call LHA_blockread(blockname,buff,par,val,found)
 
239
                 if(found) GL=1
 
240
             end if
 
241
 
 
242
             !if LHA_blockread has been called, record name and value
 
243
 
 
244
             if(GL .eq. 1) then
 
245
                  value(npara)=val
 
246
                  ctemp=par
 
247
                  call LHA_case_trap(ctemp)
 
248
                  param(npara)=ctemp
 
249
                  npara=npara+1
 
250
                  GL=0
 
251
                  write (logfile,*) 'Parameter ',ctemp,' has been read with value ',val
 
252
             endif
 
253
 
 
254
         endif
 
255
      enddo
 
256
      
 
257
      npara=npara-1
 
258
c      close(iunit)
 
259
      close(logfile)
 
260
      
 
261
 99   return
 
262
 
 
263
      end
 
264
 
 
265
 
 
266
 
 
267
      subroutine LHA_get_real(npara,param,value,name,var,def_value_num)
 
268
c----------------------------------------------------------------------------------
 
269
c     finds the parameter named "name" in param and associate to "value" in value
 
270
c----------------------------------------------------------------------------------
 
271
      implicit none
 
272
 
 
273
c
 
274
c     parameters
 
275
c
 
276
      integer maxpara
 
277
      parameter (maxpara=1000)
 
278
c
 
279
c     arguments
 
280
c
 
281
      integer npara
 
282
      character*20 param(maxpara),value(maxpara)
 
283
      character*(*)  name
 
284
      real*8 var,def_value_num
 
285
      character*20 c_param,c_name,ctemp
 
286
      character*19 def_value
 
287
c
 
288
c     local
 
289
c
 
290
      logical found
 
291
      integer i
 
292
c
 
293
c     start
 
294
c
 
295
      i=1
 
296
      found=.false.
 
297
      do while(.not.found.and.i.le.npara)
 
298
         ctemp=param(i)
 
299
         call LHA_firststring(c_param,ctemp)
 
300
         ctemp=name
 
301
         call LHA_firststring(c_name,ctemp)
 
302
         call LHA_case_trap(c_name)
 
303
         call LHA_case_trap(c_param)
 
304
         found = (c_param .eq. c_name)
 
305
         if (found) then
 
306
             read(value(i),*) var
 
307
         end if
 
308
         i=i+1
 
309
      enddo
 
310
      if (.not.found) then
 
311
         write (*,*) "Warning: parameter ",name," not found"
 
312
         write (*,*) "         setting it to default value ",def_value_num
 
313
         var=def_value_num
 
314
      endif
 
315
      return
 
316
 
 
317
      end
 
318
c
 
319
 
 
320
 
 
321
 
 
322
 
 
323
      subroutine LHA_open_file(lun,filename,fopened)
 
324
c***********************************************************************
 
325
c ����opens file input-card.dat in current directory or above
 
326
c***********************************************************************
 
327
      implicit none
 
328
c
 
329
c ����Arguments
 
330
c
 
331
      integer lun
 
332
      logical fopened
 
333
      character*(*) filename
 
334
      character*90  tempname
 
335
      integer fine
 
336
      integer dirup,i
 
337
 
 
338
c-----
 
339
c �Begin Code
 
340
c-----
 
341
c
 
342
c ����first check that we will end in the main directory
 
343
c
 
344
      open(unit=lun,file=filename,status='old',ERR=20)
 
345
c      write(*,*) 'read model file ',filename
 
346
      fopened=.true.
 
347
      return
 
348
      
 
349
20    tempname=filename
 
350
      fine=index(tempname,' ')
 
351
      if(fine.eq.0) fine=len(tempname)
 
352
      tempname=tempname(1:fine)
 
353
c
 
354
c ��������if I have to read a card
 
355
c
 
356
      if(index(filename,"_card").gt.0) then
 
357
        tempname='./Cards/'//tempname
 
358
      endif
 
359
 
 
360
      fopened=.false.
 
361
      do i=0,5
 
362
        open(unit=lun,file=tempname,status='old',ERR=30)
 
363
        fopened=.true.
 
364
c        write(*,*) 'read model file ',tempname
 
365
        exit
 
366
30      tempname='../'//tempname
 
367
        if (i.eq.5)then
 
368
           write(*,*) 'Warning: file ',filename,' not found in the parent directories!'
 
369
           stop
 
370
        endif
 
371
      enddo
 
372
 
 
373
      return
 
374
      end
 
375