source: cpp/frams/_demos/full_props.cpp @ 132

Last change on this file since 132 was 121, checked in by sz, 11 years ago

updated file headers and makefiles

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include <stdlib.h>
6#include <stdio.h>
7#include <time.h>
8#include <frams/virtfile/stdiofile.h>
9
10#include <frams/model/model.h>
11#include <frams/genetics/defgenoconv.h>
12#include <frams/errmgr/stdouterr.h>
13
14/**
15 @file
16 Sample code: Adding/removing default properties in f0 genotypes
17 Usage: full_props [-r[everse]] [genotype_or_stdin]
18
19 Calling examples:
20
21 # convert f1 -> f0 + explicitly set all properties to their default values  (the result is still valid f0)
22 ./full_props "X[|]arX[-1:1,fo:0.2]"
23
24   //0
25   p:x=0, y=0, z=0, m=1, s=1, dn=1, fr=0.4, ing=0.25, as=0.25, rx=0, ry=0, rz=0, i=, Vstyle=part, vs=0.2, vr=0.5, vg=0.5, vb=0.5
26   p:x=1, y=0, z=0, m=2, s=1, dn=1, fr=0.4, ing=0.25, as=0.25, rx=0, ry=0, rz=0, i=, Vstyle=part, vs=0.2, vr=0.5, vg=0.5, vb=0.5
27   p:x=2, y=0, z=0, m=1, s=1, dn=1, fr=0.4, ing=0.277778, as=0.166667, rx=0, ry=0, rz=0, i=, Vstyle=part, vs=0.2, vr=0.5, vg=0.5, vb=0.5
28   j:p1=0, p2=1, rx=0, ry=0, rz=0, dx=1, dy=0, dz=0, stif=1, rotstif=1, stam=0.25, i=, Vstyle=joint, vr=0.5, vg=0.5, vb=0.5
29   j:p1=1, p2=2, rx=-0.7853, ry=0, rz=0, dx=1, dy=0, dz=0, stif=1, rotstif=1, stam=0.277778, i=, Vstyle=joint, vr=0.5, vg=0.5, vb=0.5
30   n:p=-1, j=0, d="|:p=0.25, r=1", i=, Vstyle=neuro
31   n:p=2, j=-1, d="N:in=0.8, fo=0.2, si=2, s=0", i=, Vstyle=neuro
32   c:n1=1, n2=0, w=1, i=
33
34 # convert the previous output to the regular f0 format (removing redundant default properties)
35 ./full_props "X[|]arX[-1:1,fo:0.2]" | ./full_props -r
36
37   //0
38   p:
39   p:1, m=2
40   p:2, ing=0.277778, as=0.166667
41   j:0, 1, dx=1
42   j:1, 2, rx=-0.7853, dx=1, stam=0.277778
43   n:j=0, d=|
44   n:p=2, d=N:fo=0.2
45   c:1, 0
46
47*/
48
49//optional:
50DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
51
52int main(int argc,char*argv[])
53{
54StdioFILE::setStdio();//setup VirtFILE::Vstdin/out/err
55StdoutErrorHandler err(ErrorHandlerBase::DontBlock,VirtFILE::Vstderr); //errors -> stderr, don't interfere with stdout
56
57bool reverse=false;
58char* gen_arg=0;
59for(int i=1;i<argc;i++)
60        {
61        char* ar=argv[i];
62        if (ar[0]=='-')
63                switch(ar[1])
64                        {
65                        case 'r': reverse=true; break;
66                        case 'h': puts("usage: full_props [-r[everse]] [genotype_or_stdin]\n"); break;
67                        }
68        else
69                if (!gen_arg)
70                        gen_arg=ar;
71        }
72SString gen;
73if (gen_arg)
74        gen=gen_arg;
75else
76        loadSString(VirtFILE::Vstdin,gen);
77Geno g(gen);
78Model m(g);
79
80if (!m.isValid())
81        {
82        FMprintf("","full_props",FMLV_ERROR,"Cannot build Model from the supplied genotype\n");
83        return 2;       
84        }
85
86m.open();
87for(int i=0;i<m.getNeuroCount();i++)
88        {
89        Neuro *n=m.getNeuro(i);
90        SyntParam p=n->classProperties(reverse);
91        p.update();// ...so everyone reading the source can recognize that p was created to update the neuro d field
92        // but actually, calling update() here is not necessary, because ~SyntParam() would do it anyway
93        }
94m.close();
95
96// normal f0 would be retrieved using m.getF0Geno()
97// the following form allows for more control:
98Geno f0_g;
99m.makeGeno(f0_g,NULL,reverse);//third arg is "handle_defaults" == whether f0 should omit default property values
100puts((const char*)f0_g.toString());
101
102return 0;
103}
104
Note: See TracBrowser for help on using the repository browser.