Changeset 1731


Ignore:
Timestamp:
02/11/11 18:08:42 (7 months ago)
Author:
Tobias Richter
Message:

refs #290

added hdf5 specific isexternalgroup and even isexternaldataset

the only thing that I cannot get to work right now is inquirefile
hdf5 seems to insist on reporting the file you opened, rather than
the one it currently reads through traversing the link. Ideas anyone?

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/napi.h

    r1728 r1731  
    246246#    define NXinquirefile       MANGLE(nxiinquirefile)  
    247247#    define NXisexternalgroup   MANGLE(nxiisexternalgroup) 
     248#    define NXisexternaldataset   MANGLE(nxiisexternaldataset) 
    248249#    define NXlinkexternal      MANGLE(nxilinkexternal) 
    249250#    define NXlinkexternaldataset      MANGLE(nxilinkexternaldataset) 
     
    723724extern  NXstatus  NXisexternalgroup(NXhandle handle, CONSTCHAR *name, CONSTCHAR *nxclass, char *url, int urlLen);  
    724725 
     726 
     727  /** 
     728   * Test if a dataset is actually pointing to an external file. If so, retrieve the URL of the  
     729   * external file. 
     730   * \param handle A NeXus file handle as initialized by NXopen. 
     731   * \param name The name of the dataset to test. 
     732   * \param url A buffer to copy the URL too. 
     733   * \param urlLen The length of the Url buffer. At maximum urlLen bytes will be copied to url. 
     734   * \return NX_OK when the dataset is pointing to an external file, NX_ERROR else. 
     735   * \ingroup c_external 
     736   */ 
     737extern  NXstatus  NXisexternaldataset(NXhandle handle, CONSTCHAR *name, char *url, int urlLen);  
     738 
    725739  /** 
    726740   * Create a link to a group in an external file. This works by creating a NeXus group under the current level in  
    727    * the hierarchy which actually points to a group in  another file.  
     741   * the hierarchy which actually points to a group in another file.  
    728742   * \param handle A NeXus file handle as initialized by NXopen. 
    729743   * \param name The name of the group which points to the external file. 
     
    905919        NXstatus ( *nxprintlink)(NXhandle handle, NXlink* link); 
    906920        NXstatus ( *nxnativeexternallink)(NXhandle handle, CONSTCHAR* name, CONSTCHAR* externalfile, CONSTCHAR* remotetarget); 
     921        NXstatus ( *nxnativeinquirefile)(NXhandle handle, char* externalfile, const int filenamelength); 
     922        NXstatus ( *nxnativeisexternallink)(NXhandle handle, CONSTCHAR* name, char* url, int urllen); 
    907923  } NexusFunction, *pNexusFunction; 
    908924  /*---------------------*/ 
  • trunk/src/napi.c

    r1729 r1731  
    12781278  pFileStack fileStack; 
    12791279  char *pPtr = NULL; 
    1280   int length; 
     1280  int length, status; 
     1281 
     1282  pNexusFunction pFunc = handleToNexusFunc(handle); 
     1283   if (pFunc->nxnativeinquirefile != NULL) { 
     1284 
     1285        status = LOCKED_CALL(pFunc->nxnativeinquirefile(pFunc->pNexusData, filename, filenameBufferLength)); 
     1286        if (status < 0) { 
     1287                return NX_ERROR; 
     1288        } else { 
     1289                return NX_OK; 
     1290        } 
     1291 
     1292   } 
    12811293 
    12821294  fileStack = (pFileStack)handle; 
     
    13021314  pNexusFunction pFunc = handleToNexusFunc(fid); 
    13031315 
    1304   status = LOCKED_CALL(pFunc->nxopengroup(pFunc->pNexusData, name,nxclass)); 
     1316   if (pFunc->nxnativeisexternallink != NULL) { 
     1317        status = LOCKED_CALL(pFunc->nxnativeisexternallink(pFunc->pNexusData, name, url, urlLen)); 
     1318        if (status == NX_OK) { 
     1319                return NX_OK; 
     1320        } 
     1321        // need to continue, could still be old style link 
     1322   } 
     1323 
     1324  status = LOCKED_CALL(pFunc->nxopengroup(pFunc->pNexusData, name, nxclass)); 
    13051325  if(status != NX_OK){ 
    13061326    return status; 
     
    13231343} 
    13241344/*------------------------------------------------------------------------*/ 
    1325 NXstatus  NXlinkexternal(NXhandle fid, CONSTCHAR *name, CONSTCHAR *nxclass, CONSTCHAR *url){ 
     1345NXstatus  NXisexternaldataset(NXhandle fid, CONSTCHAR *name, 
     1346                            char *url, int urlLen){ 
     1347  int status, attStatus, length = 1023, type = NX_CHAR; 
     1348  char nxurl[1024]; 
     1349 
     1350  pNexusFunction pFunc = handleToNexusFunc(fid); 
     1351 
     1352   if (pFunc->nxnativeisexternallink != NULL) { 
     1353        status = LOCKED_CALL(pFunc->nxnativeisexternallink(pFunc->pNexusData, name, url, urlLen)); 
     1354        if (status == NX_OK) { 
     1355                return NX_OK; 
     1356        } 
     1357        // need to continue, could still be old style link 
     1358   } 
     1359 
     1360  status = LOCKED_CALL(pFunc->nxopendata(pFunc->pNexusData, name)); 
     1361  if(status != NX_OK){ 
     1362    return status; 
     1363  } 
     1364  NXMDisableErrorReporting(); 
     1365  attStatus = NXgetattr(fid,"napimount",nxurl,&length, &type); 
     1366  NXMEnableErrorReporting(); 
     1367  LOCKED_CALL(pFunc->nxclosedata(pFunc->pNexusData)); 
     1368  if(attStatus == NX_OK){ 
     1369    length = strlen(nxurl); 
     1370    if(length > urlLen){ 
     1371      length = urlLen - 1; 
     1372    } 
     1373    memset(url,0,urlLen); 
     1374    memcpy(url,nxurl,length); 
     1375    return attStatus; 
     1376  } else { 
     1377    return NX_ERROR; 
     1378  } 
     1379} 
     1380/*------------------------------------------------------------------------*/ 
     1381NXstatus  NXlinkexternal(NXhandle fid, CONSTCHAR *name, CONSTCHAR *nxclass, CONSTCHAR *url) { 
    13261382  int status, type = NX_CHAR, length=1024, urllen; 
    13271383  char nxurl[1024], exfile[512], expath[512]; 
  • trunk/src/napi5.c

    r1730 r1731  
    21052105  /* ------------------------------------------------------------------- */ 
    21062106 
     2107   NXstatus  NX5nativeinquirefile(NXhandle fileid, char* externalfile, const int filenamelen) 
     2108  { 
     2109     pNexusFile5 pFile; 
     2110     ssize_t name_size; 
     2111 
     2112     pFile = NXI5assert(fileid); 
     2113 
     2114     name_size = H5Fget_name(pFile->iFID, externalfile, filenamelen); 
     2115 
     2116     // Check for failure again 
     2117     if( name_size < 0 ) { 
     2118         NXReportError("ERROR: retrieving file name"); 
     2119         return NX_ERROR; 
     2120     } 
     2121     return NX_OK; 
     2122  } 
     2123  /* ------------------------------------------------------------------- */ 
     2124 
     2125   NXstatus  NX5nativeisexternallink(NXhandle fileid, const char* name, char* url, const int urllen) 
     2126  { 
     2127     pNexusFile5 pFile; 
     2128     herr_t ret; 
     2129     H5L_info_t link_buff; 
     2130     int size=1024; 
     2131     char linkval_buff[size]; 
     2132     const char *filepath, *objpath; 
     2133 
     2134     pFile = NXI5assert(fileid); 
     2135 
     2136     ret = H5Lget_info(pFile->iFID, name, &link_buff, H5P_DEFAULT); 
     2137     if (ret < 0 || link_buff.type != H5L_TYPE_EXTERNAL) { 
     2138       return NX_ERROR; 
     2139     } 
     2140 
     2141     ret = H5Lget_val(pFile->iFID, name, linkval_buff, size, H5P_DEFAULT); 
     2142     if (ret < 0) { 
     2143       return NX_ERROR; 
     2144     } 
     2145 
     2146     ret = H5Lunpack_elink_val(linkval_buff, size, 0, &filepath, &objpath); 
     2147     if (ret < 0 || link_buff.type != H5L_TYPE_EXTERNAL) { 
     2148       return NX_ERROR; 
     2149     } 
     2150 
     2151    snprintf(url, urllen, "nxfile://%s#%s", filepath, objpath); 
     2152    return NX_OK; 
     2153      
     2154  } 
     2155  /* ------------------------------------------------------------------- */ 
     2156 
    21072157  NXstatus  NX5sameID (NXhandle fileid, NXlink* pFirstID, NXlink* pSecondID) 
    21082158  { 
     
    21702220      fHandle->nxprintlink=NX5printlink; 
    21712221      fHandle->nxnativeexternallink=NX5nativeexternallink; 
    2172 //      fHandle->nxnativeexternallink=NULL; 
     2222      fHandle->nxnativeinquirefile=NX5nativeinquirefile; 
     2223      fHandle->nxnativeisexternallink=NX5nativeisexternallink; 
    21732224} 
    21742225 
  • trunk/src/nexus_symbols.txt

    r1687 r1731  
    5252nxiinquirefile_ 
    5353nxiisexternalgroup_ 
     54nxiisexternaldataset_ 
    5455NXMSetError 
    5556NXMSetTError 
Note: See TracChangeset for help on using the changeset viewer.