//============================================================================== /// Parse a single base dimension definition. /// /// \param [in] dim The YAML map node for the dimension. /// void DefinitionParser::ParseBaseDimension( const YAML::Node& dim ) { QString name; dim["name"] >> name; QString unit_name; dim["unit"] >> unit_name; DimensionId id; id[unit_name] = 1; (void)DefineDimension( dim.GetMark(), name, id, unit_name ); }
//============================================================================== /// Parse a single derived dimension definition. /// /// \param [in] dim The YAML map node for the dimension. /// void DefinitionParser::ParseDerivedDimension( const YAML::Node& dim ) { QString name; dim["name"] >> name; QString unit_name; dim["unit"] >> unit_name; QString derivation; dim["derivation"] >> derivation; DimensionId id = ParseDerivation( derivation ); (void)DefineDimension( dim.GetMark(), name, id, unit_name ); }
bool CNetCDFTraj::WriteHeader(CAmberTopology* p_top) { if( p_top == NULL ){ INVALID_ARGUMENT("p_top == NULL"); } if( NCID < 0 ) { ES_ERROR("file is not opened"); return(false); } int dimensionID[NC_MAX_VAR_DIMS]; NumOfTopologyAtoms = p_top->AtomList.GetNumberOfAtoms(); ActualAtoms = NumOfTopologyAtoms; CurrentSnapshot = 0; TotalSnapshots = 0; if( Coordinates != NULL ) { delete Coordinates; } Coordinates = new float[ActualAtoms*3]; // global dimmensions DefineDimension(AMBER_NETCDF_FRAME, NC_UNLIMITED, &TimeDID); DefineDimension(AMBER_NETCDF_SPATIAL, 3, &SpatialDID); DefineDimension(AMBER_NETCDF_ATOM, ActualAtoms, &CoordinateDID); DefineDimension(AMBER_NETCDF_LABEL, AMBER_NETCDF_LABELLEN, &LabelDID); DefineDimension(AMBER_NETCDF_CELL_SPATIAL, 3, &CellSpatialDID); DefineDimension(AMBER_NETCDF_CELL_ANGULAR, 3, &CellAngularDID); // put global attributes Conventions = "AMBER"; ConventionVersion = "1.0"; PutAttributeText(NC_GLOBAL, "title", Title); PutAttributeText(NC_GLOBAL, "application", Application); PutAttributeText(NC_GLOBAL, "program", Program); PutAttributeText(NC_GLOBAL, "programVersion", Version); PutAttributeText(NC_GLOBAL, "Conventions", Conventions); PutAttributeText(NC_GLOBAL, "ConventionVersion", ConventionVersion); // handle definition of non-optional variables dimensionID[0] = SpatialDID; DefineVariable(AMBER_NETCDF_SPATIAL, NC_CHAR, 1, dimensionID, &SpatialVID); dimensionID[0] = TimeDID; DefineVariable(AMBER_NETCDF_TIME, NC_FLOAT, 1, dimensionID, &TimeVID); PutAttributeText(TimeVID, "units", "picosecond"); dimensionID[0] = TimeDID; dimensionID[1] = CoordinateDID; dimensionID[2] = SpatialDID; DefineVariable(AMBER_NETCDF_COORDS, NC_FLOAT, 3, dimensionID, &CoordinateVID); PutAttributeText(CoordinateVID, "units", "angstrom"); dimensionID[0] = CellSpatialDID; DefineVariable(AMBER_NETCDF_CELL_SPATIAL, NC_CHAR, 1, dimensionID, &CellSpatialVID); dimensionID[0] = CellAngularDID; dimensionID[1] = LabelDID; DefineVariable(AMBER_NETCDF_CELL_ANGULAR, NC_CHAR, 2, dimensionID, &CellAngularVID); // set up box coords HasBox = p_top->BoxInfo.GetType() != AMBER_BOX_NONE; if( HasBox ) { dimensionID[0] = TimeDID; dimensionID[1] = CellSpatialDID; DefineVariable("cell_lengths", NC_DOUBLE, 2, dimensionID, &CellLengthVID); PutAttributeText(CellLengthVID, "units", "angstrom"); dimensionID[1] = CellAngularDID; DefineVariable("cell_angles", NC_DOUBLE, 2, dimensionID, &CellAngleVID); PutAttributeText(CellAngleVID, "units", "degree"); } int err,oldMode; // set fill mode err = nc_set_fill(NCID, NC_NOFILL, &oldMode); if (err != NC_NOERR) { CSmallString error; error << "unable to set fill value (" << nc_strerror(err) << ")"; ES_ERROR(error); return(false); } // end definition err = nc_enddef(NCID); if (err != NC_NOERR) { CSmallString error; error << "unable to end definitions (" << nc_strerror(err) << ")"; ES_ERROR(error); return(false); } size_t start[3]; size_t count[3]; char xyz[3]; char abc[15] = { 'a', 'l', 'p', 'h', 'a', 'b', 'e', 't', 'a', ' ', 'g', 'a', 'm', 'm', 'a' }; // setup labels start[0] = 0; count[0] = 3; xyz[0] = 'x'; xyz[1] = 'y'; xyz[2] = 'z'; err = nc_put_vara_text(NCID, SpatialVID, start, count, xyz); if (err != NC_NOERR) { CSmallString error; error << "unable to set spatial VID 'x', 'y' and 'z' (" << nc_strerror(err) << ")"; ES_ERROR(error); return(false); } start[0] = 0; count[0] = 3; xyz[0] = 'a'; xyz[1] = 'b'; xyz[2] = 'c'; err = nc_put_vara_text(NCID, CellSpatialVID, start, count, xyz); if (err != NC_NOERR) { CSmallString error; error << "unable to set spatial cell VID 'a', 'b' and 'c' (" << nc_strerror(err) << ")"; ES_ERROR(error); return(false); } start[0] = 0; start[1] = 0; count[0] = 3; count[1] = 5; err = nc_put_vara_text(NCID, CellAngularVID, start, count, abc); if (err != NC_NOERR) { CSmallString error; error << "unable to set angular cell VID 'alpha', 'beta ' and 'gamma' (" << nc_strerror(err) << ")"; ES_ERROR(error); return(false); } return(true); }