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
|
int main (void)
{
char line[256];
double data[500];
int i, j, k, t, n;
double P, T, Qa, Qsh, Lt, Dt, Mg, dvsg, mfpg, rhog, Kn, Cc;
double Dp[500], Diff[500], tau[500], Pn[500];
FILE *FH0;
char* echofile;
echofile="output_data.txt";
FH0=fopen(echofile,"w+");
if (FH0==NULL)
{
printf("Error: echofile could not be opened\n");
exit(1);
}
ifstream indata;
indata.open("input_data.txt");
if (! indata.is_open())
{
fprintf(FH0,"Error: inputfile could not be opened\n");
exit(1);
}
//read the number of lines and calculates the number of diameters
ifstream file( "input_data.txt" ) ;
string liness ;
vector<string> lines ;
while( getline( file, liness ) )
lines.push_back( liness ) ;
int totlines = lines.size();
int top = totlines - 9;
fprintf(FH0,"total lines\t \t %i\n",totlines);
fprintf(FH0,"read lines\t \t %i\n",top);
fprintf(FH0,"\n");
for (i=0;i<4;i++) //reads the singly-line data after the *
{
indata.getline(line,256,'*');
fprintf(FH0,line);
fprintf(FH0,"\n");
indata >> data[i];
fprintf(FH0,"%g",data[i]);
}
n=0;
fprintf(FH0,"\n\n diameters read \n");
while (!indata.eof());
{
for(t=1; t<=top; t++)
{
n++;
indata >> data[9+t];
// indata.ignore(top,'\n');
// particle diameter [nm -> m]
Dp[t-1] = data[9+t]*1.0e-9;
fprintf(FH0,"%d\t %g\n",n, Dp[t-1]);
}
}
indata.close();
|