• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

tools/mesh/dx2uhbd.c

00001 /* ///////////////////////////////////////////////////////////////////////////
00002 // File:     dx2uhbd.c
00003 //
00004 // Purpose:  Convert OpenDx format potential to UHBD format
00005 //
00006 // Author:   rok, based on dx2mol.c
00007 //
00008 // rcsid="$Id: dx2uhbd.c 1154 2007-10-08 20:20:27Z sobolevnrm $"
00010 
00011 #include "apbscfg.h"
00012 #include "maloc/maloc.h"
00013 #include "apbs/apbs.h"  
00014 
00015 VEMBED(rcsid="$Id: dx2uhbd.c 1154 2007-10-08 20:20:27Z sobolevnrm $")
00016 
00017 int main(int argc, char **argv) {
00018 
00019   /*** Variables ***/
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   /*** Check Invocation ***/
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   /*** Read DX format file ***/ 
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   /*** Intialize socket for writing ***/
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   /*** Write potential data in UHBD format ***/
00092   /*   sprintf(outpath, "%s.%s", writestem, "grd"); */
00093   
00094   Vnm_tprint(1, "Writting UHBD file ... \n");
00095   /* Vnm_tprint(1, "%s\n", outpath); */
00096   Vgrid_writeUHBD(grid, "FILE", "ASC", VNULL, outpath, title,
00097                         grid->data);
00098   Vgrid_dtor(&grid);
00099 
00100 
00101   /*** Close the socket ***/
00102   Vio_connectFree(sock);
00103   Vio_dtor(&sock);
00104 
00105   return 0;
00106 }

Generated on Wed Oct 20 2010 11:12:19 for APBS by  doxygen 1.7.2