source: cpp/frams/_demos/saver_test_geno.cpp @ 517

Last change on this file since 517 was 517, checked in by Maciej Komosinski, 8 years ago

Added an example of saving MiniGenotype? objects to a file

File size: 1.1 KB
RevLine 
[517]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#include "genotypeloader.h"
6#include <common/virtfile/stdiofile.h>
7
8/**
9 @file
10 Sample code: Saving genotypes
11
12 \include saver_test_geno.cpp
13*/
14
15int main(int argc,char*argv[])
16{
17if (argc<3)
18        {
19        fprintf(stderr,"Arguments: filename number_of_genotypes\n"
20             "Example: saver_test_geno file.gen 3\n"
21                );
22        return 1;
23        }
24
25StdioFileSystem_autoselect stdiofilesys;
26VirtFILE *f=Vfopen(argv[1],"w");
27if (f)
28        {
29        int N=atoi(argv[2]);
30        MiniGenotype g;
31        Param p(minigenotype_paramtab,&g);
32        g.clear();
33        printf("Saving %d genotypes to %s\n",N,argv[1]);
34        for(int i=1;i<=N;i++)
35                {
36                g.name=SString::sprintf("Genotype#%d",i);
37                g.genotype=""; for(int x=0;x<i;x++) g.genotype+="X";
38                g.velocity=0.1*i;
39                g.energy0=1;
40                g.info="Saved by saver_test_geno.cpp";
41                g.is_valid=1;
42                p.save(f,"org");
43                }
44        delete f;
45        return 0;
46        }
47else
48        {
49        printf("Could not write to %s\n",argv[1]);
50        return 1;
51        }
52}
Note: See TracBrowser for help on using the repository browser.