lib/metamri/raw_image_file.rb in metamri-0.2.17 vs lib/metamri/raw_image_file.rb in metamri-0.2.18
- old
+ new
@@ -1,5 +1,6 @@
+# encoding: utf-8
require 'pp'
require 'rubygems';
require 'yaml';
# require 'sqlite3';
require 'dicom'
@@ -29,11 +30,11 @@
}
#:startdoc:
# The file name that the instance represents.
attr_reader :filename
- # Which header reading utility reads this file, currently 'rdgehdr' or 'dicom_hdr'.
+ # Which header reading utility reads this file, currently 'rdgehdr'(old p-files&wimr) or 'dicom_hdr' or 'printraw'(new p-files->waisman).
attr_reader :hdr_reader
# File types are either 'dicom' or 'pfile'.
attr_reader :file_type
# The date on which this scan was acquired, this is a ruby DateTime object.
attr_reader :timestamp
@@ -269,18 +270,25 @@
def read_header(absfilepath)
case File.basename(absfilepath)
when /^P.{5}\.7$|^I\..{3}/
# Try reading Pfiles or Genesis I-Files with GE's printraw
- @current_hdr_reader = PRINTRAW
- header = `#{PRINTRAW} '#{absfilepath}' 2> /dev/null`
- #header = `#{RDGEHDR} #{absfilepath}`
- if ( header.chomp != "" and
- header.length > MIN_HDR_LENGTH )
- @current_hdr_reader = nil
- return [ header, PRINTRAW ]
- end
+ # printraw works on the new waisman p-files
+ # rdgehdr works on wimr p-files, and old waisman p-files
+ @current_hdr_reader = PRINTRAW
+ puts "aaaaaaa absfilepath="+absfilepath
+ header = `#{PRINTRAW} '#{absfilepath}' 2> /dev/null`
+ #header = `#{RDGEHDR} #{absfilepath}`
+ #puts "bbbbb header="+header
+ header = header.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "").force_encoding('UTF-8')
+ if ( header.chomp != "" and
+ header.length > MIN_HDR_LENGTH )
+ @current_hdr_reader = nil
+ return [ header, PRINTRAW ]
+ end
+
+
# Try reading Pfiles or Genesis I-Files with GE's rdgehdr -- rdgehdr newer version needs macos 10.8, adrcdev2 = 10.7.5 -
# works on old headers, not on new header format
###@current_hdr_reader = RDGEHDR
###header = `#{RDGEHDR} '#{absfilepath}' 2> /dev/null`
#header = `#{RDGEHDR} #{absfilepath}`
@@ -347,11 +355,11 @@
# 0008,0030 Study Time TM 6 101538
# 0008,0080 Institution Name LO 4 Institution
# 0008,1010 Station Name SH 8 Station
# 0008,0018 SOP Instance UID 12 1.2.840.113619.2.155.3596.6906438.17031.1121881958.942
# 0008,1030 Study Description LO 12 PILOT Study
- # 0008,103E Series Description LO 12 3pl loc FGRE
+ # 0008,103E Series Description LO 12 3pl loc FGR
# 0008,1070 Operators' Name PN 2 SP
# 0008,1090 Manufacturer's Model Name LO 16 DISCOVERY MR750
# 0010,0010 Patient's Name PN 12 mosPilot
# 0010,0020 Patient ID LO 12 RMREKKPilot
# 0010,0040 Patient's Sex CS 2 F
@@ -601,14 +609,29 @@
rep_time_pat = /reptime = ([0-9]+)/i # not sure ifg this is right
study_uid_pat = /Ssop_uid = ([[:graph:]]+)/i
series_uid_pat = /series_uid = ([[:graph:]]+)/i
image_uid_pat = /image_uid = (.*)/i #([[:graph:]]+)/i
+ # @hdr_data = @hdr_data.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "").force_encoding('UTF-8')
+ #@hdr_data = @hdr_data.encode!('UTF-8', 'UTF-8', :invalid => :replace)
+ #@hdr_data_2 = @hdr_data.encode("UTF-8")
+ #@hdr_data.encode!("ISO-8859-1", :invalid => :replace).encode("UTF-8")
+ #@hdr_data.encode("UTF-8", :invalid => :replace, :replace => "") == invalid byte sequence in UTF-8
+ #@hdr_data.encode!("UTF-8", :invalid => :replace, :replace => "") invalid byte sequence in UTF-8
+ #@hdr_data.encode("ISO-8859-1", :invalid => :replace) invalid byte sequence in UTF-8
+ #@hdr_data = @hdr_data.encode('UTF-8','binary', :invalid => :replace,:undef => :replace, :replace =>'') #Attribute was supposed to be a Hash, but was a String
+ #@hdr_data = @hdr_data.encode('UTF-8','UTF-8', :invalid => :replace,:undef => :replace, :replace =>'') # invalid byte sequence in UTF-8
+ #@hdr_data.encode('UTF-8','UTF-8', :invalid => :replace,:undef => :replace, :replace =>'') # invalid byte sequence in UTF-8
+ hdr_data_bak = @hdr_data
+ @hdr_data.encode!("ISO-8859-1", :invalid => :replace).encode("UTF-8") #Attribute was supposed to be a Hash, but was a String
+ puts "aaaaaaaaaaa"
+
rmr_number_pat =~ @hdr_data
@rmr_number = ($1).nil? ? "rmr not found" : ($1).strip.chomp
-
+ puts "bbbbbbbb "
+
source_pat =~ @hdr_data
@source = ($1).nil? ? "source not found" : ($1).strip.chomp
num_slices_pat =~ @hdr_data
@num_slices = ($1).to_i
@@ -632,28 +655,28 @@
@acquisition_matrix_y = ($1).to_i
series_description_pat =~ @hdr_data
@series_description = ($1).strip.chomp
-
recon_diam_pat =~ @hdr_data
@reconstruction_diameter = ($1).to_i
bold_reps_pat =~ @hdr_data
@bold_reps = ($1).to_i
rep_time_pat =~ @hdr_data
@rep_time = ($1).to_f / 1000000
-
study_uid_pat =~ @hdr_data
@study_uid = ($1).strip.chomp unless $1.nil?
series_uid_pat =~ @hdr_data
- @series_uid = ($1).strip.chomp unless $1.nil?
-
+ @series_uid = ($1).strip.chomp unless $1.nil?
image_uid_pat =~ @hdr_data
@image_uid = ($1).strip.chomp unless $1.nil?
+
+puts "rrrrrr @image_uid ="+@image_uid .to_s
+ @hdr_data = nil
end
# Extracts a collection of metadata from @hdr_data retrieved using the rdgehdr
# utility.
\ No newline at end of file