[Dart-dev] [3837] DART/trunk/matlab: needed for observation sequence netcdf processing
nancy at ucar.edu
nancy at ucar.edu
Thu Apr 30 18:26:31 MDT 2009
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/dart-dev/attachments/20090430/2b29142f/attachment.html
-------------- next part --------------
Modified: DART/trunk/matlab/SimpleMap.m
===================================================================
--- DART/trunk/matlab/SimpleMap.m 2009-05-01 00:25:15 UTC (rev 3836)
+++ DART/trunk/matlab/SimpleMap.m 2009-05-01 00:26:31 UTC (rev 3837)
@@ -30,9 +30,7 @@
% Licensed under the GPL -- www.gpl.org/licenses/gpl.html
%
% <next few lines under version control, do not edit>
-% $URL:
-% http://subversion.ucar.edu/DAReS/DART/trunk/diagnostics/matlab/fit_ens_mean_time.m
-% $
+% $URL$
% $Id$
% $Revision$
% $Date$
Modified: DART/trunk/matlab/get_copy_index.m
===================================================================
--- DART/trunk/matlab/get_copy_index.m 2009-05-01 00:25:15 UTC (rev 3836)
+++ DART/trunk/matlab/get_copy_index.m 2009-05-01 00:26:31 UTC (rev 3837)
@@ -19,14 +19,17 @@
% $Revision$
% $Date$
-f = netcdf(fname);
-num_copies = ncsize(f{'copy'}); % determine # of ensemble members
-close(f)
+if ( exist('nc_varget') == 2)
+ copy_meta_data = nc_varget(fname,'CopyMetaData');
+ atts = nc_getdiminfo(fname,'copy');
+ num_copies = atts.Length;
+else
+ f = netcdf(fname);
+ num_copies = ncsize(f{'copy'});
+ close(f)
+ copy_meta_data = getnc(fname, 'CopyMetaData');
+end
-% Need to get the Copy MetaData (strings with the names)
-% We then search the metadata for each copy for the appropriate copies.
-copy_meta_data = getnc(fname, 'CopyMetaData');
-
% For a single copy, the size is nx1, for more k copies, it's kxn
if size(copy_meta_data, 2) == 1
copy_meta_data = transpose(copy_meta_data);
Added: DART/trunk/matlab/get_qc_index.m
===================================================================
--- DART/trunk/matlab/get_qc_index.m (rev 0)
+++ DART/trunk/matlab/get_qc_index.m 2009-05-01 00:26:31 UTC (rev 3837)
@@ -0,0 +1,71 @@
+function copy_index = get_qc_index(fname, copystring)
+%get_qc_index Gets an index corresponding to copy meta_data string
+% Retrieves index associated with a given copy meta_data string in
+% file fname. If string is not found in meta_data list, a -1 is returned.
+%
+% Example:
+% fname = 'Prior_Diag.nc';
+% copystring = 'ensemble member 5';
+% copy_index = get_qc_index(fname, copystring);
+
+% Data Assimilation Research Testbed -- DART
+% Copyright 2004-2007, Data Assimilation Research Section
+% University Corporation for Atmospheric Research
+% Licensed under the GPL -- www.gpl.org/licenses/gpl.html
+%
+% <next few lines under version control, do not edit>
+% $URL$
+% $Id$
+% $Revision$
+% $Date$
+
+% Need to get the QC MetaData (strings with the names)
+% We then search the metadata for each copy for the appropriate copies.
+
+if ( exist('nc_varget') == 2)
+ qc_meta_data = nc_varget(fname,'QCMetaData');
+ atts = nc_getdiminfo(fname,'qc_copy');
+ num_copies = atts.Length;
+else
+ f = netcdf(fname);
+ num_copies = ncsize(f{'qc_copy'}); % determine # of ensemble members
+ close(f)
+ qc_meta_data = getnc(fname,'QCMetaData');
+end
+
+% For a single copy, the size is nx1, for more k copies, it's kxn
+if size(qc_meta_data, 2) == 1
+ qc_meta_data = transpose(qc_meta_data);
+end
+
+nowhitecs = dewhite(copystring);
+
+% Figure out which copy is the matching one
+copy_index = -1;
+for i = 1:num_copies,
+
+ % for matching -- we want to ignore whitespace -- find it & remove it
+ nowhitemd = dewhite(qc_meta_data(i,:));
+
+ if strcmp(nowhitemd , nowhitecs) == 1
+ fprintf('%s is copy %3i\n', copystring,i);
+ copy_index = i;
+ end
+end
+
+% Provide modest error support
+
+if (copy_index < 0)
+ disp(sprintf('ERROR: %s is not a valid metadata string for file %s', ...
+ copystring, fname))
+ disp('valid metadata strings are: ')
+ for i = 1:num_copies,
+ disp(sprintf('%s',deblank(qc_meta_data(i,:))))
+ end
+ error('please try again')
+end
+
+function str2 = dewhite(str1)
+% internal function to remove whitespace from a character string
+i = find( ~isspace(str1) );
+str2 = str1(i);
Property changes on: DART/trunk/matlab/get_qc_index.m
___________________________________________________________________
Name: svn:mime-type
+ text/x-matlab
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:eol-style
+ native
Added: DART/trunk/matlab/locations_in_region.m
===================================================================
--- DART/trunk/matlab/locations_in_region.m (rev 0)
+++ DART/trunk/matlab/locations_in_region.m 2009-05-01 00:26:31 UTC (rev 3837)
@@ -0,0 +1,70 @@
+function inds = locations_in_region(locations, region)
+% locations_in_region returns the indices of the locations in the specified region.
+%
+% USAGE:
+% inds = locations_in_region(locations, region);
+%
+% locations is N-by-3 array of locations - [lon; lat; lvl]
+% region is an N-by-1 array of region boundaries:
+% [leftlon rightlon minlat maxlat [minz maxz]]
+% If leftlon is numerically larger than rightlon,
+% the region will span the Prime Meridian.
+%
+% EXAMPLE: simple case
+% inds = locations_in_region(locations,[180 360 -90 90]); % Western Hemisphere
+%
+% EXAMPLE: longitude region spanning the Prime Meridian
+% inds = locations_in_region(locations,[330 180 -90 90]); % Everything BUT the Americas
+%
+% EXAMPLE: vertical subsetting
+% inds = locations_in_region(locations,[0 360 -90 90 0 1000]); % Everything between 0,1000
+
+% Data Assimilation Research Testbed -- DART
+% Copyright 2004-2007, Data Assimilation Research Section
+% University Corporation for Atmospheric Research
+% Licensed under the GPL -- www.gpl.org/licenses/gpl.html
+%
+% <next few lines under version control, do not edit>
+% $URL$
+% $Id$
+% $Revision$
+% $Date$
+
+if (length(region) == 6)
+ zmin = min(region(5:6));
+ zmax = max(region(5:6));
+elseif (length(region) < 4)
+ error('region must be an array of length 4 or 6')
+end
+
+ymin = min(region(3:4));
+ymax = max(region(3:4));
+xmin = mod(region(1),360.0);
+xmax = mod(region(2),360.0);
+
+lons = mod(locations(:,1),360.0);
+
+% find the ones in the right latitudes & levels
+
+latlogical = ((locations(:,2) >= ymin) & (locations(:,2) <= ymax));
+lvllogical = ((locations(:,3) >= zmin) & (locations(:,3) <= zmax));
+
+% find the ones in the right longitudes ... including wrapping
+
+if ( xmin == xmax )
+ lonlogical = ones(size(latlogical)); % everybody plays
+else
+
+ if ( xmin > xmax )
+ xmax = xmax + 360.0;
+ inds = find(lons < xmin);
+ lons(inds) = lons(inds) + 360.0;
+ end
+ lonlogical = ((lons >= xmin) & (lons <= xmax));
+end
+
+% put it all together ...
+
+inds = find( (lonlogical .* latlogical .* lvllogical) > 0 );
+
+function a = ReadObsSeq(fname)
Property changes on: DART/trunk/matlab/locations_in_region.m
___________________________________________________________________
Name: svn:mime-type
+ text/x-matlab
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:eol-style
+ native
Modified: DART/trunk/matlab/scalebar.m
===================================================================
--- DART/trunk/matlab/scalebar.m 2009-05-01 00:25:15 UTC (rev 3836)
+++ DART/trunk/matlab/scalebar.m 2009-05-01 00:26:31 UTC (rev 3837)
@@ -41,8 +41,8 @@
end
ax = axes('position',[ xmin ymin wid height ]);
- frog = [1:64];
- m = (zmax-zmin)/(64-1);
+ frog = [1:length(colormap)];
+ m = (zmax-zmin)/(length(colormap)-1);
b = zmin - m;
x_axis = frog*m + b;
More information about the Dart-dev
mailing list