# This program processes data generated by the program write.jl # It computes the mean values and standard deviations of the mean values # - separately for data in columns 1 and 2 # This function reads data and computes the means and standard devs function processdata(f,ftype) dd=zeros(Float64,2) # to store a single line read from the file av=zeros(Float64,2,2) # to accumulate means and means squares fname=string(ftype,"$f",".dat") # the file name with file index f file=open(fname,"r") println(fname) # prints the file name as a check n=0 while !eof(file) # loop until the end of the file is reached; eof() function if ftype=="ran" dd[1]=parse(Float64,readuntil(file," ")) # reads the number from column 1, assumes " " item separation dd[2]=parse(Float64,readline(file)) # reads the line from column 2 elseif ftype=="bin" read!(file,dd) # reads entire 2-number item in binary format end @. av[1,:]=av[1,:]+dd[:] # accumulating the mean @. av[2,:]=av[2,:]+dd[:]^2 # accumulating the mean of the squares n=n+1 # counting how many lines processed end close(file) println("Processed lines of data: ",n) @. av[:,:] = av[:,:]/n # dividing by n to get the mean @. av[2,:] = abs((av[2,:]-av[1,:]^2)/(n-1))^0.5 # standard dev of the mean return av end println("Give file number") # will read data from one of the files f=parse(Int,readline(stdin)) # The data can be read either from the binary or ASCII formatted file from write.jl println("ASCII (1) or binary (2) data file") t=parse(Int,readline(stdin)) if t==1 ftype="ran" elseif t==2 ftype="bin" else throw(DomainError(t,"Follow the instructions, please!")) end av=processdata(f,ftype) # processes the file and obtain the final results println("Mean values and standard deviations of the mean values") for i=1:2 println(i," ",av[1,i]," ",av[2,i]) end