
/**************************************************************
*                                                             *
*  MATRIZENINITIALISIERUNG                                    *
*                                                             *
*  Autor     : MAURER Christian                               *
*  Zweck     : initialisiert Matrix                           *
*  Version   : 1.0:                              24.3.1988    *
*              1.1:                              26.5.1988    *
*                 pointer auf last und next wird NULL         *
*                 zugewiesen.                                 *
*              1.2:                              27.7.1988    *
*                 Datentypen, Fehlerbehandlung                *
*  Kommentar : Das Modul allociert automatisch Speicher       *
*              fuer die Ergebnismatrix, gibt ihm Namen und    *
*              gibt Ergebnismatrix Dimension der Uebergebenen *
*                                                             *
*              cc +fi initmat.c                               *
*                                                             *
***************************************************************/


#include <df0:include/exec/types.h>
#include <df0:include/matrix.h>

struct matrix *InitMat (a, b_name, name)
struct matrix *a;
UBYTE *b_name, *name;
{
   UBYTE  *strncat(), *strncpy();
   DOUBLE *malloc();
   struct matrix *c;
   SHORT i, strlen();
   VOID KillMat();

   c = (struct matrix *) malloc (sizeof (struct matrix));
   if (!c) {
      return (NULL);
   } else {
      c -> zeilen  = a -> zeilen;
      c -> spalten = a -> spalten;

      c -> last = NULL;
      c -> next = NULL;

      for (i=1; i<=a->zeilen; ++i)
         if ((c->mat[i] = (double *) malloc (8*(a->spalten + 1))) == 0L) {
            c -> zeilen = i - 1;
            KillMat (c);
            return (NULL);
         }
      if (name == 0L) {
         strncpy (c->name, a->name, 15);
         strncat (c->name, b_name, 15-strlen (c->name));
      } else
         strncpy (c->name, name, 15);

      return (c);
   }
}
