From c3b11576b328c62053ccaf98f4c76a4cbb909099 Mon Sep 17 00:00:00 2001
From: Laura Schreiber <laura.schreiber@inaf.it>
Date: Tue, 10 Sep 2024 10:45:01 +0200
Subject: [PATCH] version with where_stars optimised

---
 extract_stars.pro | 17 +++++++++++++++--
 is_star.pro       | 33 +++++++++++++++++++++++++++++++++
 merge_list.pro    | 19 ++++++++++++-------
 readme.txt        | 23 ++++++++++-------------
 reverse_class.pro | 10 +++++-----
 sort_list.pro     | 23 +++++++++++++++--------
 star_param.pro    | 13 +++++++------
 starfinder.pro    |  8 ++++++--
 starlist.pro      | 24 +++++++++++++++---------
 update_list.pro   | 27 ++++++++++++++-------------
 10 files changed, 132 insertions(+), 65 deletions(-)
 create mode 100644 is_star.pro

diff --git a/extract_stars.pro b/extract_stars.pro
index ff0e6a8..0b98a11 100644
--- a/extract_stars.pro
+++ b/extract_stars.pro
@@ -1,4 +1,4 @@
-; $Id: extract_stars.pro, v 1.1 Mar 2012 e.d. $
+; $Id: extract_stars.pro, v 2.0 Sep 2024 e.d. $
 ;
 ;+
 ; NAME:
@@ -26,11 +26,24 @@
 ; MODIFICATION HISTORY:
 ; 	Written by:	Emiliano Diolaiti, June 2001.
 ;   1) Created this file (E. D., March 2012).
+;   2) Modified data type: from array of structures to structure of arrays (E.D., September 2024).
 ;-
 
 FUNCTION extract_stars, list, n
 
     on_error, 2
     s = where_stars(list, n)
-    if  n ne 0  then  return, list[s]  else  return, -1
+    if  n ne 0  then begin
+      sublist = starlist(n)
+      sublist.x = list.x[s]
+      sublist.sigma_x = list.sigma_x[s]
+      sublist.y = list.y[s]
+      sublist.sigma_y = list.sigma_y[s]
+      sublist.f = list.f[s]
+      sublist.sigma_f = list.sigma_f[s]
+      sublist.c = list.c[s]
+      sublist.is_a_star = list.is_a_star[s]
+    endif else $
+      sublist = -1
+    return, sublist
 end
diff --git a/is_star.pro b/is_star.pro
new file mode 100644
index 0000000..203e5a1
--- /dev/null
+++ b/is_star.pro
@@ -0,0 +1,33 @@
+; $Id: is_star.pro, v 1.0 Sep 2024 e.d. $
+;
+;+
+; NAME:
+;	IS_STAR
+;
+; PURPOSE:
+;	Check status of one or more elements in the list of stars and presumed stars.
+;
+; CATEGORY:
+;	STARFINDER auxiliary procedures.
+;
+; CALLING SEQUENCE:
+;	Result = IS_STAR(List, S)
+;
+; INPUTS:
+;	List:	list of stars and presumed stars
+;
+;	S:	subscript(s) of element(s) to be checked
+;
+; OUTPUTS:
+;	Return scalar or array of binary values for each element defined by parameter S.
+;	Returned value is 1 for a confirmed star, 0 otherwise.
+;
+; MODIFICATION HISTORY:
+; 	Written by:	Emiliano Diolaiti, September 2024.
+;-
+
+FUNCTION is_star, list, s
+
+    on_error, 2
+    return, list.is_a_star[s] and 1B
+end
diff --git a/merge_list.pro b/merge_list.pro
index 3138063..da253e2 100644
--- a/merge_list.pro
+++ b/merge_list.pro
@@ -1,4 +1,4 @@
-; $Id: merge_list.pro, v 1.1 Mar 2001 e.d. $
+; $Id: merge_list.pro, v 2.0 Sep 2024 e.d. $
 ;
 ;+
 ; NAME:
