Esempio n. 1
0
/** Determine if Netcdf file contains multi-D REMD info. If so set the
  * number of replica dimensions (remd_dimension_) and figure out
  * the dimension types (remdDim)
  */
int NetcdfFile::SetupMultiD(ReplicaDimArray& remdDim) {
    int dimensionDID;

    if ( nc_inq_dimid(ncid_, NCREMD_DIMENSION, &dimensionDID) != NC_NOERR)
        return 1;

    // Although this is a second call to dimid, makes for easier code
    if ( (dimensionDID = GetDimInfo(NCREMD_DIMENSION, &remd_dimension_))==-1 )
        return -1;
    if (ncdebug_ > 0)
        mprintf("\tNetcdf file has multi-D REMD info, %i dimensions.\n",remd_dimension_);
    // Ensure valid # dimensions
    if (remd_dimension_ < 1) {
        mprinterr("Error: Number of REMD dimensions is less than 1!\n");
        return -1;
    }
    // Start and count for groupnum and dimtype, allocate mem
    start_[0]=0;
    start_[1]=0;
    start_[2]=0;
    count_[0]=remd_dimension_;
    count_[1]=0;
    count_[2]=0;
    int* remd_dimtype = new int[ remd_dimension_ ];
    // Get dimension types
    int dimtypeVID;
    if ( checkNCerr(nc_inq_varid(ncid_, NCREMD_DIMTYPE, &dimtypeVID)) ) {
        mprinterr("Error: Getting dimension type variable ID for each dimension.\n");
        return -1;
    }
    if ( checkNCerr(nc_get_vara_int(ncid_, dimtypeVID, start_, count_, remd_dimtype)) ) {
        mprinterr("Error: Getting dimension type in each dimension.\n");
        return -1;
    }
    // Get VID for replica indices
    if ( checkNCerr(nc_inq_varid(ncid_, NCREMD_INDICES, &indicesVID_)) ) {
        mprinterr("Error: Getting replica indices variable ID.\n");
        return -1;
    }
    // Print info for each dimension
    for (int dim = 0; dim < remd_dimension_; ++dim)
        remdDim.AddRemdDimension( remd_dimtype[dim] );
    delete[] remd_dimtype;
    return 0;
}
Esempio n. 2
0
NclFDimRec *GetDimInfo(void* therec, NclQuark dim_name)
{
    NclFileGrpNode *grpnode = (NclFileGrpNode *)therec;
    NclFileDimNode *dimnode;
    NclFDimRec *tmp = NULL;
    int n;

    if(NULL != grpnode->dim_rec)
    {
        for(n = 0; n < grpnode->dim_rec->n_dims; n++)
        {
            dimnode = &(grpnode->dim_rec->dim_node[n]);
            if(dimnode->name != dim_name)
                continue;

            tmp = (NclFDimRec *)NclCalloc(1, sizeof(NclFDimRec));
            assert(tmp);

            tmp->dim_name_quark = dimnode->name;
            tmp->dim_size = dimnode->size;
            tmp->is_unlimited  = dimnode->is_unlimited;

            return tmp;
        }
    }

    if(NULL != grpnode->grp_rec)
    {
        for(n = 0; n < grpnode->grp_rec->n_grps; n++)
        {
            tmp = GetDimInfo(grpnode->grp_rec->grp_node[n], dim_name);
            if(NULL != tmp)
                return tmp;
        }
    }

    return tmp;
}
Esempio n. 3
0
/** Setup ncatom, ncatom3, atomDID, coordVID, spatialDID, spatialVID,
  * velocityVID, frcVID. Check units and spatial dimensions.
  */
