int main(int argc, char **argv)
{
  SHAPEFILE *sha;
  SHAPEFILE_RECORD *rec;
  PROJECTION *proj;

  int rc;
  int i, max;

  DBUG_ENTER("main");
  DBUG_PROCESS(argv[0]);
  DBUG_PUSH("d:t");

  if(argc != 2)
  {
    printf("usage %s <shapefile>\n", argv[0]);
    DBUG_RETURN(-1);
  }

  if(!(sha = shapefile_init(0)))
  {
    printf("Couldn't init\n");
    DBUG_RETURN(-2);
  }

  if((rc= shapefile_open(sha, argv[1], 'r')) < 0)
  {
    printf("Couldn't open\n");
    DBUG_RETURN(-3);
  }

  proj = projection_init();

  if(sha->flags & SHAPEFILE_HAS_PRJ)
  {
    projection_set(proj, sha->prj->proj4_def, "+proj=latlong");
    shapefile_set_projection(sha, proj);
  }

  shapefile_dump(sha);

  max = sha->dbf->numrecords < 100 ? sha->dbf->numrecords : 100;

  for(i=1; i<max; i+=10)
  {
    shapefile_seek_record(sha, i);
    if((rec = shapefile_read_next(sha)))
    {
      shapefile_record_dump(rec);
      shapefile_record_free(rec);
    } else {
      printf("Error reading record\n");
      return 4;
    }
    printf("\n\n\n");
  }

  shapefile_close(sha);
  shapefile_free(sha);

  DBUG_RETURN(0);
}
Esempio n. 2
0
int main(int argc, char *argv[])
{	 
	// Set the translation part to be the identity.
	locked_matrix[3][0] = locked_matrix[3][1] = locked_matrix[3][2] = 0;
	locked_matrix[0][3] = locked_matrix[1][3] = locked_matrix[2][3] = 0;
	locked_matrix[3][3] = 1;

	locked_matrix[0][0] = locked_matrix[1][1] = locked_matrix[2][2] = 1;
	locked_matrix[0][1] = locked_matrix[1][0] = locked_matrix[2][0] = locked_matrix[0][2]= locked_matrix[2][1] = locked_matrix[1][2]=0;
	
	memcpy(&final_matrix,locked_matrix[0],sizeof last_matrix);

	try
	{
		
		bcm_host_init();
		opengl_init();
		projection_init();
		textures_init();
		model_board_init();
		printf("AHRS Textures loaded\n");
		fflush(stdout);
		
		uint32_t time_start = 0;
		int missed = 0;
		uint32_t time_fps = 0;
		int fps = 0;
		uint32_t time_delay = 0;
			
		//non blocking sdtin read
		fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK);
	
		while(1)
		{			
	
			time_start += 20;
			uint32_t predicted_delay = time_start - millis(); //calc predicted delay
			if (predicted_delay > 20) predicted_delay = 0; //check for overflow
			if (predicted_delay != 0){
				delay(predicted_delay); 
				time_delay += predicted_delay;
			}else{
				time_start = millis(); //reset timer to now
				printf("AHRS Skipping Idle...\n");
				missed++;
			}

			int count = 1;
			char buffer[100];
			//stdin is line buffered so we can cheat a little bit
			while (count > 0){ // dump entire buffer
				count = read(STDIN_FILENO, buffer, sizeof(buffer));
				if (count > 1){ //ignore blank lines
					buffer[count-1] = '\0'; //replace last char with string ending
					//printf("!%s!\n",buffer);
					//check the line
					int temp[4];
					
					int result = sscanf(buffer,"%d %d %d", &temp[0], &temp[1],  &temp[2]);
					if (result != 3){
						fprintf(stderr, "AHRS Unrecognized input with %d items.\n", result);
					}else{
						acceleration[0] = temp[1];
						acceleration[1] = temp[2];
						acceleration[2] = 0;
						frame = temp[0];
					}
					
				}
			}
			if (state != frame){
				printf("AHRS Entering Mode %d\n",frame);
				state = frame;
				changes++;
			}	
			redraw_scene();

			fps++;
			if (time_fps < millis()){
				printf("AHRS FPS:%d  mis:%d idle:%d%% changes:%d\n",fps,missed,time_delay/10, changes);
				fps = 0;
				time_delay = 0;
				time_fps += 1000;
				if (time_fps < millis()) time_fps = millis()+1000;	
			}		
			
		}
		
		opengl_deinit();
		bcm_host_deinit();
		return 0;
	}
	catch(const std::exception & error)
	{
		std::cerr << "Error: " << error.what() << std::endl;
		exit(9);
	}
}