@@ -23,6 +23,7 @@
 ; 	Written by:	Emiliano Diolaiti, June 2001.
 ; 	1) Created this file (E. D., March 2012).
 ; 	2) Fixed bug when input list L1 is empty (E. D., April 2012).
+; 	3) Modified data type: from array of structures to structure of arrays (E.D., September 2024).
 ;-
 
 FUNCTION merge_list, l1, l2
@@ -31,13 +32,17 @@ FUNCTION merge_list, l1, l2
     if n_tags(l1) eq 0 then $
        l = l2 else $
     begin
-       n1 = n_elements(l1)
-;       if  n1 eq 0  then  l = l2  else $
-;       begin
-       n2 = n_elements(l2)
+       n1 = n_elements(l1.is_a_star)
+       n2 = n_elements(l2.is_a_star)
        l = starlist(n1 + n2)
-       l[0] = l1  &  l[n1] = l2
-;       endelse
+       l.x = [l1.x, l2.x]
+       l.sigma_x = [l1.sigma_x, l2.sigma_x]
+       l.y = [l1.y, l2.y]
+       l.sigma_y = [l1.sigma_y, l2.sigma_y]
+       l.f = [l1.f, l2.f]
+       l.sigma_f = [l1.sigma_f, l2.sigma_f]
+       l.c = [l1.c, l2.c]
+       l.is_a_star = [l1.is_a_star, l2.is_a_star]
     endelse
     return, l
 end
diff --git a/readme.txt b/readme.txt
index 01de606..34c55d9 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,10 +1,9 @@
-StarFinder v 1.8.2a
+Starfinder v 1.8.2b
 
 
 WEB PAGE
 
-http://davide2.bo.astro.it/?page_id=5128
-
+https://www.ict.inaf.it/gitlab/laura.schreiber/starfinder2
 
 ARCHIVE CONTENT
 
@@ -33,7 +32,7 @@ This archive includes the following files:
 
 INSTALLATION
 
-Open the compressed archive StarFinder.zip and put all its 
+Open the compressed archive Starfinder.zip and put all its 
 content in a new directory named 'starfinder'. Then modify the 
 IDL system variable !Path including the path to the new directory.
 
@@ -44,24 +43,22 @@ THE IDL ASTRONOMY USER'S LIBRARY (http://idlastro.gsfc.nasa.gov).
 INFO / BUGS REPORT
 
 Please send information requests and bug reports to:
-Emiliano Diolaiti (emiliano.diolaiti@oabo.inaf.it)
-Laura Schreiber (laura.schreiber@oabo.inaf.it)
+Laura Schreiber (laura.schreiber@inaf.it)
+Emiliano Diolaiti (emiliano.diolaiti@inaf.it)
+
 
 
 COPYRIGHT
 
-The StarFinder software is provided "as is" without express or implied warranty.
+The Starfinder software is provided "as is" without express or implied warranty.
 It can be used freely for research and educational purposes.
 
 Please reference the authors in any publication resulting from
-the use of the StarFinder code. The references are:
+the use of the Starfinder code. The references are:
 
 Diolaiti E., Bendinelli O., Bonaccini D., Close L.M., Currie D.G., 
 Parmeggiani G., Astronomy & Astrophysics Supplement Series, 147, 
 335, 2000
 
-Schreiber L., Diolaiti E., Bellazzini M., Ciliegi P., Foppiani I., 
-Greggio L., Lanzoni B., Lombini M., Second International Conference 
-on Adaptive Optics for Extremely Large Telescopes, 
-Online at http://ao4elt2.lesia.obspm.fr, id.P57, 
-Bibliographic Code 2011aoel.confP..57S, 2011
+Schreiber L., Diolaiti E., Beltramo-Martin O., Fiorentino G., Proc. SPIE 11448, Adaptive Optics Systems VII, 114480H (14 December 2020); 
+doi: 10.1117/12.2564105
diff --git a/reverse_class.pro b/reverse_class.pro
index e1ec2bd..140f108 100644
--- a/reverse_class.pro
+++ b/reverse_class.pro
@@ -1,4 +1,4 @@
-; $Id: reverse_class.pro, v 1.1 Mar 2012 e.d. $
+; $Id: reverse_class.pro, v 2.0 Sep 2024 e.d. $
 ;
 ;+
 ; NAME:
