source: trunk/src/read_lvm.m @ 794

Last change on this file since 794 was 794, checked in by sommeria, 10 years ago

read_rdvision corrected

File size: 3.5 KB
Line 
1% read_lvm: read data from the output files of labview (file extension .lvm)
2function Data=read_lvm(filename)
3Data.ListGlobalAttribute={'FileName','Experiment','DateTime'};
4[Path,Data.FileName] = fileparts(filename);% record the file name
5[tild,Data.Experiment]=fileparts(Path);% record the experient name
6
7%% read the full text of the file as a char string txt
8txt = fileread(filename);
9
10%% get time string (date and time of the experiment)
11
12Date_pos=regexp(txt,'Date\s','once');%find the char string 'Date' followed by a blank
13txt(1:Date_pos+length('Date'))=[]; %remove the header until 'Date';
14DateString=txt(1:regexp(txt,'\n','once')-1);% read char until the next line break
15r1=regexp(DateString,'(?<DateDat>\S+)','names');% keep the non blank string
16Time_pos=regexp(txt,'Time\s','once');%find the char string 'Time' followed by a blank
17txt(1:Time_pos+length('Time'))=[]; %remove the header until 'Time';
18TimeString=txt(1:regexp(txt,'\n','once')-1);% read char until the next line break
19r2=regexp(TimeString,'(?<TimeDat>\S+)','names');% keep the non blank string
20TimeString=regexprep(r2.TimeDat,',','.');% replace ',' by '.'
21Dot_pos=regexp(TimeString,'\.');
22TimeString=TimeString(1:Dot_pos+2); % round to 1/100 s
23r1.DateDat=regexprep(r1.DateDat,'/','-');%replace '/' by '-' (to get standard date representation recognized by Matlab)
24Data.DateTime=[r1.DateDat ' ' TimeString];%insert date to the time string (separated by a blank)
25
26%% remove header text
27Header_pos=regexp(txt,'***End_of_Header***','once');%find the first '***End_of_Header***'
28txt(1:Header_pos+length('***End_of_Header***')+1)=[];%remove header
29Header_pos=regexp(txt,'***End_of_Header***','once');%find the second '***End_of_Header***'
30txt(1:Header_pos+length('***End_of_Header***')+1)=[];%remove header
31title_pos=regexp(txt,'\S','once');% find the next non blank char
32txt(1:title_pos-1)=[];% remove the  blank char at the beginning
33
34%% get the list of channel names
35Break_pos=regexp(txt,'\n','once');%find the line break
36VarNameCell=textscan(txt(1:Break_pos-1),'%s');% read list of variable names (until next line break)
37Data.ListVarName=VarNameCell{1};
38Data.ListVarName(end)=[]; %remove last name (Comment)
39Data.ListVarName{1}='Time'; %replace first name ('X_Value') by 'Time')
40NbChannel=numel(Data.ListVarName);
41for ivar=1:NbChannel
42    Data.VarDimName{ivar}='nb_sample';
43end
44
45%% get the data
46txt(1:Break_pos-1)=[];%removes line of channel names
47txt=regexprep(txt,',','.');%replace comma by dots (French to English notation)
48txt=textscan(txt,'%s');% transform txt in a cell of strings
49txt=reshape(txt{1},NbChannel,[]);
50txt=cellfun(@str2double,txt);% transform char to a matrix of numbers
51txt=txt'; %transpose matrix
52for ivar=1:NbChannel
53    Data.(Data.ListVarName{ivar})=txt(:,ivar);
54end
55
56%% calculate position in case of a non-zero motor signal
57% To plot profiles(e;g.for C5):  plot(Data.Position(Data.Speed<0),Data.C5(Data.Speed<0))
58SpeedDown=-1; %motot speed 1 cm/s
59SpeedUp=1; %motot speed 1 cm/s
60if isfield(Data,'Motor_profile')% Motor_profile signal =0 (no motion), -5 (down), +5(up)
61    Data.ListVarName=[Data.ListVarName' {'Position','Speed'}];
62    Data.VarDimName=[Data.VarDimName {'nb_sample','nb_sample'}];
63    Speed=zeros(size(Data.Motor_profile));
64    if ~isempty(find(Data.Motor_profile>2.5|Data.Motor_profile<-2.5))
65    Speed(Data.Motor_profile>2.5)=SpeedUp;% threshold at 2.5 to avoid noise effects
66    Speed(Data.Motor_profile<-2.5)=SpeedDown;
67    Data.Speed=Speed;
68    Speed(end)=[];
69    Data.Position=[0; cumsum(Speed.*diff(Data.Time))];
70    end
71end
72   
Note: See TracBrowser for help on using the repository browser.