source: trunk/src/read_lvm.m @ 789

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

read_lvm added (reading Labview data)

File size: 3.3 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
23Data.DateTime=[r1.DateDat ' ' TimeString];%insert date to the time string (separated by a blank)
24
25%% remove header text
26Header_pos=regexp(txt,'***End_of_Header***','once');%find the first '***End_of_Header***'
27txt(1:Header_pos+length('***End_of_Header***')+1)=[];%remove header
28Header_pos=regexp(txt,'***End_of_Header***','once');%find the second '***End_of_Header***'
29txt(1:Header_pos+length('***End_of_Header***')+1)=[];%remove header
30title_pos=regexp(txt,'\S','once');% find the next non blank char
31txt(1:title_pos-1)=[];% remove the  blank char at the beginning
32
33%% get the list of channel names
34Break_pos=regexp(txt,'\n','once');%find the line break
35VarNameCell=textscan(txt(1:Break_pos-1),'%s');% read list of variable names (until next line break)
36Data.ListVarName=VarNameCell{1};
37Data.ListVarName(end)=[]; %remove last name (Comment)
38Data.ListVarName{1}='Time'; %replace first name ('X_Value') by 'Time')
39NbChannel=numel(Data.ListVarName);
40for ivar=1:NbChannel
41    Data.VarDimName{ivar}='nb_sample';
42end
43
44%% get the data
45txt(1:Break_pos-1)=[];%removes line of channel names
46txt=regexprep(txt,',','.');%replace comma by dots (French to English notation)
47txt=textscan(txt,'%s');% transform txt in a cell of strings
48txt=reshape(txt{1},NbChannel,[]);
49txt=cellfun(@str2double,txt);% transform char to a matrix of numbers
50txt=txt'; %transpose matrix
51for ivar=1:NbChannel
52    Data.(Data.ListVarName{ivar})=txt(:,ivar);
53end
54
55%% calculate position in case of a non-zero motor signal
56% To plot profiles(e;g.for C5):  plot(Data.Position(Data.Speed<0),Data.C5(Data.Speed<0))
57SpeedDown=-1; %motot speed 1 cm/s
58SpeedUp=1; %motot speed 1 cm/s
59if isfield(Data,'Motor_profile')% Motor_profile signal =0 (no motion), -5 (down), +5(up)
60    Data.ListVarName=[Data.ListVarName' {'Position','Speed'}];
61    Data.VarDimName=[Data.VarDimName {'nb_sample','nb_sample'}];
62    Speed=zeros(size(Data.Motor_profile));
63    if ~isempty(find(Data.Motor_profile>2.5|Data.Motor_profile<-2.5))
64    Speed(Data.Motor_profile>2.5)=SpeedUp;% threshold at 2.5 to avoid noise effects
65    Speed(Data.Motor_profile<-2.5)=SpeedDown;
66    Data.Speed=Speed;
67    Speed(end)=[];
68    Data.Position=[0; cumsum(Speed.*diff(Data.Time))];
69    end
70end
71   
Note: See TracBrowser for help on using the repository browser.