Example #1
0
BOOL LASreaderQFIT::open(ByteStreamIn* stream)
{
  U32 i;

  if (stream == 0)
  {
    fprintf(stderr,"ERROR: ByteStreamIn* pointer is zero\n");
    return FALSE;
  }

  this->stream = stream;

  // read the QFIT header

  try { stream->get32bitsLE((U8*)&version); } catch(...)
  {
    fprintf(stderr,"ERROR: reading QFIT header\n");
    return FALSE;
  }

  // is QFIT file little-endian

  if (version == 40 || version == 48 || version == 56)
  {
    little_endian = TRUE;
    endian_swap = (IS_LITTLE_ENDIAN() == FALSE);
  }
  else
  {
    ENDIAN_SWAP_32((U8*)&version);
    if (version == 40 || version == 48 || version == 56)
    {
      little_endian = FALSE;
      endian_swap = (IS_LITTLE_ENDIAN() == TRUE);
    }
    else
    {
      fprintf(stderr,"ERROR: corrupt QFIT header.\n");
      return FALSE;
    }
  }

  // read version bytes until point start offset

  try { stream->getBytes((U8*)buffer, version); } catch(...)
  {
    fprintf(stderr,"ERROR: reading %d bytes until point start offset from QFIT header\n", version);
    return FALSE;
  }

  // read point start offset

  try { if (little_endian) stream->get32bitsLE((U8*)&offset); else stream->get32bitsBE((U8*)&offset); } catch(...)
  {
    fprintf(stderr,"ERROR: reading point start offset from QFIT header\n");
    return FALSE;
  }

  // seek to end of file find out number of points

  stream->seekEnd();
  npoints = (stream->tell() - offset) / version;

  // seek back to start of points

  stream->seek(offset);

  // populate the header as much as possible

  sprintf(header.system_identifier, "LAStools (c) by Martin Isenburg");
  sprintf(header.generating_software, "via LASreaderQFIT (%d)", LAS_TOOLS_VERSION);

  header.number_of_point_records = (U32)npoints;
  header.number_of_points_by_return[0] = header.number_of_point_records;

  header.extended_number_of_point_records = npoints;
  header.extended_number_of_points_by_return[0] = npoints;

  header.x_scale_factor = 0.000001;
  header.y_scale_factor = 0.000001;
  header.z_scale_factor = 0.001;
  header.x_offset = 0;
  header.y_offset = 0;
  header.z_offset = 0;

  try { 
    LASattribute scan_azimuth(LAS_ATTRIBUTE_I32, "scan azimuth", "Scan Azimuth (degrees X 1,000)");
    scan_azimuth.set_scale(0.001);
    scan_azimuth.set_min(0);
    scan_azimuth.set_max(360000);
    header.add_extra_attribute(scan_azimuth);
  }
  catch(...) {
    fprintf(stderr,"ERROR: initializing attribute scan_azimuth\n");
    return FALSE;
  }


  try { 
    LASattribute pitch(LAS_ATTRIBUTE_I32, "pitch", "Pitch (degrees X 1,000)");
    pitch.set_scale(0.001);
    pitch.set_min(-90000);
    pitch.set_max(90000);
    header.add_extra_attribute(pitch);
  }
  catch(...) {
    fprintf(stderr,"ERROR: initializing attribute pitch\n");
    return FALSE;
  }


  try { 
    LASattribute roll(LAS_ATTRIBUTE_I32, "roll", "Roll (degrees X 1,000)");
    roll.set_scale(0.001);
    roll.set_min(-90000);
    roll.set_max(90000);
    header.add_extra_attribute(roll);
  }
  catch(...) {
    fprintf(stderr,"ERROR: initializing attribute roll\n");
    return FALSE;
  }

  if (version == 48)
  {
    try { 
      LASattribute pulse_width(LAS_ATTRIBUTE_U8, "pulse width", "Pulse Width (digitizer samples)");
      header.add_extra_attribute(pulse_width);
    }
    catch(...) {
      fprintf(stderr,"ERROR: initializing attribute pulse width\n");
      return FALSE;
    }
  }

  header.update_extra_bytes_vlr();

  // set point type

  header.point_data_format = 1;
  header.point_data_record_length = 28 + header.get_total_extra_attributes_size();

  // initialize point

  point.init(&header, header.point_data_format, header.point_data_record_length, &header);

  // initialize extra attribute offsets

  scan_azimuth_array_offset = point.attributer->get_extra_attribute_array_offset("scan azimuth");
  pitch_array_offset = point.attributer->get_extra_attribute_array_offset("pitch");
  roll_array_offset = point.attributer->get_extra_attribute_array_offset("roll");
  if (version == 48)
  {
    pulse_width_array_offset = point.attributer->get_extra_attribute_array_offset("pulse width");
  }

  // set point count to zero

  p_count = 0;

  // approximate bounding box init

  populated_header = FALSE;

  if (!read_point()) return FALSE;

  header.min_x = header.max_x = point.get_x();
  header.min_y = header.max_y = point.get_y();
  header.min_z = header.max_z = point.get_z();

  for (i = header.number_of_point_records/50; i < header.number_of_point_records; i += header.number_of_point_records/50)
  {
    if (!seek(i)) return FALSE;
    if (!read_point()) return FALSE;
  }

  return seek(0);
}
Example #2
0
int main(int argc, char *argv[])
{
	unsigned freq=0;
	float time = 0;
	unsigned BASE = 0xFCA0;
	unsigned count = 0;
	CLRSCR();
	BASE=AskForBaseAddress(BASE);
	CLRSCR();
	count=AskForCountAddress(); //get counter offset
	BASE+=count;                //add counter offset to base address
	DELAY(100);
	PUTS("8254 Counter Sample");
	PUTS("--This program measures frequency and pulse width and generates frequency.");
	PUTS("--To measure frequency, connect a source to Clk IN on Pin 33.");
	PUTS("");
	PUTS("Press any key to continue.");
	getch();
	while(!kbhit()){
	  freq = freq;
	  time = frequency_measure(BASE);
	  printf("\nThe frequency is %10.3f\n\n", time);
	  PUTS("Press any key to continue to pulse width test.");
	  GOTOXY(1,WHEREY()-4);
	}
	getch();
	CLRSCR();                //is this correct???
	PUTS("--To measure pulse width, connect a source to Gate 1 on Pin 34.");
	PUTS("--Without a source, pulse width will read zero.");
	PUTS("--Ground Pin 37.");
	PUTS("");
	PUTS("Press any key to continue.");
	getch();
	while(!kbhit()){
	  time = pulse_width(BASE);
	  printf(" Pulse1 %g \n", time);
	  DELAY(1000);
	  time = pulse_width(BASE);
	  printf(" Pulse2 %g \n", time);
	  DELAY(397);
	  time = pulse_width(BASE);
	  printf(" Pulse3 %g \n", time);
	  time = pulse_width(BASE);
	  printf(" Pulse4 %g \n", time);
	  DELAY(300);
	  time = pulse_width(BASE);
	  printf(" Pulse5 %g \n", time);
	  DELAY(10);
	  time = pulse_width(BASE);
	  printf(" Pulse6 %g \n\n", time);
	  PUTS("Press any key to continue to next test.");
	  GOTOXY(1,WHEREY()-8);
  }
  getch();
  CLRSCR();
  while(!kbhit()){
	 PUTS("Generating frequency...");
	 PUTS("Verify signal by connecting a frequency meter to Out 2 on Pin 35.");
	 PUTS("Press any key to continue.");
	 generatefrequency(BASE, 25000);
	 GOTOXY(1,WHEREY()-3);
  }
  getch();
	//DELAY(2000);
}