home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
NASANETS.ZIP
/
COMPILE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-07
|
18KB
|
434 lines
/*=============================*/
/* NETS */
/* */
/* a product of the AI Section */
/* NASA, Johnson Space Center */
/* */
/* principal author: */
/* Paul Baffes */
/* */
/* contributing authors: */
/* Bryan Dulock */
/* Chris Ortiz */
/*=============================*/
/*
----------------------------------------------------------------------
Code For Production of Delivery Code (Prefix = CC_)
----------------------------------------------------------------------
This code is divided into 3 major sections:
(1) include files
(2) externed functions
(3) subroutines
Each section is further explained below.
----------------------------------------------------------------------
*/
/*
----------------------------------------------------------------------
INCLUDE FILES
----------------------------------------------------------------------
*/
#include "common.h"
#include "weights.h"
#include "layer.h"
#include "net.h"
#include "netio.h"
/*
----------------------------------------------------------------------
EXTERNED FUNCTIONS AND GLOBALS
----------------------------------------------------------------------
Below are the functions defined in other files which are used by the
code here. They are organized by section.
----------------------------------------------------------------------
*/
extern int N_reset_wts();
extern int N_save_wts();
extern void IO_my_get_string();
extern void IO_print();
extern void sys_delete_file();
extern int PA_check_signature();
extern char IO_str[MAX_LINE_SIZE];
/*
======================================================================
ROUTINES IN DELIVER.C
======================================================================
The routines in this file are grouped below by function. Each routine
is prefixed by the string "CC_" indicating that it is defined in the
"deliver.c" file. The types returned by the routines are also shown
so that cross checking is more easily done between these functions
and the other files which intern them.
Type Returned Routine
------------- -------
CREATION ROUTINES
void CC_create_delivery
void CC_setup_header
void CC_create_initialize
void CC_create_prop
void CC_create_cleanup
void CC_create_main
======================================================================
*/
void CC_create_delivery(ptr_net, net_file, wts_file)
Net *ptr_net;
char *net_file, *wts_file;
/*
----------------------------------------------------------------------
Using the network as a guide, this routine creates a deliverable
file which is used simply to execute the network.
----------------------------------------------------------------------
*/
BEGIN
FILE *fp;
void CC_setup_header(), CC_create_initialize(), CC_create_prop(),
CC_create_cleanup(), CC_create_main(), CC_set_name();
char cc_file[MAX_WORD_SIZE], net_name[MAX_WORD_SIZE];
/*-----------------------------------------------------*/
/* if the weights file is not in portable format, quit */
/*-----------------------------------------------------*/
if (PA_check_signature(wts_file, PORTABLE_FORMAT) == ERROR)
return;
/*-------------------------------------*/
/* first, prompt for delivery file and */
/* check that the file can be opened */
/*-------------------------------------*/
sprintf(IO_str, "\n Enter name of delivery file: ");
IO_print(0);
IO_my_get_string(cc_file);
while (cc_file[0] == ENDSTRING) BEGIN
sprintf(IO_str, "\n try again: ");
IO_print(0);
IO_my_get_string(cc_file);
ENDWHILE
if( (fp = fopen(cc_file, "wt")) == NULL) BEGIN
sprintf(IO_str, "\n*** can't open %s file ***\n", cc_file);
IO_print(0);
return;
ENDIF
/*------------------------------------*/
/* once the prompting is done, we can */
/* begin. First,though, save off the */
/* current network weights since they */
/* will be trashed in the process of */
/* making the delivery file. */
/*------------------------------------*/
N_save_wts(ptr_net, "temp.wts", FAST_FORMAT);
/*---------------------------------------------*/
/* Next, check the weights to see that they */
/* are compatible with the net's configuration */
/* and if not, print out message and abort. */
/*---------------------------------------------*/
if (N_reset_wts(ptr_net, wts_file, PORTABLE_FORMAT) == ERROR) BEGIN
sprintf(IO_str, "\n*** weights not compatible with network");
IO_print(0);
ENDIF
else BEGIN
/*-------------------------------------------*/
/* setup the net_name variable using the net */
/* ID so that this code will be unique. */
/*-------------------------------------------*/
CC_set_name(net_name, net_file);
/*------------------------------------------------*/
/* Create the headers and routines which are used */
/* to initialize, propagate, and free a network. */
/*------------------------------------------------*/
CC_setup_header(fp, ptr_net, net_name);
CC_create_main(fp, net_name);
CC_create_initialize(fp, ptr_net, net_file, wts_file, net_name);
CC_create_prop(fp, net_name);
CC_create_cleanup(fp, net_name);
ENDELSE
/*-------------------------------------------*/
/* reset the weights of the network to their */
/* former values, throw away the temporary */
/* file, and close the delivery file. */
/*-------------------------------------------*/
N_reset_wts(ptr_net, "temp.wts", FAST_FORMAT);
sys_delete_file("temp.wts");
fclose(fp);
END /* CC_create_delivery */
void CC_set_name(net_name, net_file)
char *net_name, *net_file;
/*
----------------------------------------------------------------------
Using the name of the network specification file (stored in the
"net_file" parameter) this routine sets up the string which will be
used as a precursor to all variable and routine names in the delivery
file. The idea is to read until a "." or the end of the string is
encountered.
----------------------------------------------------------------------
*/
BEGIN
int i = 0;
while ((net_file[i] != '.') && (net_file[i] != ENDSTRING)) BEGIN
net_name[i] = net_file[i];
/*-------------------------------------------------*/
/* I know this is stupid, but the stupid masscomp */
/* C compiler choked on an autoincrement of "i" */
/* within the array reference. So I had to come */
/* down a peg to the brute force approach. */
/*-------------------------------------------------*/
i++;
ENDWHILE
net_name[i++] = '_';
net_name[i] = ENDSTRING;
END /* CC_set_name */
void CC_setup_header(fp, ptr_net, name)
FILE *fp;
Net *ptr_net;
char *name;
/*
----------------------------------------------------------------------
This routine prints out the initial includes and defines for the
delivery file. Also, two arrays of floating point numbers are
declared as global variables; these will be the arrays which are
used to put inputs into the network.
----------------------------------------------------------------------
*/
BEGIN
fprintf(fp, "\n/*=============================*/");
fprintf(fp, "\n/* NETS Netwo