-
Notifications
You must be signed in to change notification settings - Fork 0
/
astap_main.pas
14935 lines (12740 loc) · 618 KB
/
astap_main.pas
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
unit astap_main;
{Copyright (C) 2017, 2022 by Han Kleijn, www.hnsky.org
email: han.k.. at...hnsky.org
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.
{Notes on MacOS pkg making:
1) Modify app in applications via "show contents", add updated files.
2) Add the app in program packages
3) Build package. Will produce PKG file containing the app.
Compiler settings for macOS:
targetOS: Darwin
CPU family X86_64
LCL widegetset: cocoa
}
{open compiler isssues:
MacOS
Listview smallimages are not displayed.
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39193
MacOS
ScrollCode=scEndScroll does not appears at the end of scroll
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/37454
Mac
Listview event OnCustomDrawItem is never triggered/fired in Mac, widget Cocoa
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39500
}
interface
uses
{$ifdef mswindows}
Windows,
Classes, Controls, Dialogs,StdCtrls, ExtCtrls, ComCtrls, Menus,
windirs,{for directories from windows}
{$else} {unix}
LCLType, {for vk_...}
Unix, {for console}
Classes, Controls, Dialogs,StdCtrls, ExtCtrls, ComCtrls, Menus,process,
BaseUnix, {for fpchmod}
{$endif}
LCLIntf,{for selectobject, openURL}
LCLProc,
FPImage,
fpreadTIFF, {all part of fcl-image}
fpreadPNG,fpreadBMP,fpreadJPEG,
fpwriteTIFF,fpwritePNG,fpwriteBMP,fpwriteJPEG, fptiffcmn, {images}
GraphType, {fastbitmap}
LCLVersion, SysUtils, Graphics, Forms, strutils, math,
clipbrd, {for copy to clipboard}
Buttons, PopupNotifier, simpleipc,
CustApp, Types,
iostream, {for using stdin for data}
IniFiles;{for saving and loading settings}
type
{ Tmainwindow }
Tmainwindow = class(TForm)
add_marker_position1: TMenuItem;
bin3x3: TMenuItem;
BitBtn1: TBitBtn;
error_label1: TLabel;
FontDialog1: TFontDialog;
image_north_arrow1: TImage;
LabelThree1: TLabel;
LabelVar1: TLabel;
LabelCheck1: TLabel;
Memo1: TMemo;
Memo3: TMemo;
menucopy2: TMenuItem;
Menufind2: TMenuItem;
menufindnext2: TMenuItem;
MenuItem1: TMenuItem;
bin2x2: TMenuItem;
image_cleanup1: TMenuItem;
localgaussian1: TMenuItem;
localcoloursmooth1: TMenuItem;
autocorrectcolours1: TMenuItem;
center_lost_windows: TMenuItem;
deepsky_annotation1: TMenuItem;
hyperleda_annotation1: TMenuItem;
MenuItem10: TMenuItem;
annotate_with_measured_magnitudes1: TMenuItem;
compress_fpack1: TMenuItem;
measuretotalmagnitude1: TMenuItem;
MenuItem13: TMenuItem;
MenuItem14: TMenuItem;
loadsettings1: TMenuItem;
localbackgroundequalise1: TMenuItem;
menufindnext1: TMenuItem;
Menufind1: TMenuItem;
annotate_minor_planets1: TMenuItem;
batch_annotate1: TMenuItem;
extract_pixel_11: TMenuItem;
copy_paste_tool1: TMenuItem;
MenuItem15: TMenuItem;
annotations_visible1: TMenuItem;
MenuItem20: TMenuItem;
extract_pixel_21: TMenuItem;
extract_pixel_22: TMenuItem;
batch_solve_astrometry_net: TMenuItem;
copy_to_clipboard1: TMenuItem;
grid1: TMenuItem;
freetext1: TMenuItem;
MenuItem21: TMenuItem;
bin_2x2menu1: TMenuItem;
bin_3x3menu1: TMenuItem;
imageinspection1: TMenuItem;
inspector1: TMenuItem;
MenuItem22: TMenuItem;
flip_v1: TMenuItem;
flip_H1: TMenuItem;
rotate_arbitrary1: TMenuItem;
roundness1: TMenuItem;
MenuItem28: TMenuItem;
MenuItem29: TMenuItem;
MenuItem30: TMenuItem;
add_sip_check1: TMenuItem;
add_limiting_magn_check1: TMenuItem;
batch_overwrite1: TMenuItem;
convert_to_ppm1: TMenuItem;
MenuItem31: TMenuItem;
MenuItem32: TMenuItem;
hfd_arcseconds1: TMenuItem;
MenuItem33: TMenuItem;
MenuItem34: TMenuItem;
Constellations1: TMenuItem;
aavso_chart1: TMenuItem;
import_auid1: TMenuItem;
N4: TMenuItem;
MenuItem38: TMenuItem;
simbad_query1: TMenuItem;
positionanddate1: TMenuItem;
removegreenpurple1: TMenuItem;
Shape1: TShape;
sip1: TMenuItem;
zoomfactorone1: TMenuItem;
extractred1: TMenuItem;
extractblue1: TMenuItem;
extractgreen1: TMenuItem;
MenuItem24: TMenuItem;
writepositionshort1: TMenuItem;
Shape_alignment_marker2: TShape;
Shape_alignment_marker3: TShape;
shape_manual_alignment1: TShape;
sqm1: TMenuItem;
Rota_mainmenu1: TMenuItem;
batch_rotate_left1: TMenuItem;
batch_rotate_right1: TMenuItem;
gradient_removal1: TMenuItem;
histogram_values_to_clipboard1: TMenuItem;
local_adjustments1: TMenuItem;
angular_distance1: TMenuItem;
j2000_1: TMenuItem;
galactic1: TMenuItem;
MenuItem23: TMenuItem;
annotate_unknown_stars1: TMenuItem;
gaia_star_position1: TMenuItem;
j2000d1: TMenuItem;
mountposition1: TMenuItem;
northeast1: TMenuItem;
selectfont1: TMenuItem;
popupmenu_statusbar1: TPopupMenu;
shape_marker4: TShape;
Stretchdrawmenu1: TMenuItem;
stretch_draw_fits1: TMenuItem;
show_statistics1: TMenuItem;
PopupMenu_histogram1: TPopupMenu;
remove_atmouse1: TMenuItem;
remove_longitude_latitude1: TMenuItem;
menupaste1: TMenuItem;
PopupMenu_memo2: TPopupMenu;
select_all1: TMenuItem;
PageControl1: TPageControl;
save_to_tiff1: TMenuItem;
extract_pixel_12: TMenuItem;
MenuItem7: TMenuItem;
menupaste: TMenuItem;
menucopy1: TMenuItem;
PopupMenu_memo1: TPopupMenu;
radec_copy1: TMenuItem;
radec_paste1: TMenuItem;
radec_search1: TMenuItem;
PopupMenu_ra_dec1: TPopupMenu;
save_settings1: TMenuItem;
MenuItem16: TMenuItem;
MenuItem17: TMenuItem;
enterposition2: TMenuItem;
flipped1: TMenuItem;
inversimage1: TMenuItem;
Enter_rectangle_with_label1: TMenuItem;
MenuItem18: TMenuItem;
select_all2: TMenuItem;
set_area1: TMenuItem;
rotate1: TMenuItem;
shape_histogram1: TShape;
shape_paste1: TShape;
submenurotate1: TMenuItem;
MenuItem19: TMenuItem;
shape_marker2: TShape;
shape_marker3: TShape;
solvebytwopositions1: TMenuItem;
enterposition1: TMenuItem;
save_settings_as1: TMenuItem;
settings_menu1: TMenuItem;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
UpDown1: TUpDown;
variable_star_annotation1: TMenuItem;
clean_up1: TMenuItem;
preview_demosaic1: TMenuItem;
PopupNotifier1: TPopupNotifier;
remove_colour1: TMenuItem;
Returntodefaultsettings1: TMenuItem;
saturation_factor_plot1: TTrackBar;
savesettings1: TMenuItem;
MenuItem11: TMenuItem;
MenuItem12: TMenuItem;
remove_markers1: TMenuItem;
SimpleIPCServer1: TSimpleIPCServer;
zoomin1: TMenuItem;
zoomout1: TMenuItem;
select_directory_thumb1: TMenuItem;
add_marker1: TMenuItem;
calibrate_photometry1: TMenuItem;
MenuItem9: TMenuItem;
astrometric_solve_image1: TMenuItem;
remove_left1: TMenuItem;
remove_right1: TMenuItem;
remove_above1: TMenuItem;
remove_below1: TMenuItem;
MenuItem8: TMenuItem;
Shape_alignment_marker1: TShape;
shape_marker1: TShape;
SpeedButton1: TSpeedButton;
split_osc1: TMenuItem;
recent7: TMenuItem;
recent8: TMenuItem;
recent3: TMenuItem;
recent4: TMenuItem;
recent5: TMenuItem;
recent6: TMenuItem;
MenuItem2: TMenuItem;
helponline1: TMenuItem;
MenuItem3: TMenuItem;
MenuItem5: TMenuItem;
brighten_area1: TMenuItem;
convert_to_fits1: TMenuItem;
convertmono1: TMenuItem;
MenuItem6: TMenuItem;
recent1: TMenuItem;
recent2: TMenuItem;
star_annotation1: TMenuItem;
Remove_deep_sky_object1: TMenuItem;
MenuItem4: TMenuItem;
ra1: TEdit;
dec1: TEdit;
Label1: TLabel;
Label2: TLabel;
MainMenu1: TMainMenu;
Help: TMenuItem;
Exit1: TMenuItem;
About1: TMenuItem;
File1: TMenuItem;
OpenDialog1: TOpenDialog;
N1: TMenuItem;
N2: TMenuItem;
ShowFITSheader1: TMenuItem;
SaveDialog1: TSaveDialog;
error_get_it: TLabel;
ra_label: TLabel;
dec_label: TLabel;
rotation1: TLabel;
inversemousewheel1: TCheckBox;
LoadFITSPNGBMPJPEG1: TMenuItem;
SaveasJPGPNGBMP1: TMenuItem;
GroupBox1: TGroupBox;
save1: TButton;
solve_button1: TButton;
batch_add_solution1: TMenuItem;
tools1: TMenuItem;
TrayIcon1: TTrayIcon;
View1: TMenuItem;
flip_horizontal1: TMenuItem;
flip_vertical1: TMenuItem;
N5: TMenuItem;
SaveFITSwithupdatedheader1: TMenuItem;
demosaic_bayermatrix1: TMenuItem;
N6: TMenuItem;
Undo1: TMenuItem;
stretch_draw1: TMenuItem;
data_range_groupBox1: TGroupBox;
Label12: TLabel;
minimum1: TScrollBar;
Label13: TLabel;
maximum1: TScrollBar;
min2: TEdit;
max2: TEdit;
histogram1: TImage;
Label5: TLabel;
range1: TComboBox;
PopupMenu1: TPopupMenu;
Copyposition1: TMenuItem;
Copypositionindeg1: TMenuItem;
writeposition1: TMenuItem;
N7: TMenuItem;
Enter_annotation1: TMenuItem;
Saveasfits1: TMenuItem;
Stackimages1: TMenuItem;
Export_image1: TMenuItem;
ImageList1: TImageList;
N9: TMenuItem;
CropFITSimage1: TMenuItem;
stretch1: TComboBox;
Polynomial1: TComboBox;
N3: TMenuItem;
StatusBar1: TStatusBar;
Panel1: TPanel;
Image1: TImage;
procedure add_marker_position1Click(Sender: TObject);
procedure annotate_with_measured_magnitudes1Click(Sender: TObject);
procedure annotations_visible1Click(Sender: TObject);
procedure autocorrectcolours1Click(Sender: TObject);
procedure batch_annotate1Click(Sender: TObject);
procedure batch_solve_astrometry_netClick(Sender: TObject);
procedure calibrate_photometry1Click(Sender: TObject);
procedure Constellations1Click(Sender: TObject);
procedure convert_to_ppm1Click(Sender: TObject);
procedure flip_H1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure freetext1Click(Sender: TObject);
procedure hfd_arcseconds1Click(Sender: TObject);
procedure compress_fpack1Click(Sender: TObject);
procedure copy_to_clipboard1Click(Sender: TObject);
procedure extract_pixel_11Click(Sender: TObject);
procedure extract_pixel_12Click(Sender: TObject);
procedure extract_pixel_22Click(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
procedure histogram_range1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure histogram_values_to_clipboard1Click(Sender: TObject);
procedure Image1Paint(Sender: TObject);
procedure imageflipv1Click(Sender: TObject);
procedure annotate_unknown_stars1Click(Sender: TObject);
procedure import_auid1Click(Sender: TObject);
procedure inspector1Click(Sender: TObject);
procedure j2000d1Click(Sender: TObject);
procedure measuretotalmagnitude1Click(Sender: TObject);
procedure loadsettings1Click(Sender: TObject);
procedure localbackgroundequalise1Click(Sender: TObject);
procedure menucopy1Click(Sender: TObject);
procedure Menufind1Click(Sender: TObject);
procedure menufindnext1Click(Sender: TObject);
procedure copy_paste_tool1Click(Sender: TObject);
procedure extract_pixel_21Click(Sender: TObject);
procedure batch_rotate_left1Click(Sender: TObject);
procedure angular_distance1Click(Sender: TObject);
procedure j2000_1Click(Sender: TObject);
procedure galactic1Click(Sender: TObject);
procedure gaia_star_position1Click(Sender: TObject);
procedure extractred1Click(Sender: TObject);
procedure extractblue1Click(Sender: TObject);
procedure extractgreen1Click(Sender: TObject);
procedure grid1Click(Sender: TObject);
procedure bin_2x2menu1Click(Sender: TObject);
procedure convert_to_png1Click(Sender: TObject);
procedure MenuItem22Click(Sender: TObject);
procedure positionanddate1Click(Sender: TObject);
procedure inspection1click(Sender: TObject);
procedure removegreenpurple1Click(Sender: TObject);
procedure roundness1Click(Sender: TObject);
procedure sip1Click(Sender: TObject);
procedure split_osc1Click(Sender: TObject);
procedure sqm1Click(Sender: TObject);
procedure mountposition1Click(Sender: TObject);
procedure northeast1Click(Sender: TObject);
procedure range1Change(Sender: TObject);
procedure remove_atmouse1Click(Sender: TObject);
procedure gradient_removal1Click(Sender: TObject);
procedure remove_longitude_latitude1Click(Sender: TObject);
procedure selectfont1Click(Sender: TObject);
procedure select_all1Click(Sender: TObject);
procedure save_to_tiff1Click(Sender: TObject);
procedure menupasteClick(Sender: TObject);
procedure annotate_minor_planets1Click(Sender: TObject);
procedure radec_copy1Click(Sender: TObject);
procedure radec_paste1Click(Sender: TObject);
procedure radec_search1Click(Sender: TObject);
procedure save_settings1Click(Sender: TObject);
procedure enterposition1Click(Sender: TObject);
procedure inversimage1Click(Sender: TObject);
procedure set_area1Click(Sender: TObject);
procedure rotate_arbitrary1Click(Sender: TObject);
procedure receivemessage(Sender: TObject); {For single instance, receive paramstr(1) from second instance prior to termination}
procedure add_marker1Click(Sender: TObject);
procedure center_lost_windowsClick(Sender: TObject);
procedure convertmono1Click(Sender: TObject);
procedure deepsky_annotation1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: char);
procedure helponline1Click(Sender: TObject);
procedure Image1MouseEnter(Sender: TObject);
procedure image_cleanup1Click(Sender: TObject);
procedure deepsky_overlay1Click(Sender: TObject);
procedure brighten_area1Click(Sender: TObject);
procedure convert_to_fits1click(Sender: TObject);
procedure bin2x2Click(Sender: TObject);
procedure max2EditingDone(Sender: TObject);
procedure Memo1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure localgaussian1Click(Sender: TObject);
procedure localcoloursmooth1Click(Sender: TObject);
procedure hyperleda_annotation1Click(Sender: TObject);
procedure clean_up1Click(Sender: TObject);
procedure remove_colour1Click(Sender: TObject);
procedure Returntodefaultsettings1Click(Sender: TObject);
procedure rotateleft1Click(Sender: TObject);
procedure saturation_factor_plot1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure saturation_factor_plot1MouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure savesettings1Click(Sender: TObject);
procedure Polynomial1Change(Sender: TObject);
procedure remove_markers1Click(Sender: TObject);
procedure Panel1MouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure Panel1MouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure show_statistics1Click(Sender: TObject);
procedure SimpleIPCServer1MessageQueued(Sender: TObject);
procedure StatusBar1MouseEnter(Sender: TObject);
procedure stretch_draw_fits1Click(Sender: TObject);
procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
procedure variable_star_annotation1Click(Sender: TObject);
procedure zoomfactorone1Click(Sender: TObject);
procedure zoomin1Click(Sender: TObject);
procedure zoomout1Click(Sender: TObject);
procedure astrometric_solve_image1Click(Sender: TObject);
procedure min2EditingDone(Sender: TObject);
procedure remove_above1Click(Sender: TObject);
procedure remove_below1Click(Sender: TObject);
procedure remove_left1Click(Sender: TObject);
procedure remove_right1Click(Sender: TObject);
procedure select_directory_thumb1Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure OpenDialog1SelectionChange(Sender: TObject);
procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer );
procedure recent1Click(Sender: TObject);
procedure Remove_deep_sky_object1Click(Sender: TObject);
procedure ShowFITSheader1Click(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ra1Change(Sender: TObject);
procedure dec1Change(Sender: TObject);
procedure solve_button1Click(Sender: TObject);
procedure SaveFITSwithupdatedheader1Click(Sender: TObject);
procedure Memo1Change(Sender: TObject);
procedure SaveasJPGPNGBMP1Click(Sender: TObject);
procedure LoadFITSPNGBMPJPEG1Click(Sender: TObject);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormResize(Sender: TObject);
procedure batch_add_solution1Click(Sender: TObject);
procedure flip_horizontal1Click(Sender: TObject);
procedure flip_vertical1Click(Sender: TObject);
procedure demosaic_bayermatrix1Click(Sender: TObject);
procedure star_annotation1Click(Sender: TObject);
procedure Undo1Click(Sender: TObject);
procedure stretch_draw1Click(Sender: TObject);
procedure Copyposition1Click(Sender: TObject);
procedure Copypositionindeg1Click(Sender: TObject);
procedure writeposition1Click(Sender: TObject);
procedure Enter_annotation1Click(Sender: TObject);
procedure Stackimages1Click(Sender: TObject);
procedure Saveasfits1Click(Sender: TObject);
procedure Export_image1Click(Sender: TObject);
procedure CropFITSimage1Click(Sender: TObject);
procedure maximum1Scroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
procedure stretch1Change(Sender: TObject);
procedure histogram1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure maximum1Change(Sender: TObject);
procedure minimum1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure DisplayHint(Sender: TObject);
end;
var
mainwindow: Tmainwindow;
type
image_array = array of array of array of Single;
star_list = array of array of double;
Theader =record {contains the most important header info}
height : integer;{image height}
width : integer;
naxis : integer;{number of dimensions}
naxis3 : integer;{number of colors}
crpix1 : double; {reference point X}
crpix2 : double;
cdelt1 : double; {X pixel size (deg)}
cdelt2 : double; {Y pixel size (deg)}
ra0 : double; {mount position}
dec0 : double;
crota1 : double; {image rotation at center in degrees}
crota2 : double; {image rotation at center in degrees}
cd1_1 : double; {solution matrix}
cd1_2 : double;
cd2_1 : double;
cd2_2 : double;
exposure : double;
datamin_org : double;
datamax_org : double;{for update histogram}
set_temperature : integer;
dark_count : integer;
light_count : integer;
flat_count : integer;
flatdark_count : integer;
egain : string; {gain in e-/adu}
gain : string; {gain in 0.1dB or else}
date_obs : string;
calstat : string;
filter_name: string;
end;
type
timgbackup = record
head_val: Theader;{most important header values}
header : string; {full header text}
filen : string; {filename}
xbinning: double; {for binning routine. If twice binned or SQM routine}
ybinning: double;
XPIXSZ : double;
YPIXSZ : double;
img : image_array;
end;
var
img_backup : array of timgbackup;{dynamic so memory can be freed}
img_loaded,img_temp,img_dark,img_flat,img_bias,img_average,img_variance,img_buffer,img_final : image_array;
head, {for lights}
head_2, {for analysing lights and dark, flats}
head_ref {for reference light in stacking}
: Theader;{contains the most important header info}
settingstring :tstrings; {settings for save and loading}
user_path : string;{c:\users\name\appdata\local\astap or ~/home/.config/astap}
distortion_data : star_list;
filename2: string;
nrbits,size_backup,index_backup : integer;{number of backup images for ctrl-z, numbered 0,1,2,3}
ra_mount,dec_mount,{telescope ra,dec}
Xbinning,Ybinning,
ra_radians,dec_radians, pixel_size : double;
var
a_order,ap_order: integer;{Simple Imaging Polynomial use by astrometry.net, if 2 then available}
a_0_0, a_0_1, a_0_2, a_0_3, a_1_0, a_1_1, a_1_2, a_2_0, a_2_1, a_3_0 : double; {SIP, Simple Imaging Polynomial use by astrometry.net, Spitzer}
b_0_0, b_0_1, b_0_2, b_0_3, b_1_0, b_1_1, b_1_2, b_2_0, b_2_1, b_3_0 : double; {SIP, Simple Imaging Polynomial use by astrometry.net, Spitzer}
ap_0_0, ap_0_1,ap_0_2, ap_0_3, ap_1_0, ap_1_1, ap_1_2, ap_2_0, ap_2_1, ap_3_0 : double;{SIP, Simple Imaging Polynomial use by astrometry.net}
bp_0_0, bp_0_1,bp_0_2, bp_0_3, bp_1_0, bp_1_1, bp_1_2, bp_2_0, bp_2_1, bp_3_0 : double;{SIP, Simple Imaging Polynomial use by astrometry.net}
histogram : array[0..2,0..65535] of integer;{red,green,blue,count}
his_total_red, his_total_green,his_total_blue,extend_type,r_aperture : integer; {histogram number of values}
his_mean,noise_level : array[0..2] of integer;
stretch_c : array[0..32768] of single;{stretch curve}
stretch_on, esc_pressed, fov_specified,unsaved_import, last_extension : boolean;
star_level,star_bg,sd_bg, magn_limit : double;
object_name,
imagetype ,sitelat, sitelong,centalt,centaz: string;
focus_temp,cblack,cwhite,sqmfloat :double; {from FITS}
subsamp, focus_pos : integer;{not always available. For normal DSS =1}
date_avg,ut,pltlabel,plateid,telescop,instrum,origin,sqm_value : string;
old_crpix1,old_crpix2,old_crota1,old_crota2,old_cdelt1,old_cdelt2,old_cd1_1,old_cd1_2,old_cd2_1,old_cd2_2 : double;{for backup}
warning_str,{for solver}
roworder :string;
copy_paste_x,
copy_paste_y,
copy_paste_w,
copy_paste_h : integer;
position_find: Integer; {for fits header memo1 popup menu}
var {################# initialised variables #########################}
PatternToFind : string=''; {for fits header memo1 popup menu }
hist_range {range histogram 255 or 65535 or streched} : integer=255;
fits_file: boolean=false;
image_move_to_center : boolean=false;
xpixsz: double=0;//Pixel Width in microns (after binning)
ypixsz: double=0;//Pixel height in microns (after binning)
focallen: double=0;
lat_default: string='';
long_default: string='';
down_x: integer=0;
down_y: integer=0;
down_xy_valid: boolean=false;{required for Linux GTK.}
startX: integer=0; {range 0..}
startY: integer=0;
stopX: integer=0; {range 0..}
stopY: integer=0;
width_radians : double=(140/60)*pi/180;
height_radians: double=(100/60)*pi/180;
mouse_enter : integer=0;{for crop function}
application_path:string='';{to be set in main}
database_path:string='';{to be set in main}
bayerpat: string='';{bayer pattern}
bayerpattern_final :integer=2; {ASI294, ASI071, most common pattern}
sip : boolean=false; {use SIP coefficients}
xbayroff: double=0;{additional bayer pattern offset to apply}
Ybayroff: double=0;{additional bayer pattern offset to apply}
annotated : boolean=false;{any annotation in fits file?}
sqm_key : ansistring='SQM ';
centaz_key : ansistring='CENTAZ ';
hfd_median : double=0;{median hfd, use in reporting in write_ini}
hfd_counter: integer=0;{star counter (for hfd_median), use in reporting in write_ini}
aperture_ratio: double=0; {ratio flux_aperture/hfd_median}
flux_aperture : double=99;{circle where flux is measured}
annulus_radius : integer=14;{inner of square where background is measured. Square has width and height twice annulus_radius}
copy_paste :boolean=false;
shape_fitsX: double=0;
shape_fitsY: double=0;
shape_fitsX2: double=0;
shape_fitsY2: double=0;
shape_fitsX3: double=0;
shape_fitsY3: double=0;
shape_nr: integer=1;
shape_marker1_fitsX: double=10;
shape_marker1_fitsY: double=10;
shape_marker2_fitsX: double=20;
shape_marker2_fitsY: double=20;
shape_marker3_fitsX: double=0;
shape_marker3_fitsY: double=0;
shape_marker4_fitsX: double=0;
shape_marker4_fitsY: double=0;
commandline_execution : boolean=false;{program executed in command line}
commandline_log : boolean=false;{file log request in command line}
stdin_mode : boolean=false;{file send via stdin}
errorlevel : integer=0;{report errors when shutdown}
mouse_positionRADEC1 : string='';{For manual reference solving}
mouse_positionRADEC2 : string='';{For manual reference solving}
flipped_img : string='';
bayer_pattern : array[0..3] of string=('GRBG',
'BGGR',
'RGGB',
'GBRG');
annotation_color: tcolor=clyellow;
annotation_diameter : integer=20;
pedestal : integer=0;
procedure ang_sep(ra1,dec1,ra2,dec2 : double;out sep: double);
function load_fits(filen:string;light {load as light or dark/flat},load_data,update_memo: boolean;get_ext: integer;out head: Theader; out img_loaded2: image_array): boolean;{load fits file}
procedure plot_fits(img: timage;center_image,show_header:boolean);
procedure use_histogram(img: image_array; update_hist: boolean);{get histogram}
procedure HFD(img: image_array;x1,y1,rs {boxsize}: integer;aperture_small:double; out hfd1,star_fwhm,snr{peak/sigma noise}, flux,xc,yc:double);{calculate star HFD and FWHM, SNR, xc and yc are center of gravity, rs is the boxsize, aperture for the flux measurment. All x,y coordinates in array[0..] positions}
procedure backup_img;
procedure restore_img;
function load_image(re_center, plot:boolean) : boolean; {load fits or PNG, BMP, TIF}
procedure demosaic_bayer(var img: image_array); {convert OSC image to colour}
Function INT_IEEE4_reverse(x: double):longword;{adapt intel floating point to non-intel float}
function save_fits(img: image_array;filen2:ansistring;type1:integer;override2:boolean): boolean;{save to 8, 16 OR -32 BIT fits file}
procedure update_text(inpt,comment1:string);{update or insert text in header}
procedure add_text(inpt,comment1:string);{add text to header memo}
procedure update_longstr(inpt,thestr:string);{update or insert long str including single quotes}
procedure add_long_comment(descrip:string);{add long text to header memo. Split description over several lines if required}
procedure update_generic(message_key,message_value,message_comment:string);{update header using text only}
procedure update_integer(inpt,comment1:string;x:integer);{update or insert variable in header}
procedure add_integer(inpt,comment1:string;x:integer);{add integer variable to header}
procedure update_float(inpt,comment1:string;x:double);{update keyword of fits header in memo}
procedure remove_key(inpt:string; all:boolean);{remove key word in header. If all=true then remove multiple of the same keyword}
function strtofloat1(s:string): double;{string to float, error tolerant}
function strtofloat2(s:string): double;{works with either dot or komma as decimal separator}
function TextfileSize(const name: string): LongInt;
function floattostr6(x:double):string;
function floattostr4(x:double):string;
procedure update_menu(fits :boolean);{update menu if fits file is available in array or working from image1 canvas}
procedure get_hist(colour:integer;img :image_array);{get histogram of img_loaded}
procedure save_settings2;
procedure progress_indicator(i:double; info:string);{0 to 100% indication of progress}
{$ifdef mswindows}
procedure ExecuteAndWait(const aCommando: string; show_console:boolean);
{$else} {unix}
procedure execute_unix(const execut:string; param: TStringList; show_output: boolean);{execute linux program and report output}
procedure execute_unix2(s:string);
{$endif}
function mode(img :image_array;colorm,xmin,xmax,ymin,ymax,max1:integer):integer;{find the most common value of a local area and assume this is the best average background value}
function get_negative_noise_level(img :image_array;colorm,xmin,xmax,ymin,ymax: integer;common_level:double): double;{find the negative noise level below most_common_level of a local area}
function prepare_ra5(rax:double; sep:string):string; {radialen to text format 24h 00.0}
function prepare_ra6(rax:double; sep:string):string; {radialen to text format 24h 00 00}
function prepare_dec4(decx:double;sep:string):string; {radialen to text format 90d 00 }
function prepare_dec(decx:double; sep:string):string; {radialen to text, format 90d 00 00}
function prepare_ra(rax:double; sep:string):string; {radialen to text, format 24: 00 00.0 }
function prepare_ra8(rax:double; sep:string):string; {radialen to text, format 24: 00 00.00 }
Function prepare_dec2(decx:double; sep:string):string; {radialen to text, format 90d 00 00.1}
function inttostr5(x:integer):string;{always 5 digit}
function SMedian(list: array of double; leng: integer): double;{get median of an array of double. Taken from CCDciel code but slightly modified}
procedure mad_median(list: array of double; leng :integer;out mad,median :double);{calculate mad and median without modifying the data}
procedure DeleteFiles(lpath,FileSpec: string);{delete files such *.wcs}
procedure new_to_old_WCS;{convert new style FITsS to old style}
procedure old_to_new_WCS;{ convert old WCS to new}
procedure show_marker_shape(shape: TShape; shape_type,w,h,minimum:integer; fitsX,fitsY: double);{show manual alignment shape}
function check_raw_file_extension(ext: string): boolean;{check if extension is from raw file}
function convert_raw(loadfile,savefile :boolean;var filename3: string; var img: image_array): boolean; {convert raw to fits file using DCRAW or LibRaw}
function unpack_cfitsio(filename3: string): boolean; {convert .fz to .fits using funpack}
function pack_cfitsio(filename3: string): boolean; {convert .fz to .fits using funpack}
function load_TIFFPNGJPEG(filen:string; var head :theader; var img_loaded2: image_array) : boolean;{load 8 or 16 bit TIFF, PNG, JPEG, BMP image}
procedure get_background(colour: integer; img :image_array;calc_hist, calc_noise_level: boolean; out background, starlevel: double); {get background and star level from peek histogram}
function extract_exposure_from_filename(filename8: string):integer; {try to extract exposure from filename}
function extract_temperature_from_filename(filename8: string): integer; {try to extract temperature from filename}
function extract_objectname_from_filename(filename8: string): string; {try to extract exposure from filename}
function test_star_spectrum(r,g,b: single) : single;{test star spectrum. Result of zero is perfect star spectrum}
procedure measure_magnitudes(annulus_rad:integer; deep: boolean; var stars :star_list);{find stars and return, x,y, hfd, flux}
function binX2X3_file(binfactor:integer) : boolean; {converts filename2 to binx2,binx3, binx4 version}
procedure ra_text_to_radians(inp :string; out ra : double; out errorRA :boolean); {convert ra in text to double in radians}
procedure dec_text_to_radians(inp :string; out dec : double; out errorDEC :boolean); {convert ra in text to double in radians}
function image_file_name(inp : string): boolean; {readable image name?}
procedure plot_annotations(use_solution_vectors,fill_combo: boolean); {plot annotations stored in fits header. Offsets are for blink routine}
procedure RGB2HSV(r,g,b : single; out h {0..360}, s {0..1}, v {0..1}: single);{RGB to HSVB using hexcone model, https://en.wikipedia.org/wiki/HSL_and_HSV}
procedure HSV2RGB(h {0..360}, s {0..1}, v {0..1} : single; out r,g,b: single); {HSV to RGB using hexcone model, https://en.wikipedia.org/wiki/HSL_and_HSV}
function get_demosaic_pattern : integer; {get the required de-bayer range 0..3}
Function LeadingZero(w : integer) : String;
procedure log_to_file(logf,mess : string);{for testing}
procedure log_to_file2(logf,mess : string);{used for platesolve2 and photometry}
procedure demosaic_advanced(var img : image_array);{demosaic img_loaded}
procedure bin_X2X3X4(binfactor:integer);{bin img_loaded 2x or 3x or 4x}
procedure local_sd(x1,y1, x2,y2{regio of interest},col : integer; img : image_array; out sd,mean :double; out iterations :integer);{calculate mean and standard deviation in a rectangle between point x1,y1, x2,y2}
function extract_raw_colour_to_file(filename7,filtern: string; xp,yp : integer) : string;{extract raw colours and write to file}
function fits_file_name(inp : string): boolean; {fits file name?}
function prepare_IAU_designation(rax,decx :double):string;{radialen to text hhmmss.s+ddmmss format}
procedure sensor_coordinates_to_celestial(fitsx,fitsy : double; out ram,decm : double {fitsX, Y to ra,dec});
procedure celestial_to_pixel(ra_t,dec_t: double; out fitsX,fitsY: double);{ra,dec to fitsX,fitsY}
procedure show_shape_manual_alignment(index: integer);{show the marker on the reference star}
procedure write_astronomy_wcs(filen:string);
function savefits_update_header(filen2:string) : boolean;{save fits file with updated header}
procedure plot_the_annotation(x1,y1,x2,y2:integer; typ:double; name,magn :string);{plot annotation from header in ASTAP format}
procedure reset_fits_global_variables(light :boolean; out head:theader ); {reset the global variable}
function convert_to_fits(var filen: string): boolean; {convert to fits}
procedure QuickSort(var A: array of double; iLo, iHi: Integer) ;{ Fast quick sort. Sorts elements in the array list with indices between lo and hi}
procedure convert_mono(var img: image_array);
procedure Wait(wt:single=500); {smart sleep}
procedure update_header_for_colour; {update naxis and naxis3 keywords}
procedure flip(x1,y1 : integer; out x2,y2 :integer);{array to screen or screen to array coordinates}
const bufwide=1024*120;{buffer size in bytes}
head1: array [0..28] of ansistring=
(
{0}('SIMPLE = T / FITS header '),
{1}('BITPIX = 8 / Bits per entry '),
{2}('NAXIS = 2 / Number of dimensions '),
{3}('NAXIS1 = 100 / length of x axis '),
{4}('NAXIS2 = 100 / length of y axis '),
{5}('NAXIS3 = 3 / length of z axis (mostly colors) '),
{6}('EQUINOX = 2000.0 / Equinox of coordinates '),
{7}('DATAMIN = 0 / Minimum data value '),
{8}('DATAMAX = 255 / Maximum data value '),
{9}('BZERO = 0.0 / physical_value = BZERO + BSCALE * array_value '),
{10}('BSCALE = 1.0 / physical_value = BZERO + BSCALE * array_value '),
{11}('CTYPE1 = '+#39+'RA---TAN'+#39+' / first parameter RA , projection TANgential '),
{12}('CTYPE2 = '+#39+'DEC--TAN'+#39+' / second parameter DEC, projection TANgential '),
{13}('CUNIT1 = '+#39+'deg '+#39+' / Unit of coordinates '),
{14}('CRPIX1 = 0.0 / X of reference pixel '),
{15}('CRPIX2 = 0.0 / Y of reference pixel '),
{16}('CRVAL1 = 0.0 / RA of reference pixel (deg) '),
{17}('CRVAL2 = 0.0 / DEC of reference pixel (deg) '),
{18}('CDELT1 = 0.0 / X pixel size (deg) '),
{19}('CDELT2 = 0.0 / Y pixel size (deg) '),
{20}('CROTA1 = 0.0 / Image twist of X axis (deg) '),
{21}('CROTA2 = 0.0 / Image twist of Y axis W of N (deg) '),
{22}('CD1_1 = 0.0 / CD matrix to convert (x,y) to (Ra, Dec) '),
{23}('CD1_2 = 0.0 / CD matrix to convert (x,y) to (Ra, Dec) '),
{24}('CD2_1 = 0.0 / CD matrix to convert (x,y) to (Ra, Dec) '),
{25}('CD2_2 = 0.0 / CD matrix to convert (x,y) to (Ra, Dec) '),
{26}('PLTSOLVD= T / ASTAP from hnsky.org '),
{27}('END '),
{28}(' ')); {should be empthy !!}
pi_=pi; {for evaluate in debugging}
type byteX3 = array[0..2] of byte;
byteXX3 = array[0..2] of word;
byteXXXX3 = array[0..2] of single;
var
TheFile3 : tfilestream;
Reader : TReader;
fitsbuffer : array[0..bufwide] of byte;{buffer for 8 bit FITS file}
fitsbuffer2: array[0..round(bufwide/2)] of word absolute fitsbuffer;{buffer for 16 bit FITS file}
fitsbufferRGB: array[0..trunc(bufwide/3)] of byteX3 absolute fitsbuffer;{buffer for 8 bit RGB FITS file}
fitsbufferRGB16: array[0..trunc(bufwide/6)] of byteXX3 absolute fitsbuffer;{buffer for 16 bit RGB PPM file}
fitsbufferRGB32: array[0..trunc(bufwide/12)] of byteXXXX3 absolute fitsbuffer;{buffer for -32 bit PFM file}
fitsbuffer4: array[0..round(bufwide/4)] of longword absolute fitsbuffer;{buffer for floating bit ( -32) FITS file}
fitsbuffer8: array[0..trunc(bufwide/8)] of int64 absolute fitsbuffer;{buffer for floating bit ( -64) FITS file}
fitsbufferSINGLE: array[0..round(bufwide/4)] of single absolute fitsbuffer;{buffer for floating bit ( -32) FITS file}
fitsbufferDouble: array[0..round(bufwide/8)] of double absolute fitsbuffer;{buffer for floating bit ( -64) FITS file}
implementation
uses unit_dss, unit_stack, unit_tiff,unit_star_align, unit_astrometric_solving, unit_star_database, unit_annotation, unit_thumbnail, unit_xisf,unit_gaussian_blur,unit_inspector_plot,unit_asteroid,
unit_astrometry_net, unit_live_stacking, unit_hjd,unit_hyperbola, unit_aavso, unit_listbox, unit_sqm, unit_stars_wide_field,unit_constellations,unit_raster_rotate;
{$R astap_cursor.res} {FOR CURSORS}
{$IFDEF fpc}
{$R *.lfm}
{$else} {delphi}
{$R *.dfm}
{$endif}
var
recent_files : tstringlist;
stop_RX, stop_RY, start_RX,start_RY :integer; {for rubber rectangle. These values are the same startX,.... except if image is flipped}
object_xc,object_yc, object_raM,object_decM : double; {near mouse auto centered object position}
var {################# initialised variables #########################}
bandpass: double=0;{from fits file}
equinox:double=0;{from fits file}
SaveasTIFF1filterindex : integer=1;
SaveasJPGPNGBMP1filterindex : integer=4;
LoadFITSPNGBMPJPEG1filterindex: integer=1;
marker_position : string='';
mouse_fitsx : double=0;
mouse_fitsy : double=0;
coord_frame : integer=0; {J2000=0 or galactic=1}
hfd_arcseconds: boolean=false; {HFD in arc seconds or pixels}
{$IFDEF Darwin}
font_name: string= 'Courier';
font_size : integer = 9;
{$else}
{$IFDEF linux}
font_name: string= 'Monospace';
font_size : integer= 10;
{$ELSE}
font_name: string= 'Courier';
font_size : integer = 9;
{$ENDIF}
{$ENDIF}
font_charset : integer=0; {Ansi_char}
font_style : tFontStyles=[];
font_color : tcolor= cldefault;
freetext : string='';
const
crMyCursor = 5;
procedure reset_fits_global_variables(light :boolean;out head:theader); {reset the global variable}
begin
if light then
begin
head.crota2:=99999;{just for the case it is not available, make it later zero}
head.crota1:=99999;
head.ra0:=0;
head.dec0:=0;
ra_mount:=99999;
dec_mount:=99999;
head.cdelt1:=0;
head.cdelt2:=0;
xpixsz:=0;
ypixsz:=0;
focallen:=0;
subsamp:=1;{just for the case it is not available}
head.cd1_1:=0;{just for the case it is not available}
head.cd1_2:=0;{just for the case it is not available}
head.cd2_1:=0;{just for the case it is not available}
head.cd2_2:=0;{just for the case it is not available}
bayerpat:='';{reset bayer pattern}
xbayroff:=0;{offset to used to correct BAYERPAT due to flipping}
ybayroff:=0;{offset to used to correct BAYERPAT due to flipping}
roworder:='';{'BOTTOM-UP'= lower-left corner first in the file. or 'TOP-DOWN'= top-left corner first in the file.}
a_order:=0;{Simple Imaging Polynomial use by astrometry.net, if 2 then available}
ap_order:=0;{Simple Imaging Polynomial use by astrometry.net, if 2 then available}
a_0_0:=0; a_0_1:=0; a_0_2:=0; a_0_3:=0; a_1_0:=0; a_1_1:=0; a_1_2:=0;a_2_0:=0; a_2_1:=0; a_3_0:=0;
b_0_0:=0; b_0_1:=0; b_0_2:=0; b_0_3:=0; b_1_0:=0; b_1_1:=0; b_1_2:=0;b_2_0:=0; b_2_1:=0; b_3_0:=0;
ap_0_0:=0; ap_0_1:=0; ap_0_2:=0; ap_0_3:=0; ap_1_0:=0; ap_1_1:=0; ap_1_2:=0; ap_2_0:=0; ap_2_1:=0; ap_3_0:=0;
bp_0_0:=0; bp_0_1:=0; bp_0_2:=0; bp_0_3:=0; bp_1_0:=0; bp_1_1:=0; bp_1_2:=0; bp_2_0:=0; bp_2_1:=0; bp_3_0:=0;
centalt:='';{assume no data available}
centaz:='';{assume no data available}
x_coeff[0]:=0; {reset DSS_polynomial, use for check if there is data}
y_coeff[0]:=0;
a_order:=0; {SIP_polynomial, use for check if there is data}
ap_order:=0; {SIP_polynomial, use for check if there is data}
xbinning:=1;{normal}
ybinning:=1;
date_avg:='';ut:=''; pltlabel:=''; plateid:=''; telescop:=''; instrum:=''; origin:=''; object_name:='';{clear}
sitelat:=''; sitelong:='';
focus_temp:=999;{assume no data available}
focus_pos:=0;{assume no data available}
annotated:=false; {any annotation in the file}
flux_magn_offset:=0;{factor to calculate magnitude from flux, new file so set to zero}
sqm_value:='';
end;
head.date_obs:='';
head.calstat:='';{indicates calibration state of the image; B indicates bias corrected, D indicates dark corrected, F indicates flat corrected, S stacked. Example value DFB}
head.filter_name:='';
head.naxis:=-1;{assume failure}
head.naxis3:=1;
head.datamin_org:=0;
imagetype:='';
head.exposure:=0;
head.set_temperature:=999;
head.gain:='';
head.egain:='';{assume no data available}
end;{reset global variables}
function load_fits(filen:string;light {load as light or dark/flat},load_data,update_memo: boolean;get_ext: integer;out head: Theader; out img_loaded2: image_array): boolean;{load fits file}
{if light=true then read also head.ra0, head.dec0 ....., else load as dark, flat}
{if load_data then read all else header only}
{if reset_var=true, reset variables to zero}
var
header : array[0..2880] of ansichar;
i,j,k,nr,error3,naxis1, reader_position,n,file_size : integer;
dummy,scale,ccd_temperature, jd2 : double;
col_float,bscale,measured_max,scalefactor : single;
s : string[3];
bzero : integer;{zero shift. For example used in AMT, Tricky do not use int64, maxim DL writes BZERO value -2147483647 as +2147483648 !! }
aline,number,field : ansistring;
rgbdummy : byteX3;
word16 : word; {for 16 signed integer}
int_16 : smallint absolute word16;{for 16 signed integer}
x_longword : longword;
x_single : single absolute x_longword;{for conversion 32 bit "big-endian" data}
int_32 : integer absolute x_longword;{for 32 bit signed integer}
x_qword : qword;
x_double : double absolute x_qword;{for conversion 64 bit "big-endian" data}
int_64 : int64 absolute x_qword;{for 64 bit signed integer}
tfields,tform_counter,header_count,pointer,let : integer;
ttype,tform,tunit : array of string;
tbcol,tform_nr : array of integer;
simple,image,bintable,asciitable : boolean;
abyte : byte;
var {################# initialised variables #########################}
end_record : boolean=false;
procedure close_fits_file; inline;
begin
Reader.free;
TheFile3.free;
end;
Function validate_double:double;{read floating point or integer values}
var t : string[20];
r,err : integer;
begin
t:='';
r:=I+10;{position 11 equals 10}
while ((header[r]<>'/') and (r<=I+29) {pos 30}) do {'/' check is strictly not necessary but safer}
begin {read 20 characters max, position 11 to 30 in string, position 10 to 29 in pchar}
if header[r]<>' ' then t:=t+header[r];
inc(r);