home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 April / DPPCPRO0498.ISO / April / MathCad / SETUP / DATA.Z / TRNSPOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-05  |  2.2 KB  |  59 lines

  1. #include "mcadincl.h"
  2.     
  3.     
  4.     LRESULT transposeFunction( LPCOMPLEXARRAY      Y,
  5.                                 LPCCOMPLEXARRAY     X );
  6.  
  7.     FUNCTIONINFO    transpose = 
  8.     { 
  9.     "transpose",                                    // Name by which mathcad will recognize the function
  10.     "X",                                            // transpose will be called as transpose(X)
  11.     "returns a transpose of X"  ,                   // description of transpose(X)
  12.     (LPCFUNCTION)transposeFunction,                 // pointer to the executible code
  13.     COMPLEX_ARRAY,                                  // the output is a complex array
  14.     1,                                              // the function takes on 1 argument
  15.     { COMPLEX_ARRAY}    // the input type is a complex array
  16.     };
  17.     
  18.     
  19.     LRESULT transposeFunction( LPCOMPLEXARRAY      Y,
  20.                                 LPCCOMPLEXARRAY     X   )
  21.     {
  22.         unsigned int i, j;
  23.         
  24.         // allocate space for the return array Y
  25.         if ( !MathcadArrayAllocate( Y,  // allocate space for Y 
  26.                     X->cols,    //  with X cols
  27.                     X->rows,    //  and X rows
  28.                     X->hReal != NULL,   //  allocate the real part if X has a real part 
  29.                     X->hImag != NULL    //  allocate the imaginary part if X has 
  30.                                 //  an imaginary part
  31.                     ) ) 
  32.             return 2;           // if allocation is insufficient
  33.                                 // return the error code
  34.                         
  35.         
  36.         
  37.         for ( i = 0; i < Y->cols; i++ )
  38.         {
  39.             if ( isUserInterrupted( ) ) 
  40.             {
  41.                 MathcadArrayFree( Y );
  42.                 return  3;      // user interrupted
  43.             }
  44.             
  45.             for ( j = 0; j < Y->rows; j++ )     
  46.             {
  47.                 
  48.                 if ( X->hReal != NULL )     
  49.                     Y->hReal[i][j] = X->hReal[j][i];
  50.                 if ( X->hImag != NULL )     
  51.                     Y->hImag[i][j] = X->hImag[j][i]; 
  52.             }
  53.         }               
  54.         
  55.         return 0;               // return 0 to indicate there was no error
  56.             
  57.     }           
  58.     
  59.