function ok = mkdbd(dbid, dbname, filedir, fileext); % function ok = mkdbd(dbid, dbname, filedir, fileext); % makes a database directory file % files are in filedir and have extenstion fileext % database directory id is dbid, name is dbname % database directory will be put in c:\dbases\dbid.dbd % files must be accessible through tsi % tsi full id is dbdid.filename % database directory format is: % id name % first line is: dbid dbname % remaining lines are: seriesid seriesname % example: % mkdbd('xyz','xyz mutual funds','c:\dbases\xyz','tsi'); % % Note: this will close ALL FILES to avoid overloading the file system % % see also: TSI, MKDBL % copyright, 1996, William F. Sharpe % wfsharpe@leland.stanford.edu % this version Jan. 15, 1996 % deblank inputs if needed dbid = deblank(dbid); dbname = deblank(dbname); filedir = deblank(filedir); fileext = deblank(fileext); % add slash to filedir if needed if filedir(length(filedir)) ~= '\' filedir = [ filedir '\']; end; % delete any previous version of temp.txt fid = fopen('c:\dbases\temp.txt','r'); if fid >0 fclose(fid); delete c:\dbases\temp.txt; end; % list directory and place on temp.txt disp (' '); disp ( ' Getting Directory............................'); diary off diary c:\dbases\temp.txt stg = [ 'ls ' filedir '*.' fileext ';']; eval(stg); diary off % read temp.txt disp(' '); disp(' Getting Information........................'); fid = fopen('c:\dbases\temp.txt','r'); x = fscanf(fid,'%c'); fclose(fid); % go through directory to get information for dbd upext = ['.' fileext]; upext = upper(upext); r = x; n = 0; while length(r)>0 [tok,r] = strtok(r); if (length(findstr(upper(tok),upext))>0) & ... length(findstr(upper(tok),'*'))==0 sid = strtok(tok,'.'); fullid = [ dbid '.' sid]; [src,nm,curr,dates,rets] = tsi(fullid); fclose('all'); % needed to avoid overloading file system fullidx = [ fullid blanks(20)]; fullidx = fullidx(1:20); nmx = [nm blanks(60)]; nmx = nmx(1:60); ln = [ fullidx nmx]; n = n+1; if n == 1 dbd = ln; else dbd = [ dbd; ln]; end; end; end; % sort on name disp (' '); disp (' Sorting..............................'); numcols = size(dbd,2); nmmat = dbd(:,21:numcols); [slst,ii] = strsort(nmmat); dbd = dbd(ii,:); % write on file disp (' '); disp (' Saving..............................'); % open database directory file dbfl = [ 'c:\dbases\' dbid '.dbd']; fido = fopen(dbfl,'w'); % write first line dbidx = [ dbid blanks(20)]; dbidx = dbidx(1:20); dbnamex = [ dbname blanks(60)]; dbnamex = dbnamex(1:60); ln = [dbidx dbnamex ]; putl(fido,ln); % write remaining lines numrows = size(dbd,1); for i = 1:1:numrows putl(fido,dbd(i,:)); end; fclose(fido);