#include <GTXCharData.hpp>
#include <GTXDoubleData.hpp>
#include <GTXVariableFormat.hpp>
#include <GTXError.hpp>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "utils.hpp"
#define GTX_STUDY "GTXserver_Tests"
#define GTX_DIR2D "write2D"
#define GTX_DIR3D "write3D"
#define GTX_GRID_FILE "grid"
#define GTX_POINTS_FILE "points"
#define GTX_LINES_FILE "lines"
#define GTX_HPOINTS_FILE "lines_header"
#define GTX_VARIABLE "variable"
#define GTX_AVARIABLE "avariable"
#define GTX_MACRO "macro[xxxxx]"
#define GTX_MACRO_SEL "macro_hole_sel[xxxxx]"
#define GTX_LID_VARIABLE "HoleId"
#define DEFAULT_GTX_SERVERNAME "localhost"
#define MAX_HOSTNAME_LEN 1024
#define MAX_PATH_LEN 1024
#ifdef winnt
#define GTX_STUDY_PATH "C:\\" GTX_STUDY
#else
#define GTX_STUDY_PATH "/tmp/" GTX_STUDY
#endif
const char *GTXvar_types[] =
{
"Float",
"Character",
"X gravity center",
"Y gravity center",
"Z gravity center",
"Macro"
};
static void st_usage(char *exe_name,
int help)
{
(void)printf("Usage: %s [-help] [-host hostname] [-port port_number]\n",
exe_name);
(void)printf(" [-path data_path]");
if (help)
{
(void)printf(" -help : Print this message.\n");
(void)printf(" -debug : Print client/server messages.\n");
(void)printf(" -host hostname : Server's hostname.\n");
(void)printf(" -port port_number : Port used between client and server\n");
(void)printf(" -path data_path : Initialize connection with given data_path.\n");
(void)printf("The default is to run a new server on a random port.");
(void)printf("If -host or -port is specified, a server must have been started first on the given host/port");
}
}
const char *item)
{
int i;
return(1);
return(0);
}
static int st_create_grid(int dimension)
{
int nsample,nx,ny,nz,error;
double *array;
int i,j,nb_list;
int selection_ind[3] = {1,12,50};
error = 1;
array = NULL;
nb_list = 0;
nx = 20;
ny = 15;
nz = (dimension == 3)? 30: 1;
nsample = nx*ny*nz;
if (st_is_in_list( &list, GTX_GRID_FILE))
{
}
if (dimension == 3)
1., 2., 3.,
4., 5., 6.,
nx, ny, nz);
else
1., 2.,
4., 5.,
nx, ny);
array = (double*)malloc(nsample*sizeof(double));
if (array == NULL)
for (i = 0; i < nsample; i++)
array[i] = (double)(rand() % 1000);
delete doubledata;
for (i = 0; i<3; i++)
{
for (j = 0; j<nsample;j++)
array[j] = selection_ind[i]*1000 + (rand()%1000);
delete doubledata;
}
error = 0;
if (array) free(array);
return(error);
}
static int st_create_points(int dimension)
{
int nsample,error;
double *x,*y,*z, *array;
int i,nb_list;
error = 1;
x = y = z = array = NULL;
nb_list = 0;
nsample = 50;
x = (double*)malloc(sizeof(double)*nsample);
y = (double*)malloc(sizeof(double)*nsample);
if (dimension == 3)
z = (double*)malloc(sizeof(double)*nsample);
array = (double*)malloc(sizeof(double)*nsample);
for (i = 0; i < nsample; i++)
{
x[i] = (double)((rand() % 3500) - 1000);
y[i] = (double)((rand() % 3500) + 2000);
if (z)
z[i] = (double)((rand() % 9000) + 3000);
array[i] = (double)(rand() % 1000);
}
if (st_is_in_list( &list, GTX_POINTS_FILE))
{
}
if (dimension ==2)
else
if (dimension ==2)
else
delete doubledata;
error = 0;
if (x) free(x);
if (y) free(y);
if (z) free(z);
if (array) free(array);
return(error);
}
static int st_create_lines(int dimension)
{
int error;
double *xhead,*yhead,*zhead;
double *x,*y,*z, *array;
unsigned char *sel_array;
char **hole_id;
int i,j,k,ind,nb_list;
int nlines = 3;
int nsample[3] = {5,10,20};
int max_nsample, total_nsample;
int selection_ind[3] = {1,2,3};
error = 1;
x = y = z = array = NULL;
xhead = yhead = zhead = NULL;
hole_id = NULL;
nb_list = 0;
max_nsample = 0;
total_nsample = 0;
for (i = 0; i < nlines; i++)
{
total_nsample += nsample[i];
if (nsample[i] > max_nsample)
max_nsample = nsample[i];
}
xhead = (double*)malloc(sizeof(double)*nlines);
yhead = (double*)malloc(sizeof(double)*nlines);
if (dimension == 3)
zhead = (double*)malloc(sizeof(double)*nlines);
x = (double*)malloc(sizeof(double)*max_nsample);
y = (double*)malloc(sizeof(double)*max_nsample);
if (dimension == 3)
z = (double*)malloc(sizeof(double)*max_nsample);
array = (double*)malloc(sizeof(double)*max_nsample);
sel_array = (unsigned char*)malloc(sizeof(unsigned char)*total_nsample);
hole_id = (char**)malloc(sizeof(char*)*nlines);
for (i = 0; i < nlines; i++)
hole_id[i] = (char*)malloc(sizeof(char)*7);
for (i = 0; i < nlines; i++)
{
xhead[i] = (double)((rand() % 3500) - 1000);
yhead[i] = (double)((rand() % 1000) + 4500);
if (zhead)
zhead[i] = (double)((rand() % 1000) + 11000);
(void)sprintf(hole_id[i], "Hole %d", i+1);
}
if (st_is_in_list( &list, GTX_HPOINTS_FILE))
{
}
if (dimension ==2)
else
delete chardata;
if (st_is_in_list( &list, GTX_LINES_FILE))
{
}
for (i = 0; i < nlines; i++)
{
for (j = 0; j < nsample[i]; j++)
{
x[j] = xhead[i];
if (dimension == 2)
y[j] = ((j == 0)? yhead[i]: y[j-1])- (double)(rand() % 250);
else
{
y[j] = yhead[i];
z[j] = ((j == 0)? zhead[i]: z[j-1]) - (double)(rand() % 900);
}
}
if (dimension == 2)
nsample[i], xhead[i], yhead[i], x, y);
else
nsample[i], xhead[i], yhead[i], (zhead != NULL)? zhead[i]: 0.,
x, y, z);
}
for (i = 0; i < nlines; i++)
{
for (j = 0; j < nsample[i]; j++)
array[j] = (rand() % 1000) / 1000.;
delete doubledata;
}
{
}
for (i = 0; i < nlines; i++)
{
char tmp[10];
for (j = 0; j < nsample[i]; j++)
{
sprintf(tmp, "%d_%d", i+1, j+1);
}
}
{
}
for (ind = 0; ind < nlines; ind++)
{
for (i = 0, k = 0; i < nlines; i++)
{
for (j = 0; j < nsample[i]; j++, k++)
sel_array[k] = (ind == i);
}
}
error = 0;
if (xhead) free(xhead);
if (yhead) free(yhead);
if (zhead) free(zhead);
if (hole_id)
{
for (i = 0; i < nlines; i++)
if (hole_id[i]) free(hole_id[i]);
free(hole_id);
}
if (x) free(x);
if (y) free(y);
if (z) free(z);
if (array) free(array);
if (sel_array) free(sel_array);
return(error);
}
int main(int argc,
char *argv[])
{
int dim,error;
const char *dir;
char **vars = NULL;
int *indices = NULL;
error = 1;
Arguments args;
args.ParseCommandLine(argc, argv);
try
{
if (args.run_server)
{
args.port = 0;
}
client->
Connect(args.host, args.port, args.data_path);
if(!st_is_in_list( &list, GTX_STUDY))
client->
NewStudy(GTX_STUDY, GTX_STUDY_PATH);
for (dim = 2; dim <= 3; dim++)
{
dir = (dim == 2)? GTX_DIR2D: GTX_DIR3D;
if (!st_is_in_list( &list, dir))
st_create_grid(dim);
st_create_points(dim);
st_create_lines(dim);
}
error = 0;
}
{
}
return(error);
}