[83] | 1 | // This file is a part of the Framsticks GDK library. |
---|
| 2 | // Copyright (C) 2002-2013 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 "stdiofile.h" |
---|
| 9 | |
---|
| 10 | #include "model.h" |
---|
| 11 | #include "defgenoconv.h" |
---|
| 12 | #include "stdouterr.h" |
---|
| 13 | |
---|
| 14 | /** |
---|
| 15 | @file |
---|
| 16 | Sample code: Adding/removing default properties in f0 genotypes |
---|
| 17 | Usage: fullneuroprops [-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 | ./fullprops "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 | ./fullprops "X[|]arX[-1:1,fo:0.2]" | ./fullprops -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: |
---|
| 50 | DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes |
---|
| 51 | |
---|
| 52 | int main(int argc,char*argv[]) |
---|
| 53 | { |
---|
| 54 | StdioFILE::setStdio();//setup VirtFILE::Vstdin/out/err |
---|
| 55 | StdoutErrorHandler err(ErrorHandlerBase::DontBlock,VirtFILE::Vstderr); //errors -> stderr, don't interfere with stdout |
---|
| 56 | |
---|
| 57 | bool reverse=false; |
---|
| 58 | char* gen_arg=0; |
---|
| 59 | for(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: fullneuroprops [-r[everse]] [genotype_or_stdin]\n"); break; |
---|
| 67 | } |
---|
| 68 | else |
---|
| 69 | if (!gen_arg) |
---|
| 70 | gen_arg=ar; |
---|
| 71 | } |
---|
| 72 | SString gen; |
---|
| 73 | if (gen_arg) |
---|
| 74 | gen=gen_arg; |
---|
| 75 | else |
---|
| 76 | loadSString(VirtFILE::Vstdin,gen); |
---|
| 77 | Geno g(gen); |
---|
| 78 | Model m(g); |
---|
| 79 | |
---|
| 80 | if (!m.isValid()) |
---|
| 81 | { |
---|
| 82 | FMprintf("","fullneuroprops",FMLV_ERROR,"Cannot build Model from the supplied genotype\n"); |
---|
| 83 | return 2; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | m.open(); |
---|
| 87 | for(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 | } |
---|
| 94 | m.close(); |
---|
| 95 | |
---|
| 96 | // normal f0 would be retrieved using m.getF0Geno() |
---|
| 97 | // the following form allows for more control: |
---|
| 98 | Geno f0_g; |
---|
| 99 | m.makeGeno(f0_g,NULL,reverse);//third arg is "handle_defaults" == whether f0 should omit default property values |
---|
| 100 | puts((const char*)f0_g.toString()); |
---|
| 101 | |
---|
| 102 | return 0; |
---|
| 103 | } |
---|
| 104 | |
---|