00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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, ×tep)))
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