Jump to content

Recommended Posts

I am unable to compile a C++ program which I have downloaded from internet.

 

I have no knowledge of c++, but use other languages like perl on linux. So i tried to compile on Linux using gcc, g++, cc etc. however I got two errors:

 

main.cpp: In function ‘int main(int, char**)’:

main.cpp:44: error: ‘atoi’ was not declared in this scope

 

I tried in Turbo C++ compiler also, but that gave 25 errors.

Being unfamiliar with C++, I cannot solve the errors. But can someone compile the program and send them or tell me the options with gcc or the linux compilers so that I may be able to compile this.

 

 




#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>

using namespace std;

#define AC

bool read_profile(string fname,vector<vector<double> >& profile,string& seq);
//main
int main(int argc, char * argv[])
{
int LG;
vector<double> vec;
int veclen,seqlen;
double sum,ave;
int j,k,lg;
string seqid,seq,fname,fnameout;
vector<vector<double > > oneprofile;

if(argc!=4)
{
cout<<"usage: programm LG PSSM_file¡¡outname"<<endl;
return 0;
}
LG=atoi(argv[1]);
if(LG<=0)
{
cout<<"invalid value of LG "<<LG<<endl;
return 0;
}
fname=argv[2];
fnameout=argv[3];


#ifdef AC
cout<<"calculate AC variables...";
#else
cout<<"calculate ACC variables...";
#endif

#ifndef AC
vector< double > cc;
#endif

vector<double> ave_local;
ave_local.resize(20);

vector<double> ac;
ac.resize(20);


if(!read_profile(fname,oneprofile,seq))
{
cout<<"cannot read profile from "<<fname<<endl;
return 0;
}
seqlen=(int)oneprofile.size();
if(LG>=seqlen)
{
cout<<"too large value of LG (must be less than the length of the sequence)"<<endl;
return 0;
}

#ifdef AC
veclen=LG*20;
vec.resize(veclen);
#else
int index;
veclen=LG*400;
vec.resize(veclen);
cc.resize(380);
int k1,k2;
double ave1,ave2;
#endif

for(k=0;k<20;k++)
ave_local[k]=0;
for(j=0;j<seqlen;j++)
{
for(k=0;k<20;k++)
ave_local[k]+=oneprofile[j][k];
}
for(k=0;k<20;k++)
ave_local[k]/=seqlen;


for(lg=1;lg<=LG;lg++)
{
//calculate AC variable
for(k=0;k<20;k++)
{
ave=ave_local[k];
sum=0;
for(j=0;j<seqlen-lg;j++)
{
sum+=(oneprofile[j][k]-ave)*(oneprofile[j+lg][k]-ave);
}
sum/=(seqlen-lg);
ac[k]=sum;
}
#ifdef AC
for(k=0;k<20;k++)
vec[(lg-1)*20+k]=ac[k];
#else
for(k=0;k<20;k++)
vec[(lg-1)*400+k]=ac[k];
#endif

#ifndef AC
//calculate CC variable
for(k1=0;k1<20;k1++)
for(k2=0;k2<20;k2++)
{
if(k1!=k2)
{
sum=0;

ave1=ave_local[k1];
ave2=ave_local[k2];

sum=0;
for(j=0;j<seqlen-lg;j++)
sum+=(oneprofile[j][k1]-ave1)*(oneprofile[j+lg][k2]-ave2);
sum/=(seqlen-lg);
if(k1>k2)
index=k1*19+k2;
else
index=k1*19+k2-1;
cc[index]=sum;
}
}
for(k=0;k<380;k++)
vec[(lg-1)*400+k+20]=cc[k];
#endif

}
ofstream fileout(fnameout.c_str());
if(!fileout.is_open())
{
cout<<"cannot open file for out, file: "<<fnameout<<endl;
return 0;
}
for(j=0;j<veclen;j++)
fileout<<vec[j]<<endl;

cout<<"done"<<endl;
return 1;
}
bool read_profile(string fname,vector<vector<double> >& profile,string& seq)
{
const int aapsi2rank[20]={0,14,11,2,1,13,3,5,6,7,9,8,10,4,12,15,16,18,19,17};
string filename,line;
ifstream filein;
int j,ni;
char c;
double tempd;
vector<double> one_profile;
one_profile.resize(20);


filein.open(fname.c_str());
if(!filein.is_open())
return false;

profile.clear();
seq.clear();
getline(filein,line);//ignore the first three lines
getline(filein,line);
getline(filein,line);
while(!filein.eof())
{
getline(filein,line);
if(line.empty())//terminate
break;
stringstream ss(line);
ss>>ni>>c;
seq.push_back(c);
for(j=0;j<20;j++)
{
if(ss.eof())
return false;
ss>>tempd;
one_profile[aapsi2rank[j]]=tempd;
}
profile.push_back(one_profile);
}
return true;
}

Link to comment
https://forums.phpfreaks.com/topic/176441-gcc-compile/
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.