@@ -22,19 +22,19 @@
 ;		of all elements in the list
 ;
 ; OUTPUTS:
-;	Return list where the classification of the subscripted elements;
-;	is reversed
+;	Return list where the classification of the subscripted elements is reversed
 ;
 ; MODIFICATION HISTORY:
 ; 	Written by:	Emiliano Diolaiti, June 2001.
 ; 	1) Created this file (E.D., March 2012).
+; 	2) Modified data type: from array of structures to structure of arrays (E.D., September 2024).
 ;-
 
 FUNCTION reverse_class, list, SUBSCRIPTS = s
 
     on_error, 2
-    if  n_elements(s) eq 0  then  s = lindgen(n_elements(list))
+    if  n_elements(s) eq 0  then  s = lindgen(n_elements(list.is_a_star))
     l = list
-    l[s].is_a_star = (not l[s].is_a_star) and 1B
+    l.is_a_star[s] = (not l.is_a_star[s]) and 1B
     return, l
 end
diff --git a/sort_list.pro b/sort_list.pro
index 7b4f0e0..fa0e9bb 100644
--- a/sort_list.pro
+++ b/sort_list.pro
@@ -1,4 +1,4 @@
-; $Id: sort_list.pro, v 1.1 Mar 2012 e.d. $
+; $Id: sort_list.pro, v 2.0 Sep 2024 e.d. $
 ;
 ;+
 ; NAME:
@@ -16,16 +16,15 @@
 ; INPUTS:
 ;	List:	list of stars
 ;
-; KEYWORD PARAMETERS:
-;	SUBSCRIPTS:	subscripts of stars to be sorted. If undefined, sort
-;		all stars in the list
-;
-; OUTPUTS:
-;	Return sorted list of sublist, if SUBSCRIPTS is set.
+; OPTIONAL OUTPUTS:
+;	SUBSCRIPTS: subscripts of sorted stars in the input list.
 ;
 ; MODIFICATION HISTORY:
 ; 	Written by:	Emiliano Diolaiti, June 2001.
 ;   1) Created this file (E. D., March 2012).
+;   2) Modified data type: from array of structures to structure of arrays (E.D., September 2024).
+;   3) Corrected comment about keyword parameter SUBSCRIPT 
+;      (it is an optional output, not an optional input) (E.D., September 2024).
 ;-
 
 FUNCTION sort_list, list, SUBSCRIPTS = s
@@ -33,5 +32,13 @@ FUNCTION sort_list, list, SUBSCRIPTS = s
     on_error, 2
     if  n_tags(list) eq 0  then  return, list
     s = reverse(sort(list.f))
-    return, list[s]
+    list.x = list.x[s]
+    list.sigma_x = list.sigma_x[s]
+    list.y = list.y[s]
+    list.sigma_y = list.sigma_y[s]
+    list.f = list.f[s]
+    list.sigma_f = list.sigma_f[s]
+    list.c = list.c[s]
+    list.is_a_star = list.is_a_star[s]
+    return, list
 end
diff --git a/star_param.pro b/star_param.pro
index 4a4ac9e..3b500ef 100644
--- a/star_param.pro
+++ b/star_param.pro
@@ -1,4 +1,4 @@
-; $Id: star_param.pro, v 1.1 Mar 2012 e.d. $
+; $Id: star_param.pro, v 2.0 Sep 2024 e.d. $
 ;
 ;+
 ; NAME:
@@ -34,6 +34,7 @@
 ; MODIFICATION HISTORY:
 ; 	Written by:	Emiliano Diolaiti, June 2001.
 ;   1) Created this file (E. D., March 2012).
+;   2) Modified data type: from array of structures to structure of arrays (E.D., September 2024).
 ;-
 
 PRO star_param, list, SUBSCRIPTS = s, $
@@ -45,13 +46,13 @@ PRO star_param, list, SUBSCRIPTS = s, $
     endif
     n = n_elements(s)
     if  n eq 0  then begin
