--- trunk/src/applications/atom2md/atom2md.cpp 2006/08/02 18:06:18 1020 +++ trunk/src/applications/atom2md/atom2md.cpp 2012/08/22 02:28:28 1782 @@ -1,12 +1,14 @@ /********************************************************************** -main.cpp - Main conversion program, command-line handling. +atom2md.cpp - OpenBabel-based conversion program to OpenMD file, + command-line handling. Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. -Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison -Some portions Copyright (C) 2004-2005 by Chris Morley +Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison +Some portions Copyright (C) 2004-2006 by Chris Morley +Some portions Copyright (C) 2008-2009 by J. Daniel Gezelter -This file is part of the Open Babel project. -For more information, see +This file is part of both the OpenMD and Open Babel projects. +For more information, see and This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,40 +21,38 @@ GNU General Public License for more details. ***********************************************************************/ #include "config.h" -#if HAVE_IOSTREAM - #include -#elif HAVE_IOSTREAM_H - #include + +// used to set import/export for Cygwin DLLs +#ifdef WIN32 +#define USING_OBDLL #endif -#if HAVE_FSTREAM - #include -#elif HAVE_FSTREAM_H - #include -#endif -#if HAVE_SSTREAM - #include -#elif - #include -#endif +#include + +#include +#include +#include + #include #include #if HAVE_CONIO_H #include #endif -#if !HAVE_STRNCASECMP -extern "C" int strncasecmp(const char *s1, const char *s2, size_t n); +#ifdef _MSC_VER +#define strncasecmp _strnicmp #endif -#include "openbabel/obconversion.hpp" -#include "brains/Register.hpp" +#include +#include +#include +#include using namespace std; using namespace OpenBabel; -using namespace oopse; -void DoOption(const char* p, OBConversion& Conv, OBConversion::Option_type typ, - int& arg, int argc, char *argv[]); + +void DoOption(const char* p, OBConversion& Conv, OBConversion::Option_type typ, + int& arg, int argc, char *argv[]); void usage(); void help(); @@ -61,28 +61,27 @@ int main(int argc,char *argv[]) int main(int argc,char *argv[]) { - registerOBFormats(); OBConversion Conv(&cin, &cout); //default input and output are console -// string GenOptions; OBFormat* pInFormat = NULL; OBFormat* pOutFormat = NULL; vector FileList, OutputFileList; string OutputFileName; -// obMessageLevel filterLevel = obWarning; // 2 out of 5 // Parse commandline bool gotInType = false, gotOutType = false; - bool UseSavedOptions = false; + bool SplitOrBatch=false; - char *oext; - char *iext; + char *oext = NULL; + char *iext = NULL; + + // for use with command name to type conversion string inputExt; string outputExt; //Save name of program without its path (and .exe) string pn(argv[0]); - unsigned int pos; + string::size_type pos; #ifdef _WIN32 pos = pn.find(".exe"); if(pos!=string::npos) @@ -94,194 +93,314 @@ int main(int argc,char *argv[]) else program_name=argv[0]+pos+1; - const char* p; - int arg; - for (arg = 1; arg < argc; arg++) - { - if (argv[arg]) - { - if (argv[arg][0] == '-') - { - switch (argv[arg][1]) - { + const char* p; + int arg; + for (arg = 1; arg < argc; ++arg) + { + if (argv[arg]) + { + if (argv[arg][0] == '-') + { + switch (argv[arg][1]) + { - case 'V': - { - cout << "Open Babel " << BABEL_VERSION << " -- " - << __DATE__ << " -- " << __TIME__ << endl; - exit(0); - } + case 'V': + { + cout << program_name << ": part of OpenMD " << + OPENMD_VERSION_MAJOR << "." << OPENMD_VERSION_MINOR << + "." << OPENMD_VERSION_TINY << + " and Open Babel " << BABEL_VERSION << " -- " + << __DATE__ << " -- " << __TIME__ << endl; + exit(0); + } - case 'i': - gotInType = true; - iext = argv[arg] + 2; - if(!*iext) - iext = argv[++arg]; //space left after -i: use next argument + case 'i': + gotInType = true; + iext = argv[arg] + 2; + if(!*iext) + iext = argv[++arg]; //space left after -i: use next argument - if (strncasecmp(iext, "MIME", 4) == 0) - { - // get the MIME type from the next argument - iext = argv[++arg]; - pInFormat = Conv.FormatFromMIME(iext); - } - else - { - //The ID provided by the OBFormat class is used as the identifying file extension - pInFormat = Conv.FindFormat(iext); - } - if(pInFormat==NULL) - { - cerr << program_name << ": cannot read input format!" << endl; - usage(); - } - inputExt = iext; - break; + if (strncasecmp(iext, "MIME", 4) == 0) + { + // get the MIME type from the next argument + iext = argv[++arg]; + pInFormat = Conv.FormatFromMIME(iext); + } + else + { + //The ID provided by the OBFormat class is used as the identifying file extension + pInFormat = Conv.FindFormat(iext); + } + if(pInFormat==NULL) + { + cerr << program_name << ": cannot read input format!" << endl; + usage(); + } + break; + + case 'o': + gotOutType = true; + oext = argv[arg] + 2; + if(!*oext) + oext = argv[++arg]; //space left after -i: use next argument - case 'o': - gotOutType = true; - oext = argv[arg] + 2; - if(!*oext) - oext = argv[++arg]; //space left after -i: use next argument - - if (strncasecmp(oext, "MIME", 4) == 0) - { - // get the MIME type from the next argument - oext = argv[++arg]; - pOutFormat = Conv.FormatFromMIME(oext); - } - else - pOutFormat = Conv.FindFormat(oext); + if (strncasecmp(oext, "MIME", 4) == 0) + { + // get the MIME type from the next argument + oext = argv[++arg]; + pOutFormat = Conv.FormatFromMIME(oext); + } + else + pOutFormat = Conv.FindFormat(oext); - if(pOutFormat==NULL) - { - cerr << program_name << ": cannot write output format!" << endl; - usage(); - } - outputExt = oext; - break; - - case '?': - case 'H': - if(isalnum(argv[arg][2])) - { - if(strncasecmp(argv[arg]+2,"all",3)) - { - OBFormat* pFormat = Conv.FindFormat(argv[arg]+2); - if(pFormat) - { - cout << argv[arg]+2 << " " << pFormat->Description() << endl; - if(strlen(pFormat->SpecificationURL())) - cout << "Specification at: " << pFormat->SpecificationURL() << endl; - } - else - cout << "Format type: " << argv[arg]+2 << " was not recognized" <Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) - continue; - cout << str << endl; - const char* p = strchr(pFormat->Description(),'\n'); - cout << p+1; //second line of description - if(strlen(pFormat->SpecificationURL())) - cout << "Specification at: " << pFormat->SpecificationURL(); - cout << endl << endl; - } - } - } - else - help(); - exit(0); + if(pOutFormat==NULL) + { + cerr << program_name << ": cannot write output format!" << endl; + usage(); + } + break; + + /*case 'F': + if(!Conv.SetOutFormat("fpt")) + cout << "FingerprintFormat needs to be loaded" << endl; + else + { + Conv.AddOption("F",OBConversion::OUTOPTIONS); + Conv.Write(NULL); + } + return 0; + */ + case 'L': //display a list of plugin type or classes + { + const char* param=NULL; + if(argc>arg+1) + param = argv[arg+2]; + OBPlugin::List(argv[arg+1], param); + return 0; + } + case '?': + case 'H': + if(isalnum(argv[arg][2]) || arg==argc-2) + { + if(strncasecmp(argv[arg]+2,"all",3)) + { + const char* pID= (arg==argc-2) ? argv[arg+1] : argv[arg]+2; + OBFormat* pFormat = Conv.FindFormat(pID); + if(pFormat) + { + cout << pID << " " << pFormat->Description() << endl; + if(pFormat->Flags() & NOTWRITABLE) + cout << " This format is Read-only" << endl; + if(pFormat->Flags() & NOTREADABLE) + cout << " This format is Write-only" << endl; + + if(strlen(pFormat->SpecificationURL())) + cout << "Specification at: " << pFormat->SpecificationURL() << endl; + } + else + cout << "Format type: " << pID << " was not recognized" < tempFileList(FileList); + FileList.clear(); + vector::iterator itr; + for(itr=tempFileList.begin();itr!=tempFileList.end();++itr) + DLHandler::findFiles (FileList, *itr); +#endif + + if (!gotInType) { - cerr << "No input file or format spec!" <1) - { - clog << OutputFileList.size() << " files output. The first is " << OutputFileList[0] <] [-o] " << endl; cout << "Try -H option for more information." << endl; -/* -#ifdef _DEBUG + +#ifdef DEBUG //CM keep window open cout << "Press any key to finish" < [Options]" << endl << endl; cout << "Each spec can be a file whose extension decides the format." << endl; cout << "Optionally the format can be specified by preceding the file by" << endl; @@ -358,23 +479,23 @@ void help() OBFormat* pDefault = OBConversion::GetDefaultFormat(); - if(pDefault) - cout << pDefault->TargetClassDescription();// some more options probably for OBMol + if(pDefault) + cout << pDefault->TargetClassDescription();// some more options probably for OBMol - OBFormat* pAPI= OBConversion::FindFormat("obapi"); - if(pAPI) - cout << pAPI->Description(); - - cout << "The following file formats are recognized:" << endl; + OBFormat* pAPI= OBConversion::FindFormat("obapi"); + if(pAPI) + cout << pAPI->Description(); + + cout << "The following file formats are recognized:" << endl; Formatpos pos; OBFormat* pFormat; const char* str=NULL; while(OBConversion::GetNextFormat(pos,str,pFormat)) - { - if((pFormat->Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) - continue; - cout << " " << str << endl; - } + { + if((pFormat->Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) + continue; + cout << " " << str << endl; + } cout << "\nSee further specific info and options using -H, e.g. -Hpdb" << endl; }