% Last edited on 2024-09-23 17:19:15 by stolfi

function keg_check_size(M,NI,NJ,name)
  % Checks whether {M} has {NI} rows and {NJ} columns.
  % Fails if not, with a "{name} has wrong size".
  % If {NI} and/or {NJ} is negative, the corresponding check is skipped.
  
  ok = true
  MI, MJ = size(M)
  if ((NI >= 0) & (MI != NI))
    ok = false
  endif
  if ((NJ >= 0) & (MJ != NJ))
    ok = false
  endif
  if (! ok)
    error("** array %s has wrong size %d × %d, should be %d × %d\n", name, MI, MJ, NI, NJ)
  endif
endfunction

    