Module: LasReader

Included in:
CWLSLas
Defined in:
lib/las_reader.rb,
lib/las_reader/version.rb

Defined Under Namespace

Classes: Curve, CurveInfo, Mnemonic, WellInfo

Constant Summary collapse

VERSION =
"0.0.5"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#curvesObject (readonly)

Returns the value of attribute curves.



11
12
13
# File 'lib/las_reader.rb', line 11

def curves
  @curves
end

#file_encodeObject (readonly)

Returns the value of attribute file_encode.



14
15
16
# File 'lib/las_reader.rb', line 14

def file_encode
  @file_encode
end

#parametersObject (readonly)

Returns the value of attribute parameters.



12
13
14
# File 'lib/las_reader.rb', line 12

def parameters
  @parameters
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/las_reader.rb', line 9

def version
  @version
end

#well_infoObject (readonly)

Returns the value of attribute well_info.



13
14
15
# File 'lib/las_reader.rb', line 13

def well_info
  @well_info
end

#wrapObject (readonly)

Returns the value of attribute wrap.



10
11
12
# File 'lib/las_reader.rb', line 10

def wrap
  @wrap
end

Instance Method Details

#get_file_encoding(encoding) ⇒ Object



171
172
173
174
175
176
177
178
# File 'lib/las_reader.rb', line 171

def get_file_encoding(encoding)
  return Encoding.default_external if encoding.nil?
  if Encoding.name_list.include?(encoding)
    return Encoding.find(encoding)
  else
    raise "Encoding not supported" 
  end
end

#load_file(file_name, file_options = {}) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/las_reader.rb', line 180

def load_file(file_name, file_options = {})

temp_array = []
@curves = {}
@parameters = {}
@acurves = []

read_state = 0

@file_encoding = get_file_encoding(file_options[:encoding]) 

unless File.exist?(file_name)
  raise "No such file or directory"
end

File.open(file_name, encoding: @file_encoding).each do |uline|

  # characters not supported in the default encoding are replaced by space - This is suggested by the CWLS LAS documentation.
  line = uline.encode(Encoding.default_external, @file_encoding, invalid: :replace, undef: :replace, replace: ' ')

  # ignore comments
  next if line[0].chr == '#' 
  # The '~' is used to inform the beginning of a section
  if line[0].chr == '~' 
    case line[1].chr
        when 'V' # Version information section
          read_state = 1 
        when 'W' # Well identification section
          @well_info = WellInfo.new
          read_state = 2 
        when 'C' # Curve information section
          read_state = 3
        when 'P' # Parameters information section
          #set_log_pattern(curves.size)
          read_state = 4 
        when 'O' # Other information section
          read_state = 5 
        when 'A' # ASCII Log data section
          read_state = 6 
        else
          raise "unsupported file format for #{line}"
        read_state = 0 # Unknow file format
      end
    else
      case read_state
      when 1
        set_version(line.lstrip)
      when 2
        set_well_info(line.lstrip) 
      when 3
        set_curve_info(line.lstrip)
      when 4
        set_parameters(line.lstrip)
      when 5
        set_other_info(line) 
      when 6
        if self.wrap
          temp_array = log_wrap_data(line,temp_array)
        else
          log_nowrap_data(line)
        end 
      end
    end
  end
end

#log_nowrap_data(info) ⇒ Object



161
162
163
164
165
166
167
168
169
# File 'lib/las_reader.rb', line 161

def log_nowrap_data(info)
  d=info.scan(/[-]?[0-9]+.[0-9]+/)
  unless d.nil?
    self.curves.each do |k,v|
      value = d[@acurves.index(k)].to_f
      v.log_data << ((value == @well_info.null_value) ? nil : value)
    end
  end
end

#log_wrap_data(info, temp_array) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/las_reader.rb', line 148

def log_wrap_data(info,temp_array)
  d=info.scan(/[-]?[0-9]+.[0-9]+/)
  a = temp_array + d if not d.nil?
  if a.size == self.curves.size
    self.curves.each do |k,v|
      value = a[@acurves.index(k)].to_f
      v.log_data << ((value == @well_info.null_value) ? nil : value)
    end
    a = []
  end
  return a
end

#set_curve_info(info) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/las_reader.rb', line 29

def set_curve_info(info)
  mnemonic = info.match(/(\w+)\s*\.(\S*)\s+(.*):\s*(.*)$/)
  unless mnemonic.nil?
    @curves["#{mnemonic[1]}"] = Curve.new(mnemonic[1],mnemonic[2],mnemonic[3],mnemonic[4])
    @acurves << mnemonic[1]
  end
end

#set_other_info(info) ⇒ Object



145
146
# File 'lib/las_reader.rb', line 145

def set_other_info(info)
end

#set_parameters(info) ⇒ Object



37
38
39
40
41
42
# File 'lib/las_reader.rb', line 37

def set_parameters(info)
  mnemonic = info.match(/(\w+)\s*\.(\S+)\s+(.*):\s*(.*)$/)
  unless mnemonic.nil?
    @parameters["#{mnemonic[1]}"] = Mnemonic.new(mnemonic[1],mnemonic[2],mnemonic[3],mnemonic[4])
  end
