#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>

struct spmat {
  int m, n, nmbelems, *rowbase, *colind;
  double *elems;
};

/* sp_nrm1: return sparse matrix 1-norm. */
double sp_nrm1(struct spmat aa)
{
  abort();
}

/* sp_nrmi: return sparse matrix inf-norm. */
double sp_nrmi(struct spmat aa)
{
  abort();
}

/* sp_transp: form sparse matrix transpose. */
struct spmat sp_transp(struct spmat aa)
{
  abort();
}

/* sp_setup: define sparse test matrix. */
struct spmat sp_setup(int m, int n)
{
  struct spmat aa;
  /* The test matrix is an upper bi-diagonal matrix of order min(m,n).
     For 0<=i<ord, A(i,i)=i+1;
     For 0<=i<ord-1, A(i,i+1)=-1. */
  int ord, k, i;
  if (m<n) {
    ord = m;
  }
  else {
    ord = n;
  }
  aa.m = m; aa.n = n;
  aa.nmbelems = 2*ord-1;
  aa.rowbase = (int *) malloc((aa.m+1)*sizeof(int));
  aa.colind = (int *) malloc(aa.nmbelems*sizeof(int));
  aa.elems = (double *) malloc(aa.nmbelems*sizeof(double));
  k = 0; i = 0;
  while (i<ord) {
    aa.rowbase[i] = k;
    aa.colind[k] = i;
    aa.elems[k] = i+1;
    ++k;
    if (i<ord-1) {
      aa.colind[k] = i+1;
      aa.elems[k] = -1;
      ++k;
    }
    ++i;
  }
  while (i<=m) {
    aa.rowbase[i] = k;
    ++i;
  }
  return aa;
}
 
main()
{
  int m, n, i, k;
  struct spmat aa, bb;
  /* form test matrix aa */
  m = 5; n = 4;
  aa = sp_setup (m, n);
  printf(" %s %4d  %s %4d  %s %4d\n",
	 "m", aa.m, "n", aa.n, "nmbelems", aa.nmbelems);
  for (i=0; i<=aa.m; i++) {
    printf(" %4d", aa.rowbase[i]);
  }
  printf("\n");
  for (k=0; k<aa.nmbelems; k++) {
    printf(" %4d", aa.colind[k]);
  }
  printf("\n");
  for (k=0; k<aa.nmbelems; k++) {
    printf(" %12.2e", aa.elems[k]);
  }
  printf("\n");
  /* print norms of aa */
  printf("  %s  %12.2e    %s  %12.2e\n",
    "nrm1", sp_nrm1(aa), "nrmi", sp_nrmi(aa));
  /* form transpose matrix */
  bb = sp_transp(aa);
  /* print norms of bb */
  printf("  %s  %12.2e    %s  %12.2e\n",
    "nrm1", sp_nrm1(bb), "nrmi", sp_nrmi(bb));
}