home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / languages / progs / shell / Sources / c / DArray < prev    next >
Encoding:
Text File  |  1994-06-25  |  1.7 KB  |  100 lines

  1. #include <stdio.h>
  2.  
  3. #include "DeskLib:WimpSWIs.h"
  4.  
  5. #include "Shell.Array.h"
  6. #include "Shell.Extra.h"
  7. #include "Shell.SafeAlloc.h"
  8.  
  9.  
  10.  
  11.  
  12.  
  13. #define COLUMN_WIDTH 8
  14.  
  15.  
  16.  
  17.  
  18.  
  19. void    Shell_DoubleArrayDrawer(
  20.     Shell_convertpoint    convert,
  21.     wimp_point        rectsize,
  22.     void            *reference,
  23.     const wimp_rect        *redrawrect
  24.     )
  25. {
  26.     wimp_rect        rect    = *redrawrect;
  27.     double            **data    = (double **) reference;
  28.     int            i, j;
  29.     char            s[64];
  30.  
  31. Shell_ConvertToSubTextRect2( &rect, rectsize);
  32. rect.min.x /= COLUMN_WIDTH;
  33. rect.max.x /= COLUMN_WIDTH;
  34.  
  35.  
  36. for ( i=rect.min.x; i<=rect.max.x; i++)    {
  37.     int x = i*COLUMN_WIDTH*Shell_TEXTXSIZE;
  38.  
  39.     for ( j=rect.min.y; j<=rect.max.y; j++)    {
  40.         sprintf( s, "%.2g", data[j][i]);
  41.             /* Note the order. This is so that matrices are displayed with first    */
  42.             /* indice denoting the row, and the second denoting the column.        */
  43.         s[ COLUMN_WIDTH-1] = '\0';
  44.         Shell_PrintString( s, x, rectsize.y - j*Shell_TEXTYSIZE, convert);
  45.         }
  46.  
  47.     }
  48.  
  49. return;
  50. }
  51.  
  52.  
  53.  
  54.  
  55. BOOL Shell_DoubleArraySaver( char *filename, Shell_rectblock *r)
  56. {
  57. double    **data    = (double **) r->reference;
  58. int    x, y;
  59. FILE    *f;
  60.  
  61. f = fopen( filename, "w);
  62. if (!f)    return FALSE;
  63.  
  64. for ( y=0; y<info->info.size.y; y++)    {
  65.     for ( x=0; x<info->info.size.x; x++)    {
  66.         fprintf( f, info->fn( x, y, &info->info));
  67.         fprintf( f, "\t");
  68.         }
  69.     fprintf( f, "\n");
  70.     }
  71. return TRUE;
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. Shell_rectblock    *Shell_Add2DDoubleArray(
  79.     Shell_windblock *w, int x, int y, int xsize, int ysize,
  80.     int forecol, int backcol, double **data
  81.     )
  82. {
  83.     Shell_rectblock        *rectblock;
  84.  
  85. rectblock = Shell_AddRectangle2(
  86.     w,
  87.     x, y - ysize*Shell_TEXTYSIZE,
  88.     x + xsize * COLUMN_WIDTH * Shell_TEXTXSIZE, y,
  89.     Shell_DoubleArrayDrawer,
  90.     (void *) data
  91.     );
  92.  
  93.  
  94. Shell_MakeRectIcon( rectblock, forecol, backcol, "r1");
  95.  
  96. return rectblock;
  97. }
  98.  
  99.  
  100.