Home > atmlab > arts > scenegen > asg_crop.m

asg_crop

PURPOSE ^

ASG_CROP crop the data in G

SYNOPSIS ^

function [G]=asg_crop(G,LIMITS,DIMS);

DESCRIPTION ^

 ASG_CROP  crop the data in G

          asg_crop just simply cut out the data
          in G inside the specified limits

 FORMAT   G=asg_crop( G, LIMITS, DIMS)
 
 IN        
          G        original gformat data             
          LIMITS   a two column matrix
                   specifying limits.
                   The first row corresponds
                   to the dimension specified
                   in DIMS(1)
          DIMS     a vector with dimensions                   

 example usage:
 LIMITS(1,1:2)=[10e3 18e3];
 LIMITS(2,1:2)=[2 4];
 DIMS(1)=1;DIMS(2)=2;
 grid=[-1:0.1:1];
 F=asg_crop(D,G,LIMITS,DIMS);    

  2007-11-13 created by Bengt Rydberg

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

asg_crop.m

SOURCE CODE ^

0001 % ASG_CROP  crop the data in G
0002 %
0003 %          asg_crop just simply cut out the data
0004 %          in G inside the specified limits
0005 %
0006 % FORMAT   G=asg_crop( G, LIMITS, DIMS)
0007 %
0008 % IN
0009 %          G        original gformat data
0010 %          LIMITS   a two column matrix
0011 %                   specifying limits.
0012 %                   The first row corresponds
0013 %                   to the dimension specified
0014 %                   in DIMS(1)
0015 %          DIMS     a vector with dimensions
0016 %
0017 % example usage:
0018 % LIMITS(1,1:2)=[10e3 18e3];
0019 % LIMITS(2,1:2)=[2 4];
0020 % DIMS(1)=1;DIMS(2)=2;
0021 % grid=[-1:0.1:1];
0022 % F=asg_crop(D,G,LIMITS,DIMS);
0023 %
0024 %  2007-11-13 created by Bengt Rydberg
0025 
0026 function [G]=asg_crop(G,LIMITS,DIMS);
0027 
0028 
0029 if size(LIMITS,2)~=2
0030    error('LIMITS must be a 2 column matrix or a row vector of length 2') 
0031 end
0032 
0033 if ~isvector(DIMS)
0034    error('DIMS must be a vector')
0035 end
0036 
0037 if length(DIMS)~=size(LIMITS,1)
0038    error('mismatch in size of DIMS and LIMITS')
0039 end
0040 
0041 for i=1:length(G)
0042   for j=1:length(DIMS)
0043       gname = sprintf( 'GRID%d', DIMS(j) );
0044       if ~isempty(G(i).(gname))
0045     ind=find(G(i).(gname)>=LIMITS(j,1) & G(i).(gname)<=LIMITS(j,2));
0046         if isempty(ind)
0047        error('no data exist inside the specified limits')
0048         else
0049            G(i).(gname)=G(i).(gname)(ind);
0050            %shift the data so the first dimension holds
0051            %the data of interest
0052            data_dim=dimens(G(i).DATA);
0053            old_dim=DIMS(j);
0054            data=G(i).DATA;
0055            if isvector(data)
0056          data=vec2col(data);
0057            end
0058            data=shiftdim(G(i).DATA,old_dim-1);
0059            data=data(ind,:,:,:,:,:,:,:,:,:,:);        
0060            %shift back
0061            data=shiftdim(data,data_dim-old_dim+1);
0062            G(i).DATA=data;
0063         end
0064       end
0065   end
0066 end
0067 
0068 
0069

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005