00001
00054 #include "apbscfg.h"
00055 #include "apbs/apbs.h"
00056
00057 #define ERRRC 12
00058
00059 VEMBED(rcsid="$Id: benchmark.c 1552 2010-02-10 17:46:27Z yhuang01 $")
00060
00061 int main(int argc, char **argv) {
00062
00063
00064 int nx, ny, nz, i, j, k, itmp;
00065 double hy, hx, hzed, xmin, ymin, zmin, pt[3], value, sum, dtmp;
00066 int test_int = 44;
00067 double test_double = -37.56;
00068 double test_exp = 5555000.12;
00069 char *usage = "\n benchmark <asc|xdr> nx ny nz\n";
00070 char *iofmt;
00071 char test_string[VMAX_BUFSIZE];
00072 char tok[VMAX_BUFSIZE];
00073 char *MCwhiteChars = " =,;\t\n";
00074 char *MCcommChars = "#%";
00075 Vgrid *grid;
00076 Vio *sock;
00077
00078
00079 Vio_start();
00080 Vnm_redirect(0);
00081 if (argc != 5) {
00082 Vnm_print(2,"\n*** Syntax error: got %d arguments, expected 4.\n\n",
00083 argc);
00084 Vnm_print(2,"%s\n", usage);
00085 return ERRRC;
00086 }
00087 if (Vstring_strcasecmp(argv[1], "XDR") == 0) iofmt = "XDR";
00088 else if (Vstring_strcasecmp(argv[1], "ASC") == 0) iofmt = "ASC";
00089 else {
00090 Vnm_print(2, "Invalid format (%s)!\n", argv[1]);
00091 Vnm_print(2,"%s\n", usage);
00092 return ERRRC;
00093 }
00094 sscanf(argv[2], "%d", &nx);
00095 sscanf(argv[3], "%d", &ny);
00096 sscanf(argv[4], "%d", &nz);
00097 hx = 1;
00098 hy = 1;
00099 hzed = 1;
00100 xmin = 0;
00101 ymin = 0;
00102 zmin = 0;
00103
00104 Vnm_print(1, "Validating I/O for %s format...\n", iofmt);
00105 sock = Vio_ctor("FILE", iofmt, "localhost", "benchmark.test", "w");
00106 if (sock == VNULL) {
00107 Vnm_print(2, "Problem opening virtual socket!\n");
00108 return ERRRC;
00109 }
00110 if (Vio_connect(sock, 0) < 0) {
00111 Vnm_print(2, "Vgrid_readDX: Problem connecting virtual socket!\n");
00112 return ERRRC;
00113 }
00114 Vio_setWhiteChars(sock, MCwhiteChars);
00115 Vio_setCommChars(sock, MCcommChars);
00116 sprintf(test_string, "integer %d double %4.3f exponential %12.5e\n",
00117 test_int, test_double, test_exp);
00118 Vnm_print(1, "Writing '%s' to socket\n", test_string);
00119 Vio_printf(sock, "%s", test_string);
00120 Vio_connectFree(sock);
00121 Vio_dtor(&sock);
00122
00123 sock = Vio_ctor("FILE", iofmt, "localhost", "benchmark.test", "r");
00124 if (sock == VNULL) {
00125 Vnm_print(2, "Problem opening virtual socket!\n");
00126 return ERRRC;
00127 }
00128 if (Vio_accept(sock, 0) < 0) {
00129 Vnm_print(2, "Vgrid_readDX: Problem accepting virtual socket!\n");
00130 return ERRRC;
00131 }
00132 Vio_setWhiteChars(sock, MCwhiteChars);
00133 Vio_setCommChars(sock, MCcommChars);
00134 VASSERT(Vio_scanf(sock, "%s", tok) == 1);
00135 Vnm_print(1, "Read token '%s' from socket\n", tok);
00136 VASSERT(Vio_scanf(sock, "%s", tok) == 1);
00137 VASSERT(sscanf(tok, "%i", &itmp) == 1);
00138 Vnm_print(1, "Read integer '%d' from socket\n", itmp);
00139 VASSERT(itmp == test_int);
00140 VASSERT(Vio_scanf(sock, "%s", tok) == 1);
00141 Vnm_print(1, "Read token '%s' from socket\n", tok);
00142 VASSERT(Vio_scanf(sock, "%s", tok) == 1);
00143 VASSERT(sscanf(tok, "%lf", &dtmp) == 1);
00144 Vnm_print(1, "Read double '%lf' from socket\n", dtmp);
00145 VASSERT(dtmp == test_double);
00146 VASSERT(Vio_scanf(sock, "%s", tok) == 1);
00147 Vnm_print(1, "Read token '%s' from socket\n", tok);
00148 VASSERT(Vio_scanf(sock, "%s", tok) == 1);
00149 VASSERT(sscanf(tok, "%le", &dtmp) == 1);
00150 Vnm_print(1, "Read exponential '%le' from socket\n", dtmp);
00151 VASSERT(dtmp == test_exp);
00152 Vio_acceptFree(sock);
00153 Vio_dtor(&sock);
00154
00155 return 0;
00156
00157 }