package MpmasSpatialExchangeInfo;

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

sub filename {
	return "SpatialExchangeInfo";
}
sub required {
	return 0;
}

sub write {
	my $self = shift;
	my $out;

	my $dbgversion = <<SPATDBG;
		THE SPATIAL EXCHANGE INFO
															
		The following flags are used to export spatial maps.							
		To do so, pass an argument   -A##,  where ## is the ID given bellow.							
									
		In theory, any data may be spatially exported, but it requires passing from 							
		parcel to landscape ! Thus, not all will be applicable so far… 							
									
		Number of ContentTypes		49					
		Number of columns		4					
									
	TESTED	ContentType	Origin/ Type	ID	Export and allocate spatally MONTHLY	Store at Sector Level	Import from Wasim		
	1	contFarmID,	input	0	0	0	0		
	1	contPropID,	input	1	0	0	0		
	1	contSoilID,	input	2	0	0	0		
	1	contCluID,	input	3	0	0	0		
	1	contNetwID,	input	4	0	0	0		
	0	contPopID,	input	5	0	0	0		
	0	contMapColor,	input	6	0	0	0		
	0	contDistFromHome	input	7	0	0	0		
	0	contUserMapID,	internal	8	0	0	0		
	0	contSectorID,	internal	9	0	0	0		
	0	contENDBASIC,	control	10	0	0	0		
	0	contSoilN,	TSPC	11	0	0	0		
	0	contSoilP,	TSPC	12	0	0	0		
	0	contSoilK,	TSPC	13	0	0	0		
	0	contSoilSe,	TSPC	14	0	0	0		
	0	contSoilA,	TSPC	15	0	0	0		
	0	contSoilC,	TSPC	16	0	0	0		
	0	contSoilSl,	TSPC	17	0	0	0		
	0	contSlopeLen,	TSPC	18	0	0	0		
	0	contSlopeErosion,	TSPC	19	0	0	0		
	0	contSoilCond,	TSPC	20	0	0	0		
	0	contENDTSPC,	control	21	0	0	0		
	1	contCropAct,	EDIC/MAS	22	0	0	0		
	1	contPrecip	EDIC/MAS/Wasim	23	1	1	1		
	1	cont_SectorReuseFactor	EDIC/MAS/Wasim	24	1	1	0		
	0	contENDIRRIG	control	25	0	0	0		
	0	contSoilMoist	Coupling/Wasim	26	1	1	0		
	1	contSoilMoist05	Coupling/Wasim	27	1	1	0		
	0	contSoilMoist1	Coupling/Wasim	28	1	1	0		
	0	contETpot	Coupling/Wasim	29	1	1	0		
	0	contETreal	Coupling/Wasim	30	1	1	0		
	0	contSurfaceRunoff	Coupling/Wasim	31	1	1	0		
	0	contPercol	Coupling/Wasim	32	1	1	0		
	0	contBaseFlow	Coupling/Wasim	33	1	1	0		
	0	contGroundwaterRecharge	Coupling/Wasim	34	1	1	0		
	0	contIrrigGrid	Coupling/Wasim	35	1	1	0		
	0	contLUGrid	Coupling/Wasim	36	1	1	0		
	0	contLUwasim	Coupling/Wasim	37	1	1	0		  
	1	contETdiff	Coupling/Wasim	38	1	1	0		
	0	contFlowMat	Coupling/Wasim	39	1	1	0		
	0	contWATERWAYS	Coupling/Wasim	40	1	1	0		
	0	contDEM	Coupling/Wasim	41	1	1	0		
	0	contIrrigQuant	Coupling/Wasim	42	1	1	0		
	0	contInterceptEvap	Coupling/Wasim	43	1	1	0		
	0	contThrougfall	Coupling/Wasim	44	1	1	0		
	0	contENDCOUPL	control	45	0	0	0		
	1	cont_etrToEtPot_monthly,	EDIC/MAS/Wasim	46	1	0	1		
	1	contIrrigQuantEdic	EDIC/MAS/Wasim	47	1	0	0		
	0	contENDMONTHLY	control	48	0	0	0		
SPATDBG

my $inputversion = <<SPAT;

						49
						4



						0	0	0	0
						1	0	0	0
						2	0	0	0
						3	0	0	0
						4	0	0	0
						5	0	0	0
						6	0	0	0
						7	0	0	0
						8	0	0	0
						9	0	0	0
						10	0	0	0
						11	0	0	0
						12	0	0	0
						13	0	0	0
						14	0	0	0
						15	0	0	0
						16	0	0	0
						17	0	0	0
						18	0	0	0
						19	0	0	0
						20	0	0	0
						21	0	0	0
						22	0	0	0
						23	1	1	1
						24	1	1	0
						25	0	0	0
						26	1	1	0
						27	1	1	0
						28	1	1	0
						29	1	1	0
						30	1	1	0
						31	1	1	0
						32	1	1	0
						33	1	1	0
						34	1	1	0
						35	1	1	0
						36	1	1	0
						37	1	1	0
						38	1	1	0
						39	1	1	0
						40	1	1	0
						41	1	1	0
						42	1	1	0
						43	1	1	0
						44	1	1	0
						45	0	0	0
						46	1	0	1
						47	1	0	0
						48	0	0	0

SPAT

	for my $i (0..1) { # Loop over 0 input version
		my $dir = $self->outdir();
		my $ext = $self->extension();
		my $mn = $self->mname();
		my $content = $inputversion;
		if ($i) {
			$dir = $self->outdir_cm();
			$ext = $self->extension_cm();
			$content = $dbgversion;
		}
		
		my $fn = $dir.$mn."_".$self->filename() .$ext;
		open($out, ">", $fn ) or die "Can't open $fn: $!";
		print "\e[K \r";
		print "Writing $fn...\r";
		print $out $content;
		#print "..done!\n";
		close ($out);
	}
}
1;
