Work in progress

compiles with warnings, definitely not working
This commit is contained in:
Michael Tryby
2019-04-12 18:00:36 -04:00
parent 8989be193a
commit 880bdfffba
4 changed files with 171 additions and 53 deletions

View File

@@ -83,8 +83,8 @@ ENDIF (MSVC)
# configure file groups # configure file groups
file(GLOB EPANET_SOURCES RELATIVE ${PROJECT_SOURCE_DIR} src/*.c) file(GLOB EPANET_SOURCES RELATIVE ${PROJECT_SOURCE_DIR} src/*.c src/util/list.c)
file(GLOB EPANET_LIB_ALL RELATIVE ${PROJECT_SOURCE_DIR} src/*) file(GLOB EPANET_LIB_ALL RELATIVE ${PROJECT_SOURCE_DIR} src/* src/util/list.*)
# exclude epanet python API from the default build # exclude epanet python API from the default build
list(REMOVE_ITEM EPANET_LIB_ALL "src/epanet_py.c") list(REMOVE_ITEM EPANET_LIB_ALL "src/epanet_py.c")
source_group("Library" FILES ${EPANET_LIB_ALL}) source_group("Library" FILES ${EPANET_LIB_ALL})

72
src/demand.c Normal file
View File

@@ -0,0 +1,72 @@
/*
******************************************************************************
Project: OWA EPANET
Version: 2.2
Module: demand.c
Description: demand pattern list
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 04/12/2019
******************************************************************************
*/
#include <stdlib.h>
#include <string.h>
#include "demand.h"
typedef struct demand_data_s
{
double base_demand;
int pattern_index;
char *category_name;
} demand_data_t;
demand_data_t *create_demand_data(double base_demand, int pat_index, char *cat_name)
{
demand_data_t *demand_data = (demand_data_t *)malloc(sizeof(demand_data_t));
demand_data->base_demand = base_demand;
demand_data->pattern_index = pat_index;
if (cat_name)
demand_data->category_name = strdup(cat_name);
else
demand_data->category_name = NULL;
return demand_data;
}
void delete_demand_data(void *data)
{
demand_data_t *demand_data = *(demand_data_t **)data;
if (demand_data->category_name)
free(demand_data->category_name);
free(demand_data);
}
demand_data_t *get_demand_data(list_node_t *lnode)
{
return *(demand_data_t **)get_data(lnode);
}
double get_base_demand(demand_data_t *data)
{
return data->base_demand;
}
int get_pattern_index(demand_data_t *data)
{
return data->pattern_index;
}
char *get_category_name(demand_data_t *data)
{
return data->category_name;
}

42
src/demand.h Normal file
View File

@@ -0,0 +1,42 @@
/*
******************************************************************************
Project: OWA EPANET
Version: 2.2
Module: demand.h
Description: demand pattern list
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 04/12/2019
******************************************************************************
*/
#ifndef DEMAND_H
#define DEMAND_H
#include "util/list.h"
// Forward declarations
typedef struct demand_data_s demand_data_t;
// demand list gets declared in types.h typedef struct Snode
extern list_t *p_demand_list;
demand_data_t *create_demand_data(double base_demand, int pat_index, char *cat_name);
void delete_demand_data(void *data);
demand_data_t *get_demand_data(list_node_t *lnode);
double get_base_demand(demand_data_t *data);
int get_pattern_index(demand_data_t *data);
char *get_category_name(demand_data_t *data);
#endif /* DEMAND_H */

View File

@@ -14,9 +14,12 @@
#ifndef TYPES_H #ifndef TYPES_H
#define TYPES_H #define TYPES_H
#include "hash.h"
#include <stdio.h> #include <stdio.h>
#include "hash.h"
#include "util/list.h"
/* /*
------------------------------------------- -------------------------------------------
Definition of 4-byte integers & reals Definition of 4-byte integers & reals
@@ -370,7 +373,8 @@ typedef struct // Node Object
double X; // x-coordinate double X; // x-coordinate
double Y; // y-coordinate double Y; // y-coordinate
double El; // elevation double El; // elevation
Pdemand D; // demand pointer // Pdemand D; // demand pointer
list_t *D; // pointer to demand list
Psource S; // source pointer Psource S; // source pointer
double C0; // initial quality double C0; // initial quality
double Ke; // emitter coeff. double Ke; // emitter coeff.