The simplest way to use the server once it is initialized is to calculate mileage between two places. For example, calculating the miles between “Chicago IL” and “Philadelphia PA”. 


Here is the function that calculates the distance between two places:


HRESULT PCRSCalcTrip (Trip trip, char *orig, char *origRR, char *origGeo, char *dest, char *destRR, char *destGeo, long *pMiles)


Example:


if (0 != (srvRet =
   PCRSCalcTrip(myTrip, "CHICAGO IL", "NS", "C",
      "PHILADELPHIA PA", "NS", "C", &miles_tenths)))
   printf("Trip error: %d\n", srvRet);
else
{
   miles = (float) miles_tenths / 10;
   printf(buf, "CHICAGO IL to PHILADELPHIA is %3.1f miles.", miles);
}


PCRSCalcTrip() returns the distance between orig and dest (in tenths of miles/kms) in the pointer pMiles. Trip calculation is based on the default options or whatever route options have been previously specified (see Changing Options). Since the distance is returned as tenths of miles, your application should divide the result by 10 to obtain a floating point representation of miles. The RR fields in the function calls take 4-char SCAC codes such as ‘CN’ and ‘BNSF’.  The orig/destGeo fields denote how the station name is entered (SPLC, FSAC, 3-3-3, or R260).


Before calculating distances, you can validate your place names using the function PCRSGeoLookup(). It will place the number of matching places in the PC*MILER Rail database in the numMatches variable passed in. The function returns 0 on success, or a negative error code otherwise (as do all the DLL functions).


HRESULT PCRSGeoLookup(Trip trip, char *placeName, char *placeCode, char *RR, int *numMatches)


The following example shows how to calculate the distance between “Chicago IL” and “Philadelphia PA” on Norfolk Southern  (NS).


void RunRoute()
{
  long tmiles;
  Trip myTrip;
  int matches;

  /* Note: Server must already be initialized. */
  // Create a new trip:
  if (0 != (srvRet = PCRSNewTrip (&myTrip)))
  {
     // Handle Trip Creation Error here
  }
 
  /* All subsequent err handling blocks have been 
    omitted for brevity */

  // Optional: Set routing options
  srvRet = PCRSSetRouteFormula (myTrip, "P"); // Practical
    srvRet = PCRSSetRouteMethod (myTrip, "N");  // Non-Familized
    srvRet = PCRSSetRouteType (myTrip, "I"); // Interactive

  /* Calculate the same trip using shortest distance */
  srvRet = PCRSSetRouteFormula (myTrip, "S"); // Shortest
  srvRet = PCRSCalcTrip (myTrip, "Chicago IL", "NS", 
        "C", "Philadelphia PA", "NS", "C", &tmiles);
  printf("Shortest miles: %f\n", tmiles / 10.0);

/* Calculate the same trip using Coal/Bulk routing */
  srvRet = PCRSSetRouteFormula (myTrip, "C"); // Coal/Bulk
  srvRet = PCRSCalcTrip (myTrip, "Chicago IL", "NS", 
         "C", "Philadelphia PA", "NS", "C", &tmiles);
  printf("Bulk miles: %f\n", tmiles / 10.0);

  /* Calc Practical miles between Seattle / Philly: */
  /* This determines junctions between RRs and chooses */
  /* route w/ least non-family jcns + lowest miles */
  srvRet = PCRSSetRouteFormula (myTrip, "P");
  srvRet = PCRSSetRouteType (myTrip, "A"); // AutoRouting
  srvRet = PCRSCalcTrip (myTrip, "Seattle WA", "BNSF", 
      "C", "Philadelphia PA", "CSXT", "C", &tmiles);
  printf("Seattle->Philly miles: %f\n", tmiles / 10.0);

/* Check for place name matches for Seattle WA on BNSF */
  srvRet = PCRSGeoLookup (myTrip, "Seattle WA", "C",
        "BNSF", &matches);
  printf("Matching places in PC*MILER|Rail database: %d\n", 
      matches);
       }