Class: SciYAG::Backends::MultiTextBackend

Inherits:
TextBackend show all
Includes:
Dobjects
Defined in:
lib/SciYAG/Backends/multitext.rb

Constant Summary

Constants inherited from TextBackend

TextBackend::InvalidLineRE, TextBackend::UNCOMPRESSORS

Instance Method Summary collapse

Methods inherited from TextBackend

#compute_error_bars, #expand_sets, #get_io_object, #get_io_set, #get_set_string, #read_file

Methods inherited from Backend

#base_line=, #clear_xy_filters, default_state, describe, #expand_sets, #get_cached_entry, #has_set?, list_backends, list_descriptions, logger=, #meta_data, #pop_xy_filter, #push_xy_filter, #set_type, #sets_available, #xy_data, #xyz_data

Methods included from MetaBuilder::DescriptionExtend

#base_description, #create_factory, #describe, #description, #factory_class, #factory_description, #factory_description_hash, #factory_description_list, #group, #has_factory?, #inherit_parameters, #param, #param_accessor, #param_reader, #param_writer, #register_class, #set_description

Methods included from MetaBuilder::DescriptionInclude

#description, #get_param, #get_param_raw, #long_name, #option_parser_banner, #option_parser_fill, #option_parser_options, #parameter, #restore_state, #save_state, #set_param, #set_param_raw

Constructor Details

#initializeMultiTextBackend

Returns a new instance of MultiTextBackend.



41
42
43
44
45
46
47
48
49
50
# File 'lib/SciYAG/Backends/multitext.rb', line 41

def initialize
  @dummy = nil
  @current = nil            
  # @current is an array of Dvectors holding the contents of the most
  # recently read files, so that there is no need to read it again.
  @skip = 0
  @included_modules = []    # to make sure we give them to
  # compute_formula
  super()
end

Instance Method Details

#extend(mod) ⇒ Object



52
53
54
55
# File 'lib/SciYAG/Backends/multitext.rb', line 52

def extend(mod)
  super
  @included_modules << mod
end

#get_data(cols, files, set) ⇒ Object

Reads the data using the columns specification, provided that the appropriate files have already been loaded into @current. For now no single sanity check.



82
83
84
85
86
87
88
89
90
91
# File 'lib/SciYAG/Backends/multitext.rb', line 82

def get_data(cols,files,set)
  vectors = []
  cols.each_index do |i|
    vectors.push(@current[files[i]][cols[i].to_i])
  end
  x_formula, y_formula = set.split(':')      
  mods = @included_modules
  return [Dvector.compute_formula(x_formula,vectors,mods),
          Dvector.compute_formula(y_formula,vectors,mods)]
end

#query_xy_data(set) ⇒ Object

This is called by the architecture to get the data. It splits the set name into filename@cols, reads the file if necessary and calls get_data



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/SciYAG/Backends/multitext.rb', line 60

def query_xy_data(set)
  cols = []
  files= []
  nb_match = -1
  new_set = set.gsub(/\[(.*?)@(.*?)\]/) do |match|
    cols.push($2)
    files.push($1)
    nb_match += 1
    "column[#{nb_match}]"
  end
  @current = Hash.new
  files.uniq.each do |file|
    @current[file] = Dvector.fancy_read(file, nil, 
                                        'index_col'  => true, 
                                        'skip_first' => @skip) 
  end
  return Function.new(*get_data(cols,files,new_set))
end