예제 #1
0
int NASAKeywordHandler::ReadGroup( const char *pszPathPrefix )

{
    CPLString osName, osValue;

    for( ; TRUE; )
    {
        if( !ReadPair( osName, osValue ) )
            return FALSE;

        if( EQUAL(osName,"OBJECT") || EQUAL(osName,"GROUP") )
        {
            if( !ReadGroup( (CPLString(pszPathPrefix) + osValue + ".").c_str() ) )
                return FALSE;
        }
        else if( EQUALN(osName,"END",3) )
        {
            return TRUE;
        }
        else
        {
            osName = pszPathPrefix + osName;
            papszKeywordList = CSLSetNameValue( papszKeywordList, 
                                                osName, osValue );
        }
    }
}
예제 #2
0
void vargas::SAM::Header::parse(std::string hdr) {
    sorting_order = "";
    grouping = "";
    sequences.clear();
    read_groups.clear();
    programs.clear();

    std::vector<std::string> lines = split(hdr, '\n');

    // @HD line
    std::vector<std::string> tags = split(lines[0], '\t');
    if (tags[0] != "@HD") throw std::invalid_argument("First line must start with \"@HD\"");
    std::vector<std::string> pair;
    for (auto &p : tags) {
        if (p.at(0) == '@') continue;
        split(p, ':', pair);
        if (pair.size() != 2) continue;
        if (pair[0] == "VN") {
            version = pair[1];
        } else if (pair[0] == "SO") {
            sorting_order = pair[1];
        } else if (pair[0] == "GO") {
            grouping = pair[1];
        }
    }

    // Other lines
    for (auto &l : lines) {
        std::string tag = l.substr(0, 3);
        if (tag == "@SQ") add(Sequence(l));
        else if (tag == "@RG") add(ReadGroup(l));
        else if (tag == "@PG") add(Program(l));
    }
}
예제 #3
0
  /**
   * @brief extracts read group objects from a SAM header
   */
  vector<ReadGroup> SamHeader::read_groups() const {
    const static auto RG_TAG = "@RG";
    const static auto NOT_FOUND = string::npos;
    auto result = vector<ReadGroup>();
    auto text = header_text();

    for (auto rg_start=text.find(RG_TAG), rg_end=rg_start; rg_start!=NOT_FOUND; rg_start=text.find(RG_TAG,rg_end+1) ) {
      rg_end = text.find('\n', rg_start+1);
      auto rg_record = text.substr(rg_start, rg_end-rg_start);
      result.push_back(ReadGroup(rg_record));
    }
    return result;
  }
예제 #4
0
파일: AseFile.cpp 프로젝트: Mantora/GA
int AseFile::ReadAseFile()
{
	char temp[255];
	if(!file)return 0;

	while( fgets(temp, 255, file) )
	{
		if( EqualString( temp, "*MATERIAL_LIST") )		{	if(!ReadMaterial_List())return 0;}
		else if( EqualString( temp, "*GEOMOBJECT") )	{	if(!ReadGeomObject())return 0;}
		else if( EqualString( temp, "*GROUP") )			{	if(!ReadGroup())return 0;}
		else if( EqualString( temp, "*LIGHTOBJECT") )	{	if(!ReadLightObject())return 0;}
	//	else if( EqualString( temp, "*CAMERAOBJECT") )	{	if(!ReadCameraObject())return 0;}
		else ReadUnknown( temp);
	}
	return 1;
}
예제 #5
0
int NASAKeywordHandler::Ingest( FILE *fp, int nOffset )

{
/* -------------------------------------------------------------------- */
/*      Read in buffer till we find END all on it's own line.           */
/* -------------------------------------------------------------------- */
    if( VSIFSeekL( fp, nOffset, SEEK_SET ) != 0 )
        return FALSE;

    for( ; TRUE; ) 
    {
        const char *pszCheck;
        char szChunk[513];

        int nBytesRead = VSIFReadL( szChunk, 1, 512, fp );

        szChunk[nBytesRead] = '\0';
        osHeaderText += szChunk;

        if( nBytesRead < 512 )
            break;

        if( osHeaderText.size() > 520 )
            pszCheck = osHeaderText.c_str() + (osHeaderText.size() - 520);
        else
            pszCheck = szChunk;

        if( strstr(pszCheck,"\r\nEND\r\n") != NULL 
            || strstr(pszCheck,"\nEND\n") != NULL 
            || strstr(pszCheck,"\r\nEnd\r\n") != NULL 
            || strstr(pszCheck,"\nEnd\n") != NULL )
            break;
    }

    pszHeaderNext = osHeaderText.c_str();

/* -------------------------------------------------------------------- */
/*      Process name/value pairs, keeping track of a "path stack".      */
/* -------------------------------------------------------------------- */
    return ReadGroup( "" );
}
예제 #6
0
int CPLKeywordParser::Ingest( VSILFILE *fp )

{
/* -------------------------------------------------------------------- */
/*      Read in buffer till we find END all on it's own line.           */
/* -------------------------------------------------------------------- */
    for( ; TRUE; ) 
    {
        const char *pszCheck;
        char szChunk[513];

        int nBytesRead = VSIFReadL( szChunk, 1, 512, fp );

        szChunk[nBytesRead] = '\0';
        osHeaderText += szChunk;

        if( nBytesRead < 512 )
            break;

        if( osHeaderText.size() > 520 )
            pszCheck = osHeaderText.c_str() + (osHeaderText.size() - 520);
        else
            pszCheck = szChunk;

        if( strstr(pszCheck,"\r\nEND;\r\n") != NULL 
            || strstr(pszCheck,"\nEND;\n") != NULL )
            break;
    }

    pszHeaderNext = osHeaderText.c_str();

/* -------------------------------------------------------------------- */
/*      Process name/value pairs, keeping track of a "path stack".      */
/* -------------------------------------------------------------------- */
    return ReadGroup( "" );
}
예제 #7
0
int VICARKeywordHandler::Ingest( VSILFILE *fp, GByte *pabyHeader )

