; GENERATE FILES FOR BINARY-TREE ; ; REQUIRES averagenode.spi and update_lut.spi ; --------------- Parameters --------------- x20 = 1 ; starting depth (TO DO: be able to start from >1) x22 = 9 ; ending depth (--> 2**x22 class averages) x28 = 136 ; temporary dimension for labelling (3-digit class, 5-digit population) ;x28 = 128 ; temporary dimension for labelling (3-digit class, 4-digit population) ;x28 = 115 ; temporary dimension for labelling (3-digit class, 3-digit population) ; NOTE: accordingly change label syntax in AVERAGENODE.SPI at LA B call ; ---------------- Inputs ---------------- fr l [dendro_doc]docdendro ; dendrogram document fr g [particles]flt/flt****** ; particle template ; ---------------- Outputs ---------------- fr g [binary_dir]tree ; output directory fr g [node_lut][binary_dir]/node2termini ; node-to-particle lookup table fr g [node_doc][binary_dir]/docnode{***x80} ; particles-per-node list fr g [node_avg][binary_dir]/avgnode{***x80} ; node average fr g [labeled_avg][binary_dir]/labeled{***x80} ; labeled node average ; ------------ END BATCH HEADER ------------ fr g [temp_lut][node_lut]_unrenum vm echo "if(! -d [binary_dir]) mkdir [binary_dir]"|csh x80=2**(x20-1) ; initialize node# x61=1 ; initialize first-terminus ; clean up pre-existing files de a [node_doc] de a [node_avg] de a [labeled_avg] de [node_lut] de [temp_lut] ; WHOLE DENDROGRAM==CLASS #1, DEPTH==1 ; get number of termini ud n,x76 [dendro_doc] if(x20.eq.1) then vm echo "Depth 01"; date vm cp [dendro_doc].$DATEXT [node_doc].$DATEXT ; average images @averagenode(x80,x61,x76,x28) ; update node-to-terminus lookup-table @update_lut(x80,x61,x76) endif ; LOOK FOR TWO PRIMARY BRANCHES, DEPTH==2 vm echo "Depth 02"; date x10=0 ; initialize terminus-counter x61=1 ; reset first-terminus if(x20.le.2) then ; loop through termini do lb7 x70=1,x76 ; get particle# (x71), height (x72) ud ic,x70,x71,x72 [dendro_doc] ; increment terminus-counter x10=x10+1 ; save particle# (x71) to node doc sd x10,x71,x70 [node_doc] ; x70==dendrogram-key ; check if height equals 1 if(x72.eq.1) then ; average images & update counters @averagenode(x80,x61,x70,x28) @update_lut(x80,x61,x70) ; reset terminus-counter, first-terminus x10=0 x61=x70+1 endif lb7 ; end terminus-loop endif ; GENERATE BRANCHES FOR DEPTH>=3 if(x20.lt.3) x20=3 ; start at depth aat least 3 ; loop through node-depths do lb2 x21=3,x22 vm echo "Depth {**x21}"; date ; calculate first and last node #s to split x30=2**(x21-2) ; first node at next highest depth x39=2**(x21-1) - 1 ; last node at next highest depth ; loop through nodes do lb3 x31=x30,x39 ; initialize maximum height, corresponding terminus x38=0 ; maximum height x45=0 ; terminus with maximum height ; read first (x41), last (x49) termini under parent node (x31) ud x31,x41,x49 [temp_lut] ud e ; TO DO: trap for nodes with 1-2 particles x48=x49-1 ; last terminus to search ; loop through termini do lb4 x40=x41,x48 ; read height (x72) ud ic,x40,x71,x72 [dendro_doc] ; if height greater than maximum... if(x72.gt.x38) then ; update maximum x38=x72 ; update corresponding terminus x45=x40 endif lb4 ; end terminus-loop x46=x45+1 ; first terminus of rightward branch ; loop through left-branch termini do lb5 x50=x41,x45 ; read particle# ud ic,x50,x71,x72 [dendro_doc] x10=x50-x41+1 ; terminus-counter ; write particle# (x71), dendrogram-key (x70) sd x10,x71,x70 [node_doc] lb5 ; end left-loop ; average images @averagenode(x80,x41,x45,x28) @update_lut(x80,x41,x45) ; loop through right-branch termini do lb6 x60=x46,x49 ; read particle# ud ic,x60,x71,x72 [dendro_doc] x10=x60-x46+1 ; terminus-counter ; write particle# (x71), dendrogram-key (x70) sd x10,x71,x70 [node_doc] lb6 ; end right-loop ; average images @averagenode(x80,x46,x49,x28) @update_lut(x80,x46,x49) lb3 ; end node-loop lb2 ; end depth-loop ; CLEAN UP doc ren [temp_lut] [node_lut] SD / FIRST LAST POPULATION [node_lut] sd e [node_lut] ;de ;[temp_lut] ud ice [dendro_doc] vm echo "Done"; date en d ; Modified 2007-12-13 ; TO DO: add ability to start from depth >1