#include<math.h>
#include<stdio.h>
#include <stdlib.h>
#include "settings.h"
#include "data.h"

/*****************************************************************************
  DumpList()
*****************************************************************************/
void DumpList( FILES *Out, int NSoil, int NVeg) 
{

  int i;			/* counter */
  int j;			/* counter */
  int col = 0;


  /* Aggegated values -  output is written in ExecDump() in DumpPix and below:

        DumpPix(Current, &(Dump->Aggregate), &(Total->Evap), &(Total->Precip),
          &(Total->RadClass), &(Total->Snow), &(Total->Soil), Soil->MaxLayers, 
          Veg->MaxLayers);
        fprintf(Dump->Aggregate.FilePtr, "%g %g %lu", 
           Total->MeanTair, Total->ChannelInt, Total->Saturated);
        fprintf(Dump->Aggregate.FilePtr, "\n");
  --------------------------------------------------------------------------*/

  col = 0;
  fprintf(Out->FilePtr, "#  Aggregated.Values -------------------\n");
  fprintf(Out->FilePtr, "Date/Time %d\n", col);
  col++;

  /* Evaporation */
  fprintf(Out->FilePtr, "ETot %d\n", col);
  col++;

  for (i = 0; i < NVeg+1; i++){
    fprintf(Out->FilePtr, "EPot%d %d\n", i, col);
    col++;
  }

  for (i = 0; i < NVeg+1; i++){
    fprintf(Out->FilePtr, "EAct%d %d\n", i, col);
    col++;
  }

  for (i = 0; i < NVeg; i++){
    fprintf(Out->FilePtr, "EInt%d %d\n", i, col);
    col++;
  }

  for (i = 0; i < NVeg; i++)
    for (j = 0; j < NSoil; j++){
      fprintf(Out->FilePtr, "ESoil%d_%d %d\n", i, j, col);
      col++;
    }

  fprintf(Out->FilePtr, "EvapSoil %d\n", col);
  col++;
  

  /*Precipitation */
  fprintf(Out->FilePtr, "Precip %d\n", col);
  col++;

  for (i = 0; i < NVeg; i++){
    fprintf(Out->FilePtr, "IntRain%d %d\n", i, col);
    col++;
  }

  for (i = 0; i < NVeg; i++){
    fprintf(Out->FilePtr, "IntSnow%d %d\n", i, col);
    col++;
  }

  /* Radiation */
  fprintf(Out->FilePtr, "RadBeam %d\n", col);
  col++;

  fprintf(Out->FilePtr, "RadDiffuse %d\n", col);
  col++;
  

  /* Snow */
  fprintf(Out->FilePtr, "HasSnow %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "SnowCoverOver %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "LastSnow %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "Swq %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "SnowMelt %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "PackWater %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "SnowTPack %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "SnowSurfWater %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "SnowTSurf %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "SnowColdContent %d\n", col);
  col++;
  

  /* Soil */
  for (i = 0; i < NSoil; i++){
    fprintf(Out->FilePtr, "SoilMoist%d %d\n", i, col);
    col++;
  }

  for (i = 0; i < NSoil; i++){
    fprintf(Out->FilePtr, "SoilPerc%d %d\n", i, col);
    col++;
  }

  fprintf(Out->FilePtr, "TableDepth %d\n", col);
  col++;

  fprintf(Out->FilePtr, "SatFlow %d\n", col);
  col++;

  fprintf(Out->FilePtr, "Runoff %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "SoilTSurf %d\n", col);
  col++;

  fprintf(Out->FilePtr, "SoilQnet %d\n", col);
  col++;

  fprintf(Out->FilePtr, "SoilQs %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "SoilQe %d\n", col);
  col++;
  
  fprintf(Out->FilePtr, "SoilQg %d\n", col);
  col++;

  fprintf(Out->FilePtr, "SoilQst %d\n", col);
  col++;

  fprintf(Out->FilePtr, "SoilRa %d\n", col);
  col++;

  fprintf(Out->FilePtr, "GwRecharge %d\n", col);
  col++;

  fprintf(Out->FilePtr, "QuickVol %d\n", col);
  col++;

  /* always written last */
  fprintf(Out->FilePtr, "MeanTair %d\n", col);
  col++;

  fprintf(Out->FilePtr, "ChannelInt %d\n", col);
  col++;

  fprintf(Out->FilePtr, "GwToChannel %d\n", col);
  col++;

  fprintf(Out->FilePtr, "FrozenSoilHeatFlux %d\n", col);
  col++;

  fprintf(Out->FilePtr, "NSaturated %d\n", col);
  col++;

  fclose(Out->FilePtr);
}
