cdm/src/main/java/ucar/nc2/iosp/NCheader.java
static public int
    checkFileType(ucar.unidata.io.RandomAccessFile raf)
            throws IOException
    {
        int format = 0;

        byte[] magic = new byte[MAGIC_NUMBER_LEN];

        // If this is not an HDF5 file, then the magic number is at
        // position 0; If it is an HDF5 file, then we need to search
        // forward for it.

        // Look for the relevant leading tag
        raf.seek(0);
        if(raf.readBytes(magic, 0, MAGIC_NUMBER_LEN) < MAGIC_NUMBER_LEN)
            return 0; // unknown
        // Some version of CDF
        int hdrlen = 0;
        hdrlen = CDF1HEAD.length; // all CDF headers are assumed to be same length
        format = 0;
        if(memequal(CDF1HEAD, magic, CDF1HEAD.length))
            format = NC_FORMAT_CLASSIC;
        else if(memequal(CDF2HEAD, magic, CDF2HEAD.length))
            format = NC_FORMAT_64BIT_OFFSET;
        else if(memequal(CDF5HEAD, magic, CDF5HEAD.length))
            format = NC_FORMAT_CDF5;
        else if(memequal(H4HEAD, magic, H4HEAD.length))
            format = NC_FORMAT_HDF4;
        if(format != 0) {
            raf.seek(hdrlen);
            return format;
        }
        // For HDF5, we need to search forward
        format = 0;
        long filePos = 0;
        long size = raf.length();
        while((filePos < size - 8) && (filePos < MAXHEADERPOS)) {
            boolean match;
            raf.seek(filePos);
            if(raf.readBytes(magic, 0, MAGIC_NUMBER_LEN) < MAGIC_NUMBER_LEN)
                return 0; // unknown
            // Test for HDF5
            if(memequal(H5HEAD, magic, H5HEAD.length)) {
                format = NC_FORMAT_HDF5;
                break;
            }
            filePos = (filePos == 0) ? 512 : 2 * filePos;
        }
        if(format != 0)
            raf.seek(filePos + H5HEAD.length);
        return format;
    }
static public int
    checkFileType(ucar.unidata.io.RandomAccessFile raf)
            throws IOException
    {
        int format = 0;

        byte[] magic = new byte[MAGIC_NUMBER_LEN];

        // If this is not an HDF5 file, then the magic number is at
        // position 0; If it is an HDF5 file, then we need to search
        // forward for it.

        // Look for the relevant leading tag
        raf.seek(0);
        if(raf.readBytes(magic, 0, MAGIC_NUMBER_LEN) < MAGIC_NUMBER_LEN)
            return 0; // unknown
        // Some version of CDF
        int hdrlen = 0;
        hdrlen = CDF1HEAD.length; // all CDF headers are assumed to be same length
        format = 0;
        if(memequal(CDF1HEAD, magic, CDF1HEAD.length))
            format = NC_FORMAT_CLASSIC;
        else if(memequal(CDF2HEAD, magic, CDF2HEAD.length))
            format = NC_FORMAT_64BIT_OFFSET;
        else if(memequal(CDF5HEAD, magic, CDF5HEAD.length))
            format = NC_FORMAT_CDF5;
        else if(memequal(H4HEAD, magic, H4HEAD.length))
            format = NC_FORMAT_HDF4;
        if(format != 0) {
            raf.seek(hdrlen);
            return format;
        }
        // For HDF5, we need to search forward
        format = 0;
        long filePos = 0;
        long size = raf.length();
        while((filePos < size - 8) && (filePos < MAXHEADERPOS)) {
            boolean match;
            raf.seek(filePos);
            if(raf.readBytes(magic, 0, MAGIC_NUMBER_LEN) < MAGIC_NUMBER_LEN)
                return 0; // unknown
            // Test for HDF5
            if(memequal(H5HEAD, magic, H5HEAD.length)) {
                format = NC_FORMAT_HDF5;
                break;
            }
            filePos = (filePos == 0) ? 512 : 2 * filePos;
        }
        if(format != 0)
            raf.seek(filePos + H5HEAD.length);
        return format;
    }
static public int checkFileType ( ucar . unidata . io . RandomAccessFile raf ) throws IOException { int format = 0 ; byte [ ] magic = new byte [ MAGIC_NUMBER_LEN ] ; // If this is not an HDF5 file, then the magic number is at // position 0; If it is an HDF5 file, then we need to search // forward for it. // Look for the relevant leading tag raf . seek ( 0 ) ; if ( raf . readBytes ( magic , 0 , MAGIC_NUMBER_LEN ) < MAGIC_NUMBER_LEN ) return 0 ; // unknown // Some version of CDF int hdrlen = 0 ; hdrlen = CDF1HEAD . length ; // all CDF headers are assumed to be same length format = 0 ; if ( memequal ( CDF1HEAD , magic , CDF1HEAD . length ) ) format = NC_FORMAT_CLASSIC ; else if ( memequal ( CDF2HEAD , magic , CDF2HEAD . length ) ) format = NC_FORMAT_64BIT_OFFSET ; else if ( memequal ( CDF5HEAD , magic , CDF5HEAD . length ) ) format = NC_FORMAT_CDF5 ; else if ( memequal ( H4HEAD , magic , H4HEAD . length ) ) format = NC_FORMAT_HDF4 ; if ( format != 0 ) { raf . seek ( hdrlen ) ; return format ; } // For HDF5, we need to search forward format = 0 ; long filePos = 0 ; long size = raf . length ( ) ; while ( ( filePos < size - 8 ) && ( filePos < MAXHEADERPOS ) ) { boolean match ; raf . seek ( filePos ) ; if ( raf . readBytes ( magic , 0 , MAGIC_NUMBER_LEN ) < MAGIC_NUMBER_LEN ) return 0 ; // unknown // Test for HDF5 if ( memequal ( H5HEAD , magic , H5HEAD . length ) ) { format = NC_FORMAT_HDF5 ; break ; } filePos = ( filePos == 0 ) ? 512 : 2 * filePos ; } if ( format != 0 ) raf . seek ( filePos + H5HEAD . length ) ; return format ; }
Figure out what kind of netcdf-related file we have.
Constraint: leave raf read pointer to point just after
the magic number.

@param raf to test type
@return
@throws IOException
Figure out what kind of netcdf - related file we have . Constraint : leave raf read pointer to point just after the magic number .