/* --------------------------------------------------------------------------- Jason II Mosaic Navigation (JaMN) Extraction Utility. written by C R Young last updated 9/27/06 Copyright (C) 2006 C R Young This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . INTELLECTUAL PROPERTY You may do anything you like with this code, including, but not limited to, printing it out and pitching it over the side of the boat. LEGAL DISCLAIMER By using this code you agree that I am in no way responsible for any damages that may befall you due to my incompetence, negligence, or any other nasty thing that you acuse me of. Afterall, you could do this by hand. ---------------------------------------------------------------------------*/ #include #include #include #include #define MAXSTR 80 #define MAXPICS 1000 #define MAXLINE 10000 #define MAXLINES 1 #define MAXFIELD 100 #define MAXFILES 25 #define MAXDIVES 100 #define CHECKTAGSIZE 8 struct NavData { char date[MAXSTR]; char time[MAXSTR]; double localX; double localY; double Lat; double Lon; double UTMX; double UTMY; double depth; double pitch; double heading; double roll; double altitude; int Switch; }; /* My error message */ void MyError(error_text) char error_text[]; { fprintf(stderr,"\nRY's run-time error...\n"); fprintf(stderr,"\n\t%s\n",error_text); fprintf(stderr,"\n...now exiting to system...\n\n"); exit(1); } main (int argc, char *argv[]) { FILE *fptr, *Nav_data, *Pics, *Dive_trac; int i, j, end, countline, Numpics, match, thin, pos; struct NavData Data; int matchcount, thincount, picnum; char Pic_list[MAXPICS][MAXSTR], check[2]; char date[MAXSTR], dum[MAXSTR]; char time[MAXSTR]; float localX; float localY; float Lat; float Lon; float UTMX; float UTMY; float depth; float pitch; float heading; float roll; float altitude; /*********************/ /* Begin read files */ /*********************/ if( argc > 3 || argc < 3) { printf("usage: JaMN [navigation data file] [thinning interval (secs.)]\n"); exit(1) ; } thin = atoi(argv[2]); /* Read filelist */ Pics = fopen ("files.txt", "r"); if (!Pics) { printf ( "Error opening file!\nCould not read files.txt...\n"); MyError("Required file not found!\n"); } end = 0; Numpics = 0; printf("\nFiles in directory:\n"); while (end == 0) { if(end == 0){ fscanf(Pics,"%s", &Pic_list[Numpics]); end = feof(Pics); if(end == 0){ printf( "%s\n", Pic_list[Numpics]); } Numpics += 1; } } printf("\nScanning file. Please wait...\n"); Numpics -= 1; if(fclose(Pics) != 0) MyError("Could not close input file: files.txt.\n"); /* "open" files for reading / writing */ fptr = fopen (argv[1], "r"); // navigation data file Nav_data = fopen ("Nav_data.csv", "w"); // navigation output file Dive_trac = fopen ("Dive_trac.csv", "w"); // navigation output file /* Printing headers in output files */ fprintf(Nav_data, "file,date,time,localX,localY,Lat,Lon,UTMX,UTMY,depth,pitch,heading,roll,altitude\n"); fprintf(Dive_trac, "date,time,localX,localY,Lat,Lon,UTMX,UTMY,depth,pitch,heading,roll,altitude\n"); for(i=0; i<13; i++) { fscanf(fptr, "%s", &dum); } end = 0; countline = 1; thincount = 1; picnum = 0; /*********************************************/ /* Main loop reading through navigation data */ /*********************************************/ while( end == 0){ /* Force end of file read, then push chars back into stack */ for(i=0; i<2; i++){ check[i] = getc(fptr); end = feof(fptr); } for(i=1; i>-1; i--){ ungetc(check[i],fptr); } /* Read line */ if(end == 0 ) { fscanf(fptr, "%s", &date); fscanf(fptr, "%s", &time); fscanf(fptr, "%f", &localX); fscanf(fptr, "%f", &localY); fscanf(fptr, "%f", &Lat); fscanf(fptr, "%f", &Lon); fscanf(fptr, "%f", &UTMX); fscanf(fptr, "%f", &UTMY); fscanf(fptr, "%f", &depth); fscanf(fptr, "%f", &pitch); fscanf(fptr, "%f", &heading); fscanf(fptr, "%f", &roll); fscanf(fptr, "%f", &altitude); /**********************************/ /* Print data to dive track file */ /**********************************/ if(thincount == thin){ fprintf(Dive_trac, "%s,", date); fprintf(Dive_trac, "%s,", time); fprintf(Dive_trac, "%.2f,", localX); fprintf(Dive_trac, "%.2f,", localY); fprintf(Dive_trac, "%.6f,", Lat); fprintf(Dive_trac, "%.6f,", Lon); fprintf(Dive_trac, "%.2f,", UTMX); fprintf(Dive_trac, "%.2f,", UTMY); fprintf(Dive_trac, "%.2f,", depth); fprintf(Dive_trac, "%.2f,", pitch); fprintf(Dive_trac, "%.2f,", heading); fprintf(Dive_trac, "%.2f,", roll); fprintf(Dive_trac, "%.6f\n", altitude); thincount = 0; } thincount += 1; /**********************************/ /* Print data to output nav file */ /**********************************/ // Match date and time match = 1; // check date // year for (pos=0; pos < 4; pos++){ if(date[pos] != Pic_list[picnum][pos]){ match = 0; } } // month for (pos=5; pos < 7; pos++){ if(date[pos] != Pic_list[picnum][pos]){ match = 0; } } // day for (pos=8; pos < 10; pos++){ if(date[pos] != Pic_list[picnum][pos]){ match = 0; } } // check time // hour for (pos=0; pos < 2; pos++){ if(time[pos] != Pic_list[picnum][pos+11]){ match = 0; } } // min for (pos=3; pos < 5; pos++){ if(time[pos] != Pic_list[picnum][pos+11]){ match = 0; } } // sec for (pos=6; pos < 8; pos++){ if(time[pos] != Pic_list[picnum][pos+11]){ match = 0; } } if(match == 1){ fprintf(Nav_data, "%s,", Pic_list[picnum]); date[4] = '_'; date[7] = '_'; fprintf(Nav_data, "%s,", date); time[2] = '_'; time[5] = '_'; fprintf(Nav_data, "%s,", time); fprintf(Nav_data, "%.2f,", localX); fprintf(Nav_data, "%.2f,", localY); fprintf(Nav_data, "%.6f,", Lat); fprintf(Nav_data, "%.6f,", Lon); fprintf(Nav_data, "%.2f,", UTMX); fprintf(Nav_data, "%.2f,", UTMY); fprintf(Nav_data, "%.2f,", depth); fprintf(Nav_data, "%.2f,", pitch); fprintf(Nav_data, "%.2f,", heading); fprintf(Nav_data, "%.2f,", roll); fprintf(Nav_data, "%.6f\n", altitude); picnum += 1; } // printf( "%s,", date); // printf( "%s\n", time); countline += 1; // end = feof(fptr); } /* END IF ENDFILE */ // end = feof(fptr); } /* END WHILE ENDFILE */ printf("\nNumber of lines in database file: %d\n\n", countline-1); /* Close all files */ if(fclose(fptr) != 0) MyError("Could not close file: INFILE.\n"); if(fclose(Nav_data) != 0) { MyError("Could not close output file.\n"); } if(fclose(Dive_trac) != 0) { MyError("Could not close output file.\n"); } }