source: trunk/src/read_lvm.m @ 1162

Last change on this file since 1162 was 1127, checked in by g7moreau, 11 months ago

Update Joel email

File size: 4.4 KB
Line 
1% read_lvm: read data from the output files of labview (file extension .lvm)
2
3%=======================================================================
4% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
5%   http://www.legi.grenoble-inp.fr
6%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
7%
8%     This file is part of the toolbox UVMAT.
9%
10%     UVMAT is free software; you can redistribute it and/or modify
11%     it under the terms of the GNU General Public License as published
12%     by the Free Software Foundation; either version 2 of the license,
13%     or (at your option) any later version.
14%
15%     UVMAT is distributed in the hope that it will be useful,
16%     but WITHOUT ANY WARRANTY; without even the implied warranty of
17%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18%     GNU General Public License (see LICENSE.txt) for more details.
19%=======================================================================
20
21function Data=read_lvm(filename)
22Data.ListGlobalAttribute={'FileName','Experiment','DateTime'};
23[Path,Data.FileName] = fileparts(filename);% record the file name
24[tild,Data.Experiment]=fileparts(Path);% record the experient name
25
26%% read the full text of the file as a char string txt
27txt = fileread(filename);
28
29%% get time string (date and time of the experiment)
30
31Date_pos=regexp(txt,'Date\s','once');%find the char string 'Date' followed by a blank
32txt(1:Date_pos+length('Date'))=[]; %remove the header until 'Date';
33DateString=txt(1:regexp(txt,'\n','once')-1);% read char until the next line break
34r1=regexp(DateString,'(?<DateDat>\S+)','names');% keep the non blank string
35Time_pos=regexp(txt,'Time\s','once');%find the char string 'Time' followed by a blank
36txt(1:Time_pos+length('Time'))=[]; %remove the header until 'Time';
37TimeString=txt(1:regexp(txt,'\n','once')-1);% read char until the next line break
38r2=regexp(TimeString,'(?<TimeDat>\S+)','names');% keep the non blank string
39TimeString=regexprep(r2.TimeDat,',','.');% replace ',' by '.'
40Dot_pos=regexp(TimeString,'\.');
41TimeString=TimeString(1:Dot_pos+2); % round to 1/100 s
42r1.DateDat=regexprep(r1.DateDat,'/','-');%replace '/' by '-' (to get standard date representation recognized by Matlab)
43Data.DateTime=[r1.DateDat ' ' TimeString];%insert date to the time string (separated by a blank)
44
45%% remove header text
46Header_pos=regexp(txt,'***End_of_Header***','once');%find the first '***End_of_Header***'
47txt(1:Header_pos+length('***End_of_Header***')+1)=[];%remove header
48Header_pos=regexp(txt,'***End_of_Header***','once');%find the second '***End_of_Header***'
49txt(1:Header_pos+length('***End_of_Header***')+1)=[];%remove header
50title_pos=regexp(txt,'\S','once');% find the next non blank char
51txt(1:title_pos-1)=[];% remove the  blank char at the beginning
52
53%% get the list of channel names
54Break_pos=regexp(txt,'\n','once');%find the line break
55VarNameCell=textscan(txt(1:Break_pos-2),'%s');% read list of variable names (until next line break)
56Data.ListVarName=VarNameCell{1};
57Data.ListVarName(end)=[]; %remove last name (Comment)
58Data.ListVarName{1}='Time'; %replace first name ('X_Value') by 'Time')
59NbChannel=numel(Data.ListVarName);
60for ivar=1:NbChannel
61    Data.VarDimName{ivar}='nb_sample';
62end
63
64%% get the data
65txt(1:Break_pos-1)=[];%removes line of channel names
66txt=regexprep(txt,',','.');%replace comma by dots (French to English notation)
67txt=textscan(txt,'%s');% transform txt in a cell of strings
68txt=reshape(txt{1},NbChannel,[]);
69txt=cellfun(@str2double,txt);% transform char to a matrix of numbers
70txt=txt'; %transpose matrix
71for ivar=1:NbChannel
72    Data.(Data.ListVarName{ivar})=txt(:,ivar);
73end
74
75%% calculate position in case of a non-zero motor signal
76% To plot profiles(e;g.for C5):  plot(Data.Position(Data.Speed<0),Data.C5(Data.Speed<0))
77SpeedDown=-1; %motot speed 1 cm/s
78SpeedUp=1; %motot speed 1 cm/s
79if isfield(Data,'Motor_profile')% Motor_profile signal =0 (no motion), -5 (down), +5(up)
80    Data.ListVarName=[Data.ListVarName' {'Position','Speed'}];
81    Data.VarDimName=[Data.VarDimName {'nb_sample','nb_sample'}];
82    Speed=zeros(size(Data.Motor_profile));
83    if ~isempty(find(Data.Motor_profile>2.5|Data.Motor_profile<-2.5))
84        Speed(Data.Motor_profile>2.5)=SpeedDown;% threshold at 2.5 to avoid noise effects
85        Speed(Data.Motor_profile<-2.5)=SpeedUp;
86        Data.Speed=Speed;
87        Speed(end)=[];
88        Data.Position=[0; cumsum(Speed.*diff(Data.Time))];
89        Data.Position=Data.Position-min(Data.Position);% set minimum to 0
90    end
91end
92   
Note: See TracBrowser for help on using the repository browser.