source: ETALON/SPESO/analysis/analyseDataRange.m @ 751

Last change on this file since 751 was 81, checked in by delerue, 10 years ago

Changed path in some parts of the analysis code

File size: 4.9 KB
Line 
1%dirname='20140202'
2%time_start_of_range='00-00-00';
3%time_end_of_range='01-00-00';
4
5function analyseDataRange(dirname,time_start_of_range,time_end_of_range)
6    addSPESOpath
7    basedir='/sps/sera/delerue/smith-purcell/SPESO/data/';
8    cd(basedir)
9   
10base_save_file_name= [  dirname '/' 'data_' dirname '_from_' time_start_of_range '_to_' time_end_of_range ];
11mat_save_file=[base_save_file_name '_save.mat' ];
12%%% End of parameters
13start_of_day=datenum(dirname,'yyyymmdd');
14num_start_of_range=datenum([dirname ' ' time_start_of_range ],'yyyymmdd HH-MM-SS');
15  num_end_of_range=datenum([dirname ' ' time_end_of_range ],'yyyymmdd HH-MM-SS');
16
17%num_end_of_range-num_start_of_range
18
19htmlOut=[ '<h1> Range summary : ' dirname ' from ' time_start_of_range ...
20          ' until ' time_end_of_range ' </h1>'];
21htmlOut=[ htmlOut '<A HREF=summary.html> Daily summary for ' dirname ' </A> <BR/>'];
22
23
24
25txt=ls('--color=never','-1',[ dirname '/*_dec.txt.gz' ]);
26txt=strrep(txt,char(32),char(10));
27txt=[char(10) txt char(10) ]; %we are sure that the text starts and finishes with char(10)
28txt=strrep(txt,[char(10) char(10) ], char(10));
29txt=strrep(txt,[char(10) char(10) ], char(10));
30allPos=strfind(txt,char(10));
31nFiles=size(allPos,2)-1
32iFile=0;
33allData=0;
34allSignals=0;
35channelsToPlot=[ 8 10 12 13 14 ];
36
37
38htmlOut=[ htmlOut ' <TABLE>'  ];
39           
40        htmlOut=[ htmlOut  '<TR><TD colspan=' num2str(length(channelsToPlot)) '> Average </TD></TR><TR>' ];
41        for iloop=channelsToPlot
42        htmlOut=[ htmlOut '<TD> <IMG width=400 SRC=../' base_save_file_name '_data_' num2str(iloop) '.png></TD>' ];
43        end %for
44            htmlOut=[ htmlOut ' </TR>'  ];
45
46%%% Check the number of files to be analysed
47iFileToAnalyse=0;
48for iloop=2:size(allPos,2)   
49  date_txt=txt(allPos(1,iloop-1)+21:allPos(1,iloop-1)+21+18);
50    date_array(iloop-1)=datenum(date_txt,'yyyy-mm-dd_HH-MM-SS');
51    if ((date_array(iloop-1)>=num_start_of_range)&&(date_array(iloop-1)<=num_end_of_range))
52        iFileToAnalyse=iFileToAnalyse+1;
53    end %if file OK
54end %for each file
55
56            matFileAlreadyDone=0;
57    if (exist(mat_save_file)==2)
58        disp(['Mat file exists ' mat_save_file ]);
59        mat=load(mat_save_file);
60        if (mat.iFile==iFileToAnalyse)
61            matFileAlreadyDone=1;
62        end
63    else
64        disp(['Mat file does not exist ' mat_save_file ]);
65    end
66
67%%% Analyse each file to be analysed
68if (matFileAlreadyDone==0)
69
70for iloop=2:size(allPos,2)   
71    %    disp(['dir:' txt(allPos(1,iloop-1):allPos(1,iloop)) '/' ])
72  date_txt=txt(allPos(1,iloop-1)+21:allPos(1,iloop-1)+21+18);
73%    datenum(date_txt,'yyyy-mm-dd_HH-MM-SS')
74%    datenum(date_txt,'yyyy-mm-dd_HH-MM-SS')-start_of_day
75    date_array(iloop-1)=datenum(date_txt,'yyyy-mm-dd_HH-MM-SS');
76    if ((date_array(iloop-1)>=num_start_of_range)&&(date_array(iloop-1)<=num_end_of_range))
77        iFile=iFile+1;
78        disp(['dir: ' num2str(iFile) ' => ' txt(allPos(1,iloop-1)+1:allPos(1,iloop)) ])       
79        [data,signals]=analyseFile(txt(allPos(1,iloop-1)+1:allPos(1,iloop)));
80        if(iFile==1) %first file to be analysed
81        allData=data;
82        allSignals=zeros(nFiles,size(signals,1),size(signals,2));
83        else
84            allData=allData+data;
85        end
86        allSignals(iFile,:,:)=signals;
87        base_save_file_name_file=strrep(strrep(txt(allPos(1,iloop-1)+1:allPos(1,iloop)),'_dec.txt.gz',''),char(10),'');
88            htmlOut=[ htmlOut ' <TR><TD><A HREF=../' base_save_file_name_file ...
89                      '_dec.html> ' base_save_file_name_file ' </A></TD></TR><TR>'  ];
90        for iloop=channelsToPlot
91        htmlOut=[ htmlOut '<TD> <IMG width=400 SRC=../' base_save_file_name_file '_channel_' num2str(iloop) '.png></TD>' ];
92                 
93        end %for
94            htmlOut=[ htmlOut ' </TR>'  ];
95                  end %if file OK
96end %for each file
97            htmlOut=[ htmlOut ' </TABLE>'  ];
98    save(mat_save_file,'iFile','dirname','time_start_of_range','time_end_of_range','allData','allSignals');
99
100    rangeInfo=[ 'Data from ' dirname ' at ' time_start_of_range ' until ' time_end_of_range ];
101
102%size(allPos)
103figure(10041)
104clf
105hold on
106plot(date_array-start_of_day)
107line([ 0 size(allPos,2)-1 ],[num_start_of_range-start_of_day num_start_of_range-start_of_day],'Color','g')
108line([ 0 size(allPos,2)-1 ],[num_end_of_range-start_of_day num_end_of_range-start_of_day],'Color','r')
109hold off
110ylabel('time for start of day (fraction of day)')
111xlabel('file number')
112    title({ rangeInfo; [ 'Time versus files - ' 'nFiles= ' num2str(iFile) ]});
113   
114
115print('-dpng',[base_save_file_name '_day.png' ]);
116        htmlOut=[ htmlOut ' <IMG width=400 SRC=' base_save_file_name ...
117                  '_day.png> <BR/>' ];
118
119if (iFile>0)
120    plotRange(rangeInfo,allData,iFile,allSignals,base_save_file_name);
121end   
122
123        fid=fopen([base_save_file_name '_core.html' ],'w');
124        fprintf(fid,'%s',htmlOut);
125        fclose(fid);
126end % if matFileAlreadyDone==0       
127
128end %function
129
Note: See TracBrowser for help on using the repository browser.