Home > bobstuff > txt.m

txt

PURPOSE ^

TXT Fill a matrix with lines of text entered from the keyboard.

SYNOPSIS ^

function t = txt( t_old )

DESCRIPTION ^

  TXT  Fill a matrix with lines of text entered from the keyboard.

  t = TXT( t_old ) returns an array containing lines of text entered from 
  the keyboard. If t_old is specified, the new text is appended, and the 
  result returned in t. Each line is padded with blanks to 80 characters, 
  and there is a maximum of 100 lines. Text input is terminated by 
  entering a line with the single character '.'.  NOTE: lines cannot 
  begin with a space - they must start with letters, numbers or valid 
  punctuation symbols.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  ver. 1: 12/1/96 (RG)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001       function  t = txt( t_old )
0002 %  TXT  Fill a matrix with lines of text entered from the keyboard.
0003 %
0004 %  t = TXT( t_old ) returns an array containing lines of text entered from
0005 %  the keyboard. If t_old is specified, the new text is appended, and the
0006 %  result returned in t. Each line is padded with blanks to 80 characters,
0007 %  and there is a maximum of 100 lines. Text input is terminated by
0008 %  entering a line with the single character '.'.  NOTE: lines cannot
0009 %  begin with a space - they must start with letters, numbers or valid
0010 %  punctuation symbols.
0011 %
0012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0013 %  ver. 1: 12/1/96 (RG)
0014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0015 
0016 end_chr = '.' ;            % end of text character
0017 ascii_b = 32 ;            % Ascii decimal code for ' '
0018 
0019 if nargin == 0            % if t_old not specified, create t
0020     t = [] ;            
0021     n_lines = 0 ;
0022 else                % else append new text to old
0023     t = t_old ;
0024     n_lines = length( t(:,1) ) ;
0025 end
0026                       % get text from keyboard - up to 100 lines
0027 disp('Start entering text (no quotes necessary). Type . by itself to terminate.')
0028 while( n_lines < 101 )
0029 
0030     line = input('','s') ;    %  issue prompt, then
0031                 %  check for input terminator
0032     L = length( line ) ;
0033     if (L==1) & (line(1)==end_chr ), break; end
0034 
0035     n_blanks = 79 - L ;    
0036 
0037     if n_blanks < 0        %  if too long, truncate at 80 chars
0038     line = line(1:80) ;    %  else pad with blanks to 80 chars
0039     else
0040         line = [ line, setstr( ascii_b*ones(1,n_blanks)) ] ;
0041     end
0042                 %  add this line to the text array
0043     t = [t; line] ;
0044 
0045     n_lines = n_lines + 1 ;    %  increment line count
0046 
0047 end

Generated on Thu 01-Dec-2005 07:46:03 by m2html © 2003