コード例 #1
0
ファイル: nc4info.c プロジェクト: wkliao/netcdf-c
/**
 * @internal
 *
 * Construct the provenance information for a newly created file
 * using dfalt as the default.
 * Note that creation of the _NCProperties attribute is deferred
 * to the sync_netcdf4_file function.
 *
 * @param file Pointer to file object.
 * @param dfalt
 *
 * @return ::NC_NOERR No error.
 * [Note: other errors are reported via LOG()]
 * @author Dennis Heimbigner
 */
int
NC4_set_provenance(NC_FILE_INFO_T* file, const struct NCPROPINFO* dfalt)
{
    int ncstat = NC_NOERR;
    struct NCPROVENANCE* provenance = NULL;
    int superblock = -1;

    LOG((3, "%s: ncid 0x%x", __func__, file->root_grp->hdr.id));

    assert(file->provenance == NULL);

    provenance = calloc(1,sizeof(struct NCPROVENANCE));
    if(provenance == NULL) {ncstat = NC_ENOMEM; goto done;}

    /* Initialize from the default */
    provenance->propattr.version = globalpropinfo.version;
    /* Get the superblock number */
    if((ncstat = NC4_hdf5get_superblock(file,&superblock)))
        goto done;
    provenance->superblockversion = superblock;

    /* Capture properties */
    provenance->propattr.properties = nclistnew();
    if(provenance->propattr.properties == NULL)
    {ncstat = NC_ENOMEM; goto done;}
    /* add in the dfalt values */
    if(dfalt != NULL) {
        int i;
        for(i=0;i<nclistlength(dfalt->properties);i++) {
            char* prop = nclistget(dfalt->properties,i);
            if(prop != NULL) {
                prop = strdup(prop);
                if(prop == NULL) {ncstat = NC_ENOMEM; goto done;}
                nclistpush(provenance->propattr.properties,prop);
            }
        }
    }

done:
    if(ncstat) {
        LOG((0,"Could not create _NCProperties attribute"));
        (void)NC4_free_provenance(provenance);
    } else
        file->provenance = provenance;
    return NC_NOERR;
}
コード例 #2
0
ファイル: nc4info.c プロジェクト: jarlela/netcdf-c
int
NC4_get_fileinfo(NC_HDF5_FILE_INFO_T* h5, struct NCPROPINFO* init)
{
    int ncstat = NC_NOERR;

    /* Allocate the fileinfo in h5 */
    h5->fileinfo = (struct NCFILEINFO*)calloc(1,sizeof(struct NCFILEINFO));
    if(h5->fileinfo == NULL)
	{ncstat = NC_ENOMEM; goto done;}

    /* Get superblock version */
    NCHECK((ncstat = NC4_hdf5get_superblock(h5,&h5->fileinfo->superblockversion)));
    /* Get properties attribute if not already defined */
    if(init == NULL) {
        NCHECK((ncstat = NC4_get_propattr(h5)));
    } else { /*init != NULL*/
       h5->fileinfo->propattr = *init; /* Initialize */
    }
done:
    return ncstat;    
}
コード例 #3
0
ファイル: nc4info.c プロジェクト: wkliao/netcdf-c
/**
 * @internal
 *
 * Construct the provenance information for a newly opened file
 * Using the specified _NCProperties value. If NULL, then
 * initialize using dfalt.
 *
 * @param file Pointer to file object.
 * @param propstring The contents of _NCProperties
 * @param dfalt
 *
 * @return ::NC_NOERR No error.
 * @return ::NC_ENOMEM
 * @return ::NC_EINVAL
 * @author Dennis Heimbigner
 */
int
NC4_get_provenance(NC_FILE_INFO_T* file, const char* propstring, const struct NCPROPINFO* dfalt)
{
    int ncstat = NC_NOERR;
    struct NCPROVENANCE* provenance;
    char *name = NULL;
    char *value = NULL;
    int v = 0;
    int superblock = -1;

    LOG((3, "%s: ncid 0x%x propstring %s", __func__, file->root_grp->hdr.id, propstring));

    assert(file->provenance == NULL);
    if((file->provenance = calloc(1,sizeof(struct NCPROVENANCE))) == NULL)
    {ncstat = NC_ENOMEM; goto done;}
    provenance = file->provenance;
    if((provenance->propattr.properties = nclistnew()) == NULL)
    {ncstat = NC_ENOMEM; goto done;}

    /* Set the superblock */
    if((ncstat = NC4_hdf5get_superblock(file,&superblock)))
        goto done;
    provenance->superblockversion = superblock;

    if(propstring == NULL) {
        /* Use dfalt */
        if((ncstat=propinfo_default(&provenance->propattr,dfalt)))
            goto done;
    } else {
        NClist* list = provenance->propattr.properties;
        if((ncstat=properties_parse(propstring,list)))
            goto done;
        /* Check the version and remove from properties list*/
        if(nclistlength(list) < 2)
        {ncstat = NC_EINVAL; goto done;} /* bad _NCProperties attribute */
        /* Extract the purported version=... */
        name = nclistremove(list,0);
        value = nclistremove(list,0);
        if(strcmp(name,NCPVERSION) == 0) {
            if(sscanf(value,"%d",&v) != 1)
            {ncstat = NC_EINVAL; goto done;} /* illegal version */
            if(v <= 0 || v > NCPROPS_VERSION)
            {ncstat = NC_EINVAL; goto done;} /* unknown version */
            provenance->propattr.version = v;
        } else
        {ncstat = NC_EINVAL; goto done;} /* bad _NCProperties attribute */
        /* Now, rebuild from version 1 to version 2 if necessary */
        if(provenance->propattr.version == 1) {
            int i;
            for(i=0;i<nclistlength(list);i+=2) {
                char* newname = NULL;
                name = nclistget(list,i);
                if(name == NULL) continue; /* ignore */
                if(strcmp(name,NCPNCLIB1) == 0)
                    newname = NCPNCLIB2; /* change name */
                else if(strcmp(name,NCPHDF5LIB1) == 0)
                    newname = NCPHDF5LIB2;
                else continue; /* ignore */
                /* Do any rename */
                nclistset(list,i,strdup(newname));
                if(name) {free(name); name = NULL;}
            }
        }
    }
done:
    if(name != NULL) free(name);
    if(value != NULL) free(value);
    return ncstat;
}