49 if (this->file) this->file =
file;
56 return open(out, header, compressor, requested_version, chunk_size);
63 fprintf(stderr,
"ERROR: file name pointer is zero\n");
67 file = fopen(file_name,
"wb");
70 fprintf(stderr,
"ERROR: cannot open file '%s'\n", file_name);
74 if (setvbuf(
file,
NULL, _IOFBF, io_buffer_size) != 0)
76 fprintf(stderr,
"WARNING: setvbuf() failed with buffer size %u\n", io_buffer_size);
85 return open(out, header, compressor, requested_version, chunk_size);
92 fprintf(stderr,
"ERROR: file pointer is zero\n");
99 if(_setmode( _fileno( stdout ), _O_BINARY ) == -1 )
101 fprintf(stderr,
"ERROR: cannot set stdout to binary (untranslated) mode\n");
112 return open(out, header, compressor, requested_version, chunk_size);
123 return open(out, header, compressor, requested_version, chunk_size);
132 fprintf(stderr,
"ERROR: ByteStreamOut pointer is zero\n");
139 fprintf(stderr,
"ERROR: LASheader pointer is zero\n");
158 U8 point_data_format;
159 U16 point_data_record_length;
164 point_is_standard = header->
laszip->
is_standard(&point_data_format, &point_data_record_length);
176 U32 laszip_vlr_data_size = 0;
177 if (compressor || point_is_standard ==
FALSE)
183 else if (requested_version) laszip->
request_version(requested_version);
185 laszip_vlr_data_size = 34 + 6*laszip->
num_items;
208 fprintf(stderr,
"ERROR: writing header->file_signature\n");
213 fprintf(stderr,
"ERROR: writing header->file_source_id\n");
218 fprintf(stderr,
"ERROR: writing header->global_encoding\n");
223 fprintf(stderr,
"ERROR: writing header->project_ID_GUID_data_1\n");
228 fprintf(stderr,
"ERROR: writing header->project_ID_GUID_data_2\n");
233 fprintf(stderr,
"ERROR: writing header->project_ID_GUID_data_3\n");
238 fprintf(stderr,
"ERROR: writing header->project_ID_GUID_data_4\n");
244 fprintf(stderr,
"WARNING: header->version_major is %d. writing 1 instead.\n", header->
version_major);
247 fprintf(stderr,
"ERROR: writing header->version_major\n");
255 fprintf(stderr,
"ERROR: writing header->version_major\n");
262 fprintf(stderr,
"WARNING: header->version_minor is %d. writing 4 instead.\n", header->
version_minor);
265 fprintf(stderr,
"ERROR: writing header->version_minor\n");
273 fprintf(stderr,
"ERROR: writing header->version_minor\n");
279 fprintf(stderr,
"ERROR: writing header->system_identifier\n");
284 fprintf(stderr,
"ERROR: writing header->generating_software\n");
289 fprintf(stderr,
"ERROR: writing header->file_creation_day\n");
294 fprintf(stderr,
"ERROR: writing header->file_creation_year\n");
299 fprintf(stderr,
"ERROR: writing header->header_size\n");
303 if (laszip) offset_to_point_data += (54 + laszip_vlr_data_size);
304 if (header->
vlr_lastiling) offset_to_point_data += (54 + 28);
307 fprintf(stderr,
"ERROR: writing header->offset_to_point_data\n");
311 if (laszip) number_of_variable_length_records++;
312 if (header->
vlr_lastiling) number_of_variable_length_records++;
315 fprintf(stderr,
"ERROR: writing header->number_of_variable_length_records\n");
318 if (compressor) point_data_format |= 128;
321 fprintf(stderr,
"ERROR: writing header->point_data_format\n");
326 fprintf(stderr,
"ERROR: writing header->point_data_record_length\n");
331 fprintf(stderr,
"ERROR: writing header->number_of_point_records\n");
334 for (i = 0; i < 5; i++)
338 fprintf(stderr,
"ERROR: writing header->number_of_points_by_return[%d]\n", i);
344 fprintf(stderr,
"ERROR: writing header->x_scale_factor\n");
349 fprintf(stderr,
"ERROR: writing header->y_scale_factor\n");
354 fprintf(stderr,
"ERROR: writing header->z_scale_factor\n");
359 fprintf(stderr,
"ERROR: writing header->x_offset\n");
364 fprintf(stderr,
"ERROR: writing header->y_offset\n");
369 fprintf(stderr,
"ERROR: writing header->z_offset\n");
374 fprintf(stderr,
"ERROR: writing header->max_x\n");
379 fprintf(stderr,
"ERROR: writing header->min_x\n");
384 fprintf(stderr,
"ERROR: writing header->max_y\n");
389 fprintf(stderr,
"ERROR: writing header->min_y\n");
394 fprintf(stderr,
"ERROR: writing header->max_z\n");
399 fprintf(stderr,
"ERROR: writing header->min_z\n");
414 U64 start_of_waveform_data_packet_record = 0;
417 fprintf(stderr,
"ERROR: writing start_of_waveform_data_packet_record\n");
425 fprintf(stderr,
"ERROR: writing header->start_of_waveform_data_packet_record\n");
436 fprintf(stderr,
"ERROR: writing header->start_of_first_extended_variable_length_record\n");
441 fprintf(stderr,
"ERROR: writing header->number_of_extended_variable_length_records\n");
451 fprintf(stderr,
"ERROR: writing header->extended_number_of_point_records\n");
454 for (i = 0; i < 15; i++)
462 fprintf(stderr,
"ERROR: writing header->extended_number_of_points_by_return[%d]\n", i);
476 fprintf(stderr,
"ERROR: writing %d bytes of data from header->user_data_in_header\n", header->
user_data_in_header_size);
482 fprintf(stderr,
"ERROR: there should be %d bytes of data in header->user_data_in_header\n", header->
user_data_in_header_size);
502 fprintf(stderr,
"ERROR: writing header->vlrs[%d].reserved\n", i);
507 fprintf(stderr,
"ERROR: writing header->vlrs[%d].user_id\n", i);
512 fprintf(stderr,
"ERROR: writing header->vlrs[%d].record_id\n", i);
517 fprintf(stderr,
"ERROR: writing header->vlrs[%d].record_length_after_header\n", i);
522 fprintf(stderr,
"ERROR: writing header->vlrs[%d].description\n", i);
552 U16 reserved = 0xAABB;
555 fprintf(stderr,
"ERROR: writing reserved %d\n", (
I32)reserved);
558 U8 user_id[16] =
"laszip encoded\0";
561 fprintf(stderr,
"ERROR: writing user_id %s\n", user_id);
564 U16 record_id = 22204;
567 fprintf(stderr,
"ERROR: writing record_id %d\n", (
I32)record_id);
570 U16 record_length_after_header = laszip_vlr_data_size;
573 fprintf(stderr,
"ERROR: writing record_length_after_header %d\n", (
I32)record_length_after_header);
576 char description[32];
577 memset(description, 0, 32);
581 fprintf(stderr,
"ERROR: writing description %s\n", description);
602 fprintf(stderr,
"ERROR: writing compressor %d\n", (
I32)compressor);
607 fprintf(stderr,
"ERROR: writing coder %d\n", (
I32)laszip->
coder);
612 fprintf(stderr,
"ERROR: writing version_major %d\n", laszip->
version_major);
617 fprintf(stderr,
"ERROR: writing version_minor %d\n", laszip->
version_minor);
622 fprintf(stderr,
"ERROR: writing version_revision %d\n", laszip->
version_revision);
627 fprintf(stderr,
"ERROR: writing options %d\n", (
I32)laszip->
options);
632 fprintf(stderr,
"ERROR: writing chunk_size %d\n", laszip->
chunk_size);
637 fprintf(stderr,
"ERROR: writing num_points %d\n", (
I32)laszip->
num_points);
642 fprintf(stderr,
"ERROR: writing num_bytes %d\n", (
I32)laszip->
num_bytes);
647 fprintf(stderr,
"ERROR: writing num_items %d\n", laszip->
num_items);
654 fprintf(stderr,
"ERROR: writing type %d of item %d\n", laszip->
items[i].
type, i);
659 fprintf(stderr,
"ERROR: writing size %d of item %d\n", laszip->
items[i].
size, i);
664 fprintf(stderr,
"ERROR: writing version %d of item %d\n", laszip->
items[i].
version, i);
676 U16 reserved = 0xAABB;
679 fprintf(stderr,
"ERROR: writing reserved %d\n", (
I32)reserved);
682 U8 user_id[16] =
"lastools tile\0\0";
685 fprintf(stderr,
"ERROR: writing user_id %s\n", user_id);
688 U16 record_id = 22204;
691 fprintf(stderr,
"ERROR: writing record_id %d\n", (
I32)record_id);
694 U16 record_length_after_header = 28;
697 fprintf(stderr,
"ERROR: writing record_length_after_header %d\n", (
I32)record_length_after_header);
700 U8 description[32] =
"LAStools tile for streaming TIN";
703 fprintf(stderr,
"ERROR: writing description %s\n", description);
719 fprintf(stderr,
"ERROR: writing header->vlr_lastiling->level %u\n", header->
vlr_lastiling->
level);
734 fprintf(stderr,
"ERROR: writing header->vlr_lastiling->min_x %g\n", header->
vlr_lastiling->
min_x);
739 fprintf(stderr,
"ERROR: writing header->vlr_lastiling->max_x %g\n", header->
vlr_lastiling->
max_x);
744 fprintf(stderr,
"ERROR: writing header->vlr_lastiling->min_y %g\n", header->
vlr_lastiling->
min_y);
749 fprintf(stderr,
"ERROR: writing header->vlr_lastiling->max_y %g\n", header->
vlr_lastiling->
max_y);
768 fprintf(stderr,
"ERROR: there should be %d bytes of data in header->user_data_after_header\n", header->
user_data_after_header_size);
799 fprintf(stderr,
"ERROR: header pointer is zero\n");
804 fprintf(stderr,
"ERROR: stream pointer is zero\n");
809 fprintf(stderr,
"ERROR: stream is not seekable\n");
817 fprintf(stderr,
"ERROR: updating header->number_of_point_records\n");
821 for (i = 0; i < 5; i++)
825 fprintf(stderr,
"ERROR: updating header->number_of_points_by_return[%d]\n", i);
834 fprintf(stderr,
"ERROR: updating header->max_x\n");
840 fprintf(stderr,
"ERROR: updating header->min_x\n");
846 fprintf(stderr,
"ERROR: updating header->max_y\n");
852 fprintf(stderr,
"ERROR: updating header->min_y\n");
858 fprintf(stderr,
"ERROR: updating header->max_z\n");
864 fprintf(stderr,
"ERROR: updating header->min_z\n");
873 fprintf(stderr,
"ERROR: updating header->number_of_point_records\n");
877 for (i = 0; i < 5; i++)
881 fprintf(stderr,
"ERROR: updating header->number_of_points_by_return[%d]\n", i);
888 fprintf(stderr,
"ERROR: updating header->max_x\n");
893 fprintf(stderr,
"ERROR: updating header->min_x\n");
898 fprintf(stderr,
"ERROR: updating header->max_y\n");
903 fprintf(stderr,
"ERROR: updating header->min_y\n");
908 fprintf(stderr,
"ERROR: updating header->max_z\n");
913 fprintf(stderr,
"ERROR: updating header->min_z\n");
917 if (update_extra_bytes)
953 fprintf(stderr,
"WARNING: written %I64d points but expected %I64d points\n",
p_count,
npoints);
955 fprintf(stderr,
"WARNING: written %lld points but expected %lld points\n",
p_count,
npoints);
973 fprintf(stderr,
"ERROR: stream not seekable. cannot update header from %I64d to %I64d points.\n",
npoints,
p_count);
975 fprintf(stderr,
"ERROR: stream not seekable. cannot update header from %lld to %lld points.\n",
npoints,
p_count);