0001 function out=extract_obslog(file,string,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 out=[];
0021 fprintf('Number of inputs = %d\n', nargin)
0022
0023 if nargin ==2
0024 disp('extract_obslog:: Using the entire file-no time interval')
0025 else if nargin ==4
0026 disp('extract_obslog:: Using the time interval')
0027 disp(varargin(1))
0028 disp('extract_obslog:: TO')
0029 disp(varargin(2))
0030 else
0031 error('extract_obslog:: Not correct number of arguments: Either call this function with 2 arguments or with 4 arguments- \n See help extract_obslog for details')
0032 end
0033 end
0034
0035 if(nargin==4)
0036 time_start=datevec(varargin(1),'dd-mmm-yyyy:HH:MM:SS');
0037 time_end=datevec(varargin(2),'dd-mmm-yyyy:HH:MM:SS');
0038 tstart_num=datenum(time_start);
0039 tend_num=datenum(time_end);
0040 end
0041 fid = fopen(file,'r');
0042 i=0;
0043 while 1
0044 tline = fgetl(fid);
0045 if ~ischar(tline), break, end
0046
0047 try
0048
0049 pat = '\s\s\s';
0050 tline;
0051 string;
0052 t=regexp(tline, pat,'split');
0053 i;
0054 t=regexp(tline, pat,'split');
0055
0056
0057 a=strfind(tline,string);
0058
0059
0060 if a~[];
0061
0062
0063
0064
0065
0066 if nargin ==4
0067 time_startfile=datevec(t{1},'dd-mmm-yyyy:HH:MM:SS');
0068 time_endfile=datevec(t{2},'dd-mmm-yyyy:HH:MM:SS');
0069 tstart_filenum=datenum(time_startfile);
0070 tend_filenum=datenum(time_endfile);
0071
0072
0073 if (tend_filenum<tend_num) & (tstart_filenum>tstart_num)
0074 i=i+1;
0075 out{i,1}=t{1};
0076 out{i,2}=t{2};
0077 out{i,3}=t{3};
0078 end
0079 else if nargin==2
0080
0081 i=i+1;
0082
0083
0084
0085 end
0086 end
0087 end
0088 catch
0089 disp('extract_obslog:: Error');
0090 end
0091 end
0092
0093 ST = fclose(fid);