This repository has been archived by the owner on Aug 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
94 lines (75 loc) · 1.7 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdlib.h>
#include <stdio.h>
#include "gmomcc.h"
#include "gevmcc.h"
#include "gamsse.h"
int main(
int argc,
char** argv
)
{
char buffer[GMS_SSSIZE];
gmoHandle_t gmo;
gevHandle_t gev;
gamsse_t* se = NULL;
int rc = EXIT_FAILURE;
if( argc < 2 )
{
printf("usage: %s <cntrlfile> [<optfile>]\n", argv[0]);
return 1;
}
/* create GMO and GEV handles */
if( !gmoCreate(&gmo, buffer, sizeof(buffer)) || !gevCreate(&gev, buffer, sizeof(buffer)) )
{
fprintf(stderr, "%s\n", buffer);
goto TERMINATE;
}
/* load GAMS control file */
if( gevInitEnvironmentLegacy(gev, argv[1]) )
{
fprintf(stderr, "Could not load control file %s\n", argv[1]);
goto TERMINATE;
}
/* let gmo know about gev */
if( gmoRegisterEnvironment(gmo, gev, buffer) )
{
fprintf(stderr, "Error registering GAMS Environment: %s\n", buffer);
goto TERMINATE;
}
/* load instance data */
if( gmoLoadDataLegacy(gmo, buffer) )
{
fprintf(stderr, "Could not load model data.\n");
goto TERMINATE;
}
se_Initialize();
se_Create(&se, buffer, sizeof(buffer));
if( se == NULL )
{
fprintf(stderr, buffer);
goto TERMINATE;
}
/* overwrite option file setting in GMO */
if( argc >= 3 )
{
gmoOptFileSet(gmo, 1);
gmoNameOptFileSet(gmo, argv[2]);
}
if( se_CallSolver(se, gmo) != 0 )
goto TERMINATE;
rc = EXIT_SUCCESS;
TERMINATE:
if( se != NULL )
se_Free(&se);
se_Finalize();
if( gmo != NULL )
{
gmoUnloadSolutionLegacy(gmo);
gmoFree(&gmo);
}
if( gev != NULL )
gevFree(&gev);
gmoLibraryUnload();
gevLibraryUnload();
return rc;
}