set opt(chan)			Channel/UnderwaterChannel
set opt(prop)			Propagation/UnderwaterPropagation
set opt(netif)			Phy/UnderwaterPhy
set opt(mac)			Mac/UnderwaterMac/BroadcastMac
set opt(ifq)			Queue/DropTail
set opt(ll)				LL
set opt(energy)         EnergyModel
set opt(txpower)       2
set opt(rxpower)        0.75
set opt(initialenergy)  12000
set opt(idlepower)      0.01
set opt(ant)            Antenna/OmniAntenna  
set opt(filters)        GradientFilter   
set opt(max_pkts)		50000
set opt(interval_)	          5;
set opt(pkt_len)	          150;  
set opt(bit_rate)                         50e3 ;#50kbps
set opt(encoding_efficiency)          1
set opt(ifqlen)		              50	
set opt(nn)	                		240
set opt(sonocount)	                	40
set opt(x)	                		1500	
set opt(y)	                        	1500  
set opt(z)                      		1500
set opt(seed)	                		0
set opt(stop)	                		3600 
set opt(tr)	                		"Scenario.tr"	
set opt(nam)                            	"Scenario.nam"  
set opt(datafile)	                    "Scenario.data"
set opt(adhocRouting)                 	UWSNPROTOCOL
set start_time				1

LL set mindelay_		50us
LL set delay_			25us
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 0.05
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0

Mac/UnderwaterMac set bit_rate_  $opt(bit_rate)
Mac/UnderwaterMac set encoding_efficiency_  $opt(encoding_efficiency)
Node/MobileNode/UnderwaterSensorNode set position_update_interval_ 1.0

Phy/UnderwaterPhy set CPThresh_ 10 
Phy/UnderwaterPhy set CSThresh_ 0  
Phy/UnderwaterPhy set RXThresh_ 0   
Phy/UnderwaterPhy set Pt_ 0.2818
Phy/UnderwaterPhy set freq_ 25  ;#frequency range in khz 
Phy/UnderwaterPhy set K_ 2.0   ;#spherical spreading

# ==================================================================
# Main Program
# =================================================================

#
# Initialize Global Variables

set ns_ [new Simulator]
set topo  [new Topography]

$topo load_cubicgrid $opt(x) $opt(y) $opt(z)
#$ns_ use-newtrace
set tracefd	[open $opt(tr) w]
$ns_ trace-all $tracefd

set nf [open $opt(nam) w]
$ns_ namtrace-all-wireless $nf $opt(x) $opt(y)

set data [open $opt(datafile) a]

set total_number [expr $opt(nn)-1]
set god_ [create-god $opt(nn)]

set chan_1_ [new $opt(chan)]

$ns_ at 0.0 "$god_  set_filename $opt(datafile)"

global defaultRNG

$defaultRNG seed $opt(seed)

$ns_ node-config -adhocRouting $opt(adhocRouting)  \
		 -llType $opt(ll) \
		 -macType $opt(mac) \
		 -ifqType $opt(ifq) \
		 -ifqLen $opt(ifqlen) \
		 -antType $opt(ant) \
		 -propType $opt(prop) \
		 -phyType $opt(netif) \
		 -agentTrace ON \
         -routerTrace ON \
         -macTrace ON \
         -movementTrace ON \
         -topoInstance $topo\
         -energyModel $opt(energy)\
         -txpower $opt(txpower)\
         -rxpower $opt(rxpower)\
         -initialEnergy $opt(initialenergy)\
         -idlePower $opt(idlepower)\
         -channel $chan_1_

set xrand_ [new RandomVariable/Uniform]
$xrand_ set min_ 0
$xrand_ set max_ $opt(x)
set yrand_ [new RandomVariable/Uniform]
$yrand_ set min_ 0
$yrand_ set max_ $opt(y)
set zrand_ [new RandomVariable/Uniform]
$zrand_ set min_ 10
$zrand_ set max_ $opt(z)

for {set i 0} { $i < $opt(sonocount)} { incr i } { ;#Generating 40 Sonobouys node

	set p [expr round([$xrand_ value])]
	set q [expr round([$yrand_ value])]
	set node_($i) [ $ns_  node $i]
	$node_($i) set sinkStatus_ 1
	$god_ new_node $node_($i)
	$node_($i) set X_  $p
	$node_($i) set Y_   $q
	$node_($i) set Z_   0
	$node_($i) set max_speed 2
	$node_($i) set min_speed 0
	$node_($i) setPositionUpdateInterval 1
	$node_($i) random-motion 0
	$node_($i) move
	set a_($i) [new Agent/Null]
	$ns_ attach-agent $node_($i) $a_($i)
}

for {set i $opt(sonocount)} { $i < $opt(nn)} { incr i } { ;#Generating Other nodes

	set p [expr round([$xrand_ value])]
	set q [expr round([$yrand_ value])]
	set k [expr -1*round([$zrand_ value])]
	set node_($i) [ $ns_  node $i]
	$node_($i) set sinkStatus_ 1
	$god_ new_node $node_($i)
	$node_($i) set X_  $p
	$node_($i) set Y_   $q
	$node_($i) set Z_   $k
	$node_($i) set max_speed 2
	$node_($i) set min_speed 0
	$node_($i) setPositionUpdateInterval 1
	$node_($i) random-motion 0
	$node_($i) move
	set a_($i) [new Agent/Null]
	$ns_ attach-agent $node_($i) $a_($i)
}

##end reading

set node_($total_number) [$ns_  node $total_number]
$node_($total_number) set sinkStatus_ 1
$node_($total_number) set passive 1
$god_ new_node $node_($total_number)
$node_($total_number) set X_  30
$node_($total_number) set Y_   60
$node_($total_number) set Z_ -180

set a_($total_number) [new Agent/UDP]
$ns_ attach-agent $node_($total_number) $a_($total_number)
$ns_ connect $a_($total_number) $a_(0)

set cbr_($total_number) [new Application/Traffic/CBR]
$cbr_($total_number) set packetSize $opt(pkt_len)   ;#80
$cbr_($total_number) set interval_ $opt(interval_)
$cbr_($total_number) set random 0
$cbr_($total_number) set maxpkts_  $opt(max_pkts)

$cbr_($total_number) attach-agent $a_($total_number)
#SENDER NODE"


$ns_ at 15 "$cbr_($total_number) start"
$ns_ at $opt(stop).002 "$a_($total_number) terminate"


puts "+++++++AFTER ANNOUNCE++++++++++++++"




set node_size 3
for {set k 0} { $k<$opt(nn) } { incr k } {
	$ns_ initial_node_pos $node_($k) $node_size
}

$ns_ at $opt(stop).001 "puts \"==$$$$$$$$$$==$total_number\""
$ns_ at $opt(stop).001 "puts \"+++++++++++++++++++++++++++++++++++++++++++++++++++++++\""
$ns_ at $opt(stop).001  "$god_ compute_energy"
$ns_ at $opt(stop).001  "$ns_ nam-end-wireless $opt(stop)"
$ns_ at $opt(stop).001 "puts \"NS EXISTING...\"; $ns_ halt"

 $ns_ run



