#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#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
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");
}
}
static int st_is_in_list(int nlist,
char **list,
char *item)
{
int i;
for (i = 0; i < nlist; i++)
if (!strcmp(list[i], item))
return(1);
return(0);
}
static int st_create_grid(int dimension)
{
int nsample,nx,ny,nz,error;
double *array;
char **list;
int i,j,nb_list;
int selection_ind[3] = {1,12,50};
error = 1;
array = NULL;
nb_list = 0;
list = NULL;
nx = 20;
ny = 15;
nz = (dimension == 3)? 30: 1;
nsample = nx*ny*nz;
goto label_end;
if (st_is_in_list(nb_list, list, GTX_GRID_FILE) &&
goto label_end;
1., 2., 3.,
4., 5., 6.,
nx, ny, nz))
goto label_end;
goto label_end;
goto label_end;
goto label_end;
goto label_end;
goto label_end;
goto label_end;
array = (double*)malloc(nsample*sizeof(double));
if (array == NULL) goto label_end;
for (i = 0; i < nsample; i++)
array[i] = (double)(rand() % 1000);
goto label_end;
goto label_end;
goto label_end;
goto label_end;
for (i = 0; i<3; i++)
{
goto label_end;
for (j = 0; j<nsample;j++)
array[j] = selection_ind[i]*1000 + (rand()%1000);
goto label_end;
}
error = 0;
label_end:
if (array) free(array);
return(error);
}
static int st_create_points(int dimension)
{
int nsample,error;
double *x,*y,*z, *array;
char **list;
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);
if (x == NULL || y == NULL || array == NULL) goto label_end;
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);
}
goto label_end;
if (st_is_in_list(nb_list, list, GTX_POINTS_FILE) &&
goto label_end;
goto label_end;
goto label_end;
goto label_end;
goto label_end;
10, 2, " "))
goto label_end;
goto label_end;
goto label_end;
error = 0;
label_end:
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,test_val;
unsigned char *sel_array, *sel_array_client;
char **hole_id,**list;
int i,j,k,ind,nb_list;
int nlines = 3;
int nsample[3] = {5,10,20};
int max_nsample, total_nsample;
gtx_long retval_nbsample;
int selection_ind[3] = {1,2,3};
double *ret_data;
int ret_nsample;
error = 1;
x = y = z = array = NULL;
xhead = yhead = zhead = NULL;
hole_id = NULL;
nb_list = 0;
max_nsample = 0;
total_nsample = 0;
ret_data = NULL;
sel_array = NULL;
sel_array_client = NULL;
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);
if (x == NULL || y == NULL || array == NULL) goto label_end;
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);
}
goto label_end;
if (st_is_in_list(nb_list, list, GTX_HPOINTS_FILE) &&
goto label_end;
goto label_end;
(const char * const *)hole_id))
goto label_end;
if (st_is_in_list(nb_list, list, GTX_LINES_FILE) &&
goto label_end;
goto label_end;
goto label_end;
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);
}
}
nsample[i], xhead[i], yhead[i], (zhead != NULL)? zhead[i]: 0.,
x, y, z))
goto label_end;
}
goto label_end;
10, 6, " "))
goto label_end;
goto label_end;
for (i = 0; i < nlines; i++)
{
for (k = 0; k < nsample[i]; k++)
array[k] = (rand() % 1000) / 1000.;
goto label_end;
}
goto label_end;
{
goto label_end;
}
goto label_end;
goto label_end;
for (i = 0; i < nlines; i++)
{
char **carray = NULL;
carray = (char**)malloc(sizeof(char*)*nsample[i]);
if (carray == NULL)
goto label_end;
for (k = 0; k < nsample[i]; k++)
carray[k] = NULL;
for (k = 0; k < nsample[i]; k++)
{
carray[k] = (char*)malloc(sizeof(char)*10);
if (carray[k] == NULL) goto label_end;
sprintf(carray[k], "%d_%d", i+1, k+1);
}
(const char * const *)carray))
goto label_end;
for (k = 0; k < nsample[i]; k++)
free(carray[k]);
free(carray);
}
goto label_end;
{
char **cret_data = NULL;
char *ctest_val = NULL;
goto label_end;
}
goto label_end;
goto label_end;
goto label_end;
for (ind = 0; ind < nlines; ind++)
{
goto label_end;
for (i = 0, k = 0; i < nlines; i++)
{
for (j = 0; j < nsample[i]; j++, k++)
sel_array[k] = (ind == i);
}
goto label_end;
goto label_end;
}
goto label_end;
goto label_end;
goto label_end;
error = 0;
label_end:
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);
if (ret_data)
return(error);
}
int main(int argc,
char *argv[])
{
char *tmp_str, host[MAX_HOSTNAME_LEN];
unsigned short port;
int i,dim,error,run_server;
char data_path[MAX_PATH_LEN];
char *dir;
int nb_list = 0;
char **list = NULL;
char **vars = NULL;
int *indices = NULL;
error = 1;
run_server = 1;
(void)strcpy(host, DEFAULT_GTX_SERVERNAME);
(void)strcpy(data_path, "");
for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-port"))
{
i++;
if (i < argc)
{
run_server = 0;
port = (unsigned short)strtol(argv[i], &tmp_str, 10);
if (port == 0 && tmp_str == argv[i])
{
(void)fprintf(stderr,"Invalid Port Number.");
exit(1);
}
}
else
{
st_usage(argv[0], 0);
exit(1);
}
}
else if (!strcmp(argv[i], "-host"))
{
i++;
if (i<argc)
{
run_server = 0;
if (strlen(argv[i]) > MAX_HOSTNAME_LEN-1)
{
(void)fprintf(stderr,"Host Name must contain less than %d characters.",
MAX_HOSTNAME_LEN);
exit(1);
}
(void)strcpy(host, argv[i]);
}
else
{
st_usage(argv[0], 0);
exit(1);
}
}
else if (!strcmp(argv[i], "-path"))
{
i++;
if (i < argc)
{
if (strlen(argv[i]) > MAX_PATH_LEN-1)
{
(void)fprintf(stderr,"Path must contain less than %d characters.",
MAX_PATH_LEN);
exit(1);
}
(void)strcpy(data_path, argv[i]);
}
else
{
st_usage(argv[0], 0);
exit(1);
}
}
else if (!strcmp(argv[i], "-debug"))
else if (!strcmp(argv[i], "-help"))
{
st_usage(argv[0], 1);
exit(0);
}
}
goto label_end;
if (run_server)
{
port = 0;
goto label_end;
}
goto label_end;
goto label_end;
goto label_end;
if (!st_is_in_list(nb_list, list, GTX_STUDY) &&
goto label_end;
goto label_end;
for (dim = 2; dim <= 3; dim++)
{
dir = (dim == 2)? GTX_DIR2D: GTX_DIR3D;
goto label_end;
if (!st_is_in_list(nb_list, list, dir) &&
goto label_end;
goto label_end;
if (st_create_grid(dim)) goto label_end;
if (st_create_points(dim)) goto label_end;
if (st_create_lines(dim)) goto label_end;
}
error = 0;
label_end:
return(error);
}