1 /* Copyright 2008 Jason Kim Chong Polak
3 Please respect the following:
5 This file is part of bioCity. bioCity is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "ConfReader.hh"
34 int translate_data( string
, string
[], int );
35 void print_default( string
);
39 cout
<<"#bioCity: Welcome to bioCity Matrix 0.4 (staging branch)"<<endl
;
40 cout
<<"#bioCity: The current byte-size of the world class is "<<sizeof(World
)<<endl
;
43 * This part initializes environment variables
44 * and sets defaults if the configuration file
47 //START Environment variables
49 double dim_x
= 500, dim_y
= 500;
53 string scenario
="scen_singl_pop";
55 //array of scenario functions defined in World.cpp
56 typedef void (World::*ptrUpdate
)( );
57 ptrUpdate update_func
[][2] =
59 { &World::scen_single_pop
, &World::scen_single_pop_init
}
61 string update_func_names
[] =
65 int update_func_len
= 1;
67 //END environment variables
69 ConfReader
conf( "bioc.conf" );
72 if ( !conf
.success() )
74 cout
<<"#Configuration file not found. Using defaults.";
78 if (!conf
.field_int( "population", &psize
) )
79 print_default( "population" );
80 if (!conf
.field_double( "dimx", &dim_x
) )
81 print_default("dimx");
82 if (!conf
.field_double( "dimy", &dim_y
) )
83 print_default("dimy");
84 if (!conf
.field_int( "time", &time
) )
85 print_default("time");
86 if (!conf
.field_int( "graphics", &graphics
) )
87 print_default("graphics");
88 if (!conf
.field_string( "scenario", &scenario
) )
89 print_default( "scenario" );
92 cout
<<"#bioCity: Current World Parameters"<<endl
;
93 cout
<<setw(spacing
)<<std::left
<<"#Population Size:"<<std::right
<<psize
<<endl
;
94 cout
<<setw(spacing
)<<std::left
<<"#Dimension X:"<<std::right
<<dim_x
<<endl
;
95 cout
<<setw(spacing
)<<std::left
<<"#Dimension Y:"<<std::right
<<dim_y
<<endl
;
96 cout
<<setw(spacing
)<<std::left
<<"#Time:"<<std::right
<<time
<<endl
;
97 cout
<<setw(spacing
)<<std::left
<<"#Graphics:"<<std::right
<<graphics
<<endl
;
98 cout
<<setw(spacing
)<<std::left
<<"#Scenario:"<<std::right
<<scenario
<<endl
;
101 scenario_num
= translate_data( scenario
, update_func_names
, update_func_len
) - 1;
104 * This is where the magic happens :)
107 World
W1( psize
, dim_x
, dim_y
);
108 (W1
.*update_func
[scenario_num
][1])();
110 //Let the main know about all the functions
111 //that can be use so that the user can
118 id0
= g2_open_X11( (int) dim_x
, (int) dim_y
);
119 //int id1 = g2_open_EPSF_CLIP( "locationd.eps", (int) dim_x, (int) dim_y );
121 //g2_attach(id, id1);
122 W1
.print_graph( id
);
124 // g2_detach(id, id1);
125 cout
<<"Timestep\tPopulation\t First\t Second"<<endl
;
129 for ( i
= 0; i
< time
; i
++ )
131 (W1
.*update_func
[scenario_num
][0])();
133 if (i
%20 == 0 && i
> 0)
137 if (graphics
) { W1
.print_graph( id
); }
142 W1.print_graph( id );
146 if (graphics
) { W1
.print_graph( id
); }
149 //W1.complete_stats( );
150 cout
<<"#The world has ended! Input anything to quit."<<endl
;
155 int translate_data(string varName
, string database
[], int length
)
157 int numOptions
= length
;
160 for (int i
= 0; i
< numOptions
; i
++)
162 if (database
[i
] == varName
)
170 void print_default(string field
)
172 cout
<<"# WARNING: \""<<field
<<"\" not found, using default!"<<endl
;