function outData=expandTo1KmRes(inData,area)
% Expands the input data to 1 kilometer resolution
% Used for certain MODIS products that are at 5-km resolution
% when needed to be output to a text file that requires 1-km resolution
% Takes a single pixel and expands to 5-by-5
% Final grid size needs to be 2030x1354, while 406*5=2030 & 270*5=1350
% Use meshgrid and nearest neighbor 2-d interpolation
% area argument used here to select the correct area corresponding to, e.g., cloud mask, bt,etc
% Missing points on edge given a NaN value
% Kevin Baggett
% Wed Feb 27 18:04:55 UTC 2002

[row,col]=size(inData);

[X,Y] = meshgrid([1:5:5*col],[1:5:5*row]);
XI = [1:5*col];
YI = [1:5*row]';

outData = interp2(X,Y,inData,XI,YI,'nearest');
%set outliers (columns 1351 to 1354) to NaN;
outData(:,1351:1354)=NaN;

[npixels_across npixels_along] = size(outData);
start(1) = round(min( [max([area(1) 0]) (npixels_across - 1)]));
start(2) = round(min( [max([area(2) 0]) (npixels_along - 1)]));
edge(1) = floor(min( [max([area(3) 0]) (npixels_across - start(1))]));
edge(2) = floor(min( [max([area(4) 0]) (npixels_along - start(2))]));

outData=outData(start(1):start(1)+edge(1)-1,start(2):start(2)+edge(2)-1);