end

#set_version(info) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/las_reader.rb', line 16

def set_version(info)
  version = info.match(/(VERS\s*\.).+([1-3]\.[0-9]).*:\s*(.*)/)
  if version.nil?
    wrap_mode = info.match(/(WRAP\s*\.).+(YES|NO).*:\s*(.*)/)
    if not wrap_mode.nil?
      @wrap =  (wrap_mode[2] == "YES") ? true : false
    end
  else
    @version = version[2]
    raise "LAS version not supported" if @version.to_f > 2.0
  end
end

#set_well_info(info) ⇒ Object



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
# File 'lib/las_reader.rb', line 44

def set_well_info(info)
 
  strt = info.match(/(STRT)\s*\.(\w).+\s([0-9]+\.[0-9]+).*:\s*(.*)/)
  unless strt.nil?
    @well_info.start_depth = strt[3].to_f
    @well_info.depth_unit = strt[2]
    return
  end

  stop = info.match(/(STOP)\s*\.(\w).+\s([0-9]+\.[0-9]+).*:\s*(.*)/)
  unless stop.nil?
    @well_info.stop_depth = stop[3].to_f
    return
  end

  step = info.match(/(STEP)\s*\.(\w).+\s(-?[0-9]+\.[0-9]+).*:\s*(.*)/)
  unless step.nil?
    @well_info.step = step[3].to_f
    return
  end

  null = info.match(/(NULL)\s*\..+\s(-?[0-9]+\.[0-9]+).*:\s*(.*)/)
  unless null.nil?
    @well_info.null_value = null[2].to_f
    return
  end

  comp = info.match(/(COMP\s*\..+COMPANY:\s*(.*))|(COMP\s*\.\s*(.*)\s*:\s*COMPANY)/)
  unless comp.nil?
    @well_info.company_name = (comp[2] or comp[4]).strip
    return
  end

  well = info.match(/(WELL\s*\..+WELL:\s*(.*))|(WELL\s*\.\s*(.*)\s*:\s*.*)/)
  unless well.nil?
    @well_info.well_name = (well[2] or well[4]).strip
    return
  end

  fld = info.match(/(FLD\s*\..+FIELD:\s*(.*))|(FLD\s*\.\s*(.*)\s*:\s*FIELD)/)
  unless fld.nil?
    @well_info.field_name = (fld[2] or fld[4]).strip
    return
  end

  loc = info.match(/(LOC\s*\..+LOCATION:\s*(.*))|(LOC\s*\.\s*(.*)\s*:\s*LOCATION)/)
  unless loc.nil?
    @well_info.location = (loc[2] or loc[4]).strip
    return
  end

  prov = info.match(/(PROV\s*\..+PROVINCE:\s*(.*))|(PROV\s*\.\s*(.*)\s*:\s*PROVINCE)/)
  unless prov.nil?
    @well_info.province = (prov[2] or prov[4]).strip
    return
  end

  cnty = info.match(/(CNTY\s*\..+COUNTY:\s*(.*))|(CNTY\s*\.\s*(.*)\s*:\s*COUNTY)/)
  unless cnty.nil?
    @well_info.county = (cnty[2] or cnty[4]).strip
    return
  end

  stat = info.match(/(STAT\s*\..+STATE:\s*(.*))|(STAT\s*\.\s*(.*)\s*:\s*STATE)/)
  unless stat.nil?
    @well_info.state = (stat[2] or stat[4]).strip
    return
  end

  ctry  = info.match(/(CTRY\s*\..+COUNTRY:\s*(.*))|(CTRY\s*\.\s*(.*)\s*:\s*COUNTRY)/)
  unless ctry.nil?
    @well_info.country = (ctry[2] or ctry[4]).strip
    return
  end

  srvc = info.match(/(SRVC\s*\..+SERVICE COMPANY:\s*(.*))|(SRVC\s*\.\s*(.*)\s*:\s*SERVICE COMPANY)/)
  unless srvc.nil?
    @well_info.service_company = (srvc[2] or srvc[4]).strip
    return
  end

  data = info.match(/(DATE\s*\..+LOG DATE:\s*(.*))|(DATE\s*\.\s*(.*)\s*:\s*LOG DATE)/)
  unless data.nil?
    @well_info.date_logged = (data[2] or data[4]).strip
    return
  end

  uwi = info.match(/(UWI\s*\..+UNIQUE WELL ID:\s*(.*))|(UWI\s*\.\s*(.*)\s*:\s*UNIQUE WELL ID)/)
  unless uwi.nil?
    @well_info.uwi = (uwi[2] or uwi[4]).strip
    return
  end

  api = info.match(/(API\s*\..+UNIQUE WELL ID\s*:\s*(.*))|(API\s*\.\s*(.*)\s*:\s*UNIQUE WELL ID\s*)/)
  unless api.nil?
    @well_info.api = (api[2] or api[4]).strip
    return
  end

end