function [data] = nldnc_timestep(ncobj,varName,t) % function [data] = nldnc_timestep(ncobj,varName,t) % % Inputs: % ncobj : a netcdf file object created with command % netcdf(filename, 'nowrite') % where filename is the name of the file from dbconv % varName : variable name to load eg: 'TEMPERATURE' % t : timetsep to load % Outputs % data : a matlab structure that contains the data from the timestep % and the relevant dimensions. % % Uses: % % Written by C. Dallimore 19 Jan 06 % % Get variable object ncVar = ncobj{varName}; if isempty(ncVar) data = []; disp ('Variable not found. Valid variables are') variables=var(ncobj); for i = 1:length(variables) self = variables{i}; theNCid = ncid(self); theVarid = varid(self); [dimName, dimSize] = ncmex('varinq', theNCid, theVarid); disp([' ',dimName]) end return end % Get dimensions of variable vardims = dim(ncVar); % varcmd is the command we will run to load this timestep % it depends on which dimension T is varcmd = sprintf('data.data = ncVar (',char(varName)); for i = 1:length(vardims) self = vardims{i}; theNCid = ncid(self); theDimid = dimid(self); [dimName, dimSize] = ncmex('diminq', theNCid, theDimid); dimVar = ncobj{dimName}; if (strcmp(dimName,'T')) if (t > dimSize) data = []; disp ('Timestep out of range') return end cmd = sprintf('data.%s = dimVar (t);',char(dimName)); eval(cmd); dimName = 'Ordinal_Dates'; dimVar = ncobj{dimName}; cmd = sprintf('data.%s = dimVar (t);',char(dimName)); eval(cmd); tindex = i; varcmd = [varcmd,'t']; else cmd = sprintf('data.%s = dimVar (:);',char(dimName)); eval(cmd); varcmd = [varcmd,':']; end if i ~= length(vardims) varcmd = [varcmd,',']; else varcmd = [varcmd,');']; end end eval(varcmd); pts = find(data.data < -9.9e+16); data.data(pts)=NaN;