# AWK script for X-d 2 tables #++++++++++++++++ #.IDENTIFICATION X2.awk #.LANGUAGE AWK Script #.AUTHOR Francois Ochsenbein #.ENVIRONMENT #.KEYWORDS #.VERSION 1.0 31-Dec-2006 #.PURPOSE #.COMMENTS # Argument t1 = file with RA,Dec of the primary (largest) table # Argument t2 = file with RA,Dec of the secondary (smallest) table # Argument col= name of column in t1 which contains the marker # Argument val= value of the marker (X) # Argument r = maximal possible radius (arcmin), or rs= # Argument deep=1 to look in all possible counterparts # Output = SQL Commands to add the X-mark # Examples in J/A+A/455/453 #---------------- function print2(m) { print m > "/dev/stderr" } function r2(x,y,z) { return(x*x+y*y+z*z) } BEGIN { if (t1 == "") { print2("++++X2.awk: t1 arg. missing (primary table), assume table1") t1 = "table1"; } if (t2 == "") { print2("++++X2.awk: t2 arg. missing (secondary table), assume table2") t2 = "table2"; } if (col == "") { print2("++++X2.awk: col arg. missing (cross-col.name), assume X") col = "X"; } if (val == "") { print2("++++X2.awk: X arg. missing (cross-col.contents), assume X") val = "X" } if ((r==0) && (rs>0)) r = rs/60.; if (r == 0) { print2("++++X2.awk: r arg. missing (max.dist.arcmin), assume 0.1") r = 0.1; } rs = r*60. PI = 4.*atan2(1.0, 1.0); DEG = PI/180.0; r2m = r*r*DEG*DEG/3600. # Load the secondary table if (index(t1, ".") == 0) t1 = t1 ".dat" if (index(t2, ".") == 0) t2 = t2 ".dat" print2("----adding " t1 "(" col ")='" val "' when r<=" rs "''") N2 = 0 cmd = "tabmap -data -ascii -map '${RAdeg} ${DEdeg}' " t2 print2("....X2.awk: Launch: " cmd) while ((cmd | getline)>0) { ++N2; cd = cos($2*DEG); tX[N2] = cd *cos($1*DEG); tY[N2] = cd *sin($1*DEG); tZ[N2] = sin($2*DEG) tN[N2] = 0 # Index of counterpart; <=-2 ==> several counterparts tr[N2] = 0 # Distance to counterpart } if (N2 < 1) { print2("****X2.awk: secondary table empty: " t2) exit(1); } print2("....X2.awk: seconday table (" t2 ") loaded: " (N2-1) " positions.") close(cmd) printf "set %s = '' ;\n\n", col #### Input is the largest table N1 = 0 cmd = "tabmap -data -ascii -map '${RAdeg} ${DEdeg}' " t1 print2("....X2.awk: Launch: " cmd) while ((cmd | getline)>0) { ++N1; #printf "#%4d: %s\n", N1, $0 cd = cos($2*DEG); X = cd *cos($1*DEG); Y = cd *sin($1*DEG); Z = sin($2*DEG); # r2(X,Y,Z); st = 0; # Set to 1 if a corresponding object is found for(i=1; i<=N2; i++) { r2i = r2(X-tX[i],Y-tY[i],Z-tZ[i]); if (r2i > r2m) continue; if (tN[i] != 0) { # Already matched... if (tN[i] < 0) tN[i]--; else tN[i] = -2; if (r2i0) printf "set %s = '%s' where recno = %d ; \n", col, val, N1 } #### List the secondary records without counterpart n0 = 0; n2 = 0; for (i=1; i<=N2; i++) { if (tN[i] == 0) n0++; if (tN[i] < -1) n2++; } if (n0>0) { print2("====Secondary without primary: " n0); line = "" if (n0<=20) for (i=1; i<=N2; i++) { if (tN[i] == 0) line = line sprintf("%8d", i) } if (length(line>0)) print2(line); } else print2("====Secondary have all a primary counterpart") if (n2>0) { print2("++++Secondary with several primaries: " n2); line = "" if (n2<=20) for (i=1; i<=N2; i++) { if (tN[i] < -1) line = line sprintf("%8d", i) } f (length(line>0)) print2(line) } exit(0) }