I am new in C++ programming, i am trying to add some codes to my programme, to enable it process several input files automatically during runtime and give results in several output files relating to the input files.My idea is to prepare several text files with the required informations and put them in one folder/ directory which i can use as a single input, instead of typingin each text file as i am now working with my programme. Any body can render me a helping hand on how to go about the idea in C++ codes.
below is part of the programme i am developing.
#include <iostream>
#include <conio.h>
#include <math.h>
#include <windows.h>
#include <vector>
#include "epanet2.h"
#include <stdlib.h>
#include <fstream>
#include <istream>
#include <sstream>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
using namespace std;
#define PIPE_CLOSED 0
#define PIPE_OPEN 1
#define MAX_PATH_LEN 500 /* Maximum number of Chars in a datafile line */
#define MAX_LABEL_LEN 25 /* Maximum length of an ID or Label */
char file[MAX_PATH_LEN];
char rept[MAX_PATH_LEN];
int Numinpfile;
int Numpipes;
int Numnodes;
double Demand_loss;
double trans_ADF;
double pi;
double Loss_Demand;
double cost;
ofstream outputfile;
if(argc<1){
cout << "You are requested to supply the folder containing networks parameters related to epanet !.>\n";
exit(1);
}
char* dirname=argv[1]; // Seperately copy argv[1] (first argument) to variable dirname
cout << "dirname : "<< dirname << endl;
char* argv_[MAX_PATH_LEN];
argv_[0]=argv[0]; // argv[0] is the calling program name, copy this as it is.
for(int i=1;i<argc-1;i++){ // then copy the rest (argv[2], argv[3],...) of arguments to new arrays
cerr << argv[i+1]<<endl;
argv_[i]=argv[i+1];
}
argc--; // argc should be in the descending order.
Organise_Input_data(dirname);
cout << "Networks Inputfolder" <<directory<< " Is organised for use ....\n" << endl;
prepare_Input_param(filename);
cout << " Network Inputfile " << file << " is imported and prepared in order to be analysed...\n" << endl;
/** read the text file specified by filename argument and obtain epanet related parameters */
void prepare_Input_param(char* filename)
{
//open the file
ifstream myfile (filename);
if(!myfile.is_open()){ // This is very useful .
cout << "I can not open the file:"<<filename <<" I cannot continue i quit!!\n";
exit(1);
}
myfile >> file; //read the name of the file
myfile >> rept; //read the name of the report file
myfile >> Numpipes; //number of pipes
float Demandwithoutme=0;
float Htotal_irreg=0;
int index = -1;
char tmp[MAX_LABEL_LEN]; // Convert a C++ string to a Cstyle char*
strcpy(tmp,pipes[i].c_str()); // Epanet written in C language which doesnot accept strings
ret=ENgetlinkindex_wrap(tmp,&index);
cout << " Get-pipes-index Error returned " << ret << endl;
cout << " Breaking a pipe now " << ret << endl;
ret=ENsetlinkvalue_wrap(index,EN_INITSTATUS,PIPE_CLOSED);
cout << " setlinkvalue Error returned " << ret << endl;
ret= ENopenH_wrap();
ret= ENinitH_wrap(10);
do
{
ret=ENrunH_wrap(&time);
cout << "At ENrunH_wrap Error returned " << ret << endl;
for (int i=0; i<Numnodes; i++)
{
cout << "Numnodes : "<< Numnodes << endl;
int index=-1;
char tmp[MAX_LABEL_LEN]; // convert C++ string to C style char*
strcpy(tmp,nodes[i].c_str());
ret=ENgetnodeindex_wrap(tmp,&index);
if(ret!=0){outputfile << "At ENgetnodeindex_wrap Epanet Error returned " << ret << endl;}
ret=ENgetnodevalue_wrap(index,EN_DEMAND,&break_dwm);
//if(ret!=0){outputfile << "At ENgetnodevalue_wrap Epanet Error returned " << ret << endl;}
break_Demand.push_back(break_dwm);
Demandwithoutme+=break_dwm;
}
ret= ENnextH_wrap(&tstep);
}
while (tstep=0);