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
|
FILE *pfile;
int r, c;
float temp, y, b;
char string[10], filepath[100];
if ((setFlowRateTableName())==true)
{
printf("Input the slope of the water: ");
flowRateTable.param.s = readValueGTzero();
printf("Input the slope of the channel sides: ");
flowRateTable.param.z = readValueGTzero();
do
{
printf("Please give the coefficient of roughness: ");
scanf("%f", &temp);
flowRateTable.param.n = temp;
if (((flowRateTable.param.n)<N_MIN)||((flowRateTable.param.n)>N_MAX))
{
printf("The coefficient of roughness must be between %f and %f.\n", N_MIN, N_MAX);
}
}while (((flowRateTable.param.n)<N_MIN)||((flowRateTable.param.n)>N_MAX));
printf("Input initial base width: ");
flowRateTable.baseWidth.initialValue = readValueGTzero();
printf("Input step size for base width: ");
flowRateTable.baseWidth.stepSize = readValueGTzero();
printf("Input inital water depth: ");
flowRateTable.waterDepth.initialValue = readValueGTzero();
printf("Input step size for water depth: ");
flowRateTable.waterDepth.stepSize = readValueGTzero();
y=flowRateTable.waterDepth.initialValue;
for (r=0;r<NUMROWS;r++)
{
b = flowRateTable.baseWidth.initialValue;
for (c=0;c<NUMCOLS;c++)
{
flowRateTable.flowRates[r][c] = computeFlowrate(b, y);
b = b + flowRateTable.baseWidth.stepSize;
}
y = y + flowRateTable.waterDepth.stepSize;
}
strcpy(filepath, directory);
strcat(filepath, flowRateTable.name);
strcat(filepath, extension);
pfile = fopen(filepath, "w");
if (pfile != NULL)
{
printf("%s\n", filepath);
fputs(" Base Depth-->\nWater Depth|", pfile);
for (r=0;r<NUMROWS;r++)
{
temp = flowRateTable.baseWidth.initialValue + (r*flowRateTable.baseWidth.stepSize);
sprintf(string, "%f", temp);
fputs(string, pfile);
fputs("\t", pfile);
}
for (r=0;r<NUMROWS;r++)
{
temp = flowRateTable.waterDepth.initialValue + (r*flowRateTable.waterDepth.stepSize);
sprintf(string, "%4.2f", temp);
fputs(string, pfile);
fputs("|", pfile);
for (c=0;c<NUMCOLS;c++)
{
sprintf(string, "%4.2f", (flowRateTable.flowRates[r][c]));
//fwrite(string, 1, 6, pfile);
fputs(string, pfile);
}
fputs("\n", pfile);
}
} else {
printf("Something is wrong with opening the file. At least you got this far?");//this will probably have to be changed to something more official.
}
}
return;
| |