Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

main.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2006 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: main.c,v $
00013  *      $Author: johns $       $Locker:  $             $State: Exp $
00014  *      $Revision: 1.12 $       $Date: 2006/01/05 00:05:53 $
00015  *
00016  ***************************************************************************/
00017 
00018 /*
00019  * A general main for testing plugins.  
00020  * Compile using: gcc main.c plugin.c -I../../include -o plugintest
00021  * Replace plugin.c with the plugin file you want to test.
00022  * Usage: plugintest <filetype> <file> 
00023  */
00024 
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #include "molfile_plugin.h"
00029 
00030 static molfile_plugin_t *plugin = 0;
00031 static const char *filetype = NULL;
00032 
00033 static int register_cb(void *v, vmdplugin_t *p) {
00034   if (!strcmp(p->type, MOLFILE_PLUGIN_TYPE) && !strcmp(p->name, filetype))
00035     plugin = (molfile_plugin_t *)p;
00036 
00037   return VMDPLUGIN_SUCCESS;
00038 }
00039 
00040 int main(int argc, char *argv[]) {
00041   const char *filename;
00042   int rc, natoms;
00043   molfile_timestep_t timestep;
00044   void *handle;
00045 
00046   if (argc < 3) {
00047     fprintf(stderr, "Usage: %s <filetype> <filename>\n", argv[0]);
00048     return 1;
00049   }
00050   filetype = argv[1];
00051   filename = argv[2];
00052  
00053   vmdplugin_init();
00054   vmdplugin_register(NULL, register_cb);
00055   if (!plugin) {
00056     fprintf(stderr, "No plugin for filetype %s was linked in!\n", filetype);
00057     return 1;
00058   }
00059   
00060   if (!plugin->open_file_read) {
00061     fprintf(stdout, "FAILED: No open_file_read found.\n");
00062     return 1;
00063   } 
00064   handle = plugin->open_file_read(filename, filetype, &natoms);
00065   if (!handle) {
00066     fprintf(stderr, "FAILED: open_file_read returned NULL\n");
00067     return 1;
00068   }
00069   printf("Opened file %s; found %d atoms\n", 
00070     filename, natoms);
00071   if (plugin->read_structure) {
00072     int optflags;
00073     molfile_atom_t *atoms;
00074     atoms = (molfile_atom_t *)malloc(natoms * sizeof(molfile_atom_t));
00075     rc = plugin->read_structure(handle, &optflags, atoms);
00076     if (rc) {
00077       fprintf(stderr, "FAILED: read_structure returned %d\n", rc);
00078       plugin->close_file_read(handle);
00079       return 1;
00080     } else {
00081       printf("Succesfully read atom structure information.\n");
00082     }
00083     if (plugin->read_bonds) {
00084       int nbonds, *from, *to;
00085       if ((rc = plugin->read_bonds(handle, &nbonds, &from, &to))) {
00086         fprintf(stderr, "FAILED: read_bonds returned %d\n", rc);
00087       } else {
00088         printf("read_bonds read %d bonds\n", nbonds);
00089         free(from);
00090         free(to);
00091       }
00092     } else {
00093       printf("File contains no bond information\n");
00094     }
00095   }
00096   if (plugin->read_next_timestep) {
00097     int nsteps = 0;
00098     timestep.coords = (float *)malloc(3*natoms*sizeof(float));
00099     while (!(rc = plugin->read_next_timestep(handle, natoms, &timestep))) 
00100       nsteps++;
00101     free(timestep.coords);
00102     if (rc != -1) {
00103       fprintf(stderr, "FAILED: read_next_timestep returned %d\n", rc);
00104     } else {
00105       printf("successfully read %d timesteps\n", nsteps);
00106     }
00107   }
00108   plugin->close_file_read(handle); 
00109 
00110   vmdplugin_fini();
00111   printf("Tests finished.\n");
00112   return 0;
00113 }
00114 

Generated on Wed Mar 22 13:15:30 2006 for VMD Plugins (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002