extern Pointer ReadFromTPASmart (CharPtr accn, Uint2Ptr datatype, Uint2Ptr entityID) { Char cmmd [256]; Pointer dataptr; FILE* fp; Char path [PATH_MAX]; Char err_path [PATH_MAX]; if (datatype != NULL) { *datatype = 0; } if (entityID != NULL) { *entityID = 0; } if (StringHasNoText (accn)) return NULL; if (tpasmartfetchcmd == NULL) { if (GetAppParam ("SEQUIN", "TPASMART", "FETCHSCRIPT", NULL, cmmd, sizeof (cmmd))) { tpasmartfetchcmd = StringSaveNoNull (cmmd); } } if (tpasmartfetchcmd == NULL) return NULL; TmpNam (path); #ifdef OS_UNIX sprintf (err_path, "%s.err", path); sprintf (cmmd, "csh %s %s > %s 2>%s", tpasmartfetchcmd, accn, path, err_path); system (cmmd); #endif #ifdef OS_MSWIN sprintf (cmmd, "%s %s -o %s", tpasmartfetchcmd, accn, path); system (cmmd); #endif fp = FileOpen (path, "r"); if (fp == NULL) { FileRemove (path); return NULL; } dataptr = ReadAsnFastaOrFlatFile (fp, datatype, entityID, FALSE, FALSE, TRUE, FALSE); FileClose (fp); FileRemove (path); #ifdef OS_UNIX FileRemove (err_path); #endif return dataptr; }
void WorkspaceWork::RemoveFile() { int i = filelist.GetCursor(); int s = filelist.GetSbPos(); bool separator = false; if(i >= 0 && i < fileindex.GetCount()) { int fx = fileindex[i]; separator = actual.file[fx].separator; if(separator && closed.Find(GetActiveSepfo()) >= 0) { int px = fx; while(--px >= 0 && !actual.file[fx].separator) ; if(px >= 0) { int c = closed.Find(Sepfo(GetActivePackage(), actual.file[px])); if(c >= 0) closed.Unlink(c); } } actual.file.Remove(fx); } if(separator || IsAux()) SaveLoadPackageNS(false); else SaveLoadPackage(false); if (separator || FileRemove()) { filelist.SetSbPos(s); filelist.SetCursor(i); } }
QByteArray QFileIOService::ExecuteRDSCommand(QRDSServer &rdsserver, quint8 command, const QMap<QString, QString> &map) { QByteArray ret; switch (command) { case QBrowseDirCommand: return BrowseDir(rdsserver, map); break; case QFileReadCommand: return FileRead(rdsserver, map); break; case QFileWriteCommand: return FileWrite(rdsserver, map); break; case QFileRenameCommand: return FileRename(rdsserver, map); break; case QFileRemoveFileCommand: return FileRemove(rdsserver, map, true); break; case QFileRemoveDirectoryCommand: return FileRemove(rdsserver, map, false); break; case QFileExistCommand: return Existence(rdsserver, map); break; case QFileCreateDirCommand: return CreateDir(rdsserver, map); break; case QFileGetRootDirCommand: return GetRootDir(rdsserver); break; } return ret; }
void DirRemove( const char *path ) { int i; int numFiles; fileInfo_t *pFileInfo; char new_path[256]; pFileInfo = (fileInfo_t*) malloc( sizeof(fileInfo_t) * MAX_DIR_FILES ); if( !pFileInfo ) { #ifdef _DEBUG printf("DirRemove : malloc() failed.\n"); #endif return; } numFiles = DirGetContents( path, NULL, pFileInfo, MAX_DIR_FILES ); for( i = 0; i < numFiles; i++ ) { if( pFileInfo[i].flags & FLAG_DIRECTORY ) { // build new path strcpy( new_path, path ); strcat( new_path, pFileInfo[i].name ); strcat( new_path, "/" ); DirRemove( new_path ); } else { strcpy( new_path, path ); strcat( new_path, pFileInfo[i].name ); FileRemove( new_path ); } } // all files have been removed so we can delete the directory now FileRmdir( path ); free(pFileInfo); }
Int2 Main() { static Char pcUname[2000]=""; /* Arg -l to keep the log file */ Int2 retval = 0; #ifdef OS_UNIX struct utsname utsbuf; #endif #define NUMARGS 1 static Nlm_Arg myargs[NUMARGS] = { /*0*/ { "Keep error.log file?", "F", NULL, NULL, TRUE, 'l', ARG_BOOLEAN, 0.0, 0, NULL} }; if ( !Nlm_GetArgs("Benchtraj", NUMARGS, myargs) ) return 1; ErrSetOptFlags(EO_SHOW_SEVERITY|EO_SHOW_CODES|EO_LOG_FILELINE|EO_SHOW_USERSTR|EO_SHOW_ERRTEXT|EO_BEEP|EO_WAIT_KEY|EO_LOGTO_USRFILE); #ifdef OS_UNIX /* use uname to get sysinfo */ if (uname(&utsbuf)>=0) { sprintf(pcUname,"%s %s %s %s %s\n",utsbuf.sysname,utsbuf.nodename,utsbuf.release,utsbuf.version,utsbuf.machine); } #else #ifdef OS_MSWIN /* assume ver is available */ if (GetMSWinVerInfo(pcUname)!=ERR_SUCCESS) { StringCpy(pcUname,"Not Available\n"); } #endif #endif printf("OS Reported:\n%s\n",pcUname); retval = TRADESBenchmark(); if (!myargs[0].intvalue) FileRemove("error.log"); return retval; }
NLM_EXTERN Boolean VecScreenAsynchronousRequest ( CharPtr database, BioseqPtr bsp, VQUEUE* queue, VecScreenResultProc resultproc, VecScreenAnnounceProc announceproc, VoidPtr userdata ) { CONN conn; FILE *fp; Char path [PATH_MAX]; Char str [128]; if (bsp == NULL || queue == NULL || resultproc == NULL) return FALSE; if (StringHasNoText (database)) { database = "UniVec"; } sprintf (str, "db=%s", database); conn = VecScreenOpenConnection (str); if (conn == NULL) return FALSE; TmpNam (path); fp = FileOpen (path, "w"); BioseqToFasta (bsp, fp, ISA_na (bsp->mol)); FileClose (fp); fp = FileOpen (path, "r"); QUERY_CopyFileToQuery (conn, fp); FileClose (fp); QUERY_SendQuery (conn); VecScreen_AddToQueue (queue, resultproc, announceproc, userdata, conn, bsp); FileRemove (path); return TRUE; }
NLM_EXTERN void ViewSortedProteins (SeqEntryPtr sep) { Char path [PATH_MAX]; FILE *fp; if (sep == NULL) return; TmpNam (path); fp = FileOpen(path, "w"); if (fp == NULL) { Message (MSG_ERROR, "Unable to open %s", path); return; } WriteSortedProteinsToFile (fp, sep); FileClose(fp); LaunchGeneralTextViewer (path, "Sorted Proteins"); FileRemove (path); }
static Int2 LIBCALLBACK TPASmartBioseqFetchFunc (Pointer data) { BioseqPtr bsp; Char cmmd [256]; Pointer dataptr; Uint2 datatype; Uint2 entityID; FILE* fp; OMProcControlPtr ompcp; ObjMgrProcPtr ompp; Char path [PATH_MAX]; Char err_path [PATH_MAX]; SeqEntryPtr sep = NULL; SeqIdPtr sip; TextSeqIdPtr tsip; ompcp = (OMProcControlPtr) data; if (ompcp == NULL) return OM_MSG_RET_ERROR; ompp = ompcp->proc; if (ompp == NULL) return OM_MSG_RET_ERROR; sip = (SeqIdPtr) ompcp->input_data; if (sip == NULL) return OM_MSG_RET_ERROR; if (sip->choice != SEQID_TPG) return OM_MSG_RET_ERROR; tsip = (TextSeqIdPtr) sip->data.ptrvalue; if (tsip == NULL || StringHasNoText (tsip->accession)) return OM_MSG_RET_ERROR; if (tpasmartfetchcmd == NULL) { if (GetAppParam ("SEQUIN", "TPASMART", "FETCHSCRIPT", NULL, cmmd, sizeof (cmmd))) { tpasmartfetchcmd = StringSaveNoNull (cmmd); } } if (tpasmartfetchcmd == NULL) return OM_MSG_RET_ERROR; TmpNam (path); #ifdef OS_UNIX sprintf (err_path, "%s.err", path); sprintf (cmmd, "csh %s %s > %s 2>%s", tpasmartfetchcmd, tsip->accession, path, err_path); system (cmmd); #endif #ifdef OS_MSWIN sprintf (cmmd, "%s %s -o %s", tpasmartfetchcmd, tsip->accession, path); system (cmmd); #endif fp = FileOpen (path, "r"); if (fp == NULL) { FileRemove (path); #ifdef OS_UNIX FileRemove (err_path); #endif return OM_MSG_RET_ERROR; } dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, &entityID, FALSE, FALSE, TRUE, FALSE); FileClose (fp); FileRemove (path); #ifdef OS_UNIX FileRemove (err_path); #endif if (dataptr == NULL) return OM_MSG_RET_OK; sep = GetTopSeqEntryForEntityID (entityID); if (sep == NULL) return OM_MSG_RET_ERROR; bsp = BioseqFindInSeqEntry (sip, sep); ompcp->output_data = (Pointer) bsp; ompcp->output_entityID = ObjMgrGetEntityIDForChoice (sep); return OM_MSG_RET_DONE; }
//================================================================== bool FileManagerAndroid::GrabFile(const char* pFileName, DVec<U8> &out_data, const char* pMode) { DFUNCTION(); DLOG("File: %s", pFileName); #if defined(ANDROID) bool prefs = isPrefsMode( pMode ); if (prefs) { // Read from the prefs storage DLOG("Grabbing file (prefs): %s", pFileName); char *contents = ::DoReadPrefs(pFileName); if (0 == contents) { DLOG("Failed to open the file"); return false; } // Decode into binary size_t binLength = 0; void *binData = FromBase64(contents, &binLength); free(contents); if (binData == 0) { DPRINT("!! File '%s' was not base64 format. Rejecting.", pFileName); return false; } // Copy into output array and free original // TODO: Could be sped up by pre-calculating length and not // copying. out_data.resize(binLength); memcpy(&out_data[0], binData, binLength); free(binData); DLOG("copied %d bytes", binLength); return true; } ::FileLoad(pFileName); int datasize; void *data; if (!FileGetData(pFileName, &data, &datasize)) { //DASSTHROW(0, ("failed loading file '%s'", pFileName)); return false; } out_data.resize(datasize); DVERBOSE("GrabFile: memcpy-ing '%s', %d bytes", pFileName, datasize); memcpy(&out_data[0], data, datasize); FileRemove(pFileName); DVERBOSE("GrabFile: released"); #endif return true; }
static BioseqPtr FetchBioseqFromSmartNotId (CharPtr accn, Uint2Ptr pEntityID) { BioseqPtr bsp; Char cmmd [256]; Pointer dataptr; Uint2 datatype; Uint2 entityID; FILE* fp; OMProcControlPtr ompcp; ObjMgrProcPtr ompp; Char path [PATH_MAX]; Char err_path [PATH_MAX]; SeqEntryPtr sep = NULL; SeqIdPtr sip; TextSeqIdPtr tsip; Int4 gi = 0; ValNodePtr vnp; time_t t1, t2; if (srcchkfetchcmd == NULL) { if (GetAppParam ("SEQUIN", "TBL_CHK", "FETCHSCRIPT", NULL, cmmd, sizeof (cmmd))) { srcchkfetchcmd = StringSaveNoNull (cmmd); } } if (srcchkfetchcmd == NULL) { if (GetAppParam ("SEQUIN", "SMART", "FETCHSCRIPT", NULL, cmmd, sizeof (cmmd))) { srcchkfetchcmd = StringSaveNoNull (cmmd); } } if (srcchkfetchcmd == NULL) return NULL; TmpNam (path); t1 = time(NULL); #ifdef OS_UNIX sprintf (err_path, "%s.err", path); sprintf (cmmd, "csh %s %s > %s 2>%s", srcchkfetchcmd, accn, path, err_path); system (cmmd); #endif #ifdef OS_MSWIN sprintf (cmmd, "%s %s -o %s", srcchkfetchcmd, accn, path); system (cmmd); #endif fp = FileOpen (path, "r"); if (fp == NULL) { FileRemove (path); #ifdef OS_UNIX FileRemove (err_path); #endif return OM_MSG_RET_ERROR; } dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, &entityID, FALSE, FALSE, TRUE, FALSE); FileClose (fp); FileRemove (path); #ifdef OS_UNIX FileRemove (err_path); #endif if (dataptr == NULL) return NULL; sep = GetTopSeqEntryForEntityID (entityID); if (sep == NULL) return NULL; sip = SmartGuessMakeId (accn); bsp = BioseqFindInSeqEntry (sip, sep); sip = SeqIdFree (sip); if (debug_mode) { t2 = time(NULL); if (t2 - t1 > 1) { printf("Time to download %s from SMART:%d\n", accn, t2 - t1); } } if (pEntityID != NULL) { *pEntityID = entityID; } return bsp; }
int copyFile(char *src, char*dst, int compressFlag, long *compressedFileSize) { // compress = 1 means inflate // compress = 0 means just copy // compress = -1 means deflate time_t timeStamp; char *copyBuffer1 = NULL; char *copyBuffer2 = NULL; char *uncompressedBytesArray = NULL; char *compressedBytesArray = NULL; copyBuffer1 = malloc(COPYBUFFER_SIZE); copyBuffer2 = malloc(COPYBUFFER_SIZE); uncompressedBytesArray = malloc(UNCOMPRESSED_ARRAY_SIZE); compressedBytesArray = malloc(COMPRESSED_ARRAY_SIZE); if ((copyBuffer1 == NULL) || (copyBuffer2 == NULL) || (uncompressedBytesArray == NULL) || (compressedBytesArray == NULL)) { if (copyBuffer1 != NULL) free(copyBuffer1); if (copyBuffer2 != NULL) free(copyBuffer2); if (uncompressedBytesArray != NULL) free(uncompressedBytesArray); if (compressedBytesArray != NULL) free(compressedBytesArray); SCP_LOG("out of memory in copyFile", __FUNCTION__); } SCP_LOG("CopyFile src:%s, dst:%s, compressFlag:%d", __FUNCTION__, src, dst, compressFlag); size_t bufsize = COPYBUFFER_SIZE; int retVal = 0; int didFileHeader = 0; FILE *fdout; if (compressedFileSize != NULL) *compressedFileSize = 0; fdout = fopen(dst, "w"); // if we are out of space, try removing the original first and reopening the file if (fdout == NULL) { FileRemove(dst); fdout = fopen(dst, "w"); } if (fdout != NULL) { SCP_LOG("OPENED! output file %s", __FUNCTION__, dst); FILE *fdin; if (NULL != (fdin = fopen(src, "r"))) { SCP_LOG("OPENED! input %s", __FUNCTION__, src); while (!feof(fdin)) { int bytes = 0; if (compressFlag == 0) { bytes = fread((void*)copyBuffer1, 1, bufsize, fdin); SCP_LOG("READ %d bytes when tried %d bytes", __FUNCTION__, bytes, bufsize); } if (compressFlag < 0) { if (!didFileHeader) { compFileHeader_t header; if(UiUtil_GetLocalTime( &timeStamp) == 0){ header.creationTime = timeStamp; } else { header.creationTime = time(NULL); } header.version = COMP_VERSION; int bout = fwrite((void*)&header, 1, sizeof(compFileHeader_t), fdout); if (bout != sizeof(compFileHeader_t)) { SCP_LOG("Tried to write %d bytes to %s and only wrote %d", __FUNCTION__, sizeof(compFileHeader_t), dst, bout); retVal = -1; break; } else { SCP_LOG("Wrote file header to %s", __FUNCTION__, dst); } didFileHeader = 1; } bytes = fread((void*)copyBuffer1, 1, bufsize, fdin); SCP_LOG("READ %d bytes when tried %d bytes", __FUNCTION__, bytes, bufsize); int compLen = bytes; compress(copyBuffer2, &compLen, copyBuffer1, bytes); SCP_LOG("Compressed %d bytes into %d bytes", __FUNCTION__, bytes, compLen); if (bytes == compLen) { SCP_LOG("No compression needed for this block.", __FUNCTION__); memcpy(copyBuffer2, copyBuffer1, bytes); } compBlockHeader_t *header = (compBlockHeader_t*)copyBuffer1; header->compressedBytes = compLen; header->uncompressedBytes = bytes; char *startOfData = copyBuffer1+sizeof(compBlockHeader_t); memcpy(startOfData, copyBuffer2, compLen); bytes = sizeof(compBlockHeader_t)+compLen; if (compressedFileSize != NULL) { *compressedFileSize += (long)bytes;; } } if (compressFlag > 0) { if (!didFileHeader) { compFileHeader_t header; if (fread((void*)&header, 1, sizeof(compFileHeader_t), fdin) != sizeof(compFileHeader_t)) { SCP_LOG("Tried to READ %d bytes of header and didn't", __FUNCTION__, sizeof(compFileHeader_t)); break; } if (header.version != COMP_VERSION) { SCP_LOG("Unsuported compress file verison %d", __FUNCTION__, header.version); retVal = -1; break; } didFileHeader = 1; } compBlockHeader_t header; if (fread((void*)&header, 1, sizeof(compBlockHeader_t), fdin) != sizeof(compBlockHeader_t)) { SCP_LOG("Tried to READ %d bytes of header and didn't", __FUNCTION__, sizeof(compBlockHeader_t)); break; } SCP_LOG("READ %d bytes of header. %d compressed bytes and %d uncompressed bytes", __FUNCTION__, sizeof(compBlockHeader_t), header.compressedBytes, header.uncompressedBytes); if ((header.compressedBytes == 0) && (header.uncompressedBytes == 0)) { SCP_LOG("Tail header read. EOF!", __FUNCTION__); break; } if ((header.compressedBytes > COMPRESSED_ARRAY_SIZE) || (header.compressedBytes <= 0)) { SCP_LOG("Compressed bytes should be 0-%d and it's %d", __FUNCTION__, COMPRESSED_ARRAY_SIZE, header.compressedBytes); retVal = -1; break; } if ((header.uncompressedBytes > UNCOMPRESSED_ARRAY_SIZE) || (header.uncompressedBytes <= 0)) { SCP_LOG("Uncompressed bytes should be 1-%d and it's %d", __FUNCTION__, UNCOMPRESSED_ARRAY_SIZE, header.uncompressedBytes); retVal = -1; break; } if (fread(copyBuffer1, 1, header.compressedBytes, fdin) != header.compressedBytes) { SCP_LOG("Tried to READ %d bytes of data and didn't", __FUNCTION__, header.compressedBytes); retVal = -1; break; } SCP_LOG("READ %d bytes of data.", __FUNCTION__, header.compressedBytes); if (header.uncompressedBytes > header.compressedBytes) { SCP_LOG("About to decompress %d bytes", __FUNCTION__, header.compressedBytes); int uncompBytes = inflater(copyBuffer2, COPYBUFFER_SIZE, copyBuffer1, header.compressedBytes); SCP_LOG("Decompressed %d bytes into %d bytes", __FUNCTION__, header.compressedBytes, uncompBytes); memcpy(copyBuffer1, copyBuffer2, uncompBytes); SCP_LOG("DECOMP:%2048s", __FUNCTION__, dst); bytes = uncompBytes; } else { SCP_LOG("NO DECOMP NEEDED.", __FUNCTION__); bytes = header.compressedBytes; } } if (bytes > 0) { SCP_LOG("Writing %d bytes to %s", __FUNCTION__, bytes, dst); int bout = fwrite((void*)copyBuffer1, 1, bytes, fdout); if (bout != bytes) { SCP_LOG("Tried to write %d bytes to %s and only wrote %d", __FUNCTION__, bytes, dst, bout); retVal = -1; break; } else { SCP_LOG("Wrote %d bytes to %s", __FUNCTION__, bytes, dst); } } else {break;} } if (compressFlag < 0) { compBlockHeader_t tailHeader; tailHeader.compressedBytes = 0; tailHeader.uncompressedBytes = 0; int bout = fwrite((void*)&tailHeader, 1, sizeof(compBlockHeader_t), fdout); if (bout != sizeof(compBlockHeader_t)) { SCP_LOG("Tried to write tail header to %s and only wrote %d", __FUNCTION__, dst, bout); retVal = -1; } else { if (compressedFileSize != NULL) { *compressedFileSize += (long)bout; } SCP_LOG("Wrote tail header to %s", __FUNCTION__, dst); } } fclose(fdin); SCP_LOG("Closed fdin", __FUNCTION__); } else { SCP_LOG("Unable to fopen input file %s", __FUNCTION__, src); retVal = -1; } fclose(fdout); SCP_LOG("Closed fdout", __FUNCTION__); } else { SCP_LOG("Unable to fopen %s as writeable.", __FUNCTION__, dst); retVal = -1; } SCP_LOG("CopyFile returning %d", __FUNCTION__, retVal); free(compressedBytesArray); free(uncompressedBytesArray); free(copyBuffer2); free(copyBuffer1); return retVal; }
static TrajErr TRADESBenchmark(void) { /* protein is 1CDZ, same as beta protein - mixed alpha/beta protein 96 AA */ static Char sequence[]="ELPDFFQGKHFFLYGEFPGDERRKLIRYVTAFNGELEDYMSDRVQFVITAQEWDPSFEEALMDNPSLAFVRPRWIYSCNEKQKLLPHQLYGVVPQA"; CharPtr pc; FILE *f; Char fnamseq[PATH_MAX]; Char fnam[PATH_MAX]; Char fnamtrj[PATH_MAX]; Char fnuturndb[PATH_MAX]; Int2 err,numAA,cnt; Int4 randseed,dbsize; pMakeTrjParamBlock mkdata; pFoldTrajParamBlock foldtrajprm; CPUTimePtr pTime1,pTime2,pTime3,pTime4; BiostrucPtr bspBiostruc; PDNMS pdnmsModelstruc; PMSD pmsdHead; PDNML pdnmlModel; PMLD pmldThis; BiostrucIdPtr pbi=NULL; BiostrucDescrPtr pbd=NULL; printf("%d is the CODEBASE version here.\n6502:UNIX x86_32, 6503003:UNIX x86_64, 6500:Win32, 6401:UNIX PPC_32\n\n", S4VERSION); sprintf(fnuturndb,"UTURNDB"); /* to clean up errant U-Turn files CWVH 2010 */ if (!OPENMMDBAPI(0,NULL)) { ErrPostEx(SEV_ERROR,2,1,"Unable to open MMDBAPI"); return ERR_FAIL; } printf("One moment, opening rotamer library...\n"); if (LoadRotLib()!=ERR_SUCCESS) { ErrPostEx(SEV_ERROR,1,8,"Cannot open rotamer library (%s%s) - if the file is missing, please re-install the software",CFG_local_datafilepath,NEWSCWRL_FNAM); return ERR_FAIL; } pc=DFPTmpNam(FALSE,FALSE); if ((f=FileOpen(pc,"w"))==NULL) { CLOSEMMDBAPI(); FreeRotLib(); ErrPostEx(SEV_ERROR,errno,1,"Failed to open %s file",pc); return ERR_FAIL; } fprintf(f,"%s\n",sequence); /* Make sure disk space was sufficient to write to file */ if (fflush(f)==EOF) { FileClose(f); CLOSEMMDBAPI(); FreeRotLib(); ErrPostEx(SEV_ERROR,errno,1,"Failed to write to %s file",pc); return ERR_FAIL; } FileClose(f); StringCpy(fnamseq,pc); sprintf(fnam,"%s%s",CFG_local_datafilepath,BENCH_TRAJ); sprintf(fnamtrj,"%s%s%s",CFG_local_datafilepath,BENCH_TRAJ,ASN_EXT); mkdata = (pMakeTrjParamBlock)MemNew(sizeof(MakeTrjParamBlock)); mkdata->TrajMethod = 2; /* from sequence */ mkdata->valfnamin = NULL; mkdata->pcChain = NULL; mkdata->modelnum = 1; mkdata->startres = 1; mkdata->endres = 0; mkdata->peakheight = 100; mkdata->noise = 0; mkdata->savechi = 0; mkdata->sigma_x = 0.0; mkdata->sigma_y = 0.0; mkdata->temperature = 0; mkdata->timestep = 0.0; mkdata->seqfnamin = fnamseq; mkdata->tgtype = 4; mkdata->sstrufname = NULL; mkdata->DoRPS = FALSE; mkdata->uturn = FALSE; mkdata->SStruinput = FALSE; mkdata->trjfnamout = fnam; mkdata->comprtype = USE_RLE; mkdata->constrfnamin = NULL; mkdata->units=UNITS_ARBITRARY; mkdata->templat=NULL; mkdata->zhangwindsize = 0; mkdata->alignfile=NULL; mkdata->ssmask=NULL; mkdata->dumpcsv=0; mkdata->benchmark=1; mkdata->all_coil = (Boolean)(FALSE); mkdata->all_beta = (Boolean)(FALSE); /* ensure config file is set right, even if user may have fudged it */ if (SetConfigFileValues(WALK_PHIPSI,50.0/*errtol*/, 0.25/*abbb*/, 0.50/*absc*/, 0.0/*tunnelprob*/)!=ERR_SUCCESS) { CLOSEMMDBAPI(); FreeRotLib(); mkdata=MemFree(mkdata); FileRemove(pc); #ifdef OS_UNIX ErrPostEx(SEV_ERROR,0,0,"Unable to write config file .foldtrajrc, cannot continue"); #else ErrPostEx(SEV_FATAL,0,0,"Unable to write config file foldtraj.ini, cannot continue"); #endif return ERR_FAIL; } printf("Predicting secondary structure and generating trajectory distribution...\n"); pTime1=CPUTimeMeasure(); MakeTrj((VoidPtr)mkdata); printf("MadeTrj complete, unpacking ASN.1 Trajectory Graph\n"); pTime2=CPUTimeMeasure(); mkdata=MemFree(mkdata); FileRemove(fnamseq); if (UnPackAsnTrajGraph(fnam,&numAA,sequence,NULL,&pbi,&pbd,NULL)==NULL) { CLOSEMMDBAPI(); FreeRotLib(); FileRemove(fnamtrj); ErrPostEx(SEV_ERROR,2,3,"Unable to read trajectory distribution %s, please create a new one",fnam); return ERR_FAIL; } randseed=54374; RandomSeed(randseed); StringCpy(tmpskelfname,DFPTmpNam(FALSE,FALSE)); /* make the ASN.1 file for this protein's chemical graph */ BuildSkelASN(sequence,tmpskelfname); InitBSPLog(randseed,sequence,totalstruc); TGInit(tmpdbasename,DB_READ,&dbsize); printf("Folding protein...\n"); pTime3=CPUTimeMeasure(); for (cnt=0;cnt<100;cnt++) { bspBiostruc=NULL; bspBiostruc=MIMEBiostrucAsnGet(tmpskelfname,"r",NULL); if (bspBiostruc==NULL) { CLOSEMMDBAPI(); FreeRotLib(); FileRemove(fnamtrj); BSFree(bspTempLog); FileRemove(tmpskelfname); TGClose(); CleanUpDB(tmpdbasename); CleanUpDB(fnuturndb); ErrPostEx(SEV_ERROR,3,1,"Unable to fetch Biostruc"); return ERR_FAIL; } if (pbi!=NULL) { if (bspBiostruc->id!=NULL) AsnGenericChoiceSeqOfFree(bspBiostruc->id,(AsnOptFreeFunc)BiostrucIdFree); bspBiostruc->id=pbi; pbi=NULL; } if (pbd!=NULL) { if (bspBiostruc->descr!=NULL) AsnGenericChoiceSeqOfFree(bspBiostruc->descr,(AsnOptFreeFunc)BiostrucDescrFree); bspBiostruc->descr=pbd; pbd=NULL; } /* now the chemical graph is correctly in memory as a modelstruc, with co-ordinates (and hence PALDs) assigned only to a-carbons */ pdnmsModelstruc=MakeAModelstruc(bspBiostruc); if (pdnmsModelstruc==NULL) { CLOSEMMDBAPI(); FreeRotLib(); FileRemove(fnamtrj); BSFree(bspTempLog); FileRemove(tmpskelfname); TGClose(); CleanUpDB(tmpdbasename); CleanUpDB(fnuturndb); ErrPostEx(SEV_ERROR,4,1,"Unable to convert Biostruc to Modelstruc. Please ensure your protein only contains the 20 standard amino acids."); return ERR_FAIL; } pmsdHead=(PMSD)(pdnmsModelstruc->data.ptrvalue); /* remove ppAsnOrder for all models so it will be rebuilt in WriteAsnAllModel */ pdnmlModel=pmsdHead->pdnmlModels; while (pdnmlModel) { pmldThis=(PMLD)(pdnmlModel->data.ptrvalue); if (pmldThis->ppAsnOrder) { PTRVectorFree(pmldThis->ppAsnOrder,0); pmldThis->ppAsnOrder=NULL; } pdnmlModel=pdnmlModel->next; } if (dbsize!=((PMMD)((pmsdHead->pdnmmHead)->data.ptrvalue))->iResCount) { CLOSEMMDBAPI(); FreeRotLib(); FreeAModelstruc(pdnmsModelstruc); BSFree(bspTempLog); FileRemove(fnamtrj); FileRemove(tmpskelfname); TGClose(); CleanUpDB(tmpdbasename); CleanUpDB(fnuturndb); ErrPostEx(SEV_ERROR,1,1,"protein length inconsistency error, expect: %d actual: %d, possibly due to corrupt trajectory file; aborting",((PMMD)((pmsdHead->pdnmmHead)->data.ptrvalue))->iResCount,dbsize); return ERR_FAIL; } foldtrajprm=(pFoldTrajParamBlock)MemNew(sizeof(FoldTrajParamBlock)); foldtrajprm->pmsdRoot=pmsdHead; foldtrajprm->Model=1; foldtrajprm->err=0; foldtrajprm->gen=0; foldtrajprm->errorfile=NULL; /* do the folding here */ TRADEProtein((VoidPtr)foldtrajprm,1); err=foldtrajprm->err; foldtrajprm=MemFree(foldtrajprm); FreeAModelstruc(pdnmsModelstruc); if (err!=ERR_SUCCESS && err!=ERR_INCOMPLETE) { FileRemove(fnamtrj); FileRemove(tmpskelfname); BSFree(bspTempLog); TGClose(); CleanUpDB(tmpdbasename); CleanUpDB(fnuturndb); CLOSEMMDBAPI(); FreeRotLib(); ErrPostEx(SEV_ERROR,1,1,"Benchtraj returned a folding error %d",err); return ERR_FAIL; } } pTime4=CPUTimeMeasure(); FileRemove(fnamtrj); FileRemove(tmpskelfname); BSFree(bspTempLog); TGClose(); CleanUpDB(tmpdbasename); CleanUpDB(fnuturndb); CLOSEMMDBAPI(); FreeRotLib(); printf("Benchmark complete.\n\nSummary\n-------\n Usr time Sys time\n -------- --------\n"); printf("Maketrj %9.3f %9.3f\nFoldtraj %9.3f %9.3f\n\n",CPUTimeGetUser(pTime2)-CPUTimeGetUser(pTime1),CPUTimeGetSys(pTime2)-CPUTimeGetSys(pTime1),CPUTimeGetUser(pTime4)-CPUTimeGetUser(pTime3),CPUTimeGetSys(pTime4)-CPUTimeGetSys(pTime3)); printf("Benchtraj successful\n"); return ERR_SUCCESS; }
/*---------------------------------------------------------------------------- > Function Name: RtStatus_t DeleteAllRecords(int32_t StartingCluster,FindData_t *_finddata) FunctionType: Reentrant Inputs: 1) StartingCluster 2) FindData_t structure Outputs: Returns an Error if function fails Description: Deletes all the files and directories of the specified path < ----------------------------------------------------------------------------*/ RtStatus_t DeleteAllRecords(int32_t StartingCluster, FindData_t * _finddata) { RtStatus_t RetValue = SUCCESS; int32_t HandleNumber = 0; uint8_t Buf[5]; int32_t TemphandleNumber = 0; ClearData(_finddata); PutWord(Buf, 0x2e2a, 0); Buf[2] = 0x2a; while (1) { TemphandleNumber = HandleNumber; if ((HandleNumber = FindFirst(_finddata, (uint8_t *) Buf)) < 0) { /* FindFirst function returns handle number with setting mode = READ + DIRECTORY so we have to set write mode for this handle */ HandleNumber = TemphandleNumber; Handle[HandleNumber].HandleActive = 1; Handle[HandleNumber].Mode = (FileSystemModeTypes_t) (Handle[HandleNumber].Mode | WRITE_MODE); if ((RetValue = ChangeToLowLevelDir(HandleNumber, _finddata, StartingCluster)) < 0) { Freehandle(HandleNumber); return RetValue; } ClearData(_finddata); Freehandle(HandleNumber); continue; } Handle[HandleNumber].Mode = (FileSystemModeTypes_t) (Handle[HandleNumber].Mode | WRITE_MODE); if ((_finddata->attrib & DIRECTORY) == DIRECTORY) { if ((RetValue = ChangeToLowLevelDir(HandleNumber, _finddata, StartingCluster)) < 0) { Freehandle(HandleNumber); return RetValue; } ClearData(_finddata); Freehandle(HandleNumber); continue; } else { if ((RetValue = FileRemove(_finddata->startrecord - 1, HandleNumber)) < 0) { Freehandle(HandleNumber); return RetValue; } } while (1) { if ((RetValue = FindNext(HandleNumber, _finddata)) < 0) { if ((RetValue = ChangeToLowLevelDir(HandleNumber, _finddata, StartingCluster)) < 0) { Freehandle(HandleNumber); return RetValue; } ClearData(_finddata); Freehandle(HandleNumber); break; } if ((_finddata->attrib & DIRECTORY) == DIRECTORY) { if ((RetValue = ChangeToLowLevelDir(HandleNumber, _finddata, StartingCluster)) < 0) { Freehandle(HandleNumber); return RetValue; } ClearData(_finddata); Freehandle(HandleNumber); break; } else { if ((RetValue = FileRemove(_finddata->startrecord - 1, HandleNumber)) < 0) { Freehandle(HandleNumber); return RetValue; } } } } // while(1) }
void DIGCLIENT DIGCliRemove( char const *name, dig_open mode ) { FileRemove( name, mode ); }
/*---------------------------------------------------------------------------- > Function Name: RtStatus_t ChangeToLowLevelDir(int32_t HandleNumber,FindData_t *_finddata,int32_t StartingCluster) FunctionType: Reentrant Inputs: 1) Handle Number 2) FindData_t Structure 3) Starting Cluster Outputs: Returns SUCCESS on success else an Error Code Description: Changes to low level directory if available within the given directory and updates the Handle < ----------------------------------------------------------------------------*/ RtStatus_t ChangeToLowLevelDir(int32_t HandleNumber, FindData_t * _finddata, int32_t StartingCluster) { RtStatus_t RetValue = SUCCESS; int32_t RecordNumber; uint8_t Buffer[32]; int32_t ClusterNumber = 0; uint8_t Buf[5]; // int64_t lTemp; PutWord(Buf, 0x2e2e, 0); if ((RetValue = Fseek(HandleNumber, -DIRRECORDSIZE, SEEK_CUR))) return RetValue; if ((RetValue = Isdirectoryempty(HandleNumber)) == SUCCESS) { if ((ReadDirectoryRecord(HandleNumber, 0, Buffer)) <= 0) return ERROR_OS_FILESYSTEM_NO_MATCHING_RECORD; // sdk2.6 changed this from right shift to a left shift. ClusterNumber = ((FSGetWord(Buffer, DIR_FSTCLUSLOOFFSET)) | (FSGetWord(Buffer, DIR_FSTCLUSHIOFFSET) << 16)); if ((RetValue = Fseek(HandleNumber, 0, SEEK_SET)) < 0) return RetValue; if ((RetValue = Chdir((uint8_t *) & Buf)) < 0) return RetValue; Handle[HandleNumber] = Handle[CWD_HANDLE]; if ((RecordNumber = DelGetRecordNumber(HandleNumber, ClusterNumber)) < 0) return ERROR_OS_FILESYSTEM_NO_MATCHING_RECORD; if ((RetValue = FileRemove(RecordNumber, HandleNumber)) < 0) return RetValue; if (Handle[HandleNumber].StartingCluster == MediaTable[Handle[HandleNumber].Device].RootdirCluster || Handle[HandleNumber].StartingCluster == StartingCluster) return ERROR_OS_FILESYSTEM_DIR_NOT_REMOVABLE; return SUCCESS; } if ((ReadDirectoryRecord(HandleNumber, (_finddata->startrecord - 1), Buffer)) <= 0) return ERROR_OS_FILESYSTEM_NO_MATCHING_RECORD; if ((RetValue = Fseek(HandleNumber, -DIRRECORDSIZE, SEEK_CUR))) return RetValue; // sdk2.6 changed this from a right shift to a left shift. ClusterNumber = ((FSGetWord(Buffer, DIR_FSTCLUSLOOFFSET)) | (FSGetWord(Buffer, DIR_FSTCLUSHIOFFSET) << 16)); UpdateHandle(HandleNumber, ClusterNumber); Handle[CWD_HANDLE] = Handle[HandleNumber]; return SUCCESS; }
void DIGCLIENTRY( Remove )( char const *name, dig_open mode ) { FileRemove( name, DIG2WVOpenMode( mode ) ); }
static Boolean LIBCALLBACK SecondVecScreenCallback ( CONN conn, Nlm_VoidPtr userdata, EIO_Status status ) { VQueuePtr cqp; FILE *fp; Char line [256]; Char path [PATH_MAX]; CharPtr rid; CharPtr sttus; CharPtr str; Boolean success = FALSE; Boolean waiting = FALSE; /* look for waiting, failure, or success */ cqp = (VQueuePtr) userdata; TmpNam (path); fp = FileOpen (path, "w"); QUERY_CopyResultsToFile (conn, fp); FileClose (fp); fp = FileOpen (path, "r"); str = ReadALine (line, sizeof (line), fp); while (str != NULL) { if (! StringHasNoText (line)) { if (line [0] == '>') { if (StringNICmp (line, ">Vector", 7) == 0) { rid = StringStr (line, "RID: "); if (rid != NULL) { rid += 5; sttus = StringStr (rid, " Status: "); if (sttus != NULL) { *sttus = '\0'; sttus += 9; if (StringCmp (cqp->rid, rid) != 0) { ErrPostEx (SEV_ERROR, 0, 0, "RID mismatch '%s' vs '%s'", cqp->rid, rid); cqp->done = TRUE; } else if (StringStr (sttus, "FAILED") != NULL) { cqp->done = TRUE; } else if (StringStr (sttus, "unknown") != NULL) { ErrPostEx (SEV_ERROR, 0, 0, "RID unknown '%s'", rid); cqp->done = TRUE; } else if (StringStr (sttus, "SUCCESS") != NULL) { success = TRUE; } else if (StringStr (sttus, "WAITING") != NULL) { waiting = TRUE; /* Message (MSG_POST, "WAITING"); */ } } } } else if (StringNICmp (line, ">Message", 8) == 0) { str = ReadALine (line, sizeof (line), fp); while (str != NULL && StringNCmp (line, "//", 2) != 0) { Message (MSG_POST, "%s\n", str); if (StringStr (line, "FAILURE") != NULL) { if (! waiting) { cqp->done = TRUE; } } str = ReadALine (line, sizeof (line), fp); } } } } str = ReadALine (line, sizeof (line), fp); } FileClose (fp); if (success) { cqp->resultproc (path, cqp->userdata, cqp->rid, cqp->seqid, success); cqp->done = TRUE; } else if (cqp->done) { cqp->resultproc (NULL, cqp->userdata, cqp->rid, cqp->seqid, success); } FileRemove (path); return TRUE; }
static Boolean LIBCALLBACK FirstVecScreenCallback ( CONN conn, Nlm_VoidPtr userdata, EIO_Status status ) { VQueuePtr cqp; FILE *fp; Char line [256]; Char path [PATH_MAX]; CharPtr rid; CharPtr rtoe; CharPtr str; long int val; /* read rID or failure message */ cqp = (VQueuePtr) userdata; TmpNam (path); fp = FileOpen (path, "w"); QUERY_CopyResultsToFile (conn, fp); FileClose (fp); fp = FileOpen (path, "r"); str = ReadALine (line, sizeof (line), fp); while (str != NULL) { if (! StringHasNoText (line)) { if (line [0] == '>') { if (StringNICmp (line, ">Vector", 7) == 0) { rid = StringStr (line, "RID: "); if (rid != NULL) { rid += 5; rtoe = StringStr (rid, " RTOE: "); if (rtoe != NULL) { *rtoe = '\0'; rtoe += 7; StringNCpy_0 (cqp->rid, rid, sizeof (cqp->rid)); if (sscanf (rtoe, "%ld", &val) == 1) { cqp->estTime = (time_t) val; cqp->secondsToWait = (Int2) val + 2; } else { cqp->secondsToWait = 15; } if (cqp->secondsToWait > 15) { cqp->secondsToWait = 15; } if (cqp->announceproc != NULL) { cqp->announceproc (rid, cqp->seqid, (Int2) val); } } } else if (StringStr (line, "FAILED") != NULL) { cqp->done = TRUE; if (cqp->resultproc != NULL) { cqp->resultproc (NULL, cqp->userdata, cqp->rid, cqp->seqid, FALSE); } } } else if (StringNICmp (line, ">Message", 8) == 0) { str = ReadALine (line, sizeof (line), fp); while (str != NULL && StringNCmp (line, "//", 2) != 0) { Message (MSG_POST, "%s\n", str); if (StringStr (line, "FAILURE") != NULL) { cqp->done = TRUE; } str = ReadALine (line, sizeof (line), fp); } } } } str = ReadALine (line, sizeof (line), fp); } FileClose (fp); FileRemove (path); return TRUE; }