source: CIVL/examples/compare/provesa/driver_sw.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/***
2 * IMPORTANT: Change the values of the variables marked by 'CHANGEME'
3 ***/
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <math.h>
8
9#ifdef _CIVL
10$input double global_x[6];
11$output int global_retval;
12$output double global_f;
13$output double global_grad[6];
14#else
15//#pragma CIVL input
16double global_x[6];
17//#pragma CIVL output
18int global_retval;
19//#pragma CIVL output
20double global_f;
21//#pragma CIVL output
22double global_grad[6];
23#endif
24
25int g_fcn(double *obj, double g_x[6], const double x[6]);
26
27int main(void) {
28 double x[6],obj,gradient[6];
29 int retval;
30 int i;
31
32 #ifndef _CIVL
33// for (i=0;i<6;i++) global_x[i] = pow(i,0.6);
34 FILE* f1 = fopen("x.in", "r");
35 double in = 0;
36 i = 0;
37 while( fscanf(f1, "%lf,", &in) > 0 ) // parse %d followed by ','
38 {
39 global_x[i++] = in;
40 }
41 fclose(f1);
42
43 #endif
44// printf("==================== INPUT STARTS HERE ====================\n");
45// for (i=0;i<6;i++) printf("global_x[%d] = %f\n", i, global_x[i]);
46// printf("==================== INPUT ENDS HERE ====================\n");
47 for (i=0;i<6;i++) x[i] = global_x[i];
48// Flip second and third vertices if determinant is negative
49 if ((x[1]-x[0])*(x[5]-x[3])-(x[4]-x[3])*(x[2]-x[0]) < 0.0)
50 {
51 obj = x[1];
52 x[1] = x[2];
53 x[2] = obj;
54 obj = x[4];
55 x[4] = x[5];
56 x[5] = obj;
57 }
58
59 retval = g_fcn(&obj,gradient,x);
60 global_retval = retval;
61 #ifdef _CIVL
62// printf("==================== RESULT STARTS HERE ====================\n");
63 #endif
64// printf("global_retval=%d\n", retval);
65 global_f = obj;
66 //printf("global_f=%f\n", obj);
67 for (i=0;i<6;i++) global_grad[i] = gradient[i];
68
69 FILE* f2 = fopen("g.out", "w");
70 fprintf(f2, "%d\n", retval);
71 for (i=0;i<6;i++) fprintf(f2, "%.17g\n", gradient[i]);
72 fclose(f2);
73
74// for (i=0;i<6;i++) printf("global_grad[%d]=%f\n", i, gradient[i]);
75 #ifdef _CIVL
76// printf("==================== RESULT ENDS HERE ====================\n");
77 #endif
78 return 0;
79}
Note: See TracBrowser for help on using the repository browser.