int main()

{  
	int i;  //loop counter


	//header
	printf("MECH 7171 Engineering programming                %c\n",179); 
	printf("Lab #4                                           %c\n",179); 
	printf("Mark Naismith, A00819714, Set 5B                 %c\n",179);
	printf("Cyrus Ang,     A00781218, Set 5B                 %c\n",179);
	printf("Corbin Turner, A00780890, Set 5B                 %c\n",179);
	printf("December 6, 2013                                 %c\n",179);
	printf("This program reads data from a data.txt file and %c\n",179);
	printf("stores the data in a structure within the program%c\n",179);
	printf("that is transfered between modular functions.    %c\n",179);
	printf("The tasks that this program completes are the    %c\n",179); 
	printf("analytical solution to 2D conductive             %c\n",179); 
	printf("heat transfer probrlems as well as               %c\n",179); 
	printf("the numerical solutions. The end result is a     %c\n",179); 
	printf("given heat transfer problem                      %c\n",179); 
	printf("that is solved numerically.                      %c\n",179);

	//this loop "closes the box" of the header. Run program for details.
	for(i=0;i<49;i++)printf("%c",196); 
	printf("%c\n",217); 

	//creation of the structure for simulations. Holds all relevant data
	PROGRAMDATA pd;

	//File stream pointer for the input file. This will be passed to the GetProgramData
	//function for every simulation
	FILE *f;

	//Opens stream to the input file. Read only
	f=fopen(DATA_FILENAME, "r");

	//Check to see if the file exists, if not, exits function, main() complains
	if(f==NULL)
	{
		printf("Input file \"%s\" doesn't exist! Exiting...",DATA_FILENAME);
		getchar();
		return 5;   
	}

	i = 0;
	//The proceding blocks are all very similar. Only the first will be explained.
	do{
		i++;
		pd = GetProgramData(f);
		if (pd.run == 1)//Checks to see if user wants to run 
		{
			printf("\nRunning Simulation %d :\n", i);
			simulate(pd);
		}
	} while (pd.run != -1);

	// closes data file once all simulations are complete 
	//(could be closed before Given problem)
	fclose(f);

	//End Program
	printf("Press Enter to end the program....");
	fflush(stdin);//needed if the last file needed to be overwriten.
	getchar();
	return 0;
}
Пример #2
0
bool csShaderGLAVP::LoadProgramStringToGL ()
{
  if (!shaderPlug->ext)
    return false;

  const csGLExtensionManager* ext = shaderPlug->ext;

  if(!ext->CS_GL_ARB_vertex_program)
    return false;

  csRef<iDataBuffer> data = programBuffer;
  if (!data)
    data = GetProgramData();
  if (!data)
    return false;

  //step to first !!
  const char* programstring = (char*)data->GetData ();
  size_t stringlen = data->GetSize ();

  size_t i=0;
  while (*programstring != '!' && i<stringlen)
  {
    ++programstring;
    ++i;
  }
  stringlen -= i;

  ext->glGenProgramsARB(1, &program_num);
  ext->glBindProgramARB(GL_VERTEX_PROGRAM_ARB, program_num);
  
  ext->glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, 
    (GLsizei)stringlen, (void*) programstring);

  const GLubyte * programErrorString = glGetString(GL_PROGRAM_ERROR_STRING_ARB);

  GLint errorpos;
  glGetIntegerv (GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
  if(errorpos != -1)
  {
    int realErrorPos = 0;
    while (errorpos > 0)
    {
      if (programstring[realErrorPos] == '#')
      {
        while (programstring[realErrorPos] != '\n')
          realErrorPos++;
      }
      errorpos--;
      realErrorPos++;
    }

    CS_ALLOC_STACK_ARRAY (char, errorStart, strlen (programstring) + 1);
    strcpy (errorStart, programstring);

    char* start = errorStart + realErrorPos;
    /*while (start > errorStart)
    {
      if (*(start - 1) == '\n')
      {
	break;
      }
      start--;
    }*/

    char* end = strchr (start, '\n');
    if (end)
      *(end-1) = 0;

    if (doVerbose)
    {
      Report (CS_REPORTER_SEVERITY_WARNING, 
        "Couldn't load vertex program %s", CS::Quote::Double (description.GetDataSafe ()));
      Report (CS_REPORTER_SEVERITY_WARNING, "Program error at: %s", CS::Quote::Double (start));
      Report (CS_REPORTER_SEVERITY_WARNING, "Error string: %s", 
        CS::Quote::Single ((const char*)programErrorString));
    }
    return false;
  }
Пример #3
0
bool csShaderGLCGCommon::WriteToCacheWorker (iHierarchicalCache* cache,
  const ProfileLimits& limits, const ProfileLimitsPair& limitsPair, 
  const char* tag, const ProgramObject& program,
  csString& failReason)
{
  if (!cache) return false;

  csMemFile cacheFile;
  
  uint32 diskMagic = csLittleEndian::UInt32 (cacheFileMagic);
  if (cacheFile.Write ((char*)&diskMagic, sizeof (diskMagic))
      != sizeof (diskMagic))
  {
    failReason = "write error (magic)";
    return false;
  }
  
  csRef<iDataBuffer> programBuffer = GetProgramData();
  CS::Utility::Checksum::MD5::Digest progHash = CS::Utility::Checksum::MD5::Encode (
    programBuffer->GetData(), programBuffer->GetSize());
  if (cacheFile.Write ((char*)&progHash, sizeof (progHash))
      != sizeof (progHash))
  {
    failReason = "write error (hash)";
    return false;
  }
  
  if (!program.IsValid())
  {
    uint32 diskState = csLittleEndian::UInt32 (cpsInvalid);
    if (cacheFile.Write ((char*)&diskState, sizeof (diskState))
	!= sizeof (diskState))
    {
      failReason = "write error (state-invalid)";
      return false;
    }
  }
  else
  {
    {
      uint32 diskState = csLittleEndian::UInt32 (cpsValid);
      if (cacheFile.Write ((char*)&diskState, sizeof (diskState))
	  != sizeof (diskState))
      {
	failReason = "write error (state-valid)";
	return false;
      }
    }
    
    CS::PluginCommon::ShaderCacheHelper::WriteString (&cacheFile, description);
    
    CS_ASSERT(!program.GetID().archive.IsEmpty());
    CS::PluginCommon::ShaderCacheHelper::WriteString (&cacheFile,
      program.GetID().archive);
    CS_ASSERT(!program.GetID().item.IsEmpty());
    CS::PluginCommon::ShaderCacheHelper::WriteString (&cacheFile,
      program.GetID().item);
  }
  
  csString cacheName ("/");
  cacheName += tag;
  if (!cache->CacheData (cacheFile.GetData(), cacheFile.GetSize(),
    cacheName))
  {
    failReason = "failed writing to cache";
    return false;
  }
  return true;
}
Пример #4
0
iShaderProgram::CacheLoadResult csShaderGLCGCommon::LoadFromCache (
  iHierarchicalCache* cache, iBase* previous, iDocumentNode* node,
  csRef<iString>* failReason, csRef<iString>* tag,
  ProfileLimitsPair* cacheLimits)
{
  if (!cache) return iShaderProgram::loadFail;

  csRef<iShaderProgramCG> prevCG (scfQueryInterfaceSafe<iShaderProgramCG> (
    previous));

  csRef<iStringArray> allCachedPrograms;
  if ((programType == progVP) && prevCG.IsValid())
  {
    csShaderGLCGFP* prevFP = static_cast<csShaderGLCGFP*> (
      (iShaderProgramCG*)prevCG);
    csString tagStr ("CG");
    tagStr += prevFP->cacheLimits.ToString();
    if (failReason) failReason->AttachNew (
      new scfString ("paired cached programs not found"));
    allCachedPrograms.AttachNew (new scfStringArray);
    allCachedPrograms->Push (tagStr);
  }
  else
    allCachedPrograms = cache->GetSubItems ("/");

  if (!allCachedPrograms.IsValid() || (allCachedPrograms->GetSize() == 0))
  {
    if (failReason) failReason->AttachNew (
      new scfString ("no cached programs found"));
    return iShaderProgram::loadFail;
  }
  
  if (!GetProgramNode (node)) return iShaderProgram::loadFail;
  csRef<iDataBuffer> programBuffer = GetProgramData();
  CS::Utility::Checksum::MD5::Digest progHash = CS::Utility::Checksum::MD5::Encode (
    programBuffer->GetData(), programBuffer->GetSize());
  
  csArray<CachedShaderWrapper> cachedProgWrappers;
  for (size_t i = 0; i < allCachedPrograms->GetSize(); i++)
  {
    const char* tag = allCachedPrograms->Get (i);
    if ((tag[0] != 'C') || (tag[1] != 'G')) continue;

    CachedShaderWrapper wrapper;
    if (!wrapper.limits.FromString (tag+2)) continue;
    wrapper.name = tag;

    csString cachePath ("/");
    cachePath.Append (tag);
    csRef<iDataBuffer> cacheBuf = cache->ReadCache (cachePath);
    if (!cacheBuf.IsValid()) continue;
    
    csRef<iFile> cacheFile;
    cacheFile.AttachNew (new csMemFile (cacheBuf, true));
    wrapper.cacheFile = cacheFile;
  
    uint32 diskMagic;
    if (cacheFile->Read ((char*)&diskMagic, sizeof (diskMagic))
	!= sizeof (diskMagic)) continue;
    if (csLittleEndian::UInt32 (diskMagic) != cacheFileMagic)
      continue;
      
    CS::Utility::Checksum::MD5::Digest diskHash;
    if (cacheFile->Read ((char*)&diskHash, sizeof (diskHash))
	!= sizeof (diskHash)) continue;
    if (diskHash != progHash) continue;
    
    cachedProgWrappers.Push (wrapper);
  }
  
  if (cachedProgWrappers.GetSize() == 0)
  {
    if (failReason && !*failReason) failReason->AttachNew (
      new scfString ("all cached programs failed to read"));
    return iShaderProgram::loadFail;
  }
  
  cachedProgWrappers.Sort ();

  ProfileLimits currentLimits (
    (programType == progVP) ? shaderPlug->currentLimits.vp 
      : shaderPlug->currentLimits.fp);
  bool strictMatch = (programType == progVP) ? shaderPlug->strictMatchVP 
      : shaderPlug->strictMatchFP;
  const char* progTypeNode = 0;
  switch (programType)
  {
    case progVP: progTypeNode = "cgvp"; break;
    case progFP: progTypeNode = "cgfp"; break;
  }
  
  csString allReasons;
  bool oneReadCorrectly = false;
  ProfileLimits bestLimits (
    CS::PluginCommon::ShaderProgramPluginGL::Other,
    CG_PROFILE_UNKNOWN);
  bool bestLimitsSet = false;
  for (size_t i = cachedProgWrappers.GetSize(); i-- > 0;)
  {
    const CachedShaderWrapper& wrapper = cachedProgWrappers[i];
    const ProfileLimits& limits =
      (programType == progVP) ? wrapper.limits.vp : wrapper.limits.fp;

    if (!bestLimitsSet)
    {
      bestLimits = limits;
      bestLimitsSet = true;
    }
      
    if (strictMatch && (limits != currentLimits))
    {
      allReasons += wrapper.name;
      allReasons += ": strict mismatch; ";
      continue;
    }
  
    bool profileSupported =
      (shaderPlug->ProfileNeedsRouting (limits.profile)
        && shaderPlug->IsRoutedProfileSupported (limits.profile))
      || cgGLIsProfileSupported (limits.profile);
    if (!profileSupported)
    {
      allReasons += wrapper.name;
      allReasons += ": Profile unsupported; ";
      continue;
    }
    
    if ((limits.vendor != currentLimits.vendor)
        && (limits.vendor != CS::PluginCommon::ShaderProgramPluginGL::Other))
    {
      allReasons += wrapper.name;
      allReasons += ": vendor mismatch; ";
      continue;
    }
    
    bool limitsSupported = currentLimits >= limits;
    if (!limitsSupported)
    {
      allReasons += wrapper.name;
      allReasons += ": Limits exceeded; ";
      continue;
    }
    
    iFile* cacheFile = wrapper.cacheFile;
    
    {
      uint32 diskState;
      if (cacheFile->Read ((char*)&diskState, sizeof (diskState))
	  != sizeof (diskState)) continue;
      if (csLittleEndian::UInt32 (diskState) != cpsValid)
      {
        oneReadCorrectly = true;
        continue;
      }
    }
  
    
    description = CS::PluginCommon::ShaderCacheHelper::ReadString (cacheFile);
    
    bool breakFail = false;
    csRef<iDocumentNode> cgNode = node->GetNode (progTypeNode);
    if (!cgNode.IsValid()) continue;
    csRef<iDocumentNodeIterator> nodes = cgNode->GetNodes();
    while(nodes->HasNext() && !breakFail)
    {
      csRef<iDocumentNode> child = nodes->Next();
      if(child->GetType() != CS_NODE_ELEMENT) continue;
      const char* value = child->GetValue ();
      csStringID id = xmltokens.Request (value);
      switch(id)
      {
	case XMLTOKEN_VARIABLEMAP:
	  if (!ParseVmap (child))
	    breakFail = true;
	  break;
	case XMLTOKEN_CLIP:
	  if (!ParseClip (child))
	    breakFail = true;
	  break;
	default:
	  /* Ignore unknown nodes. Invalid nodes would have been caught
	     by the first (not from cache) parsing */
	  break;
      }
    }
    if (breakFail) continue;
    
    csString objectCodeCachePathArc =
      CS::PluginCommon::ShaderCacheHelper::ReadString (cacheFile);
    if (objectCodeCachePathArc.IsEmpty()) continue;
    csString objectCodeCachePathItem =
      CS::PluginCommon::ShaderCacheHelper::ReadString (cacheFile);
    if (objectCodeCachePathItem.IsEmpty()) continue;
    
    ProgramObjectID progId (objectCodeCachePathArc, objectCodeCachePathItem);
    ProgramObject programObj;
    //if (!LoadObjectCodeFromCompileCache (limits, cache))
    if (!shaderPlug->progCache.LoadObject (progId, programObj))
      continue;
    
    oneReadCorrectly = true;
    if (program)
    {
      cgDestroyProgram (program);
      program = 0;
    }
    
    if (!programObj.IsValid()) continue;
    
    cgGetError(); // Clear error
    program = cgCreateProgram (shaderPlug->context, 
      CG_OBJECT, programObj.GetObjectCode(), limits.profile, 0, 0);
    if (!program) continue;
    CGerror err = cgGetError();
    if (err != CG_NO_ERROR)
    {
      const char* errStr = cgGetErrorString (err);
      shaderPlug->Report (CS_REPORTER_SEVERITY_WARNING,
	"Cg error %s", errStr);
      continue;
    }
    programProfile = limits.profile;
    programPositionInvariant = programObj.GetFlags() & ProgramObject::flagPositionInvariant;
    unusedParams = programObj.GetUnusedParams();
    
    ClipsToVmap();
    GetParamsFromVmap();

    bool doLoadToGL = !shaderPlug->ProfileNeedsRouting (programProfile);

    cgGetError(); // Clear error
    if (doLoadToGL)
    {
      cgGLLoadProgram (program);
    }
    else
    {
      cgCompileProgram (program);
    }
    
    shaderPlug->PrintAnyListing();
    err = cgGetError();
    if ((err != CG_NO_ERROR)
      || (doLoadToGL && !cgGLIsProgramLoaded (program)))
    {
      //if (shaderPlug->debugDump)
	//DoDebugDump();
	
      const char* errStr = cgGetErrorString (err);
      shaderPlug->Report (CS_REPORTER_SEVERITY_WARNING,
	"Cg error %s", errStr);
  
      if (shaderPlug->doVerbose
	  && (((programType == progVP) && (programProfile >= CG_PROFILE_ARBVP1))
	    || ((programType == progFP) && (programProfile >= CG_PROFILE_ARBFP1))))
      {
	const char* err = (char*)glGetString (GL_PROGRAM_ERROR_STRING_ARB);
	shaderPlug->Report (CS_REPORTER_SEVERITY_WARNING,
	  "OpenGL error string: %s", err);
      }
  
      shaderPlug->SetCompiledSource (0);
      continue;
    }
    
    GetPostCompileParamProps ();
    
    if (shaderPlug->debugDump)
      DoDebugDump();
      
    tag->AttachNew (new scfString (wrapper.name));

    if (cacheLimits != 0)
      *cacheLimits = wrapper.limits;
    
    bool loaded = !shaderPlug->ProfileNeedsRouting (programProfile)
      || LoadProgramWithPS1 ();
    if (loaded && (bestLimits < currentLimits))
    {
      /* The best found program is worse than the current limits, so pretend
         that the shader program failed (instead just being 'invalid') -
         that will make xmlshader try to load the program from scratch,
         ie with current limits, which may just work. */
      if (failReason)
        failReason->AttachNew (new scfString ("Provoking clean load with current limits"));
      return iShaderProgram::loadFail;
    }
    return loaded ? iShaderProgram::loadSuccessShaderValid
        : iShaderProgram::loadSuccessShaderInvalid;
  }
  
  if (oneReadCorrectly)
  {
    if (bestLimits < currentLimits)
    {
      /* The 'invalid' programs may compile with the current limits -
         so again, provoke clean load */
      if (failReason)
        failReason->AttachNew (new scfString ("Provoking clean load with current limits"));
      return iShaderProgram::loadFail;
    }
    else
      return iShaderProgram::loadSuccessShaderInvalid;
  }
  else
    return iShaderProgram::loadFail;
}
Пример #5
0
void ShowProgramDatacfg(int person)
{
	FILE *fp;
	char buffer[257], buffer2[513], command[81], command2[81],
		 command3[81], command4[81], temp[2];
	int i;

	if(fp=fopen("NiKom:Datocfg/ProgramData.cfg", "r"))
	{
		while(!feof(fp))
		{
			buffer[0] = NULL, buffer2[0] = command[0] = NULL;

			fgets(buffer,256,fp);
			buffer[strlen(buffer)-1] = NULL;
			i = 0;

			while(i<strlen(buffer))
			{
				if(buffer[i] != '%')
				{
					if(buffer2[0] = NULL)
					{
						buffer2[0] = buffer[i];
						buffer2[1] = NULL;
					}
					else
					{
						temp[0] = buffer[i];
						temp[1] = NULL;
						strcat(buffer2,temp);
					}

				}
				else
				{
					if(buffer[i+1] == '%' || buffer[i+1] == NULL)
					{
						strcat(buffer2, "%");
						if(buffer[i+1] != NULL)
							i++;
					}
					else
					{
						command[0] = command2[0] = NULL;
						command3[0] = NULL, command4[0] = NULL;

						while(buffer[++i] != '%' && buffer[i] != NULL)
						{
							if(buffer[i] != '|')
							{
								if(command[0] == NULL)
								{
									command[0] = buffer[i];
									command[1] = NULL;
								}
								else
								{
									temp[0] = buffer[i];
									temp[1] = NULL;
									strcat(command, temp);
								}
							}
							else
							{
								while(buffer[++i] != '%' && buffer[i] != NULL)
								{
									if(command2[0] == NULL)
									{
										command2[0] = buffer[i];
										command2[1] = NULL;
									}
									else
									{
										temp[0] = buffer[i];
										temp[1] = NULL;
										strcat(command2, temp);
									}
								}

								if(buffer[++i] != NULL)
								{
									while(buffer[i] != ',' && buffer[i] != NULL)
									{
										if(command3[0] == NULL)
										{
											command3[0] = buffer[i];
											command3[1] = NULL;
										}
										else
										{
											temp[0] = buffer[i];
											temp[1] = NULL;
											strcat(command3, temp);
										}
										i++;
									}


									while(buffer[i] != '%' && buffer[i] != NULL)
									{
										if(command4[0] == NULL)
										{
											command4[0] = buffer[i];
											command4[1] = NULL;
										}
										else
										{
											temp[0] = buffer[i];
											temp[1] = NULL;
											strcat(command4, temp);
										}
										i++;
									}
								}
							}
						}


						if(buffer2[0] != NULL)
						{
							puttekn(buffer2,-1);
							buffer2[0] = NULL;
						}

						if(command && command2)
						{
							if(command3[0] == NULL)
							{
								puttekn(GetProgramData(person, NULL, command, command2), -1);
								puttekn("\n\r", -1);
							}
							else
							{
								if(atoi(GetProgramData(person, NULL, command, command2)))
									puttekn(command3, -1);
								else
									puttekn(command4, -1);

								puttekn("\n\r", -1);
								i = strlen(buffer);
							}

						}

						printf("Command = !%s!, command2 = !%s!, command3 = !%s!, command4 = !%s!\n", command, command2, command3, command4);
					}
				}
				if(buffer2[0] != NULL)
					puttekn(buffer2,-1);

				i++;
			}
		}
		fclose(fp);
		puttekn("\n\r", -1);
	}
}