#include <stdlib.h>
#include "stack-c.h"
#include "api_scilab.h"
#include "Scierror.h"
#include "sciprint.h"

#include "Correction.h"
#include "Erreur.h"


/*****************************************************
 * SCILAB function : MakeElevConsistentWithFlowDir   *
 *****************************************************/

/*int gtw_MakeElevConsistentWithFlowDir ( char * fname )
{
    int m,n,l;
    int HandleFlowDir,HandleRaster,root;

    CheckRhs(3,3);
    CheckLhs(0,1);
    
    // Variable HandleRaster

    GetRhsVar(1,"i",&m,&n,&l);
    CheckScalar(1,m,n);
    HandleRaster = *istk(l);

    // Variable HandleFlowDir

    GetRhsVar(2,"i",&m,&n,&l);
    CheckScalar(2,m,n);
    HandleFlowDir = *istk(l);

    // Variable root

    GetRhsVar(3,"i",&m,&n,&l);
    CheckScalar(3,m,n);
    root = *istk(l);

    // Appel a l'API

    if ( MakeElevConsistentWithFlowDir ( HandleRaster ,
										 HandleFlowDir ,
										 root) )
        Scierror (999, GetErreur());

    return(0);
}*/

/*****************************************************
 * SCILAB function : MakeElevConsistentWithFlowDir   *
 *****************************************************/
 
int gtw_RaiseStreamNetwork ( char * fname )
{
    int m,n,l;
    int HandleRaster;
	double slope;
	char * FichGeom , * FichLinks , * FichNodes ;
	char strFichGeom[120], strFichLinks[120], strFichNodes[120] ;

    CheckRhs(5,5);
    CheckLhs(0,1);
    
	// Variable FichGeom
	
	GetRhsVar(1,"c",&m,&n,&l);
	FichGeom = cstk(l);

	// Variable FichLinks
	
	GetRhsVar(2,"c",&m,&n,&l);
	FichLinks = cstk(l);

	// Variable FichNodes
	
	GetRhsVar(3,"c",&m,&n,&l);
	FichNodes = cstk(l);
	
    // Variable HandleRaster

    GetRhsVar(4,"i",&m,&n,&l);
    CheckScalar(4,m,n);
    HandleRaster = *istk(l);

    // Variable slope

    GetRhsVar(5,"d",&m,&n,&l);
    CheckScalar(5,m,n);
    slope = *stk(l);

	// Protection des chaines de caractères
	
	strncpy(strFichGeom, FichGeom, 120);
	strncpy(strFichLinks, FichLinks, 120);
	strncpy(strFichNodes, FichNodes, 120);
			
	if ( RaiseStreamNetwork ( strFichGeom , strFichLinks , strFichNodes , HandleRaster , slope ) )
		Scierror (999, GetErreur());

	return(0);
}	

