コード例 #1
0
ファイル: daputil.c プロジェクト: dschwen/libmesh
/* Return value of param or NULL if not found */
const char*
dapparamvalue(NCDAPCOMMON* nccomm, const char* key)
{
    const char* value;

    if(nccomm == NULL || key == NULL) return 0;
    value=ncurilookup(nccomm->oc.url,key);
    return value;
}
コード例 #2
0
ファイル: daputil.c プロジェクト: dschwen/libmesh
/* Search for substring in value of param. If substring == NULL; then just
   check if param is defined.
*/
int
dapparamcheck(NCDAPCOMMON* nccomm, const char* key, const char* subkey)
{
    const char* value;
    char* p;

    if(nccomm == NULL || key == NULL) return 0;
    if((value=ncurilookup(nccomm->oc.url,key)) == NULL)
	return 0;
    if(subkey == NULL) return 1;
    p = strstr(value,subkey);
    if(p == NULL) return 0;
    p += strlen(subkey);
    if(*p != '\0' && strchr(checkseps,*p) == NULL) return 0;
    return 1;
}
コード例 #3
0
ファイル: ddispatch.c プロジェクト: SiggyF/netcdf-c
int
NC_urlmodel(const char* path)
{
    int model = 0;
    NCURI* tmpurl = NULL;
    struct NCPROTOCOLLIST* protolist;

    if(!ncuriparse(path,&tmpurl)) goto done;

    /* Look at any prefixed parameters */
    if(ncurilookup(tmpurl,"netcdf4",NULL)
       || ncurilookup(tmpurl,"netcdf-4",NULL)) {
	model = (NC_DISPATCH_NC4|NC_DISPATCH_NCD);
    } else if(ncurilookup(tmpurl,"netcdf3",NULL)
              || ncurilookup(tmpurl,"netcdf-3",NULL)) {
	model = (NC_DISPATCH_NC3|NC_DISPATCH_NCD);
    } else if(ncurilookup(tmpurl,"cdmremote",NULL)
	      || ncurilookup(tmpurl,"cdmr",NULL)) {
	model = (NC_DISPATCH_NCR|NC_DISPATCH_NC4);
    }

    if(model == 0) {
        /* Now look at the protocol */
        for(protolist=ncprotolist;protolist->protocol;protolist++) {
	    if(strcmp(tmpurl->protocol,protolist->protocol) == 0) {
    	        model |= protolist->modelflags;
    	        if(protolist->substitute) {
    	            if(tmpurl->protocol) free(tmpurl->protocol);
    		    tmpurl->protocol = strdup(protolist->substitute);
    	        }
    	        break;	    
	    }
	}
    }	

    /* Force NC_DISPATCH_NC3 if necessary */
    if((model & NC_DISPATCH_NC4) == 0)
	model |= (NC_DISPATCH_NC3 | NC_DISPATCH_NCD);

done:
    ncurifree(tmpurl);
    return model;
}
コード例 #4
0
ファイル: ddispatch.c プロジェクト: wkliao/netcdf-c
int
NC_urlmodel(const char* path, int mode, char** newurl)
{
    int found, model = 0;
    struct NCPROTOCOLLIST* protolist;
    NCURI* url = NULL;
    char* p;

    if(path == NULL) return 0;

    /* find leading non-blank */
    for(p=(char*)path;*p;p++) {if(*p != ' ') break;}

    /* Do some initial checking to see if this looks like a file path */
    if(*p == '/') return 0; /* probably an absolute file path */

    /* Parse the url */
    if(ncuriparse(path,&url) != NCU_OK)
	goto fail; /* Not parseable as url */

    /* Look up the protocol */
    for(found=0,protolist=ncprotolist;protolist->protocol;protolist++) {
        if(strcmp(url->protocol,protolist->protocol) == 0) {
	    found = 1;
	    break;
	}
    }
    if(found) {
	model = protolist->model;
	/* Substitute the protocol in any case */
	if(protolist->substitute) ncurisetprotocol(url,protolist->substitute);
    } else
	goto fail; /* Again, does not look like a url */

    if(model != NC_FORMATX_DAP2 && model != NC_FORMATX_DAP4) {
        /* Look for and of the following params:
  	   "dap2", "protocol=dap2", "dap4", "protocol=dap4" */
	const char* proto = NULL;
	const char* match = NULL;
	if((proto=ncurilookup(url,"protocol")) == NULL) proto = NULL;
	if(proto == NULL) proto = "";
	if((match=ncurilookup(url,"dap2")) != NULL || strcmp(proto,"dap2") == 0)
            model = NC_FORMATX_DAP2;
	else if((match=ncurilookup(url,"dap4")) != NULL || strcmp(proto,"dap4") == 0)
            model = NC_FORMATX_DAP4;
	else
	model = 0; /* Still don't know */
    }
    if(model == 0) {/* Last resort: use the mode */
        /* If mode specifies netcdf-4, then this is assumed to be dap4 */
        if(mode & NC_NETCDF4)
	    model = NC_FORMATX_DAP4;
        else
            model = NC_FORMATX_DAP2; /* Default */
    }
    if(newurl)
	*newurl = ncuribuild(url,NULL,NULL,NCURIALL);
    if(url) ncurifree(url);
    return model;
fail:
    if(url) ncurifree(url);
    return 0;
}