diff --git a/src/XTC/dump_xtc.h b/src/XTC/dump_xtc.h index 8d7d89df46..081891b224 100644 --- a/src/XTC/dump_xtc.h +++ b/src/XTC/dump_xtc.h @@ -34,7 +34,7 @@ namespace LAMMPS_NS { class DumpXTC : public Dump { public: DumpXTC(class LAMMPS *, int, char**); - ~DumpXTC(); + virtual ~DumpXTC(); private: int natoms,ntotal; diff --git a/src/dump.cpp b/src/dump.cpp index 551cde0ad4..9b1b10fe98 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -404,7 +404,11 @@ void Dump::openfile() #ifdef LAMMPS_GZIP char gzip[128]; sprintf(gzip,"gzip -6 > %s",filecurrent); +#ifdef _WIN32 + fp = _popen(gzip,"wb"); +#else fp = popen(gzip,"w"); +#endif #else error->one(FLERR,"Cannot open gzipped file"); #endif diff --git a/src/dump.h b/src/dump.h index 12113df549..3f581767e2 100644 --- a/src/dump.h +++ b/src/dump.h @@ -1,4 +1,4 @@ -/* ---------------------------------------------------------------------- +/* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov @@ -149,13 +149,14 @@ integer for dump. E: Cannot open gzipped file -LAMMPS is attempting to open a gzipped version of the specified file -but was unsuccessful. Check that the path and name are correct. +LAMMPS was compiled without support for reading and writing gzipped +files through a pipeline to the gzip program with -DLAMMPS_GZIP. E: Cannot open dump file -The output file for the dump command cannot be opened. Check that the -path and name are correct. +The specified file cannot be opened. Check that the path and name are +correct. If the file is a compressed file, also check that the gzip +executable can be found and run. E: Illegal ... command diff --git a/src/dump_image.cpp b/src/dump_image.cpp index a0063ff30f..51c77158eb 100644 --- a/src/dump_image.cpp +++ b/src/dump_image.cpp @@ -33,7 +33,6 @@ using namespace MathConst; #define BIG 1.0e20 -enum{PPM,JPG,PNG}; enum{NUMERIC,ATOM,TYPE,ELEMENT,ATTRIBUTE}; enum{STATIC,DYNAMIC}; enum{NO,YES}; @@ -547,7 +546,10 @@ void DumpImage::write() if (filetype == JPG) image->write_JPG(fp); else if (filetype == PNG) image->write_PNG(fp); else image->write_PPM(fp); - fclose(fp); + if (multifile) { + fclose(fp); + fp = NULL; + } } } diff --git a/src/dump_image.h b/src/dump_image.h index 53230b6cbf..9c42c584c1 100644 --- a/src/dump_image.h +++ b/src/dump_image.h @@ -1,4 +1,4 @@ -/* ---------------------------------------------------------------------- +/* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov @@ -27,12 +27,14 @@ namespace LAMMPS_NS { class DumpImage : public DumpCustom { public: DumpImage(class LAMMPS *, int, char**); - ~DumpImage(); + virtual ~DumpImage(); int pack_comm(int, int *, double *, int, int *); void unpack_comm(int, int, double *); - private: + protected: int filetype; + enum{PPM,JPG,PNG}; + int acolor,adiam; // what determines color/diam of atoms double adiamvalue; // atom diameter value int atomflag,bondflag; // 0/1 for draw atoms,bonds @@ -62,7 +64,7 @@ class DumpImage : public DumpCustom { double **bufcopy; // buffer for communicating bond/atom info int maxbufcopy; - void init_style(); + virtual void init_style(); int modify_param(int, char **); void write(); @@ -85,10 +87,14 @@ E: Invalid dump image filename The file produced by dump image cannot be binary and must be for a single processor. -E: Cannot dump JPG file +E: Support for writing images in JPEG format not included LAMMPS was not built with the -DLAMMPS_JPEG switch in the Makefile. +E: Support for writing images in PNG format not included + +LAMMPS was not built with the -DLAMMPS_PNG switch in the Makefile. + E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the diff --git a/src/dump_movie.cpp b/src/dump_movie.cpp new file mode 100644 index 0000000000..6c11f64e16 --- /dev/null +++ b/src/dump_movie.cpp @@ -0,0 +1,106 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Axel Kohlmeyer (Temple U) +------------------------------------------------------------------------- */ + +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "dump_movie.h" +#include "comm.h" +#include "force.h" +#include "memory.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +DumpMovie::DumpMovie(LAMMPS *lmp, int narg, char **arg) : + DumpImage(lmp, narg, arg) +{ + if (multiproc || compressed || multifile) + error->all(FLERR,"Invalid dump movie filename"); + + filetype = PPM; + bitrate = 2000; + framerate = 24; + fp = NULL; +} + +/* ---------------------------------------------------------------------- */ + +void DumpMovie::openfile() +{ + char moviecmd[1024]; + + if ((comm->me == 0) && (fp == NULL)) { + +#ifdef LAMMPS_FFMPEG + sprintf(moviecmd,"ffmpeg -v error -y -r %.2f -f image2pipe -c:v ppm -i - " + "-r 24.0 -b:v %dk %s ", framerate, bitrate, filename); +#else + error->one(FLERR,"Cannot generate movie file"); +#endif + +#if defined(_WIN32) + fp = _popen(moviecmd,"wb"); +#else + fp = popen(moviecmd,"w"); +#endif + + if (fp == NULL) { + char str[128]; + sprintf(str,"Failed to open FFmpeg pipeline to file %s",filename); + error->one(FLERR,str); + } + } +} +/* ---------------------------------------------------------------------- */ + +void DumpMovie::init_style() +{ + // initialize image style circumventing multifile check + + multifile = 1; + DumpImage::init_style(); + multifile = 0; +} + +/* ---------------------------------------------------------------------- */ + +int DumpMovie::modify_param(int narg, char **arg) +{ + int n = DumpImage::modify_param(narg,arg); + if (n) return n; + + if (strcmp(arg[0],"bitrate") == 0) { + if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); + bitrate = force->inumeric(FLERR,arg[1]); + if (bitrate <= 0.0) error->all(FLERR,"Illegal dump_modify command"); + return 2; + } + + if (strcmp(arg[0],"framerate") == 0) { + if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); + framerate = force->numeric(FLERR,arg[1]); + if ((framerate <= 0.1) || (framerate > 24.0)) + error->all(FLERR,"Illegal dump_modify framerate command"); + return 2; + } + + return 0; +} + diff --git a/src/dump_movie.h b/src/dump_movie.h new file mode 100644 index 0000000000..2cb4d878d9 --- /dev/null +++ b/src/dump_movie.h @@ -0,0 +1,73 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef DUMP_CLASS + +DumpStyle(movie,DumpMovie) + +#else + +#ifndef LMP_DUMP_MOVIE_H +#define LMP_DUMP_MOVIE_H + +#include "dump_image.h" + +namespace LAMMPS_NS { + +class DumpMovie : public DumpImage { + public: + DumpMovie(LAMMPS *, int, char**); + + virtual void openfile(); + virtual void init_style(); + virtual int modify_param(int, char **); + + protected: + double framerate; // frame rate of animation + int bitrate; // bitrate of video file in kbps +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Invalid dump movie filename + +The file produced by dump movie cannot be binary or compressed +and must be a single file for a single processor. + +E: Cannot generate movie file + +LAMMPS was built without the -DLAMMPS_FFMPEG switch in the Makefile + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +E: pipe:: Input/output error + +Harmless. This happens when the pipeline to FFmpeg is closed and no +more image data is sent to be appended to the movie. FFmpeg will +simply terminate and close the movie file. + +E: Failed to open FFmpeg pipeline to file %s + +The specified file cannot be opened. Check that the path and name are +correct and writable and that the FFmpeg executable can be found and run. + +*/ diff --git a/src/fix_tmd.cpp b/src/fix_tmd.cpp index e8ab940d6f..11c8c7920e 100644 --- a/src/fix_tmd.cpp +++ b/src/fix_tmd.cpp @@ -393,7 +393,7 @@ void FixTMD::readfile(char *file) int nlocal = atom->nlocal; char *buffer = new char[CHUNK*MAXLINE]; - char *ptr,*next,*bufptr; + char *next,*bufptr; int i,m,nlines,tag,imageflag,ix,iy,iz; double x,y,z,xprd,yprd,zprd; @@ -518,8 +518,14 @@ void FixTMD::open(char *file) else { #ifdef LAMMPS_GZIP char gunzip[128]; - sprintf(gunzip,"gunzip -c %s",file); + sprintf(gunzip,"gzip -c -d %s",file); + +#ifdef _WIN32 + fp = _popen(gunzip,"rb"); +#else fp = popen(gunzip,"r"); +#endif + #else error->one(FLERR,"Cannot open gzipped file"); #endif diff --git a/src/fix_tmd.h b/src/fix_tmd.h index a6b96fbb1c..d00bb303ec 100644 --- a/src/fix_tmd.h +++ b/src/fix_tmd.h @@ -1,4 +1,4 @@ -/* ---------------------------------------------------------------------- +/* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov @@ -98,12 +98,13 @@ fix group. E: Cannot open gzipped file -LAMMPS is attempting to open a gzipped version of the specified file -but was unsuccessful. Check that the path and name are correct. +LAMMPS was compiled without support for reading and writing gzipped +files through a pipeline to the gzip program with -DLAMMPS_GZIP. E: Cannot open file %s The specified file cannot be opened. Check that the path and name are -correct. +correct. If the file is a compressed file, also check that the gzip +executable can be found and run. */ diff --git a/src/reader.cpp b/src/reader.cpp index 79dbb1c046..588b21062c 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -41,8 +41,14 @@ void Reader::open_file(const char *file) else { #ifdef LAMMPS_GZIP char gunzip[1024]; - sprintf(gunzip,"gunzip -c %s",file); + sprintf(gunzip,"gzip -c -d %s",file); + +#ifdef _WIN32 + fp = _popen(gunzip,"rb"); +#else fp = popen(gunzip,"r"); +#endif + #else error->one(FLERR,"Cannot open gzipped file"); #endif diff --git a/src/reader.h b/src/reader.h index 571016ba7f..8f36bf622a 100644 --- a/src/reader.h +++ b/src/reader.h @@ -49,12 +49,13 @@ class Reader : protected Pointers { E: Cannot open gzipped file -LAMMPS is attempting to open a gzipped version of the specified file -but was unsuccessful. Check that the path and name are correct. +LAMMPS was compiled without support for reading and writing gzipped +files through a pipeline to the gzip program with -DLAMMPS_GZIP. E: Cannot open file %s The specified file cannot be opened. Check that the path and name are -correct. +correct. If the file is a compressed file, also check that the gzip +executable can be found and run. */