Home Manual Packages Global Index Keywords Quick Reference ``` #include "Chris/jgraph.i" struct CHalo { long level ; long mother; long firstchild; long nsisters; long sister; double rho_saddle; double density; double densmax; double radius ; double mass ; double position(3); } func Read_node (filenode) { /* DOCUMENT Read_node(filenode) reads an output file of ADAPTAHOP and returns the result in a NODE structure */ ff=open(filenode); vutils=array(long,2); read,ff,vutils; nnode=vutils(1); Node=array(double,15,nnode); read,ff,Node; close,ff; hh=array(CHalo,nnode); hh.level=Node(2,); hh.mother=Node(3,); hh.firstchild=Node(4,); hh.nsisters=Node(5,); hh.sister=Node(6,); hh.rho_saddle=Node(7,); hh.density=Node(8,); hh.densmax=Node(9,); hh.radius=Node(10,); hh.mass=Node(11,); hh.position=Node(13:15,); return hh; } func PlotDaughter (Node,i,color=,scaleR=) { /* DOCUMENT PlotDaughter(Node,i,color=,scaleR=) For a substructure ensemble Node, plots the childs of structure Node(i). i can be a scalar or an index array. The circles radius can be multiplied by scaleR (default scaleR=1000). SEE ALSO : PlotNode, PlotNodeLeaves */ if(is_void(color)) color="red"; if(is_void(scaleR)) scaleR=1000.; if(numberof(i)>1){ for(j=1;j<=numberof(i);j++) { print,i(j); PlotDaughter,Node,i(j),color=color,scaleR=scaleR; } return; } fchild=Node(i).firstchild; JDrawCircle,(Node.position)(1,i),(Node.position)(2,i),(Node.radius)(i)*scaleR,color=color,width=5; if(fchild!=0) { Ncurr=Node(fchild); nsisters=Ncurr.nsisters-1; JDrawCircle,(Ncurr.position)(1),(Ncurr.position)(2),(Ncurr.radius)*scaleR,color="red",width=5; for(p=1;p<=nsisters;p++) { Ncurr=Node(Ncurr.sister); JDrawCircle,(Ncurr.position)(1),(Ncurr.position)(2),(Ncurr.radius)*scaleR,color="red",width=5; } } else { write,"No Daughter !"; } return 0; } func PlotTreeNode (Node) { for(i=1;i<=dimsof(Node)(2);i++) { PL,[Node(i).level],[i]; PL,[Node(Node(i).mother).level],[Node(i).mother]; plg,[Node(i).level,Node(Node(i).mother).level],[i,Node(i).mother]; } return 0; } func FindLeaves (Node,i,levmax=) { /* DOCUMENT For a given Adaptahop Node and a given substructure index i, it returns all the index of corresponding 'leaves', i.e all substructures which have Node(i) as a mother and no child. i can be a scalar or an index array. If i is an array, it SHOULD correspond to Nodes that have the SAME level to avoid redundancy. levmax defined the maximum level that should be reached by the recursive algorithm to find the structure children. (default levmax=19999) SEE ALSO : PlotNodeLeaves EXAMPLE ww=FindLeaves(qq,where(qq.level==1)); window,0; PlotNode(qq(unique(ww)),scaleR=50.,color=__green4); get all leaves */ if(is_void(levmax)) levmax=19999; if(numberof(i)>1) { ww=[]; for(j=1;j<=numberof(i);j++) { if((Node(i(j)).firstchild==0)*(Node(i(j)).level<=levmax)) { grow,ww,[i(j)]; } else if(Node(i(j)).level>levmax) { } else { grow,ww,FindLeaves(Node,i(j),levmax=levmax); } } return ww; } if((Node(i).firstchild==0)*(Node(i).level<=levmax)) { return [i]; } else if(Node(i).level>levmax) { return [-1]; } else { r2=_FindLeaves(Node,i,levmax=levmax); www=where(r2==0); r=r2(www(0)+1:); return r; } } func _FindLeaves (Node,i,res=,levmax=) { local r1; if(is_void(res)) res=[0]; if((Node(i).firstchild==0)||(Node(i).level>=levmax)) { //write,"NO child"; if((numberof(res)==1)*(res(1)==0)) { return [0,i]; } else { return [i]; } //return grow(res,[i]); } else { Node_Child=Node(Node(i).firstchild); isist=array(long,Node_Child.nsisters); isist(1)=Node(i).firstchild; for(j=1;j<=dimsof(isist)(2);j++) { if(Node(isist(j)).sister!=0) { isist(j+1)=Node(isist(j)).sister; } r1=res(1); //write,"res1="; //res; res=grow(res,_FindLeaves(Node,isist(j),res=res,levmax=levmax)); //write,"res2="; //res; //r1; www=where(res==r1); res=res(www(0):); //write,"res3="; //res; } return res; } } func PlotNode (Node,color=,level=,scaleR=,width=) { /* DOCUMENT PlotNode(Node,color=,level=,scaleR=,width=) plots all the Node substructures of a given level. if level is not given all the subtructures will be drawn. SEE ALSO : PlotDaughter,PlotTreeNodes */ if(is_void(color)) color="red"; if(is_void(scaleR)) scaleR=1000.; if(is_void(level)) { level=Node.level; } else { level=array(level,dimsof(Node)(2)); } for(i=1;i<=dimsof(Node)(2);i++) { if((Node.level)(i)==level(i)) JDrawCircle,(Node.position)(1,i),(Node.position)(2,i),(Node.radius)(i)*scaleR,color=color,width=width; } return 0; } func PlotNodeLeaves (Node,color=,scaleR=,width=) { /* DOCUMENT PlotNodeLeaves(Node,color=,scaleR=,width=) plots all the leaves contained in Node. SEE ALSO : PlotDaughter, PlotNode */ if(is_void(color)) color="red"; if(is_void(scaleR)) scaleR=1000.; for(i=2;i<=dimsof(Node)(2);i++) { if((Node.level)(i)==1) { if((Node.firstchild)(i)==0) { JDrawCircle,(Node.position)(1,i),(Node.position)(2,i),(Node.radius)(i)*scaleR,color=color,width=width; } else { r=FindLeaves(Node,i); for(j=1;j<=dimsof(r)(2);j++) { JDrawCircle,(Node.position)(1,r(j)),(Node.position)(2,r(j)),(Node.radius)(r(j))*scaleR,color=color,width=width; } } } } return 0; } func PlotLink (Node) { for(i=1;i<=dimsof(Node)(2);i++) { mum=Node.mother(i); if((Node.level)(i)>1) { xd=(Node.position)(,i); xm=(Node.position)(,mum); plg,[xd(2),xm(2)],[xd(1),xm(1)],width=4,color="black"; PL,[xm(2)],[xm(1)]; } } return 0; } func Findeq (Node,Vcenter,level,&www) { www=where(Node.level==level); Ncenter=(Node.position)(,www); Ncenter=Ncenter(,-:1:dimsof(Vcenter)(3),); Vcenter=Vcenter(,,-:1:dimsof(Ncenter)(4)); diff=Ncenter-Vcenter; dist=abs(diff(1,,),diff(2,,),diff(3,,)); res=dist(,mnx); return res; } func Findeq2 (Node,Vcenter,level) { www=where(Node.level==level); Ncenter=(Node.position)(,www); Ncenter=Ncenter(,-:1:dimsof(Vcenter)(3),); Vcenter=Vcenter(,,-:1:dimsof(Ncenter)(4)); diff=Ncenter-Vcenter; dist=abs(diff(1,,),diff(2,,),diff(3,,)); res=dist(,mnx); return www(res); } func PlotEq (Node,W,Vcenter,Eq) { N=(Node.position)(,W); for(i=1;i<=dimsof(Eq)(2);i++) { plg,[Vcenter(2,i),N(2,Eq(i))],[Vcenter(1,i),N(1,Eq(i))],width=4,color="black"; PL,[Vcenter(2,i),N(2,Eq(i))],[Vcenter(1,i),N(1,Eq(i))]; } return 0; } func PlotGroup (Node) { for(i=1;i<=dimsof(Node)(3);i++) { if(Node(4,i)==0) JDrawCircle,Node(13,i),Node(14,i),Node(10,i)*1000.,color="red",width=5; } return 0; } func PlotGroup2 (Node) { for(i=1;i<=dimsof(Node)(3);i++) { if(Node(4,i)==0) plmk,Node(14,i),Node(13,i),color="red"; } return 0; } ```