/*
==============
GetToken
==============
*/
qboolean GetToken (qboolean crossline)
{
	char    *token_p;

	if (tokenready)                         // is a token allready waiting?
	{
		tokenready = false;
		return true;
	}

	// printf("script_p %x (%x)\n", script->script_p, script->end_p ); fflush( stdout );

	if (script->script_p >= script->end_p)
	{
		return EndOfScript (crossline);
	}

	tokenready = false;

	// skip space, ctrl chars
skipspace:
	while (*script->script_p <= 32)
	{
		if (script->script_p >= script->end_p)
		{
			return EndOfScript (crossline);
		}
		if (*(script->script_p++) == '\n')
		{
			if (!crossline)
			{
				Error ("Line %i is incomplete\n",scriptline);
			}
			scriptline = ++script->line;
		}
	}

	if (script->script_p >= script->end_p)
	{
		return EndOfScript (crossline);
	}

	// strip single line comments
	if (*script->script_p == ';' || *script->script_p == '#' ||		 // semicolon and # is comment field
		(*script->script_p == '/' && *((script->script_p)+1) == '/')) // also make // a comment field
	{											
		if (!crossline)
			Error ("Line %i is incomplete\n",scriptline);
		while (*script->script_p++ != '\n')
		{
			if (script->script_p >= script->end_p)
			{
				return EndOfScript (crossline);
			}
		}
		scriptline = ++script->line;
		goto skipspace;
	}

	//  strip out matching /* */ comments
	if (*script->script_p == '/' && *((script->script_p)+1) == '*')
	{
		script->script_p += 2;
		while (*script->script_p != '*' || *((script->script_p)+1) != '/')
		{
			if (*script->script_p++ != '\n')
			{
				if (script->script_p >= script->end_p)
				{
					return EndOfScript (crossline);
				}

				scriptline = ++script->line;
			}
		}
		script->script_p += 2;
		goto skipspace;
	}

	// copy token to buffer
	token_p = token;

	if (*script->script_p == '"')
	{
		// quoted token
		script->script_p++;
		while (*script->script_p != '"')
		{
			*token_p++ = *script->script_p++;
			if (script->script_p == script->end_p)
				break;
			if (token_p == &token[MAXTOKEN])
				Error ("Token too large on line %i\n",scriptline);
		}
		script->script_p++;
	}
	else	// regular token
	while ( *script->script_p > 32 && *script->script_p != ';')
	{
		if ( !ExpandMacroToken( token_p ) )
		{
			if ( !ExpandVariableToken( token_p ) )
			{
				*token_p++ = *script->script_p++;
				if (script->script_p == script->end_p)
					break;
				if (token_p == &token[MAXTOKEN])
					Error ("Token too large on line %i\n",scriptline);

			}
		}
	}

	// add null to end of token
	*token_p = 0;

	// check for other commands
	if (!stricmp (token, "$include"))
	{
		GetToken (false);
		AddScriptToStack (token);
		return GetToken (crossline);
	}
	else if (!stricmp (token, "$definemacro"))
	{
		GetToken (false);
		DefineMacro(token);
		return GetToken (crossline);
	}
	else if (!stricmp (token, "$definevariable"))
	{
		GetToken (false);
		DefineVariable(token);
		return GetToken (crossline);
	}
	else if (AddMacroToStack( token ))
	{
		return GetToken (crossline);
	}

	return true;
}
示例#2
0
/*
==============
GetToken
==============
*/
qboolean GetToken (qboolean crossline)
{
	char    *token_p;

	if (tokenready)                         // is a token allready waiting?
	{
		tokenready = false;
		return true;
	}

	// printf("script_p %x (%x)\n", script->script_p, script->end_p ); fflush( stdout );

	if (script->script_p >= script->end_p)
	{
		return EndOfScript (crossline);
	}

	tokenready = false;

	// skip space, ctrl chars
skipspace:
	while (*script->script_p <= 32)
	{
		if (script->script_p >= script->end_p)
		{
			return EndOfScript (crossline);
		}
		if (*(script->script_p++) == '\n')
		{
			if (!crossline)
			{
				Error ("Line %i is incomplete\n",scriptline);
			}
			scriptline = ++script->line;
		}
	}

	if (script->script_p >= script->end_p)
	{
		return EndOfScript (crossline);
	}

	// strip single line comments
	if (*script->script_p == ';' || *script->script_p == '#' ||		 // semicolon and # is comment field
		(*script->script_p == '/' && *((script->script_p)+1) == '/')) // also make // a comment field
	{											
		if (!crossline)
			Error ("Line %i is incomplete\n",scriptline);
		while (*script->script_p++ != '\n')
		{
			if (script->script_p >= script->end_p)
			{
				return EndOfScript (crossline);
			}
		}
		scriptline = ++script->line;
		goto skipspace;
	}

	//  strip out matching /* */ comments
	if (*script->script_p == '/' && *((script->script_p)+1) == '*')
	{
		script->script_p += 2;
		while (*script->script_p != '*' || *((script->script_p)+1) != '/')
		{
			if (*script->script_p++ != '\n')
			{
				if (script->script_p >= script->end_p)
				{
					return EndOfScript (crossline);
				}

				scriptline = ++script->line;
			}
		}
		script->script_p += 2;
		goto skipspace;
	}

	// copy token to buffer
	token_p = token;

	if (*script->script_p == '"')
	{
		// quoted token
		script->script_p++;
		while (*script->script_p != '"')
		{
			*token_p++ = *script->script_p++;
			if (script->script_p == script->end_p)
				break;
			if (token_p == &token[MAXTOKEN])
				Error ("Token too large on line %i\n",scriptline);
		}
		script->script_p++;
	}
	else if ( g_bCheckSingleCharTokens && !g_sSingleCharTokens.IsEmpty() && strchr( g_sSingleCharTokens.String(), *script->script_p ) != NULL )
	{
		*token_p++ = *script->script_p++;
	}
	else	// regular token
	while ( *script->script_p > 32 && *script->script_p != ';')
	{
		if ( !ExpandMacroToken( token_p ) )
		{
			if ( !ExpandVariableToken( token_p ) )
			{
				*token_p++ = *script->script_p++;
				if (script->script_p == script->end_p)
					break;
				if (token_p == &token[MAXTOKEN])
					Error ("Token too large on line %i\n",scriptline);

			}
		}
	}

	// add null to end of token
	*token_p = 0;

	// check for other commands
	if ( !stricmp( token, "$include" ) )
	{
		GetToken( false );

		bool bFallbackToToken = true;

		CUtlVector< CUtlString > expandedPathList;

		if ( CmdLib_ExpandWithBasePaths( expandedPathList, token ) > 0 )
		{
			for ( int i = 0; i < expandedPathList.Count(); ++i )
			{
				CUtlVector< CUtlString > findFileList;
				FindFileAbsoluteList( findFileList, expandedPathList[i].String() );

				if ( findFileList.Count() > 0 )
				{
					bFallbackToToken = false;

					// Only add the first set of glob matches from the first base path
					for ( int j = 0; j < findFileList.Count(); ++j )
					{
						AddScriptToStack( const_cast< char * >( findFileList[j].String() ) );
					}

					break;
				}
			}
		}

		if ( bFallbackToToken )
		{
			AddScriptToStack( token );
		}

		return GetToken( crossline );
	}
	else if (!stricmp (token, "$definemacro"))
	{
		GetToken (false);
		DefineMacro(token);
		return GetToken (crossline);
	}
	else if (!stricmp (token, "$definevariable"))
	{
		GetToken (false);
		DefineVariable(token);
		return GetToken (crossline);
	}
	else if (AddMacroToStack( token ))
	{
		return GetToken (crossline);
	}

	return true;
}
示例#3
0
bool CNetCDFTraj::WriteHeader(CAmberTopology* p_top)
{
    if( p_top == NULL ){
        INVALID_ARGUMENT("p_top == NULL");
    }

    if( NCID < 0 ) {
        ES_ERROR("file is not opened");
        return(false);
    }

    int dimensionID[NC_MAX_VAR_DIMS];

    NumOfTopologyAtoms = p_top->AtomList.GetNumberOfAtoms();
    ActualAtoms = NumOfTopologyAtoms;

    CurrentSnapshot = 0;
    TotalSnapshots = 0;
    if( Coordinates != NULL ) {
        delete Coordinates;
    }
    Coordinates = new float[ActualAtoms*3];

    // global dimmensions
    DefineDimension(AMBER_NETCDF_FRAME, NC_UNLIMITED, &TimeDID);
    DefineDimension(AMBER_NETCDF_SPATIAL, 3, &SpatialDID);
    DefineDimension(AMBER_NETCDF_ATOM, ActualAtoms, &CoordinateDID);
    DefineDimension(AMBER_NETCDF_LABEL, AMBER_NETCDF_LABELLEN, &LabelDID);
    DefineDimension(AMBER_NETCDF_CELL_SPATIAL, 3, &CellSpatialDID);
    DefineDimension(AMBER_NETCDF_CELL_ANGULAR, 3, &CellAngularDID);

    // put global attributes
    Conventions =  "AMBER";
    ConventionVersion = "1.0";

    PutAttributeText(NC_GLOBAL, "title", Title);
    PutAttributeText(NC_GLOBAL, "application", Application);
    PutAttributeText(NC_GLOBAL, "program", Program);
    PutAttributeText(NC_GLOBAL, "programVersion", Version);
    PutAttributeText(NC_GLOBAL, "Conventions", Conventions);
    PutAttributeText(NC_GLOBAL, "ConventionVersion", ConventionVersion);

    // handle definition of non-optional variables
    dimensionID[0] = SpatialDID;
    DefineVariable(AMBER_NETCDF_SPATIAL, NC_CHAR, 1, dimensionID, &SpatialVID);

    dimensionID[0] = TimeDID;
    DefineVariable(AMBER_NETCDF_TIME, NC_FLOAT, 1, dimensionID, &TimeVID);
    PutAttributeText(TimeVID, "units", "picosecond");

    dimensionID[0] = TimeDID;
    dimensionID[1] = CoordinateDID;
    dimensionID[2] = SpatialDID;
    DefineVariable(AMBER_NETCDF_COORDS, NC_FLOAT, 3, dimensionID, &CoordinateVID);
    PutAttributeText(CoordinateVID, "units", "angstrom");

    dimensionID[0] = CellSpatialDID;
    DefineVariable(AMBER_NETCDF_CELL_SPATIAL, NC_CHAR, 1, dimensionID, &CellSpatialVID);

    dimensionID[0] = CellAngularDID;
    dimensionID[1] = LabelDID;
    DefineVariable(AMBER_NETCDF_CELL_ANGULAR, NC_CHAR, 2, dimensionID, &CellAngularVID);

    // set up box coords
    HasBox = p_top->BoxInfo.GetType() != AMBER_BOX_NONE;

    if( HasBox ) {
        dimensionID[0] = TimeDID;
        dimensionID[1] = CellSpatialDID;
        DefineVariable("cell_lengths", NC_DOUBLE, 2, dimensionID, &CellLengthVID);
        PutAttributeText(CellLengthVID, "units", "angstrom");

        dimensionID[1] = CellAngularDID;
        DefineVariable("cell_angles", NC_DOUBLE, 2, dimensionID, &CellAngleVID);
        PutAttributeText(CellAngleVID, "units", "degree");
    }

    int err,oldMode;

    // set fill mode
    err = nc_set_fill(NCID, NC_NOFILL, &oldMode);
    if (err != NC_NOERR) {
        CSmallString error;
        error << "unable to set fill value (" << nc_strerror(err) << ")";
        ES_ERROR(error);
        return(false);
    }

    // end definition
    err = nc_enddef(NCID);
    if (err != NC_NOERR) {
        CSmallString error;
        error << "unable to end definitions (" << nc_strerror(err) << ")";
        ES_ERROR(error);
        return(false);
    }

    size_t start[3];
    size_t count[3];
    char xyz[3];
    char abc[15] = { 'a', 'l', 'p', 'h', 'a',
                     'b', 'e', 't', 'a', ' ',
                     'g', 'a', 'm', 'm', 'a' };

    // setup labels
    start[0] = 0;
    count[0] = 3;
    xyz[0] = 'x';
    xyz[1] = 'y';
    xyz[2] = 'z';
    err = nc_put_vara_text(NCID, SpatialVID, start, count, xyz);
    if (err != NC_NOERR) {
        CSmallString error;
        error << "unable to set spatial VID 'x', 'y' and 'z' (" << nc_strerror(err) << ")";
        ES_ERROR(error);
        return(false);
    }

    start[0] = 0;
    count[0] = 3;
    xyz[0] = 'a';
    xyz[1] = 'b';
    xyz[2] = 'c';
    err = nc_put_vara_text(NCID, CellSpatialVID, start, count, xyz);
    if (err != NC_NOERR) {
        CSmallString error;
        error << "unable to set spatial cell VID 'a', 'b' and 'c' (" << nc_strerror(err) << ")";
        ES_ERROR(error);
        return(false);
    }

    start[0] = 0;
    start[1] = 0;
    count[0] = 3;
    count[1] = 5;
    err = nc_put_vara_text(NCID, CellAngularVID, start, count, abc);
    if (err != NC_NOERR) {
        CSmallString error;
        error << "unable to set angular cell VID 'alpha', 'beta ' and 'gamma' (" << nc_strerror(err) << ")";
        ES_ERROR(error);
        return(false);
    }

    return(true);
}