source: trunk/src/script_readlvm.m @ 1179

Last change on this file since 1179 was 1179, checked in by sommeria, 4 weeks ago

a few bug repairs and cleaning

File size: 8.5 KB
Line 
1%% get the input file
2project='/fsnet/project/coriolis/2024/24PLUME';
3fileinput=uigetfile_uvmat('pick an input file',project);
4[Path,Name,Ext]=fileparts(fileinput);
5
6%% read the input file
7FileType='';
8if strcmp(Ext,'.lvm')
9    disp(['reading ' fileinput '...'])
10    Data=read_lvm(fileinput)
11elseif strcmp(Ext,'.nc')
12    disp(['reading ' fileinput '...'])
13    Data=nc2struct(fileinput)
14else
15    disp('invalid input file extension')
16end
17
18%% save netcdf file as .lvm
19if strcmp(Ext,'.lvm')
20    OutputFile=fullfile(Path,[Name '.nc']);
21    errormsg=struct2nc(OutputFile,Data);% copy the data in a netcdf file
22    if isempty(errormsg)
23        disp([OutputFile ' written'])
24    else
25        disp(errormsg)
26    end
27    [success,msg] = fileattrib(OutputFile,'+w','g')% allow writing access for the group of users
28end
29
30%% use calibration stored in a specified xml file; always use the same file
31ProbeDoc=[];
32%XmlFile=fullfile(Path,[Name '.xml']);
33XmlFile=fullfile(Path,'calib.xml'); 
34if exist(XmlFile,'file')
35    ProbeDoc=xml2struct(XmlFile)
36else
37    disp('no calibration file .xml detected')
38end
39
40% if isfield(Data,'Position'), C2,C4,C6
41%     Min=1; Data.Position=Data.Position+PositionMin;
42% end
43% a5=-2.134088,b5=1010.1611, Data.C2=Data.C2; Data.C5=a5*Data.C5+b5; Data.C6=Data.C2;
44% ylabelstring='density drho (kg/m3)';
45
46
47%% transform temperature probe signals
48if isfield(ProbeDoc,'T5')&& ~isempty(ProbeDoc.T5)  % if temperature calibration exists; see calibT.m
49   
50    Data.T5=exp((Data.T5 - ProbeDoc.T5.a)./ProbeDoc.T5.b);% transform volt signal into temperature
51    Data.T5=filter(ones(1,60)/60,1,Data.T5); % filter the signal to 4 Hz
52    figure(6); set(6,'name','temperature'); plot(Data.Time,Data.T5);
53    %plot(Data.Time,Data.T5,Data.Time,20+Data.Position/100)
54    title([Data.Experiment ', '  Data.FileName ', Time=' Data.DateTime ', temperature'])
55    xlabel('Time(s)'); ylabel('temperature (degree C)'); %ylim([20 37])
56    grid on
57end
58
59%% check camera signal
60ind_start=find(Data.Trig_cam>3.5,1,'first')
61disp(['camera starts at time ' num2str(Data.Time(ind_start))])
62%% transform and filter conductivity probe signals into [temperature-corrected] density
63ylabelstring='conductivity signal (volts)'; clist=0;% counter of conductivity probes
64for ilist=1:numel(Data.ListVarName)
65    if isequal(Data.ListVarName{ilist}(1),'C');% if the var name begins by 'C'
66        clist=clist+1;
67        CName{clist}=Data.ListVarName{ilist};
68        if isfield(ProbeDoc,CName{clist})&& ~isempty(ProbeDoc.(CName{clist}))
69       
70            a=ProbeDoc.(CName{clist}).a; b=ProbeDoc.(CName{clist}).b;
71            % Data.(CName{clist})=a*Data.(CName{clist})+b;% volts STRAIGHT into density (if const T)
72           
73            %% BUT now need to modify conductivity, density due to temperature effect
74            %% first put into conductivity - using just C5 conductivity calibration for now (22/7/15)
75            ac1 = 0.5766e4; bc1 = 2.9129e4; %% this was found later, w/ different gain. Use the one below instead
76            %% ac1 = 0.4845e4; bc1 = 2.064e4; %% this was w/ the gain when we did the experiments; but it doesn't work?
77            Data.(CName{clist})=ac1*Data.(CName{clist})+bc1; %% voltage translated into conductivity via calibration
78             
79            %% read in temperature...
80            refT = 23; T = Data.T5;
81            Hewitt_fit = [2.2794885e-11 -6.2634979e-9 1.5439826e-7 7.8601061e-5 2.1179818e-2];
82            bfit = reshape(polyval(Hewitt_fit,T(:)),size(T)); bref = reshape(polyval(Hewitt_fit,refT(:)),size(refT));
83            sigTsig18 = (1+bfit.*(T-18)); sigREFsig18 = (1+bref.*(refT-18));
84            modfactor = sigTsig18./sigREFsig18;
85            modfactor = 1./modfactor;  %% now in sigREF/sigT, which (* sigT) below to get sigREF, which can convert to rho
86            Data.(CName{clist})=Data.(CName{clist}).*modfactor %% = temp corrected conductivity (= as if at reference temp)
87           
88            %% now we need to put the modified conductivity back into a (modified) voltage, then estimate density directly.
89            ac2 = 1.7343e-4; bc2 = -5.0048;
90            Data.(CName{clist})=ac2*Data.(CName{clist})+bc2; % temp-corrected voltage
91            Data.(CName{clist})=a*Data.(CName{clist})+b; % now finally voltage into density
92            Data.(CName{clist})=filter(ones(1,20)/20,1,Data.(CName{clist})); % filter the signal to 10 Hz
93            ylabelstring='density drho (g/cm3)';
94                 
95        end
96    end
97end
98
99%% plot conductivity signals
100figure(1); set(1,'name','conductivity')
101bandwidth2=60; % corresponds to 0.25 cm (1 cm/s with 240 pts/s), removes 4 Hertz
102plot_string='plot(';
103for clist=1:numel(CName)
104    Data.(CName{clist})=filter(ones(1,bandwidth2)/bandwidth2,1,Data.(CName{clist}));%low pass filter
105    plot_string=[plot_string 'Data.Time,Data.' CName{clist} ','];
106end
107plot_string(end)=')';
108eval(plot_string)
109legend(CName')
110htitle=title([Data.Experiment ', '  Data.FileName ', Time=' Data.DateTime ', conductivity probes']);
111set(htitle,'Interpreter','none')% desable tex interpreter
112xlabel('Time(s)')
113ylabel(ylabelstring)
114        ylim([1 1.02])
115grid on
116
117if isfield(Data,'Position')
118    %% plot motor position
119    figure(2)
120    set(2,'name','position')
121    plot(Data.Time,Data.Position)
122    htitle=title([Data.Experiment ', '  Data.FileName ', Time=' Data.DateTime ', probe position ']);
123    set(htitle,'Interpreter','none')% desable tex interpreter
124    xlabel('Time(s)')
125    ylabel('Z (cm)')
126    grid on
127    hold on
128    plot(Data.Time,Data.Speed)
129       
130    %% plot conductivity probe profiles (limited to downward motion, Data.Speed<0)
131    if ~isempty(ProbeDoc)
132        figure(3)
133        set(3,'name','profiles')
134        Zmotor=Data.Position(Data.Speed<0);
135        Z=Zmotor*ones(1,numel(CName));%motor position transformed in a matrix with a columnfor each probe
136        Zmax=max(Zmotor);
137        plot_string='plot(';
138        for clist=1:numel(CName)
139            if isfield(ProbeDoc,CName{clist})&& ~isempty(ProbeDoc.(CName{clist})) && size(ProbeDoc.(CName{clist}).Position,2)>=2 % if at least two positions are defined to indicate that the probe moves
140               Zprobe=Zmotor-Zmax+ProbeDoc.(CName{clist}).Position(2,3);%upper position of the probe
141               Zprobe(Zprobe<ProbeDoc.(CName{clist}).Position(1,3))=ProbeDoc.(CName{clist}).Position(1,3);
142                Z(:,clist)=Zprobe;% add to z the first z position of the chosen probe (given in the xml file)
143                plot_string=[plot_string 'Z(:,' num2str(clist) '),Data.' CName{clist} '(Data.Speed<0),'];
144            end
145        end
146        plot_string(end)=')';
147        eval(plot_string)
148        legend(CName')
149        htitle=title([Data.Experiment ', '  Data.FileName ', Time=' Data.DateTime ', conductivity probes']);
150        set(htitle,'Interpreter','none')% desable tex interpreter
151        xlabel('Z(cm)')
152        ylabel(ylabelstring)
153        ylim([1 1.02])
154        grid on
155    end
156       
157end
158
159%%%%
160figure(4)
161bandwidth1=480; % corresponds to 2 cm (1 cm/s with 240 pts/s)
162bandwidth2=60; % corresponds to 0.25 cm (1 cm/s with 240 pts/s), removes 4 Hertz
163C5_filter_low=filter(ones(1,bandwidth2)/bandwidth2,1,Data.C5);%low pass filter
164C5_filter=filter(ones(1,bandwidth1)/bandwidth1,1,C5_filter_low);%low pass filter
165C5_filter=C5_filter_low-C5_filter;% high pass filter
166C5_filter(Data.Speed>-0.1)=NaN;
167plot(Data.Time,C5_filter)
168ylim([-0.001 0.001])
169hold on
170plot(Data.Time,Data.Position/100000)
171grid on
172hold off
173title('C5 filtered')
174
175%%%%
176figure(5)
177bandwidth1=480; % corresponds to 2 cm (1 cm/s with 240 pts/s)
178bandwidth2=60; % corresponds to 0.25 cm (1 cm/s with 240 pts/s), removes 4 Hertz
179C3_filter_low=filter(ones(1,bandwidth2)/bandwidth2,1,Data.C3);%low pass filter
180C3_filter=filter(ones(1,bandwidth1)/bandwidth1,1,C3_filter_low);%low pass filter
181C3_filter=C3_filter_low-C3_filter;% high pass filter
182C3_filter(Data.Speed>-0.1)=NaN;
183plot(Data.Time,C3_filter)
184ylim([-0.001 0.001])
185hold on
186plot(Data.Time,Data.Position/100000)
187grid on
188hold off
189title('C3 filtered')
190
191%% plot velocity (ADV) signals
192% figure(5)
193% set(5,'name','velocity')
194% plot(Data.Time,Data.ADV_X,Data.Time,Data.ADV_Y,Data.Time,Data.ADV_Z1,Data.Time,Data.ADV_Z2)
195% legend({'ADV_X';'ADV_Y';'ADV_Z1';'ADV_Z2'})
196% title([Data.Experiment ', '  Data.FileName ', Time=' Data.DateTime ', signal velocity'])
197% xlabel('Time(s)')
198% ylabel('signal (Volt)')
199% grid on
200
201%% plot velocity interface signals
202% figure(6)
203% set(6,'name','interface')
204% plot(Data.Time,Data.I1,Data.Time,Data.I2,Data.Time,Data.I3,Data.Time,Data.I4)
205% legend({'I1';'I2';'I3';'I4'})
206% title([Data.Experiment ', '  Data.FileName ', Time=' Data.DateTime ', signal interface (ultrasound)'])
207% xlabel('Time(s)')
208% ylabel('signal (Volt)')
209% grid on
210
211
212
Note: See TracBrowser for help on using the repository browser.