//st1='286	Kappa Canis Majoris		06	50	-32.5	242.4	-14.5	B1.5IV	3.50	-3.42	4.13	0.50	790';
//strsplit(st1,["	"])
function str=cndisplay(h)
    str=h.user_data;
endfunction

if(~exists("clines"))
    fd=mopen('constellations_tabbed.txt','r')
    clines=mgetl(fd)
    mclose(fd)
end

cplot=28; //number of constellations to plot
cmap=rainbowcolormap(cplot);
cnames=[];
numlines=size(clines)(1);
cind=0;
cpos=[];
drawlater
for(i=1:numlines)
    st1=clines(i);
    if(isempty(st1))
        continue;
    end
    if(~isdigit(part(st1,1)))
        //this is a constellation name
        if(cind>=cplot)
            break;
        end
        if(cind>0.5)
            cpos=[mean(cpos,1);cpos];//point for legend entry
            sh=scatter3(cpos(:,1),cpos(:,2),cpos(:,3),36,"markerEdgeColor",cmap(cind,:),"markerFaceColor",cmap(cind,:));
            dh=datatipCreate(sh,1);
            dh.user_data=cnames($);
            datatipSetDisplay(dh,cndisplay);
        end
        cnames($+1)=st1;
        cind=cind+1;
        cpos=[];
    else
        //this is a star
        sparts=strsplit(st1,["	"]);
        ra_h=strtod(sparts(4));
        ra_m=strtod(sparts(5));
        decl=strtod(sparts(6));
        vl=1;
        ra=(ra_h+ra_m/60)/24*(2*%pi);
        dc=decl/360*(2*%pi);
        x=vl*cos(ra)*cos(dc);
        y=vl*sin(ra)*cos(dc);
        z=vl*sin(dc);
        cpos($+1,:)=[x y z]; //append row
    end
end

cpos=[mean(cpos,1);cpos];//point for legend entry
sh=scatter3(cpos(:,1),cpos(:,2),cpos(:,3),36,"markerEdgeColor",cmap(cind,:),"markerFaceColor",cmap(cind,:));
dh=datatipCreate(sh,1);
dh.user_data=cnames($);
datatipSetDisplay(dh,cndisplay);

isoview
drawnow
