home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e065 / 3.ddi / ARTIO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  40.7 KB  |  1,270 lines

  1. /* artio.c - character recognition user I/O function
  2.  ************************************************************************
  3.  * Copyright(C) 1988-1990 NeuralWare Inc                                *
  4.  * Penn Center West, IV-227, Pittsburgh, PA 15276                       *
  5.  *                                                                      *
  6.  * All rights reserved.  No part of this program may be reproduced,     *
  7.  * stored in a retrieval system, or transmitted, in any form or by any  *
  8.  * means, electronic, mechanical, photocopying, recording or otherwise  *
  9.  * without the prior written permission of the copyright owner,         *
  10.  * NeuralWare, Inc.                                                     *
  11.  ************************************************************************
  12.  */
  13. #ifndef SKY
  14. #include "string.h"
  15. #endif
  16.  
  17. #define UIO_SERVER             1
  18. #define SERVER_EMULATOR_FILE   1
  19. #define SKIP_COMPAT_DATA       1
  20. #include "userutl.h"
  21. #include "uio_strc.h"
  22. #include "uio_tran.h"
  23. #include "uio_reqs.pro"
  24. #include "uio_cmds.pro"
  25.  
  26. #ifndef SUN
  27. #ifndef DLC
  28. #include <stdlib.h>
  29. #endif
  30. #endif
  31.  
  32. #ifdef MAC
  33. #include "macuio.redef"
  34. #endif
  35.  
  36. /************************************************************************
  37.  *                                                                      *
  38.  *      Character Recognition User I/O Routine                          *
  39.  *                                                                      *
  40.  *      Options:                                                        *
  41.  *                                                                      *
  42.  *      ATTENTION I/O:  This allows the user to create a file of        *
  43.  *                      character patterns and their associated         *
  44.  *                      ASCII code. This file is written in .nna        *
  45.  *                      format and can be used either for File I/O      *
  46.  *                      or for User I/O learning. The user              *
  47.  *                      is prompted for file name (.nna extension       *
  48.  *                      assumed), and is given the option of writing or *
  49.  *                      appending the file. The user is provided with   *
  50.  *                      a grid in which to draw patterns. On entering   *
  51.  *                      a pattern, the user is prompted to enter, from  *
  52.  *                      the keyboard, the character that the pattern    *
  53.  *                      depicts. The file is closed on quitting.        *
  54.  *                                                                      *
  55.  *      REWIND:         If a file is open it is rewound.                *
  56.  *                                                                      *
  57.  ************************************************************************
  58.  */
  59.  
  60. /* grid definitions */
  61. static long     n_across, n_down, n_inputs;
  62.  
  63. #define N_ACR_MIN       1
  64. #define N_ACR_MAX       16
  65. #define N_ACC_DEF       6
  66. #define N_DWN_MIN       1
  67. #define N_DWN_MAX       16
  68. #define N_DWN_DEF       8
  69.  
  70. /* window coordinates - initialized in usrIO( ) */
  71. static int      wxstrt[4], wystrt[4], wxend[4], wyend[4];
  72.  
  73. typedef struct _grid {
  74.         unsigned char   gr_key;         /* window key for grid */
  75.         unsigned char   gr_flag;        /* grid flag */
  76.         int      gr_xoff, gr_yoff;      /* x,y offset from window origin */
  77.         int      gr_nx, gr_ny;          /* # pixels in x, y directions */
  78.         int      gr_pxx, gr_pxy;        /* size of a grid pixel */
  79.         int      gr_color[3];           /* color of lines and pixels */
  80. #define          GR_OFF         0       /* off color index */
  81. #define          GR_ON          1       /* on color index */
  82. #define          GR_LINE        2       /* line color index */
  83.         float   *gr_data;               /* data for grid */
  84. } GRID;
  85.  
  86. static  GRID    ip_grid = { 0 };        /* Input Grid */
  87. static  GRID    f1_grid = { 0 };        /* F1 grid (ART 1) */
  88. static  float   f1data[ N_ACR_MAX * N_DWN_MAX ]; /* f1 data */
  89. static  char    ip_text[] = "Input Pattern";
  90. static  char    f1_text[] = "F1 Activity";
  91. static  int     wrstepf =  0 ;  /* WRSTEP flag */
  92.  
  93. /* Local menu definitions */
  94.  
  95. #define CR_SCROLL       0
  96. #define CR_SEEK         1
  97. #define CR_ENTER        2
  98. #define CR_QUIT         3
  99. #define CR_AUTO         4
  100.  
  101. #define NULL_STR    0
  102.  
  103. static GMENU_ITEM  PMenuList[] = {      /* Menu list */
  104.           { CR_SCROLL, NULL_STR, NULL_STR },
  105.           { CR_SEEK,   NULL_STR, NULL_STR },
  106.           { CR_ENTER,  NULL_STR, NULL_STR },
  107.           { CR_QUIT,   NULL_STR, NULL_STR },
  108.           { CR_AUTO,   NULL_STR, NULL_STR }
  109. };
  110. static GMENU    AIOMenu  = {    /* Attention I/O menu */
  111.         0,
  112.         4,                              /* # items */
  113.         3,                              /* key */
  114.         0x0000
  115. };
  116. static GMENU    LrnMenu  = {    /* Attention I/O menu */
  117.         0,
  118.         5,                              /* # items */
  119.         3,                              /* key */
  120.         0x0000
  121. };
  122.  
  123. /* File definitions */
  124. static  char    filename[13];
  125. static  char    filenroot[9] = "art1";          /* Default .nna file */
  126. static  int     curr_pattern, n_patterns;   /* pattern index, # patterns */
  127. #define MAX_N_PATTERNS  100
  128. static  long    filepos[ MAX_N_PATTERNS ];      /* Array of file positions */
  129. static  int     shuffle_array[ MAX_N_PATTERNS ];/* Index into shuffle array */
  130. static  int     shufflex =  0 ;         /* Shuffle Index */
  131. #define MAX_STR 78                              /* For reading from file */
  132. static  char    fbuf[MAX_STR + 1];              /* buffer for file i/o */
  133. static  FILE    *fp = 0;                        /* File pointer */
  134. static  float   fdata[ N_ACR_MAX * N_DWN_MAX ]; /* file data */
  135. static  float   fout[7];                        /* file desired output */
  136.  
  137. /* Network parameters */
  138. static  int   nlayp, ninp, noutp, ltype;        /* Network parameters */
  139. static  char  *csp, *netnp;                     /* Network pointers*/
  140.  
  141. /* Graphics parameters */
  142. static  int   xsize, ysize, ncolor, chrx, chry; /* graphics parameters */
  143. /* Miscellaneous */
  144. static  int     abortio;
  145. static  int     autoip;
  146.  
  147. #ifdef DLC
  148. /* --- prototypes --- */
  149.         DispGrid( GRID * );
  150.         DispPattern( GRID * );
  151.         Sketch( GRID * );
  152.         DrawPixel( GRID *, int, int, int );
  153.         FillPosArr(  );
  154.         ReadFData( );
  155.         WriteFData( );
  156.         Shuffle( int );
  157. #endif
  158.  
  159. DispGrid( gridp )
  160. GRID    *gridp;         /* pointer to grid structure */
  161. {
  162.   int   wx;             /* work index */
  163.   int   x0,y0,x1,y1;    /* endpoints of gridlines */
  164.  
  165.   /* Draw vertical gridlines */
  166.   x1 = x0 = gridp->gr_xoff;
  167.   y0 = gridp->gr_yoff;
  168.   y1 = y0 + gridp->gr_ny * ( gridp->gr_pxy + 1 );
  169.  
  170.   for (wx = 0; wx <= gridp->gr_nx; wx++, x1 = x0 += gridp->gr_pxx + 1 )
  171.     ug_line( gridp->gr_key, gridp->gr_color[GR_LINE], 0, x0, y0, x1, y1, 0 );
  172.  
  173.   /* Draw horizontal gridlines */
  174.   x0 = gridp->gr_xoff;
  175.   x1 = x0 + gridp->gr_nx * ( gridp->gr_pxx + 1 );
  176.   y1 = y0 = gridp->gr_yoff;
  177.  
  178.   for (wx = 0; wx <= gridp->gr_ny; wx++, y1 = y0 += gridp->gr_pxy + 1 )
  179.     ug_line( gridp->gr_key, gridp->gr_color[GR_LINE], 0, x0, y0, x1, y1, 0 );
  180. }
  181.  
  182. VOID DispPattern( gridp )
  183. GRID    *gridp;         /* Pointer to grid structure */
  184. {
  185.   int   wx, wy, wz;     /* work indices */
  186.   float *dp;            /* pointer to data */
  187.  
  188.   dp = &gridp->gr_data[0];
  189.   if ( dp == ( float * )0 ) return;
  190.  
  191.   for ( wy = gridp->gr_ny, wz = 0; --wy >= 0 ; )
  192.     for ( wx = 0; wx < gridp->gr_nx; wx++, wz++ )
  193.       DrawPixel( gridp, wx, wy,
  194.                  gridp->gr_color[ dp[wz]>0.0001 ? GR_ON : GR_OFF ] );
  195. }
  196.  
  197.  
  198. VOID Sketch( gridp )
  199. GRID    *gridp;         /* Pointer to grid structure */
  200. {
  201.   int   x0, y0, x1, y1;         /* Grid boundary */
  202.   int   wx, wy, wz;             /* work indices */
  203.   int   key, xp, yp, button;    /* mouse parameters */
  204.   float *dp;                    /* pointer to data */
  205.  
  206.   dp = &gridp->gr_data[0];
  207.   if ( dp == ( float * )0 ) return;
  208.   x0 = gridp->gr_xoff;
  209.   y0 = gridp->gr_yoff;
  210.   x1 = x0 + gridp->gr_nx * ( gridp->gr_pxx + 1 );
  211.   y1 = y0 + gridp->gr_ny * ( gridp->gr_pxy + 1 );
  212.  
  213.   for (;;) {
  214.     ug_mouse( &key, &xp, &yp, &button );
  215.     if ( key != gridp->gr_key || xp < x0 || xp >= x1 || yp < y0 || yp >= y1 )
  216.       return;
  217.     if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
  218.       /* Calculate grid coordinate */
  219.       wx = ( xp - x0 ) / ( gridp->gr_pxx + 1 );
  220.       wy = ( yp - y0 ) / ( gridp->gr_pxy + 1 );
  221.       DrawPixel( gridp, wx, wy,
  222.                  gridp->gr_color[ button == MBUT_LEFT ? GR_ON : GR_OFF ] );
  223.       /* Modify data array */
  224.       wz = (gridp->gr_ny - wy - 1) * gridp->gr_nx + wx;
  225.       dp[wz] = button == MBUT_LEFT ? 1.0 : -1.0;
  226.     }
  227.   }
  228. }
  229.  
  230.  
  231. DrawPixel( gridp, x, y, color )
  232. GRID    *gridp;         /* pointer to grid structure */
  233. int      x, y;          /* grid coordinate */
  234. int      color;         /* pixel color */
  235. {
  236.       int       xstrt, ystrt;
  237.  
  238.       xstrt = gridp->gr_xoff + 1 + ( gridp->gr_pxx + 1 ) * x;
  239.       ystrt = gridp->gr_yoff + 1 + ( gridp->gr_pxy + 1 ) * y;
  240.       ug_boxf( gridp->gr_key, color, 0, xstrt, ystrt,
  241.                xstrt + gridp->gr_pxx - 1, ystrt + gridp->gr_pxy - 1 );
  242. }
  243.  
  244. /* NOTE: following routine will not cope with
  245.    general format ".nna" files. In particular, it
  246.    is assumed that any new line which does not
  247.    start with a continuation character ('&') or
  248.    a comment character ('!') is the start of a
  249.    non-empty record; it is also assumed that there
  250.    are no comments in the middle of records */
  251.  
  252. FillPosArr( )
  253. {
  254.   int   wx;             /* work index */
  255.   int   ch;             /* Character */
  256.   long  fpos;           /* File position */
  257.   int   ftt;            /* First time through */
  258.  
  259.   fseek( fp, 0l, 0 );                   /* beginning of file */
  260.   for ( wx = 0; wx < MAX_N_PATTERNS; ) {
  261.     if ( (ch=fgetc( fp )) != '!' && ch != '&' ) {
  262.       ungetc( ch, fp );
  263.       fpos = ftell( fp );
  264.       ftt = 1;
  265.     } else ftt = 0;
  266.     /* Make sure there is something on the line;
  267.        scan to end of line */
  268.    while ( (ch=fgetc( fp)) != NEW_LINE ) {
  269.       if ( ftt && ch >= (int)'0' ) {
  270.         filepos[wx++] = fpos;
  271.         ftt = 0;
  272.       }
  273.       if ( ch == EOF ) return( wx );
  274.     }
  275.   }
  276. }
  277.  
  278. ReadFData( flag )
  279. int     flag;           /* Whether or not desired output should be read */
  280. {
  281.   int    wx, wy;        /* work index */
  282.   int    ch;
  283.   float *dp;            /* data pointer */
  284.  
  285.   char  sbuf[100];
  286.  
  287.   if ( curr_pattern < 0 ) curr_pattern = 0;
  288.  
  289.   if ( curr_pattern >= n_patterns ) {   /* Don't read from file */
  290.     for ( wx = 0; wx < n_inputs; wx++ )
  291.       fdata[wx] = -1.0;
  292.     curr_pattern = n_patterns;
  293.     return( 0 );
  294.   } else {
  295.     fseek( fp, filepos[curr_pattern], 0 );
  296.     /* NOTE: Following code assumes data has been written using
  297.        format of WriteFData( ) routine */
  298.     for (wx = 0, wy = 18, dp = fdata; wx < n_inputs;
  299.          wx++, wy--, dp++ ) {
  300.       if ( wy == 0 ) {  /* Look for continuation */
  301.         while ( (ch=fgetc( fp)) != NEW_LINE )
  302.           if ( ch == EOF ) goto bad_return;
  303.         if ( fgetc( fp ) != '&' ) goto bad_return;
  304.         wy = 18;
  305.       }
  306.       if ( fscanf( fp, "%f", dp ) <= 0 ) goto bad_return;
  307.     }
  308.   }
  309.     fseek( fp, filepos[curr_pattern], 0 );
  310.   return( 0 );
  311.  
  312. bad_return:
  313.   PutStr( "Bad file format\n" );
  314.   return( -1 );
  315. }
  316.  
  317.  
  318. WriteFData( flag )
  319. int     flag;           /* Whether or not desired output should be written */
  320. {
  321.   int   wx, wy;         /* work index */
  322.  
  323.   if ( curr_pattern < 0 ) curr_pattern = 0;
  324.  
  325.   if ( curr_pattern >= n_patterns ) {
  326.     curr_pattern = n_patterns;
  327.     n_patterns++;
  328.     fseek( fp, 0l, 2 );                 /* Seek End of File */
  329.     filepos[curr_pattern] = ftell( fp );
  330.   }
  331.  
  332.   fseek( fp, filepos[curr_pattern], 0 );
  333.  
  334.   fputc( ' ', fp );
  335.   for ( wx = 0, wy = 18; wx < n_inputs; wx++, wy-- )
  336.   {
  337.     if ( wy == 0 ) {
  338.       fputc( NEW_LINE, fp );
  339.       fputc( '&' , fp );                /* Continuation line */
  340.       wy = 18;
  341.     }
  342.     fprintf( fp, " %2.0f.", fdata[wx] );
  343.   }
  344.   fputc( NEW_LINE, fp );
  345.   curr_pattern++;
  346. }
  347.  
  348.  
  349. Shuffle( size )
  350. int     size;
  351. {
  352.   int   wx, wy, wz;
  353.   int   swap;
  354.  
  355.   for ( wx = 0, wy = size; wx < size; wx++, wy-- ) {
  356.     wz = rand( ) % wy;
  357.     swap = shuffle_array[wx];
  358.     shuffle_array[wx] = shuffle_array[wx + wz];
  359.     shuffle_array[wx + wz] = swap;
  360.   }
  361. }
  362.  
  363. /*****************************************************************************/
  364. /*                                                                           */
  365. /* Functions necessary for handling the User I/O package itself.             */
  366. /*                                                                           */
  367. /*****************************************************************************/
  368.  
  369. /* */
  370. /* UIO_Init   function to initialize user I/O
  371.  ************************************************************************
  372. */
  373. NINT UIO_Init(file)
  374. TEXT *file;
  375. {
  376.   NINT ret_val = UIO_OK;
  377.  
  378.     fp = (FILE *)0;
  379.  
  380.     PMenuList[CR_SCROLL].text = "Scroll";
  381.     PMenuList[CR_SCROLL].text2 = "";
  382.  
  383.     PMenuList[CR_SEEK].text = "Seek";
  384.     PMenuList[CR_SEEK].text2 = "";
  385.  
  386.     PMenuList[CR_ENTER].text = "Enter";
  387.     PMenuList[CR_ENTER].text2 = "";
  388.  
  389.     PMenuList[CR_QUIT].text = "Quit";
  390.     PMenuList[CR_QUIT].text2 = "";
  391.  
  392.     PMenuList[CR_AUTO].text = "Auto";
  393.     PMenuList[CR_AUTO].text2 = "";
  394.  
  395.     AIOMenu.item = PMenuList;
  396.     LrnMenu.item = PMenuList;
  397.  
  398.         /* Get screen parameters */
  399.         ug_gparms( &xsize, &ysize, &ncolor, &chrx, &chry);
  400.  
  401.         if ( ncolor < 8 ) {
  402.           gm_intcolor = 1;
  403.           gm_txtcolor = 0;
  404.           gm_outcolor = 0;
  405.         } else {
  406.           gm_intcolor = 7;
  407.           gm_txtcolor = 4;
  408.           gm_outcolor = 0;
  409.         }
  410.         ip_grid.gr_color[GR_OFF]  = f1_grid.gr_color[GR_OFF]  = gm_intcolor;
  411.         ip_grid.gr_color[GR_ON]   = f1_grid.gr_color[GR_ON]   = gm_txtcolor;
  412.         ip_grid.gr_color[GR_LINE] = f1_grid.gr_color[GR_LINE] = gm_txtcolor;
  413.  
  414.         InitGMenu( &AIOMenu, chrx, chry );
  415.         AIOMenu.x0 = 0; /* Menu position relative to window */
  416.         AIOMenu.y0 = 0;
  417.  
  418.         InitGMenu( &LrnMenu, chrx, chry );
  419.         LrnMenu.x0 = 0; /* Menu position relative to window */
  420.         LrnMenu.y0 = 0;
  421.  
  422.   return(ret_val);
  423. }
  424.  
  425. /* */
  426. /* UIO_Term   function to terminate user I/O
  427.  ************************************************************************
  428. */
  429. NINT UIO_Term(process)
  430. NINT process;
  431. {
  432.   NINT ret_val = UIO_OK;
  433.  
  434.             /* if a file is open */
  435.         if ( fp != (FILE *)0 ) fclose( fp );  /* close it */
  436.         fp = (FILE *)0;
  437.         PutStr( "bye bye\n" );      /* display a message */
  438.  
  439.   return(ret_val);
  440. }
  441.  
  442. /* */
  443. /* UIO_Attention  function to signal user I/O program
  444.  ************************************************************************
  445. */
  446. NINT UIO_Attention()
  447. {
  448.     NINT ret_val = UIO_OK;
  449.     NINT newfile;
  450.     NINT key, xp, yp, button;                  /* mouse interface */
  451.  
  452.     TEXT sbuf[60], *sp;                        /* work string and pointer */
  453.  
  454.     GMENU_ITEM  *gmip;
  455.  
  456.       if ( fp != (FILE *) 0 ) fclose( fp );
  457.  
  458.       sprintf( sbuf,
  459.                "Enter name of pattern file ( default: %s ):", filenroot );
  460.       PutStr( sbuf );
  461.       sp = GetStr( );
  462.       PutStr("\n");
  463.       if ( strcmp( sp, "" ) != 0 ) strncpy( filenroot, sp, 9 );
  464.       strcpy( filename, filenroot );
  465.       strcat( filename, ".nna" );
  466.       if ( (fp = fopen( filename, "r" )) == (FILE *)0 )
  467.         {
  468.           newfile = 1;
  469.         }
  470.       else
  471.         {
  472.           newfile = 0;
  473.           fclose(fp);
  474.         }
  475.  
  476.       if ( ( fp = fopen( filename, "a+" ) ) == (FILE *)0 ) {
  477.         sprintf( sbuf, "Cannot open file <%s>\n", filename );
  478.         PutStr( sbuf );
  479.         goto aio_return;
  480.       }
  481.  
  482.       fseek( fp, 0l, 0 );
  483.       if ( newfile ) {                  /* New file */
  484.         PutStr( "Enter number of pixels across:" );
  485.         sp = GetStr( );
  486.         PutStr("\n");
  487.         sscanf( sp, "%ld", &n_across );
  488.         if ( n_across < N_ACR_MIN ) n_across = N_ACR_MIN;
  489.         if ( n_across > N_ACR_MAX ) n_across = N_ACR_MAX;
  490.         PutStr( "Enter number of pixels down:" );
  491.         sp = GetStr( );
  492.         PutStr("\n");
  493.         sscanf( sp, "%ld", &n_down );
  494.         if ( n_down < N_DWN_MIN ) n_down = N_DWN_MIN;
  495.         if ( n_down > N_DWN_MAX ) n_down = N_DWN_MAX;
  496.         fprintf( fp,
  497.         "! number of pixels across = %2ld, number of pixels down = %2ld%s",
  498.                  n_across, n_down, NEW_LINE_STR );
  499.       } else {
  500.         if ( fgets( fbuf, MAX_STR, fp ) == 0 ) goto aio_read_error;
  501.         sscanf( fbuf,
  502.         "! number of pixels across = %ld, number of pixels down = %ld",
  503.                  &n_across, &n_down );
  504.  
  505.         if ( n_across < N_ACR_MIN || n_across > N_ACR_MAX ||
  506.              n_down   < N_DWN_MIN || n_down   > N_DWN_MAX ) {
  507.           PutStr( "Unexpected values in file\n" );
  508.           goto aio_return;
  509.         }
  510.       }
  511.       n_inputs = n_across * n_down;     /* # PEs in input buffer */
  512.  
  513.      n_patterns = FillPosArr(  ); /* Fill Position array */
  514.      curr_pattern = n_patterns;  /* End of file */
  515.       ReadFData( 0 );                   /* Special eof case */
  516.  
  517.  
  518.       /* Set up grid window and grid */
  519.       ip_grid.gr_data = fdata;
  520.       ip_grid.gr_key = 1;
  521.       ip_grid.gr_flag = 0;
  522.       ip_grid.gr_xoff = ip_grid.gr_yoff = 0;
  523.       ip_grid.gr_nx = n_across;
  524.       ip_grid.gr_ny = n_down;
  525.       ip_grid.gr_pxx = 16 - ( n_across + n_down ) / 4;
  526.       ip_grid.gr_pxy = ip_grid.gr_pxx;
  527.  
  528.       wxstrt[0] = ( xsize - (ip_grid.gr_nx * (ip_grid.gr_pxx+1) + 1) ) / 2 ;
  529.       wystrt[0] = ( ysize - (ip_grid.gr_ny * (ip_grid.gr_pxy+1) + 1) ) / 2 ;
  530.       wxend[0] = wxstrt[0] + ip_grid.gr_nx * (ip_grid.gr_pxx+1);
  531.       wyend[0] = wystrt[0] + ip_grid.gr_ny * (ip_grid.gr_pxy+1);
  532.       ug_window( ip_grid.gr_key, ip_grid.gr_color[GR_OFF],
  533.                  wxstrt[0], wystrt[0], wxend[0], wyend[0] );
  534.       DispGrid( &ip_grid );
  535.       DispPattern( &ip_grid );
  536.  
  537.       /* Set up menu and menu window */
  538.       AIOMenu.key = 2;
  539.       wxstrt[1] = ( xsize - AIOMenu.x1 ) / 2;
  540.       wxend[1] = wxstrt[1] + AIOMenu.x1 + 2;
  541.       wystrt[1] = ( wystrt[0] - AIOMenu.y1 ) / 2;
  542.       wyend[1] = wystrt[1] + AIOMenu.y1 + 2;
  543.       ug_window( AIOMenu.key, ip_grid.gr_color[GR_OFF],
  544.                  wxstrt[1], wystrt[1], wxend[1], wyend[1] );
  545.       DispGMenu( &AIOMenu );
  546.  
  547.       for ( ; ; ) {
  548.         while ( ( gmip=LookGMenu(&AIOMenu,&button) ) != (GMENU_ITEM *) 0 ) {
  549.           switch( gmip->code ) {
  550.             case CR_SCROLL:
  551.               if ( button == MBUT_LEFT )  {             /* Scroll down */
  552.                 curr_pattern++;
  553.                 if ( ReadFData( 0 ) < 0 ) goto aio_return;
  554.                 DispPattern( &ip_grid );
  555.               }
  556.               if ( button == MBUT_RIGHT ) {             /* Scroll up */
  557.                 curr_pattern--;
  558.                 if ( ReadFData( 0 ) < 0 ) goto aio_return;
  559.                 DispPattern( &ip_grid );
  560.               }
  561.               break;
  562.             case CR_SEEK:
  563.               if ( button == MBUT_LEFT ) {      /* Start of file data */
  564.                 curr_pattern = 0;
  565.                 if ( ReadFData( 0 ) < 0 ) goto aio_return;
  566.                 DispPattern( &ip_grid );
  567.               }
  568.               if ( button == MBUT_RIGHT ) {             /* End of file data */
  569.                 curr_pattern = n_patterns;
  570.                 if ( ReadFData( 0 ) < 0 ) goto aio_return;
  571.                 DispPattern( &ip_grid );
  572.               }
  573.               break;
  574.             case CR_ENTER:
  575.               if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
  576.                 WriteFData( 0 );
  577.                 ReadFData( 0 );
  578.                 DispPattern( &ip_grid );
  579.               }
  580.               break;
  581.             case CR_QUIT:
  582.               if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
  583.     ret_val = UIO_ERROR;
  584.                 goto aio_return;
  585.               }
  586.               break;
  587.           }
  588.  
  589.           /* If button was pressed, wait for it to be released */
  590.           while ( button != 0 )
  591.             ug_mouse( &key, &xp, &yp, &button );
  592.         }
  593.         Sketch( &ip_grid );
  594.       }
  595.  
  596. aio_read_error:
  597.       sprintf( sbuf, "Error reading file <%s>\n", filename );
  598.       PutStr( sbuf );
  599.  
  600. aio_return:
  601.       if ( fp != (FILE *)0 ) fclose( fp );
  602.       fp = (FILE *)0;
  603.       ug_windel( 1 );
  604.       ug_windel( 2 );
  605.  
  606.       return(ret_val);
  607. }
  608.  
  609. /* */
  610. /*****************************************************************************/
  611. /*                                                                           */
  612. /*  Functions necessary for handling a learning session.                     */
  613. /*                                                                           */
  614. /*****************************************************************************/
  615.  
  616. /* UIO_Learn_Start  function to initiate learning
  617.  ************************************************************************
  618. */
  619. NINT UIO_Learn_Start()
  620. {
  621.     NINT ret_val = UIO_OK;
  622.     NINT wx, wy;                               /* work indices */
  623.     TEXT sbuf[60], *sp;                        /* work string and pointer */
  624.  
  625.       abortio = 0;                              /* abort flag */
  626.       autoip = 0;                               /* Assume hand input */
  627.       wrstepf = 0;                              /* write step flag */
  628.       if ( fp == (FILE *)0 ) {                  /* Not yet opened */
  629.         sprintf( sbuf,
  630.                  "Enter name of pattern file ( default: %s ):", filenroot );
  631.         PutStr( sbuf );
  632.         sp = GetStr( );
  633.         PutStr("\n");
  634.         if ( strcmp( sp, "" ) != 0 ) strncpy( filenroot, sp, 9 );
  635.         strcpy( filename, filenroot );
  636.         strcat( filename, ".nna" );
  637.         if ( ( fp = fopen( filename, "r" ) ) == (FILE *)0 ) {
  638.           sprintf( sbuf, "Cannot open file <%s>; learn aborted\n", filename );
  639.           PutStr( sbuf );
  640.           abortio = 1;
  641.           goto lrns_return;
  642.         }
  643.         shufflex = 0;
  644.         /* Initialize shuffle array */
  645.         for ( wx = 0; wx < MAX_N_PATTERNS; wx++ )
  646.           shuffle_array[ wx ] = wx;
  647.  
  648.         n_patterns = FillPosArr(  );            /* Fill Position array */
  649.         curr_pattern = 0;                       /* Start of of file */
  650.       }
  651.  
  652.       fseek( fp, 0l, 0 );                       /* rewind */
  653.  
  654.       if ( fgets( fbuf, MAX_STR, fp ) == 0 ) {
  655.         PutStr( "Read error; learn aborted\n" );
  656.         abortio = 1;
  657.         goto lrns_return;
  658.       }
  659.       sscanf( fbuf,
  660.         "! number of pixels across = %ld, number of pixels down = %ld",
  661.                  &n_across, &n_down );
  662.       if ( n_across < N_ACR_MIN || n_across > N_ACR_MAX ||
  663.            n_down   < N_DWN_MIN || n_down   > N_DWN_MAX ) {
  664.         PutStr( "Unexpected values in file; learn aborted\n" );
  665.         abortio = 1;
  666.         goto lrns_return;
  667.       }
  668.  
  669.       n_inputs = n_across * n_down;     /* # PEs in input buffer */
  670.       ug_rdnetinf( &nlayp, &ninp, &noutp, <ype, &csp, &netnp );
  671.      if ( n_inputs != ninp ) {
  672.         PutStr( "Data incompatible with network; learn aborted\n" );
  673.         abortio = 1;
  674.         goto lrns_return;
  675.       }
  676.  
  677.       /* Initialize grids and associated window */
  678.       ip_grid.gr_data = fdata;
  679.       f1_grid.gr_data = f1data;
  680.       ip_grid.gr_key = f1_grid.gr_key = 1;
  681.       ip_grid.gr_flag = f1_grid.gr_flag = 0;
  682.       ip_grid.gr_nx = f1_grid.gr_nx = n_across;
  683.       ip_grid.gr_ny = f1_grid.gr_ny =n_down;
  684.       ip_grid.gr_pxx = f1_grid.gr_pxx = 16 - ( n_across / 2 );
  685.       ip_grid.gr_pxy = f1_grid.gr_pxy = ip_grid.gr_pxx;
  686.       ip_grid.gr_xoff = 3 * chrx;
  687.       ip_grid.gr_yoff = f1_grid.gr_yoff = 4 * chry;
  688.       f1_grid.gr_xoff = ip_grid.gr_xoff + 22 * chrx;
  689.  
  690.       wx = 50 * chrx;
  691.       wy = 5 * chry + ip_grid.gr_ny * ( ip_grid.gr_pxy + 1 ) + 1;
  692.       wxstrt[0] = ( xsize - wx ) / 2 ;
  693.       wystrt[0] = ( ysize - wy ) / 2 ;
  694.       wxend[0] = wxstrt[0] + wx;
  695.       wyend[0] = wystrt[0] + wy;
  696.  
  697.       ug_window( ip_grid.gr_key, ip_grid.gr_color[GR_OFF],
  698.                  wxstrt[0], wystrt[0], wxend[0], wyend[0] );
  699.  
  700.       /* Set up menu and menu window */
  701.       LrnMenu.key = 2;
  702.       wxstrt[1] = ( xsize - LrnMenu.x1 ) / 2;
  703.       wxend[1] = wxstrt[1] + LrnMenu.x1 + 2;
  704.       wystrt[1] = ( wystrt[0] - LrnMenu.y1 ) / 2;
  705.       wyend[1] = wystrt[1] + LrnMenu.y1 + 2;
  706.       ug_window( LrnMenu.key, gm_intcolor,
  707.                  wxstrt[1], wystrt[1], wxend[1], wyend[1] );
  708.  
  709. lrns_return:
  710.       if ( abortio ) {
  711.         if ( fp != (FILE *)0 ) fclose( fp );
  712.         fp = (FILE *)0;
  713.         ug_windel( 1 );
  714.         ug_windel( 2 );
  715.   ret_val = UIO_ERROR;
  716.       }
  717.  
  718.       return(ret_val);
  719. }
  720.  
  721. /* */
  722. /* UIO_Learn_Input  function to read training data
  723.  ************************************************************************
  724. */
  725. NINT UIO_Learn_Input(LayN, nPEs, Datap)
  726. NINT  LayN;
  727. NINT  nPEs;
  728. SREAL *Datap;
  729. {
  730.     NINT ret_val = UIO_OK;
  731.     NINT key, xp, yp, button;                  /* mouse interface */
  732.     TEXT sbuf[60], *sp;                        /* work string and pointer */
  733.     GMENU_ITEM  *gmip;
  734.  
  735.  
  736.      if ( abortio ) goto lrnin_return;
  737.       /* Display grids */
  738.       if ( ReadFData( 0 ) < 0 ) goto lrnin_return;
  739.       ug_winclr( ip_grid.gr_key );
  740.       DispGrid( &ip_grid );
  741.       DispGrid( &f1_grid );
  742.       ug_puts( ip_grid.gr_key, ip_grid.gr_color[GR_ON], 0,
  743.                3 * chrx, 3 * chry, ip_text, 0 );
  744.       ug_puts( ip_grid.gr_key, ip_grid.gr_color[GR_ON], 0,
  745.                25 * chrx, 3 * chry, f1_text, 0 );
  746.       if ( !autoip ) {
  747.         ug_winclr( LrnMenu.key );
  748.         DispGMenu( &LrnMenu );
  749.         DispPattern( &ip_grid );
  750.         for ( ; ; ) {
  751.           while ( ( gmip=LookGMenu(&LrnMenu,&button) ) != (GMENU_ITEM *) 0 ) {
  752.             switch( gmip->code ) {
  753.               case CR_SCROLL:
  754.                 if ( button == MBUT_LEFT )  {           /* Scroll down */
  755.                   curr_pattern++;
  756.                   if ( ReadFData( 0 ) < 0 ) goto lrnin_return;
  757.                   DispPattern( &ip_grid );
  758.                 }
  759.                 if ( button == MBUT_RIGHT ) {           /* Scroll up */
  760.                   curr_pattern--;
  761.                   if ( ReadFData( 0 ) < 0 ) goto lrnin_return;
  762.                   DispPattern( &ip_grid );
  763.                 }
  764.                 break;
  765.               case CR_SEEK:
  766.                 if ( button == MBUT_LEFT ) {    /* Start of file data */
  767.                   curr_pattern = 0;
  768.                   if ( ReadFData( 0 ) < 0 ) goto lrnin_return;
  769.                   DispPattern( &ip_grid );
  770.                 }
  771.                 if ( button == MBUT_RIGHT ) {           /* End of file data */
  772.                   curr_pattern = n_patterns;
  773.                   if ( ReadFData( 0 ) < 0 ) goto lrnin_return;
  774.                   DispPattern( &ip_grid );
  775.                 }
  776.                 break;
  777.  
  778.               case CR_ENTER:
  779.                 if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
  780.                   memcpy( Datap,
  781.         fdata, n_inputs * sizeof( float ) );
  782.                   curr_pattern++;
  783.                   goto lrnin_return;
  784.                 }
  785.                 break;
  786.               case CR_QUIT:
  787.                 if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
  788.      ret_val = UIO_ERROR;
  789.                   goto lrnin_return;
  790.                 }
  791.                 break;
  792.               case CR_AUTO:
  793.                 if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
  794.                   autoip = 1;
  795.                   goto auto_lrn;
  796.                 }
  797.                 break;
  798.             }
  799.             /* If button was pressed, wait for it to be released */
  800.             while ( button != 0 )
  801.               ug_mouse( &key, &xp, &yp, &button );
  802.           }
  803.           Sketch( &ip_grid );
  804.         }
  805.       } else {
  806. auto_lrn:
  807.         if ( shufflex == 0 ) Shuffle( n_patterns );
  808.         curr_pattern = shuffle_array[ shufflex++ ];
  809.         if ( ReadFData( 0 ) < 0 ) {
  810.           PutStr( "Error reading file; learn aborted\n" );
  811.           abortio = 1;
  812.           goto lrnin_return;
  813.         }
  814.         if ( shufflex >= n_patterns ) shufflex = 0;
  815.         memcpy( Datap,
  816.     fdata, n_inputs * sizeof( float ) );
  817.      }
  818.  
  819. lrnin_return:
  820.       if ( abortio ) {
  821.         if ( fp != (FILE *)0 ) fclose( fp );
  822.         fp = (FILE *)0;
  823.         ug_windel( 1 );
  824.         ug_windel( 2 );
  825.   ret_val = UIO_ERROR;
  826.       }
  827.  
  828.       return(ret_val);
  829. }
  830.  
  831.  
  832. /* FUNCTION */
  833. NINT UIO_Learn_Output(LayN, nPEs, Datap)
  834. NINT  LayN;
  835. NINT  nPEs;
  836. SREAL *Datap;
  837. {
  838.   NINT ret_val = UIO_OK;
  839.  
  840.   /* USER TO PLACE CODE HERE */
  841.  
  842.         /* IODATA points to an empty array of IOCOUNT values.  The
  843.            elements of the array will become the desired outputs for
  844.            training purposes.  These desired outputs correspond to
  845.            the most recent "RQ_LEARNIN" request.
  846.         */
  847.  
  848.  
  849.   return(ret_val);
  850. }
  851.  
  852. /* */
  853. /* UIO_Learn_Result function to write results from learning
  854.  ************************************************************************
  855. */
  856. NINT UIO_Learn_Result(LayN, nPEs, Datap)
  857. NINT  LayN;
  858. NINT  nPEs;
  859. SREAL *Datap;
  860. {
  861.     NINT ret_val = UIO_OK;
  862.     NINT  key, xp, yp, button;                  /* mouse interface */
  863.  
  864.         if ( abortio ) goto write_return;
  865.         if ( autoip ) {
  866.         } else {
  867.           for ( ; ; ) {
  868.             ug_mouse( &key, &xp, &yp, &button ); /* wait for mouse */
  869.             if (button == MBUT_LEFT || button == MBUT_RIGHT) break;
  870.           }
  871.         }
  872.  
  873. write_return:
  874.       if ( abortio ) {
  875.         if ( fp != (FILE *)0 ) fclose( fp );
  876.         fp = (FILE *)0;
  877.         ug_windel( 1 );
  878.         ug_windel( 2 );
  879.   ret_val = UIO_ERROR;
  880.       }
  881.  
  882.       return(ret_val);
  883. }
  884.  
  885.  
  886. /* FUNCTION */
  887. NINT UIO_Learn_End()
  888. {
  889.   NINT ret_val = UIO_OK;
  890.  
  891.   /* USER TO PLACE CODE HERE */
  892.  
  893.   return(ret_val);
  894. }
  895.  
  896. /* */
  897. /*****************************************************************************/
  898. /*                                                                           */
  899. /*  Functions necessary for handling a recall or testing session.            */
  900. /*                                                                           */
  901. /*****************************************************************************/
  902.  
  903. /* FUNCTION */
  904. NINT UIO_Recall_Start()
  905. {
  906.     NINT ret_val = UIO_OK;
  907.     NINT key, xp, yp, button;                  /* mouse interface */
  908.     NINT wx, wy;                               /* work indices */
  909.     TEXT sbuf[60], *sp;                        /* work string and pointer */
  910.     GMENU_ITEM  *gmip;
  911.  
  912.       abortio = 0;                              /* abort flag */
  913.       autoip = 0;                               /* Assume hand input */
  914.       wrstepf = 0;                              /* write step flag */
  915.       if ( fp == (FILE *)0 ) {                  /* Not yet opened */
  916.         sprintf( sbuf,
  917.                  "Enter name of pattern file ( default: %s ):", filenroot );
  918.         PutStr( sbuf );
  919.         sp = GetStr( );
  920.         PutStr("\n");
  921.         if ( strcmp( sp, "" ) != 0 ) strncpy( filenroot, sp, 9 );
  922.         strcpy( filename, filenroot );
  923.         strcat( filename, ".nna" );
  924.         if ( ( fp = fopen( filename, "r" ) ) == (FILE *)0 ) {
  925.           sprintf( sbuf, "Cannot open file <%s>; learn aborted\n", filename );
  926.           PutStr( sbuf );
  927.           abortio = 1;
  928.           goto lrns_return;
  929.         }
  930.         shufflex = 0;
  931.         /* Initialize shuffle array */
  932.         for ( wx = 0; wx < MAX_N_PATTERNS; wx++ )
  933.           shuffle_array[ wx ] = wx;
  934.  
  935.         n_patterns = FillPosArr(  );            /* Fill Position array */
  936.         curr_pattern = 0;                       /* Start of of file */
  937.       }
  938.  
  939.       fseek( fp, 0l, 0 );                       /* rewind */
  940.  
  941.       if ( fgets( fbuf, MAX_STR, fp ) == 0 ) {
  942.         PutStr( "Read error; learn aborted\n" );
  943.         abortio = 1;
  944.         goto lrns_return;
  945.       }
  946.       sscanf( fbuf,
  947.         "! number of pixels across = %ld, number of pixels down = %ld",
  948.                  &n_across, &n_down );
  949.       if ( n_across < N_ACR_MIN || n_across > N_ACR_MAX ||
  950.            n_down   < N_DWN_MIN || n_down   > N_DWN_MAX ) {
  951.         PutStr( "Unexpected values in file; learn aborted\n" );
  952.         abortio = 1;
  953.         goto lrns_return;
  954.       }
  955.  
  956.       n_inputs = n_across * n_down;     /* # PEs in input buffer */
  957.       ug_rdnetinf( &nlayp, &ninp, &noutp, <ype, &csp, &netnp );
  958.      if ( n_inputs != ninp ) {
  959.         PutStr( "Data incompatible with network; learn aborted\n" );
  960.         abortio = 1;
  961.         goto lrns_return;
  962.       }
  963.  
  964.       /* Initialize grids and associated window */
  965.       ip_grid.gr_data = fdata;
  966.       f1_grid.gr_data = f1data;
  967.       ip_grid.gr_key = f1_grid.gr_key = 1;
  968.       ip_grid.gr_flag = f1_grid.gr_flag = 0;
  969.       ip_grid.gr_nx = f1_grid.gr_nx = n_across;
  970.       ip_grid.gr_ny = f1_grid.gr_ny =n_down;
  971.       ip_grid.gr_pxx = f1_grid.gr_pxx = 16 - ( n_across / 2 );
  972.       ip_grid.gr_pxy = f1_grid.gr_pxy = ip_grid.gr_pxx;
  973.       ip_grid.gr_xoff = 3 * chrx;
  974.       ip_grid.gr_yoff = f1_grid.gr_yoff = 4 * chry;
  975.       f1_grid.gr_xoff = ip_grid.gr_xoff + 22 * chrx;
  976.  
  977.       wx = 50 * chrx;
  978.       wy = 5 * chry + ip_grid.gr_ny * ( ip_grid.gr_pxy + 1 ) + 1;
  979.       wxstrt[0] = ( xsize - wx ) / 2 ;
  980.       wystrt[0] = ( ysize - wy ) / 2 ;
  981.       wxend[0] = wxstrt[0] + wx;
  982.       wyend[0] = wystrt[0] + wy;
  983.  
  984.       ug_window( ip_grid.gr_key, ip_grid.gr_color[GR_OFF],
  985.                  wxstrt[0], wystrt[0], wxend[0], wyend[0] );
  986.  
  987.       /* Set up menu and menu window */
  988.       LrnMenu.key = 2;
  989.       wxstrt[1] = ( xsize - LrnMenu.x1 ) / 2;
  990.       wxend[1] = wxstrt[1] + LrnMenu.x1 + 2;
  991.       wystrt[1] = ( wystrt[0] - LrnMenu.y1 ) / 2;
  992.       wyend[1] = wystrt[1] + LrnMenu.y1 + 2;
  993.       ug_window( LrnMenu.key, gm_intcolor,
  994.                  wxstrt[1], wystrt[1], wxend[1], wyend[1] );
  995.  
  996. lrns_return:
  997.       if ( abortio ) {
  998.         if ( fp != (FILE *)0 ) fclose( fp );
  999.         fp = (FILE *)0;
  1000.         ug_windel( 1 );
  1001.         ug_windel( 2 );
  1002.         ret_val = UIO_ERROR;
  1003.   }
  1004.       return(ret_val);
  1005. }
  1006.  
  1007.  
  1008. /* FUNCTION */
  1009. NINT UIO_Read(LayN, nPEs, Datap)
  1010. NINT  LayN;
  1011. NINT  nPEs;
  1012. SREAL *Datap;
  1013. {
  1014.     NINT ret_val = UIO_OK;
  1015.     NINT key, xp, yp, button;                  /* mouse interface */
  1016.     GMENU_ITEM  *gmip;
  1017.  
  1018.      if ( abortio ) goto lrnin_return;
  1019.       /* Display grids */
  1020.       if ( ReadFData( 0 ) < 0 ) goto lrnin_return;
  1021.       ug_winclr( ip_grid.gr_key );
  1022.       DispGrid( &ip_grid );
  1023.       DispGrid( &f1_grid );
  1024.       ug_puts( ip_grid.gr_key, ip_grid.gr_color[GR_ON], 0,
  1025.                3 * chrx, 3 * chry, ip_text, 0 );
  1026.       ug_puts( ip_grid.gr_key, ip_grid.gr_color[GR_ON], 0,
  1027.                25 * chrx, 3 * chry, f1_text, 0 );
  1028.       if ( !autoip ) {
  1029.         ug_winclr( LrnMenu.key );
  1030.         DispGMenu( &LrnMenu );
  1031.         DispPattern( &ip_grid );
  1032.         for ( ; ; ) {
  1033.           while ( ( gmip=LookGMenu(&LrnMenu,&button) ) != (GMENU_ITEM *) 0 ) {
  1034.             switch( gmip->code ) {
  1035.               case CR_SCROLL:
  1036.                 if ( button == MBUT_LEFT )  {           /* Scroll down */
  1037.                   curr_pattern++;
  1038.                   if ( ReadFData( 0 ) < 0 ) goto lrnin_return;
  1039.                   DispPattern( &ip_grid );
  1040.                 }
  1041.                 if ( button == MBUT_RIGHT ) {           /* Scroll up */
  1042.                   curr_pattern--;
  1043.                   if ( ReadFData( 0 ) < 0 ) goto lrnin_return;
  1044.                   DispPattern( &ip_grid );
  1045.                 }
  1046.                 break;
  1047.               case CR_SEEK:
  1048.                 if ( button == MBUT_LEFT ) {    /* Start of file data */
  1049.                   curr_pattern = 0;
  1050.                   if ( ReadFData( 0 ) < 0 ) goto lrnin_return;
  1051.                   DispPattern( &ip_grid );
  1052.                 }
  1053.                 if ( button == MBUT_RIGHT ) {           /* End of file data */
  1054.                   curr_pattern = n_patterns;
  1055.                   if ( ReadFData( 0 ) < 0 ) goto lrnin_return;
  1056.                   DispPattern( &ip_grid );
  1057.                 }
  1058.                 break;
  1059.               case CR_ENTER:
  1060.                 if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
  1061.             memcpy( Datap,
  1062.         fdata, n_inputs * sizeof( float ) );
  1063.                   curr_pattern++;
  1064.                   goto lrnin_return;
  1065.                 }
  1066.                 break;
  1067.               case CR_QUIT:
  1068.                 if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
  1069.       ret_val = UIO_ERROR;
  1070.                   goto lrnin_return;
  1071.                 }
  1072.                 break;
  1073.               case CR_AUTO:
  1074.                 if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
  1075.                   autoip = 1;
  1076.                   goto auto_lrn;
  1077.                 }
  1078.                 break;
  1079.             }
  1080.             /* If button was pressed, wait for it to be released */
  1081.             while ( button != 0 )
  1082.               ug_mouse( &key, &xp, &yp, &button );
  1083.           }
  1084.           Sketch( &ip_grid );
  1085.         }
  1086.       } else {
  1087. auto_lrn:
  1088.         if ( shufflex == 0 ) Shuffle( n_patterns );
  1089.         curr_pattern = shuffle_array[ shufflex++ ];
  1090.         if ( ReadFData( 0 ) < 0 ) {
  1091.           PutStr( "Error reading file; learn aborted\n" );
  1092.           abortio = 1;
  1093.           goto lrnin_return;
  1094.         }
  1095.         if ( shufflex >= n_patterns ) shufflex = 0;
  1096.         memcpy( Datap,
  1097.     fdata, n_inputs * sizeof( float ) );
  1098.      }
  1099.  
  1100. lrnin_return:
  1101.       if ( abortio ) {
  1102.         if ( fp != (FILE *)0 ) fclose( fp );
  1103.         fp = (FILE *)0;
  1104.         ug_windel( 1 );
  1105.         ug_windel( 2 );
  1106.   ret_val = UIO_ERROR;
  1107.       }
  1108.  
  1109.       return(ret_val);
  1110. }
  1111.  
  1112. /* */
  1113. /* UIO_Write    function to write out results
  1114.  ************************************************************************
  1115. */
  1116. NINT UIO_Write(LayN, nPEs, Datap)
  1117. NINT  LayN;
  1118. NINT  nPEs;
  1119. SREAL *Datap;
  1120. {
  1121.     NINT ret_val = UIO_OK;
  1122.     NINT key, xp, yp, button;                  /* mouse interface */
  1123.  
  1124.         if ( abortio ) goto write_return;
  1125.         if ( autoip ) {
  1126.         } else {
  1127.           for ( ; ; ) {
  1128.             ug_mouse( &key, &xp, &yp, &button ); /* wait for mouse */
  1129.             if (button == MBUT_LEFT || button == MBUT_RIGHT) break;
  1130.           }
  1131.         }
  1132.  
  1133. write_return:
  1134.       if ( abortio ) {
  1135.         if ( fp != (FILE *)0 ) fclose( fp );
  1136.         fp = (FILE *)0;
  1137.         ug_windel( 1 );
  1138.         ug_windel( 2 );
  1139.   ret_val = UIO_ERROR;
  1140.       }
  1141.  
  1142.       return(ret_val);
  1143. }
  1144.  
  1145. /* */
  1146. /* UIO_Write_Step function to write interim results
  1147.  ************************************************************************
  1148. */
  1149. NINT UIO_Write_Step(LayN, nPEs, Datap)
  1150. NINT  LayN;
  1151. NINT  nPEs;
  1152. SREAL *Datap;
  1153. {
  1154.   NINT ret_val = UIO_OK;
  1155.  
  1156.       /* Alternates between pre-resonant and post-resonant F1 activity */
  1157.  
  1158.       if ( abortio ) goto wrstep_return;
  1159.  
  1160.       if ( wrstepf ) {
  1161.         memcpy( f1_grid.gr_data, Datap,
  1162.     n_inputs * sizeof( float ) );
  1163.         DispPattern( &f1_grid );
  1164.         wrstepf = 0;
  1165.       } else {
  1166.         memcpy( f1_grid.gr_data, Datap,
  1167.     n_inputs * sizeof( float ) );
  1168.         DispPattern( &ip_grid );
  1169.         wrstepf = 1;
  1170.       }
  1171.        
  1172. wrstep_return:
  1173.       if ( abortio ) {
  1174.         if ( fp != (FILE *)0 ) fclose( fp );
  1175.         fp = (FILE *)0;
  1176.         ug_windel( 1 );
  1177.         ug_windel( 2 );
  1178.         ret_val = UIO_ERROR;
  1179.       }
  1180.  
  1181.   return(ret_val);
  1182. }
  1183.  
  1184.  
  1185. /* */
  1186. /* UIO_Recall_Test  function to read desired output for recall test
  1187.  ************************************************************************
  1188. */
  1189. NINT UIO_Recall_Test(LayN, nPEs, Datap)
  1190. NINT  LayN;
  1191. NINT  nPEs;
  1192. SREAL *Datap;
  1193. {
  1194.   NINT ret_val = UIO_OK;
  1195.  
  1196.  
  1197.         /* IODATA points to an empty array of IOCOUNT values.  The
  1198.            elements of the array will become the desired outputs for
  1199.            recall purposes.  This request is only made during a
  1200.            Execute Network/Recall Test.
  1201.         */
  1202.  
  1203.   return(ret_val);
  1204. }
  1205.  
  1206. /* */
  1207. /* UIO_Recall_End
  1208.  ************************************************************************
  1209. */
  1210. NINT UIO_Recall_End()
  1211. {
  1212.   NINT ret_val = UIO_OK;
  1213.  
  1214.   /* USER TO PLACE CODE HERE */
  1215.  
  1216.   return(ret_val);
  1217. }
  1218.  
  1219.  
  1220. /* */
  1221. /*****************************************************************************/
  1222. /*                                                                           */
  1223. /*  Other miscelaneous functions.                                            */
  1224. /*                                                                           */
  1225. /*****************************************************************************/
  1226.  
  1227. /* FUNCTION */
  1228. NINT UIO_Instrument(Instrument_id, nDataElems, DataElemp)
  1229. NINT  Instrument_id;
  1230. NINT  nDataElems;
  1231. SREAL *DataElemp;
  1232. {
  1233.   NINT ret_val = UIO_OK;
  1234.  
  1235.  
  1236.   /* USER TO PLACE CODE HERE */
  1237.  
  1238.   return(ret_val);
  1239. }
  1240.  
  1241.  
  1242. /* FUNCTION */
  1243. NINT UIO_Rewind()
  1244. {
  1245.   NINT ret_val = UIO_OK;
  1246.  
  1247.  
  1248.   /* USER TO PLACE CODE HERE */
  1249.  
  1250.       if ( fp != (FILE *)0 ) fseek( fp, 0l, 0 );
  1251.  
  1252.   return(ret_val);
  1253. }
  1254.  
  1255.  
  1256. /* */
  1257. /* FUNCTION */
  1258. NINT UIO_Explain(LayN, nPEs, Datap)
  1259. NINT  LayN;
  1260. NINT  nPEs;
  1261. SREAL *Datap;
  1262. {
  1263.   NINT ret_val = UIO_OK;
  1264.  
  1265.  
  1266.   /* USER TO PLACE CODE HERE */
  1267.  
  1268.   return(ret_val);
  1269. }
  1270.