void WriteNet_bn ( const net_bn*  net,   stream_ns*  file )

Writes net to a new file specified by file.

The file format that the net is written in depends on the file extension (i.e., the ending of the file name passed to NewFileStream_ns or NewMemoryStream_ns). If the extension is ".neta", a binary format producing much smaller files and allowing for encryption is used. Otherwise the DNET file format is used, which is a text file format that may be useful in examining/editing the files produced, or exporting them to another program (for more information, see http://www.norsys.com/dl/DNET_File_Format.txt). It is advised to end the file names with either ".neta" or ".dne", so that way they can be more easily identified by other people and other programs, such as Netica Application.

All versions of Netica API and Netica Application can read/write ".dne" files (which are the same as ".dnet" files), and all versions of them after 2.27 can read/write ".neta" files.

If file already exists, it is overwritten. The net is always saved using a "safe-save", which writes it to a new file, and then if there was no problem, it deletes the old file and changes the name of the new file to that of the old. That way there is no risk of data loss in case of an interruption due to a software error or hardware failure.

If there are findings entered in net, you may want to retract them with RetractNetFindings_bn before writing net, since otherwise they will be saved in the file.

If the file size is very large, it may be because of large tables (such as CPTs). If these are defined by equations, it may be worthwhile to delete them with DeleteNodeTables_bn before writing the net to file, and restoring them with EquationToTable_bn after reading the net back in.


This function is available in all versions. Versions previous to 2.27 could not read/write files in .neta format.

See also:

NewFileStream_ns    Generates the required stream_ns
ReadNet_bn    Reads back the net saved
RetractNetFindings_bn    May want to retract findings before saving net
WriteNetFindings_bn    Just save the findings currently entered as a case
GetNetFileName_bn    Later retrieve the name of the file written to


// Sets net2 to a copy of net1, but without its visual information
file = NewFileStream_ns ("temp.dne", env, NULL);
WriteNet_bn (net1, file);
net2 = ReadNet_bn (file, NO_VISUAL_INFO);
if ((error = GetError_ns (env, WARNING_ERR, NULL)) != NULL)
    fprintf (stderr, "%s\n", ErrorMessage_ns (error));