function fdisplay(fnum,isload)
%Display after the file is picked or loaded
% isload=1 when load a file
% isload=0 when just display a loaded file

global xfile xf xhand xslide ncf jtime goodindex

xfile=ncf(fnum).file;
xf.var=ncf(fnum).var;
xf.topatt=ncf(fnum).topatt;
xf.dim=ncf(fnum).dim;
xf.varlist=ncf(fnum).varlist;
xf.topattlist=ncf(fnum).topattlist;
xf.dimlist=ncf(fnum).dimlist;
xf.att=ncf(fnum).att;
xf.attlist=ncf(fnum).attlist;

set(xhand.varlist,'visible','on','string',xf.varlist,'value',1,...
	'BackGroundColor',[1 0.9 .8]);
set(xhand.lengthtitle,'visible','on');
set(xhand.length,'visible','on','string','');
set(xhand.dt,'visible','on');
set(xhand.dttitle,'visible','on');
set(xhand.radio,'visible','on','value',1);
set(xhand.att,'visible','on','enable','on',...
	'string',{'ATTRIBUTES',xf.topattlist{:}},'value',1);
set(xhand.attvalue,'visible','on',...
	'string','Click PopupMenu to see file attributes...');
set(xhand.singlevalue,'visible','on','string','');
set(xhand.singlevaluetitle,'visible','on');
set(xhand.allvarname,'visible','on');

if isload==1
	if any(strcmp('time2',xf.varlist)),
		realtimejulian=xfile{'time'}(:)+xfile{'time2'}(:)*1e-3/(24*3600);
	elseif any(strcmp('time',xf.varlist))
		realtimejulian=xfile{'time'}(:);
		test=lower(xfile{'time'}.units(:));
		if isempty(test)
			warndlg('The ''units'' attribute of ''time'' doesn''t exist. Julian day assumed.','Warning');		
		elseif ~isempty(findstr(test,'millisec'))
			realtimejulian=realtimejulian*1e-3/(24*3600);
		elseif ~isempty(findstr(test,'sec'))
			realtimejulian=realtimejulian/(24*3600);
		elseif ~isempty(findstr(test,'min'))
			realtimejulian=realtimejulian/(24*60);
		elseif ~isempty(findstr(test,'hour'))
			realtimejulian=realtimejulian/(24);
		end;
	elseif any(strcmp('TIM',xf.varlist))
		realtimejulian=xfile{'TIM'}(:); %for ADCP files
		test=lower(xfile{'TIM'}.units(:));
		if isempty(test)
			warndlg('The ''units'' attribute of ''TIM'' doesn''t exist. Julian day assumed.','Warning');		
		elseif ~isempty(findstr(test,'millisec'))
			realtimejulian=realtimejulian*1e-3/(24*3600);
		elseif ~isempty(findstr(test,'sec'))
			realtimejulian=realtimejulian/(24*3600);
		elseif ~isempty(findstr(test,'min'))
			realtimejulian=realtimejulian/(24*60);
		elseif ~isempty(findstr(test,'hour'))
			realtimejulian=realtimejulian/(24);
		end;
	else
		errordlg('netCDF files must have time variable(s), i.e. ''time'',''time2'', or ''TIM'' !','Error');
		return;
	end;
	
	% removing erroneous julian days in original files
	goodindex{fnum}=find(realtimejulian>1721028);
	realtimejulian=realtimejulian(goodindex{fnum});
	
	jtime{fnum}=realtimejulian;
	
	if jtime{fnum}(end)<1757585
		jtime{fnum}(:)=jtime{fnum}(:)+693960;
	end;
	
	tlength=length(jtime{fnum});
	ttime=24*3600*jtime{fnum};
	ttest=diff(ttime);
	delt=ttest(1);
	realdt=round(mean(diff(jtime{fnum}))*24*3600);
	tindx=find(round(ttest)>round(delt));
	
		
	if ~isempty(tindx) & round(delt)~=realdt
		warndlg({'The timebase of this file is not continuous.',...
					'The dT is likely incorrect, but it won''t affect other operations.'},...
					'Notes');


%%%% The following code will be used to fix the problem locally, later
% 		warndlg('File can''t be loaded - Timebase is not continuous.','Notes');
% 		cmgtoolfunc('closefile');
% 		return;
		
% 		for ti=1:length(tindx)
% 			spans=round(ttest(tindx(ti))/delt)-1;
% 			tblock{ti}=ttime(tindx(ti))+delt*(1:spans);
% 	% 		tblock{ti},if ti>10,return;end;
% 		end;
% 		tindxl=length(tindx);
% 		for ti=1:tindxl
% 			t2=tindxl-ti+1;
% 			ttime=[ttime(1:tindx(t2),1);tblock{t2}(:);ttime(tindx(t2)+1:end,1)];
% 		end;
% 		jtime{fnum}=ttime(:)/24/3600;
% 	
% 		notvar={'time','time2','depth','lat','lon'};
% 		vari=xf.varlist;
% 		for jj=1:length(notvar)
% 			mark=strcmpi(notvar{jj},vari);
% 			vari=vari(find(mark==0));
% 		end;
% 		for ii=1:length(vari)
% 			dum=xfile{vari{ii}}(:);
% 			[m,n]=size(dum);
% 			if m<n
% 				dum=dum';
% 				[m,n]=size(dum);
% 			end;
% 			if m==tlength
% 				for ti=1:tindxl
% 					t2=tindxl-ti+1;
% 					dum=[dum(1:tindx(t2),:);nan*ones(length(tblock{t2}),n);dum(tindx(t2)+1:end,:)];
% 				end;
% 	% 			xfile{vari{ii}}(:)=dum;
% 			end;
% 		end;
% 		warndlg('Timebase is not continuous. CMGTooL filled the gap for you','Notes');
	end;
				
end;
	
		
delt=round(mean(diff(jtime{fnum}))*24*3600);

set(xhand.dt,'string',num2str(delt),'Foregroundcolor',[0 0 0]);

slideconfig(jtime{fnum});

set(xhand.newvarlist,'visible','on','string',xf.newvarlist,'value',1,...
	'BackGroundColor',[1 1 1]);
% set(xhand.savevarlist,'string',xf.savevarlist,'value',1);
set(xhand.savevarlist,'string',xf.nicknames,'value',1);
set(xhand.newvarname,'visible','on');
set(xhand.graphit,'visible','on','enable','on');
set(xhand.saveit,'visible','on','enable','on');
set(xhand.analyzeit,'visible','on','enable','on');
set(xhand.zoomtext,'visible','on');
set(xhand.zoomframe,'visible','on');
[ymd,hms]=getgregorian(min(jtime{fnum}));
set(xhand.zoomymdfrom,'visible','on','string',ymd);
set(xhand.zoomhmsfrom,'visible','on','string',hms);
[ymd,hms]=getgregorian(max(jtime{fnum}));
set(xhand.zoomymdto,'visible','on','string',ymd);
set(xhand.zoomhmsto,'visible','on','string',hms);
set(xhand.zoomslidefrom,'visible','on','enable','off','value',0);
set(xhand.zoomslideto,'visible','on','enable','off','value',1);
% xdata=get(xhand.main,'UserData');
xslide.from=min(jtime{fnum});
xslide.to=max(jtime{fnum});	

return;


