Home > matutils > fastextract > fast_extract.m

fast_extract

PURPOSE ^

tool for reading many datasets in at once

SYNOPSIS ^

function fast_extract(file,dir)

DESCRIPTION ^

 tool for reading many datasets in at once
 To work, you must:
 1) create variable "ind" with value 1 and save to where.mat
 This tells it where to start, and must be set this way to start from beginning
 2) change the list of start and stop times below
 3) add a call to this function at the end of your startup.m file
 4) call matlab repeatedly with command sh ./many_matlabs
 the number of calls to matlab is set in that file

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fast_extract(file,dir)
0002 % tool for reading many datasets in at once
0003 % To work, you must:
0004 % 1) create variable "ind" with value 1 and save to where.mat
0005 % This tells it where to start, and must be set this way to start from beginning
0006 % 2) change the list of start and stop times below
0007 % 3) add a call to this function at the end of your startup.m file
0008 % 4) call matlab repeatedly with command sh ./many_matlabs
0009 % the number of calls to matlab is set in that file
0010 
0011 if(~exist('where.mat'))
0012   ind = 1
0013 else
0014   load where
0015 end
0016 
0017 if(length(dir)<1)
0018   dir = '.'
0019 end
0020 
0021 disp(dir);
0022 
0023 if(~exist('file'))
0024   error('no schedule file')
0025 end
0026 
0027 [start, stop, sched] = textread(file,'%s %s %s');
0028 
0029 if ind>size(start,1)
0030   disp('Out of times')
0031   exit
0032 end
0033 
0034 disp(sprintf('%s %s %s',start{ind},stop{ind},sched{ind}));
0035 
0036 % variable i tells which set to do next, lstart and lstop are the
0037 % times of last read
0038 
0039 t1=tstr2date(start{ind});
0040 t2=tstr2date(stop{ind});
0041 % if lstop exists, it means that were not done with the previous set
0042 if exist('lstop')
0043   situation=1; % 1 means that we are halfway through a scan
0044   % we need to pick the next chunk of this data
0045   nstart=lstop; % start with last
0046   t=tstr2date(lstop);
0047   t.hour=t.hour+1; % increment by 4 hrs
0048   if t.hour>23
0049     t.hour=t.hour-24;t.day=t.day+1; % handle crossing of utc=0;
0050   end
0051   nstop=date2tstr(t); % pick this 6hr chunk as next
0052   lstop=nstop;lstart=nstart;
0053 
0054   % add a thing that tells you if the selected end date is past the
0055   % stop point...if so:
0056   if tstr2mjd(nstop)>tstr2mjd(stop{ind})
0057     nstop=stop{ind};
0058   else 
0059     save where ind lstop lstart
0060   end
0061 
0062 else % lstop doesnt exist...ready to start new scan
0063   situation=2; % 2 means that we can do the whole scan at once
0064   nstart=start{ind};nstop=stop{ind};
0065   if (t1.day==t2.day&t1.hour+1<t2.hour)|(t1.day<t2.day&t2.hour-t1.hour+24>1) % scan is more than 6 hrs
0066     situation=3; % 3 means that were starting a new segmented scan
0067     nstart=start{ind};
0068     t=t1;t.hour=t.hour+1;
0069     if t.hour>23
0070       t.hour=t.hour-24;t.day=t.day+1; % handle crossing of utc=0;
0071     end
0072     nstop=date2tstr(t); % pick this 6hr chunk as next
0073     lstop=nstop;lstart=nstart;
0074     save where ind lstop lstart
0075   end 
0076 end
0077 
0078 % Now read new patch in
0079 dnew=read_arc(nstart,nstop);
0080 
0081 switch situation
0082 case 1
0083   load temp %temp will have d if this scan has already started
0084   d=catstruct(1,[d dnew]);
0085   save temp d
0086 case 2
0087   d=dnew;
0088 case 3
0089   d=dnew; 
0090   save temp d
0091 end
0092 
0093 if nstop==stop{ind} %weve finished a scan
0094   t=monthStr2num(tstr2date(start{ind}));
0095   eval(sprintf('save %s/%s_%.2d%s%.2d.mat d',dir,cell2mat(sched(ind)),t.year,cell2mat(getmonth(t.month)),t.day));
0096   
0097   % increment ind if appropriate
0098   ind=ind+1;
0099   save where ind
0100 end
0101 
0102 exit
0103 
0104 return

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005