function [errorflag] = printMetadataInfo(filePathName)

%   prototype: [errorflag] = printMetadataInfo( filePathName )   
%   Created on: 07/8/2011
%   Primary Author: Ed May
%   Last Author: 
%   Last edited on: 
%   Version: 1.0
%   
%   Detailed explanation:
%   Prints various file and variable information, in addition to 
%   metadescription, metakey and metadata from file 'filePathName'
%   Returns 0 if no errors, 1 if error occured

% To do: need to detect and control file open errors
% To do: need to detect and control when Metadata variables are missing

errorflag=0;	% no errors
if exist(filePathName,'file') ~= 2 
	fprintf(1,'The file %s\n',filePathName)
	fprintf(1,'Does not exist!\n')
	errorflag=1;
	return
end
fprintf(1,'Metadata Information stored in  %s\n',filePathName)
inFileStruct=load(filePathName);

whos	% generates a table of inscope variables
fieldnames(inFileStruct);	% get info on variables in the file

[rows,cols]=size(fieldnames(inFileStruct));

fprintf(1,'\nPrint a list of variables in the file master struct.\n')
for i= 1:rows
	% construction below fails in Matlab while ok in Octave
	%fprintf(1,' %s\n', cell2mat(fieldnames(inFileStruct)(i)))
	Ca=fieldnames(inFileStruct);
	fprintf(1,' %s\n', cell2mat(Ca(i)))
end


[rows,cols]=size(inFileStruct.metadescription);
fprintf(1,'\nPrint a list of metadescription for this file.\n')
for i= 1:cols
	fprintf(1,' %s\n', cell2mat(inFileStruct.metadescription(i)))
end

[rows,cols]=size(inFileStruct.metakey);
fprintf(1,'\nPrint a list of metadata values and metakey pairs for this file.\n')
for i= 1:cols
	fprintf(1,' %g\t%s\n', inFileStruct.metadata(1,i),cell2mat(inFileStruct.metakey(i)))
end

[drows,dcols]=size(inFileStruct.metadata);
if dcols ~= cols 
	errorflag=1;
	fprintf(1,'\nError: Missmatch in number of columns between metakey %d and metadata %d\n',...
	cols,dcols)
end

return