-       n = n_elements(list)  &  s = lindgen(n) ; extract all elements
+       n = n_elements(list.is_a_star)  &  s = lindgen(n) ; extract all elements
     endif
     if  s[0] lt 0  then  n = 0  else begin $
-       x = list[s].x  &  sigma_x = list[s].sigma_x
-       y = list[s].y  &  sigma_y = list[s].sigma_y
-       f = list[s].f  &  sigma_f = list[s].sigma_f
-       c = list[s].c
+       x = list.x[s]  &  sigma_x = list.sigma_x[s]
+       y = list.y[s]  &  sigma_y = list.sigma_y[s]
+       f = list.f[s]  &  sigma_f = list.sigma_f[s]
+       c = list.c[s]
     endelse
     return
 end
diff --git a/starfinder.pro b/starfinder.pro
index d6482d8..05d0e18 100644
--- a/starfinder.pro
+++ b/starfinder.pro
@@ -1,4 +1,4 @@
-; $Id: starfinder.pro, v 1.8.2a May 2014 e.d. $
+; $Id: starfinder.pro, v 1.8.2b_dev01 Sep 2024 e.d. $
 ;
 ;+
 ; NAME:
@@ -435,6 +435,8 @@
 ;   26) Removed bug in STARFINDER_FIT module: sometimes very close sources 
 ;       were swapped by call to COMPARE_LISTS (E.D., April 2012).
 ;   27) Updated documentation (E. D., May 2014).
+;   28)  Modified data type of variable "list_of_stars":
+;        from array of structures to structure of arrays (E.D., September 2024).
 ;-
 
 
@@ -1164,7 +1166,9 @@ PRO starfinder, $
 ;             print, "STARFINDER: final re-fitting: iteration", iter + 1
        for  n = 0L, n_stars - 1  do $
           ; modified March 2012
-          if list_of_stars[n].is_a_star or re_fitting eq 1 then $   ;;; if list_of_stars[n].is_a_star or re_fitting eq 1 or iter eq 0 then $
+;         if list_of_stars[n].is_a_star or re_fitting eq 1 then $   ;;; if list_of_stars[n].is_a_star or re_fitting eq 1 or iter eq 0 then $
+          ; modified September 2024
+          if is_star(list_of_stars, n) or re_fitting eq 1 then $   ;;; if list_of_stars[n].is_a_star or re_fitting eq 1 or iter eq 0 then $
           starfinder_fit, list_of_stars, n, image, siz, background, stars, $
                           noise_std, sv_par, x_bad, y_bad, fit_par, fit_data, $
                           model_data, threshold_n, re_fitting, _EXTRA = extra, $
diff --git a/starlist.pro b/starlist.pro
index 11994b1..83234d2 100644
--- a/starlist.pro
+++ b/starlist.pro
@@ -1,12 +1,11 @@
-; $Id: starlist.pro, v 1.1 Mar 2012 e.d. $
+; $Id: starlist.pro, v 2.0 Sep 2024 e.d. $
 ;
 ;+
 ; NAME:
 ;	STARLIST
 ;
 ; PURPOSE:
-;	Create a new list of elements representing either
-;	true or presumed stars.
+;	Create a new list of elements representing true or presumed stars.
 ;
 ; CATEGORY:
 ;	STARFINDER auxiliary procedures.
@@ -18,24 +17,31 @@
 ;	N:	number of elements in the list
 ;
 ; OPTIONAL INPUTS:
-;	X, Y, F:	1D vectors with position and flux of new elements
+;	X, Y:	1D vectors with positions of new elements
 ;	
-;	C: 1D vector with correlation coefficients of new elements (if available)
+; F: 1D vector with fluxes of new elements (used only if X, Y are defined)
+; 
+;	C: 1D vector with correlation coefficients of new elements (used only if X, Y, F are defined)
 ;
 ; OUTPUTS:
