This repository has been archived by the owner on Feb 22, 2021. It is now read-only.
forked from alisw/POWHEG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergedata.f
181 lines (177 loc) · 5.46 KB
/
mergedata.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
c program to merge gnuplot data tables.
c a line starting with '#' followed by a line with 4 numbers
c is considered the beginning of a data set. All files to be
c merged must be identical in format.
c When the program starts, it expects as input a list of filenames,
c one per line, to be merged. An empty lines terminates the list.
implicit none
integer maxfiles,maxlines
parameter (maxfiles=1000,maxlines=25000)
character *(100) files(maxfiles)
character *(100) line(maxlines,maxfiles)
integer nlines(maxfiles)
integer ifile,nfiles,ios,k,imethod
character cmethod
real * 8 v1,v2,v3,v4,y,err
integer ilength
external ilength
C - kh modification started here >>>>>>>
imethod=-1
CALL getarg(1,cmethod)
if(cmethod.eq.'1') then
imethod=1
elseif(cmethod.eq.'2') then
imethod=2
elseif(cmethod.eq.'3') then
imethod=3
elseif(cmethod.eq.'4') then
imethod=4
elseif(cmethod.eq.'5') then
imethod=5
elseif(cmethod.eq.' ') then
imethod=0 ! If nothing follows ./mergedata.exe on the command
! line this setting is acquired which then steers the
! code to read in the combination mode and input files
! from the read command prompts as it had been doing.
else
write(6,*) 'Combination mode must be "1-5" or " " : ',
$ cmethod
write(6,*) 'Quitting ...'
stop
endif
if(imethod.ne.0) then
do ifile=1,maxfiles
CALL getarg(ifile+1,files(ifile))
if(trim(files(ifile)).eq.'') then
nfiles=ifile-1
write(6,*) 'mergedata.exe found',nfiles,
$ 'files on the command line ...'
goto 9
endif
enddo
endif
9 continue
if(imethod.eq.0) then
C - <<<<<<< kh modification ended here.
write(*,*) ' enter 1 for combining sets with equal statistics'
write(*,*) ' 2 to combine uneven sets'
write(*,*) ' 3 to add sets (like born+virtual+real ... etc'
write(*,*) ' 4 to get maximum'
write(*,*) ' 5 to get minimum'
read(*,*) imethod
write(*,*) ' enter files'
do ifile=1,maxfiles
read(*,'(a)') files(ifile)
if(files(ifile).eq.' ') then
nfiles=ifile-1
goto 10
endif
enddo
write(*,*) ' too manny files, increase maxfiles'
call exit(-1)
endif
10 continue
c load data
do ifile=1,nfiles
open(unit=11,file=files(ifile),status='old')
do k=1,maxlines+1
read(unit=11,fmt='(a)',end=111) line(k,ifile)
if(k.eq.maxlines+1) then
write(*,*) ' too many lines in file, increase maxlines'
call exit(-1)
endif
goto 12
111 nlines(ifile)=k-1
goto 11
12 continue
enddo
11 continue
enddo
do ifile=1,nfiles
if(nlines(ifile).ne.nlines(1)) then
write(*,*) ' error: file', files(ifile),
1 ' does not match in length'
call exit(-1)
endif
enddo
do k=1,nlines(1)
read(unit=line(k,1),fmt=*,iostat=ios) v1,v2,v3,v4
if(ios.ne.0) then
write(12,'(a)') line(k,1)(1:ilength(line(k,1)))
else
if(imethod.eq.1) then
y=v3
err=v4**2
elseif(imethod.eq.2) then
if(v4.ne.0) then
y=v3/v4**2
err=1/v4**2
else
y=0
err=0
endif
elseif(imethod.eq.3) then
y=v3
err=v4**2
elseif(imethod.eq.4) then
y=v3
err=v4**2
elseif(imethod.eq.5) then
y=v3
err=v4**2
endif
do ifile=2,nfiles
read(unit=line(k,ifile),fmt=*,iostat=ios) v1,v2,v3,v4
if(imethod.eq.1.or.imethod.eq.3) then
y=y+v3
err=err+v4**2
elseif(imethod.eq.2) then
if(v4.ne.0) then
y=y+v3/v4**2
err=err+1/v4**2
endif
elseif(imethod.eq.3) then
y=y+v3
err=err+v4**2
elseif(imethod.eq.4) then
if(v3.gt.y) then
y=v3
err=v4**2
endif
elseif(imethod.eq.5) then
if(v3.lt.y) then
y=v3
err=v4**2
endif
endif
enddo
if(imethod.eq.1) then
y=y/nfiles
err=sqrt(err/nfiles**2)
elseif(imethod.eq.2) then
if(err.ne.0) then
y=y/err
err=1/sqrt(err)
else
y=0
err=0
endif
elseif(imethod.ge.3) then
err=sqrt(err)
endif
write(12,'(4(1x,d14.8))') v1,v2,y,err
endif
enddo
end
function ilength(line)
integer ilength
character *(*) line
ilength=len(line)
do j=ilength,1,-1
if(line(j:j).ne.' ') then
ilength=j
return
endif
enddo
ilength=0
end