-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatsheader80.cpp
executable file
·1127 lines (793 loc) · 31.5 KB
/
atsheader80.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "atsheader80.h"
void ATSHeader80::mv_header_read(){
HeaderLength = header.HeaderLength;
HeaderVer = header.HeaderVer;
Samples = header.Samples;
SampleFreq = header.SampleFreq;
atsDateTime = header.atsDateTime;
LSBVal = header.LSBVal;
GMTOffset = header.GMTOffset;
// strncpy(skip1, header.skip1);
SampleFreqOrig = header.SampleFreqOrig;
SerNoADU = header.SerNoADU;
SerNoADB = header.SerNoADB;
ChanNo = header.ChanNo;
cSensorChopper = header.cSensorChopper;
strncpy(cChannelType, header.cChannelType, sizeof(this->cChannelType));
strncpy(cSensorType, header.cSensorType, sizeof(cSensorType));
SensorNo = header.SensorNo;
x1 = header.x1;
y1 = header.y1;
z1 = header.z1;
x2 = header.x2;
y2 = header.y2;
z2 = header.z2;
DipoleLength = header.DipoleLength;
Angle = header.Angle;
ProbeResistivity = header.ProbeResistivity;
DCOffset = header.DCOffset;
Gain = header.Gain;
Gain2 = header.Gain2;
//strncpy(skip2, header.skip2, sizeof(skip2));
atsLatitude = header.atsLatitude;
atsLongitude = header.atsLongitude;
atsElevation = header.atsElevation;
LatLon_Type = header.LatLon_Type;
Coord_Type = header.Coord_Type;
Ref_Meridian = header.Ref_Meridian;
x = header.x;
y = header.y;
Sync_Status = header.Sync_Status;
Accuracy = header.Accuracy;
UTCGPSOffset = header.UTCGPSOffset;
strncpy(cSystemType, header.cSystemType, sizeof(cSystemType));
strncpy(csurvey_header_fname, header.csurvey_header_fname, sizeof(csurvey_header_fname));
strncpy(meas_type, header.meas_type, sizeof(meas_type));
strncpy(clog_file_sys_self_test, header.clog_file_sys_self_test, sizeof(clog_file_sys_self_test));
strncpy(result_self_test, header.result_self_test, sizeof(result_self_test));
strncpy(skip4, header.skip4, sizeof(skip4));
num_cal_freq = header.num_cal_freq;
lofe = header.lofe;
vocf = header.vocf;
start_cal_info_head = header.start_cal_info_head;
strncpy(skip5, header.skip5, sizeof(skip5));
strncpy(cadu_cal_file_name, header.cadu_cal_file_name, sizeof(cadu_cal_file_name));
date_of_cal_adu = header.date_of_cal_adu;
strncpy(csensor_cal_file_name, header.csensor_cal_file_name, sizeof(csensor_cal_file_name));
date_of_cal_sensor = header.date_of_cal_sensor;
//strncpy(skip6, header.skip6, sizeof(skip6));
strncpy(cClient, header.cClient, sizeof(cClient));
strncpy(cContractor, header.cContractor, sizeof(cContractor));
strncpy(cArea, header.cArea, sizeof(cArea));
strncpy(cSurveyID, header.cSurveyID, sizeof(cSurveyID));
strncpy(cOperator, header.cOperator, sizeof(cOperator));
strncpy(ccoordinates_type, header.ccoordinates_type, sizeof(ccoordinates_type));
atsZoneNumber = header.atsZoneNumber;
atsLetterDesignator = header.atsLetterDesignator;
strncpy(atsemptystr, header.atsemptystr, sizeof(atsemptystr));
atsNorthing = header.atsNorthing;
atsEasting = header.atsEasting;
atsutm_meridian = header.atsutm_meridian;
strncpy(cReferenceEllipsoid, header.cReferenceEllipsoid, sizeof(cReferenceEllipsoid));
strncpy(cskip7, header.cskip7, sizeof(cskip7));
strncpy(achXmlHeader, header.Achxmlheader, sizeof(achXmlHeader));
strncpy(cComments, header.cComments, sizeof(cComments));
}
void ATSHeader80::mv_header_write() {
// if (header_ver) header.HeaderVer = header_ver;
header.HeaderVer = HeaderVer;
//(header_length) header.HeaderLength = header_length;
header.HeaderLength = HeaderLength;
header.Samples = Samples;
header.SampleFreq = SampleFreq;
header.atsDateTime = atsDateTime;
header.LSBVal = LSBVal;
header.GMTOffset = GMTOffset;
//strncpy(header.skip1, skip1);
header.SampleFreqOrig = SampleFreqOrig;
header.SerNoADU = SerNoADU;
header.SerNoADB = SerNoADB;
header.ChanNo = ChanNo;
header.cSensorChopper = cSensorChopper;
strncpy(header.cChannelType, cChannelType, sizeof(cChannelType));
strncpy(header.cSensorType, cSensorType, sizeof(cSensorType));
header.SensorNo = SensorNo;
header.x1 = x1;
header.y1 = y1;
header.z1 = z1;
header.x2 = x2;
header.y2 = y2;
header.z2 = z2;
header.DipoleLength = DipoleLength;
header.Angle = Angle;
header.ProbeResistivity = ProbeResistivity;
header.DCOffset = DCOffset;
header.Gain = Gain;
header.Gain2 = Gain2;
//strncpy(header.skip2, skip2, sizeof(skip2));
header.atsLatitude = atsLatitude;
header.atsLongitude = atsLongitude;
header.atsElevation = atsElevation;
header.LatLon_Type = LatLon_Type;
header.Coord_Type = Coord_Type;
header.Ref_Meridian = Ref_Meridian;
header.x = x;
header.y = y;
header.Sync_Status = Sync_Status;
header.Accuracy = Accuracy;
header.UTCGPSOffset = UTCGPSOffset;
strncpy(header.cSystemType, cSystemType, sizeof(cSystemType));
strncpy(header.csurvey_header_fname, csurvey_header_fname, sizeof(csurvey_header_fname));
strncpy(header.meas_type, meas_type, sizeof(meas_type));
strncpy(header.clog_file_sys_self_test, clog_file_sys_self_test, sizeof(clog_file_sys_self_test));
strncpy(header.result_self_test, result_self_test, sizeof(result_self_test));
strncpy(header.skip4, skip4, sizeof(skip4));
header.num_cal_freq = num_cal_freq;
header.lofe = lofe;
header.vocf = vocf;
header.start_cal_info_head = start_cal_info_head;
strncpy(header.skip5, skip5, sizeof(skip5));
strncpy(header.cadu_cal_file_name, cadu_cal_file_name, sizeof(cadu_cal_file_name));
header.date_of_cal_adu = date_of_cal_adu;
strncpy(header.csensor_cal_file_name, csensor_cal_file_name, sizeof(csensor_cal_file_name));
header.date_of_cal_sensor = date_of_cal_sensor;
//strncpy(header.skip6, skip6, sizeof(skip6));
strncpy(header.cClient, cClient, sizeof(cClient));
strncpy(header.cContractor, cContractor, sizeof(cContractor));
strncpy(header.cArea, cArea, sizeof(cArea));
strncpy(header.cSurveyID, cSurveyID, sizeof(cSurveyID));
strncpy(header.cOperator, cOperator, sizeof(cOperator));
strncpy(header.ccoordinates_type, ccoordinates_type, sizeof(ccoordinates_type));
header.atsZoneNumber = atsZoneNumber;
header.atsLetterDesignator = atsLetterDesignator;
strncpy(header.atsemptystr, atsemptystr, sizeof(atsemptystr));
header.atsNorthing = atsNorthing;
header.atsEasting = atsEasting;
header.atsutm_meridian = atsutm_meridian;
strncpy(header.cReferenceEllipsoid, cReferenceEllipsoid, sizeof(cReferenceEllipsoid));
strncpy(header.cskip7, cskip7, sizeof(cskip7));
strncpy(header.Achxmlheader, achXmlHeader, sizeof(achXmlHeader));
strncpy(header.cComments, cComments, sizeof(cComments));
}
ATSHeader80::~ATSHeader80()
{
}
ATSHeader80::ATSHeader80()
{
// empty all elements except ats header version
std:char myenv[80]="TZ=GMT0GMT";
if (!putenv(myenv)) tzset();
else cerr << "atsheader::no environment free; times will be interpreted wrong" << endl;
ATSHeader80::clean_header();
HeaderLength = 1024;
#ifdef CLASSDBG
cerr << "init ATSHeader80 " << sizeof(ATSHeader80) << endl;
#endif
}
/*!
\fn ATSHeader80::read_header(ifstream& ifs)
We have to make sure to skip the first byte of the Interface class!
The ifstream must be opened before
*/
size_t ATSHeader80::read_header(ifstream& ifs)
{
ifs.seekg(0);
ifs.read((char*) &header, sizeof(header));
if (header.HeaderVer >= 1080) {
this->tslices.reserve(C_ATS_CEA_NUM_HEADERS);
this->tslices.resize(C_ATS_CEA_NUM_HEADERS);
for (size_t ii = 0; ii < C_ATS_CEA_NUM_HEADERS; ++ii) {
ifs.read((char*) &tslice, sizeof(tslice));
this->tslices[ii] = tslice;
}
}
this->HeaderLength = ifs.tellg();
ATSHeader80::mv_header_read();
#ifdef CLASSDBG
cerr << "HeaderLength " << HeaderLength << endl;
cerr << "HeaderVer " << HeaderVer << endl;
cerr << "Samples " << Samples << endl;
cerr << "GMT2UTC " << UTCGPSOffset << endl;
//cerr << "sizes its ats" << sizeof(ITSHeader) << " " << sizeof(ATSHeader80) << endl;
#endif
cerr << this->cSensorChopper << "chopper " << header.cSensorChopper << endl;
//cerr << sizeof(ATSHeader80) << " sizes " << sizeof(ITSHeader) << endl;
#ifdef swap_ats
// atsbswap();
#endif
// ITSHEader is the virtual base clas which has a size of a byte
// ifs.seekg(sizeof(ATSHeader80) - sizeof(ITSHeader));
cerr << "position" << ifs.tellg();
cerr << endl << "HEADER IN " << this->SampleFreq << " " << this->SampleFreqOrig << endl;
return this->HeaderLength;
}
/*!
\fn ATSHeader80::write_header(ofstream& ofs)
We have to make sure to skip the first byte of the Interface class!
*/
size_t ATSHeader80::write_header(ofstream& ofs){
#ifdef swap_ats
ATSHeader80::byteswap_header
#endif
ofs.seekp(0);
// cerr << "start " << ofs.tellp() << endl;
ATSHeader80::mv_header_write();
ofs.write((char*) &header, sizeof(header));
//cerr << "\nwrite " << this->cSensorChopper << "chopper " << header.cSensorChopper << endl;
//cerr << "\nwrite " << this->cSensorChopper << "chopper " << header.cSensorChopper << endl;
char a='1';
//cout << "Das Zeichen " << 1 << " hat den Wert " << (int)(a);
// cerr << "end " << ofs.tellp() << endl;
if (this->HeaderVer >= 1080) {
for (size_t ii = 0; ii < C_ATS_CEA_NUM_HEADERS; ++ii) {
ofs.write((char*) &this->tslices.at(ii), sizeof(tslice));
}
}
return ofs.tellp();
}
size_t ATSHeader80::get_headersize() const {
return size_t (HeaderLength);
// if (HeaderLength > 1022) { // we might have read a file here before
// return size_t (HeaderLength);
// }
// // what do we do if we init a new one... take this!
// else return size_t (sizeof(ATSHeader80) - sizeof(ITSHeader));
}
void ATSHeader80::set_headersize(const size_t& hsize){
HeaderLength = (unsigned short int) (hsize);
}
void ATSHeader80::set_headerversion(const size_t &hver)
{
HeaderVer = (unsigned short int) (hver);
}
/*!
\fn ATSHeader80::set_samples(size_t& samples)
set_ the total samples to be written
*/
size_t ATSHeader80::set_samples(const size_t& samples)
{
if (samples != LONG_MAX) this->Samples = (unsigned int) samples;
return 0;
}
/*!
\fn ATSHeader80::set_lsb(double& lsbval)
set_ lsb for writing
*/
double ATSHeader80::set_lsb(const double& lsbval)
{
if (lsbval != DBL_MAX) this->LSBVal = lsbval;
return LSBVal;
}
/*!
get the minimum information about the header always needed
*/
void ATSHeader80::identify(string& headertype, string& headerversion, size_t& headersize, size_t& n_channels, size_t& storagebits, vector<ATSSliceHeader> &tslices) const {
headertype = "ats";
headerversion = num2str(this->HeaderVer);
n_channels = 1;
storagebits = 32;
headersize = this->HeaderLength;
if (this->HeaderVer >= 1080) {
tslices.reserve(this->tslices.size());
tslices.resize(this->tslices.size());
for (size_t i = 0; i < this->tslices.size(); ++i) {
tslices[i] = this->tslices.at(i);
}
}
}
/*!
channel_type Ex..Hz
*/
string ATSHeader80::get_channel_type() const {
string channel_type = this->cChannelType;
channel_type = channel_type.substr(0,2);
clean_b_str(channel_type);
return channel_type;
}
/*!
\fn ATSHeader80::set_datetime(const long int& datetime)
get UNIX time stamp
*/
void ATSHeader80::set_datetime(const long int& datetime)
{
this->atsDateTime = datetime;
}
/*
get correction for start time in seconds
.. which is not impelemented in atsheader
*/
void ATSHeader80::set_delta_start(const double& delta_start) {
}
/*
get correction for stop time in seconds
.. which is not impelemented in atsheader
*/
void ATSHeader80::set_delta_stop(const double& delta_stop){
}
/*!
\fn ATSHeader80::set_samplefreq(const double& samplefreq)
get sample freq for writing
*/
void ATSHeader80::set_samplefreq(const double& samplefreq)
{
if (samplefreq != DBL_MAX) this->SampleFreq = float(samplefreq);
}
/*!
e.g. after filtering the sample frequency is different.
This can have consquences in using transfer functions; e.g. the transfer functions
of the original sampling frequency must be used;
only if the original frequency was 0 or DBL_MAX this value may be overwritten - otherwise NOT;
check this somewhere, here at this point I don't know
*/
void ATSHeader80::set_samplefreq_orig(const double& samplefreq_orig)
{
if (samplefreq_orig != DBL_MAX) this->SampleFreqOrig = float(samplefreq_orig);
}
/*!
\fn ITSHeader::get_sensor_pos(double& x1, double& y1, double& z1, double& x2, double& y2, double& z2)
regardless whether you have dipole length or ange and so on the interface class uses 3Dim setup
*/
void ATSHeader80::get_sensor_pos(double& dx1, double& dy1, double& dz1, double& dx2, double& dy2, double& dz2)
{
// clean
double assume_zero_length = 0.00001;
if (abs(this->x1) < assume_zero_length) this->x1 = 0.0;
if (abs(this->x2) < assume_zero_length) this->x2 = 0.0;
if (abs(this->y1) < assume_zero_length) this->y1 = 0.0;
if (abs(this->y2) < assume_zero_length) this->y2 = 0.0;
if (abs(this->z1) < assume_zero_length) this->z1 = 0.0;
if (abs(this->z2) < assume_zero_length) this->z2 = 0.0;
// it can happen that dipole was used instead of x,y,z
if ( (x1 == x2) && (y1 == y2) && (abs(DipoleLength) > assume_zero_length) ) {
this->x1 = -cos(M_PI / 180. * Angle) * DipoleLength / 2.;
this->x2 = cos(M_PI / 180. * Angle) * DipoleLength / 2.;
this->y1 = -sin(M_PI / 180. * Angle) * DipoleLength / 2.;
this->y2 = sin(M_PI / 180. * Angle) * DipoleLength / 2.;
// clean values from numeriocal artefacts
if (abs(this->x1) < assume_zero_length) this->x1 = 0.;
if (abs(this->x2) < assume_zero_length) this->x2 = 0.;
if (abs(this->y1) < assume_zero_length) this->y1 = 0.;
if (abs(this->y2) < assume_zero_length) this->y2 = 0.;
if (abs(this->z1) < assume_zero_length) this->z1 = 0.;
if (abs(this->z2) < assume_zero_length) this->z2 = 0.;
}
dx1 = double(this->x1);
dx2 = double(this->x2);
dy1 = double(this->y1);
dy2 = double(this->y2);
dz1 = double(this->z1);
dz2 = double(this->z2);
}
/*!
\fn ATSHeader80::get_coordinates(int& lagra, int& lamin, double& lasec, int& logra, int& lomin, double& losec)
*/
void ATSHeader80::get_coordinates(int& lagra, int& lamin, double& lasec, string& LatH, int& logra, int& lomin, double& losec, string& LongH) const
{
coordinates coordi;
coordi.getlatlon(this->atsLatitude, this->atsLongitude);
coordi.get_lat_lon(lagra, lamin, lasec, LatH, logra, lomin, losec, LongH);
}
/*!
\fn ATSHeader80::get_bits(size_t& adcbits, size_t& storagebits)
fixed values for ats version 0.72
*/
void ATSHeader80::get_bits(size_t& adcbits, size_t& storagebits) const
{
adcbits = 24;
storagebits = 32;
}
/*!
\fn ATSHeader80::get_sensor_calfile()
mostly we have SENSOR.CAL which is not a cal file; therfore
we generate a calibration file from Sensortype and serialnumber
*/
string ATSHeader80::get_sensor_calfile() const
{
string sensor_calfile_used;
// get info like MFS EFP
string SensorType = this->get_sensor_type();
// get the serial num like 123
string SensorNum = this->get_sensor_id();
// get the calibration file entry - which unfortunately mostly SENSOR.CAL
string sensor_calfile(&this->csensor_cal_file_name[0], sizeof(this->csensor_cal_file_name));
// clean an lower all strings
clean_b_str(sensor_calfile);
sensor_calfile_used = SensorType; // should be mfs06 or mfs05 etc
stringstream convert_num;
// sensor.cal is a empty template
if ( (return_lower(sensor_calfile) == "sensor.cal")
&& (return_lower(SensorType) != "efp05") && (return_lower(SensorType) != "efp06") ) { // no file is given; template no electrodes
if (this->SensorNo < 10) sensor_calfile_used = trim(sensor_calfile_used) + "00"; // mfs0600 now
else if (this->SensorNo < 100) sensor_calfile_used = trim(sensor_calfile_used) + "0"; // mfs060 now
else sensor_calfile_used = trim(sensor_calfile_used); // mfs06
sensor_calfile_used += (num2str(this->SensorNo) + ".txt");
sensor_calfile = sensor_calfile_used;
#ifdef CLASSDBG
cerr << "ATSHeader80::get_sensor_calfile-> " << sensor_calfile << endl;
#endif
}
// check that out
else if ( (return_lower(sensor_calfile) != "sensor.cal") // has a cal file name
&& ( return_lower(SensorType) != "efp05") && ( return_lower(SensorType) != "efp06") ) { // also provide to use electrodes
#ifdef CLASSDBG
cerr << "ATSHeader80::get_sensor_calfile-> " << sensor_calfile << endl;
#endif
}
else if ( (return_lower(SensorType) == "efp05") || (return_lower(SensorType) == "efp06") ||
(return_lower(SensorType) == "unkn_e") || (return_lower(SensorType) == "linear")) {
#ifdef CLASSDBG
cerr << "ATSHeader80::get_sensor_calfile-> no transfer function used for " << SensorType << ": linear" << endl;
#endif
sensor_calfile = "";
}
else {
cerr << "ATSHeader80::get_sensor_calfile-> fail to make a name returning " << sensor_calfile << endl;
}
return sensor_calfile;
}
/*!
\fn ATSHeader80::get_system_calfile(string& system_calfile)
*/
string ATSHeader80::get_system_calfile() const
{
// do not use aduxxx.txt that is a fake
// adu has no calibration
string tmp(&this->cadu_cal_file_name[0], sizeof(this->cadu_cal_file_name));
//lower(tmp);
clean_b_str(tmp);
// avoid to return ADU..TXT !!!
if ((tmp.find("adu") != tmp.npos) || (tmp.find("ADU") != tmp.npos)) return "";
else return tmp;
}
/*!
\fn ITSHeader::get_system_name()
*/
string ATSHeader80::get_system_name() const
{
string check = this->cSystemType;
clean_b_str(check);
lower(check);
if (check == "adu06" || check == "adu-06") return "ADU06";
if (check == "adu07" || check == "adu-07") return "ADU07";
if (check == "emimt24" || check == "emi-mt24"|| check == "emi mt24") return "EMIMT24";
if (check == "goerap" || check == "rap") return "GOERAP";
if (check == "linear") return "linear";
else return "ADU06";
}
string ATSHeader80::get_system_id() const {
return num2str(this->SerNoADU);
}
void ATSHeader80::set_channel_no(const size_t& channel_no) {
this->ChanNo = (char) channel_no;
// cerr << "got -----------------------------------" << this->ChanNo << channel_no << endl;
}
size_t ATSHeader80::get_channel_no() const {
// cerr << "put -----------------------------------" << this->ChanNo << size_t(this->ChanNo) << endl;
return this->ChanNo;
}
string ATSHeader80::get_channel_id() const {
return num2str(this->SerNoADB);
}
string ATSHeader80::get_sensor_id() const {
return num2str(this->SensorNo);
}
/*!
\fn ITSHeader::get_sensor_type()
something MFS
*/
string ATSHeader80::get_sensor_type() const
{
string tmp(&this->cSensorType[0], sizeof(this->cSensorType));
clean_b_str(tmp);
return tmp;
}
double ATSHeader80::get_sensor_resistivity() const{
return double(this->ProbeResistivity);
}
long ATSHeader80::get_gmt_offset() const{
return long(this->GMTOffset);
}
long ATSHeader80::get_utc_to_gps_offset() const {
return long (UTCGPSOffset);
}
int ATSHeader80::get_is_gmt() const{
return 1;
}
double ATSHeader80::get_dc_offset() const{
return double(this->DCOffset);
}
double ATSHeader80::get_gain() const{
return double(this->Gain);
}
/*
this has to be change asap - not stored in header yet
*/
string ATSHeader80::get_sensor_chopper() const{
if (this->cSensorChopper == 1) return "on";
else if (this->cSystemChopper == 0) return "off";
else return "off";
}
string ATSHeader80::get_system_chopper() const {
if (this->cSystemChopper == 0) return "on";
else return "off";
}
/*
elevation is in cm defined in ATS format
*/
double ATSHeader80::get_elevation() const {
return double (this->atsElevation / 100.);
}
string ATSHeader80::get_meastype() const {
string tmp(&this->meas_type[0], sizeof(this->meas_type));
clean_b_str(tmp);
return tmp;
}
string ATSHeader80::get_system_selftest_file() const {
string tmp(&this->clog_file_sys_self_test[0], sizeof(this->clog_file_sys_self_test));
clean_b_str(tmp);
return tmp;
}
string ATSHeader80::get_result_selftest() const {
string tmp(&this->result_self_test[0], sizeof(this->result_self_test));
clean_b_str(tmp);
return tmp;
}
string ATSHeader80::get_client() const {
string tmp(&this->cClient[0], sizeof(this->cClient));
clean_b_str(tmp);
return tmp;
}
string ATSHeader80::get_contractor() const {
string tmp(&this->cContractor[0], sizeof(this->cContractor));
clean_b_str(tmp);
return tmp;
}
string ATSHeader80::get_area() const {
string tmp(&this->cArea[0], sizeof(this->cArea));
clean_b_str(tmp);
return tmp;
}
string ATSHeader80::get_survey_id() const {
string tmp(&this->cSurveyID[0], sizeof(this->cSurveyID));
clean_b_str(tmp);
return tmp;
}
string ATSHeader80::get_system_operator() const {
string tmp(&this->cOperator[0], sizeof(this->cOperator));
clean_b_str(tmp);
return tmp;
}
string ATSHeader80::get_xmlheader() const {
string tmp(&this->achXmlHeader[0], sizeof(this->achXmlHeader));
clean_b_str(tmp);
return tmp;
}
string ATSHeader80::get_comments() const {
string tmp(&this->cComments[0], sizeof(this->cComments));
clean_b_str(tmp);
return tmp;
}
void ATSHeader80::clean_header(){
//HeaderVer = ATSHEADERVERSION;
this->HeaderVer = 80;
this->HeaderLength = this->SerNoADU = this->SerNoADB = this->ChanNo = this->SensorNo = this->Ref_Meridian = 0;
this->GMTOffset = this->atsLatitude = this->atsLongitude = this->atsElevation = 0;
this->UTCGPSOffset = 0;
this->SampleFreq = 0;
this->SampleFreqOrig = 0;
this->DipoleLength = this->ProbeResistivity = this->DCOffset = this->Gain = this->Gain2 = this->Angle =
this->x1 = this->y1 = this->z1 = this->x2 = this->y2 = this->z2 = 0.;
this->Samples = 0; this->atsDateTime = 0;
this->date_of_cal_adu = 0; this->date_of_cal_sensor = 0;
this->LSBVal = this->x = this->y = 0.0;
this->num_cal_freq = this->lofe = this->vocf = this->start_cal_info_head = 0;
// new in 73 Version
this->atsZoneNumber = 0;
this->atsNorthing = this->atsEasting = 0;
this->atsutm_meridian = 0;
//this->cSensorChopper = 0;
//this->cSystemChopper = 0;
//this->Sync_Status = 0;
//this->LatLon_Type = 0;
//this->Coord_Type = 0;
//this->Accuracy = 0;
// empty all strings
// string_z( this->skip1, sizeof( this->skip1));
// string_z( this->cChannelType, sizeof( this->cChannelType));
// string_z( this->cSensorType, sizeof( this->cSensorType));
//string_z( this->skip2, sizeof( this->skip2));
// string_z( this->cSystemType, sizeof( this->cSystemType));
// string_z( this->csurvey_header_fname, sizeof( this->csurvey_header_fname));
// string_z( this->meas_type, sizeof( this->meas_type));
// string_z( this->clog_file_sys_self_test, sizeof( this->clog_file_sys_self_test));
// string_z( this->result_self_test, sizeof( this->result_self_test));
// string_z( this->skip4, sizeof( this->skip4));
// string_z( this->skip5, sizeof( this->skip5));
// string_z( this->cadu_cal_file_name, sizeof( this->cadu_cal_file_name));
// string_z( this->csensor_cal_file_name, sizeof( this->csensor_cal_file_name));
// strncpy( this->csensor_cal_file_name, " ", sizeof(csensor_cal_file_name));
//string_z( this->skip6, sizeof( this->skip6));
// string_z( this->cClient, sizeof( this->cClient));
// string_z( this->cContractor, sizeof( this->cContractor));
// string_z( this->cArea, sizeof( this->cArea));
// string_z( this->cSurveyID, sizeof( this->cSurveyID));
// string_z( this->cOperator, sizeof( this->cOperator));
// string_z( this->cskip7, sizeof( this->cskip7));
// string_z( this->Achxmlheader, sizeof( this->Achxmlheader));
// string_z( this->cComments, sizeof( this->cComments));
// this->atsLetterDesignator = ' ';
string_z( this->atsemptystr, sizeof(this->atsemptystr));
// string_z( this->ccoordinates_type, sizeof( this->ccoordinates_type));
// string_z( this->cReferenceEllipsoid, sizeof( this->cReferenceEllipsoid));
}
void ATSHeader80::byteswap_header(){
// byteswap of the header
//tbswap(HeaderLength);
//tbswap(HeaderVer);
if (tbswap(this->Samples) != 4) {
cerr << " int has not 4 bytes, exit" << endl;
exit(0);
}
if (tbswap(this->SampleFreq) != 4) {
cerr << "float has not 4 bytes, exit" << endl;
exit(0);
}
if (tbswap(this->SampleFreqOrig) != 4) {
cerr << "float has not 4 bytes, exit" << endl;
exit(0);
}
tbswap(this->atsDateTime);
if (tbswap(this->LSBVal) != 8) {
cerr << "double has not 8 bytes, exit" << endl;
exit(0);
}
tbswap(this->GMTOffset);
tbswap(this->DipoleLength); tbswap( this->ProbeResistivity);
tbswap( this->DCOffset); tbswap( this->Gain); tbswap( this->Gain2); tbswap( this->Angle);
tbswap( this->x1); tbswap( this->y1); tbswap( this->z1);
tbswap( this->x2); tbswap( this->y2); tbswap( this->z2);
tbswap( this->x); tbswap( this->y);
tbswap( this->atsLatitude);
tbswap( this->atsLongitude);
tbswap( this->atsElevation);
tbswap( this->date_of_cal_adu);
tbswap( this->date_of_cal_sensor);
tbswap( this->atsNorthing);
tbswap( this->atsEasting);
}
/*
get something like 123 as serial number;
ats can only store a number
*/
void ATSHeader80::set_channel_type(const string& channel_type) {
string_z(this->cChannelType, sizeof(this->cChannelType));
channel_type.copy(&this->cChannelType[0], sizeof(this->cChannelType));
}
void ATSHeader80::set_sensor_pos(const double& x1, const double& y1, const double& z1, const double& x2, const double& y2, const double& z2) {
if (x1 != DBL_MAX) this->x1 = float(x1);
if (y1 != DBL_MAX) this->y1 = float(y1);
if (z1 != DBL_MAX) this->z1 = float(z1);
if (x2 != DBL_MAX) this->x2 = float(x2);
if (y2 != DBL_MAX) this->y2 = float(y2);
if (z2 != DBL_MAX) this->z2 = float(z2);
double tx, ty, tz;
tx = this->x2 - this->x1;
ty = this->y2 - this->y1;
tz = this->z2 - this->z1;
DipoleLength = float (sqrt(tx * tx + ty * ty + tz * tz));
Angle = float( 180. / M_PI * atan2(ty,tx));
}
void ATSHeader80::set_coordinates(const int& lagra, const int& lamin, const double& lasec, const string& LatH, const int& logra, const int& lomin, const double& losec, const string& LonH) {
coordinates coordi;
coordi.getlatlon(lagra, lamin, lasec, LatH, logra, lomin, losec, LonH);
coordi.get_msecs(atsLatitude, atsLongitude);
}
void ATSHeader80::set_bits(const size_t& adcbits, const size_t& storagebits) {
// not defined in ats ver. 0.72; default 24bit ADC and 32bit int
}
void ATSHeader80::set_sensor_calfile(const string& sensor_cal_file) {
string_z(this->csensor_cal_file_name, sizeof(this->csensor_cal_file_name));
sensor_cal_file.copy(&this->csensor_cal_file_name[0], sizeof(this->csensor_cal_file_name));
}
void ATSHeader80::set_system_calfile(const string& system_calfile) {
string_z(cadu_cal_file_name, sizeof(cadu_cal_file_name));
system_calfile.copy(&this->cadu_cal_file_name[0], sizeof(this->cadu_cal_file_name));
}
void ATSHeader80::set_system_name(const string& data_logger_name) {
string_z(cSystemType, sizeof(cSystemType));
data_logger_name.copy(&this->cSystemType[0], sizeof(this->cSystemType));
}
void ATSHeader80::set_channel_id(const string& channel_id) {
unsigned short int tmp = str2num<unsigned short int>(channel_id);
if (tmp != USHRT_MAX)
this->SerNoADB = str2num<unsigned short int>(channel_id);
}
/*!
ATS uses a number only
*/
void ATSHeader80::set_sensor_id(const string& sensor_id) {
unsigned short int tmp = str2num<unsigned short int>(sensor_id);
if (tmp != USHRT_MAX)