static void CAL_SetupAudioFile() { int handle; long length; char fname[13]; int i; strcpy(fname, aheadname); strcat(fname, extension); handle = OpenRead(fname); if (handle == -1) CA_CannotOpen(fname); length = ReadLength(handle); MM_GetPtr((memptr)&audiostarts, length); for (i = 0; i < (length/4); i++) audiostarts[i] = ReadInt32(handle); CloseRead(handle); /* open the data file */ strcpy(fname, afilename); strcat(fname, extension); audiohandle = OpenRead(fname); if (audiohandle == -1) CA_CannotOpen(fname); }
void loadCalibrationData() { TFileHandle hFileHandle; TFileIOResult nIoResult; short nFileSize=sizeof(baseHeading); OpenRead(hFileHandle, nIoResult, BASEDATADAT, nFileSize); ReadFloat(hFileHandle, nIoResult, baseHeading); Close(hFileHandle, nIoResult); nFileSize=sizeof(result); OpenRead(hFileHandle, nIoResult, COMPASSADJUSTMENTSDAT, nFileSize); for (int i=0; i<360; i++) { ReadFloat(hFileHandle, nIoResult, result[i]); } Close(hFileHandle, nIoResult); /*nFileSize=22*sizeof(BPgm1one); OpenRead(hFileHandle, nIoResult, FIELD, nFileSize); ReadFloat(hFileHandle, nIoResult, BPgm1one); ReadFloat(hFileHandle, nIoResult, BPgm1two); ReadFloat(hFileHandle, nIoResult, BPgm1three); ReadFloat(hFileHandle, nIoResult, BPgm1four); ReadFloat(hFileHandle, nIoResult, BPgm1five); ReadFloat(hFileHandle, nIoResult, BPgm1six); ReadFloat(hFileHandle, nIoResult, BPgm2one); ReadFloat(hFileHandle, nIoResult, BPgm3one); ReadFloat(hFileHandle, nIoResult, BPgm4one); ReadFloat(hFileHandle, nIoResult, BPgm4two); ReadFloat(hFileHandle, nIoResult, BPgm4three); ReadFloat(hFileHandle, nIoResult, RPgm1one); ReadFloat(hFileHandle, nIoResult, RPgm1two); ReadFloat(hFileHandle, nIoResult, RPgm1three); ReadFloat(hFileHandle, nIoResult, RPgm1four); ReadFloat(hFileHandle, nIoResult, RPgm1five); ReadFloat(hFileHandle, nIoResult, RPgm1six); ReadFloat(hFileHandle, nIoResult, RPgm2one); ReadFloat(hFileHandle, nIoResult, RPgm3one); ReadFloat(hFileHandle, nIoResult, RPgm4one); ReadFloat(hFileHandle, nIoResult, RPgm4two); ReadFloat(hFileHandle, nIoResult, RPgm4three); Close(hFileHandle, nIoResult);*/ }
task main() { Task_Kill(displayDiagnostics); Display_Clear(); initializeGlobalVariables(); // Defined in "initialize.h", this intializes all struct members. const int finish_delay = 4*1000; // MAGIC_NUM: milliseconds to delay when program ends. // TODO: Figure out why the delay is nowhere near this. TFileHandle IO_handle; TFileIOResult IO_result; const string filename = "_reset_pods.txt"; const string filename_temp = "_reset_pods_tmp.txt"; // temp makes the filename too long?? int file_size = 0; short rotation[POD_NUM] = {0,0,0,0}; // Read in all the values of the pods from a text file. OpenRead(IO_handle, IO_result, filename, file_size); // TODO: Add more error handling. if (IO_result==ioRsltSuccess) { nxtDisplayTextLine(0, "Read from file"); nxtDisplayTextLine(1, "\"_reset_pods.txt\""); } else if (IO_result==ioRsltFileNotFound) { OpenRead(IO_handle, IO_result, filename_temp, file_size); // TODO: Add more error handling. if (IO_result==ioRsltSuccess) { nxtDisplayTextLine(0, "Read from file"); nxtDisplayTextLine(1, "\"_pods_tmp.txt\""); } else if ( (IO_result==ioRsltFileNotFound) || (IO_result==ioRsltNoSpace) || (IO_result==ioRsltNoMoreFiles) ) { nxtDisplayTextLine(2, "No data file."); nxtDisplayTextLine(3, "Terminating."); Time_Wait(finish_delay); return; // The only way to break out of this function? } } else if ((IO_result==ioRsltNoSpace)||(IO_result==ioRsltNoMoreFiles)) { nxtDisplayTextLine(2, "No data file."); nxtDisplayTextLine(3, "Terminating."); Time_Wait(finish_delay); return; // The only way to break out of this function? } for (int i=POD_FR; i<(int)POD_NUM; i++) { ReadShort(IO_handle, IO_result, rotation[i]); } Close(IO_handle, IO_result); nxtDisplayTextLine(3, "FL:%5d FR:%5d", rotation[POD_FL], rotation[POD_FR]); nxtDisplayTextLine(4, "BL:%5d BR:%5d", rotation[POD_BL], rotation[POD_BR]); nxtDisplayCenteredTextLine(6, "Press [ENTER] to"); nxtDisplayCenteredTextLine(7, "end program."); do { Buttons_UpdateData(); Time_Wait(100); // MAGIC_NUM: Arbitrary LCD refresh delay. } while (Buttons_Released(NXT_BUTTON_YES)==false); }
InputStreamPtr Directory::OpenRead(const String& fileName) { String path; if (paths.length()) { MultiStringHelper pathsL(paths); MultiStringHelper::Iterator it = pathsL.Iterate(); while (it.HasNext(path)) { InputStreamPtr ptr = OpenRead(path, fileName); if (ptr) return ptr; } } else return OpenRead("", fileName); return InputStreamPtr(); }
boolean CA_LoadFile(const char *filename, memptr *ptr) { int handle; ssize_t l; long size; if ((handle = OpenRead(filename)) == -1) return false; size = ReadLength(handle); MM_GetPtr(ptr, size); l = ReadBytes(handle, (byte *)(*ptr), size); if (l == -1) { perror("CA_FarRead"); return false; } else if (l == 0) { fprintf(stderr, "CA_FarRead hit EOF?\n"); return false; } else if (l != size) { fprintf(stderr, "CA_FarRead only read %d out of %ld\n", l, size); return false; } CloseRead(handle); return true; }
bool IPlatformFile::CopyFile(const TCHAR* To, const TCHAR* From) { const int64 MaxBufferSize = 1024*1024; TAutoPtr<IFileHandle> FromFile(OpenRead(From)); if (!FromFile.IsValid()) { return false; } TAutoPtr<IFileHandle> ToFile(OpenWrite(To)); if (!ToFile.IsValid()) { return false; } int64 Size = FromFile->Size(); if (Size < 1) { check(Size == 0); return true; } int64 AllocSize = FMath::Min<int64>(MaxBufferSize, Size); check(AllocSize); uint8* Buffer = (uint8*)FMemory::Malloc(int32(AllocSize)); check(Buffer); while (Size) { int64 ThisSize = FMath::Min<int64>(AllocSize, Size); FromFile->Read(Buffer, ThisSize); ToFile->Write(Buffer, ThisSize); Size -= ThisSize; check(Size >= 0); } FMemory::Free(Buffer); return true; }
//----handles the storage of data----// void swapFiles() { OpenWrite(hFileHandle2,nIoResultRead,sFileName2,nFileSize2); OpenRead(hFileHandle,nIoResult,sFileName1,nFileSize); float tempVar; char tempX, tempY, tempTheta, z; while(nIoResult != ioRsltEndOfFile) { for(z = 0; z<numNeuralUnits; z++) { ReadFloat(hFileHandle,nIoResult,tempVar); if(nIoResult == ioRsltEndOfFile) {break;} WriteFloat(hFileHandle2,nIoResultRead,tempVar); } if(nIoResult == ioRsltEndOfFile) {break;} ReadByte(hFileHandle, nIoResult, tempX); ReadByte(hFileHandle, nIoResult, tempY); ReadByte(hFileHandle, nIoResult, tempTheta); WriteByte(hFileHandle2,nIoResultRead,tempX); WriteByte(hFileHandle2,nIoResultRead,tempY); WriteByte(hFileHandle2,nIoResultRead,tempTheta); } char x; for(x = 0; x<numNeuralUnits; x++) { WriteFloat(hFileHandle2, nIoResult, localTemp.localArray[x]); } WriteByte(hFileHandle2, nIoResult, poseWorld.maxActivatedCell.x); WriteByte(hFileHandle2, nIoResult, poseWorld.maxActivatedCell.y); WriteByte(hFileHandle2, nIoResult, poseWorld.maxActivatedCell.theta); Close(hFileHandle2,nIoResultRead); Close(hFileHandle,nIoResult); Delete(sFileName1,nIoResult); Rename(sFileName1,nIoResult,sFileName2); }
Surface *Surface::Load(const OSChar *inFilename) { FILE *file = OpenRead(inFilename); if (!file) { #ifdef ANDROID ByteArray bytes = AndroidGetAssetBytes(inFilename); if (bytes.Ok()) { Surface *result = LoadFromBytes(bytes.Bytes(), bytes.Size()); return result; } #endif return 0; } Surface *result = TryJPEG(file,0,0); if (!result) { rewind(file); result = TryPNG(file,0,0); } fclose(file); return result; }
void initializeRobot() { CloseAllHandles(nIoResult); // make sure everything is closed wait1Msec(100); OpenRead(hFileHandle, nIoResult, sFileName , nFileSize); // open the existing file ReadFloat(hFileHandle, nIoResult, drift); // read a single float value from it ReadFloat(hFileHandle, nIoResult, Driver_Cal); // read a single float value from it Close(hFileHandle, nIoResult); // and close the file HTGYROsetCal(HTGYRO, Driver_Cal); // force the GYRO driver calibration to the value from Autonomous disableDiagnosticsDisplay(); StartTask(display); StartTask(buttons); StartTask(gyro); StartTask(Lifter); StartTask(lightFun); //StartTask(sensors); StartTask(grabbers); RequestedScreen=S_GYRO; // default the screen display to the GYRO information calibrate=1; grabbers_state = grabbersMid; servo[shoulder] = SHOULDER_DOWN; getJoystickSettings(joystick); motor[lightMotor] = 50; // reset light sensor into UP position for safety wait1Msec(500); motor[lightMotor] = 0; wait1Msec(400); return; }
void getUserControlProgram(string& sFileName) { byte nParmToReadByte[2]; int nFileSize; TFileIOResult nIoResult; TFileHandle hFileHandle; sFileName = ""; nParmToReadByte[1] = 0; hFileHandle = 0; OpenRead(hFileHandle, nIoResult, kConfigName, nFileSize); if (nIoResult == ioRsltSuccess) { for (int index = 0; index < nFileSize; ++index) { ReadByte(hFileHandle, nIoResult, nParmToReadByte[0]); strcat(sFileName, nParmToReadByte); } // // Delete the ".rxe" file extension // int nFileExtPosition; nFileExtPosition = strlen(sFileName) - 4; if (nFileExtPosition > 0) StringDelete(sFileName, nFileExtPosition, 4); } Close(hFileHandle, nIoResult); return; }
void TabularFile::ReadFromFile(const std::string & filename, size_t first_data_line, size_t n_columns, bool read_last_line) { std::ifstream in_file; OpenRead(in_file, filename); std::string line; columns_.resize(n_columns); std::vector<double> data(n_columns); // First line in file is line number 1. Read and discard up to first_data_line for (size_t i = 1; i < first_data_line; ++i) { std::getline(in_file, line); } std::string this_line, next_line; std::getline(in_file, this_line); while(std::getline(in_file, next_line)) { ParseAsciiArrayFast(this_line, data.begin(), n_columns); for (size_t i = 0; i < n_columns; ++i) { columns_[i].push_back(data[i]); } this_line = next_line; } // Reading last line if(read_last_line) { ParseAsciiArrayFast(this_line, data.begin(), n_columns); for (size_t i = 0; i < n_columns; ++i) { columns_[i].push_back(data[i]); } } }
/**Creates file instance linked to filename. \sa Open.*/ File::File( const string& filename, bool writable ): fp(NULL), contentSize(0), validName("") { if( writable ) OpenWrite( filename ); else OpenRead( filename ); }
void NRLib::ReadStormBinarySurf(const std::string & filename, RegularSurface<A> & surface) { std::ifstream file; OpenRead(file, filename.c_str(), std::ios::in | std::ios::binary); int line = 0; // Header try { std::string token = ReadNext<std::string>(file, line); if (token != "STORMGRID_BINARY") { throw FileFormatError("Error reading " + filename + ", file is not " "in STORM binary format."); } int ni = ReadNext<int>(file, line); int nj = ReadNext<int>(file, line); double dx = ReadNext<double>(file, line); double dy = ReadNext<double>(file, line); double x_min = ReadNext<double>(file, line); double x_max = ReadNext<double>(file, line); double y_min = ReadNext<double>(file, line); double y_max = ReadNext<double>(file, line); double lx = x_max - x_min; double ly = y_max - y_min; if (!NRLibPrivate::Equal(lx/(ni-1), dx)) { throw FileFormatError("Inconsistent data in file. dx != lx/(nx-1)."); } if (!NRLibPrivate::Equal(ly/(nj-1), dy)) { throw FileFormatError("Inconsistent data in file. dy != ly/(ny-1)."); } surface.Resize(ni, nj); surface.SetDimensions(x_min, y_min, lx, ly); DiscardRestOfLine(file, line, true); ReadBinaryDoubleArray(file, surface.begin(), surface.GetN()); surface.SetMissingValue(static_cast<A>(STORM_MISSING)); if (!CheckEndOfFile(file)) { throw FileFormatError("File too long."); } surface.SetName(GetStem(filename)); } catch (EndOfFile& ) { throw FileFormatError("Unexcpected end of file found while parsing " " \"" + filename + "\""); } catch (Exception& e) { throw FileFormatError("Error parsing \"" + filename + "\" as a " "STORM surface file at line " + ToString(line) + ":" + e.what() + "\n"); } }
bool FStreamingNetworkPlatformFile::InitializeInternal(IPlatformFile* Inner, const TCHAR* HostIP) { // look for the commandline that will read files from over the network if (HostIP == nullptr) { UE_LOG(LogStreamingPlatformFile, Error, TEXT("No Host IP specified in the commandline.")); bIsUsable = false; return false; } // optionally get the port from the command line int32 OverridePort; if (FParse::Value(FCommandLine::Get(), TEXT("fileserverport="), OverridePort)) { UE_LOG(LogStreamingPlatformFile, Display, TEXT("Overriding file server port: %d"), OverridePort); FileServerPort = OverridePort; } // Send the filenames and timestamps to the server. FNetworkFileArchive Payload(NFS_Messages::GetFileList); FillGetFileList(Payload, true); // Send the directories over, and wait for a response. FArrayReader Response; if(SendPayloadAndReceiveResponse(Payload,Response)) { // Receive the cooked version information. int32 ServerPackageVersion = 0; int32 ServerPackageLicenseeVersion = 0; ProcessServerInitialResponse(Response, ServerPackageVersion, ServerPackageLicenseeVersion); // Make sure we can sync a file. FString TestSyncFile = FPaths::Combine(*(FPaths::EngineDir()), TEXT("Config/BaseEngine.ini")); IFileHandle* TestFileHandle = OpenRead(*TestSyncFile); if (TestFileHandle != nullptr) { uint8* FileContents = (uint8*)FMemory::Malloc(TestFileHandle->Size()); if (!TestFileHandle->Read(FileContents, TestFileHandle->Size())) { UE_LOG(LogStreamingPlatformFile, Fatal, TEXT("Could not read test file %s."), *TestSyncFile); } FMemory::Free(FileContents); delete TestFileHandle; } else { UE_LOG(LogStreamingPlatformFile, Fatal, TEXT("Could not open test file %s."), *TestSyncFile); } FCommandLine::AddToSubprocessCommandline( *FString::Printf( TEXT("-StreamingHostIP=%s"), HostIP ) ); return true; } return false; }
bool TabularFile::CheckFile(const std::string & filename, size_t & first_data_line, size_t & n_columns, bool & read_last_line, std::string & last_line) { // Check if the last line of the file consists of data // and make initial guess if the last line shoud be read (not reading when equal to 0 or -999) std::ifstream in_file0; OpenRead(in_file0, filename); last_line = FindLastNonEmptyLine(in_file0); std::vector<std::string> tokens = GetTokens(last_line); read_last_line = true; if (!IsType<double>(tokens[0])) { read_last_line = false; } else { for (size_t i = 0; i < tokens.size(); ++i) { if (!IsType<double>(tokens[i])) read_last_line = false; else { if(atof(tokens[i].c_str()) == 0.0 || atof(tokens[i].c_str()) == -999.0) read_last_line = false; } } } std::ifstream in_file; OpenRead(in_file, filename); int line_number = 0; std::string line; while (GetNextNonEmptyLine(in_file, line_number, line)) { std::vector<std::string> tokens = GetTokens(line); if (IsType<double>(tokens[0])) { first_data_line = line_number; n_columns = tokens.size(); for (size_t i = 0; i < n_columns; ++i) { if (!IsType<double>(tokens[i])) return false; } return true; } } return false; }
static void FetchGiantStep(ZZ_pEX& g, long gs, const ZZ_pEXModulus& F) { if (use_files) { ifstream s; OpenRead(s, FileName("giant", gs)); NTL_INPUT_CHECK_ERR(s >> g); } else
//////////////////////////////////////////////////////////// /// Restart the sound from the beginning //////////////////////////////////////////////////////////// bool SoundFile::Restart() { if (myData) { // Reopen from memory return OpenRead(myData, mySize, myNbSamples, myChannelsCount, mySampleRate); } else if (myFilename != L"") { // Reopen from file return OpenRead(myFilename, myNbSamples, myChannelsCount, mySampleRate); } else { // Trying to reopen a file opened in write mode... error std::wcerr << L"Warning : trying to restart a sound opened in write mode, which is not allowed" << std::endl; return false; } }
float readTeleopForwards() { TFileHandle hFileHandle; TFileIOResult nIoResult; float result=0; short nFileSize=sizeof(baseHeading); OpenRead(hFileHandle, nIoResult, TELEOPFORWARDSDAT, nFileSize); ReadFloat(hFileHandle, nIoResult, result); Close(hFileHandle, nIoResult); return result; }
static void FetchGiantStep(ZZ_pX& g, long gs, const ZZ_pXModulus& F) { if (use_files) { ifstream s; OpenRead(s, FileName(ZZ_pX_stem, "giant", gs)); s >> g; s.close(); } else
bool Connection::StreamForPath(const util::http::Request *rq, util::http::Response *rs) { unsigned int generation, fid; if (sscanf(rq->path.c_str(), "/empeg/%u/%u", &generation, &fid) == 2 && generation == m_generation) { rs->body_source = OpenRead(fid); return true; } return false; }
/** Read file corresponding to index (e.g., if index is 1, read file will be loc_01.dat), and store its signature into ls. ASSUMES FILE EXISTS! */ void read_signature_from_file(loc_sig& ls, short index) { ASSERT(index >= 0 && index < NO_LOCS); TFileIOResult nIoResult; TFileHandle hFileHandle; int read_size; string sFileName = file_names[index]; OpenRead(hFileHandle, nIoResult, sFileName, read_size); for ( short i=0; i<NO_BINS; ++i ) ReadShort(hFileHandle, nIoResult, ls.sig[i]); Close(hFileHandle, nIoResult); }
/* This function reads 'threshold' and 'k' from background calibration * file "libCalib.dat" and wheel calibration file "compassCalib.dat" */ bool readCalib(){ //read the max and min from file "libCalib.dat" TFileIOResult nIoResult; short filehandle; const string filename1 = "libCalib.dat"; short filesize = 1000; OpenRead(filehandle, nIoResult, filename1, filesize); short min, max; ReadShort(filehandle, nIoResult, min); ReadShort(filehandle, nIoResult, max); //if file not existed, beep! if(nIoResult){ nxtDisplayStringAt(0,31,"Please run background calibration program."); PlayTone(1175,15); wait1Msec(2000); return false; } Close(filehandle, nIoResult); threshold = (min + max) / 2; //threshold is a global variable //read k from file "compassCalib.dat" const string filename2 = "compassCalib.dat"; OpenRead(filehandle, nIoResult, filename2, filesize); ReadFloat(filehandle, nIoResult, k); //k is a global variable //if file not existed, beep! if(nIoResult){ nxtDisplayStringAt(0,31,"Please run compass calibration program."); PlayTone(1175,15); wait1Msec(2000); return false; } Close(filehandle,nIoResult); return true; }
/// Delete all loc_%%.dat files void delete_loc_files() { for ( short n=0; n<NO_LOCS; n++ ) { TFileIOResult nIoResult; TFileHandle hFileHandle; int read_size; OpenRead(hFileHandle, nIoResult, file_names[n], read_size); bool exists = (nIoResult == 0); Close(hFileHandle, nIoResult); if ( exists ) Delete(file_names[n], nIoResult); } writeDebugStreamLine("DELETING LOC FILES"); }
//reads gyro position from a file written in autonomous? int getOffset() { TFileHandle hFileHandle; TFileIOResult nIoResult; int length = 3; string name = "data.txt"; OpenRead(hFileHandle, nIoResult, name, length); if (nIoResult != 0) return 0; long offset; ReadLong(hFileHandle, nIoResult, offset); Close(hFileHandle, nIoResult); return offset; }
/** * A convenience for {@link #openRead()} that also reads all of the * file contents into a byte array which is returned. */ ECode CAtomicFile::ReadFully( /* [out] */ ArrayOf<Byte>** result) { VALIDATE_NOT_NULL(result); *result = NULL; AutoPtr<IFileInputStream> stream; FAIL_RETURN(OpenRead((IFileInputStream**)&stream)); //try { Int32 pos = 0; Int32 avail, amt; IInputStream::Probe(stream)->Available(&avail); AutoPtr<ArrayOf<Byte> > data = ArrayOf<Byte>::Alloc(avail); AutoPtr<ArrayOf<Byte> > newData; while (TRUE) { IInputStream::Probe(stream)->Read(data, pos,data->GetLength() - pos, &amt); //Log.i("foo", "Read " + amt + " bytes at " + pos // + " of avail " + data.length); if (amt <= 0) { //Log.i("foo", "**** FINISHED READING: pos=" + pos // + " len=" + data.length); goto _EXIT_; } pos += amt; IInputStream::Probe(stream)->Available(&avail); if (avail > data->GetLength() - pos) { newData = ArrayOf<Byte>::Alloc(pos + avail); newData->Copy(data, 0, pos); data = newData; } } *result = data; REFCOUNT_ADD(*result); _EXIT_: //} finally { ICloseable::Probe(stream)->Close(); //} return NOERROR; }
static void PML_OpenPageFile() { int i; PageListStruct *page; char fname[13]; strcpy(fname, pfilename); if (w0 == true || w1 == true || s0 == true || s1 == true){ strcat(fname, extension); } else { strcat(fname, extension2); } PageFile = OpenRead(fname); if (PageFile == -1) Quit("PML_OpenPageFile: Unable to open page file"); /* Read in header variables */ ChunksInFile = ReadInt16(PageFile); PMSpriteStart = ReadInt16(PageFile); PMSoundStart = ReadInt16(PageFile); /* Allocate and clear the page list */ MM_GetPtr((memptr)&PMPages, sizeof(PageListStruct) * ChunksInFile); MM_SetLock((memptr)&PMPages, true); memset(PMPages, 0, sizeof(PageListStruct) * ChunksInFile); /* Read in the chunk offsets */ for (i = 0, page = PMPages; i < ChunksInFile; i++, page++) { page->offset = ReadInt32(PageFile); } /* Read in the chunk lengths */ for (i = 0, page = PMPages; i < ChunksInFile; i++, page++) { page->length = ReadInt16(PageFile); } }
/** Given that some location files have been stored, and given that at most NO_LOCS are going to be learned, what is the next location index that is expected to be written? For instance, if 2 locations out of 3 have already been recorded in files loc_00.dat and loc_01.dat, then, the next "free" index for naming a file would be 2, and the corresponding file would be loc_02.dat */ short find_next_loc_index() { short n = 0; while ( n<NO_LOCS ) { TFileIOResult nIoResult; TFileHandle hFileHandle; int read_size; OpenRead(hFileHandle, nIoResult, file_names[n], read_size); bool exists = (nIoResult == 0); Close(hFileHandle, nIoResult); if ( !exists ) { Delete(file_names[n], nIoResult); break; } else n++; } return n; }
task main() { CloseAllHandles(nIoResult); // make sure everything is closed wait1Msec(500); OpenRead(hFileHandle, nIoResult, sFileName , nFileSize); // open the existing file ReadFloat(hFileHandle, nIoResult, fParmToReadFloat); // read a single float value from it Close(hFileHandle, nIoResult); // and close the file while(nNxtButtonPressed!=3) // continue in editor until enter button is pressed {if (nNxtButtonPressed==1) { while(nNxtButtonPressed==1){}; // right arrow increases value fParmToReadFloat+=1; } if (nNxtButtonPressed==2) { while(nNxtButtonPressed==2){}; // left arrow decreases value fParmToReadFloat-=1; } nxtDisplayCenteredBigTextLine(6, "%3.1f", fParmToReadFloat); // update the display } Delete(sFileName, nIoResult); // delete pre-existing file (if any) nxtDisplayBigTextLine(0, "Deleted"); wait1Msec(2000); nFileSize = 100; OpenWrite( hFileHandle, nIoResult, sFileName, nFileSize); // create new file nxtDisplayBigTextLine(2, "Opened"); wait1Msec(2000); WriteFloat( hFileHandle, nIoResult, fParmToReadFloat); // write our value nxtDisplayBigTextLine(4, "Written"); wait1Msec(2000); Close(hFileHandle, nIoResult); // and close the file nxtDisplayBigTextLine(6, "Closed"); wait1Msec(2000); }
//----Checks if there is a match, add activities, else creates a new association----// void checkLocalCell() { //uses a normalised version of the localTemp. The comparison local cells are stored as normalised when 1st created char z; char breakSymbol =0; signed char cellCount = 0; char match = 0; float dotTempValue = 0; float tempAngle = 0; if(nextEmptyCell == 0) { //first localCellView writeLocal(); nextEmptyCell++; PlaySound(soundFastUpwardTones); while(bSoundActive) {} } else { OpenRead(hFileHandle3,nIoResultRead,sFileName1,nFileSize); while(nIoResultRead != ioRsltEndOfFile) { //search for a previous local cell that matches the current view to a certain degree for(z = 0; z<numNeuralUnits; z++) { ReadFloat(hFileHandle3,nIoResultRead,localComparison.localArray[z]); if(nIoResultRead == ioRsltEndOfFile) {breakSymbol = 1;break;} } if(breakSymbol == 1) {break;} ReadByte(hFileHandle3, nIoResultRead, injectX); ReadByte(hFileHandle3, nIoResultRead, injectY); ReadByte(hFileHandle3, nIoResultRead, injectTheta); dotTempValue = dotMultiply(); tempAngle = acos(dotTempValue); if(tempAngle<0.17)//0.17 //if difference less than 10 degrees between vectors { match = 1; Close(hFileHandle3,nIoResultRead); break; //save cycles break out } cellCount++; } if(match == 0) {//no match found - create a new local view cell Close(hFileHandle3,nIoResultRead); swapFiles(); nextEmptyCell++; PlaySound(soundFastUpwardTones); while(bSoundActive) {} } else if(match == 1) { injectEnergy(stepSize, injectX, injectY, injectTheta); nxtDisplayStringAt(64,30,"x: %2d",injectX); nxtDisplayStringAt(64,20,"y: %2d",injectY); nxtDisplayStringAt(64,10,"T: %1d",injectTheta); PlaySound(soundBeepBeep); while(bSoundActive) {} } } }
FILE *OpenRead(const char *inUtf8Name) { WString wide = UTF8ToWide(inUtf8Name); return OpenRead( wide.c_str() ); }