CCDciel / ASTAP - THINGS TO DO IN THE FUTURE ============================================= Status at the end of the first review round (items A to F of ccdciel_bugs_and_bad_practices.txt implemented, compiled and partly tested). 1. TEST THE CORRECTIONS ----------------------- - Run the tests in ccdciel_behaviour_changes_to_test.txt. The A-D changes are compiled and partly tested (T1.1 close program OK on Windows 10); the E-F changes are compiled but not yet run. 2. CCDCIEL UNITS NOT YET REVIEWED IN DEPTH ------------------------------------------ Of the 143 units about 30 were reviewed in depth, several only partly. The others were only covered by automatic pattern scans (empty except blocks, loop bounds, self-assignments, Format() argument counts, unreleased objects, asynchronous calls), which find typical slips but not logic errors. Suggested order (most impact first): 1. Cameras cu_camera, cu_ascomcamera, cu_ascomrestcamera, rest of cu_indicamera (exposure start/abort, timeouts, image download, cooling). 2. Weather and safety (unattended operation depends on them) cu_weather, cu_safety, cu_ascomweather, cu_ascomrestweather, cu_indiweather, cu_ascomsafety, cu_ascomrestsafety, cu_indisafety, fu_weather, fu_safety. 3. Data integrity of compressed images unit_ricecomp (Rice compressor/decompressor core) and NativePackFits in unit_ricecomp_fits. 4. Guiding loop rest of cu_autoguider_internal (guide corrections, dithering, spectroscopy functions), cu_autoguider_dither. 5. Remaining device drivers filter wheels (cu_wheel, cu_ascomwheel, cu_ascomrestwheel, cu_indiwheel, cu_incamerawheel, cu_manualwheel), rotators, switches, covers/calibrators. 6. Remaining program logic rest of pu_main (capture, autofocus control, device connection), fu_starprofile (autofocus), fu_capture, fu_sequence, pu_edittargets. 7. Lower risk planetarium links (cu_planetarium*), Alpaca discovery (cu_alpacamanagement), websocket units (third-party), u_libraw, astronomy maths (u_ephem, uDE, u_refraction), remaining GUI forms and dialogs. Parts of reviewed units that were NOT covered: cu_fits: star detection, HFD, photometry, stacking (Math), debayer algorithms. pu_main: everything except the TCP/JSON-RPC server, the meridian flip, picture loading and the menu actions changed for A3. cu_tiff: read_tiff (dead code in CCDciel, but used in ASTAP). 3. ITEMS NOT IMPLEMENTED (see the status lines in the bug report) ----------------------------------------------------------------- D1 Empty except blocks (182) - log at least the message D2 Application.ProcessMessages re-entrancy - design change D7 "with" statements - readability D9 Size of pu_main.pas - split into units D10 Global DecimalSeparator - own TFormatSettings D11 Remote access without authentication - intended; optional token F9 Blocking waits in the sequence engine - state machine with timers and the partial items: A3, A5, B6, C10, C12, D8, E12, E13, F6. 4. IMPROVEMENTS --------------- See ccdciel_improvements.txt (unit tests for FITS/.fz round trips, compiler warnings as errors, one worker-thread helper, device result type, Options dialog settings for /Dome/ActionTimeout and /Focuser/MoveTimeout, etc.). 5. ASTAP / ASTAP_CLI UNITS (unit_tiff, unit_ricecomp and the _unthreaded copies) -------------------------------------------------------------------------------- Checked against the CCDciel findings. The threaded ASTAP units are the same code as CCDciel's cu_tiff.pas and unit_ricecomp.pas before the corrections (only the unit name, the CPU count function and one comment differ). Corrections that apply. STATUS: all five implemented (2026, see astap_corrections.diff); every change is marked "2026 fix (review item ASn)". Still to do: compile and test in ASTAP and ASTAP_CLI. AS1 unit_tiff.pas, compress_image_strips (= CCDciel C7) height2=0 gives thread_count=0 and a division by zero on the next line. Fix: refuse an empty image before computing thread_count. AS2 unit_tiff.pas, compress_image_strips (= CCDciel C7 / A6) An exception in a strip thread (TStripCompressThread has try/finally, no except) is stored in FatalException and never checked; the strip stream stays nil and the writer then uses it. Fix: check FatalException and nil strips after WaitFor, free the strips, raise; in save_tiff_16/32/ 48/96 catch it, free the file stream, delete the partial file and return false (this is how it was done in CCDciel's cu_tiff.pas). AS3 unit_ricecomp.pas, rice_decode_tiles and rice_encode_rows (= CCDciel A6) Same pattern: TRiceTileThread and TRiceEncodeThread use try/finally without except, and the dispatchers do not check FatalException. - decoder: the tiles of a failed worker stay blank and no error is reported (err_decode stays false); - encoder: ok stays true while tile_data[] of the failed rows is nil, so the caller writes a nil tile (access violation or corrupt .fz file). Fix: after WaitFor, if FatalException<>nil set err_decode (decoder) or ok:=false (encoder) with its message. Not applicable to unit_ricecomp_unthreaded.pas: without threads the exception reaches the caller normally. AS4 save_tiff_new in unit_tiff.pas and unit_tiff_unthreaded.pas (found while implementing CCDciel C7) The test "if bitpix<=16 then 16-bit writer" is also true for a negative FITS BITPIX (-32, -64), so a float image is written as 16-bit TIFF if a caller passes the FITS BITPIX value. CCDciel now passes 32. Check the ASTAP / ASTAP_CLI callers; if they can pass -32/-64, use abs(bitpix) or test for bitpix=8/16 explicitly. Implemented: the test is now abs(bitpix)<=16 (both TIFF units). AS5 NaN pixels (related to CCDciel C2) The TIFF writers (round(dum) after the 0..65535 clamp) and the Rice encoder (round(img[0,y,x])) raise EInvalidOp for a NaN pixel, because the comparisons in the clamp are false for NaN. In the threaded Rice encoder this becomes AS3. Applies only if ASTAP image arrays can contain NaN (CCDciel replaces NaN by 0 when reading since C2) - check the ASTAP FITS reader; otherwise add "if IsNan(v) then v:=0" before round. Implemented in all four units: NaN is written as 0; the Rice encoders also clamp to 0..65535 before round() (round raised for huge values). Checked and OK: - unit_tiff_unthreaded.pas: flip_H works correctly (the bug fixed in the threaded version, "flip_H previously had no effect", is not present). - unit_tiff_unthreaded.pas: no strip threads, so AS1/AS2 do not apply. - unit_ricecomp_unthreaded.pas: rice_encode_rows already returns for height<=0; rice_decode_tiles returns for ntiles<=0. Not reviewed (to do): - read_tiff (all versions): it is used in ASTAP and parses untrusted files (strip offsets/byte counts read from the file without limits, 32-bit row size arithmetic). Review together with CCDciel item 2.3 above. - The Rice decoder/encoder core (fits_rdecomp*, fits_rcomp_short) - same code as CCDciel unit_ricecomp, see item 2.3. - If ASTAP has its own copy of the .fz FITS layer (CCDciel unit_ricecomp_fits: NativeUnpackFits, card writers), CCDciel items C4 and C5 apply to it as well (keywords starting with Z dropped, ZBITPIX not checked, unvalidated ZNAXIS, MakeFloatCard/MakeStrCard).