int sci_sym_solve(char *fname, unsigned long fname_len){
	
	int status=0; 
  
	//check whether we have no input and one output argument or not
	CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument
	CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument

	// Check environment
	if(global_sym_env==NULL)
		sciprint("Error: Symphony environment is not initialized.\n");
	else {// There is an environment opened
		double time_limit = -1.0;
		status = sym_get_dbl_param(global_sym_env,"time_limit",&time_limit);

		if (status == FUNCTION_TERMINATED_NORMALLY) {
			if ( time_limit < 0.0 )
				sciprint("\nNote: There is no limit on time.\n");
			else sciprint("\nNote: Time limit has been set to %lf.\n",time_limit);
			status=process_ret_val(sym_solve(global_sym_env));// Call function	
			}
		else {
			sciprint("\nUnable to read time limit.\n");
			status = 1; //Error state
			}
		}
	// Return result to scilab
	return returnDoubleToScilab(status);
	}
/* Function that initializes the symphony environment
 * Returns 1 on success , 0 on failure
 */
int sci_sym_open(char *fname, unsigned long fname_len){

	// Error management variable
	SciErr sciErr;
	double status=0;
	
	//check whether we have no input and one output argument or not
	CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument
	CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument

	//check environment
	if(global_sym_env!=NULL){
		sciprint("Warning: Symphony environment is already initialized.\n");
	}else{
		global_sym_env = sym_open_environment();//open an environment
		if (!global_sym_env)
			sciprint("Error: Unable to create symphony environment.\n");
		else{
			status=1;
			//sciprint("Symphony environment is created successfully. Please run 'sym_close()' to close.\n");
			//create useful variables for user
			createNamedScalarDouble(pvApiCtx,"sym_minimize",1);
			createNamedScalarDouble(pvApiCtx,"sym_maximize",-1);
		}
	}

	/*write satus of function (success-1 or failure-0) as output argument to scilab*/
	if(returnDoubleToScilab(status))
		return 1;
	
	return 0;
}
int sci_sym_getObjSense(char *fname){
	
	//error management variable
	SciErr sciErr;
	int iRet;
	
	//data declarations
	int objSense;
	
	//ensure that environment is active
	if(global_sym_env==NULL){
		sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
		return 1;
	}
	
	//code to check arguments and get them
	CheckInputArgument(pvApiCtx,0,0) ;
	CheckOutputArgument(pvApiCtx,1,1) ;
	
	//code to give output
	iRet=sym_get_obj_sense(global_sym_env,&objSense);
	if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
		Scierror(999, "An error occured. Has a problem been loaded?\n");
		return 1;
	}
	if(objSense==1)
		sciprint("Symphony has been set to minimize the objective.\n");
	else
		sciprint("Symphony has been set to maximize the objective.\n");

	if(returnDoubleToScilab(objSense))
		return 1;
	
	return 0;
}
/*Function that closes symphony environment
 * Returns 1 on success , 0 on failure
*/
int sci_sym_close(char *fname, unsigned long fname_len){
	
	// Error management variable
	SciErr sciErr;
	double status=0;
	int output;//output parameter for closing the environment
    

  	//check whether we have no input and one output argument or not
	CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument
	CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument

	if (global_sym_env==NULL){//check for environment
		sciprint("Error: symphony environment is not initialized.\n");
	}else{
		output=sym_close_environment(global_sym_env);//close environment
		if(output==ERROR__USER){	
			status=0;//User error detected in user_free_master() function or when function invoked unsuccessfully
			sciprint("Error in user_free_master()\n");
		}else if(output==FUNCTION_TERMINATED_ABNORMALLY){
			status=0;//function invoked unsuccessfully
			sciprint("Symphony environment could not be closed.\n");
		}else if(output==FUNCTION_TERMINATED_NORMALLY){			
			status=1;//function invoked successfully and no error
			global_sym_env=NULL;//important to set to NULL, so that other functions can detect that environment is not open.
			//sciprint("Symphony environement closed successfully. Please run 'sym_open()' to restart.\n");
			//delete the sym_ variables
			deleteNamedVariable(pvApiCtx,"sym_minimize");
			deleteNamedVariable(pvApiCtx,"sym_maximize");
		}
	}

	/*write satus of function (success-1 or failure-0) as output argument to scilab*/
	if(returnDoubleToScilab(status))
		return 1;
	
	return 0;	
}