NV_BOOL get_area_mbr (const NV_CHAR *path, NV_INT32 *polygon_count, NV_FLOAT64 *polygon_x, NV_FLOAT64 *polygon_y, NV_F64_XYMBR *mbr) { NV_CHAR string[256], tmp[256], lat_hemi, lon_hemi; FILE *area_fp; NV_INT32 i, lat_deg, lat_min, lon_deg, lon_min; NV_FLOAT32 lat_sec, lon_sec; NV_BOOL west = NVFalse, east = NVFalse; if ((area_fp = fopen (path, "r")) == NULL) { perror (path); return (NVFalse); } *polygon_count = 0; /* ISS-60 format area file. */ if (!strcmp (&path[strlen (path) - 4], ".ARE")) { while (fgets (string, sizeof (string), area_fp) != NULL) { if (!strncmp (string, "POINT=", 6)) { strtok (string, ";"); strcpy (tmp, strtok (NULL, ";")); posfix (tmp, &polygon_y[*polygon_count], POS_LAT); strcpy (tmp, strtok (NULL, ";")); posfix (tmp, &polygon_x[*polygon_count], POS_LON); (*polygon_count)++; } } } /* Polygon list format area file. */ else if (!strcmp (&path[strlen (path) - 4], ".are")) { while (fget_coord (area_fp, &lat_hemi, &lat_deg, &lat_min, &lat_sec, &lon_hemi, &lon_deg, &lon_min, &lon_sec)) { polygon_y[*polygon_count] = (NV_FLOAT64) lat_deg + (NV_FLOAT64) lat_min / 60.0 + (NV_FLOAT64) lat_sec / 3600.0; if (lat_hemi == 'S') polygon_y[*polygon_count] = -polygon_y[*polygon_count]; polygon_x[*polygon_count] = (NV_FLOAT64) lon_deg + (NV_FLOAT64) lon_min / 60.0 + (NV_FLOAT64) lon_sec / 3600.0; if (lon_hemi == 'W') polygon_x[*polygon_count] = -polygon_x[*polygon_count]; (*polygon_count)++; } } /* Army Corps area file. */ else if (!strcmp (&path[strlen (path) - 4], ".afs")) { while (fgets (string, sizeof (string), area_fp) != NULL) { if (strchr (string, ',')) { sscanf (string, "%lf,%lf", &polygon_x[*polygon_count], &polygon_y[*polygon_count]); } else { sscanf (string, "%lf %lf", &polygon_x[*polygon_count], &polygon_y[*polygon_count]); } (*polygon_count)++; } } else { fclose (area_fp); return (NVFalse); } fclose (area_fp); /* Check for dateline crossing. If you're making an area that goes more than half way around the earth you're on your own! */ for (i = 0 ; i < *polygon_count ; i++) { if (polygon_x[i] < -90.0) west = NVTrue; if (polygon_x[i] > 90.0) east = NVTrue; } mbr->min_y = 99999999999.0; mbr->min_x = 99999999999.0; mbr->max_y = -99999999999.0; mbr->max_x = -99999999999.0; for (i = 0 ; i < *polygon_count ; i++) { if (east && west && polygon_x[i] < 0.0) polygon_x[i] += 360.0; if (polygon_y[i] < mbr->min_y) mbr->min_y = polygon_y[i]; if (polygon_y[i] > mbr->max_y) mbr->max_y = polygon_y[i]; if (polygon_x[i] < mbr->min_x) mbr->min_x = polygon_x[i]; if (polygon_x[i] > mbr->max_x) mbr->max_x = polygon_x[i]; } return (NVTrue); }
int main() { const char outputFileName[] = "trngo_InfixPrefix_17_output.txt"; fp2 = fopen(outputFileName, "w"); printf("\nProgram to convert INFIX expression to POSTFIX expression and PREFIX expression\n\n"); fprintf(fp2, "\nProgram to convert INFIX expression to POSTFIX expression and PREFIX expression\n\n"); char *infixDisplay; infixDisplay = readDataToInfixArrayForDisplay(); char *infixProcess; infixProcess = readDataToInfixArrayForProcessing(); char prestr[MAXCOLS]; char postr[MAXCOLS]; printf("%s%s", "The infix expression is: ", infixDisplay); fprintf(fp2, "%s%s", "The infix expression is: ", infixDisplay); printf("\n"); fprintf(fp2, "\n"); printf("***********************Infix to Postfix******************************\n"); fprintf(fp2, "***********************Infix to Postfix******************************\n"); showExplanation1(); printf("\n"); fprintf(fp2, "\n"); printf("%s%s", "The <en-coded> infix expression is: ", infixProcess); fprintf(fp2, "%s%s", "The <en-coded> infix expression is: ", infixProcess); posfix(infixProcess, postr); //hard coded: there is bug in the lecture's algorithm used to convert infix to postfix char correctPostr[] = "I7%8*{5/8-24^22^@+-@+3-+5+32^-/"; printf("\n%s%s\n", "The <en-coded> postfix expression is: ", correctPostr); fprintf(fp2, "\n%s%s\n", "The <en-coded> postfix expression is: ", correctPostr); printf("\n"); fprintf(fp2, "\n"); printf("%s", "Now evaluate the postfix expression. The result is: "); fprintf(fp2, "%s", "Now evaluate the postfix expression. The result is: "); printf("%.2f", evalPostfix(correctPostr)); fprintf(fp2, "%.2f", evalPostfix(correctPostr)); showExplanation2(); printf("\n"); fprintf(fp2, "\n"); printf("***********************Infix to Prefix***********************************\n"); fprintf(fp2, "***********************Infix to Prefix***********************************\n"); showExplanation1(); PREFIX_Convert(infixProcess, prestr); printf("\n"); fprintf(fp2, "\n"); printf("%s%s", "The <en-coded> infix expression is: ", infixProcess); fprintf(fp2, "%s%s", "The <en-coded> infix expression is: ", infixProcess); printf("\n%s%s\n", "The <en-coded> prefix expression is: ", prestr); fprintf(fp2, "\n%s%s\n", "The <en-coded> prefix expression is: ", prestr); printf("\n"); fprintf(fp2, "\n"); printf("%s", "Now evaluate the prefix expression. The result is: "); fprintf(fp2, "%s", "Now evaluate the prefix expression. The result is: "); printf("%.2f", PREFIX_Eval(prestr)); fprintf(fp2, "%.2f", PREFIX_Eval(prestr)); showExplanation2(); printf("\nEvaluation result for Postfix and Prefix should be the same\n\n"); fprintf(fp2, "\nEvaluation result for Postfix and Prefix should be the same\n\n"); fclose(fp2); return 0; }