1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include <iomanip>
#include<direct.h>
#include<windows.h>
#include<vector>
#include <cstdlib>
#include<math.h>
#include<stdio.h>
using namespace std;
double str2double ( string str );
float str2float ( string str );
vector<string> readline(string str);
void main()
{
int ID[5];
int year1, year2;
ifstream num("number.txt");
for(int a=0; a<4; a++)
{
while(num>>ID[a])
{
stringstream sch;
sch<<"schedule"<<"/"<<"schdule_"<<ID[a]<<".txt";
string schedule = sch.str();
stringstream sit;
sit<<"Site"<<"/"<<"Site"<<ID[a]<<".txt";
string site = sit.str();
stringstream sol;
sol<<"soils"<<"/"<<"soilfile_"<<ID[a]<<".txt";
string soil = sol.str();
stringstream wet;
wet<<"weather"<<"/"<<"climate_CX_"<<ID[a]<<".txt";
string weather = wet.str();
ifstream sch_in(schedule);
ifstream site_in(site);
ifstream soil_in(soil);
ifstream weather_in(weather);
ofstream example("example.sch");
ofstream site_out("site.100");
ofstream soil_out("soils.in");
ofstream weather_out("weather.wth");
string line, line1, line2, line3;
while(getline(sch_in,line))
{
example<<line<<endl;
}
while(getline(site_in, line1))
{
site_out<<line1<<endl;
}
while(getline(soil_in, line2))
{
soil_out<<line2<<endl;
}
while(getline(weather_in, line3))
{
weather_out<<line3<<endl;
}
cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"++++++++++++++++++++++++++++++++NOW RUNNING DAILYDAYCENT WITH THE FILE TYPE "<<ID[a]<<"+++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
stringstream dd;
dd<<"dailydaycent"<<" -s "<<"example"<<" -n "<<"example";
string daycent = dd.str();
system(daycent.c_str());
remove("example.bin");
example.close();
site_out.close();
soil_out.close();
weather_out.close();
sch_in.close();
site_in.close();
soil_in.close();
weather_in.close();
//data saving part!!
double sum = 0.0;
double litter = 0.0;
double Corg = 0.0;
double bio = 0.0;
string line;
vector<string>vec;
string line_n;
vector<string>vec_n;
string line_nit;
vector<string>vec_nit;
string line_soiln;
vector<string>vec_soiln;
ifstream dataread2("dc_sip.csv");
ifstream datareadnit("summary.out");
ifstream dataread3("soiln.out");
stringstream out12, out13, out14, out19, out20, out26, out27, out28;
out12<<"output"<<"/"<<"NPP.out";
out13<<"output"<<"/"<<"NEE.out";
out14<<"output"<<"/"<<"C_soil.out";
out19<<"output"<<"/"<<"NO3.out";
out20<<"output"<<"/"<<"NH4.out";
out26<<"output"<<"/"<<"BIO_AG.out";
out27<<"output"<<"/"<<"Year_N2O.out";
out28<<"output"<<"/"<<"N2O.out";
ofstream dataout12(out12.str(),ios::app);
ofstream dataout13(out13.str(),ios::app);
ofstream dataout14(out14.str(),ios::app);
ofstream dataout19(out19.str(),ios::app);
ofstream dataout20(out20.str(),ios::app);
ofstream dataout26(out26.str(),ios::app);
ofstream dataout27(out27.str(),ios::app);
ofstream dataout28(out28.str(),ios::app);
dataout12 << ID[a] << "\t"; // NPP
dataout13 << ID[a] << "\t"; // NEE
dataout14 << ID[a] << "\t"; // C_ORG_SOIL
dataout19 << ID[a] << "\t"; // NO3
dataout20 << ID[a] << "\t"; // NH4
dataout26 << ID[a] << "\t"; // BIO AG
dataout27 << ID[a] << "\t"; // year_summary_N2O
dataout28 << ID[a] << "\t"; // N2O
while(getline(dataread2,line))
{
if(line.size() == 0)
break;
vec = readline(line);
while(getline(datareadnit,line_nit))
{
if(line_nit.size() == 0)
break;
vec_nit = readline(line_nit);
while(getline(dataread3,line_soiln))
{
if(line_soiln.size() == 0)
break;
vec_soiln = readline(line_soiln);
if((str2double(vec[0])>=year1) && (str2double(vec[0])<year2 + 1))
{
Corg = str2double(vec[51]) + str2double(vec[52]) + str2double(vec[53]) + str2double(vec[54]) + str2double(vec[55]);
bio = str2double(vec[33]) + str2double(vec[34]) + str2double(vec[35]);
dataout14 << Corg << "\t"; // C_ORG_SOIL
dataout12 << vec[31] << "\t"; // NPP
dataout13 << vec[32]<< "\t"; // NEE
dataout26 << vec[33] << "\t";
dataout27 << str2double(vec[34]) + str2double(vec[35]) << "\t";
dataout28 << vec_nit[5] << "\t";
dataout19 << ((2*str2float(vec_soiln[3])) + (3*str2float(vec_soiln[4])) + (5*str2float(vec_soiln[5])) + (10*str2float(vec_soiln[6])))/20 << "\t";
dataout20 << vec_soiln[2] << "\t";
}
}
}
}
dataout14 << "\n"; // C_ORG_SOIL
dataout19 << "\n"; // NO3
dataout20 << "\n"; // NH4
dataout12 << "\n"; // NPP
dataout13 << "\n"; // NEE
dataout26 << "\n";
dataout27 << "\n";
dataout28 << "\n";
}
}
system("pause");
}
//..........................................................................................................................................................
double str2double(string str)
{
// string to double
istringstream buffer(str);
double in;
buffer >> in;
return in;
}
//...........................................................................................................................................................
float str2float ( string str )
{
// string to double
istringstream buffer(str);
float in;
buffer >> in;
return in;
}
//............................................................................................................................................................
vector<string> readline(string str)
{
vector<string>vec_str;
string str2;
int len = str.size();
double val;
size_t offset;
int cnt = 0;
int ende, start = 0;
while(((offset = str.find(",")) != -1) || ((offset = str.find(" ")) != -1) || ((offset = str.find(" ")) != -1) || ((offset = str.find(" ")) != -1) || ((offset = str.find("\t")) != -1))
{
cnt++;
if(offset == len)
break;
ende = offset - 1;
str2 = str.substr(start,(ende-start+1));
if((str2.size() > 0) && (str2 != " "))
vec_str.push_back(str2);
start = ende+1;
str.erase(offset,1);
}
ende = str.size();
str2 = str.substr(start,(ende-start+1));
vec_str.push_back(str2);
return vec_str;
}
|