%reads cdf data file
% and returns information about the file and
%the variables written to it.
clear
clc
fname = input('Enter File Name (in quotes without cdf suffix): ')
%
%obtain information about the file
disp ('cdfinfo for file')
info = cdfinfo(fname)    %info is a structure
%
%the names of the variables in the cdf file
% are obtained from the Variables field  of info structure.
disp ('Variables field of cdfinfo: ')
info.Variables
%
%Each row of info.Variables has the variable name
% in the first column.  If there are at least two
%variables (use size to check), we can extract them\
% and convert them to character string type
varName1 = char(info.Variables (1,1))
varName2 = char(info.Variables (2,1))
%
%Knowing the variable names, we can retrieve specific
% data for them using cdfread
% these are names used to write the file
%Variable is a parameter value and the names of
% of the variables are in a 1 x n cell array following it
data = cdfread(fname,'Variable',{varName1 varName2});
%
%data is a cell array, with one data set in each column.
%The vector in Cell {1,1} contains data for the first variable
%Vector in Cell{1,2} contains data for the second variable
%Assign local variable names and read each variable
% in as a column vector
%note that the cell array indexes are in curly brackets,
%whereas the indexes for vector within that cell use parentheses
%dataOne and dataTwo are column vectors with the values for 
% the first two variables in the cdf file.
dataOne = data{1,1}(:,1);
dataTwo = data{1,2}(:,1);
[dataOnelength, ncol] = size (dataOne);
[dataTwolength, ncol] = size (dataTwo);
if (max([dataOnelength dataTwolength]) < 50)
    dataOne
    dataTwo
else
    disp ('too much data for display')
end


