package MpmasEDICSurface;

use strict;
use warnings;
use Exporter;
use Storable qw(dclone);
use Data::Dumper;
use MpmasInputfile;
use MpmasInputBlock;
our @ISA = qw(MpmasInputfile);

sub filename {
	return "EdicSurfaceRunoff0";
}
sub required {
      my $self = shift;
      return 1 if ($self->config_entry("LANDSCAPE_MODEL") == 1 );
}
sub prepare_shared {
	my $self = shift;
}


sub prepare_special {
	my $self = shift;	
	my @sorted_sectors = @{$self->config_entry("SORTEDSECTORS")};
	my $dbh = $self->get_dbh;
	my $routing =  $self->config_entry("EDICROUTING")->transform($dbh,2) ;

	my $block1 = MpmasInputBlock->new(3,10);
	$block1->add_row("WATER ROUTING FILE");
	$block1->add_row(1,"SURFACE FLOWS");
	$block1->add_row(1.1,"Number of Rows","",scalar @sorted_sectors);
	$block1->add_row(1.2,"Number of Columns","",scalar @sorted_sectors);
	$block1->add_empty_rows(3);
	$block1->add_comment_row("","Gis IDs","","From Sector");
	$block1->add_comment_row("","To Sector","",@sorted_sectors);
	for my $i (@sorted_sectors) {
	     my @row = ("",$i,"");
	    for my $j (@sorted_sectors) {
		  my $x = $routing->query([$j,$i],3)||0;
		  push @row, $x;
	    }
	    
	    $block1->add_row(@row);
	}
	$self->add_block($block1);

}
