home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 344_01 / mtxio.c < prev    next >
Text File  |  1991-05-29  |  2KB  |  84 lines

  1. /*-----------------------------------------------------------------------
  2.    Main File : mtx.exe
  3.    File Name : mtxio.c
  4.  
  5.    Purpose - Allocation, initialization and output routines
  6. -----------------------------------------------------------------------*/
  7. #include "mtx.h"
  8. #include "mtxcle.h"
  9. #include "mtxio.h"
  10.  
  11.  
  12.   /* Remove trailing '_' for operations timing */
  13. #define TIME_
  14.  
  15. #ifdef TIME
  16. #include <time.h>
  17. #endif
  18.  
  19. extern int MSize;
  20. extern Mtype *Aptr;
  21. extern Mtype *bptr;
  22. extern int P;
  23. extern int display_all;
  24.  
  25.  
  26. void read_matrix()
  27. /*
  28.   Assumes all input is correct - does no checking!
  29. */
  30. {
  31.   int i,j;
  32.   char s[30];
  33.   const long int n = MSize;
  34.  
  35.   if((Aptr=(Mtype *)alloc(n*n,sizeof(Mtype)))==NULL)
  36.     error(errHISIZE);
  37.   if((bptr=(Mtype *)alloc(n,sizeof(Mtype)))==NULL)
  38.     error(errHISIZE);
  39.  
  40.   for(i=0; i < n; ++i)
  41.   {
  42.     for(j=0 ; j < n; ++j)       /*get A*/
  43.     {
  44.       fscanf(stdin,"%s",s);
  45.       A(i,j) = atoMtype(s);
  46.     }
  47.     fscanf(stdin,"%s",s);       /*get b*/
  48.     b(i) = atoMtype(s);
  49.   }
  50. }
  51.  
  52.  
  53. void print_matrix(int d_flag)
  54. {
  55.   int i,j;
  56.   const long int n = MSize;
  57.   static int mat_flag;
  58.  
  59.   if(d_flag==NO_SHOW)
  60.     return;
  61.   if(d_flag != SOLUTION_ONLY)
  62.     printf("%s\n",mat_flag++ ? "\nOutput Matrix--\n" : "\nInput Matrix--\n");
  63.   for(i=0; i < n; ++i)
  64.   {
  65.     if(d_flag==SHOW_MATRIX)
  66.       for(j=0 ; j < n; ++j)
  67.         printf("  %*.*G",4+P,P,A(i,j));
  68.     printf("  %*.*G\n",4+P,P,b(i));
  69.   }
  70.   printf("\n");
  71.  
  72. #ifdef TIME
  73.   {
  74.     static int flag;
  75.     if(flag)
  76.       print_time;
  77.     ++flag;
  78.   }
  79. #endif
  80.  
  81. }
  82.  
  83.  
  84.