/** Create Netcdf file specified by filename and set up dimension and * variable IDs. */ int Traj_AmberNetcdf::setupTrajout(FileName const& fname, Topology* trajParm, CoordinateInfo const& cInfoIn, int NframesToWrite, bool append) { readAccess_ = false; if (!append) { CoordinateInfo cInfo = cInfoIn; // Deal with output options // For backwards compatibility always write temperature if remdtraj is true. if (outputTemp_ && !cInfo.HasTemp()) cInfo.SetTemperature(true); // Explicitly write velocity - initial frames may not have velocity info. if (outputVel_ && !cInfo.HasVel()) cInfo.SetVelocity(true); if (outputFrc_ && !cInfo.HasForce()) cInfo.SetForce(true); SetCoordInfo( cInfo ); filename_ = fname; // Set up title if (Title().empty()) SetTitle("Cpptraj Generated trajectory"); // Create NetCDF file. if (NC_create( filename_.Full(), NC_AMBERTRAJ, trajParm->Natom(), CoordInfo(), Title() )) return 1; if (debug_>1) NetcdfDebug(); // Close Netcdf file. It will be reopened write. NC_close(); // Allocate memory if (Coord_!=0) delete[] Coord_; Coord_ = new float[ Ncatom3() ]; } else { // NOTE: File existence is checked for in Trajout // Call setupTrajin to set input parameters. This will also allocate // memory for coords. if (setupTrajin(fname, trajParm) == TRAJIN_ERR) return 1; // Check output options. if (outputTemp_ && !CoordInfo().HasTemp()) mprintf("Warning: Cannot append temperature data to NetCDF file '%s'; no temperature dimension.\n", filename_.base()); if (outputVel_ && !CoordInfo().HasVel()) mprintf("Warning: Cannot append velocity data to NetCDF file '%s'; no velocity dimension.\n", filename_.base()); if (outputFrc_ && !CoordInfo().HasForce()) mprintf("Warning: Cannot append force data to NetCDF file '%s'; no force dimension.\n", filename_.base()); if (debug_ > 0) mprintf("\tNetCDF: Appending %s starting at frame %i\n", filename_.base(), Ncframe()); } // Open file if ( NC_openWrite( filename_.Full() ) != 0 ) { mprinterr("Error: Opening Netcdf file %s for Write.\n", filename_.base()); return 1; } return 0; }
// Action_CreateReservoir::Setup() Action::RetType Action_CreateReservoir::Setup(ActionSetup& setup) { // Check that input parm matches current parm if (original_trajparm_->Pindex() != setup.Top().Pindex()) { mprintf("Info: createreservoir was set up for topology %s\n", original_trajparm_->c_str()); mprintf("Info: skipping topology %s\n", setup.Top().c_str()); return Action::SKIP; } if (!trajIsOpen_) { mprintf("\tCreating reservoir file %s\n", filename_.full()); CoordinateInfo cinfo = setup.CoordInfo(); if (!useVelocity_) cinfo.SetVelocity(false); if (!useForce_) cinfo.SetForce(false); if (reservoir_.InitReservoir(filename_, title_, cinfo, setup.Top().Natom(), (bin_ != 0), reservoirT_, iseed_)) { mprinterr("Error: Could not set up NetCDF reservoir.\n"); return Action::ERR; } trajIsOpen_ = true; nframes_ = 0; } return Action::OK; }