[Dart-dev] [8131] DART/trunk/matlab: Small cleanup ...
nancy at ucar.edu
nancy at ucar.edu
Thu Jun 25 09:13:26 MDT 2015
Revision: 8131
Author: thoar
Date: 2015-06-25 09:13:26 -0600 (Thu, 25 Jun 2015)
Log Message:
-----------
Small cleanup ... moving functions we believe to have outlived their usefulness
to a deprecated directory.
Modified Paths:
--------------
DART/trunk/matlab/locations_in_region.m
Added Paths:
-----------
DART/trunk/matlab/deprecated/
DART/trunk/matlab/deprecated/CompareObsDiag.m
DART/trunk/matlab/deprecated/DiffnetCDFstate.m
DART/trunk/matlab/deprecated/read_state.m
DART/trunk/matlab/deprecated/state_diag.m
Removed Paths:
-------------
DART/trunk/matlab/CompareObsDiag.m
DART/trunk/matlab/DiffnetCDFstate.m
DART/trunk/matlab/read_state.m
DART/trunk/matlab/state_diag.m
-------------- next part --------------
Deleted: DART/trunk/matlab/CompareObsDiag.m
===================================================================
--- DART/trunk/matlab/CompareObsDiag.m 2015-06-24 22:57:10 UTC (rev 8130)
+++ DART/trunk/matlab/CompareObsDiag.m 2015-06-25 15:13:26 UTC (rev 8131)
@@ -1,123 +0,0 @@
-function CompareObsDiag(file1,file2)
-%% CompareObsDiag checks to see if two obs_diag netcdf files are identical.
-%
-% CompareObsDiag will subtract each numeric variable and print a
-% summary of the min/max differences for each variable.
-% If there are a different number of 'copies', for example, you can
-% specify which copies to compare in the call to get_hyperslab().
-% At present, this is a manual edit within this file.
-% This file is largely similar to Compare_netCDF_files.m but explicitly
-% checks only the FIRST 21 copies and uses a snctools get_var instead
-% of the native Matlab netcdf.getVar().
-%
-% Example:
-%
-% file1 = 'obs_diag_output.nc';
-% file2 = 'obs_diag_output_proposed.nc';
-% CompareObsDiag(file1,file2)
-
-%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
-% provided by UCAR, "as is", without charge, subject to all terms of use at
-% http://www.image.ucar.edu/DAReS/DART/DART_download
-%
-% DART $Id$
-
-fid = fopen('CompareObsDiag_results.txt','a+');
-fprintf(fid,'\n---\n');
-fprintf(fid,'%s\n',datestr(now));
-
-fprintf(fid,'Comparing %s\n',file1);
-fprintf(fid,'with %s\n',file2);
-CompareTwoFiles(file1,file2,fid)
-
-fclose(fid);
-
-%%---------------------------------------------------------------------
-% Display min and max of the difference of two numeric variables
-% from two separate files.
-%----------------------------------------------------------------------
-
-function CompareTwoFiles(file1, file2, fid)
-
-if (exist(file1,'file') ~= 2), error('%s does not exist.',file1); end
-if (exist(file2,'file') ~= 2), error('%s does not exist.',file2); end
-
-f1info = ncinfo(file1);
-nvariables = length(f1info.Variables);
-ncid1 = netcdf.open(file1,'NOWRITE');
-ncid2 = netcdf.open(file2,'NOWRITE');
-
-% Loop over all the variables in the first file ... the variables
-% can be in any order in either file. I do not check to see if
-% there are variables present in the second file that are not in
-% the first file.
-
-for ivar = 1:nvariables
-
- varid1 = ivar-1; % Because netCDF tools use C-like indices.
-
- [varname1, xtype1, ~, numatts1] = netcdf.inqVar( ncid1,varid1);
- varid2 = netcdf.inqVarID(ncid2,varname1);
- [varname2, xtype2, ~, numatts2] = netcdf.inqVar( ncid2,varid2);
-
- FillValue1 = has_att(ncid1, varid1, numatts1, '_FillValue');
- FillValue2 = has_att(ncid2, varid2, numatts2, '_FillValue');
-
- switch (f1info.Variables(ivar).Datatype)
- case {'char','character'}
- fprintf(fid,'%32s is a %s variable.\n',varname1,f1info.Variables(ivar).Datatype);
- fprintf( '%32s is a %s variable.\n',varname1,f1info.Variables(ivar).Datatype);
- otherwise
-
- bob = get_hyperslab('fname',file1,'varname',varname1,'copy1',1,'copycount',21);
- data1 = bob(:);
- bob = get_hyperslab('fname',file2,'varname',varname1,'copy1',1,'copycount',21);
- data2 = bob(:);
-
- bob = data1 - data2;
- datamin = min(bob);
- datamax = max(bob);
-
- fprintf(fid,'%32s has min/max differences of %g %g\n',varname1,datamin,datamax);
- if ((datamin ~= 0.0) && (datamax ~= 0.0))
- fprintf('%32s has min/max differences of %g %g\n',varname1,datamin,datamax);
- end
- end
-
-end
-
-netcdf.close(ncid1)
-netcdf.close(ncid2)
-
-%%---------------------------------------------------------------------
-% helper functions
-%----------------------------------------------------------------------
-
-function data = has_att(ncid,varid,numatts,attstring)
-
-data = [];
-
-for iatt = 1:numatts
- attid = iatt - 1;
- attname = netcdf.inqAttName(ncid, varid, attid);
-
- switch( attname )
- case (attstring)
- data = netcdf.getAtt(ncid, varid, attstring);
- otherwise
- end
-end
-
-function data = my_getVar(ncid,varid,FillValue,start,count)
-
-data = netcdf.getVar(ncid, varid, start, count);
-if ( ~ isempty(FillValue) )
- data(data == FillValue) = NaN;
-end
-
-
-% <next few lines under version control, do not edit>
-% $URL$
-% $Revision$
-% $Date$
-
Deleted: DART/trunk/matlab/DiffnetCDFstate.m
===================================================================
--- DART/trunk/matlab/DiffnetCDFstate.m 2015-06-24 22:57:10 UTC (rev 8130)
+++ DART/trunk/matlab/DiffnetCDFstate.m 2015-06-25 15:13:26 UTC (rev 8131)
@@ -1,79 +0,0 @@
-function DiffnetCDFstate(file1,file2,outfile)
-%% DiffnetCDFstate checks to see if the netcdf pieces are available.
-%
-% DiffnetCDFstate(nc1, nc2, outfile);
-%
-% fname ... a filename that contains diagnostic information.
-% The last line contains three things:
-% 1) an error code (0 == files identical)
-% 2) the min of the difference
-% 3) the max of the difference
-%
-% Example:
-%
-% file1 = 'test1/Prior_Diag.nc';
-% file2 = 'test2/Prior_Diag.nc';
-% outfile = 'test1_2.diff';
-% DiffnetCDFstate(file1,file2,outfile)
-
-%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
-% provided by UCAR, "as is", without charge, subject to all terms of use at
-% http://www.image.ucar.edu/DAReS/DART/DART_download
-%
-% DART $Id$
-
-%----------------------------------------------------------------------
-% Check for the existence of the two input files.
-%----------------------------------------------------------------------
-
-if (exist(file1,'file') ~= 2), error('%s does not exist.',file1); end
-if (exist(file2,'file') ~= 2), error('%s does not exist.',file2); end
-
-%----------------------------------------------------------------------
-% if the 'state' variable exists, read in the WHOLE THING.
-%----------------------------------------------------------------------
-
-if ( nc_isvar(file1,'state'))
- a = nc_varget(file1,'state');
-else
- error('%s has no ''state'' variable.',file1)
-end
-
-if ( nc_isvar(file2,'state'))
- b = nc_varget(file2,'state');
-else
- error('%s has no ''state'' variable.',file2)
-end
-
-% string them into 1D arrays and take the difference
-
-c = b(:) - a(:);
-
-%c(1) = c(1) + 0.1e-15;
-
-a = min(c);
-b = max(c);
-clear c
-
-% Write the min and max of the differences to a file
-
-fid = fopen(outfile,'wt');
-fprintf(fid,'%s\n',datestr(now));
-fprintf(fid,'%s\n',pwd);
-fprintf(fid,'%s\n',file1);
-fprintf(fid,'%s\n',file2);
-
-if ( (a == 0.0) && (b == 0.0) )
- fprintf(fid,'0 %e %e\n',a,b);
-else
- fprintf(fid,'1 %e %e\n',a,b);
-end
-
-fclose(fid);
-
-
-% <next few lines under version control, do not edit>
-% $URL$
-% $Revision$
-% $Date$
-
Copied: DART/trunk/matlab/deprecated/CompareObsDiag.m (from rev 8130, DART/trunk/matlab/CompareObsDiag.m)
===================================================================
--- DART/trunk/matlab/deprecated/CompareObsDiag.m (rev 0)
+++ DART/trunk/matlab/deprecated/CompareObsDiag.m 2015-06-25 15:13:26 UTC (rev 8131)
@@ -0,0 +1,123 @@
+function CompareObsDiag(file1,file2)
+%% CompareObsDiag checks to see if two obs_diag netcdf files are identical.
+%
+% CompareObsDiag will subtract each numeric variable and print a
+% summary of the min/max differences for each variable.
+% If there are a different number of 'copies', for example, you can
+% specify which copies to compare in the call to get_hyperslab().
+% At present, this is a manual edit within this file.
+% This file is largely similar to Compare_netCDF_files.m but explicitly
+% checks only the FIRST 21 copies and uses a snctools get_var instead
+% of the native Matlab netcdf.getVar().
+%
+% Example:
+%
+% file1 = 'obs_diag_output.nc';
+% file2 = 'obs_diag_output_proposed.nc';
+% CompareObsDiag(file1,file2)
+
+%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
+% provided by UCAR, "as is", without charge, subject to all terms of use at
+% http://www.image.ucar.edu/DAReS/DART/DART_download
+%
+% DART $Id$
+
+fid = fopen('CompareObsDiag_results.txt','a+');
+fprintf(fid,'\n---\n');
+fprintf(fid,'%s\n',datestr(now));
+
+fprintf(fid,'Comparing %s\n',file1);
+fprintf(fid,'with %s\n',file2);
+CompareTwoFiles(file1,file2,fid)
+
+fclose(fid);
+
+%%---------------------------------------------------------------------
+% Display min and max of the difference of two numeric variables
+% from two separate files.
+%----------------------------------------------------------------------
+
+function CompareTwoFiles(file1, file2, fid)
+
+if (exist(file1,'file') ~= 2), error('%s does not exist.',file1); end
+if (exist(file2,'file') ~= 2), error('%s does not exist.',file2); end
+
+f1info = ncinfo(file1);
+nvariables = length(f1info.Variables);
+ncid1 = netcdf.open(file1,'NOWRITE');
+ncid2 = netcdf.open(file2,'NOWRITE');
+
+% Loop over all the variables in the first file ... the variables
+% can be in any order in either file. I do not check to see if
+% there are variables present in the second file that are not in
+% the first file.
+
+for ivar = 1:nvariables
+
+ varid1 = ivar-1; % Because netCDF tools use C-like indices.
+
+ [varname1, xtype1, ~, numatts1] = netcdf.inqVar( ncid1,varid1);
+ varid2 = netcdf.inqVarID(ncid2,varname1);
+ [varname2, xtype2, ~, numatts2] = netcdf.inqVar( ncid2,varid2);
+
+ FillValue1 = has_att(ncid1, varid1, numatts1, '_FillValue');
+ FillValue2 = has_att(ncid2, varid2, numatts2, '_FillValue');
+
+ switch (f1info.Variables(ivar).Datatype)
+ case {'char','character'}
+ fprintf(fid,'%32s is a %s variable.\n',varname1,f1info.Variables(ivar).Datatype);
+ fprintf( '%32s is a %s variable.\n',varname1,f1info.Variables(ivar).Datatype);
+ otherwise
+
+ bob = get_hyperslab('fname',file1,'varname',varname1,'copy1',1,'copycount',21);
+ data1 = bob(:);
+ bob = get_hyperslab('fname',file2,'varname',varname1,'copy1',1,'copycount',21);
+ data2 = bob(:);
+
+ bob = data1 - data2;
+ datamin = min(bob);
+ datamax = max(bob);
+
+ fprintf(fid,'%32s has min/max differences of %g %g\n',varname1,datamin,datamax);
+ if ((datamin ~= 0.0) && (datamax ~= 0.0))
+ fprintf('%32s has min/max differences of %g %g\n',varname1,datamin,datamax);
+ end
+ end
+
+end
+
+netcdf.close(ncid1)
+netcdf.close(ncid2)
+
+%%---------------------------------------------------------------------
+% helper functions
+%----------------------------------------------------------------------
+
+function data = has_att(ncid,varid,numatts,attstring)
+
+data = [];
+
+for iatt = 1:numatts
+ attid = iatt - 1;
+ attname = netcdf.inqAttName(ncid, varid, attid);
+
+ switch( attname )
+ case (attstring)
+ data = netcdf.getAtt(ncid, varid, attstring);
+ otherwise
+ end
+end
+
+function data = my_getVar(ncid,varid,FillValue,start,count)
+
+data = netcdf.getVar(ncid, varid, start, count);
+if ( ~ isempty(FillValue) )
+ data(data == FillValue) = NaN;
+end
+
+
+% <next few lines under version control, do not edit>
+% $URL$
+% $Revision$
+% $Date$
+
Copied: DART/trunk/matlab/deprecated/DiffnetCDFstate.m (from rev 8130, DART/trunk/matlab/DiffnetCDFstate.m)
===================================================================
--- DART/trunk/matlab/deprecated/DiffnetCDFstate.m (rev 0)
+++ DART/trunk/matlab/deprecated/DiffnetCDFstate.m 2015-06-25 15:13:26 UTC (rev 8131)
@@ -0,0 +1,79 @@
+function DiffnetCDFstate(file1,file2,outfile)
+%% DiffnetCDFstate checks to see if the netcdf pieces are available.
+%
+% DiffnetCDFstate(nc1, nc2, outfile);
+%
+% fname ... a filename that contains diagnostic information.
+% The last line contains three things:
+% 1) an error code (0 == files identical)
+% 2) the min of the difference
+% 3) the max of the difference
+%
+% Example:
+%
+% file1 = 'test1/Prior_Diag.nc';
+% file2 = 'test2/Prior_Diag.nc';
+% outfile = 'test1_2.diff';
+% DiffnetCDFstate(file1,file2,outfile)
+
+%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
+% provided by UCAR, "as is", without charge, subject to all terms of use at
+% http://www.image.ucar.edu/DAReS/DART/DART_download
+%
+% DART $Id$
+
+%----------------------------------------------------------------------
+% Check for the existence of the two input files.
+%----------------------------------------------------------------------
+
+if (exist(file1,'file') ~= 2), error('%s does not exist.',file1); end
+if (exist(file2,'file') ~= 2), error('%s does not exist.',file2); end
+
+%----------------------------------------------------------------------
+% if the 'state' variable exists, read in the WHOLE THING.
+%----------------------------------------------------------------------
+
+if ( nc_isvar(file1,'state'))
+ a = nc_varget(file1,'state');
+else
+ error('%s has no ''state'' variable.',file1)
+end
+
+if ( nc_isvar(file2,'state'))
+ b = nc_varget(file2,'state');
+else
+ error('%s has no ''state'' variable.',file2)
+end
+
+% string them into 1D arrays and take the difference
+
+c = b(:) - a(:);
+
+%c(1) = c(1) + 0.1e-15;
+
+a = min(c);
+b = max(c);
+clear c
+
+% Write the min and max of the differences to a file
+
+fid = fopen(outfile,'wt');
+fprintf(fid,'%s\n',datestr(now));
+fprintf(fid,'%s\n',pwd);
+fprintf(fid,'%s\n',file1);
+fprintf(fid,'%s\n',file2);
+
+if ( (a == 0.0) && (b == 0.0) )
+ fprintf(fid,'0 %e %e\n',a,b);
+else
+ fprintf(fid,'1 %e %e\n',a,b);
+end
+
+fclose(fid);
+
+
+% <next few lines under version control, do not edit>
+% $URL$
+% $Revision$
+% $Date$
+
Copied: DART/trunk/matlab/deprecated/read_state.m (from rev 8130, DART/trunk/matlab/read_state.m)
===================================================================
--- DART/trunk/matlab/deprecated/read_state.m (rev 0)
+++ DART/trunk/matlab/deprecated/read_state.m 2015-06-25 15:13:26 UTC (rev 8131)
@@ -0,0 +1,75 @@
+function state = read_state( file_name )
+%% read_state.m reads prior_state_diagnostics -type files.
+%
+% USAGE: state = read_state( file_name )
+%
+
+%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
+% provided by UCAR, "as is", without charge, subject to all terms of use at
+% http://www.image.ucar.edu/DAReS/DART/DART_download
+%
+% DART $Id$
+
+if (exist(file_name,'file') ~= 2), error('%s does not exist.',file_name); end
+
+fid = fopen(file_name);
+global_meta_data = fgetl(fid);
+model_size = fscanf(fid, '%f', 1);
+copies_per_time = fscanf(fid, '%f', 1);
+
+% Read in the per copy meta data
+for i = 1:copies_per_time,
+ index = fscanf(fid, '%f', 1);
+ copy_meta_data(i).index = index;
+ string = fgetl(fid);
+ copy_meta_data(i).string = string;
+end
+
+% Read locat header (should test for this)
+header = fgetl(fid);
+
+% If we stay with this approach, need modules to read each piece
+% That are swapped in and out for matlab (how to automate?)
+
+% Read the locations (should be sub-module) for each state variable
+location = 0;
+for i = 1:model_size,
+% Read loc1d header, check for error at some point
+ header = fgetl(fid);
+ location(i) = fscanf(fid, '%G', 1);
+% Have to read to get end of line (should be able to work around)
+ header = fgetl(fid);
+end
+
+
+% Loop to read for many different times
+num_times = 200;
+% Need to look at storage order and efficiency
+state = zeros(num_times, copies_per_time, model_size);
+
+for j = 1:num_times,
+% Start reading the output for each copy at current time
+ for i = 1:copies_per_time,
+ time = fscanf(fid, '%d', 2);
+ header = fgetl(fid);
+
+% Read fcopy header; should check
+ header = fgetl(fid);
+
+%Read the copy index
+ copy = fscanf(fid, '%d', 1);
+ header = fgetl(fid);
+
+% Read in the state vector, model_size
+ state(j, i, :) = transpose(fscanf(fid, '%G', model_size));
+ header = fgetl(fid);
+ end
+
+end
+
+
+% <next few lines under version control, do not edit>
+% $URL$
+% $Revision$
+% $Date$
+
Copied: DART/trunk/matlab/deprecated/state_diag.m (from rev 8130, DART/trunk/matlab/state_diag.m)
===================================================================
--- DART/trunk/matlab/deprecated/state_diag.m (rev 0)
+++ DART/trunk/matlab/deprecated/state_diag.m 2015-06-25 15:13:26 UTC (rev 8131)
@@ -0,0 +1,27 @@
+%% state_diag.m uses read_state.m
+%
+
+%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
+% provided by UCAR, "as is", without charge, subject to all terms of use at
+% http://www.image.ucar.edu/DAReS/DART/DART_download
+%
+% DART $Id$
+
+file_name = input('What is file for true state');
+
+true_state = read_state(file_name);
+
+file_name = input('What is file for prior state');
+
+prior_state = read_state(file_name);
+
+file_name = input('What is file for posterior state')
+
+posterior_state = read_state(file_name);
+
+
+% <next few lines under version control, do not edit>
+% $URL$
+% $Revision$
+% $Date$
+
Modified: DART/trunk/matlab/locations_in_region.m
===================================================================
--- DART/trunk/matlab/locations_in_region.m 2015-06-24 22:57:10 UTC (rev 8130)
+++ DART/trunk/matlab/locations_in_region.m 2015-06-25 15:13:26 UTC (rev 8131)
@@ -62,9 +62,6 @@
inds = find( (lonlogical .* latlogical .* lvllogical) > 0 );
-function a = ReadObsSeq(fname)
-
-
% <next few lines under version control, do not edit>
% $URL$
% $Revision$
Deleted: DART/trunk/matlab/read_state.m
===================================================================
--- DART/trunk/matlab/read_state.m 2015-06-24 22:57:10 UTC (rev 8130)
+++ DART/trunk/matlab/read_state.m 2015-06-25 15:13:26 UTC (rev 8131)
@@ -1,75 +0,0 @@
-function state = read_state( file_name )
-%% read_state.m reads prior_state_diagnostics -type files.
-%
-% USAGE: state = read_state( file_name )
-%
-
-%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
-% provided by UCAR, "as is", without charge, subject to all terms of use at
-% http://www.image.ucar.edu/DAReS/DART/DART_download
-%
-% DART $Id$
-
-if (exist(file_name,'file') ~= 2), error('%s does not exist.',file_name); end
-
-fid = fopen(file_name);
-global_meta_data = fgetl(fid);
-model_size = fscanf(fid, '%f', 1);
-copies_per_time = fscanf(fid, '%f', 1);
-
-% Read in the per copy meta data
-for i = 1:copies_per_time,
- index = fscanf(fid, '%f', 1);
- copy_meta_data(i).index = index;
- string = fgetl(fid);
- copy_meta_data(i).string = string;
-end
-
-% Read locat header (should test for this)
-header = fgetl(fid);
-
-% If we stay with this approach, need modules to read each piece
-% That are swapped in and out for matlab (how to automate?)
-
-% Read the locations (should be sub-module) for each state variable
-location = 0;
-for i = 1:model_size,
-% Read loc1d header, check for error at some point
- header = fgetl(fid);
- location(i) = fscanf(fid, '%G', 1);
-% Have to read to get end of line (should be able to work around)
- header = fgetl(fid);
-end
-
-
-% Loop to read for many different times
-num_times = 200;
-% Need to look at storage order and efficiency
-state = zeros(num_times, copies_per_time, model_size);
-
-for j = 1:num_times,
-% Start reading the output for each copy at current time
- for i = 1:copies_per_time,
- time = fscanf(fid, '%d', 2);
- header = fgetl(fid);
-
-% Read fcopy header; should check
- header = fgetl(fid);
-
-%Read the copy index
- copy = fscanf(fid, '%d', 1);
- header = fgetl(fid);
-
-% Read in the state vector, model_size
- state(j, i, :) = transpose(fscanf(fid, '%G', model_size));
- header = fgetl(fid);
- end
-
-end
-
-
-% <next few lines under version control, do not edit>
-% $URL$
-% $Revision$
-% $Date$
-
Deleted: DART/trunk/matlab/state_diag.m
===================================================================
--- DART/trunk/matlab/state_diag.m 2015-06-24 22:57:10 UTC (rev 8130)
+++ DART/trunk/matlab/state_diag.m 2015-06-25 15:13:26 UTC (rev 8131)
@@ -1,27 +0,0 @@
-%% state_diag.m uses read_state.m
-%
-
-%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
-% provided by UCAR, "as is", without charge, subject to all terms of use at
-% http://www.image.ucar.edu/DAReS/DART/DART_download
-%
-% DART $Id$
-
-file_name = input('What is file for true state');
-
-true_state = read_state(file_name);
-
-file_name = input('What is file for prior state');
-
-prior_state = read_state(file_name);
-
-file_name = input('What is file for posterior state')
-
-posterior_state = read_state(file_name);
-
-
-% <next few lines under version control, do not edit>
-% $URL$
-% $Revision$
-% $Date$
-
More information about the Dart-dev
mailing list