Changeset 115
- Timestamp:
- 01/26/14 06:01:27 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/_demos/loader_test.cpp
r109 r115 14 14 int main(int argc,char*argv[]) 15 15 { 16 puts("This example shows how to load genotypes from the standard Framsticks genotype file");17 16 if (argc<2) 18 17 { 19 puts("(Please give the file name as command line argument)"); 18 fprintf(stderr,"Arguments: filename [optional: genotype name or index (1-based)]\n" 19 "If a genotype is indicated (by providing the optional genotype identifier), the program will output the raw genotype, suitable for Framsticks Theater's genotype viewer mode. If the second optional argument is not given, the genotype names from the file will be listed.\n" 20 "Example: loader_test walking.gen \"Basic Quadruped\" | theater -g -" 21 ); 20 22 return 1; 21 23 } … … 23 25 long count=0,totalsize=0; 24 26 MiniGenotypeLoader loader(argv[1]); 27 const char* selected=(argc<3)?NULL:argv[2]; 28 int selected_index=(selected&&isdigit(selected[0]))?atol(selected):0; 25 29 // using char* constructor (passing the file name to open) 26 30 MiniGenotype *loaded; … … 30 34 count++; 31 35 totalsize+=loaded->genotype.len(); 32 printf("%d. %s\t(%d characters)\n",count,(const char*)loaded->name,loaded->genotype.len()); 36 if (selected) 37 { 38 if (selected_index) 39 { 40 if (selected_index!=count) 41 continue; 42 } 43 else 44 { 45 if (strcmp((const char*)loaded->name,selected)) 46 continue; 47 } 48 puts((const char*)loaded->genotype); 49 return 0; 50 } 51 fprintf(stderr,"%d. %s\t(%d characters)\n",count,(const char*)loaded->name,loaded->genotype.len()); 33 52 } 34 53 // the loop repeats until loaded==NULL, which could be beacause of error 35 54 if (loader.getStatus()==MiniGenotypeLoader::OnError) 36 printf("Error: %s",(const char*)loader.getError());55 fprintf(stderr,"Error: %s",(const char*)loader.getError()); 37 56 // (otherwise it was the end of the file) 38 39 printf("\ntotal: %d items, %d characters\n",count,totalsize); 40 return 0; 57 if (selected) 58 { 59 fprintf(stderr,"genotype %s not found in %s\n",selected,argv[1]); 60 return 2; 61 } 62 else 63 { 64 fprintf(stderr,"\ntotal: %d items, %d characters\n",count,totalsize); 65 return 0; 66 } 41 67 }
Note: See TracChangeset
for help on using the changeset viewer.