#!/usr/bin/env ruby #----------------------------------------------------------------------- # call: merge_files.rb fn1 fn2 fn3 # # assume that fn1 and fn2 have the same structure: # 4 columns: run_number, than 3 integers # merge them into a single file leaving run number only once # # used by the lost run sections monitor #----------------------------------------------------------------------- require 'find' require 'fileutils' def usage puts "usage: merge_files fn1 fn2 fn3" exit(-1) end usage if ARGV.length < 2 fn1 = ARGV[0] fn2 = ARGV[1] fn3 = ARGV[2] rc = 0; #----------------------------------------------------------------------- # start #----------------------------------------------------------------------- f1 = File.open(fn1) ; output_file = File.new(fn3,"w"); rmax = -1 f1.each_line { |line1| rn1 = line1.split()[0].to_i; rs1_1 = line1.split()[1].to_i; rs2_1 = line1.split()[2].to_i; n1_1 = line1.split()[3].to_i; n2_1 = line1.split()[4].to_i; ok = 0 f2 = File.open(fn2) ; f2.each_line { |line2| rn2 = line2.split()[0].to_i; rs1_2 = line2.split()[1].to_i; rs2_2 = line2.split()[2].to_i; n1_2 = line2.split()[3].to_i; n2_2 = line2.split()[4].to_i; if (rn1 == rn2) printf "%8i %8i %8i %8i %8i %8i %8i %8i %8i\n", rn1, rs1_1, rs2_1, n1_1, n2_1, rs1_2, rs2_2, n1_2, n2_2 output_file.printf ("%8i %8i %8i %8i %8i %8i %8i %8i %8i\n", rn1, rs1_1, rs2_1, n1_1, n2_1, rs1_2, rs2_2, n1_2, n2_2); ok = 1 break end } f2.close; if (ok == 0) printf "%8i %8i %8i %8i %8i %8i %8i %8i %8i \n", rn1, rs1_1, rs2_1, n1_1, n2_1, -1, -1, -1, -1 output_file.printf("%8i %8i %8i %8i %8i %8i %8i %8i %8i \n", rn1, rs1_1, rs2_1, n1_1, n2_1, -1, -1, -1, -1) end } #----------------------------------------------------------------------- # done #----------------------------------------------------------------------- puts "merge_files.rb: exit with rc=#{rc}" exit(rc)