Changeset 1734 for trunk


Ignore:
Timestamp:
03/11/11 15:26:38 (7 months ago)
Author:
Tobias Richter
Message:

refs #290, #274, #258, #221, #285

implement all in Java
remove duplicate JavaDoc

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bindings/java/native/NexusFile.c

    r1661 r1734  
    33   Java API. 
    44 
    5    Mark Koennecke, October 2000 
    6  
    7    Version: 1.0 
    8  
    9    Version 1.1 
    10  
    11    Updated for using both HDF5 and HDF4  
    12  
    13    Mark Koennecke, August 2001 
    14  
    15    Updated for the NeXus XML-API, Mark Koennecke, October 2004 
    16  
    17    Updated for NXopengrouppath, NXopensourcepath 
    18    Mark Koennecke, December 2004 
    19  
    20    Updated for external linking, Mark Koennecke, April 2006 
    21  
    22    Updated for 64 bit types, Mark Koennecke, August 2007 
    23  
    24    Added NXinitattrdir and NXinitgroupdir, Mark Koennecke, October 2009 
    25  
    26    Added NXgetpath, Mark Koennecke, October 2009 
     5   Mark Koennecke, 2000 -- 2011 
    276 
    287   IMPLEMENTATION NOTES 
     
    405384    } 
    406385} 
     386/*------------------------------------------------------------------------ 
     387                               nxmakedata64 
     388--------------------------------------------------------------------------*/ 
     389JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxmakedata64 
     390  (JNIEnv *env, jobject obj, jint handle, jstring name, jint type,  
     391  jint rank, jlongArray dim) 
     392{ 
     393   char *Name; 
     394   NXhandle nxhandle; 
     395   jlong *iDim; 
     396   int iRet; 
     397 
     398    /* set error handler */ 
     399    NXMSetTError(env,JapiError); 
     400 
     401    /* exchange the Java handler to a NXhandle */ 
     402    nxhandle =  (NXhandle)HHGetPointer(handle); 
     403 
     404    /* extract the name and class to char * */ 
     405    Name = (char *) (*env)->GetStringUTFChars(env,name,0);     
     406 
     407    /* access dim array */ 
     408    iDim = (*env)->GetLongArrayElements(env,dim,0); 
     409 
     410    iRet = NXmakedata64(nxhandle,Name,type,rank,iDim); 
     411 
     412    /* clean up */  
     413    (*env)->ReleaseStringUTFChars(env,name, Name); 
     414    (*env)->ReleaseLongArrayElements(env,dim,iDim,0);   
     415 
     416    if (iRet != NX_OK) { 
     417      JapiError(env, "NXmakedata failed"); 
     418    } 
     419} 
    407420/*----------------------------------------------------------------------- 
    408421                               nxcompmakedata 
     
    439452    (*env)->ReleaseIntArrayElements(env,dim,iDim,0);   
    440453    (*env)->ReleaseIntArrayElements(env,chunk,iChunk,0);   
     454 
     455    if (iRet != NX_OK) { 
     456      JapiError(env, "NXcompmakedata failed"); 
     457    } 
     458} 
     459 
     460/*----------------------------------------------------------------------- 
     461                               nxcompmakedata64 
     462-------------------------------------------------------------------------*/ 
     463JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxmakecompdata64 
     464  (JNIEnv *env, jobject obj, jint handle, jstring name, jint type,  
     465   jint rank, jlongArray dim, jint compression_type, jlongArray chunk) 
     466{ 
     467   char *Name; 
     468   NXhandle nxhandle; 
     469   jlong *iDim, *iChunk; 
     470   int iRet; 
     471 
     472    /* set error handler */ 
     473    NXMSetTError(env,JapiError); 
     474 
     475    /* exchange the Java handler to a NXhandle */ 
     476    nxhandle =  (NXhandle)HHGetPointer(handle); 
     477 
     478    /* extract the name and class to char * */ 
     479    Name = (char *) (*env)->GetStringUTFChars(env,name,0);     
     480 
     481    /* access dim array */ 
     482    iDim = (*env)->GetLongArrayElements(env,dim,0); 
     483 
     484    /* access the chunksize array */ 
     485    iChunk = (*env)->GetLongArrayElements(env,chunk,0); 
     486 
     487    iRet = NXcompmakedata64(nxhandle,Name,type,rank,iDim, 
     488                          compression_type,iChunk); 
     489 
     490    /* clean up */  
     491    (*env)->ReleaseStringUTFChars(env,name, Name); 
     492    (*env)->ReleaseLongArrayElements(env,dim,iDim,0);   
     493    (*env)->ReleaseLongArrayElements(env,chunk,iChunk,0);   
    441494 
    442495    if (iRet != NX_OK) { 
     
    577630    (*env)->ReleaseIntArrayElements(env,start,iStart,0);   
    578631    (*env)->ReleaseIntArrayElements(env,end,iEnd,0);   
     632 
     633    if (iRet != NX_OK) { 
     634      JapiError(env, "NXputslab failed"); 
     635    } 
     636} 
     637/*------------------------------------------------------------------------ 
     638                               nxputslab64 
     639--------------------------------------------------------------------------*/ 
     640JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxputslab64 
     641  (JNIEnv *env, jobject obj, jint handle, jbyteArray data,  
     642   jlongArray start, jlongArray end) 
     643{ 
     644    NXhandle nxhandle; 
     645    jbyte *bdata; 
     646    jlong *iStart, *iEnd; 
     647    int iRet; 
     648 
     649    /* set error handler */ 
     650    NXMSetTError(env,JapiError); 
     651 
     652    /* exchange the Java handler to a NXhandle */ 
     653    nxhandle =  (NXhandle)HHGetPointer(handle); 
     654 
     655    /* convert arrays to C types  */ 
     656    bdata = (*env)->GetByteArrayElements(env,data,0); 
     657    iStart = (*env)->GetLongArrayElements(env,start,0); 
     658    iEnd = (*env)->GetLongArrayElements(env,end,0); 
     659 
     660 
     661    iRet = NXputslab64(nxhandle, bdata, iStart, iEnd); 
     662 
     663    /* cleanup */ 
     664    (*env)->ReleaseByteArrayElements(env,data,bdata,0);    
     665    (*env)->ReleaseLongArrayElements(env,start,iStart,0);   
     666    (*env)->ReleaseLongArrayElements(env,end,iEnd,0);   
    579667 
    580668    if (iRet != NX_OK) { 
     
    708796} 
    709797/*------------------------------------------------------------------------ 
     798                               nxgetslab64 
     799--------------------------------------------------------------------------*/ 
     800JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxgetslab64 
     801  (JNIEnv *env, jobject obj, jint handle, jlongArray start,  
     802   jlongArray end, jbyteArray data) 
     803{ 
     804    NXhandle nxhandle; 
     805    jbyte *bdata; 
     806    jlong *iStart, *iEnd; 
     807    int iRet; 
     808 
     809    /* set error handler */ 
     810    NXMSetTError(env,JapiError); 
     811 
     812    /* exchange the Java handler to a NXhandle */ 
     813    nxhandle =  (NXhandle)HHGetPointer(handle); 
     814 
     815    /* convert arrays to C types  */ 
     816    bdata = (*env)->GetByteArrayElements(env,data,0); 
     817    iStart = (*env)->GetLongArrayElements(env,start,0); 
     818    iEnd = (*env)->GetLongArrayElements(env,end,0); 
     819 
     820    iRet = NXgetslab64(nxhandle, bdata, iStart, iEnd); 
     821 
     822    /* cleanup */ 
     823    (*env)->ReleaseByteArrayElements(env,data,bdata,0);    
     824    (*env)->ReleaseLongArrayElements(env,start,iStart,0);   
     825    (*env)->ReleaseLongArrayElements(env,end,iEnd,0);   
     826 
     827    if (iRet != NX_OK) { 
     828      JapiError(env, "NXgetslab failed"); 
     829    } 
     830} 
     831/*------------------------------------------------------------------------ 
    710832                               nxgetattr 
    711833--------------------------------------------------------------------------*/ 
     
    11901312} 
    11911313/*------------------------------------------------------------------------ 
     1314                               nxgetinfo64 
     1315--------------------------------------------------------------------------*/ 
     1316JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxgetinfo64 
     1317    (JNIEnv *env, jobject obj, jint handle, jlongArray dim, jintArray args) 
     1318{ 
     1319    int rank, type, iRet, i; 
     1320    jlong iDim[NX_MAXRANK]; 
     1321    NXhandle nxhandle; 
     1322    jlong *jdata; 
     1323    jint *jargsdata; 
     1324 
     1325   /* set error handler */ 
     1326    NXMSetTError(env,JapiError); 
     1327 
     1328    /* exchange the Java handler to a NXhandle */ 
     1329    nxhandle =  (NXhandle)HHGetPointer(handle); 
     1330 
     1331    /* call */ 
     1332    iRet = NXgetinfo64(nxhandle, &rank, iDim, &type); 
     1333 
     1334    /* copy data to Java types */ 
     1335    if(iRet == NX_OK) 
     1336    { 
     1337        jdata = (*env)->GetLongArrayElements(env,dim,0); 
     1338        for(i = 0; i < rank; i++) 
     1339        { 
     1340           jdata[i] = iDim[i]; 
     1341        } 
     1342        (*env)->ReleaseLongArrayElements(env,dim,jdata,0); 
     1343 
     1344        jargsdata = (*env)->GetIntArrayElements(env,args,0); 
     1345        jargsdata[0] = rank; 
     1346        jargsdata[1] = type; 
     1347        (*env)->ReleaseIntArrayElements(env,args,jargsdata,0); 
     1348    } 
     1349} 
     1350/*------------------------------------------------------------------------ 
    11921351                               nextentry 
    11931352--------------------------------------------------------------------------*/ 
     
    12961455} 
    12971456/*------------------------------------------------------------------------*/ 
     1457JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxlinkexternaldataset 
     1458(JNIEnv *env, jobject obj, jint handle, jstring name, jstring nxurl){ 
     1459    int iRet; 
     1460    NXhandle nxhandle; 
     1461    char *Name, *Nxurl; 
     1462 
     1463    /* set error handler */ 
     1464    NXMSetTError(env,JapiError); 
     1465 
     1466    /* exchange the Java handler to a NXhandle */ 
     1467    nxhandle =  (NXhandle)HHGetPointer(handle); 
     1468   
     1469    /* extract the name and class to char * */ 
     1470    Name = (char *) (*env)->GetStringUTFChars(env,name,0);     
     1471    Nxurl = (char *) (*env)->GetStringUTFChars(env,nxurl,0);     
     1472    iRet = NXlinkexternaldataset(nxhandle,Name,Nxurl); 
     1473     
     1474    /* release strings */ 
     1475    (*env)->ReleaseStringUTFChars(env,name, Name); 
     1476    (*env)->ReleaseStringUTFChars(env,nxurl, Nxurl); 
     1477 
     1478    if (iRet != NX_OK) { 
     1479      JapiError(env, "NXlinkexternaldataset failed"); 
     1480    } 
     1481} 
     1482/*------------------------------------------------------------------------*/ 
    12981483JNIEXPORT jint JNICALL Java_org_nexusformat_NexusFile_nxisexternalgroup 
    12991484(JNIEnv *env, jobject obj, jint handle, jstring name, jstring nxclass,  
     
    13261511    return status; 
    13271512} 
     1513/*------------------------------------------------------------------------*/ 
     1514JNIEXPORT jint JNICALL Java_org_nexusformat_NexusFile_nxisexternaldataset 
     1515(JNIEnv *env, jobject obj, jint handle, jstring name, jobjectArray jnames){ 
     1516    int status, length = 1024; 
     1517    NXhandle nxhandle; 
     1518    char *Name, nxurl[1024]; 
     1519    jstring rstring; 
     1520     
     1521    /* set error handler */ 
     1522    NXMSetTError(env,JapiError); 
     1523 
     1524    /* exchange the Java handler to a NXhandle */ 
     1525    nxhandle =  (NXhandle)HHGetPointer(handle); 
     1526   
     1527    /* extract the name and class to char * */ 
     1528    Name = (char *) (*env)->GetStringUTFChars(env,name,0);     
     1529 
     1530    status = NXisexternaldataset(nxhandle,Name,nxurl,length); 
     1531 
     1532    /* release strings */ 
     1533    (*env)->ReleaseStringUTFChars(env,name, Name); 
     1534     
     1535    if(status == NX_OK){ 
     1536      rstring = (*env)->NewStringUTF(env,nxurl); 
     1537      (*env)->SetObjectArrayElement(env,jnames,0,(jobject)rstring); 
     1538    } 
     1539    return status; 
     1540} 
    13281541/*---------------------------------------------------------------------*/ 
    13291542JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_initattrdir 
  • trunk/bindings/java/org/nexusformat/NeXusFileInterface.java

    r1465 r1734  
    1111  * 
    1212  * 
    13   * @author Mark Koennecke, October 2000 
    14   * 
    15   * updated for NAPI-2.0, including HDF-5 support 
    16   * @author Mark Koennecke, August 2001 
    17   * 
    18   * updated for NXopengrouppath, NXopensourcepath, XML 
    19   * @author Mark Koennecke, December 2004 
     13  * @author Mark Koennecke, 2000 -- 2011 
    2014  * 
    2115  * copyright: see accompanying COPYRIGHT file 
     
    3428      */ 
    3529    public void flush() throws NexusException; 
     30 
    3631    /** 
    3732      * finalize closes the file. It is supposed to be called by the 
     
    4439      */ 
    4540    public void finalize() throws Throwable; 
     41 
    4642    /** 
    4743     * close the NeXus file. To make javalint and diamond happy 
     
    4945     */ 
    5046    public void close() throws NexusException; 
     47 
    5148    // group functions 
    5249    /**  
     
    7774      * @exception NexusException when something goes wrong. 
    7875      */    
    79     public void openpath(String path) throws  
    80                            NexusException; 
     76    public void openpath(String path) throws NexusException; 
     77 
    8178    /** 
    8279      * opengrouppath opens groups and datsets accroding to the path string 
     
    8784      * @exception NexusException when something goes wrong. 
    8885      */    
    89     public void opengrouppath(String path) throws  
    90                            NexusException; 
     86    public void opengrouppath(String path) throws NexusException; 
     87 
    9188    /** 
    9289     * return the current path into the NeXus file in the  
     
    9592     */ 
    9693    public String getpath() throws NexusException; 
     94 
    9795    /** 
    9896      * closegroup closes access to the current group and steps down one 
     
    10199      * operation. 
    102100      */  
    103     public void closegroup() throws  
    104                              NexusException; 
     101    public void closegroup() throws NexusException; 
    105102 
    106103    // data set handling 
     
    113110      * @param rank The rank or number of dimensions of the dataset. 
    114111      * @param dim An array containing the length of each dimension. dim must 
    115       * have at least rank entries. The first dimension can be -1 which 
    116       * means it is an unlimited dimension. 
     112      * have at least rank entries. Dimension passed as -1 denote an 
     113      * unlimited dimension. 
    117114      * @exception NexusException when the dataset could not be created. 
    118115      */  
    119116    public void makedata(String name, int type, int rank, int dim[])  
    120117        throws NexusException; 
     118 
     119    /** 
     120      * makedata creates a new dataset with the specified characteristics  
     121      * in the current group. 
     122      * @param name The name of the dataset. 
     123      * @param type The number type of the dataset. Usually a constant from 
     124      * a selection of values. 
     125      * @param rank The rank or number of dimensions of the dataset. 
     126      * @param dim An array containing the length of each dimension. dim must 
     127      * have at least rank entries. Dimension passed as -1 denote an 
     128      * unlimited dimension. 
     129      * @exception NexusException when the dataset could not be created. 
     130      */  
     131    public void makedata(String name, int type, int rank, long dim[])  
     132        throws NexusException; 
     133 
    121134    /** 
    122135      * compmakedata creates a new dataset with the specified characteristics  
     
    127140      * @param rank The rank or number of dimensions of the dataset. 
    128141      * @param dim An array containing the length of each dimension. dim must 
    129       * have at least rank entries. The first dimension can be -1 which 
    130       * means it is an unlimited dimension. 
     142      * have at least rank entries. Dimension passed as -1 denote an 
     143      * unlimited dimension. 
    131144      * @param compression_type determines the compression type.  
    132145      * @param iChunk With HDF-5, slabs can be written to compressed data  
     
    137150      */  
    138151    public void compmakedata(String name, int type, int rank, int dim[], 
    139                              int compression_type, int iChunk[]) throws 
    140                            NexusException;  
     152             int compression_type, int iChunk[]) throws NexusException;  
     153 
     154    /** 
     155      * compmakedata creates a new dataset with the specified characteristics  
     156      * in the current group. This data set will be compressed. 
     157      * @param name The name of the dataset. 
     158      * @param type The number type of the dataset. Usually a constant from 
     159      * a selection of values. 
     160      * @param rank The rank or number of dimensions of the dataset. 
     161      * @param dim An array containing the length of each dimension. dim must 
     162      * have at least rank entries. Dimension passed as -1 denote an 
     163      * unlimited dimension. 
     164      * @param compression_type determines the compression type.  
     165      * @param iChunk With HDF-5, slabs can be written to compressed data  
     166      * sets. The size of these slabs is specified through the chunk array. 
     167      * This must have the rank values for the size of the chunk to 
     168      * be written in each dimension.  
     169      * @exception NexusException when the dataset could not be created. 
     170      */  
     171    public void compmakedata(String name, int type, int rank, long dim[], 
     172             int compression_type, long iChunk[]) throws NexusException;  
     173 
    141174    /** 
    142175      * opendata opens an existing dataset for access. For instance for  
     
    146179      * something else is wrong. 
    147180      */ 
    148     public void opendata(String name)throws  
    149                            NexusException; 
     181    public void opendata(String name)throws NexusException; 
     182 
    150183    /** 
    151184      * closedata closes an opened dataset. Then no further access is  
     
    153186      * @exception NexusException when an HDF error occurrs. 
    154187      */ 
    155     public void closedata() throws 
    156                            NexusException; 
     188    public void closedata() throws NexusException; 
     189 
    157190    /** 
    158191      * causes the currently open dataset to be compressed on file. 
     
    164197      * occurs. 
    165198      */  
    166     public void compress(int compression_type) throws  
    167                            NexusException; 
     199    public void compress(int compression_type) throws NexusException; 
    168200 
    169201    // data set reading 
     
    178210      * the data. 
    179211      */ 
    180     public void getdata(Object array)throws  
    181                           NexusException; 
     212    public void getdata(Object array) throws NexusException; 
     213 
    182214    /** 
    183215      * getslab reads a subset of a large dataset into array. 
     
    191223      * the data. 
    192224      */ 
    193     public void getslab(int start[], int size[],Object array)throws 
    194                           NexusException; 
     225    public void getslab(int start[], int size[], Object array) throws 
     226                          NexusException; 
     227 
     228    /** 
     229      * getslab reads a subset of a large dataset into array. 
     230      * @param start An array of dimension rank which contains the start  
     231      * position in the dataset from where to start reading. 
     232      * @param size An array of dimension rank which contains the size 
     233      * in each dimension of the data subset to read. 
     234      * @param array An array for holding the returned data values. 
     235      * @exception NexusException when either an HDF error occurs or  
     236      * no dataset is open or array is not of the right type to hold 
     237      * the data. 
     238      */ 
     239    public void getslab(long start[], long size[], Object array) throws 
     240                          NexusException; 
     241 
    195242    /** 
    196243      * getattr retrieves the data associated with the attribute  
     
    205252      * the attribute could not be found. 
    206253      */ 
    207     public void getattr(String name,Object data, int args[])throws 
     254    public void getattr(String name, Object data, int args[]) throws 
    208255                          NexusException; 
    209256 
     
    215262      * @exception NexusException when an HDF error occurs. 
    216263      */ 
    217     public void putdata(Object array) throws  
    218                           NexusException; 
     264    public void putdata(Object array) throws NexusException; 
     265 
    219266    /** 
    220267      * putslab writes a subset of a larger dataset to a previously opened 
     
    229276    public void putslab(Object array, int start[], int size[]) throws 
    230277                          NexusException; 
     278 
     279    /** 
     280      * putslab writes a subset of a larger dataset to a previously opened 
     281      * dataset. 
     282      * @param array The data to write. 
     283      * @param start An integer array of dimension rank which holds the 
     284      * startcoordinates of the data subset in the larger dataset. 
     285      * @param size An integer array of dimension rank whidh holds the 
     286      * size in each dimension of the data subset to write. 
     287      * @exception NexusException when an HDF error occurs. 
     288      */  
     289    public void putslab(Object array, long start[], long size[]) throws 
     290                          NexusException; 
     291 
    231292    /** 
    232293      * putattr adds a named attribute to a previously opened dataset or 
     
    250311      * @exception NexusException when  an HDF error occurs. 
    251312      */  
    252     public void getinfo(int iDim[], int args[]) throws  
    253                           NexusException; 
     313    public void getinfo(int iDim[], int args[]) throws NexusException; 
     314 
     315    /** 
     316      * getinfo retrieves information about a previously opened dataset. 
     317      * @param iDim An array which will be filled with the size of 
     318      * the dataset in each dimension. 
     319      * @param args An integer array which will hold more information about 
     320      * the dataset after return. The fields: args[0] is the rank, args[1] is 
     321      * the number type. 
     322      * @exception NexusException when  an HDF error occurs. 
     323      */  
     324    public void getinfo(long iDim[], int args[]) throws NexusException; 
     325 
    254326    /** 
    255327     * setnumberformat sets the number format for printing number when 
     
    261333     * @param format The new format to use. 
    262334     */ 
    263     public void setnumberformat(int type, String format)  
    264         throws NexusException; 
     335    public void setnumberformat(int type, String format) throws NexusException; 
     336 
    265337    /** 
    266338      * groupdir will retrieve the content of the currently open vGroup. 
     
    271343      * @exception NexusException if an HDF error occurs 
    272344      */ 
    273     public Hashtable groupdir()throws 
    274                           NexusException; 
     345    public Hashtable groupdir() throws NexusException; 
     346 
    275347    /** 
    276348      * attrdir returns the attributes of the currently open dataset or 
     
    280352      * @exception NexusException when an HDF error occurs. 
    281353      */  
    282     public Hashtable attrdir()throws 
    283                           NexusException; 
     354    public Hashtable attrdir() throws NexusException; 
    284355     
    285356    // linking  
     
    290361      * @exception NexusException if an HDF error occurs. 
    291362      */ 
    292     public NXlink getgroupID() throws 
    293                           NexusException; 
     363    public NXlink getgroupID() throws NexusException; 
     364 
    294365    /** 
    295366      * getdataID gets the data necessary for linking the current dataset 
     
    298369      * @exception NexusException if an HDF error occurs. 
    299370      */ 
    300     public NXlink getdataID()throws 
    301                           NexusException; 
     371    public NXlink getdataID()throws NexusException; 
     372 
    302373    /** 
    303374      * makelink links the object described by target into the current 
     
    306377      * @exception NexusException if an error occurs. 
    307378      */ 
    308     public void   makelink(NXlink target)throws 
    309                           NexusException;      
     379    public void makelink(NXlink target)throws NexusException;      
    310380    /** 
    311381      * makenamedlink links the object described by target into the current 
     
    316386      * @exception NexusException if an error occurs. 
    317387      */ 
    318     public void   makenamedlink(String name, NXlink target)throws 
    319                           NexusException;      
     388    public void makenamedlink(String name, NXlink target) throws NexusException;      
     389 
    320390    /** 
    321391      * opensourcepath opens the group from which the current item was linked 
     
    323393      * @exception NexusException if an error occurs. 
    324394      */ 
    325     public void   opensourcepath()throws 
    326                           NexusException;      
     395    public void opensourcepath() throws NexusException;      
     396 
    327397    /** 
    328398     * inquirefile inquires which file we are currently in. This is 
     
    332402     */ 
    333403    public String inquirefile() throws NexusException; 
     404 
    334405    /**  
    335406     * linkexternal links group name, nxclass to the URL nxurl 
     
    340411     */ 
    341412    public void linkexternal(String name, String nxclass, String nxurl) throws NexusException; 
    342     /** 
    343      * nxisexternalgroup test the group name, nxclass if it is linked externally. 
     413 
     414    /**  
     415     * linkexternaldataset links dataset name to the URL nxurl 
     416     * @param name The name of the dataset to link to 
     417     * @param nxurl The URL to the linked external file 
     418     * @throws NexusException if things are wrong 
     419     */ 
     420    public void linkexternaldataset(String name, String nxurl) throws NexusException; 
     421 
     422    /** 
     423     * nxisexternalgroup test the group name, nxclass if it is linked externally 
    344424     * @param name of the group to test 
    345425     * @param  nxclass class of the group to test 
    346426     * @return null when the group is not linked, else a string giving the URL of the 
    347      * linked file. 
     427     * linked resource 
    348428     * @throws NexusException if things are wrong 
    349429     */ 
    350430    public String isexternalgroup(String name, String nxclass) throws NexusException; 
     431 
     432    /** 
     433     * nxisexternaldataset if the named dataset is is linked externally 
     434     * @param name of the dataset to test 
     435     * @return null when the it is not linked, else a string giving the URL of the 
     436     * linked resource 
     437     * @throws NexusException if things are wrong 
     438     */ 
     439    public String isexternaldataset(String name) throws NexusException; 
    351440} 
    352    
  • trunk/bindings/java/org/nexusformat/NexusFile.java

    r1486 r1734  
    11/** 
    2   * 
    3   * @mainpage The NeXus-API for Java.  
    4   * NeXus is an attempt to define a common data  
    5   * format for org and x-ray diffraction. NeXus is built on top of the 
    6   * Hierarchical Data Format from NCSA. There exist already API's to 
    7   * NeXus files for F77, F90, C and C++. This is an implementation of 
     2  * @mainpage This is an implementation of 
    83  * a Java NeXus API using native methods. 
    94  * 
    10   * Some changes to the API have been necessary however, due to the  
     5  * Some changes to the API have been necessary, due to the  
    116  * different calling standards between C and Java.  
    127  * 
    13   * 
    14   * @author Mark Koennecke, October 2000 
    15   * 
    16   * Updated: Mark Koennecke, April 2006 
     8  * @author Mark Koennecke, 2000 -- 2011 
    179  * 
    1810  * copyright: see accompanying COPYRIGHT file 
    1911  * 
    20   * added nxinitattrdir: Mark Koennecke, October 2009  
    21   * 
    2212  * @see TestJapi.java 
    23   * 
    24   */ 
    25  
    26   /** 
    27   * @example TestJapi.java 
    2813  * Test program for Java API. 
    2914  * Illustrates using the #org.nexusformat package 
     
    3722import ncsa.hdf.hdflib.HDFConstants; 
    3823 
    39 public class  NexusFile implements NeXusFileInterface { 
     24public class NexusFile implements NeXusFileInterface { 
    4025 
    4126    // constants  
     
    143128      * an HDF error occurred. 
    144129      */ 
    145     public NexusFile(String filename, int access) throws NexusException  
    146     { 
    147                 checkForNull(filename); 
     130    public NexusFile(String filename, int access) throws NexusException { 
     131         checkForNull(filename); 
    148132 
    149133         handle = init(filename,access); 
     
    152136         } 
    153137    } 
     138 
    154139    /** 
    155140      * flushes all pending data to disk. Closes any open SDS's. 
    156141      */ 
    157     public void flush() throws NexusException 
    158     { 
     142    public void flush() throws NexusException { 
    159143        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    160144         handle = nxflush(handle); 
    161145    } 
     146 
    162147    /** 
    163148     * close the NeXus file. To make javalint and diamond happy 
    164149     * @throws NexusException 
    165150     */ 
    166     public void close() throws NexusException{ 
    167         if(handle  >= 0) 
    168         { 
     151    public void close() throws NexusException { 
     152        if(handle  >= 0) { 
    169153           close(handle); 
    170154           handle = -1; 
     
    182166      * do any harm. 
    183167      */    
    184     public void finalize() throws Throwable  
    185     { 
     168    public void finalize() throws Throwable { 
    186169        close(); 
    187170    } 
     
    197180    protected native String nxgetpath(int handle); 
    198181 
    199     /**  
    200       * makegroup creates a new group below the current group within 
    201       * the NeXus file hierarchy. 
    202       * @param name The name of the group to create. 
    203       * @param nxclass The classname of the group. 
    204       * @exception NexusException if an error occurs during this operation. 
    205       */  
    206     public void makegroup(String name, String nxclass) throws  
    207                             NexusException 
    208     { 
     182    public void makegroup(String name, String nxclass) throws NexusException { 
    209183        checkForNull(name, nxclass); 
    210184        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    211185        nxmakegroup(handle, name, nxclass); 
    212186    } 
    213     /** 
    214       * opengroup opens the group name with class nxclass.  
    215       * The group must exist, otherwise an exception is thrown. opengroup is 
    216       * similar to a cd name in a filesystem. 
    217       * @param name the name of the group to open. 
    218       * @param nxclass the classname of the group to open.  
    219       * @exception NexusException when something goes wrong. 
    220       */    
    221     public void opengroup(String name, String nxclass) throws  
    222                              NexusException 
    223     { 
     187 
     188    public void opengroup(String name, String nxclass) throws NexusException { 
    224189        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    225190        checkForNull(name, nxclass); 
    226191        nxopengroup(handle, name, nxclass); 
    227192    } 
    228     /** 
    229       * openpath opens groups and datsets accroding to the path string 
    230       * given. The path syntax follows unix conventions. Both absolute 
    231       * and relative paths are possible. All objects of the path must 
    232       * exist. 
    233       * @param path The path string 
    234       * @exception NexusException when something goes wrong. 
    235       */    
    236     public void openpath(String path) throws  
    237                          NexusException 
    238     { 
     193 
     194    public void openpath(String path) throws NexusException { 
    239195        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    240196        checkForNull(path); 
    241197        nxopenpath(handle,path); 
    242198    } 
    243     /** 
    244       * opengrouppath opens groups and datsets accroding to the path string 
    245       * given. The path syntax follows unix conventions. Both absolute 
    246       * and relative paths are possible. All objects of the path must 
    247       * exist. This opens only until the last group. 
    248       * @param path The path string 
    249       * @exception NexusException when something goes wrong. 
    250       */    
    251     public void opengrouppath(String path) throws  
    252                          NexusException 
    253     { 
     199 
     200    public void opengrouppath(String path) throws NexusException { 
    254201        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    255202        checkForNull(path); 
    256203        nxopengrouppath(handle,path); 
    257204    } 
    258     /** 
    259      * return the current path into the NeXus file in the  
    260      * form of a Unix path string. 
    261      * @return A unix path string 
    262      */ 
    263     public String getpath() throws NexusException  
    264     { 
     205 
     206    public String getpath() throws NexusException { 
    265207        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    266208        return nxgetpath(handle); 
    267209    } 
    268     /** 
    269       * closegroup closes access to the current group and steps down one 
    270       * step in group hierarchy. 
    271       * @exception NexusException when an HDF error occurs during this 
    272       * operation.  
    273       */ 
    274     public void closegroup() throws  
    275                              NexusException 
    276     { 
     210 
     211    public void closegroup() throws NexusException { 
    277212        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    278213        nxclosegroup(handle); 
     
    281216    // data set handling 
    282217    // native methods for this section 
    283     protected native void nxmakedata(int handle, String name, int type, 
    284                                   int rank, int dim[]); 
    285     protected native void nxmakecompdata(int handle, String name, int type, 
    286                                   int rank, int dim[], int iCompress,  
    287                                   int iChunk[]); 
     218    protected native void nxmakedata(int handle, String name, int type, int rank, int dim[]); 
     219    protected native void nxmakedata64(int handle, String name, int type, int rank, long dim[]); 
     220    protected native void nxmakecompdata(int handle, String name, int type, int rank, int dim[], int iCompress, int iChunk[]); 
     221    protected native void nxmakecompdata64(int handle, String name, int type, int rank, long dim[], int iCompress, long iChunk[]); 
    288222    protected native void nxopendata(int handle, String name); 
    289223    protected native void nxclosedata(int handle); 
    290224    protected native void nxcompress(int handle, int compression_type); 
    291     /** 
    292       * compmakedata creates a new dataset with the specified characteristics  
    293       * in the current group. This data set will be compressed. 
    294       * @param name The name of the dataset. 
    295       * @param type The number type of the dataset. Usually a constant from 
    296       * a selection of values. 
    297       * @param rank The rank or number of dimensions of the dataset. 
    298       * @param dim An array containing the length of each dimension. dim must 
    299       * have at least rank entries. The first dimension can be -1 which 
    300       * means it is an unlimited dimension. 
    301       * @param compression_type determines the compression type.  
    302       * @param iChunk With HDF-5, slabs can be written to compressed data  
    303       * sets. The size of these slabs is specified through the chunk array. 
    304       * This must have the rank values for the size of the chunk to 
    305       * be written in each dimension.  
    306       * @exception NexusException when the dataset could not be created. 
    307       */  
     225 
    308226    public void compmakedata(String name, int type, int rank, int dim[], 
    309                              int compression_type, int iChunk[]) throws 
    310                              NexusException { 
    311         if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     227                   int compression_type, int iChunk[]) throws NexusException { 
     228        if (handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    312229        checkType(type);     
    313230        checkForNull(name, rank, iChunk); 
    314         checkForNegInIntArray(true, dim, iChunk); 
     231        checkForNegInArray(true, dim, iChunk); 
    315232        switch(compression_type) { 
    316233        case NexusFile.NX_COMP_NONE: 
     
    324241    } 
    325242 
    326     /** 
    327       * makedata creates a new dataset with the specified characteristics  
    328       * in the current group. 
    329       * @param name The name of the dataset. 
    330       * @param type The number type of the dataset. Usually a constant from 
    331       * a selection of values. 
    332       * @param rank The rank or number of dimensions of the dataset. 
    333       * @param dim An array containing the length of each dimension. dim must 
    334       * have at least rank entries. The first dimension can be -1 which 
    335       * means it is an unlimited dimension. 
    336       * @exception NexusException when the dataset could not be created. 
    337       */  
     243    public void compmakedata(String name, int type, int rank, long dim[], 
     244                   int compression_type, long iChunk[]) throws NexusException { 
     245        if (handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     246        checkType(type);     
     247        checkForNull(name, rank, iChunk); 
     248        checkForNegInArray(true, dim, iChunk); 
     249        switch(compression_type) { 
     250        case NexusFile.NX_COMP_NONE: 
     251        case NexusFile.NX_COMP_LZW: 
     252            break; 
     253        default: 
     254            throw new NexusException("Invalid compression code requested"); 
     255 
     256        } 
     257        nxmakecompdata64(handle, name, type, rank, dim, compression_type, iChunk); 
     258    } 
     259 
    338260    public void makedata(String name, int type, int rank, int dim[]) throws 
    339                            NexusException 
    340     { 
     261                           NexusException { 
    341262        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    342263        checkType(type); 
    343264        checkForNull(name, dim); 
    344         checkForNegInIntArray(true, dim); 
     265        checkForNegInArray(true, dim); 
    345266        nxmakedata(handle, name, type, rank, dim); 
    346267    } 
    347     /** 
    348       * opendata opens an existing dataset for access. For instance for  
    349       * reading or writing. 
    350       * @param name The name of the dataset to open. 
    351       * @exception NexusException when the dataset does not exist or  
    352       * something else is wrong. 
    353       */ 
    354     public void  opendata(String name)throws  
    355                            NexusException 
    356     { 
     268 
     269    public void makedata(String name, int type, int rank, long dim[]) throws 
     270                           NexusException { 
     271        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     272        checkType(type); 
     273        checkForNull(name, dim); 
     274        checkForNegInArray(true, dim); 
     275        nxmakedata64(handle, name, type, rank, dim); 
     276    } 
     277 
     278    public void opendata(String name) throws NexusException { 
    357279        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    358280        checkForNull(name); 
    359281        nxopendata(handle,name); 
    360282    } 
    361     /** 
    362       * closedata closes an opened dataset. Then no further access is  
    363       * possible without a call to opendata. 
    364       * @exception NexusException when an HDF error occurrs. 
    365       */ 
    366     public void closedata() throws 
    367                            NexusException 
    368     { 
     283 
     284    public void closedata() throws NexusException { 
    369285        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    370286        nxclosedata(handle); 
    371287    } 
    372     /** 
    373       * causes the currently open dataset to be compressed on file. 
    374       * This must be called after makedata and before writing to the 
    375       * dataset. 
    376       * @param compression_type determines the type of compression  
    377       * to use. 
    378       * @exception NexusException when no dataset is open or an HDF error  
    379       * occurs. 
    380       */  
    381     public void compress(int compression_type) throws  
    382                            NexusException 
    383     { 
     288 
     289    public void compress(int compression_type) throws NexusException { 
    384290        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    385291        switch(compression_type) { 
     
    399305    // native methods in this section 
    400306    protected native void nxgetdata(int handle, byte bdata[]); 
    401     protected native void nxgetslab(int handle, int Start[], int size[], 
    402                                     byte bdata[]); 
    403     protected native void nxgetattr(int handle, String name, byte bdata[], 
    404                                     int args[]); 
    405     /** 
    406       * getdata reads the data from an previously openend dataset into 
    407       * array. 
    408       * @param array An n-dimensional array of the appropriate number 
    409       * type for the dataset. Make sure to have the right type and size 
    410       * here. 
    411       * @exception NexusException when either an HDF error occurs or  
    412       * no dataset is open or array is not of the right type to hold 
    413       * the data. 
    414       */ 
    415     public void getdata(Object array)throws  
    416                           NexusException 
    417     { 
     307    protected native void nxgetslab(int handle, int Start[], int size[], byte bdata[]); 
     308    protected native void nxgetslab64(int handle, long Start[], long size[], byte bdata[]); 
     309    protected native void nxgetattr(int handle, String name, byte bdata[], int args[]); 
     310 
     311    public void getdata(Object array) throws NexusException { 
    418312        byte bdata[]; 
    419313        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     
    428322         } 
    429323    } 
    430     /** 
    431       * getslab reads a subset of a large dataset into array. 
    432       * @param start An array of dimension rank which contains the start  
    433       * position in the dataset from where to start reading. 
    434       * @param size An array of dimension rank which contains the size  
    435       * of the dataset subset in each dimension to read. 
    436       * @param array An array for holding the returned data values. 
    437       * @exception NexusException when either an HDF error occurs or  
    438       * no dataset is open or array is not of the right type to hold 
    439       * the data. 
    440       */ 
    441     public void getslab(int start[], int size[],Object array)throws 
    442                           NexusException 
    443     { 
     324 
     325    public void getslab(int start[], int size[], Object array) throws NexusException { 
    444326        byte bdata[]; 
    445327        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    446328        checkForNull(start, size, array); 
    447         checkForNegInIntArray(false, start, size); 
     329        checkForNegInArray(false, start, size); 
    448330        try{ 
    449331            HDFArray ha = new HDFArray(array); 
     
    455337         } 
    456338    } 
    457     /** 
    458       * getattr retrieves the data associated with the attribute  
    459       * name.  
    460       * @param name The name of the attribute. 
    461       * @param array an array with sufficient space for holding the attribute  
    462       * data. 
    463       * @param args An integer array of dimension rank which holds the 
    464       * length of the array as first value and the type as the last 
    465       * value. Both values will be updated during reading. 
    466       * @exception NexusException when either an HDF error occurs or  
    467       * the attribute could not be found. 
    468       */ 
    469     public void getattr(String name, Object array, int args[])throws 
    470                           NexusException 
    471     { 
     339 
     340    public void getslab(long start[], long size[], Object array) throws NexusException { 
     341        byte bdata[]; 
     342        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     343        checkForNull(start, size, array); 
     344        checkForNegInArray(false, start, size); 
     345        try{ 
     346            HDFArray ha = new HDFArray(array); 
     347            bdata = ha.emptyBytes(); 
     348            nxgetslab64(handle,start,size,bdata); 
     349            array = ha.arrayify(bdata); 
     350         }catch(HDFException he) { 
     351           throw new NexusException(he.getMessage()); 
     352         } 
     353    } 
     354 
     355    public void getattr(String name, Object array, int args[]) throws NexusException { 
    472356        byte bdata[]; 
    473357        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     
    487371    // native methods for this section 
    488372    protected native void nxputdata(int handle, byte array[]);  
    489     protected native void nxputslab(int handle, byte array[],  
    490                                     int start[],int size[]);  
    491     protected native void nxputattr(int handle, String name, 
    492                                     byte array[], int type);  
    493  
    494     /** 
    495       * putdata writes the data from array into a previously opened 
    496       * dataset. 
    497       * @param array The data to write. 
    498       * @exception NexusException when an HDF error occurs. 
    499       */ 
    500     public void putdata(Object array) throws  
    501                           NexusException 
    502     { 
     373    protected native void nxputslab(int handle, byte array[], int start[], int size[]);  
     374    protected native void nxputslab64(int handle, byte array[], long start[], long size[]);  
     375    protected native void nxputattr(int handle, String name, byte array[], int type);  
     376 
     377    public void putdata(Object array) throws NexusException { 
    503378       byte data[]; 
    504379 
     
    506381           checkForNull(array); 
    507382 
    508        try{ 
     383       try { 
    509384           HDFArray ha =  new HDFArray(array); 
    510385           data = ha.byteify(); 
    511386           ha = null; 
    512        }catch(HDFException he) { 
     387       } catch (HDFException he) { 
    513388           throw new NexusException(he.getMessage()); 
    514389       } 
     
    516391       data = null; 
    517392    } 
    518     /** 
    519       * putslab writes a subset of a larger dataset to a previously opened 
    520       * dataset. 
    521       * @param array The data to write. 
    522       * @param start An integer array of dimension rank which holds the 
    523       * startcoordinates of the data subset in the larger dataset. 
    524       * @param size An integer array of dimension rank which holds the 
    525       * size in each dimension of the data subset to write. 
    526       * @exception NexusException when an HDF error occurs. 
    527       */  
    528     public void putslab(Object array, int start[], int size[]) throws 
    529                           NexusException 
    530     { 
     393 
     394    public void putslab(Object array, int start[], int size[]) throws NexusException { 
    531395       byte data[]; 
    532396 
    533397       if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    534398       checkForNull(array, start, size); 
    535        checkForNegInIntArray(false, start,size); 
    536        try{ 
     399       checkForNegInArray(false, start, size); 
     400       try { 
    537401           HDFArray ha =  new HDFArray(array); 
    538402           data = ha.byteify(); 
    539403           ha = null; 
    540        }catch(HDFException he) { 
     404       } catch(HDFException he) { 
    541405           throw new NexusException(he.getMessage()); 
    542406       } 
     
    544408       data = null; 
    545409    } 
    546     /** 
    547       * putattr adds a named attribute to a previously opened dataset or 
    548       * a global attribute if no dataset is open. 
    549       * @param name The name of the attribute. 
    550       * @param array The data of the attribute. 
    551       * @param iType The number type of the attribute. 
    552       * @exception NexusException if an HDF error occurs. 
    553       */   
    554     public void putattr(String name, Object array, int iType) throws 
    555                           NexusException 
    556     { 
     410 
     411    public void putslab(Object array, long start[], long size[]) throws NexusException { 
     412       byte data[]; 
     413 
     414       if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     415       checkForNull(array, start, size); 
     416       checkForNegInArray(false, start, size); 
     417       try { 
     418           HDFArray ha =  new HDFArray(array); 
     419           data = ha.byteify(); 
     420           ha = null; 
     421       } catch(HDFException he) { 
     422           throw new NexusException(he.getMessage()); 
     423       } 
     424       nxputslab64(handle,data,start,size); 
     425       data = null; 
     426    } 
     427 
     428    public void putattr(String name, Object array, int iType) throws NexusException { 
    557429       byte data[]; 
    558430 
     
    574446    //native methods for this section 
    575447    protected native void nxgetinfo(int handle, int iDim[], int args[]); 
     448    protected native void nxgetinfo64(int handle, long iDim[], int args[]); 
    576449    protected native void nxsetnumberformat(int handle, int type,  
    577450                                            String format); 
     
    580453    protected native void initattrdir(int handle); 
    581454    protected native void initgroupdir(int handle); 
    582     /** 
    583      * setnumberformat sets the number format for printing number when 
    584      * using the XML-NeXus format. For HDF4 and HDF5 this is ignored. 
    585      * If a dataset is open, the format for the dataset is set, if none  
    586      * is open the default setting for the number type is changed. 
    587      * The format must be a ANSII-C language format string. 
    588      * @param type The NeXus type to set the format for.  
    589      * @param format The new format to use. 
    590      */ 
    591     public void setnumberformat(int type, String format)  
    592         throws NexusException{ 
     455 
     456    public void setnumberformat(int type, String format) throws NexusException { 
    593457       if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    594458       checkType(type); 
     
    596460       nxsetnumberformat(handle,type,format); 
    597461    } 
    598     /** 
    599       * getinfo retrieves information about a previously opened dataset. 
    600       * @param iDim An array which will be filled with the size of 
    601       * the dataset in each dimension. 
    602       * @param args An integer array which will hold more information about 
    603       * the dataset after return. The fields: args[0] is the rank, args[1] is 
    604       * the number type. 
    605       * @exception NexusException when  an HDF error occurs. 
    606       */  
    607     public void getinfo(int iDim[], int args[]) throws  
    608                           NexusException 
    609     { 
     462 
     463    public void getinfo(int iDim[], int args[]) throws NexusException { 
    610464       if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    611465       nxgetinfo(handle,iDim,args); 
    612466    } 
    613     /** 
    614       * groupdir will retrieve the content of the currently open vGroup. 
    615       * groupdir is similar to an ls in unix.  
    616       * @return A Hashtable  which will hold the names of the items in  
    617       * the group as keys and the NeXus classname for vGroups or the  
    618       * string 'SDS' for datasets as values.  
    619       * @exception NexusException if an HDF error occurs 
    620       */ 
    621     public Hashtable groupdir()throws 
    622                           NexusException 
    623     { 
     467 
     468    public void getinfo(long iDim[], int args[]) throws NexusException { 
     469       if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     470       nxgetinfo64(handle,iDim,args); 
     471    } 
     472 
     473    public Hashtable groupdir() throws NexusException { 
    624474        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    625475        Hashtable h = new Hashtable(); 
    626476        String names[] = new String[2]; 
    627         int i; 
    628477 
    629478        initgroupdir(handle); 
    630         while(nextentry(handle,names) != -1) 
    631         { 
     479        while(nextentry(handle,names) != -1) { 
    632480           h.put(names[0],names[1]); 
    633481        } 
    634482        return h; 
    635483    } 
    636     /** 
    637       * attrdir returns the attributes of the currently open dataset or 
    638       * the file global attributes if no dataset is open. 
    639       * @return A Hashtable which will hold the names of the attributes 
    640       * as keys. For each key there is an AttributeEntry class as value. 
    641       * @exception NexusException when an HDF error occurs. 
    642       */  
    643     public Hashtable attrdir()throws 
    644                           NexusException 
    645     { 
     484 
     485    public Hashtable attrdir()throws NexusException { 
    646486        int args[] = new int[2]; 
    647487        AttributeEntry at; 
     
    668508    protected native void nxmakenamedlink(int handle, String name, NXlink target);  
    669509    protected native void nxopensourcepath(int handle);  
    670     /** 
    671       * getgroupID gets the data necessary for linking the current vGroup 
    672       * somewhere else. 
    673       * @return A NXlink class holding the link data. 
    674       * @exception NexusException if an HDF error occurs. 
    675       */ 
    676     public NXlink getgroupID() throws 
    677                           NexusException 
    678     { 
     510 
     511    public NXlink getgroupID() throws NexusException { 
    679512      if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    680513      NXlink l = new NXlink(); 
     
    682515      return l; 
    683516    } 
    684     /** 
    685       * getdataID gets the data necessary for linking the current dataset 
    686       * somewhere else. 
    687       * @return A NXlink class holding the link data. 
    688       * @exception NexusException if an HDF error occurs. 
    689       */ 
    690     public NXlink getdataID()throws 
    691                           NexusException 
    692     { 
     517 
     518    public NXlink getdataID()throws NexusException { 
    693519      if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    694520      NXlink l = new NXlink(); 
     
    696522      return l; 
    697523    } 
    698     /** 
    699       * makelink links the object described by target into the current 
    700       * vGroup. 
    701       * @param target The Object to link into the current group. 
    702       * @exception NexusException if an error occurs. 
    703       */ 
    704     public void   makelink(NXlink target)throws 
    705                           NexusException 
    706     { 
     524 
     525    public void makelink(NXlink target) throws NexusException { 
    707526      if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    708527      checkForNull(target); 
    709528      nxmakelink(handle, target); 
    710529    } 
    711     /** 
    712       * makenamedlink links the object described by target into the current 
    713       * vGroup. The object will have a new name in the group into which it is  
    714       * linked 
    715       * @param target The Object to link into the current group. 
    716       * @param name The name of this object in the current group 
    717       * @exception NexusException if an error occurs. 
    718       */ 
    719     public void   makenamedlink(String name, NXlink target)throws 
    720         NexusException { 
     530 
     531    public void makenamedlink(String name, NXlink target) throws NexusException { 
    721532      if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    722533      checkForNull(name, target); 
     
    724535    }      
    725536 
    726     /** 
    727       * opensourcepath opens the group from which the current item was linked 
    728       * Returns an error if the current item is not linked. 
    729       * @exception NexusException if an error occurs. 
    730       */ 
    731     public void opensourcepath()throws 
    732                           NexusException 
    733     { 
     537    public void opensourcepath() throws NexusException { 
    734538      if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    735539      nxopensourcepath(handle); 
     
    748552     * checks if any of the ints in the arrays are negative,  
    749553     * throws appropriate runtime exception if so 
    750      * for some being zero is stupid, but hopefully not fatal 
    751554     */ 
    752     private void checkForNegInIntArray(boolean allowUnlimited, int[]... args) { 
    753         boolean first=true; 
     555    private void checkForNegInArray(boolean allowUnlimited, int[]... args) { 
    754556        for (int[] array : args) 
    755557                for (int value: array) { 
    756558                        if (value<0) 
    757                                 if (value == this.NX_UNLIMITED && allowUnlimited && first) { 
     559                                if (value == this.NX_UNLIMITED && allowUnlimited) { 
    758560                                        // all ok this time 
    759561                                } else 
    760562                                        throw new IllegalArgumentException("negative dimension received"); 
    761                         first=false; 
    762563                } 
    763564    } 
     565 
     566    /** 
     567     * checks if any of the longs in the arrays are negative,  
     568     * throws appropriate runtime exception if so 
     569     */ 
     570    private void checkForNegInArray(boolean allowUnlimited, long[]... args) { 
     571        for (long[] array : args) 
     572                for (long value: array) { 
     573                        if (value<0) 
     574                                if (value == this.NX_UNLIMITED && allowUnlimited) { 
     575                                        // all ok this time 
     576                                } else 
     577                                        throw new IllegalArgumentException("negative dimension received"); 
     578                } 
     579    } 
     580 
    764581    /** 
    765582      * checkType verifies if a parameter is a valid NeXus type code.  
     
    768585      * @exception NexusException if the the type is no known type value 
    769586      */ 
    770     private void checkType(int type) throws NexusException 
    771     { 
     587    private void checkType(int type) throws NexusException { 
    772588        switch(type) { 
    773589        case NexusFile.NX_FLOAT32: 
     
    792608    protected native void nxinquirefile(int handle, String names[]); 
    793609    protected native void nxlinkexternal(int handle, String name, String nxclass, String nxurl); 
     610    protected native void nxlinkexternaldataset(int handle, String name, String nxurl); 
    794611    protected native int nxisexternalgroup(int handle, String name, String nxclass, String nxurl[]);  
    795     /** 
    796      * inquirefile inquires which file we are currently in. This is 
    797      * a support function for external linking 
    798      * @return The current file 
    799      * @throws NexusException when things are wrong 
    800      */ 
     612    protected native int nxisexternaldataset(int handle, String name, String nxurl[]);  
     613 
    801614    public String inquirefile() throws NexusException { 
    802615        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     
    805618        return names[0]; 
    806619    } 
    807     /**  
    808      * linkexternal links group name, nxclass to the URL nxurl 
    809      * @param name The name of the vgroup to link to 
    810      * @param nxclass The class name of the linked vgroup 
    811      * @param nxurl The URL to the linked external file 
    812      * @throws NexusException if things are wrong 
    813      */ 
    814     public void linkexternal(String name, String nxclass, String nxurl) throws NexusException{ 
     620 
     621    public void linkexternal(String name, String nxclass, String nxurl) throws NexusException { 
    815622        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    816623        checkForNull(name, nxclass, nxurl); 
    817624        nxlinkexternal(handle,name,nxclass,nxurl); 
    818625    } 
    819     /** 
    820      * nxisexternalgroup test the group name, nxclass if it is linked externally. 
    821      * @param name of the group to test 
    822      * @param  nxclass class of the group to test 
    823      * @return null when the group is not linked, else a string giving the URL of the 
    824      * linked file. 
    825      * @throws NexusException if things are wrong 
    826      */ 
    827     public String isexternalgroup(String name, String nxclass) throws NexusException{ 
    828         if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     626 
     627    public void linkexternaldataset(String name, String nxurl) throws NexusException { 
     628        if(handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     629        checkForNull(name, nxurl); 
     630        nxlinkexternaldataset(handle,name,nxurl); 
     631    } 
     632 
     633    public String isexternalgroup(String name, String nxclass) throws NexusException { 
     634        if (handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
    829635        checkForNull(name, nxclass); 
    830636        String nxurl[] = new String[1]; 
    831637 
    832638        int status = nxisexternalgroup(handle,name,nxclass,nxurl); 
    833         if(status == 1){ 
     639        if (status == 1) { 
     640            return nxurl[0]; 
     641        } else { 
     642            return null; 
     643        } 
     644    } 
     645 
     646    public String isexternaldataset(String name) throws NexusException { 
     647        if (handle < 0) throw new NexusException("NAPI-ERROR: File not open"); 
     648        checkForNull(name); 
     649        String nxurl[] = new String[1]; 
     650 
     651        int status = nxisexternaldataset(handle,name,nxurl); 
     652        if (status == 1) { 
    834653            return nxurl[0]; 
    835654        } else { 
  • trunk/include/napi.h

    r1731 r1734  
    2626 ----------------------------------------------------------------------------*/ 
    2727/** \file  
    28  * Documentation for the NeXus-API version 4.2 
    29  * 2000-2007, the NeXus group 
     28 * Documentation for the NeXus-API version 4.3 
     29 * 2000-2011, the NeXus International Advisory Commitee 
    3030 * \defgroup c_main C API  
    3131 * \defgroup c_types Data Types 
Note: See TracChangeset for help on using the changeset viewer.