home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e065 / 2.ddi / UIO_CMDS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  18.6 KB  |  679 lines

  1. /*******************************************************************/
  2. /*                                                                 */
  3. /*    uio_cmds.c - User IO program template showing format of all  */
  4. /*                 all commands from NeuralWorks. A User program   */
  5. /*                 must provide all these functions                */
  6. /*                                                                 */
  7. /*    Documentation: TR Young         December 27, 1990            */
  8. /*    Author: John C. Fairman           August 31, 1990            */
  9. /*    Copyright 1990 by NeuralWare Inc.                            */
  10. /*                                                                 */
  11. /*    $Author   :  $                                               */
  12. /*    $Date     :  $                                               */
  13. /*    $Source   :  $                                               */
  14. /*    $Revision :  $                                               */
  15. /*    $Log      :  $                                               */
  16. /*                                                                 */
  17. /*******************************************************************/
  18. /*
  19.  *
  20.  * Functions necessary for handling the User I/O package itself:
  21.  *
  22.  *  UIO_Init()
  23.  *  UIO_Term()
  24.  *  UIO_Attention()
  25.  *
  26.  *
  27.  * Functions necessary for handling a learning session:
  28.  *
  29.  *  UIO_Learn_Start()
  30.  *  UIO_Learn_Input()
  31.  *  UIO_Learn_Output()
  32.  *  UIO_Learn_Result()
  33.  *  UIO_Learn_End()
  34.  *
  35.  *
  36.  * Functions necessary for handling a recall or testing session:
  37.  *
  38.  *  UIO_Recall_Start()
  39.  *  UIO_Read()
  40.  *  UIO_Write()
  41.  *  UIO_Write_Step()
  42.  *  UIO_Recall_Test()
  43.  *  UIO_Recall_End()
  44.  *
  45.  *
  46.  * Other miscellaneous functions:
  47.  *
  48.  *  UIO_Instrument()
  49.  *  UIO_Rewind()
  50.  *  UIO_Explain()
  51.  *
  52.  *
  53.  * Note: All these functions must be defined to avoid link errors.
  54.  *       Fill in the ones you need for your UserIO program.
  55.  */
  56.  
  57. /******************************************************************
  58.  * NOTE: Do not include <stdio.h>.  This is dealt with in userutl.h
  59.  * and related files. Some platforms, such as the Macintosh, redefine
  60.  * the stdio functions.
  61.  *
  62.  */
  63.  
  64. #define UIO_SERVER             1
  65. #define SERVER_EMULATOR_FILE   1
  66. #define SKIP_COMPAT_DATA       1
  67. #include "userutl.h"
  68. #include "uio_strc.h"
  69. #include "uio_tran.h"
  70. #include "uio_reqs.pro"
  71. #include "uio_cmds.pro"
  72.  
  73. #ifdef MAC
  74. #include "macuio.redef"
  75. #endif
  76.  
  77. /*******************************************************************/
  78. /*                                                                 */
  79. /* Functions necessary for handling the User I/O package itself.   */
  80. /*                                                                 */
  81. /*******************************************************************/
  82.  
  83. /* function:  UIO_Init.c
  84.  *    Executed once by NWorks at the begining of User IO execution.
  85.  *    Used for function initialization, memory allocation, file openning.
  86.  *
  87.  * arguments: file     = name of the User IO program being executed
  88.  *
  89.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  90.  *    UIO_UPDATE =  1,  continue execution, do update screen
  91.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  92.  */
  93.  
  94. NINT UIO_Init(file)
  95. TEXT *file;
  96. {
  97.   NINT ret_val = UIO_OK;
  98.  
  99.  
  100.   /* USER TO PLACE CODE HERE */
  101.  
  102.   return(ret_val);
  103. }
  104.  
  105.  
  106. /* */
  107. /* function:  UIO_Term()
  108.  *    Executed once by NWorks before loading another User IO program
  109.  *    or whenever deleting the network using either menu selections
  110.  *    or dialog boxes:
  111.  *
  112.  *      IO...||Parameters||USRIO filename selection
  113.  *      File...||Open...||NWorks filename selection
  114.  *      File...||New
  115.  *      File...||Close
  116.  *      File...||Revert to Saved
  117.  *      File...||Quit
  118.  *
  119.  *    Used to release all allocated memory, close any open files, etc.
  120.  *    to clean up after the User IO program execution
  121.  *
  122.  * arguments: process    = integer number assigned to User IO task
  123.  *
  124.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  125.  *    UIO_UPDATE =  1,  continue execution, do update screen
  126.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  127.  */
  128.  
  129. NINT UIO_Term(process)
  130. NINT process;
  131. {
  132.   NINT ret_val = UIO_OK;
  133.  
  134.  
  135.   /* USER TO PLACE CODE HERE */
  136.  
  137.   return(ret_val);
  138. }
  139.  
  140. /* function:  UIO_Attention()
  141.  *    Executed once by NWorks at menu selection:
  142.  *
  143.  *        I/O...||Attention I/O
  144.  *
  145.  *    Used for function initialization,
  146.  *    keyboard input of learn/recall parameters, etc.
  147.  *
  148.  *    Also used for the main body of a User Control program
  149.  *
  150.  * arguments: none
  151.  *
  152.  * return:  UIO_OK     =  0, continue execution, do not update screen
  153.  *    UIO_UPDATE =  1, continue execution, do update screen
  154.  *    UIO_ERROR  = -1, terminate execution, do update screen
  155.  */
  156.  
  157. NINT UIO_Attention()
  158. {
  159.   NINT ret_val = UIO_OK;
  160.  
  161.  
  162.   /* USER TO PLACE CODE HERE */
  163.  
  164.   return(ret_val);
  165. }
  166.  
  167.  
  168. /*******************************************************************/
  169. /*                                                                 */
  170. /*  Functions necessary for handling a learning session.           */
  171. /*                                                                 */
  172. /*******************************************************************/
  173.  
  174. /* function:  UIO_Learn_Start()
  175.  *    Executed by NWorks at the begining of learn exectution
  176.  *    from menu selections:
  177.  *          Run...||Learn...||For nn
  178.  *          Run...||Learn...||One Pass/All
  179.  *          Run...||Learn...||One
  180.  *          Run...||Learn...||Now
  181.  *          Run...||Learn...||Until
  182.  *
  183.  *    Used for function initialization,
  184.  *    keyboard input of learn parameters, etc.
  185.  *
  186.  * arguments: none
  187.  *
  188.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  189.  *    UIO_UPDATE =  1,  continue execution, do update screen
  190.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  191.  */
  192.  
  193. NINT UIO_Learn_Start()
  194. {
  195.   NINT ret_val = UIO_OK;
  196.  
  197.  
  198.   /* USER TO PLACE CODE HERE */
  199.  
  200.   return(ret_val);
  201. }
  202.  
  203.  
  204. /* */
  205. /* function:  UIO_Learn_Input.c
  206.  *    Executed by NWorks during learn execution whenever a 
  207.  *    control strategy instruction:
  208.  *
  209.  *    io  lrnin
  210.  *
  211.  *    is encountered.
  212.  *    Used for reading predictor variable (i.e. Input or X in Y=f(X))
  213.  *    information into network.
  214.  *
  215.  * arguments: LayN     = index assigned to the layer that
  216.  *           will receive the input data;
  217.  *           index is assigned according to relative
  218.  *           (to other layers) screen position
  219.  *
  220.  *    nPEs     = dimension of the input data array
  221.  *
  222.  *    Datap    = pointer to array to be filled with input data
  223.  *
  224.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  225.  *    UIO_UPDATE =  1,  continue execution, do update screen
  226.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  227.  */
  228.  
  229. NINT UIO_Learn_Input(LayN, nPEs, Datap)
  230. NINT  LayN;
  231. NINT  nPEs;
  232. SREAL *Datap;
  233. {
  234.   NINT ret_val = UIO_OK;
  235.  
  236.  
  237.   /* USER TO PLACE CODE HERE */
  238.  
  239.   return(ret_val);
  240. }
  241.  
  242.  
  243. /* function:  UIO_Learn_Output()
  244.  *    Executed by NWorks during learn execution whenever a 
  245.  *    control strategy instruction:
  246.  *
  247.  *    io  lrnout
  248.  *
  249.  *    is encountered.
  250.  *    Used for reading observed response variable
  251.  *    (i.e. desired Output or Y in Y=f(X))
  252.  *    information into network.
  253.  *
  254.  * arguments: LayN     = index assigned to the layer that
  255.  *           will receive the input data;
  256.  *           index is assigned according to relative
  257.  *           (to other layers) screen position
  258.  *
  259.  *    nPEs     = dimension of the input data array
  260.  *
  261.  *    Datap    = pointer to array to be filled with input data
  262.  *
  263.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  264.  *    UIO_UPDATE =  1,  continue execution, do update screen
  265.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  266.  */
  267.  
  268. NINT UIO_Learn_Output(LayN, nPEs, Datap)
  269. NINT  LayN;
  270. NINT  nPEs;
  271. SREAL *Datap;
  272. {
  273.   NINT ret_val = UIO_OK;
  274.  
  275.  
  276.   /* USER TO PLACE CODE HERE */
  277.  
  278.   return(ret_val);
  279. }
  280.  
  281.  
  282. /* */
  283.  
  284. /* function:  UIO_Learn_Result()
  285.  *    Executed by NWorks during learn execution given a
  286.  *    control strategy instruction:
  287.  *
  288.  *    io  lrnrslt
  289.  *
  290.  *    is encountered.
  291.  *    Nworks returns predicted response (i.e. Result or
  292.  *    Y-hat in Y=f(X) where f is the estimated network)
  293.  *    information caluclated by network.
  294.  *
  295.  * arguments: LayN     = index assigned to the layer that
  296.  *           returns the predicted response output;
  297.  *           index is assigned according to relative
  298.  *           (to other layers) screen position
  299.  *
  300.  *    nPEs     = dimension of the output data array
  301.  *
  302.  *    Datap    = pointer to array that contains output data
  303.  *
  304.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  305.  *    UIO_UPDATE =  1,  continue execution, do update screen
  306.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  307.  */
  308.  
  309. NINT UIO_Learn_Result(LayN, nPEs, Datap)
  310. NINT  LayN;
  311. NINT  nPEs;
  312. SREAL *Datap;
  313. {
  314.   NINT ret_val = UIO_OK;
  315.  
  316.  
  317.   /* USER TO PLACE CODE HERE */
  318.  
  319.   return(ret_val);
  320. }
  321.  
  322.  
  323. /* function:  UIO_Learn_End()
  324.  *    Called by NWorks at the end of learn exectution.
  325.  *    Used for summary information of learn procedure.
  326.  *
  327.  * arguments: none
  328.  *
  329.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  330.  *    UIO_UPDATE =  1,  continue execution, do update screen
  331.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  332.  */
  333.  
  334. NINT UIO_Learn_End()
  335. {
  336.   NINT ret_val = UIO_OK;
  337.  
  338.  
  339.   /* USER TO PLACE CODE HERE */
  340.  
  341.   return(ret_val);
  342. }
  343.  
  344.  
  345. /* */
  346. /*******************************************************************/
  347. /*                                                                 */
  348. /*  Functions necessary for handling a recall or testing session.  */
  349. /*                                                                 */
  350. /*******************************************************************/
  351.  
  352. /* function:  UIO_Recall_Start()
  353.  *    Executed once by NWorks at the beginning of recall execution
  354.  *    from menu selections:
  355.  *
  356.  *      Run...||Test...||For nn
  357.  *      Run...||Test...||One Pass/All
  358.  *      Run...||Test...||One
  359.  *      Run...||Recall...||For nn
  360.  *      Run...||Recall...||One Pass/All
  361.  *      Run...||Recall...||One
  362.  *      Run...||Recall...||Now
  363.  *
  364.  *    Used for function initialization,
  365.  *    keyboard input of recall parameters, etc.
  366.  *
  367.  * arguments: none
  368.  *
  369.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  370.  *    UIO_UPDATE =  1,  continue execution, do update screen
  371.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  372.  */
  373.  
  374.  
  375. NINT UIO_Recall_Start()
  376. {
  377.   NINT ret_val = UIO_OK;
  378.  
  379.  
  380.   /* USER TO PLACE CODE HERE */
  381.  
  382.   return(ret_val);
  383. }
  384.  
  385.  
  386. /* function:  UIO_Read()
  387.  *    Executed by NWorks during learn execution whenever a 
  388.  *    control strategy instruction:
  389.  *            read
  390.  *    is encountered.
  391.  *    Used for supplying predictor variable
  392.  *    (i.e. Input or X in Y=f(X))
  393.  *    information to NWorks network.
  394.  *
  395.  * arguments: LayN     = index assigned to the layer that
  396.  *           will receive the input data;
  397.  *           index is assigned according to relative
  398.  *           (to other layers) screen position
  399.  *
  400.  *    nPEs     = dimension of the input data array
  401.  *
  402.  *    Datap    = pointer to array to be filled with input data
  403.  *
  404.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  405.  *    UIO_UPDATE =  1,  continue execution, do update screen
  406.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  407.  */
  408.  
  409. NINT UIO_Read(LayN, nPEs, Datap)
  410. NINT  LayN;
  411. NINT  nPEs;
  412. SREAL *Datap;
  413. {
  414.   NINT ret_val = UIO_OK;
  415.  
  416.  
  417.   /* USER TO PLACE CODE HERE */
  418.  
  419.   return(ret_val);
  420. }
  421.  
  422.  
  423. /* */
  424. /* function:  UIO_Write()
  425.  *    Executed by NWorks during learn execution whenever a 
  426.  *    control strategy instruction:
  427.  *            rcltst
  428.  *    is encountered.
  429.  *    Nworks gives User IO predicted response
  430.  *    (i.e. Actual Output or Y-hat in Y=f(X) where
  431.  *    f is the NWorks estimated network)
  432.  *    information from the NWorks network.
  433.  *
  434.  * arguments: LayN     = index assigned to the layer that
  435.  *           returns the predicted response output;
  436.  *           index is assigned according to relative
  437.  *           (to other layers) screen position
  438.  *
  439.  *    nPEs     = dimension of the output data array
  440.  *
  441.  *    Datap    = pointer to array that contains output data
  442.  *
  443.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  444.  *    UIO_UPDATE =  1,  continue execution, do update screen
  445.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  446.  */
  447.  
  448. NINT UIO_Write(LayN, nPEs, Datap)
  449. NINT  LayN;
  450. NINT  nPEs;
  451. SREAL *Datap;
  452. {
  453.   NINT ret_val = UIO_OK;
  454.  
  455.  
  456.   /* USER TO PLACE CODE HERE */
  457.  
  458.   return(ret_val);
  459. }
  460.  
  461.  
  462. /* function:  UIO_Write_Step()
  463.  *    Executed by NWorks during learn execution whenever a
  464.  *    control strategy instruction:
  465.  *            wrstep
  466.  *    is encountered.
  467.  *    Nworks gives User IO predicted partial response
  468.  *    (i.e. Actual Output or Y-hat in Y=f_j(X) where
  469.  *    f_j is the j is the LayN-th layer of the NWorks
  470.  *    estimated network) at the specified layer using
  471.  *    information supplied to, and caluclated by, the network.
  472.  *
  473.  * arguments: LayN     = index assigned to the layer that
  474.  *           returns the predicted partial response output;
  475.  *           index is assigned according to relative
  476.  *           (to other layers) screen position
  477.  *
  478.  *    nPEs     = dimension of the output data array
  479.  *
  480.  *    Datap    = pointer to array that contains output data
  481.  *
  482.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  483.  *    UIO_UPDATE =  1,  continue execution, do update screen
  484.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  485.  */
  486.  
  487. NINT UIO_Write_Step(LayN, nPEs, Datap)
  488. NINT  LayN;
  489. NINT  nPEs;
  490. SREAL *Datap;
  491. {
  492.   NINT ret_val = UIO_OK;
  493.  
  494.  
  495.   /* USER TO PLACE CODE HERE */
  496.  
  497.   return(ret_val);
  498. }
  499.  
  500.  
  501. /* */
  502. /* function:  UIO_Recall_Test()
  503.  *    Executed by NWorks during learn execution whenever a 
  504.  *    control strategy instruction:
  505.  *            rcltst
  506.  *    is encountered.
  507.  *    Used for supplying observed response variable
  508.  *    (i.e. Test data or Desired Output or Y in Y=f(X))
  509.  *    information to NWorks network.
  510.  *
  511.  * arguments: LayN     = index assigned to the layer that
  512.  *           will receive the input data;
  513.  *           index is assigned according to relative
  514.  *           (to other layers) screen position
  515.  *
  516.  *    nPEs     = dimension of the input data array
  517.  *
  518.  *    Datap    = pointer to array to be filled with input data
  519.  *
  520.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  521.  *    UIO_UPDATE =  1,  continue execution, do update screen
  522.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  523.  */
  524.  
  525. NINT UIO_Recall_Test(LayN, nPEs, Datap)
  526. NINT  LayN;
  527. NINT  nPEs;
  528. SREAL *Datap;
  529. {
  530.   NINT ret_val = UIO_OK;
  531.  
  532.  
  533.   /* USER TO PLACE CODE HERE */
  534.  
  535.   return(ret_val);
  536. }
  537.  
  538. /* function:  UIO_Recall_End()
  539.  *    Executed once by NWorks at the end of recall execution
  540.  *    from menu selection:
  541.  *
  542.  *      Run...||Test...||For nn
  543.  *      Run...||Test...||One Pass/All
  544.  *      Run...||Test...||One
  545.  *      Run...||Recall...||For nn
  546.  *      Run...||Recall...||One Pass/All
  547.  *      Run...||Recall...||One
  548.  *      Run...||Recall...||Now
  549.  *
  550.  *    Used for function initialization,
  551.  *    keyboard input of learn parameters, etc.
  552.  *
  553.  * arguments: none
  554.  *
  555.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  556.  *    UIO_UPDATE =  1,  continue execution, do update screen
  557.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  558.  */
  559.  
  560. NINT UIO_Recall_End()
  561. {
  562.   NINT ret_val = UIO_OK;
  563.  
  564.  
  565.   /* USER TO PLACE CODE HERE */
  566.  
  567.   return(ret_val);
  568. }
  569.  
  570.  
  571. /* */
  572. /*******************************************************************/
  573. /*                                                                 */
  574. /*  Other miscellaneous functions.                                  */
  575. /*                                                                 */
  576. /*******************************************************************/
  577.  
  578. /* function:  UIO_Instrument()
  579.  *    Executed by NWorks whenever an instrument generates
  580.  *    logging output that is sent to UIO
  581.  *    (User IO selected for logging in instrument edit dialog box)
  582.  *
  583.  * arguments: Instrument_id = integer assigned to instrument
  584.  *        that sent logging output
  585.  *    nDataElems    = integer dimension of array
  586.  *        that holds logging output
  587.  *    DataElemp     = floating pointer to array
  588.  *        that holds logging output
  589.  *
  590.  * return:  UIO_OK        =  0,  continue execution, do not update screen
  591.  *    UIO_UPDATE    =  1,  continue execution, do update screen
  592.  *    UIO_ERROR     = -1,  terminate execution, do update screen
  593.  */
  594.  
  595. NINT UIO_Instrument(Instrument_id, nDataElems, DataElemp)
  596. NINT  Instrument_id;
  597. NINT  nDataElems;
  598. SREAL *DataElemp;
  599. {
  600.   NINT ret_val = UIO_OK;
  601.  
  602.  
  603.   /* USER TO PLACE CODE HERE */
  604.  
  605.   return(ret_val);
  606. }
  607.  
  608.  
  609. /* function:  UIO_Rewind()
  610.  *    Executed once by NWorks from menu selections:
  611.  *
  612.  *      I/O...||Rewind Input...||All
  613.  *      I/O...||Rewind Input...||Learn
  614.  *      I/O...||Rewind Input...||Rcl/Test
  615.  *      I/O...||Rewind Input...||Close File(s)
  616.  *
  617.  *    Used for input file rewinding, closing files
  618.  *
  619.  * arguments: none
  620.  *
  621.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  622.  *    UIO_UPDATE =  1,  continue execution, do update screen
  623.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  624.  */
  625.  
  626. NINT UIO_Rewind()
  627. {
  628.   NINT ret_val = UIO_OK;
  629.  
  630.  
  631.   /* USER TO PLACE CODE HERE */
  632.  
  633.   return(ret_val);
  634. }
  635.  
  636.  
  637. /* */
  638. /* function:  UIO_Explain()
  639.  *    Executed by NWorks once for each PE in the Output Layer
  640.  *    during menu selections:
  641.  *
  642.  *      Run...||Explain...||For nn
  643.  *      Run...||Explain...||One Pass/All
  644.  *      Run...||Explain...||One
  645.  *      Run...||Explain...||Now
  646.  *
  647.  *    Allows input of information for the NWorks Explain feature.
  648.  *
  649.  * arguments: LayN     = index assigned to the layer that
  650.  *           will receive the predicted response output;
  651.  *           index is assigned according to relative
  652.  *           (to other layers) screen position
  653.  *
  654.  *    nPEs     = dimension of the input data array, the number
  655.  *           of PE's in the input layer
  656.  *
  657.  *    Datap    = pointer to array that contains input data
  658.  *
  659.  * return:  UIO_OK     =  0,  continue execution, do not update screen
  660.  *    UIO_UPDATE =  1,  continue execution, do update screen
  661.  *    UIO_ERROR  = -1,  terminate execution, do update screen
  662.  */
  663.  
  664. NINT UIO_Explain(LayN, nPEs, Datap)
  665. NINT  LayN;
  666. NINT  nPEs;
  667. SREAL *Datap;
  668. {
  669.   NINT ret_val = UIO_OK;
  670.  
  671.  
  672.   /* USER TO PLACE CODE HERE */
  673.  
  674.   return(ret_val);
  675. }
  676.  
  677.  
  678.  
  679.