GRASS Programmer's Manual
6.4.2(2012)
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
delnode.c
Go to the documentation of this file.
1
/* LIBDGL -- a Directed Graph Library implementation
2
* Copyright (C) 2002 Roberto Micarelli
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
*/
18
19
/*
20
* Source best viewed with tabstop=4
21
*/
22
23
#include <stdio.h>
24
#include <sys/types.h>
25
#include <sys/stat.h>
26
#include <unistd.h>
27
#include <stdlib.h>
28
#include <fcntl.h>
29
#include <time.h>
30
#include <errno.h>
31
#include <math.h>
32
33
#include "../type.h"
34
#include "../graph.h"
35
36
#include "
opt.h
"
37
38
int
main
(
int
argc,
char
**argv)
39
{
40
dglGraph_s
graph;
41
dglInt32_t
nNode;
42
int
nret, fd;
43
44
/* program options
45
*/
46
char
*pszGraph;
47
char
*pszGraphOut;
48
char
*pszNode;
49
50
GNO_BEGIN
/* short long default variable help */
51
GNO_OPTION
(
"g"
,
"graph"
,
NULL
, &pszGraph,
"Input Graph file"
)
52
GNO_OPTION
(
"o"
,
"graphout"
,
NULL
, &pszGraphOut,
"Output Graph file"
)
53
GNO_OPTION
(
"n"
,
"node"
,
NULL
, &pszNode,
"Node Id to cancel"
)
54
GNO_END
if
(
GNO_PARSE
(argc, argv) < 0)
55
{
56
return
1;
57
}
58
/*
59
* options parsed
60
*/
61
62
if
(pszNode ==
NULL
) {
63
GNO_HELP
(
"delnode usage"
);
64
return
1;
65
}
66
nNode = atol(pszNode);
67
68
printf(
"Graph read:\n"
);
69
if
((fd = open(pszGraph, O_RDONLY)) < 0) {
70
perror(
"open"
);
71
return
1;
72
}
73
nret =
dglRead
(&graph, fd);
74
if
(nret < 0) {
75
fprintf(stderr,
"dglRead error: %s\n"
,
dglStrerror
(&graph));
76
return
1;
77
}
78
close(fd);
79
printf(
"Done.\n"
);
80
81
printf(
"Graph unflatten:\n"
);
82
nret =
dglUnflatten
(&graph);
83
if
(nret < 0) {
84
fprintf(stderr,
"dglUnflatten error: %s\n"
,
dglStrerror
(&graph));
85
return
1;
86
}
87
printf(
"Done.\n"
);
88
89
nret =
dglDelNode
(&graph, nNode);
90
if
(nret < 0) {
91
fprintf(stderr,
"dglDelNode error: %s\n"
,
dglStrerror
(&graph));
92
return
1;
93
}
94
95
printf(
"Graph flatten:\n"
);
96
nret =
dglFlatten
(&graph);
97
printf(
"Done.\n"
);
98
99
if
(pszGraphOut) {
100
printf(
"Graph write: %s\n"
, pszGraphOut);
101
if
((fd = open(pszGraphOut, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
102
perror(
"open"
);
103
return
1;
104
}
105
nret =
dglWrite
(&graph, fd);
106
if
(nret < 0) {
107
fprintf(stderr,
"dglWrite error: %s\n"
,
dglStrerror
(&graph));
108
return
1;
109
}
110
close(fd);
111
printf(
"Done.\n"
);
112
}
113
114
dglRelease
(&graph);
115
return
0;
116
}
lib
vector
dglib
examples
delnode.c
Generated on Sun Sep 9 2012 18:55:31 for GRASS Programmer's Manual by
1.8.1.2