function [fn1,tx1,fn2,tx2,tme1,tme2]=get_fn(pn,fld,yr,dy)

% function [fn1,tx1,fn2,tx2,tme1,tme2]=get_fn(pn,fld,yr,dy)
% is called by getgcm to determine file name and time index
%
% INPUTS
% pn    path name
% fld   field
% yr    year
% dy    day
%
% OUTPUT
% fn1   file name
% tx1   time index
% ==> When time-interpolation is required,
% ==> following output fields are provided.
% fn2   second file name
% tx2   second time index
% tme1  time in datenum format of first field
% tme2  time in datenum format of second field
%
% SEE ALSO
% getgcm

dy1 = dy;
dy2 = dy;
yr1 = yr;
yr2 = yr;

if dy==0 | mod(dy-5,10)~=0           % need time-interpolation
  dy1 = floor((dy-5)/10)*10+5;
  dy2 = ceil ((dy-5)/10)*10+5;
  if dy < 5
    dy1 = 365;
    yr1 = yr-1;
  elseif dy > 365
    dy2 = 5;
    yr2 = yr+1;
  end
end

if dy1 < 90
  fn1 = [ pn int2str(yr1) '/' fld '_08_08.00001_02160_240' ];
  tx1 = (dy1+5)/10;
elseif dy1 < 180
  fn1 = [ pn int2str(yr1) '/' fld '_08_08.02160_04320_240' ];
  tx1 = (dy1-85)/10;
elseif dy1 < 270
  fn1 = [ pn int2str(yr1) '/' fld '_08_08.04320_06480_240' ];
  tx1 = (dy1-175)/10;
else
  fn1 = [ pn int2str(yr1) '/' fld '_08_08.06480_08882_240' ];
  tx1 = (dy1-265)/10;
end

if dy2 < 90
  fn2 = [ pn int2str(yr2) '/' fld '_08_08.00001_02160_240' ];
  tx2 = (dy2+5)/10;
elseif dy2 < 180
  fn2 = [ pn int2str(yr2) '/' fld '_08_08.02160_04320_240' ];
  tx2 = (dy2-85)/10;
elseif dy2 < 270
  fn2 = [ pn int2str(yr2) '/' fld '_08_08.04320_06480_240' ];
  tx2 = (dy2-175)/10;
else
  fn2 = [ pn int2str(yr2) '/' fld '_08_08.06480_08882_240' ];
  tx2 = (dy2-265)/10;
end

tme1=datenum(yr1,1,dy1+1);
tme2=datenum(yr2,1,dy2+1);
