00001
00002
00003
00004
00005
00006
00007
00008
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 int u, i, j, k, nx, ny, nz;
00021 double avg;
00022 double hy, hx, hzed, xmin, ymin, zmin;
00023 Vio *sock;
00024 Vgrid *grid;
00025 char *inpath = VNULL;
00026 char *outpath = VNULL;
00027 char *iodev = "FILE";
00028 char *iofmt = "ASC";
00029 char *thost = VNULL;
00030 char *title = "dx2uhbd conversion";
00031 char *usage = "\n\n\
00032 -----------------------------------------------------------------------\n\
00033 Converts the OpenDX format of the electrostatic potential \n\
00034 to the UHBD format.\n\n\
00035 Usage: dx2uhbd file1.dx file2.grd\n\n\
00036 where file1.dx is a file in OpenDX format and file2.grd is the\n\
00037 file to be written in UHBD format.\n\
00038 -----------------------------------------------------------------------\n\
00039 \n";
00040
00041
00042
00043 Vio_start();
00044 if (argc != 3) {
00045 Vnm_print(2, "\n*** Syntax error: got %d arguments, expected 2.\n\n",
00046 argc-1);
00047 Vnm_print(2,"%s\n", usage);
00048 return -1;
00049 } else {
00050 inpath = argv[1];
00051 outpath = argv[2];
00052 }
00053
00054
00055 grid = Vgrid_ctor(0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, VNULL);
00056 Vnm_tprint(1, "Reading DX file ... \n");
00057 if(Vgrid_readDX(grid, "FILE", "ASC", VNULL, inpath) != 1) {
00058 Vnm_tprint( 2, "Fatal error while reading from %s\n",
00059 inpath);
00060 return 0;
00061 }
00062 nx = grid->nx;
00063 ny = grid->ny;
00064 nz = grid->nz;
00065 hx = grid->hx;
00066 hy = grid->hy;
00067 hzed = grid->hzed;
00068 xmin = grid->xmin;
00069 ymin = grid->ymin;
00070 zmin = grid->zmin;
00071 Vnm_tprint(1, " %d x %d x %d grid\n", nx, ny, nz);
00072 Vnm_tprint(1, " (%g, %g, %g) A spacings\n", hx, hy, hzed);
00073 Vnm_tprint(1, " (%g, %g, %g) A lower corner\n",
00074 xmin, ymin, zmin);
00075
00076
00077
00078
00079 sock = Vio_ctor(iodev,iofmt,thost, outpath, "w");
00080 if (sock == VNULL) {
00081 Vnm_print(2, "Problem opening virtual socket %s\n",
00082 outpath);
00083 return -1;
00084 }
00085 if (Vio_connect(sock, 0) < 0) {
00086 Vnm_print(2, "Problem connecting virtual socket %s\n",
00087 outpath);
00088 return -1;
00089 }
00090
00091
00092
00093
00094 Vnm_tprint(1, "Writting UHBD file ... \n");
00095
00096 Vgrid_writeUHBD(grid, "FILE", "ASC", VNULL, outpath, title,
00097 grid->data);
00098 Vgrid_dtor(&grid);
00099
00100
00101
00102 Vio_connectFree(sock);
00103 Vio_dtor(&sock);
00104
00105 return 0;
00106 }