Home > matutils > interf > grp_mosfield.m

grp_mosfield

PURPOSE ^

function mf=grp_mosfield(fn,dn,fld,start,stop,clean)

SYNOPSIS ^

function mf=grp_mosfield(fn,dn,fld,start,stop,clean)

DESCRIPTION ^

 function mf=grp_mosfield(fn,dn,fld,start,stop,clean)

 takes individual mosaic runs and groups the data
 according to fields

 fn    = name of mat files, 'Cl0016_day*_red.mat'
         where * is the run index
                  OR
         fn can be a data structure.  in this case leave
         dn=[] and start=stop=1;
 dn    = name of the structure in fn
        'dcal*'
 fld   = field name, 'Cl0016mos*'
         for letters, use '#'
 start = start count of * for fn and dn
 stop  = stop count of * for fn and dn
 clean = optional: 1 - remove all unnecessary struct fields

 example
   mf=grp_mosfield('/home/loh/sza_analysis/Cl0016*.mat', ...
                   'd*','Cl0016mos*',1,3);

   will load Cl0016[1:3].mat and look for d[1:3] with fields
   Cl0016mos[1:fieldnumber];

 Michael Loh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function mf=grp_mosfield(fn,dn,fld,start,stop,clean)
0002 
0003 % function mf=grp_mosfield(fn,dn,fld,start,stop,clean)
0004 %
0005 % takes individual mosaic runs and groups the data
0006 % according to fields
0007 %
0008 % fn    = name of mat files, 'Cl0016_day*_red.mat'
0009 %         where * is the run index
0010 %                  OR
0011 %         fn can be a data structure.  in this case leave
0012 %         dn=[] and start=stop=1;
0013 % dn    = name of the structure in fn
0014 %        'dcal*'
0015 % fld   = field name, 'Cl0016mos*'
0016 %         for letters, use '#'
0017 % start = start count of * for fn and dn
0018 % stop  = stop count of * for fn and dn
0019 % clean = optional: 1 - remove all unnecessary struct fields
0020 %
0021 % example
0022 %   mf=grp_mosfield('/home/loh/sza_analysis/Cl0016*.mat', ...
0023 %                   'd*','Cl0016mos*',1,3);
0024 %
0025 %   will load Cl0016[1:3].mat and look for d[1:3] with fields
0026 %   Cl0016mos[1:fieldnumber];
0027 %
0028 % Michael Loh
0029 
0030 % initialize mf
0031 mf=[];
0032 
0033 if (~exist('clean'))
0034   clean=0;
0035 end
0036 
0037 % search for * location
0038 if (isstr(fn))
0039   [fns,fne,ctype]=namesec(fn);
0040   [dns,dne,ctype]=namesec(dn);
0041 else
0042   d=fn;
0043 end
0044 
0045 for i=start:stop
0046   if (isstr(fn))
0047     disp(sprintf('Loading run %u',i));  
0048     fn=sprintf('%s%u%s',fns,i,fne);  
0049     dn=sprintf('%s%u%s',dns,i,dne);
0050     eval(sprintf('load %s;',fn'));
0051     eval(sprintf('d=%s;',dn'));
0052     eval(sprintf('clear %s;',dn'));
0053   end
0054   
0055   % extract and cut target data
0056   ind=d.array.frame.features==1;
0057   d=framecut(d,ind);
0058   
0059   % find unique fields
0060   % only do this once
0061   source=d.antenna.tracker.source;
0062   if (i==start)
0063     fields=unique(source);
0064     % find non tracking antenna
0065     fields(strcmp(fields,''))=[];
0066     % initialize empty structures
0067     fields=orderfields(fields,fld);
0068     
0069     for k=1:length(fields)
0070       eval(sprintf('mf{%u}=[];',k));
0071     end
0072   end
0073   
0074   for j=1:length(fields)
0075     % assume all trackable antennas are tracking
0076     % same source
0077     for k=1:8
0078       ind=strcmp(source(:,1,k),fields(j));
0079       if (sum(ind))
0080     break;
0081       end
0082     end
0083     buf=framecut(d,ind);
0084     eval(sprintf('mf{%u}=catstruct(1,[mf{%u} buf]);',j,j));
0085   end
0086 end
0087 
0088 % time order data
0089 mf=timeorder(mf);
0090 
0091 if (exist('clean'))
0092   if (clean)
0093     for i=1:length(mf)
0094       mf{i}=clean4map(mf{i});
0095     end
0096   end
0097 end
0098 
0099   
0100 
0101 %%%%%%%%%%%%%%%%%%%%%%%%
0102 function [s,e,ctype]=namesec(n)
0103 
0104 f=regexpi(n,'*');
0105 ctype='num';
0106 
0107 if (isempty(f))
0108   f=regexpi(n,'#')
0109   ctype='letter';
0110   if (isempty(f))
0111     error('Invalid input.  Use ''*'' or ''#''')
0112     return
0113   end
0114 end
0115 
0116 s=n(1:f-1);
0117 if (length(n)>f)
0118   e=n(f+1:length(n));
0119 else
0120   e=[];
0121 end
0122 
0123 
0124 
0125 
0126 %%%%%%%%%%%%%%%%%%%%%%%%
0127 function fields=orderfields(fields,fn)
0128 
0129 [fns,fne,ctype]=namesec(fn);
0130 
0131 for i=1:length(fields)
0132   s=regexpi(fields{i},fns,'end');
0133   if (~isempty(fne))
0134     e=regexpi(fields{i},fne,'start');
0135   else
0136     e=length(fields{i})+1;
0137   end
0138   if (e-s>=2)
0139     if (strcmp(ctype,'num'))
0140       num(i)=str2num(strcat(fields{i}(s+1:e-1)));
0141     else
0142       num(i)=strcat(fields{i}(s+1:e-1));
0143     end
0144   else
0145     error('Invalid field name')
0146   end
0147 end
0148 
0149 [num,ind]=sort(num);
0150 fields=fields(ind);
0151 
0152 disp('Fields')
0153 disp(' ')
0154 disp(fields)
0155 
0156 
0157 
0158   
0159

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