home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SRC.DI$ / MATTEST.C next >
Encoding:
C/C++ Source or Header  |  1993-03-26  |  1.7 KB  |  105 lines

  1. /*
  2.  * Mat-file test program
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include "mat.h"
  7.  
  8.  
  9. main()
  10. {
  11.     MATFile    *ph;
  12.     MATFile    *ph1;
  13.     char        **dir;
  14.     int            ndir;
  15.     int            i;
  16.     Matrix        *pmat;
  17.  
  18.  
  19.     /*
  20.      * open "matlab.mat"
  21.      */
  22.     ph = matOpen("matlab.mat", "u");
  23.  
  24.     if (ph == NULL) {
  25.         printf("No matlab.mat file.\n");
  26.         exit(0);
  27.     }
  28.  
  29.     /*
  30.      * copy matlab.mat to temp.mat by using matGetNextMatrix
  31.      */
  32.     ph1 = matOpen("temp.mat", "w");
  33.  
  34.     if (ph1 == NULL) {
  35.         printf("Not able to make temp.mat.\n");
  36.         exit(0);
  37.     }
  38.  
  39.     for (;;) {
  40.         pmat = matGetNextMatrix(ph);
  41.         if (pmat == NULL) {
  42.             if (ferror(matGetFp(ph))) {
  43.                 printf("Read error using matGetNextMatrix on matlab.mat.\n");
  44.                 exit(0);
  45.             } else {
  46.                 break;
  47.             }
  48.         }
  49.         if (matPutMatrix(ph1,pmat)) {
  50.             printf("Error writing matrix to temp.mat.\n");
  51.             exit(0);
  52.         }
  53.         mxFreeMatrix(pmat);
  54.     }
  55.  
  56.     matClose(ph1);
  57.  
  58.     /*
  59.      * get directory of matlab.mat
  60.      */
  61.     dir = matGetDir(ph, &ndir);
  62.  
  63.     if (dir == NULL) {
  64.         printf("Directory reading problem.\n");
  65.         exit(0);
  66.     } else {
  67.         printf("Directory of matlab.mat\n");
  68.         for (i=0; i < ndir; i++)
  69.             printf("%s\n",dir[i]);
  70.     }
  71.  
  72.     ph1 = matOpen("temp1.mat", "w");
  73.  
  74.     if (ph1 == NULL) {
  75.         printf("Not able to make temp1.mat.\n");
  76.         exit(0);
  77.     }
  78.  
  79.     /*
  80.      * copy matlab.mat to temp1.mat using matGetMatrix
  81.      */
  82.     for (i=0; i < ndir; i++) {
  83.         pmat = matGetMatrix(ph, dir[i]);
  84.         if (pmat == NULL) {
  85.             if (feof(matGetFp(ph))) {
  86.                 printf("Read error using matGetMatrix on matlab.mat.\n");
  87.                 exit(0);
  88.             } else {
  89.                 printf("Could not find matrix %s even though it is in the \
  90. directory.\n",dir[i]);
  91.             }
  92.         }
  93.         if (matPutMatrix(ph1,pmat)) {
  94.             printf("Error writing matrix to temp1.mat.\n");
  95.             exit(0);
  96.         }
  97.         mxFreeMatrix(pmat);
  98.     }
  99.  
  100.     matClose(ph1);
  101.  
  102.     exit(0);
  103. }
  104.  
  105.