Program Median(Input, Output) ; { Reads all specified images, computes and saves medians etc } Uses WinAPI, { No - it's not Windows. It's BP7.0 32-bit stuff } X_U, { My routines for 32-bit addressing } FITSX_U, { Random assortment of FITS read/write stuff } SORT_U ; { QuickSort } Const MedianName = 'C:\BP\TASS\CD5\H4RMED.TXT' ; { The median file } { required by Flat is actually an edited version of the one } { produced here. Mustn't make things too easy ... } { Analysis area } Min2 : Integer = 2 ; Max2 : Integer = 2033 ; Min1 : Integer = 6 ; Max1 : Integer = 2037 ; NFil = 38 ; Name : Array[0..NFil-1] of String = ('D:\IDARK15.FTS', { Dark file } 'D:\IDARK16.FTS', 'D:\IDARK17.FTS', 'D:\H4R1438.878', 'D:\H4R1438.882', 'D:\H4R1438.886', 'D:\H4R1438.890', 'D:\H4R1438.895', 'D:\H4R1438.899', 'D:\H4R1438.903', 'D:\H4R1439.870', 'D:\H4R1439.875', 'D:\H4R1439.880', 'D:\H4R1439.885', 'D:\H4R1439.891', 'D:\H4R1439.896', 'D:\H4R1439.901', 'D:\H4R1440.871', 'D:\H4R1440.875', 'D:\H4R1440.879', 'D:\H4R1440.884', 'D:\H4R1440.888', 'D:\H4R1440.892', 'D:\H4R1440.897', 'D:\H4R1442.863', 'D:\H4R1442.867', 'D:\H4R1442.871', 'D:\H4R1442.876', 'D:\H4R1442.880', 'D:\H4R1442.885', 'D:\H4R1442.889', 'D:\H4R1446.853', 'D:\H4R1446.858', 'D:\H4R1446.862', 'D:\H4R1446.866', 'D:\H4R1446.871', 'D:\H4R1446.875', 'D:\H4R1446.880') ; X1 = 25 ; { For finding median } Step1 = 50 ; { Pick a value small enough to be useful ... } X2 = 25 ; Step2 = 50 ; { ... and big enough that QuickSort doesn't choke } Var F : FITSInfoT ; { FITS control structure } FNo : Integer ; { Count files } Med : Array[0..NFil] Of Integer ; { The medians } L : Array[0..2031] of Integer ; { Arrays for sorting } Index : Array[0..2031] Of Integer ; Count : Integer ; { Count sampled pixels } I1, I2, N1_M, N2_M : Longint ; OutFile : Text ; { Median file } Begin FileMode := 2 ; Assign(OutFile, MedianName) ; Rewrite(OutFile) ; Writeln(OutFile, '"Medians"') ; N2_M := Max2 - Min2 + 1 ; N1_M := Max1 - Min1 + 1 ; For FNo := 0 to NFil-1 Do Begin Writeln('Median ', Name[FNo]) ; ReadSome(F, Name[FNo], Min1, N1_M, Min2, N2_M) ; I1 := X1 ; Count := 0 ; Repeat I2 := X2 ; Repeat L[Count] := IPtr(F.Image, I1*N2_M+I2)^ ; Inc(Count) ; Inc(I2, Step2) ; Until (I2 >= N2_M) ; Inc(I1, Step1) ; Until (I1 >= N1_M) ; ISort(L, 0, Count-1, Index) ; Med[FNo] := L[Index[Count Div 2]] ; Writeln(Med[FNo]) ; Writeln(OutFile, Med[FNo], ' ', Name[FNo]) ; { I'm sure I was going to do something else with Med } { Now ... what could it have been? } End ; Close(OutFile) ; End. { Median }