[Dart-dev] [5931] DART/branches/development/matlab/CheckTimeStamp.m: Fully documented, has the ability to print out the advance-to-time
nancy at ucar.edu
nancy at ucar.edu
Wed Nov 21 14:01:56 MST 2012
Revision: 5931
Author: thoar
Date: 2012-11-21 14:01:55 -0700 (Wed, 21 Nov 2012)
Log Message:
-----------
Fully documented, has the ability to print out the advance-to-time
if it exists. Issues warning if trying to print an advance-to-time
from a file that _might_ not have one. I don't think you can tell
for sure.
Modified Paths:
--------------
DART/branches/development/matlab/CheckTimeStamp.m
-------------- next part --------------
Modified: DART/branches/development/matlab/CheckTimeStamp.m
===================================================================
--- DART/branches/development/matlab/CheckTimeStamp.m 2012-11-20 23:20:22 UTC (rev 5930)
+++ DART/branches/development/matlab/CheckTimeStamp.m 2012-11-21 21:01:55 UTC (rev 5931)
@@ -1,16 +1,35 @@
function CheckTimeStamp(directory, varargin)
-% print the timestamps of BINARY DART-format files.
+% Prints the timestamps of BINARY DART-format files
+% and has option to print the advance-to-time (user must know if it exists)
%
-% Example 1: (check all instances of filter_ics.nnnn)
+% Inputs:
+% directory (string, required) - directory containing .ics files
+% endian (string, optional) - 'ieee-be' ('big') or 'ieee-le' ('little'),
+% default is the native endian your system uses
+% fbase (string, optional) - base of ics files, default is 'filter_ics'
+% twoTimes (string, optional) - print advance-to time ('true'/'false'), default is 'false'
%
-% CheckTimeStamp('/glade/scratch/syha/work_hires')
-%
-% Example 2: (binary file of the wrong 'endian'-ness)
-% directory = '/glade/scratch/syha/work_hires';
-% endian = 'little';
-% CheckTimeStamp(directory,'endian','little')
+% If the dates are nonsensical, you probably have the wrong 'endian' specified.
+%
+% Outputs:
+% prints to screen filename and timestamp(s)
+%
+% Example 1: check all instances of filter_ics.nnnn using native endian-ness
+%
+% CheckTimeStamp('/glade/scratch/syha/work_hires')
+%
+% Example 2: little-endian binary file
+%
+% directory = '/glade/scratch/syha/work_hires';
+% endian = 'little';
+% CheckTimeStamp(directory,'endian', endian)
+%
+% Example 3: check all instances of assim_model_state_ic.nnnn for
+% both time stamps using native endianness
+%
+% CheckTimeStamp('/glade/scratch/syha/work_hires', 'endian', 'native', ...
+% 'fbase', 'assim_model_state_ic', 'twoTimes', 'true')
-
%% DART software - Copyright 2004 - 2011 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
@@ -21,25 +40,20 @@
% $Revision$
% $Date$
-% Helen, aim: parse inputs, bulletproofing
-% Inputs:
-% Required
-% directory - directory contating .ics files
-% Optional:
-% endian - ieee-be (big) or ieee-le (liitle)
-% fbase - base of ics files, e.g. filter_ics
-% outputs: prints to screen filename and timestamp
+timebase = datenum(1601,1,1); % start of Gregorian Calendar
p = inputParser; % create new instance of parser class
p.FunctionName = 'input parser :: requires input directory (string); valid optional inputs are, endian (string), fbase (string)';
-%% set defaults for optional parameters
-defaultEndian = 'native';
-defaultFbase = 'filter_ics';
+% set defaults for optional parameters
+defaultEndian = 'native';
+defaultFbase = 'filter_ics';
+defaulttwoTimes = 'false';
addRequired( p, 'directory', @ischar); % require directory, check input is a character array
addParamValue(p, 'endian', defaultEndian, @ischar);
addParamValue(p, 'fbase', defaultFbase, @ischar);
+addParamValue(p, 'twoTimes', defaulttwoTimes, @ischar);
p.parse(directory, varargin{:}) % parse inputs
@@ -47,11 +61,12 @@
endianIn = p.Results.endian;
fbase = p.Results.fbase;
+twoTimes = p.Results.twoTimes;
-%% check inputs
+% check inputs
assert(exist(directory, 'dir')==7, 'directory %s does not exist', directory)
-
+
tempstr = strcat(fbase, '*');
ens_size = length(dir(fullfile(directory, tempstr)));
@@ -62,35 +77,72 @@
end
switch lower(endianIn)
- case {'big','ieee-be'}
+ case {'big','ieee-be'}
endian = 'ieee-be';
- case {'little','ieee-le'}
+ case {'little','ieee-le'}
endian = 'ieee-le';
otherwise
endian = 'native';
end
-
-timebase = datenum(1601,1,1); % start of Gregorian Calender
+%% loop over each file - read the first 8 integers
+% If the file has only one timestamp record, the last
+% 4 integers are garbage. rec1(1), rec(4), rec(5), and
+% rec(8) are record information only. Not useful.
+%
+% Fortran record 1 ... [reclen][seconds][days][reclen] (these are all int32)
+% Fortran record 2 ... [reclen][seconds][days][reclen] (these are all int32)
+% Fortran record 3 ... [reclen][ model_state ][reclen] (int32, N*real*8, int32)
+%
+% Some files only have two records, in which case the situation is:
+%
+% Fortran record 1 ... [reclen][seconds][days][reclen] (these are all int32)
+% Fortran record 2 ... [reclen][ model_state ][reclen] (int32, N*real*8, int32)
+%
+% The time record closest to the model state is ALWAYS the valid_time of the model.
+
for i = 1:ens_size
fname = sprintf('%s/%s.%04d',directory,fbase,i);
-
+
if exist(fname, 'file')
-
- fid = fopen(fname,'rb',endian);
- rec1 = fread(fid,4,'int32');
- days = rec1(3);
- seconds = rec1(2);
- fdays = seconds/86400;
- datestring = datestr(timebase + days + fdays);
+ fid = fopen(fname,'rb',endian);
+ rec1 = fread(fid,8,'int32');
+ fclose(fid);
- fprintf('%s.%04d has timestamp of %d %d %s\n',fbase,i,days,seconds,datestring)
- fclose(fid);
-
+ days = rec1(3);
+ seconds = rec1(2);
+ fdays = seconds/86400;
+ advanceToTime = datestr(timebase + days + fdays);
+
+ if strcmpi(twoTimes,'true')
+
+ days2 = rec1(7);
+ seconds2 = rec1(6);
+ fdays2 = seconds2/86400;
+ modelTime = datestr(timebase + days2 + fdays2);
+
+ fprintf('%s.%04d advance-to-time %d %d (%s) & model time of %d %d (%s)\n'...
+ ,fbase,i,days,seconds,advanceToTime, days2, seconds2, modelTime)
+
+ % catch some, but not all errors
+ if seconds2 < 0 || seconds2 > 86400
+ error('%s might not have two timestamps', fname)
+ end
+
+ else
+
+ fprintf('%s.%04d has timestamp of %d %d (%s)\n',fbase,i,days,seconds,advanceToTime)
+
+ end
+
+ if days < 0 || seconds < 0
+ error('%s is incorrect endian, gives negative timestamp', endian)
+ end
+
else
- fprintf('WARNING : %s.%04d does not exist \n',fbase,i)
+ fprintf('WARNING : %s.%04d does not exist \n',fbase,i)
end
end
More information about the Dart-dev
mailing list