{
/* -------------------------------------------------------------------- */
/*      Read in buffer till we find END all on it's own line.           */
/* -------------------------------------------------------------------- */
    if( VSIFSeekL( fp, 0, SEEK_SET ) != 0 )
        return FALSE;

    // Find LBLSIZE Entry
    char* pszLBLSIZE = strstr((char*)pabyHeader,"LBLSIZE");
    int nOffset = 0;

    if (pszLBLSIZE)
        nOffset = pszLBLSIZE - (const char *)pabyHeader;

    char *pch1 = strstr((char*)pabyHeader+nOffset, "=");
    if( pch1 == NULL )
        return FALSE;

    ++pch1;
    char *pch2 = strstr((char*)pabyHeader+nOffset, " ");
    if( pch2 == NULL )
        return FALSE;

    char keyval[100];
    strncpy( keyval, pch1, MAX( pch2-pch1, 99 ) );
    keyval[MAX(pch2-pch1, 99)] = '\0';
    LabelSize = atoi( keyval );
    if( LabelSize > 10 * 1024 * 124 )
        return FALSE;

    char* pszChunk = (char*) VSIMalloc( LabelSize + 1 );
    if( pszChunk == NULL )
        return FALSE;
    int nBytesRead = VSIFReadL( pszChunk, 1, LabelSize, fp );
    pszChunk[LabelSize] = 0;

    osHeaderText += pszChunk ;
    VSIFree( pszChunk );
    pszHeaderNext = osHeaderText.c_str();

/* -------------------------------------------------------------------- */
/*      Process name/value pairs, keeping track of a "path stack".      */
/* -------------------------------------------------------------------- */
    if( !ReadGroup("") )
        return FALSE;
/* -------------------------------------------------------------------- */
/*      Now check for the Vicar End-of-Dataset Label...                 */
/* -------------------------------------------------------------------- */
    const char *pszResult = CSLFetchNameValue( papszKeywordList, "EOL" );
    if( pszResult == NULL )
        return FALSE;

    if( !EQUAL(pszResult,"1") )
        return TRUE;

/* -------------------------------------------------------------------- */
/*      There is a EOL!   e.G.  h4231_0000.nd4.06                       */
/* -------------------------------------------------------------------- */

    long int nPixelOffset=0;
    if (EQUAL( CSLFetchNameValue(papszKeywordList,"FORMAT" ), "BYTE" )) {
        nPixelOffset = 1;
    }
    else if (EQUAL( CSLFetchNameValue(papszKeywordList,"FORMAT" ), "HALF" )) {
        nPixelOffset = 2;
    }
    else if (EQUAL( CSLFetchNameValue(papszKeywordList,"FORMAT" ), "FULL" )) {
        nPixelOffset = 4;
    }
    else if (EQUAL( CSLFetchNameValue(papszKeywordList,"FORMAT" ), "REAL" )) {
        nPixelOffset = 4;
    }

    const long int nCols = atoi( CSLFetchNameValue( papszKeywordList, "NS" ) );
    const long int nRows = atoi( CSLFetchNameValue( papszKeywordList, "NL" ) );
    const int nBands = atoi( CSLFetchNameValue( papszKeywordList, "NB" ) );
    const int nBB = atoi( CSLFetchNameValue( papszKeywordList, "NBB" ) );

    long int nLineOffset = nPixelOffset * nCols + nBB ;
    long int nBandOffset = nLineOffset * nRows;

    long int starteol = LabelSize + nBandOffset * nBands;
    if( VSIFSeekL( fp, starteol, SEEK_SET ) != 0 )
    {
        printf("Error seeking to EOL!\n");
        return FALSE;
    }
    char szChunk[100];
    nBytesRead = VSIFReadL( szChunk, 1, 30, fp );
    szChunk[nBytesRead] = '\0';
    pszLBLSIZE = strstr( szChunk, "LBLSIZE" );
    nOffset = 0;

    if (pszLBLSIZE)
        nOffset = pszLBLSIZE - (const char *)szChunk;
    pch1 = strstr( (char*)szChunk + nOffset,"=" ) + 1;
    pch2 = strstr( (char*)szChunk + nOffset, " " );
    strncpy( keyval, pch1, pch2-pch1 );

    int EOLabelSize = atoi( keyval );
    if( EOLabelSize > 99 )
        EOLabelSize = 99;
    if( VSIFSeekL( fp, starteol, SEEK_SET ) != 0 )
    {
        printf("Error seeking again to EOL!\n");
        return FALSE;
    }

    nBytesRead = VSIFReadL( szChunk, 1, EOLabelSize, fp );
    szChunk[nBytesRead] = '\0';
    osHeaderText += szChunk ;
    osHeaderText.append("END");
    pszHeaderNext = osHeaderText.c_str();

    return ReadGroup( "" );
}
예제 #8
0
	inline
    ReadGroup ReadCollection :: getReadGroup ( const String & spec ) const
        throw ( ErrorMsg )
    { return ReadGroup ( self -> getReadGroup ( spec . c_str () ) ); }