'Cruise07 Nov. 20, 2007
GLOBAL PlotSize,BAF,NoPlots,maxPlot,TA,BA,rows,eee,TractTrees,TractBA,TractMBF,TractStumpage,MeasPlots
GLOBAL method
' MyStumpageData$:      1 = SpNo  2 = SpName  3 = FC 4 = Stumpage

' TreeData              1=PlotNo 2=SpNo 3=Dbh 4=Logs 5=BaAc  6=TreesAc
'
'                       7=CordsAc 8=TonsAc 9=BfAc 10=StumpAc  11=Logs  12=TreeBA  13=TreeBF
'
'PlotData               1 =BaAc  2=TreesAc  3=CordsAc  4=TonsAc  5=BfAc  6=Stump
'                       7= 0 est, 1 meas, 8=Logs

'Totals(maxSp+1,6)  1=SpNo 2=Trees 3=BA 4=Cords or Tons 5=Mbf 6=Stumpage

'eee = 3 = standard cruise;   eee=4 = doubleBA cruise;   eee=5 = doubleLogs cruise
'
'-----------------------------------------------------------------------------------------------------------------------------------------------------------------
'                                                             INFORMATION ON CRUISE07
'-----------------------------------------------------------------------------------------------------------------------------------------------------------------

call Start
sub Start
topic$(1)="View information about this program"
topic$(2)="Creating data files"
topic$(3)="Process a standard plot or point sample cruise or 100% tally"
topic$(4)="Process a double-sample cruise, basal area on easy points"
topic$(5)="Process a double-sample cruise, logs on in-trees on easy points"
topic$(6)="Make a data file from a point sample cruise to test double sampling"
topic$(7)="Exit"
listbox #cruise.top, topic$(), [SelectionMade],5,20,600,300
button #cruise,"Exit",[EndIt],UR,15,5
WindowWidth=600: WindowHeight=300
open "Cruise07" for window as #cruise
print #cruise.top,"font times_new_roman 12"
wait
[SelectionMade]
print #cruise.top,"selectionindex? index"
eee=index
close #cruise
if eee=1 then
cls
call Info
end if
if eee = 2 then call MakeFile
if eee=3 then call Standard  'Standard
if eee=4 then call Standard  'DoubleBA
if eee=5 then call Standard  'DoubleLogs
if eee=6 then call FileFix
if eee=7 then end
end sub  'sub Start

sub Info
CLS
print "   "
print "Cruise07 is designed to meet the needs of foresters doing plot sampling, point sampling,"
print "or double point-sample cruises.   Cruise07  is open-source, a first as far as I know in forest"
print "inventory. You will find a file, Cruise07Code.txt, which you can modify and adapt for use in"
print "any forests anywhere. To make modifications, you will need to purchase Liberty BASIC, available"
print "for about $50 at libertybasic.com. Liberty BASIC is easy to use and makes stand-alone programs."
print "I would appreciate receiving a copy of modifications and improvements you make."
print "You can contact me at"
print "  "
print "Harry V. Wiant, Jr."
print "2440 Pine Hurst Drive"
print "State College, PA 16803"
print "  "
print "email: hwiant@msn.com."
print "  "
print "Board-foot volumes are based on equations by Wiant and Castaneda (1977."
print "Resource Inventory Notes BLM-4) and local volume equations for pulpwood"
print "by Wiant (1989. The Consultant 34:79-80)."
print "  "
print "DISCLAIMER OF WARRANTY."
print "THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTY OF ANY"
print "KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING WITHOUT LIMITATION THE WARRANTIES"
print "THAT IT IS FREE OF DEFECTS, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING."
print "THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU."
print "SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ANY CONSEQUENCES."
print "  "
print "Use of this program indicates you accept the warranty statement!"
print "  "
input "Press Enter to continue ";see$
call Start
end sub 'sub Info

sub MakeFile
CLS
print "  "
print "STUDY THE INFORMATION GIVEN BELOW BEFORE CREATING DATA FILES"
print "  "
print "-----------------------------------------------------------------------------------"
print "   STUMPAGE DATA FILE = MyStumpageData.txt"
print "   "
print "   A file is included with this program, MyStumpageData.txt, which you"
print "   will need to modify for your needs.  You must follow the format on this file,"
print "   although you can add species, change form class values, etc."
print "  "
print "   IMPORTANT, READ CAREFULLY!"
print "        1.  Hardwood pulpwood must have a SpNo of 1 and 0 for NoLogs."
print "        2.  Softwood pulpwood must have a SpNo of 2 and 0 for NoLogs."
print "        3.  Sawtimber must have a SpNo of 3 or greater."
print "        4.  Make certain every SpNo used in your cruise data file is in your"
print "            MyStumpageData.txt file also."
print "        5.  Limit species names to 10 characters."
print "        6.  Have a species code (SpNo) for each species in the cruise, such as 3"
print "            for YellowPop, 4 for NoRedOak, etc."
print "        7.  The last line in the MyStumpageData.txt file must be 999,999,999,999"
print "------------------------------------------------------------------------------------"
print "   "
print "   CRUISE DATA FILE"
print "  "
print "   Data in the cruise data file (SomeName.txt) is entered, separated with commas,"
print "   in the following order:"
print "  "
print "   PlotNo,SpNo,Dbh,NoLogs"
print "  "
print "   1,3,12,1"
print "   1,10,20,3"
print "   2,9,16,2"
print "   2,1,9,0"
print "   etc."
print "   999,999,999,999"
print "  "
print "   INPORTANT READ CAREFULLY!"
print "   1.  Record dbh to the nearest inch (no decimals)."
print "   2.  Plots must be in order from lowest to highest PlotNo."
print "   3.  If doing a 100% tally, each PlotNo is 1."
print "   4.  For a double-sample cruise, Dbh and NoLogs will be 0 for easily-measured"
PRINT "       point if using basal area: if using number of logs on in-trees, dbh will be 0.  "
print "   5.  The last line in the file must be 999,999,999,999 "
PRINT "------------------------------------------------------------------------------------"
print "    "
print "   TEST FILES"
print "   "
print "   Other files to test the program are included: TestStandard100.txt for a standard"
print "   cruise using plots or points (for a 100% tally use TestCompleteTally.txt), and"
print "   TestDoubBA100Meas23.txt and TestDoubLogs100Meas23.txt for double "
print "   sampling cruises.  Use of logs on in-trees rather than in-tree counts generally provides better"
print "   estimates when double sampling.  All test files are based on a cruise with 100 point"
print "   samples, BAF=20 on a 109-acre tract in WV. These files are convenient for comparing standard"
print "   and double-sampling where measurements were made on 23 of the 100 points."
print "  "
print "   NOTE: A useful form for field tallies is included with this program - TallySheet.doc."
print "  "
print "----------------------------------------------------------------------------------------"
input "   Press Enter to continue ";see$
call Start
end sub 'sub MakeFile
'-----------------------------------------------------------------------------------------------------------------------------------------------------------------'                                                         DATA CHECK
'----------------------------------------------------------------------------------------------------------------------------------------------------------------