-;	Return possibly initialized list of N elements
+;	Return initialized list of N elements
 ;
 ; MODIFICATION HISTORY:
 ; 	Written by:	Emiliano Diolaiti, June 2001.
 ; 	1) Added optional input C in STARLIST (E.D., March 2012).
-; 	2) Created this file (E. D., March 2012).
+; 	2) Created this file (E.D., March 2012).
+; 	3) Modified data type: from array of structures to structure of arrays (E.D., September 2024).
 ;-
 
 FUNCTION starlist, n, x, y, f, c
 
     on_error, 2
-    element = star()
-    list = replicate(element, n)
+    list = { $
+            x: fltarr(n), sigma_x: fltarr(n), $   ; x- coordinate and error
+            y: fltarr(n), sigma_y: fltarr(n), $   ; y- coordinate and error
+            f: fltarr(n), sigma_f: fltarr(n), $   ; flux and error
+            c: make_array(n, VALUE = -1.0),   $   ; correlation coefficient
+            is_a_star: bytarr(n)}                 ; flag
     if  n_elements(x) ne 0 and n_elements(y) ne 0  then $
        update_list, list, x, y, f, c
     return, list
diff --git a/update_list.pro b/update_list.pro
index aa694b4..1b2ddee 100644
--- a/update_list.pro
+++ b/update_list.pro
@@ -1,4 +1,4 @@
-; $Id: update_list.pro, v 1.1 Mar 2012 e.d. $
+; $Id: update_list.pro, v 2.0 Sep 2024 e.d. $
 ;
 ;+
 ; NAME:
@@ -25,10 +25,10 @@
 ;	Sigma_X, Sigma_Y, Sigma_F:	errors on position and flux.
 ;
 ; KEYWORD PARAMETERS:
-;	SUBSCRIPTS:	1D vector of subscripts of stars to update. If not defined,
-;		update all the stars in the list.;
+;	SUBSCRIPTS:	1D vector of subscripts of stars to be updated. If not defined,
+;		update all the stars in the list.
 ;
-;	IS_STAR:	set this keyword to say that the stars to update have already
+;	IS_STAR:	set this keyword to specify that the elements to be updated have already
 ;		been accepted as true stars.
 ;
 ; OUTPUTS:
@@ -36,23 +36,24 @@
 ;
 ; MODIFICATION HISTORY:
 ; 	Written by:	Emiliano Diolaiti, June 2001.
-; 	1) Created this file (E. D., March 2012).
+; 	1) Created this file (E.D., March 2012).
+; 	2) Modified data type: from array of structures to structure of arrays (E.D., September 2024).
 ;-
 
 PRO update_list, list, SUBSCRIPTS = s, x, y, f, c, $
-                  sigma_x, sigma_y, sigma_f, IS_STAR = is_star
+                 sigma_x, sigma_y, sigma_f, IS_STAR = is_star
 
     on_error, 2
     n = n_elements(s)
     if  n eq 0  then  s = lindgen(n_elements(x))
     if  s[0] ge 0  then begin
-       list[s].x = x  &  list[s].y = y
-       if  n_elements(f) ne 0  then  list[s].f = f
-       if  n_elements(c) ne 0  then  list[s].c = c
-       if  n_elements(sigma_x) ne 0  then  list[s].sigma_x = sigma_x
-       if  n_elements(sigma_y) ne 0  then  list[s].sigma_y = sigma_y
-       if  n_elements(sigma_f) ne 0  then  list[s].sigma_f = sigma_f
-       list[s].is_a_star = keyword_set(is_star) and 1B
+       list.x[s] = x  &  list.y[s] = y
+       if  n_elements(f) ne 0  then  list.f[s] = f
+       if  n_elements(c) ne 0  then  list.c[s] = c
+       if  n_elements(sigma_x) ne 0  then  list.sigma_x[s] = sigma_x
+       if  n_elements(sigma_y) ne 0  then  list.sigma_y[s] = sigma_y
+       if  n_elements(sigma_f) ne 0  then  list.sigma_f[s] = sigma_f
+       list.is_a_star[s] = keyword_set(is_star) and 1B
     endif
     return
 end
-- 
GitLab