Пример #1
0
void CVoxSQLite::AddProfile( const char* username, Profile& rProfile )
{
	if ( ProfileExists( username ) )
	{
		UpdateProfile( username, rProfile );
	}
	else
	{
		InsertProfile( username, rProfile );
	}
}
Пример #2
0
//-----------------------------------------------------------------
//
// Function:   ProcDump
//
// Purpose:    Called by wt profiling to dump out the information in
//             profiling data structre.  The stack is cleared of
//             functions.
//
// Input:      Profile  -   pointer to profiler data structure
//
// Output:     None
//
//------------------------------------------------------------------
void ProcDump (PSProfile *Profile )
{
   // Clear the stack of any symbols
   for ( ; iStackDepth >= 0; iStackDepth -= 1)
   {
      UpdateProfile(Profile,
                    CallStack[iStackDepth].Symbol,
                    CallStack[iStackDepth].cInstructions);
      if (iStackDepth != 0)
      {
         CallStack[iStackDepth-1].cInstructions += CallStack[iStackDepth].cInstructions;
      }
   }
   DumpProfile (*Profile);
   InitProfile (*Profile);
}
Пример #3
0
float MAlignment::align(){
	profile.push_back(seqs[0]);
	float FinalScore;
	int total_length=seqs[0].size();
	
	for(unsigned int i=1;i < seqs.size();i++){
		total_length+=seqs[i].size();
		/*******Calculate the TABLE********/		
		int ydim=profile[0].size()+1;
		int xdim=seqs[i].size()+1;
		float score[xdim*ydim];
		int trace[xdim*ydim]; // to record traces for finding the aligned sequences 1 for gap in x,2 for match,3 for gap in y
		for(int l=0; l < ydim;l++){
			score[l*xdim]=(float)l*gap;
			trace[l*xdim]=3;
		}
		for(int l=0; l < xdim;l++){
			score[l]=(float)l*gap;
			trace[l]=1;
		}

		for(int j=1; j <xdim;j++){
			for(int k=1; k <ydim;k++){
				float  temp=0.0;
				score[k*xdim+j]=score[(k-1)*xdim+j]+gap;//initialize min with adding gap in y direction
				trace[k*xdim+j]=3;
				for(unsigned int m=0;m < profile.size();m++){
					float Percentage=Similarity(profile[m][k-1],seqs[i][j-1]);
					if(FloatEqual(Percentage,1.0) == true){
						temp=temp+score[(k-1)*xdim+j-1]+identical;
						//cout<<"Identical "<<profile[m][k-1]<<","<<seqs[i][j-1]<<" Score:"<<temp<<endl;
					}else if(FloatEqual(Percentage,0.9) == true){						
						temp=temp+score[(k-1)*xdim+j-1]+verysimilar;
						//cout<<"Almost "<<profile[m][k-1]<<","<<seqs[i][j-1]<<" Score:"<<temp<<endl;
					}else if(Percentage >= 0.66 ){
						//cout<<"Temp now is "<<temp<<endl;
						temp=temp+score[(k-1)*xdim+j-1]+similar;
						//cout<<"Similar "<<profile[m][k-1]<<","<<seqs[i][j-1]<<" Score:"<<temp<<endl;
					}else if(Percentage < 0.0 ){
						temp=temp+score[(k-1)*xdim+j-1]+gap;
						//cout<<"MatchToGap "<<profile[m][k-1]<<","<<seqs[i][j-1]<<" Score:"<<temp<<endl;
					}else{						
						temp=temp+score[(k-1)*xdim+j-1]+mismatch;
						//cout<<"Mismatch "<<profile[m][k-1]<<","<<seqs[i][j-1]<<" Score:"<<temp<<endl;
					}
				}
				temp=temp/float(profile.size());
				//cout<<"Finally the score is "<<temp<<endl;
				if(temp < score[k*xdim+j]){
					//cout<<temp << " is smaller than "<< score[k*xdim+j] <<endl;
					score[k*xdim+j]=temp;
					trace[k*xdim+j]=2;
				}

				temp=score[k*xdim+j-1]+gap; //adding gap in x direction
				if(temp < score[k*xdim+j]){
					//cout<<temp << " is smaller than "<< score[k*xdim+j] <<endl;
					score[k*xdim+j]=temp;
					trace[k*xdim+j]=1;
				}
			}
		}
		//cout<<"Finish Scoring?"<<endl;
		
		/**************  Output score matrix*************
		for(int k=ydim-1; k >=0;k--){
			if( k >= 1){
				cout<<profile[0][k-1];
			}else{
				cout<<"-";
			}
			for(int j=0; j <xdim;j++){
				cout<<"\t"<<score[k*xdim+j];
			}
			cout<<endl;
		}
		cout<<"\t"<<"-";
		for(unsigned int j=0; j < seqs[i].size();j++){
			cout<<"\t"<<seqs[i][j];
		}
		cout<<endl;
		cout<<"Final Score :"<<score[xdim*ydim-1]<<endl;
		*************************************************/
		
		/**************  Out put matrix
		for(int l=ydim-1; l >=0;l--){			
			for(int m=0; m <xdim;m++){
				cout<<"\t"<<trace[l*xdim+m];
			}
			cout<<endl;
		}
		*/
		
		/**Trace back find the alignment*/
		int xInd=xdim-1;
		int yInd=ydim-1;
		while(xInd > 0 || yInd > 0 ){
			//cout <<"Checking "<<xInd<<","<<yInd<<endl;
			if(xInd-1 >=0 && trace[yInd*xdim+xInd] == 1){
				for(unsigned int m=0;m < profile.size();m++){
					if(alignment.size() > m){
						alignment[m].insert(alignment[m].begin(),"-");
					}else{
						vector<string> temp;
						temp.push_back("-");
						alignment.push_back(temp);
					}
				}
					
				if(alignment.size() > profile.size() ){
					alignment[int(profile.size())].insert(alignment[int(profile.size())].begin(),seqs[i][xInd-1]);
				}else{
					vector<string> temp;
					temp.push_back(seqs[i][xInd-1]);
					alignment.push_back(temp);
				}
				xInd=xInd-1;
				continue;
			}
			
			if(yInd-1 >=0 && trace[yInd*xdim+xInd] == 3){
				for(unsigned int m=0;m < profile.size();m++){
					if(alignment.size() > m){
						alignment[m].insert(alignment[m].begin(),profile[m][yInd-1]);
					}else{
						vector<string> temp;
						temp.push_back(profile[m][yInd-1]);
						alignment.push_back(temp);
					}
				}
					
				if(alignment.size() > profile.size()){
					alignment[int(profile.size())].insert(alignment[int(profile.size())].begin(),"-");
				}else{
					vector<string> temp;
					temp.push_back("-");
					alignment.push_back(temp);
				}			
				yInd=yInd-1;
				continue;
			}
			if(trace[yInd*xdim+xInd] == 2){
				for(unsigned int m=0;m < profile.size();m++){
					if(alignment.size() > m){
						alignment[m].insert(alignment[m].begin(),profile[m][yInd-1]);
					}else{
						vector<string> temp;
						temp.push_back(profile[m][yInd-1]);
						alignment.push_back(temp);
					}
				}
					
				if(alignment.size() > profile.size()){
					alignment[int(profile.size())].insert(alignment[int(profile.size())].begin(),seqs[i][xInd-1]);
				}else{
					vector<string> temp;
					temp.push_back(seqs[i][xInd-1]);
					alignment.push_back(temp);
				}				
				xInd=xInd-1;
				yInd=yInd-1;
			}
		}
		
		 //~ while (i > 0)
  //~ {
    //~ AlignmentA <- Ai + AlignmentA
    //~ AlignmentB <- "-" + AlignmentB
    //~ i <- i - 1
  //~ }
  //~ while (j > 0)
  //~ {
    //~ AlignmentA <- "-" + AlignmentA
    //~ AlignmentB <- Bj + AlignmentB
    //~ j <- j - 1
  //~ }

		UpdateProfile();
		FinalScore=score[xdim*ydim-1];
	}
	
	return (FinalScore)/(int)(profile[0].size())+2;
	
}
Пример #4
0
//-----------------------------------------------------------------
//
// Function:   Profile
//
// Purpose:    Used by wt profiling to keep track of trace information.
//             A stack is used to keep track of the call tree. The
//             function invocation count is incremented only when
//             the function is removed from the stack.  A function
//             is removed from the stack when another function of
//             a lower level is reached.
//
// Input:      Profile  -  pointer to profiling data structure
//             Symbol   -  function name to store in profiler data structure.
//             cInstructions  -  instructions executed by the function
//             cLevel         -  level in the call tree
//
// Output:     None
//
//------------------------------------------------------------------
void
Profile(
    PSProfile *pProfile,
    unsigned char *Symbol,
    unsigned long cInstructions,
    unsigned long cLevel
    )
{
   long cNewLevel = -1;
   PSProfile Profile;

   if (!*pProfile) {
      InitProfile(*pProfile);
   }
   Profile = *pProfile;

   if (iStackDepth == -1)
   {
      iStackDepth = 0;
      cNewLevel = 0;
   }
   else
   {
      // See if this is a lower level function than the current function on
      // the stack.  If so, pop the stack until at the same level
      if (CallStack[iStackDepth].cLevel > cLevel)
      {
         for ( ; CallStack[iStackDepth].cLevel > cLevel; iStackDepth -= 1)
         {
            UpdateProfile(pProfile,
                          CallStack[iStackDepth].Symbol,
                          CallStack[iStackDepth].cInstructions);
            CallStack[iStackDepth-1].cInstructions += CallStack[iStackDepth].cInstructions;
         }
      }

      if (CallStack[iStackDepth].cLevel == cLevel)
      {
         if (!strcmp(CallStack[iStackDepth].Symbol, Symbol))
         {
            // Function hasn't finished executing
            CallStack[iStackDepth].cInstructions += cInstructions;
         }
         else
         {
            // Function finished executing. Save info in Profile
            UpdateProfile(pProfile,
                          CallStack[iStackDepth].Symbol,
                          CallStack[iStackDepth].cInstructions);

            CallStack[iStackDepth-1].cInstructions += CallStack[iStackDepth].cInstructions;
            cNewLevel = iStackDepth;
         }
      }
      else if (CallStack[iStackDepth].cLevel < cLevel)
      {
         // New symbol at higher level
         iStackDepth++;
         cNewLevel = iStackDepth;
      }
   }

   if (cNewLevel != -1)
   {
      // Initialize the new stack element
      strcpy(CallStack[cNewLevel].Symbol , Symbol);
      CallStack[cNewLevel].cInstructions = cInstructions;
      CallStack[cNewLevel].cLevel = cLevel;
   }
}
Пример #5
0
int main(int argc,char** argv)
{
 Nodes       *OSMNodes;
 Segments    *OSMSegments;
 Ways        *OSMWays;
 Relations   *OSMRelations;
 Results     *results[NWAYPOINTS+1]={NULL};
 int          point_used[NWAYPOINTS+1]={0};
 double       point_lon[NWAYPOINTS+1],point_lat[NWAYPOINTS+1];
 index_t      point_node[NWAYPOINTS+1]={NO_NODE};
 double       heading=-999;
 int          help_profile=0,help_profile_xml=0,help_profile_json=0,help_profile_pl=0;
 char        *dirname=NULL,*prefix=NULL;
 char        *profiles=NULL,*profilename=NULL;
 char        *translations=NULL,*language=NULL;
 int          exactnodes=0,reverse=0,loop=0;
 Transport    transport=Transport_None;
 Profile     *profile=NULL;
 Translation *translation=NULL;
 index_t      start_node,finish_node=NO_NODE;
 index_t      join_segment=NO_SEGMENT;
 int          arg,nresults=0;
 waypoint_t   start_waypoint,finish_waypoint=NO_WAYPOINT;
 waypoint_t   first_waypoint=NWAYPOINTS,last_waypoint=1,waypoint;
 int          inc_dec_waypoint=1;

 printf_program_start();

 /* Parse the command line arguments */

 if(argc<2)
    print_usage(0,NULL,NULL);

 /* Get the non-routing, general program options */

 for(arg=1;arg<argc;arg++)
   {
    if(!strcmp(argv[arg],"--version"))
       print_usage(-1,NULL,NULL);
    else if(!strcmp(argv[arg],"--help"))
       print_usage(1,NULL,NULL);
    else if(!strcmp(argv[arg],"--help-profile"))
       help_profile=1;
    else if(!strcmp(argv[arg],"--help-profile-xml"))
       help_profile_xml=1;
    else if(!strcmp(argv[arg],"--help-profile-json"))
       help_profile_json=1;
    else if(!strcmp(argv[arg],"--help-profile-perl"))
       help_profile_pl=1;
    else if(!strncmp(argv[arg],"--dir=",6))
       dirname=&argv[arg][6];
    else if(!strncmp(argv[arg],"--prefix=",9))
       prefix=&argv[arg][9];
    else if(!strncmp(argv[arg],"--profiles=",11))
       profiles=&argv[arg][11];
    else if(!strncmp(argv[arg],"--translations=",15))
       translations=&argv[arg][15];
    else if(!strcmp(argv[arg],"--exact-nodes-only"))
       exactnodes=1;
    else if(!strncmp(argv[arg],"--reverse",9))
      {
       if(argv[arg][9]=='=')
          reverse=atoi(&argv[arg][10]);
       else
          reverse=1;
      }
    else if(!strncmp(argv[arg],"--loop",6))
      {
       if(argv[arg][6]=='=')
          loop=atoi(&argv[arg][7]);
       else
          loop=1;
      }
    else if(!strcmp(argv[arg],"--quiet"))
       option_quiet=1;
    else if(!strcmp(argv[arg],"--loggable"))
       option_loggable=1;
    else if(!strcmp(argv[arg],"--logtime"))
       option_logtime=2;
    else if(!strcmp(argv[arg],"--logmemory"))
       option_logmemory=1;
    else if(!strcmp(argv[arg],"--output-html"))
       option_file_html=1;
    else if(!strcmp(argv[arg],"--output-gpx-track"))
       option_file_gpx_track=1;
    else if(!strcmp(argv[arg],"--output-gpx-route"))
       option_file_gpx_route=1;
    else if(!strcmp(argv[arg],"--output-text"))
       option_file_text=1;
    else if(!strcmp(argv[arg],"--output-text-all"))
       option_file_text_all=1;
    else if(!strcmp(argv[arg],"--output-none"))
       option_file_none=1;
    else if(!strcmp(argv[arg],"--output-stdout"))
      { option_file_stdout=1; option_quiet=1; }
    else if(!strncmp(argv[arg],"--profile=",10))
       profilename=&argv[arg][10];
    else if(!strncmp(argv[arg],"--language=",11))
       language=&argv[arg][11];
    else if(!strcmp(argv[arg],"--shortest"))
       option_quickest=0;
    else if(!strcmp(argv[arg],"--quickest"))
       option_quickest=1;
    else if(!strncmp(argv[arg],"--lon",5) && isdigit(argv[arg][5]))
      {
       int point;
       char *p=&argv[arg][6];

       while(isdigit(*p)) p++;
       if(*p++!='=')
          print_usage(0,argv[arg],NULL);

       point=atoi(&argv[arg][5]);
       if(point>NWAYPOINTS || point_used[point]&1)
          print_usage(0,argv[arg],NULL);

       point_lon[point]=degrees_to_radians(atof(p));
       point_used[point]+=1;

       if(point<first_waypoint)
          first_waypoint=point;
       if(point>last_waypoint)
          last_waypoint=point;
      }
    else if(!strncmp(argv[arg],"--lat",5) && isdigit(argv[arg][5]))
      {
       int point;
       char *p=&argv[arg][6];

       while(isdigit(*p)) p++;
       if(*p++!='=')
          print_usage(0,argv[arg],NULL);

       point=atoi(&argv[arg][5]);
       if(point>NWAYPOINTS || point_used[point]&2)
          print_usage(0,argv[arg],NULL);

       point_lat[point]=degrees_to_radians(atof(p));
       point_used[point]+=2;

       if(point<first_waypoint)
          first_waypoint=point;
       if(point>last_waypoint)
          last_waypoint=point;
      }
    else if(!strncmp(argv[arg],"--heading=",10))
      {
       double h=atof(&argv[arg][10]);

       if(h>=-360 && h<=360)
         {
          heading=h;

          if(heading<0) heading+=360;
         }
      }
    else if(!strncmp(argv[arg],"--transport=",12))
      {
       transport=TransportType(&argv[arg][12]);

       if(transport==Transport_None)
          print_usage(0,argv[arg],NULL);
      }
    else
       continue;

    argv[arg]=NULL;
   }

 /* Check the specified command line options */

 if(option_file_stdout && (option_file_html+option_file_gpx_track+option_file_gpx_route+option_file_text+option_file_text_all)!=1)
   {
    fprintf(stderr,"Error: The '--output-stdout' option requires exactly one other output option (but not '--output-none').\n");
    exit(EXIT_FAILURE);
   }

 if(option_file_html==0 && option_file_gpx_track==0 && option_file_gpx_route==0 && option_file_text==0 && option_file_text_all==0 && option_file_none==0)
    option_file_html=option_file_gpx_track=option_file_gpx_route=option_file_text=option_file_text_all=1;

 /* Load in the selected profiles */

 if(transport==Transport_None)
    transport=Transport_Motorcar;

 if(profiles)
   {
    if(!ExistsFile(profiles))
      {
       fprintf(stderr,"Error: The '--profiles' option specifies a file '%s' that does not exist.\n",profiles);
       exit(EXIT_FAILURE);
      }
   }
 else
   {
    profiles=FileName(dirname,prefix,"profiles.xml");

    if(!ExistsFile(profiles))
      {
       char *defaultprofiles=FileName(ROUTINO_DATADIR,NULL,"profiles.xml");

       if(!ExistsFile(defaultprofiles))
         {
          fprintf(stderr,"Error: The '--profiles' option was not used and the files '%s' and '%s' do not exist.\n",profiles,defaultprofiles);
          exit(EXIT_FAILURE);
         }

       free(profiles);
       profiles=defaultprofiles;
      }
   }

 if(!profilename)
    profilename=(char*)TransportName(transport);

 if(ParseXMLProfiles(profiles,profilename,(help_profile_xml|help_profile_json|help_profile_pl)))
   {
    fprintf(stderr,"Error: Cannot read the profiles in the file '%s'.\n",profiles);
    exit(EXIT_FAILURE);
   }

 profile=GetProfile(profilename);

 if(!profile)
   {
    fprintf(stderr,"Error: Cannot find a profile called '%s' in the file '%s'.\n",profilename,profiles);

    profile=(Profile*)calloc(1,sizeof(Profile));
    profile->transport=transport;
   }

 /* Parse the other command line arguments that modify the profile */

 for(arg=1;arg<argc;arg++)
   {
    if(!argv[arg])
       continue;
    else if(!strncmp(argv[arg],"--highway-",10))
      {
       Highway highway;
       char *equal=strchr(argv[arg],'=');
       char *string;
       double p;

       if(!equal)
           print_usage(0,argv[arg],NULL);

       string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+10);
       string[equal-argv[arg]-10]=0;

       highway=HighwayType(string);

       if(highway==Highway_None)
          print_usage(0,argv[arg],NULL);

       p=atof(equal+1);

       if(p<0 || p>100)
          print_usage(0,argv[arg],NULL);

       profile->highway[highway]=(score_t)(p/100);

       free(string);
      }
    else if(!strncmp(argv[arg],"--speed-",8))
      {
       Highway highway;
       char *equal=strchr(argv[arg],'=');
       char *string;
       double s;

       if(!equal)
          print_usage(0,argv[arg],NULL);

       string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+8);
       string[equal-argv[arg]-8]=0;

       highway=HighwayType(string);

       if(highway==Highway_None)
          print_usage(0,argv[arg],NULL);

       s=atof(equal+1);

       if(s<0)
          print_usage(0,argv[arg],NULL);

       profile->speed[highway]=kph_to_speed(s);

       free(string);
      }
    else if(!strncmp(argv[arg],"--property-",11))
      {
       Property property;
       char *equal=strchr(argv[arg],'=');
       char *string;
       double p;

       if(!equal)
          print_usage(0,argv[arg],NULL);

       string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+11);
       string[equal-argv[arg]-11]=0;

       property=PropertyType(string);

       if(property==Property_None)
          print_usage(0,argv[arg],NULL);

       p=atof(equal+1);

       if(p<0 || p>100)
          print_usage(0,argv[arg],NULL);

       profile->props[property]=(score_t)(p/100);

       free(string);
      }
    else if(!strncmp(argv[arg],"--oneway=",9))
       profile->oneway=!!atoi(&argv[arg][9]);
    else if(!strncmp(argv[arg],"--turns=",8))
       profile->turns=!!atoi(&argv[arg][8]);
    else if(!strncmp(argv[arg],"--weight=",9))
       profile->weight=tonnes_to_weight(atof(&argv[arg][9]));
    else if(!strncmp(argv[arg],"--height=",9))
       profile->height=metres_to_height(atof(&argv[arg][9]));
    else if(!strncmp(argv[arg],"--width=",8))
       profile->width=metres_to_width(atof(&argv[arg][8]));
    else if(!strncmp(argv[arg],"--length=",9))
       profile->length=metres_to_length(atof(&argv[arg][9]));
    else
       print_usage(0,argv[arg],NULL);
   }

 /* Print one of the profiles if requested */

 if(help_profile)
   {
    PrintProfile(profile);

    exit(EXIT_SUCCESS);
   }
 else if(help_profile_xml)
   {
    PrintProfilesXML();

    exit(EXIT_SUCCESS);
   }
 else if(help_profile_json)
   {
    PrintProfilesJSON();

    exit(EXIT_SUCCESS);
   }
 else if(help_profile_pl)
   {
    PrintProfilesPerl();

    exit(EXIT_SUCCESS);
   }

 /* Load in the selected translation */

 if(option_file_html || option_file_gpx_route || option_file_gpx_track || option_file_text || option_file_text_all)
   {
    if(translations)
      {
       if(!ExistsFile(translations))
         {
          fprintf(stderr,"Error: The '--translations' option specifies a file '%s' that does not exist.\n",translations);
          exit(EXIT_FAILURE);
         }
      }
    else
      {
       translations=FileName(dirname,prefix,"translations.xml");

       if(!ExistsFile(translations))
         {
          char *defaulttranslations=FileName(ROUTINO_DATADIR,NULL,"translations.xml");

          if(!ExistsFile(defaulttranslations))
            {
             fprintf(stderr,"Error: The '--translations' option was not used and the files '%s' and '%s' do not exist.\n",translations,defaulttranslations);
             exit(EXIT_FAILURE);
            }

          free(translations);
          translations=defaulttranslations;
         }
      }

    if(ParseXMLTranslations(translations,language,0))
      {
       fprintf(stderr,"Error: Cannot read the translations in the file '%s'.\n",translations);
       exit(EXIT_FAILURE);
      }

    if(language)
      {
       translation=GetTranslation(language);

       if(!translation)
         {
          fprintf(stderr,"Warning: Cannot find a translation called '%s' in the file '%s'.\n",language,translations);
          exit(EXIT_FAILURE);
         }
      }
    else
      {
       translation=GetTranslation("");

       if(!translation)
         {
          fprintf(stderr,"Warning: No translations in '%s'.\n",translations);
          exit(EXIT_FAILURE);
         }
      }
   }

 /* Check the waypoints are valid */

 for(waypoint=1;waypoint<=NWAYPOINTS;waypoint++)
    if(point_used[waypoint]==1 || point_used[waypoint]==2)
       print_usage(0,NULL,"All waypoints must have latitude and longitude.");

 if(first_waypoint>=last_waypoint)
    print_usage(0,NULL,"At least two waypoints must be specified.");

 /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */

 if(!option_quiet)
    printf_first("Loading Files:");

 OSMNodes=LoadNodeList(FileName(dirname,prefix,"nodes.mem"));

 OSMSegments=LoadSegmentList(FileName(dirname,prefix,"segments.mem"));

 OSMWays=LoadWayList(FileName(dirname,prefix,"ways.mem"));

 OSMRelations=LoadRelationList(FileName(dirname,prefix,"relations.mem"));

 if(!option_quiet)
    printf_last("Loaded Files: nodes, segments, ways & relations");

 /* Check the profile is valid for use with this database */

 if(UpdateProfile(profile,OSMWays))
   {
    fprintf(stderr,"Error: Profile is invalid or not compatible with database.\n");
    exit(EXIT_FAILURE);
   }

 /* Find all waypoints */

 for(waypoint=first_waypoint;waypoint<=last_waypoint;waypoint++)
   {
    distance_t distmax=km_to_distance(MAXSEARCH);
    distance_t distmin;
    index_t segment=NO_SEGMENT;
    index_t node1,node2,node=NO_NODE;

    if(point_used[waypoint]!=3)
       continue;

    /* Find the closest point */

    if(!option_quiet)
       printf_first("Finding Closest Point: Waypoint %d",waypoint);

    if(exactnodes)
       node=FindClosestNode(OSMNodes,OSMSegments,OSMWays,point_lat[waypoint],point_lon[waypoint],distmax,profile,&distmin);
    else
      {
       distance_t dist1,dist2;

       segment=FindClosestSegment(OSMNodes,OSMSegments,OSMWays,point_lat[waypoint],point_lon[waypoint],distmax,profile,&distmin,&node1,&node2,&dist1,&dist2);

       if(segment!=NO_SEGMENT)
          node=CreateFakes(OSMNodes,OSMSegments,waypoint,LookupSegment(OSMSegments,segment,1),node1,node2,dist1,dist2);
      }

    if(!option_quiet)
       printf_last("Found Closest Point: Waypoint %d",waypoint);

    if(node==NO_NODE)
      {
       fprintf(stderr,"Error: Cannot find node close to specified point %d.\n",waypoint);
       exit(EXIT_FAILURE);
      }

    if(!option_quiet)
      {
       double lat,lon;

       if(IsFakeNode(node))
          GetFakeLatLong(node,&lat,&lon);
       else
          GetLatLong(OSMNodes,node,NULL,&lat,&lon);

       if(IsFakeNode(node))
          printf("Waypoint %d is segment %"Pindex_t" (node %"Pindex_t" -> %"Pindex_t"): %3.6f %4.6f = %2.3f km\n",waypoint,segment,node1,node2,
                 radians_to_degrees(lon),radians_to_degrees(lat),distance_to_km(distmin));
       else
          printf("Waypoint %d is node %"Pindex_t": %3.6f %4.6f = %2.3f km\n",waypoint,node,
                 radians_to_degrees(lon),radians_to_degrees(lat),distance_to_km(distmin));
      }

    point_node[waypoint]=node;
   }

 /* Check for reverse direction */

 if(reverse)
   {
    waypoint_t temp;

    temp=first_waypoint;
    first_waypoint=last_waypoint;
    last_waypoint=temp;

    inc_dec_waypoint=-1;
   }

 /* Loop through all pairs of waypoints */

 if(loop && reverse)
   {
    finish_node=point_node[last_waypoint];

    finish_waypoint=last_waypoint;
   }

 for(waypoint=first_waypoint;waypoint!=(last_waypoint+inc_dec_waypoint);waypoint+=inc_dec_waypoint)
   {
    if(point_used[waypoint]!=3)
       continue;

    start_node=finish_node;
    finish_node=point_node[waypoint];

    start_waypoint=finish_waypoint;
    finish_waypoint=waypoint;

    if(start_node==NO_NODE)
       continue;

    if(heading!=-999 && join_segment==NO_SEGMENT)
       join_segment=FindClosestSegmentHeading(OSMNodes,OSMSegments,OSMWays,start_node,heading,profile);

    /* Calculate the route */

    if(!option_quiet)
       printf("Routing from waypoint %d to waypoint %d\n",start_waypoint,finish_waypoint);

    results[nresults]=CalculateRoute(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,start_node,join_segment,finish_node,start_waypoint,finish_waypoint);

    if(!results[nresults])
       exit(EXIT_FAILURE);

    join_segment=results[nresults]->last_segment;

    nresults++;
   }

 if(loop && !reverse)
   {
    start_node=finish_node;
    finish_node=point_node[first_waypoint];

    start_waypoint=finish_waypoint;
    finish_waypoint=first_waypoint;

    /* Calculate the route */

    if(!option_quiet)
       printf("Routing from waypoint %d to waypoint %d\n",start_waypoint,finish_waypoint);

    results[nresults]=CalculateRoute(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,start_node,join_segment,finish_node,start_waypoint,finish_waypoint);

    if(!results[nresults])
       exit(EXIT_FAILURE);

    nresults++;
   }

 if(!option_quiet)
   {
    printf("Routed OK\n");
    fflush(stdout);
   }

 /* Print out the combined route */

 if(!option_quiet)
    printf_first("Generating Result Outputs");

 if(!option_file_none)
    PrintRoute(results,nresults,OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,translation);

 if(!option_quiet)
    printf_last("Generated Result Outputs");

 /* Destroy the remaining results lists and data structures */

#ifdef DEBUG_MEMORY_LEAK

 for(waypoint=0;waypoint<nresults;waypoint++)
    FreeResultsList(results[waypoint]);

 DestroyNodeList(OSMNodes);
 DestroySegmentList(OSMSegments);
 DestroyWayList(OSMWays);
 DestroyRelationList(OSMRelations);

 FreeXMLProfiles();

 FreeXMLTranslations();

#endif

 if(!option_quiet)
    printf_program_end();

 exit(EXIT_SUCCESS);
}