sub Standard

filedialog "Click on MyStumpageData.txt ","*.txt", fileMyStumpageData$
if fileMyStumpageData$=" " then end
open fileMyStumpageData$ for input as #5
rowsMyData=0
while eof(#5) = 0
    line input #5, datarow$
    rowsMyData=rowsMyData+1
wend
close #5
DIM MyStumpageData$(rowsMyData,4)

OPEN fileMyStumpageData$ FOR input AS #6
DIM value(rowsMyData, 4)
    FOR r = 1 to rowsMyData
      FOR c = 1 to 4
        INPUT #6, val$
        if val(val$)=999 then goto [bbb]
        MyStumpageData$(r,c)=val$           'SpNo,SpName,FC,Stumpage
      NEXT c
    NEXT r
[bbb]close #6
'first,  count lines in data file
filedialog "Click on file with cruise data ","*.txt", file$
if file$=" " then end
open file$ for input as #1
rows=0
while eof(#1) = 0
    line input #1, datarow$
    rows=rows+1
wend

close #1

DIM PlotData(rows,10)
DIM TreeData(rows,15)
OPEN file$ FOR input AS #2
DIM value(rows, 10)
    FOR r = 1 to rows
      FOR c = 1 to 4
        INPUT #2, val
         if val=999 then goto[qqq]
         TreeData(r,c)=val   'PlotNo,SpNo,Dbh,Logs,0 or 1 for double-sample crui
       NEXT c
    NEXT r
[qqq]

    minDbh=TreeData(1,3)
    maxDbh=TreeData(1,3)
    minPlot=TreeData(1,1)
    maxPlot=TreeData(1,1)
    minSp=TreeData(1,2)
    maxSp=TreeData(1,2)
    minLogs=TreeData(1,4)
    maxLogs=TreeData(1,4)
    for p=2 to rows
      if TreeData(p,1)<>0 and TreeData(p,1)<minPlot then minPlot=TreeData(p,1)
      if TreeData(p,1)>maxPlot then maxPlot=TreeData(p,1)
      if TreeData(p,2)<>0 and  TreeData(p,2)<minSp then minSp=TreeData(p,2)
      if TreeData(p,2)>maxSp then maxSp=TreeData(p,2)
      if TreeData(p,3)<>0 and TreeData(p,3)<minDbh then minDbh=TreeData(p,3)
      if TreeData(p,3)>maxDbh then maxDbh=TreeData(p,3)
      if TreeData(p,4)<>0 and TreeData(p,4)<minLogs then minLogs=TreeData(p,4)
      if TreeData(p,4)>maxLogs then maxLogs=TreeData(p,4)
     next p
     CLS
      print "This is a data check.  Do the values seem appropriate? If not, you"
      print "need to stop and check you cruise data file."
      print
      print "Minimum plot no.    = ";minPlot
      print "Maximum plot no.    = ";maxPlot
      print "Minimum species no. = ";minSp
      print "Maximum species no. = ";maxSp
      print "Minimum dbh         = ";minDbh
      print "Maximum dbh         = ";maxDbh
      print "Minimum no. logs    = ";minLogs
      print "Maximum no. logs    = ";maxLogs
      print
      'Form created with the help of Freeform 3 v03-27-03
'Generated on Oct 20, 2007 at 14:14:12
input "Do these values appear reasonable? ";w$

      if w$ = "N" then
        close #2
        end
      end if
      if w$ = "n" then
        close #2
         end
       end if
      if w$= "Y" then
       cls
       goto [back]
      end if
      if w$ = "y" then
      cls
      goto [back]
      end if
   [back]
  close #2
       '
print
options3$(0) = "Points"
options3$(1) = "Plots"
options3$(2) = "100%Tally"
listbox #Method.list, options3$(), [selectionMade3], 5, 35, 250, 90
WindowWidth = 270 : WindowHeight = 180
open "Select crusing method " for window as #Method
wait

[selectionMade3]
print #Method.list, "selection? selection$"
if selection$="Points" then method=1
if selection$="Plots" then method=2
if selection$="100%Tally" then method=3
close #Method


[WINDOW_ENTRY]
    'open a window asking for tract info.
    'STATICTEXT #handle, "string", xpos, ypos, wide, high
    '                                          left,bottom,width,height
    if method=1 then
    statictext #info.TractName$, "Tract name",                                  10,  10, 270, 18
    statictext #info.Cruiser$, "Cruiser name",                                  10,  40, 270, 18
    statictext #info.Date$, "Date",                                             10,  70, 270, 18
    statictext #info.Acres, "Acres",                                           10,  100,270, 18
    statictext #info.PlotSize, "BAF",        10,  130,270, 18
   ' statictext #info.PlotSize, "Plot size (ac)",        10,  130,270, 18
   ' NoPlots=1
    statictext #info.NoPlots, "Total no. plots or points ",        10,  160,270, 18
    if (eee=4) or (eee=5) then statictext #info.MeasPlots, "No. measured points ",10,  190,270,18
    textbox #info.TractName$, 290, 10, 100, 25
    textbox #info.Cruiser$    290, 40, 100, 25
    textbox #info.Date$       290, 70, 100, 25
    textbox #info.Acres       290, 100,100, 25
    'if method=3 then  PlotSize=Acres
    textbox #info.PlotSize    290, 130,100, 25
    textbox #info.NoPlots     290, 160,100, 25
    if (eee=4) or (eee=5) then textbox #info.MeasPlots   290, 190,100, 25
    end if

    if method=2 then
    statictext #info.TractName$, "Tract name",                                  10,  10, 270, 18
    statictext #info.Cruiser$, "Cruiser name",                                  10,  40, 270, 18
    statictext #info.Date$, "Date",                                             10,  70, 270, 18
    statictext #info.Acres, "Acres",                                           10,  100,270, 18
    'statictext #info.PlotSize, "BAF",        10,  130,270, 18
     statictext #info.PlotSize, "Plot size (ac)",        10,  130,270, 18
    statictext #info.NoPlots, "Total no. plots or points ",        10,  160,270, 18
    'if (eee=4) or (eee=5) then statictext #info.MeasPlots, "No. measured points ",10,  190,270,18
    textbox #info.TractName$, 290, 10, 100, 25
    textbox #info.Cruiser$    290, 40, 100, 25
    textbox #info.Date$       290, 70, 100, 25
    textbox #info.Acres       290, 100,100, 25
    'if method=3 then  PlotSize=Acres
    textbox #info.PlotSize    290, 130,100, 25
    textbox #info.NoPlots     290, 160,100, 25
    if (eee=4) or (eee=5) then textbox #info.MeasPlots   290, 190,100, 25
    end if

    if method=3 then
    statictext #info.TractName$, "Tract name",                                  10,  10, 270, 18
    statictext #info.Cruiser$, "Cruiser name",                                  10,  40, 270, 18
    statictext #info.Date$, "Date",                                             10,  70, 270, 18
    statictext #info.Acres, "Acres",                                           10,  100,270, 18
    'statictext #info.PlotSize, "BAF",        10,  130,270, 18
    ' statictext #info.PlotSize, "Plot size (ac)",        10,  130,270, 18
    'statictext #info.NoPlots, "Total no. plots or points ",        10,  160,270, 18
    'if (eee=4) or (eee=5) then statictext #info.MeasPlots, "No. measured points ",10,  190,270,18
    textbox #info.TractName$, 290, 10, 100, 25
    textbox #info.Cruiser$    290, 40, 100, 25
    textbox #info.Date$       290, 70, 100, 25
    textbox #info.Acres       290, 100,100, 25
    PlotSize=Acres
    NoPlots=1
   ' textbox #info.PlotSize    290, 130,100, 25
   ' textbox #info.NoPlots     290, 160,100, 25
    'if (eee=4) or (eee=5) then textbox #info.MeasPlots   290, 190,100, 25
    end if

    button #info, "OK", [ENTRY], UL, 10, 250

    WindowWidth = 450 : WindowHeight = 450
    UpperLeftX = 200 : UpperLeftY = 150

    open "Cruise information" for window as #info

    'now stop and wait
    wait


[ENTRY] 'loops around for entered values
print #info.TractName$, "!contents? TractName$"
print #info.Cruiser$, "!contents? Cruiser$"
print #info.Date$, "!contents? Date$"
print #info.Acres, "!contents? Acres"
if method<3 then print #info.PlotSize, "!contents? Plot"
if method=3 then PlotSize=Acres
if method<3 then print #info.NoPlots, "!contents? NoPlots"
if (eee=4) or (eee=5) then
  print #info.MeasPlots, "!contents? NoMeas"
  NoMeasPlots=NoMeas
end if
if method=1 then BAF=Plot
if method=2 then PlotSize=Plot
close #info

'Branch Label Event Handler
' Sample program.  Pick a contact status
options$(0) = "Int"
options$(1) = "Doyle"
options$(2) = "Scribner"

listbox #LogRule.list, options$(), [selectionMade], 5, 35, 250, 90
'button #LogRule, "Continue", [selectionMade], UL, 5, 5
'button #LogRule, "Cancel", [cancelStatusSelection], UR, 15, 5
WindowWidth = 270 : WindowHeight = 180
open "Select log rule and pulpwood units " for window as #LogRule

wait

[selectionMade]
print #LogRule.list, "selection? selection$"
if selection$="Int" then Rule$="i"
if selection$="Doyle" then Rule$="d"
if selection$="Scribner" then Rule$="s"
close #LogRule

if eee=3 then
'Branch Label Event Handler
' Sample program.  Pick a contact status
options2$(0) = "Cords"
options2$(1) = "Tons"
listbox #Pul.list, options2$(), [selectionMade2], 5, 35, 250, 90
WindowWidth = 270 : WindowHeight = 180
open "Select pulpwood units " for window as #Pul

wait

[selectionMade2]
print #Pul.list, "selection? selection$"
if selection$="Cords" then Pul$="c"
if selection$="Tons" then Pul$="t"
close #Pul
end if
'-----------------------------------------------------------------------------------------------------------------------------------------------------------------
'                                                       CALCULATE TREE VOLUMES
'-----------------------------------------------------------------------------------------------------------------------------------------------------------------

'print "Species  MBF per acre   Dollars per acre"
OPEN file$ FOR input AS #2

DIM value(rows, 12)
    FOR r = 1 to rows
      FOR c = 1 to 4
      INPUT #2, val
      if val=999 then goto[xxx]
        TreeData(r,c)=val
       NEXT c
      Next r
[xxx]
    TotBa=0
    TotVol=0
    if eee=3 then min=1  'includes pulpwood if regular cruise
    if eee>3 then min=2  'does not include pulpwood if double sample
    for species=min to maxSp
    SumDoyle=0           'see no reason for this???
    SumBA=0
    for g=1 to rows

      stump$=MyStumpageData$(species,4)
      stump=val(stump$)
      fc$=MyStumpageData$(species,3)
      FC=val(fc$)
      species$=MyStumpageData$(species,2)

      sp=TreeData(g,2)
        if sp=species then
           d=TreeData(g,3)
           TreeData(g,12)=.005454*d^2
           l=TreeData(g,4)
       if BAF=0 then
           TA=1*(1/PlotSize)
           BA=.005454*d^2*(1/PlotSize)
           TreeData(g,5)=BA
           TreeData(g,6)=TA
       end if
      if (BAF<>0) then
           if (d<>0) then TA=1*(BAF/(.005454*d^2))
           BA=1*BAF
           TreeData(g,5)=BA
           TreeData(g,6)=TA
       end if

      if (sp=1) and (l=0) and (d<>0) then
         Cords =  (.00105 * d ^ 2.2 - .017)
         Tons=2.9*Cords
         if (Pul$="c") or (Pul$="C") then stumpage=Cords*stump
         if (Pul$="t") or (Pul$="T") then stumpage=Tons*stump
         TreeData(g,7)=Cords*TA
         TreeData(g,8)=Tons*TA
         TreeData(g,10)=stumpage*TA
      end if

      if (sp=2) and (l=0) and (d<>0) then
         Cords =  (.000596 * d ^ 2.4 - .015)
         Tons=2.675*Cords
         if (Pul$="c") or (Pul$="C") then stumpage=Cords*stump
         if (Pul$="t") or (Pul$="T") then stumpage=Tons*stump
         TreeData(g,7)=Cords*TA
         TreeData(g,8)=Tons*TA
         TreeData(g,10)=stumpage*TA
      end if



        'Int vol:
        if (sp>0) and (l> 0) and (d<>0) then
        if Rule$="i" or Rule$="I" then
        xa = (1.52968 * l ^ 2 + 9.58615 * l - 13.3521)
        xb = (1.7962 - .27465 * l ^ 2 - 2.59995 * l) * d
        xc = (.04482 - .00961 * l ^ 2 + .45997 * l) * d ^ 2
        xf = ((FC - 78) * (.03)) + 1
        VX = (((xa + xb + xc) * xf)/1000)
         TreeData(g,9)=VX*TA
         TreeData(g,13)=VX*1000
         stumpage=VX*stump
         TreeData(g,10)=stumpage*TA
         TotBa=TotBa+.005454*d^2*TA
         TotLogs=TotLogs+l
         TreeData(g,11)=l
         TotVol=TotVol+VX*TA
          end if

         if Rule$="d" or Rule$="D" then
        'Doyle vol:
        xa = (17.5351 * l - .59242 * l ^ 2 - 22.5037)
        xb = (3.02988 - .02302 * l ^ 2 - 4.34381 * l) * d
        xc = (.51593 * l - .02035 * l ^ 2 - .01969) * d ^ 2
        xf = ((FC - 78) * (.03)) + 1
        VX= (((xa + xb + xc) * xf)/1000)
         TreeData(g,13)=VX*1000
         TreeData(g,9)=VX*TA
         stumpage=VX*stump
         TreeData(g,10)=stumpage*TA
          SumDoyle=SumDoyle*VX
          TotBa=TotBa+.005454*d^2*TA
         TotLogs=TotLogs+l
         TreeData(g,11)=l
         TotVol=TotVol+VX*TA
         end if

         if Rule$="s" or Rule$="S" then
        'Scribner vol:
        xa = (.55743 * l ^ 2 + 41.5128 * l - 29.3734)
        xb = (2.78043 - .04516 * l ^ 2 - 8.772721 * l) * d
        xc = (.04177 - .01578 * l ^ 2 + .59042 * l) * d ^ 2
        xf = ((FC - 78) * (.03)) + 1
        VX = (((xa + xb + xc) * xf)/1000)
          TreeData(g,13)=VX*1000
          TreeData(g,9)=VX*TA
          stumpage=VX*stump
         TreeData(g,10)=stumpage*TA
         TotBa=TotBa+.005454*d^2*TA
         TotLogs=TotLogs+l
         TreeData(g,11)=l
         TotVol=TotVol+VX*TA
        end if
        end if
        end if
     next g

    next species
    print

    'filling all trees with values
   if eee=4 then VBAR=TotVol/TotBa
    if eee=5 then VBAR2=TotVol/TotLogs
    print
for h=1 to rows
      if (TreeData(h,2)>2) and (eee=4) and (TreeData(h,3)=0) then
      z=TreeData(h,2)
      stump$=MyStumpageData$(z,4)
      stump=val(stump$)
       TreeData(h,5)=BAF
       TreeData(h,9)=VBAR*BAF
       TreeData(h,10)=stump*VBAR*BAF
      end if
      if (TreeData(h,2)>2) and (eee=5) and (TreeData(h,3)=0) and (TreeData(h,4)>0) then
      zz=TreeData(h,2)
      stump$=MyStumpageData$(zz,4)
      stump=val(stump$)
       TreeData(h,9)=VBAR2*TreeData(h,4)
       TreeData(h,10)=stump*VBAR2*TreeData(h,4)
      end if
next h


'see if array ok
'for r = 1 to 10
'for c =1 to 10
'print c, TreeData(r,c)
'next c
'print
'next r
'print "TotVol = ";TotVol
'print "TotLogs= ";TotLogs
'print "VBAR2 = ";VBAR2
close#2
'end sub
'-----------------------------------------------------------------------------------------------------------------------------------------
'                                       CALCULATE PER-ACRE AND TRACT VALUES
'-----------------------------------------------------------------------------------------------------------------------------------------
'Summary tables
Dim Totals(maxSp+1,6)  'SpNo,Trees,BA,Cords or Tons,Mbf,Stumpage
for AcreTract=1 to 2


print
f$="########.##"
'calculations for plots
sumBA=0
sumTrees=0
sumCords=0
sumTons=0
sumBF=0
sumStump=0
TotBA=0
TotTrees=0
TotAshley=0
TotCords=0
TotTons=0
TotBF=0
TotStump=0
TotBA2=0
TotTrees2=0
TotCords2=0
TotTons2=0
TotBF2=0
TotStump2=0
TotLogs=0
TotLogs2=0


print

for plot = minPlot to maxPlot

sumBA=0
sumTrees=0
sumAshley=0
sumCords=0
sumTons=0
sumBF=0
sumStump=0
sumDBH=0
sumLogs=0

for tree = 1 to rows

   if (TreeData(tree,1) = plot) and (eee=3) then
     sumDBH=sumDBH+TreeData(tree,3)
     sumBA=sumBA+TreeData(tree,5)
     sumTrees=sumTrees+TreeData(tree,6)
     if TreeData(tree,3)>9 then sumAshley=sumAshley+TreeData(tree,6)
     sumCords=sumCords+TreeData(tree,7)
     sumTons=sumTons+TreeData(tree,8)
     sumBF=sumBF+TreeData(tree,9)
     sumStump=sumStump+TreeData(tree,10)
     sumLogs=sumLogs+TreeData(tree,4)
   end if

   if (TreeData(tree,1) = plot) and (eee>3) and (TreeData(tree,2)>2) then
     sumDBH=sumDBH+TreeData(tree,3)
     sumBA=sumBA+TreeData(tree,5)
     sumTrees=sumTrees+TreeData(tree,6)
     if TreeData(tree,3)>9 then sumAshley=sumAshley+TreeData(tree,6)
     sumCords=sumCords+TreeData(tree,7)
     sumTons=sumTons+TreeData(tree,8)
     sumBF=sumBF+TreeData(tree,9)
     sumStump=sumStump+TreeData(tree,10)
     sumLogs=sumLogs+TreeData(tree,4)
   end if

  next tree

TotBA=TotBA+sumBA
TotTrees=TotTrees+sumTrees
TotAshley=TotAshley+sumAshley
TotCords=TotCords+sumCords
TotTons=TotTons+sumCords
TotBF=TotBF+sumBF
TotStump=TotStump+sumStump
TotBA2=TotBA2+sumBA^2
TotTrees2=TotTrees2+sumTrees^2
TotCords2=TotCords2+sumCords^2
TotTons2=TotTons2+sumTons^2
TotBF2=TotBF2+sumBF^2
TotStump2=TotStump2+sumStump^2
TotLogs=TotLogs+sumLogs
TotLogs2=TotLogs2+sumLogs^2

'store per-acre plot values in an array PlotData()
PlotData(plot,1)=sumBA
PlotData(plot,2)=sumTrees
PlotData(plot,3)=sumCords
PlotData(plot,4)=sumTons
PlotData(plot,5)=sumBF
PlotData(plot,6)=sumStump
if (sumDBH=0) then PlotData(plot,7)=0 else PlotData(plot,7)=1
PlotData(plot,8)=sumLogs
next plot

'test PlotData() array
'print "plot","BaAc","TreesAc","CordsAc","BfAc","$Ac"
'for r=1 to NoPlots
'print r,
'for c=1 to 6
' print PlotData(r,c),
'next c
'print
'next r
'end sub

'if eee=3 then NoPlots=NoPlots
'if eee>3 then NoPlots=NoMeasPlots






  meanBA=TotBA/NoPlots
  meanLogs=TotLogs/NoPlots
  meanTrees=TotTrees/NoPlots
  meanAshley=TotAshley/NoPlots
  meanCords=TotCords/NoPlots
  meanTons=TotTons/NoPlots
  meanBF=TotBF/NoPlots
  meanStump=TotStump/NoPlots


'SE for double sample
if eee>3 then
sumXp=0
sumXp2=0
sumY=0
sumX=0
sumX2=0
sumXY=0
sumY2=0

n=NoMeasPlots
nP=NoPlots

for h=minPlot to maxPlot
   if eee=4 then X=PlotData(h,1)
   if eee=5 then X=PlotData(h,8)
   sumXp=sumXp+X
   sumXp2=sumXp2+X^2
   if PlotData(h,7)=1 then
     Y=PlotData(h,5)
     sumY=sumY+Y
     sumY2=sumY2+Y^2
     sumX=sumX+X
     sumX2=sumX2+X^2
     sumXY=sumXY+X*Y
    end if
next h
r=sumY/sumX
mean=sumXp/NoPlots*r
S2Y=(sumY2-sumY^2/n)/(n-1)
a=(sumY2-2*r*sumXY+r^2*sumX2)/(n-1)
SE=(S2Y/nP+a/n*((nP-n)/nP))^.5
SEper=SE/mean*100
'print "mean Y = ";sumY/NoMeasPlots
'print "mean X = ";sumX/NoMeasPlots
'print "mean vol = ";mean
'print "Doub sample SE% = ";SEper
end if






  if (NoPlots>1) and (meanBA<>0) then
     SBA=(((TotBA2-(TotBA^2)/NoPlots))/(NoPlots-1))^.5
     SEBA=(((SBA)/NoPlots^.5)/meanBA)*100
     CVBA=(SBA/meanBA)*100
  end if
  if (NoPlots>1) and (meanTrees<>0) then
    STrees=(((TotTrees2-(TotTrees^2)/NoPlots))/(NoPlots-1))^.5
    SETrees=(((STrees)/NoPlots^.5)/meanTrees)*100
    CVTrees=(STrees/meanTrees)*100
  end if
  if (NoPlots>1) and (meanCords<>0) then
    SCords=(((TotCords2-(TotCords^2)/NoPlots))/(NoPlots-1))^.5
    SECords=(((SCords)/NoPlots^.5)/meanCords)*100
    CVCords=(SCords/meanCords)*100
  end if
  if (NoPlots>1) and (meanTons<>0) then
    STons=(((TotTons2-(TotTons^2)/NoPlots))/(NoPlots-1))^.5
    SETons=(((STons)/NoPlots^.5)/meanTons)*100
    CVTons=(STons/meanTons)*100
  end if
  if (NoPlots>1) and (meanBF<>0) then
     SBF=(((TotBF2-(TotBF^2)/NoPlots))/(NoPlots-1))^.5
     SEBF=(((SBF)/NoPlots^.5)/meanBF)*100
     CVBF=(SBF/meanBF)*100
  end if
  if (NoPlots>1) and (meanStump<>0) then
  SStump=(((TotStump2-(TotStump^2)/NoPlots))/(NoPlots-1))^.5
  SEStump=(((SStump)/NoPlots^.5)/meanStump)*100
  CVStump=(SStump/meanStump)*100
  end if

  if AcreTract=1 then
  print "SUMMARY TABLE"
  print
  print "Stumpage file      = ";fileMyStumpageData$
  print "Cruise data file   = ";file$
  print
  print "Tract              = ";TractName$
  print "Cruiser            = ";Cruiser$
  print "Date               = ";Date$
  print "Acres              = ";Acres
  if BAF>0 then print "BAF                = ";BAF
  if BAF=0 then print "Plot size          = ";PlotSize
  print "No. plots          = ";NoPlots
  if eee>3 then  print "No. plots measured = ";NoMeasPlots
  if (Rule$="i") or (Rule$="I") then print "Log rule           = ";"Inter."
  if (Rule$="d") or (Rule$="D") then print "Log rule           = ";"Doyle"
  if (Rule$="s") or (Rule$="S") then print "Log rule           = ";"Scribner"
  if (Pul$="c") or (Pul$="C") then print "Pulpwood           = ";"Cords"
  if (Pul$="t") or (Pul$="T") then print "Pulpwood           = ";"Tons"
  print
  if eee>3 then
  print "The SE% below is based on the usual formulae for double sampling."
  print "It is recommended that this SE% be used, especially if the easily"
  print "measured variable is basal area."
  print
  'print "Mean MBF/acre = ";
  'print using(f$,mean)
  'print "Tract volume  = ";
 ' print using(f$,mean*Acres)
  print "SE%           = ";
  print using (f$,SEper)
  end if
  print

  print
  print "The values in this table are based on estimates made for each"
  print "tree tallied; for non-measured trees in double sampling estimates"
  print "are made using the ratio estimator."
  print
  print "Measure           Acre   Tract          SE%     CV%"
  print
  print "BA";tab(10);
  print using(f$,meanBA);tab(10);
  print using(f$,meanBA*Acres);tab(10);  '*************************** do sum stuff here
  TractBA=meanBA*Acres
  print using(f$,SEBA);tab(10);
  print using(f$,CVBA);tab(10)
  print "Trees";tab(10);
  print using(f$,meanTrees);tab(10);
  print using(f$,meanTrees*Acres);tab(10);
  TractTrees=meanTrees*Acres
  print using(f$,SETrees);tab(10);
  print using(f$,CVTrees)
  if (Pul$="c") or (Pul$="C") then
  print "Cords";tab(10);
  print using(f$,meanCords);tab(10);
  print using(f$,meanCords*Acres);tab(10);
  TractCords=meanCords*Acres
  print using(f$,SECords);tab(10);
  print using(f$,CVCords)
  end if
  if (Pul$="t") or (Pul$="T") then
  print "Tons";tab(10);
  print using(f$,meanTons);tab(10);
  print using(f$,meanTons*Acres);tab(10);
  TractTons=meanTons*Acres
  print using(f$,SETons);tab(10);
  print using(f$,CVTons)
  end if
  print "MBF";tab(10);
  print using(f$,meanBF);tab(10);
  print using(f$,meanBF*Acres);tab(10);
  TractMBF=meanBF*Acres
  print using(f$,SEBF);tab(10);
  print using(f$,CVBF)
  print "Stump$";tab(10);
  print using(f$,meanStump);tab(10);
  print using(f$,meanStump*Acres);tab(10);
  TractStumpage=meanStump*Acres
  print using(f$,SEStump);tab(10);
  print using(f$,CVStump)
end if
  'Species tables
  print
  j$="####"

print
print
if AcreTract=1 then print "PER-ACRE SUMMARY TABLES BY SPECIES AND DIAMETERS"
if AcreTract=2 then print "TRACT SUMMARY TABLES BY SPECIES AND DIAMETERS"
print



for species=minSp to maxSp+1

if (species<maxSp+1) then print MyStumpageData$(species,2)
if (species=maxSp+1) then print "All species"
print
if (Pul$="c") or (Pul$="C") then print "Dbh              BA       Trees   Cords      MBF       Stumpage$"
if (Pul$="t") or (Pul$="T") then print "Dbh              BA       Trees   Tons       MBF       Stumpage$"
if eee=4 or eee=5 then print "Dbh              BA       Trees    MBF       Stumpage$"
print
f$="########.#"
'calculations by species and diameters

sumBA=0
sumTrees=0
sumCords=0
sumTons=0
sumBF=0
sumStump=0
TotBA=0
TotTrees=0
TotCords=0
TotTons=0
TotBF=0
TotStump=0
TotBA2=0
TotTrees2=0
TotCords2=0
TotTons2=0
TotBF2=0
TotStump2=0


for diam = 0 to maxDbh
sumBA=0
sumTrees=0
sumCords=0
sumTons=0
sumBF=0
sumStump=0
NoTrees=0

for tree = 1 to rows

   if (AcreTract=1) and (TreeData(tree,2) = species) and (TreeData(tree,3)=diam) then

     sumBA=sumBA+TreeData(tree,5)
     sumTrees=sumTrees+TreeData(tree,6)
     sumCords=sumCords+TreeData(tree,7)
     sumTons=sumTons+TreeData(tree,8)
     sumBF=sumBF+TreeData(tree,9)
     sumStump=sumStump+TreeData(tree,10)
     NoTrees=NoTrees+1
     end if


   if (AcreTract=2) and (TreeData(tree,2) = species) and (TreeData(tree,3)=diam) then

     sumBA=sumBA+TreeData(tree,5)*Acres
     sumTrees=sumTrees+TreeData(tree,6)*Acres
     sumCords=sumCords+TreeData(tree,7)*Acres
     sumTons=sumTons+TreeData(tree,8)*Acres
     sumBF=sumBF+TreeData(tree,9)*Acres
     sumStump=sumStump+TreeData(tree,10)*Acres
     NoTrees=NoTrees+1
     end if


     if (AcreTract=1) and (species=maxSp+1) and (TreeData(tree,3)=diam) then

     sumBA=sumBA+TreeData(tree,5)
     sumTrees=sumTrees+TreeData(tree,6)
     sumCords=sumCords+TreeData(tree,7)
     sumTons=sumTons+TreeData(tree,8)
     sumBF=sumBF+TreeData(tree,9)
     sumStump=sumStump+TreeData(tree,10)
     NoTrees=NoTrees+1
     end if

     if (AcreTract=2) and (species=maxSp+1) and (TreeData(tree,3)=diam) then

     sumBA=sumBA+TreeData(tree,5)*Acres
     sumTrees=sumTrees+TreeData(tree,6)*Acres
     sumCords=sumCords+TreeData(tree,7)*Acres
     sumTons=sumTons+TreeData(tree,8)*Acres
     sumBF=sumBF+TreeData(tree,9)*Acres
     sumStump=sumStump+TreeData(tree,10)*Acres
     NoTrees=NoTrees+1
     end if


    next tree

  TotBA=TotBA+sumBA
  TotTrees=TotTrees+sumTrees
  TotCords=TotCords+sumCords
  TotTons=TotTons+sumTons
  TotBF=TotBF+sumBF
  TotStump=TotStump+sumStump
  if NoTrees>0 then
'print "BA",
print diam;tab(10);
print using(f$,sumBA/NoPlots);tab(10);
'print using(f$,(sumBA/NoTrees)*Acres)
'print "Trees",
'print diam,
print using(f$,sumTrees/NoPlots);tab(10);
'print using(f$,(sumTrees/NoTrees)*Acres)
'print "Cords",
'print diam,
if (Pul$="c") or (Pul$="C") then print using(f$,sumCords/NoPlots);tab(10);
'print using(f$,(sumCords/NoTrees)*Acres)
'print "Tons",
'print diam,
if (Pul$="t") or (Pul$="T") then print using(f$,sumTons/NoPlots);tab(10);
'print using(f$,(sumTons/NoTrees)*Acres)
'print "MBF",
'print diam,
print using(f$,sumBF/NoPlots);tab(10);
'print using(f$,(sumBF/NoTrees)*Acres)
'print "Stumpage$",
'print diam,
print using(f$,sumStump/NoPlots)
'print using(f$,sumStump/NoTrees*Acres)

end if

next diam
print "Totals";tab(10);
print using(f$,TotBA/NoPlots);tab(10);
Totals(species,3)=TotBA/NoPlots
print using(f$,TotTrees/NoPlots);tab(10);
Totals(species,2)=TotTrees/NoPlots
if (Pul$="c") or (Pul$="C") then print using(f$,TotCords/NoPlots);tab(10);
if (Pul$="c") or (Pul$="C")then Totals(species,4)=TotCords/NoPlots
if (Pul$="t") or (Pul$="T") then print using(f$,TotTons/NoPlots);tab(10);
if (Pul$="t") or (Pul$="T") then Totals(species,4)=TotTons/NoPlots
print using(f$,TotBF/NoPlots);tab(10);
Totals(species,5)=TotBF/NoPlots
print using(f$,TotStump/NoPlots)
Totals(species,6)=TotStump/NoPlots
print

next species
next AcreTract
print
if eee=3 then
Print "APPROXIMATE BOARD-FOOT GROWTH/ACRE/YR"
PRINT "...uses method described by Ashley (1999, USDA For. Serv. NA-FR-15)"
print
print "Site","Growth BF/Ac/Yr"
print "  "
print "Good",
print int(meanAshley*5)
print "Average",
print int(meanAshley*4)
print "Poor",
print int(meanAshley*3)
print
end if


print
print "AVERAGE SAWTIMBER DBH AND VOLUME"
print
print "Species              DBH   BF"
print
No=0
SumTrees=0
SumBA=0
SumBAAc=0
SumCords=0
SumTons=0
SumVol=0
SumVolAc=0
SumStump=0
GrandSumTrees=0
GrandSumBA=0
GrandSumBAAc=0
GrandSumCords=0
GrandSumTons=0
GrandSumVol=0
GrandSumVolAc=0
GrandSumStump=0
GrandNo=0
for species=minSp to maxSp+1
for tree = 1 to rows
if TreeData(tree,2)=species and TreeData(tree,12)>0 then
  'SumTrees=SumTrees+TreeData(tree,6)
  'GrandSumTrees=GrandSumTrees+TreeData(tree,6)
  SumVol=SumVol+TreeData(tree,13)
  'SumVolAc=SumVolAc+TreeData(tree,9)
  'GrandSumVolAc=GrandSumVolAc+TreeData(Tree,9)
  'GrandSumVol=GrandSumVol+TreeData(tree,13)
  'SumStump=SumStump+TreeData(tree,10)
  'GrandSumStump=GrandSumStump+TreeData(tree,10)
  SumBA=SumBA+TreeData(tree,12)
  GrandSumBA=GrandSumBA+TreeData(tree,12)
  'SumBAAc=SumBAAc+TreeData(tree,5)
  'GrandSumBAAc=GrandSumBAAc+TreeData(tree,5)
  'SumVol=SumVol+TreeData(tree,13)
  GrandSumVol=GrandSumVol+TreeData(tree,13)
  No=No+1
  GrandNo=GrandNo+1
end if
next tree
if species>2 and No<>0 then
   print MyStumpageData$(species,2); tab(20);
   print using("###.#",((SumBA/No)/.005454)^.5); tab(20);
   print using("#####", SumVol/No)
end if
SumBA=0
SumVol=0
No=0
next species
'if (species=maxSp+1) then
print
  print "All species"; tab(20);
  print using("###.#",((GrandSumBA/GrandNo)/.005454)^.5); tab(20);
  print using ("#####",GrandSumVol/GrandNo)
'end if
print
print
print "SUMMARY TABLES FOR SAWTIMBER TOTALS BY SPECIES"
print
print "Species","     Trees","       BA","      MBF","    Stumpage$"
print
for sp=2 to maxSp
print MyStumpageData$(sp,2),
print using(f$,Totals(sp,2)),
print using(f$,Totals(sp,3)),
print using(f$,Totals(sp,5)),
print using(f$,Totals(sp,6))
next sp
print
print "Totals",
print using(f$,TractTrees),
print using(f$,TractBA),
print using(f$,TractMBF),
print using(f$,TractStumpage)
print
print
print "PERCENTAGE VALUES"
print
print "Species","     Trees","       BA","       MBF","    Stumpage$"
 print
for sp=2 to maxSp
print MyStumpageData$(sp,2),
Print using(f$,Totals(sp,2)/TractTrees*100),
print using(f$,Totals(sp,3)/TractBA*100),
print using(f$,Totals(sp,5)/TractMBF*100),
print using(f$,Totals(sp,6)/TractStumpage*100)
'print "% of all",
'print using(f$,PerTrees),
'print using(f$,PerVol),
'print using(f$,PerStump)
'print

next sp


print
print

print
print "The data below is useful if you wish to plot contour lines of volume or value,"
print " using a program such as QuikGrid, available on the www."
print
Print "PER-ACRE PLOT OR POINT VALUES"
print
print "Plot       Ba         Trees      Cords     Tons            Mbf       Stumpage$    1.00 or 0.00 (0 if estimated point or  no volume, and 1 measured)"

print
for r = minPlot to maxPlot
print r;",";
g$="#########.##"
for c =1 to 7
if c<7 then print using(g$, PlotData(r,c));tab(10);
if c=7 then print using(g$, PlotData(r,7));tab(10);
next c
print
next r
print

'print "NOTE:  Output will print properly in columns if you use the"
'print "       Edit menu Select All, and paste into Notepad before printing!"
print
print "IMPORTANT!"
print
PRINT "Before printing these results, use copy and paste into Notepad so that columns"
print "line up correctly!"
print
input "After you save the output to a file and/or print the output, hit Enter key to exit.";done$


  end sub
 sub FileFix
 'Change point-sample data to test how double sampling would have performed

print "You need to provide a name for the new data file based on your point"
print "sample cruise which you will use to evaluate how double sampling"
print "would have performed.  DO NOT USE THE SAME NAME AS FOR THE ORIGINAL FILE!"
print
print
Input "Highest Plot number in original cruise  = ";HighPlot
print
Input "Enter 1 to use BA, 2 to use Logs        = ";use
print
print "Enter number of non-measured points for"
input "each measured point, usually 2 or 3     = ";Skip
print
input "New data file name, SomeName.txt        = ";NewFile$

filedialog "Click on file with original cruise data ","*.txt", file$


open file$ for input as #original
open "Copy.txt" for output as #copy
  print #copy, input$(#original, lof(#original));
  close #original
  close #copy

open "Copy.txt" for input as #k
open NewFile$ for output as #L
MeasPlot=1
SkipTo=MeasPlot+Skip
[here]
  input #k, Plot,SpNo,Dbh,Logs
   if (Plot>MeasPlot+Skip) then MeasPlot=Plot
   print #L,Plot;
   print #L,",";
   print #L,SpNo;
   print #L,",";
 if (Plot<>999) and (Plot=MeasPlot) then
     print #L,Dbh;
     print #L,",";
     Print #L,Logs
   end if
 if (Plot<>999) and (Plot>MeasPlot) and (Plot<SkipTo) then
    if use=1 or use=2 then print #L,0;
     print #L,",";
     if use=1 then print #L,0
     if use=2 then print #L,Logs
   end if
if Plot=999 then
  print #L,Dbh;
  print #L,",";
  Print #L,Logs
  close #k
  close #L
  goto[done]
end if
SkipTo=SkipTo+MeasPlot
goto[here]

[done]
print
input "Press Enter to continue ";see$
print
call Start

end sub





  end







