%function [xlstm,tcode,rawdata,y]=readdata(maindir,datadir,mdfile);
function [xlstm,tcode,rawdata,y]=readdata(dir,mdfile,dates);

maindir=dir.main;
datadir=dir.data;
fyds=dates.fyds;
fmds=dates.fmds;
lyds=dates.lyds;
lmds=dates.lmds;
nobsperyear=dates.nfreq;


missex=1e32;
thr=10;
tflag=0;

if nobsperyear==12;
nds =   nobsperyear*(lyds-fyds)  + (lmds-fmds)+1;  % Data Set Sample Size
else;
nds =   nobsperyear*(lyds-fyds)  + (lmds-fmds)+1;  % Data Set Sample Size
end;




rawdata=[];
nlstm = strcat(maindir,  mdfile);
fnlstm=fopen(nlstm,'r');
xlstm=[];tcode=[]; 
while feof(fnlstm) ~= 1;
dum1=fscanf(fnlstm,'%s',1);
dum2=fscanf(fnlstm,'%d');
xlstm=str2mat(xlstm,dum1);
tcode=[tcode; dum2(1)];
datadir
aname=[datadir dum1 '.p59'];
fp=fopen(aname,'rt');
dum2=load(aname, '-ascii');
disp(sprintf('%s %d',aname,size(dum2)));
fclose(fp);
%dum2=dum2(1:nds,3);
dum2=dum2(1:nds,1);  % changed to drop the data
if size(find(dum2-missex),1) == size(dum2,1);
rawdata=[rawdata dum2];
end;
end;
fclose(fnlstm);
y=[];  
for i=1:cols(rawdata);
dum=transx(rawdata(:,i),tcode(i));
y=[y dum];
end;
xlstm=trimr(xlstm,1,0);

