home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / languages / rlab1_23a / CTB / abcdchk next >
Text File  |  1995-11-14  |  2KB  |  69 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. // abcdchk
  4. //
  5. // Syntax: msg=abcdchk(a,b,c,d)
  6. //
  7. //      This routine checks the matrices A,B,C,D for consistency of
  8. //      dimensions. If everything is consistent, then the string msg
  9. //      is returned as a null string. Otherwise, an error message
  10. //      is returned in msg.
  11. //
  12. //      Valid systems with empty matrices are allowed.  
  13. //
  14. // Copyright (C), by Jeffrey B. Layton, 1994
  15. // Version JBL 931016
  16. //--------------------------------------------------------------------------
  17.  
  18. abcdchk = function(a,b,c,d)
  19. {
  20.    local(msg,narg)
  21.  
  22.    narg=0;
  23.    if (exist(a)) { narg=narg+1; }
  24.    if (exist(b)) { narg=narg+1; }
  25.    if (exist(c)) { narg=narg+1; }
  26.    if (exist(d)) { narg=narg+1; }
  27.  
  28.    msg="";
  29.  
  30.    if (a.nr != a.nc) {
  31.        msg="The A matrix must be square";
  32.    }
  33.  
  34.    if (narg > 1) {
  35.        if (b.nc) {
  36.            if (a.nr != b.nr) {
  37.                msg="The A and B matrices must have the same number of rows.";
  38.            }
  39.        }
  40.    }
  41.    if (narg > 2) {
  42.        if (c.nr) {
  43.            if (c.nc != a.nc) {
  44.                msg="The A and C matrices must have the same number of columns.";
  45.            }
  46.        }
  47.    }
  48.    if (narg > 3) {
  49. // Check if a,b,c matrices have zero dimensions. If so, just return.
  50.        if ((a.nr+b.nr+c.nr) == 0) {
  51.             return msg;
  52.        }
  53. // Check C and D matrix compatibilities
  54.        if (d.nc || b.nc) {
  55.            if (d.nr != c.nr) {
  56.                msg="The C and D matrices must have the same number of rows.";
  57.            }
  58.        }
  59. // Check B and D matrix compatibilities
  60.        if (d.nr || c.nr) {
  61.            if (d.nc != b.nc) {
  62.                msg="The B and D matrices must have the same number of columns.";
  63.            }
  64.        }
  65.     }
  66.  
  67.    return msg;
  68. };
  69.