#!/usr/bin/env ruby $: << '~/src/eclipse/autopilot/common/ruby/' require 'gnuplot_support' puts "Usage: #{__FILE__} ublox_csv_dir..." if ARGV.size < 2 then exit(-1) end data = [] target_dirs = [] while target_dir = ARGV.shift if target_dir[-1] == ?/ then target_dir = target_dir[0..-2] end p target_dir rcv_data = {} Dir.open(target_dir).each{|file| if file !~ /ublox_sv_(\d+)\.csv/ then next end sv_number = $1.to_i rcv_data[sv_number] = [] target_file = "#{target_dir}/#{file}" puts "Reading #{target_file}..." open(target_file).each{|line| line.chop! values = line.split(/,\s*/) #p values if values[6].to_i != 0 then next end rcv_data[sv_number] << [values[0].to_f, values[1].to_f] # [gps_time, Carrier phase(L1 cycles)] } } data << rcv_data unless rcv_data.empty? target_dirs << target_dir.gsub(/_/, '\_') end # 時間スケールの導出 t_mins = [] t_maxs = [] data.each{|rcv_data| rcv_data.each{|prn, v| t_mins << v[0][0] t_maxs << v[-1][0] } } t_mins.sort!{|a, b| a <=> b} t_maxs.sort!{|a, b| a <=> b} #p t_mins #p t_maxs t_min = (t_mins[0] / 100).to_i * 100 t_max = ((t_maxs[-1] / 100).to_i + 1) * 100 puts "GPSTime from #{t_min} to #{t_max}." #epsファイルの生成 sv_data = {} data.each_with_index{|rcv_data, i| rcv_data.each{|prn, v| unless sv_data.include?(prn) then sv_data[prn] = [] end sv_data[prn] << [i, v] } } eps_files = {} sv_data.each{|prn, i_v_s| eps_files[prn] = [] } sv_data.each{|prn, i_v_s| fname = "ublox_sv_#{prn}_CP_compare1.eps" Plotter::plot_basic(fname){|plot| plot.xlabel "'GPS Time [sec]'" plot.xrange <<-__STRING__ [#{t_min}:#{t_max}] __STRING__ items = [] i_v_s.each{|i_v| i, v = i_v items << Gnuplot::DataSet::new( [v.collect{|item| item[0]}, v.collect{|item| item[1]}]){|ds| ds.with = "lines lw 3" ds.title = target_dirs[i] } } plot.data = items } eps_files[prn] << fname } sv_data.each{|prn, i_v_s| if i_v_s.size <= 1 then next end items = {} i1, v1 = i_v_s[0] i_v_s[1..-1].each{|i_v2| i2, v2 = i_v2 t = [] y = [] v1_index = 0 v2_index = 0 while v1_index < v1.size and v2_index < v2.size if (v1[v1_index][0] - v2[v2_index][0]).abs < 0.02 then # 多少の誤差は許容する t << v1[v1_index][0] y << v2[v2_index][1] - v1[v1_index][1] v1_index += 1 v2_index += 1 elsif v1[v1_index][0] < v2[v2_index][0] then v1_index += 1 else # v1[v1_index][0] > v2[v2_index][0] v2_index += 1 end end if t.empty? then next end items["#{target_dirs[i2]} - #{target_dirs[i1]}"] = [t, y] } if items.empty? then next end fname = "ublox_sv_#{prn}_CP_compare2.eps" Plotter::plot_basic(fname){|plot| plot.xlabel "'GPS Time [sec]'" plot.xrange <<-__STRING__ [#{t_min}:#{t_max}] __STRING__ plot_items = [] items.each{|title, t_y| plot_items << Gnuplot::DataSet::new(t_y){|ds| ds.with = "lines lw 3" ds.title = title } } plot.data = plot_items } eps_files[prn] << fname =begin fname = "ublox_sv_#{prn}_CP_compare3.eps" Plotter::plot_basic(fname){|plot| plot.xlabel "'GPS Time [sec]'" plot.xrange <<-__STRING__ [#{t_min}:#{t_max}] __STRING__ plot_items = [] items.each{|title, t_y| plot_items << Gnuplot::DataSet::new( [t_y[0], t_y[1].collect{|item| item % 1}]){|ds| ds.with = "lines lw 3" ds.title = title } } plot.data = plot_items } eps_files[prn] << fname =end } #TeXファイルの生成 tex_doc =<<-'__TEX_STRING__' \documentclass[disablejfam]{jsarticle} % pakages \usepackage{times, mathptmx} \usepackage{graphicx} \usepackage{makeidx} \usepackage{bm} \usepackage{amsmath, amssymb} \usepackage{tabularx} \usepackage{slashbox} \usepackage{enumerate} % \usepackage{hyperref} \usepackage{ascmac} \usepackage[dvipdfm,bookmarks=true,bookmarksnumbered=true,bookmarkstype=toc,colorlinks=true,linkcolor=blue]{hyperref} \begin{document} \title{u-blox LEA-4T Raw Data} \maketitle \begin{center} \begin{screen} \begin{itemize} \item u-blox LEA-4T Raw Datas \end{itemize} \end{screen} \end{center} \clearpage __TEX_STRING__ eps_files.to_a.sort{|a, b| a[0] <=> b[0]}.each{|item| sv_number = item[0] fnames = item[1] tex_doc +=<<-__TEX_STRING__ \\section*{PRN#{sv_number}} __TEX_STRING__ fnames.each{|fname| tex_doc +=<<-__TEX_STRING__ \\includegraphics[width=80mm]{#{fname}} __TEX_STRING__ } } tex_doc +=<<-'__TEX_STRING__' \end{document} __TEX_STRING__ ftex_name = 'ublox_cp_compare.tex' ftex_p = open(ftex_name, 'w') ftex_p.print tex_doc ftex_p.close print `platex #{ftex_name}` print `platex #{ftex_name}` print `dvipdfmx #{ftex_name.gsub(/\.tex/, '.dvi')}` #print `rm *.eps`