int NetcdfFile::SetupCoordsVelo(bool useVelAsCoords) {
    int spatial;
    atomDID_ = GetDimInfo(NCATOM, &ncatom_);
    if (atomDID_==-1) return 1;
    ncatom3_ = ncatom_ * 3;
    // Get coord info
    coordVID_ = -1;
    if ( nc_inq_varid(ncid_, NCCOORDS, &coordVID_) == NC_NOERR ) {
        if (ncdebug_ > 0) mprintf("\tNetcdf file has coordinates.\n");
        std::string attrText = GetAttrText(coordVID_, "units");
        if (attrText!="angstrom")
            mprintf("Warning: Netcdf file has length units of %s - expected angstrom.\n",
                    attrText.c_str());
    }
    // Get spatial info
    spatialDID_ = GetDimInfo(NCSPATIAL, &spatial);
    if (spatialDID_==-1) return 1;
    if (spatial!=3) {
        mprinterr("Error: Expected 3 spatial dimensions, got %i\n",spatial);
        return 1;
    }
    if ( checkNCerr(nc_inq_varid(ncid_, NCSPATIAL, &spatialVID_)) ) {
        mprintf("Warning: Could not get spatial VID. File may not be Amber NetCDF compliant.\n");
        mprintf("Warning: Assuming spatial variables are 'x', 'y', 'z'\n");
    } else {
        start_[0] = 0;
        count_[0] = 3;
        char xyz[3];
        if (checkNCerr(nc_get_vara_text(ncid_, spatialVID_, start_, count_, xyz))) {
            mprinterr("Error: Getting spatial variables.\n");
            return 1;
        }
        if (xyz[0] != 'x' || xyz[1] != 'y' || xyz[2] != 'z') {
            mprinterr("Error: NetCDF spatial variables are '%c', '%c', '%c', not 'x', 'y', 'z'\n",
                      xyz[0], xyz[1], xyz[2]);
            return 1;
        }
    }
    // Get velocity info
    velocityVID_ = -1;
    if ( nc_inq_varid(ncid_, NCVELO, &velocityVID_) == NC_NOERR ) {
        if (ncdebug_>0) mprintf("\tNetcdf file has velocities.\n");
    }
    // Return a error if no coords and no velocity
    if ( coordVID_ == -1 && velocityVID_ == -1 ) {
        mprinterr("Error: NetCDF file has no coords and no velocities.\n");
        return 1;
    }
    // If using velocities as coordinates, swap them now.
    if (useVelAsCoords) {
        if (velocityVID_ == -1) {
            mprinterr("Error: Cannot use velocities as coordinates; no velocities present.\n");
            return 1;
        }
        mprintf("\tUsing velocities as coordinates.\n");
        coordVID_ = velocityVID_;
        velocityVID_ = -1;
    }
    // Get force info
    frcVID_ = -1;
    if ( nc_inq_varid(ncid_, NCFRC, &frcVID_) == NC_NOERR ) {
        if (ncdebug_>0) mprintf("\tNetcdf file has forces.\n");
    }
    // Get overall replica and coordinate indices
    crdidxVID_ = -1;
    if ( nc_inq_varid(ncid_, NCREMD_REPIDX, &repidxVID_) == NC_NOERR ) {
        //if (ncdebug_ > 0)
        mprintf("    Netcdf file has overall replica indices.\n");
        if ( checkNCerr(nc_inq_varid(ncid_, NCREMD_CRDIDX, &crdidxVID_)) ) {
            mprinterr("Error: Getting overall coordinate index variable ID.\n");
            return 1;
        }
    } else
        repidxVID_ = -1;
    return 0;
}
Esempio n. 4
0
/** Get the ensemble dimension ID and size. */
int NetcdfFile::SetupEnsembleDim() {
    int ensembleSize = 0;
    ensembleDID_ = GetDimInfo( NCENSEMBLE, &ensembleSize );
    if (ensembleDID_ == -1) return 0;
    return ensembleSize;
}
Esempio n. 5
0
/** Get the frame dimension ID and # of frames (ncframe). */
int NetcdfFile::SetupFrameDim() {
    frameDID_ = GetDimInfo( NCFRAME, &ncframe_ );
    if (frameDID_==-1) return 1;
    return 0;
}