/* -------------------------------------------------------------------- */ void BLBRotate(char *base, char *ext, int *reg, int *ansi) { char fn[15]; char ext2[4]; int *num; strcpy(ext2, ext); /* * Are we doing ansi or normal */ if (changedir(cfg.helppath) == -1 ) return; sprintf(fn, "%s.%2.2s@", base, ext); if(*term.bold && filexists(fn)) { ext2[2] = '@'; num = ansi; } else { num = reg; } if(*num == 0) { sprintf(fn, "%s.%s", base, ext2); dumpf(fn); } else { sprintf(fn, "%s%d.%s", base, *num, ext2); if (!filexists(fn)) { sprintf(fn, "%s.%s", base, ext2); dumpf(fn); *num = 0; } else { dumpf(fn); } } (*num)++; changedir(cfg.homepath); }
void TERMWINDOWMEMBER showRoomDescription(void) { OC.SetOutFlag(OUTOK); label DescFile; CurrentRoom->GetDescFile(DescFile, sizeof(DescFile)); if (CurrentUser->IsViewRoomDesc() && *DescFile && !Talley->Visited(thisRoom) && IsFilenameLegal(DescFile, NULL)) { char pathToRoomDesc[128]; sprintf(pathToRoomDesc, sbs, cfg.roompath, DescFile); if (filexists(pathToRoomDesc)) { if (!CurrentUser->IsExpert()) { CRmPrintfCR(getmsg(577)); } dumpf(pathToRoomDesc, TRUE, 0); doCR(); OC.SetOutFlag(OUTOK); } else { mPrintfCR(getmsg(427), cfg.Lroom_nym, DescFile); } doCR(); } }
/* -------------------------------------------------------------------- */ void tutorial(char *filename) { int i; char temp[14]; char oldverbose; outFlag = OUTOK; setio(whichIO, echo, outFlag); if (!expert) mPrintf("\n <3J0>ump <3N0>ext <3P0>ause <3S0>top\n"); /* doCR(); */ if (changedir(cfg.helppath) == -1 ) return; /* no bad files */ if (checkfilename(filename, 0) == ERROR) { mPrintf(" No helpfile %s", filename); changedir(cfg.homepath); return; } if (ambig(filename)) { /* fill our directory array according to filename */ oldverbose = verbose; verbose = FALSE; filldirectory(filename); verbose = oldverbose; /* print out all the files */ for (i = 0; filedir[i].entry[0] && ( dumpf(filedir[i].entry) != ERROR) ; i++); if ( !i) mPrintf(" No helpfile %s", filename); /* free file directory structure */ if(filedir != NULL) _ffree((void *)filedir); } else { strcpy(temp, filename); temp[strlen(temp)-1] = '@'; if (filexists(temp) && *term.bold) dump(temp); else dumpf(filename); } /* go to our home-path */ changedir(cfg.homepath); }
void CreateConfigurationFile(int FileNameIndex, int FileDataIndex, Bool PrintStuff) { discardable *d; if (!filexists(citfiles[FileNameIndex])) { if ((d = readData(16, FileDataIndex, FileDataIndex)) != NULL) { FILE *File; if ((File = fopen(citfiles[FileNameIndex], FO_W)) != NULL) { if (PrintStuff) { #ifndef WINCIT cPrintf(getcfgmsg(133), citfiles[FileNameIndex]); doccr(); #endif } const char **Data = (const char **) d->aux; for (int i = 0; !SameString(Data[i], getcfgmsg(244)); i++) { fprintf(File, getmsg(472), Data[i], bn); } fclose(File); } else { if (PrintStuff) { #ifndef WINCIT cPrintf(getcfgmsg(134), citfiles[FileNameIndex]); doccr(); #endif } } discardData(d); } else { if (PrintStuff) { cOutOfMemory(51); } } } }
void about_callb(GtkWidget *wdg, gpointer app) { GtkWidget *content=NULL, *lbl; gchar *fname = NULL,*utf8_msg=NULL; gsize br,bw; GError *ger; static gchar *f1=NULL; static gchar *f2 = "splash.jpg"; static gchar *msg = "\nGEOMORPH 0.6\nhttp://geomorph.sourceforge.net\n\n(c) Patrice St-Gelais 2003-2009 (GPL)\[email protected]\n\nGerman translation by\nSimon Donike (2005-2008) and Tim Schuermann (2004)"; if (!f1) { f1 = x_malloc(2+strlen(PKGDATADIR)+strlen(VERSION)+strlen(f2), "Splash image"); strcpy(f1,PKGDATADIR); strcat(f1,VERSION); strcat(f1,"/"); strcat(f1,f2); } if (!utf8_msg) { utf8_msg = g_locale_to_utf8(msg,-1,&br,&bw,&ger); } if (!utf8_msg) utf8_msg = msg; if (filexists(f1)) fname = f1; else if (filexists(f2)) fname = f2; if (fname) { content = gtk_vbox_new(FALSE,0); gtk_container_add(GTK_CONTAINER(content),gtk_image_new_from_file(fname)); lbl = gtk_label_new(utf8_msg); gtk_label_set_justify(GTK_LABEL(lbl),GTK_JUSTIFY_CENTER); gtk_container_add(GTK_CONTAINER(content),lbl); gtk_widget_show_all(content); } if (content) modal_dialog (content, " ", NULL, NULL, NULL, GTK_WIN_POS_CENTER, TRUE); else my_msg(utf8_msg,INFO); }
/* -------------------------------------------------------------------- */ static void reciveFiles(void) { cPrintf(" Receiving mail and rooms."); doccr(); wxrcv(cfg.temppath, roomdatain, (char)strpos((char)tolower(node.ndprotocol[0]), extrncmd)); if (!filexists(roomdatain)) { drop_dtr(); netFailed = TRUE; } }
/* -------------------------------------------------------------------- */ static void reciveRequest(void) { cPrintf(" Receiving room request file."); doccr(); wxrcv(cfg.temppath, roomreqin, (char)strpos((char)tolower(node.ndprotocol[0]), extrncmd)); if (!filexists(roomreqin)) { drop_dtr(); netFailed = TRUE; } }
void TERMWINDOWMEMBER receiveFiles(const protocols *theProt) { cPrintf(getnetmsg(101)); doccr(); wxrcv(LocalTempPath, roomdataIn, theProt); if (!filexists(roomdataIn)) { CITWINDOW *w = ScreenSaver.IsOn() ? NULL : CitWindowsMsg(NULL, getmsg(685), getmsg(74)); Hangup(); netFailed = TRUE; if (w) { destroyCitWindow(w, FALSE); } } }
/* -------------------------------------------------------------------- */ void setfileinfo(void) { label filename; label uploader; char comments[64]; char path[80]; struct fInfo old; getNormStr("filename", filename, FILESIZE, ECHO); sprintf(path, "%s\\%s", roomBuf.rbdirname, filename); /* no bad file names */ if (checkfilename(filename, 0) == ERROR) { mPrintf("\n No file %s.\n ", filename); return; } /* no file name? */ if (!filexists(path)) { mPrintf("\n No file %s.\n ", filename); return; } if (!getInfo(filename, &old)) { strcpy(uploader, logBuf.lbname); } else { strcpy(uploader, old.uploader); } getString("comments", comments, 64, FALSE, TRUE, ""); entercomment(filename, uploader, comments); sprintf(msgBuf->mbtext, "File info changed for file %s by %s", filename, logBuf.lbname); trap(msgBuf->mbtext, T_AIDE); }
static void analyzeIdentifier(char **ch, int modelNumber, tree *tr) { char ident[2048] = "", model[2048] = "", thisModel[2048] = ""; int i = 0, n, j, containsComma = 0; while(**ch != '=') { if(**ch != ' ' && **ch != '\t') { ident[i] = **ch; i++; } *ch = *ch + 1; } n = i; i = 0; for(i = 0; i < n; i++) if(ident[i] == ',') containsComma = 1; if(!containsComma) { printf("Error, model file must have format: DNA or AA model, then a comma, and then the partition name\n"); exit(-1); } else { boolean useProteinSubstitutionFile = FALSE, found = FALSE; int openBracket = 0, closeBracket = 0, openPos = 0, closePos = 0; i = 0; while(ident[i] != ',') { if(ident[i] == '[') { openPos = i; openBracket++; } if(ident[i] == ']') { closePos = i; closeBracket++; } model[i] = ident[i]; i++; } if(closeBracket > 0 || openBracket > 0) { if((closeBracket == 1) && (openBracket == 1) && (openPos < closePos)) useProteinSubstitutionFile = TRUE; else { printf("\nError: Apparently you want to specify a user-defined protein substitution model that shall be read from file\n"); printf("It must be enclosed in opening and closing bracktes like this: [fileName]\n\n"); printf("you specified: %s\n\n", model); exit(-1); } } if(useProteinSubstitutionFile) { char protFileName[2048] = ""; int pos, k, lower = 0, upper = i - 1; while(model[lower] == '[' || model[lower] == ' ') lower++; while(model[upper] == ']' || model[upper] == ' ') upper--; assert(lower < upper); for(k = lower, pos = 0; k <= upper; k++, pos++) protFileName[pos] = model[k]; protFileName[pos] = '\0'; if(!filexists(protFileName)) { printf("\n\ncustom protein substitution file [%s] you want to use does not exist!\n", protFileName); printf("you need to specify the full path\n"); printf("the file name shall not contain blanks!\n\n"); exit(0); } strcpy(tr->initialPartitionData[modelNumber].proteinSubstitutionFileName, protFileName); /*printf("%s \n", tr->initialPartitionData[modelNumber].proteinSubstitutionFileName);*/ tr->initialPartitionData[modelNumber].protModels = PROT_FILE; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = TRUE; tr->initialPartitionData[modelNumber].dataType = AA_DATA; } else { /* AA */ for(i = 0; i < NUM_PROT_MODELS && !found; i++) { strcpy(thisModel, protModels[i]); if(strcasecmp(model, thisModel) == 0) { tr->initialPartitionData[modelNumber].protModels = i; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = TRUE; tr->initialPartitionData[modelNumber].dataType = AA_DATA; found = TRUE; } if(i != GTR && i != GTR_UNLINKED) { strcpy(thisModel, protModels[i]); strcat(thisModel, "F"); if(strcasecmp(model, thisModel) == 0) { tr->initialPartitionData[modelNumber].protModels = i; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = AA_DATA; found = TRUE; } } if(found && (tr->initialPartitionData[modelNumber].protModels == GTR || tr->initialPartitionData[modelNumber].protModels == GTR_UNLINKED)) tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; } if(!found) { if(strcasecmp(model, "DNA") == 0) { tr->initialPartitionData[modelNumber].protModels = -1; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = DNA_DATA; found = TRUE; } else { if(strcasecmp(model, "BIN") == 0) { tr->initialPartitionData[modelNumber].protModels = -1; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = BINARY_DATA; found = TRUE; } else { if(strcasecmp(model, "MULTI") == 0) { tr->initialPartitionData[modelNumber].protModels = -1; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = GENERIC_32; found = TRUE; } else { if(strcasecmp(model, "CODON") == 0) { tr->initialPartitionData[modelNumber].protModels = -1; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = GENERIC_64; found = TRUE; } } } } } if(!found) { printf("ERROR: you specified the unknown model %s for partition %d\n", model, modelNumber); exit(-1); } } i = 0; while(ident[i++] != ','); tr->initialPartitionData[modelNumber].partitionName = (char*)rax_malloc((n - i + 1) * sizeof(char)); j = 0; while(i < n) tr->initialPartitionData[modelNumber].partitionName[j++] = ident[i++]; tr->initialPartitionData[modelNumber].partitionName[j] = '\0'; } }
int main(int argc, char **argv) { /**************************************************************/ /************************** FROM previous version CVBoardTypes VMEBoard; short Device=0; short Link=0; int32_t BHandle; VMEBoard=cvV1718; Device=0; if (CAENVME_Init( VMEBoard, Link, Device, &BHandle) != cvSuccess){ printf("error opening the device\n%s",""); //exit(1); } **************************************************/ // if (argc<=1){printf("%s\n"," ... consider \" ./gregory -r /tmp/lockfile\" for gregory.net");} ///////////////////////////////////// lockfile from argument (.net) char lockfile[180]=""; Targs args; parse_arguments(argc,argv, &args);//in main=normal var, outsourced with if (args.rvalue!=NULL){strncpy( lockfile , args.rvalue, 180 );} printf( "lockfile is ... %s\n", lockfile ); // ENVIRONMENT------------- // char* BinPath, *DataPath; BinPath = getenv ("GREGORY"); if (BinPath==NULL){ BinPath=new char[2]; strcpy(BinPath, "./"); } DataPath = getenv ("GREGORY_DATA"); if (DataPath==NULL){ DataPath=new char[2]; strcpy(DataPath, "./"); } // printf("%s\n"," export GREGORY="); // printf("%s\n"," export GREGORY_DATA="); // printf("%s\n",""); printf("%s\n",""); printf( "binary path: %s (not used yet...)\n",BinPath ); printf( "data path: %s\n",DataPath ); for (int ch=0;ch<8;ch++){ WaveBinfh[ch]=NULL; } // FILL THE TABLE OF FUNCTIONS ===========================TABLE int ic=0; sprintf( compile_table[ic].name, "%s", "get_status" ); compile_table[ic].addr=(functiontype_i)&vme_get_stat_reg; ic++; sprintf( compile_table[ic].name, "%s", "get_version" ); compile_table[ic].addr=(functiontype_i)&vme_get_version; ic++; /* sprintf( compile_table[ic].name, "%s", "v1718_control" ); compile_table[ic].addr=(functiontype_i)&v1718_control; ic++; */ //----------------------------------------------------- // printf("\nlist of known functions\n%s" , ""); // for (icc=0;icc<ic;icc++){ // printf( " %s\n", compile_table[icc].name ); // } printf("%50c\n",'-'); // END OF TABLE ==========================================TABLE mmap_file=create_shared_memory( 1, "vme" ); mmap_file2=create_shared_memory( 1, "vmeOUT" ); mmap_fileS=create_shared_memory( 2, "socket" ); mmap_fileO=create_shared_memory( 3, "oscilo" ); mmap_fileC=create_shared_memory( 4, "counter" ); /* //====================================== MMAP ====== communication system("dd if=/dev/zero of=mmap.in bs=4096 count=1 2> /dev/null"); if ((mmapfd = open("mmap.in", O_RDWR, 0)) == -1) err(1, "open"); mmap_file=(char*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfd, 0); if (mmap_file == MAP_FAILED) errx(1, "either mmap"); strcpy(mmap_file, "... this is an initial input.\0\0\0" ); // "acq_setup.xml\nrun=1\n"; //====================================== MMAP ====== communication //====================================== MMAP ====== communication system("dd if=/dev/zero of=mmap.out bs=4096 count=1 2> /dev/null"); if ((mmapfd2 = open("mmap.out", O_RDWR, 0)) == -1) err(1, "open"); mmap_file2=(char*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfd2, 0); if (mmap_file2 == MAP_FAILED) errx(1, "either mmap2"); strcpy(mmap_file2, "... no output at the moment...\0\0\0" ); // "acq_setup.xml\nrun=1\n"; //====================================== MMAP ====== communication //====================================== MMAP ====== communication server sock system("dd if=/dev/zero of=mmap.socket bs=4096 count=1 2> /dev/null"); if ((mmapfdS = open("mmap.socket", O_RDWR, 0)) == -1) err(1, "open"); mmap_fileS=(char*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfdS, 0); if (mmap_fileS == MAP_FAILED) errx(1, "either mmapS"); strcpy(mmap_fileS, "...................o=ok;X=error...\0\0\0" ); // "acq_setup.xml\nrun=1\n"; //====================================== MMAP ====== communication //====================================== MMAP ====== communication server OSCILO system("dd if=/dev/zero of=mmap.oscilo bs=4096 count=1 2> /dev/null"); if ((mmapfdO = open("mmap.oscilo", O_RDWR, 0)) == -1) err(1, "open"); mmap_fileO=(char*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfdO, 0); if (mmap_fileO == MAP_FAILED) errx(1, "either mmapS"); strcpy(mmap_fileO, ".......no command to Oscilo...\0\0\0" ); // "acq_setup.xml\nrun=1\n"; //====================================== MMAP ====== communication */ /* //====================================== MMAP ====== communication 4MB char cmd3[100]; char fname3[100]; sprintf( cmd3,"dd if=/dev/zero of=%s/mmap.histo bs=4096 count=1024 2> /dev/null", DataPath ); sprintf( fname3, "%s/mmap.histo", DataPath ); system( cmd3); if ((mmapfd3 = open( fname3, O_RDWR, 0)) == -1) err(1, "open"); mmap_file3=(char*)mmap(NULL, 4194304 , PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfd3, 0); if (mmap_file3 == MAP_FAILED) errx(1, "either mmap3"); */ // strcpy(mmap_file3, "... no output at the moment...\0\0\0" ); // "acq_setup.xml\nrun=1\n"; //====================================== MMAP ====== communication //===========histogram array //http://root.cern.ch/root/roottalk/roottalk01/3614.html //hclus[9] = new TH1F("name","descr",100,0,1000); hclus[9]->Fill(1); //- BIG TRICK with allocation. We pray 4MB isok // OBJECTS have to do TMapFile ... virtual classes etc. //TH1F **harray; // harray=new(mmap_file3) TH1F*[8]; //http://root.cern.ch/root/html/TMapFile.html#TMapFile:Add //http://root.cern.ch/root/roottalk/roottalk98/2340.html //http://root.cern.ch/root/roottalk/roottalk04/0352.html //http://root.cern.ch/root/roottalk/roottalk04/0341.html // initialize threads................................ALLOCATE tinfo = (thread_info *)calloc(NTHREADS , sizeof(thread_info) ); if (tinfo == NULL) {printf("calloc failed%s\n", "");return 1;} for (int tnum = 0; tnum < NTHREADS; tnum++) {tinfo[tnum].thread_num=-1;} //==========================================CORE int cmd_param[100]; //set of parameters// minimum 10! int i=0; // CMD counter int res; printf("\n.h for help\n\n%s", ""); //---------------------infinite loop ---------------------------- char prefix[20]=" "; char posfix[20]="..."; while(1==1){ i++; usleep(100*1000); // 50ms is enough to finish thread.. cmd_line( i ); // shows PROMPT; reads INPUT to cmd_buffer; res=get_cmd_name( cmd_param );// 1=quit; 2=list if (res != 0 ){ // .n newrun? .r runnumber! .ls ! // .s status .l LOAD! .s save .c comment .f file .n numberrun ?? // filename send with 'start (maybe run and file commands before)' if ( strcmp(cmd_buffer,".q")==0 ){ //.q printf("%s quitting %s\n", prefix, posfix ); global_flag_quit=-1; // only LOOP itself strcpy(mmap_file,"quit\0"); // send it to gregory.mmap strcpy(mmap_fileO,"quit\0"); // send it oscilo // strcpy(mmap_fileS,"quit\0"); // send it oscilo strcpy(mmap_fileC,"quit\0"); // send it oscilo // i will need to shutdown the socket int socket_fd=atoi(mmap_fileS); // get (slowly) handle shutdown( socket_fd, 2 ); break; // BREAK FROM WHILE 1==1 .... quit } // .q if ( strcmp(cmd_buffer,".s")==0 ){ //.s if ( mmap_fileS[16] == 'o' ){ int socket_fd=atoi(mmap_fileS); // bad trick -get handle printf("%s socket %d port %s %s\n", prefix,socket_fd,PORT,posfix); // sprintf(outline,"%d %d %d\n%c", 1, 2 ,3 , '\0'); int socker[3]; // 32 bit ZH data for socket e0000001 e0010123 0xf0000000 socker[0]=0xe0010000; socker[1]=0x000100ff; // socker[2]=0x0001; //channel // socker[3]=0x00ff; //value socker[2]=0xf0000000; // socker[5]=0x0000; // int tmp=send(socket_fd, outline, strlen(outline), 0 ); int tmp=send(socket_fd, socker, sizeof(socker), 0 ); if (tmp < 0){ printf(" !...socket error ... i block mmap.socket from now\n"); mmap_fileS[16] = 'X'; //shutdown( socket_fd, 2 ); } }else{ // socked_fd blocked [16]==X not "o" printf(" !...socket blocked due to ealier error%s\n",""); } } // .s //--- exact match strcmp //--- strstr means line start match if ( strstr(cmd_buffer,".r")==cmd_buffer ){ // .r RUN number char oldr[70]; int newri=1; char cmdls[200]; sprintf( cmdls,"ls -1tr %s | grep run | grep \\.dat |tail -1 | awk -F _ '{sub(\"run\",\"\");print $1}' > RUNNUM ", DataPath ); system(cmdls); sprintf( cmdls,"ls -ltrh %s/run*.dat 2>/dev/null | tail -1 | awk '{print $9,\" \",$5}' > RUNNAMELAST ", DataPath ); system(cmdls); sprintf( cmdls,"ls -tr1 %s| grep -ie '^run[0-9]' | sed 's/run0*//' | cut -d. -f 1 | cut -d _ -f 1 | sort -n | tail -1 > RUNNEXT ", DataPath ); system(cmdls); //============= read ll -h output with size ========== FILE *frn=fopen("RUNNAMELAST","r"); if (frn!=NULL){ memset(&oldr[0], 0, sizeof(oldr)); fread( oldr, 1, sizeof(oldr), frn ); oldr[ strlen(oldr)-1 ]='\0'; fclose(frn); printf("%s ... LAST SAVED ON DISK\n", oldr ); } //---------------------------------- frn=fopen("RUNNUM","r"); if (frn!=NULL){ fread( oldr, 1, sizeof(oldr), frn ); fclose(frn); if ( strlen(oldr)>0){ sscanf(oldr,"%d", &newri ); //from oldr => newri printf("CURR /on disk/ RUN =%5d\n", newri ); //printf("NEXT proposed RUN =%5d\n", newri+1 ); } }//no RUNNUM file //----------------------------- frn=fopen("RUNNEXT","r"); if (frn!=NULL){ fread( oldr, 1, sizeof(oldr), frn ); fclose(frn); if ( strlen(oldr)>0){ sscanf(oldr,"%d", &newri ); //from oldr => newri // printf("CURR /on disk/ RUN =%5d\n", newri ); printf("NEXT proposed RUN =%5d\n", newri+1 ); }else{ newri=1;} }//no RUNNUM file //----------------------------- printf("%s to change the run number use run x %s\n",prefix,posfix); printf("%s run 0 ... means no data file %s\n",prefix,posfix); sprintf(cmdls,"run %d", newri+1 ); // strcpy( mmap_file, "run " ); strcpy( mmap_file, cmdls ); printf("%s run %d ... command was sent%s\n",prefix,newri+1, posfix); } // .r RUN NUMBER //means - '.ls' on the line start if ( strstr(cmd_buffer,".ls")==cmd_buffer ){ // .ls // printf("%s listing %s\n", prefix, posfix ); for (int tnum = 0; tnum < NTHREADS; tnum++) { if ( (tnum==0) && (tinfo[tnum].thread_num==1) ){ printf("[--M--] process %d (of %d): measurement thread ACTIVE\n", tnum+1, NTHREADS);} else if(tnum==0) { printf("[--M--] process %d (of %d): measurement thread NOT LOADED\n", tnum+1, NTHREADS);} if ( (tnum==1) && (tinfo[tnum].thread_num==2 )){ printf("[--M--] process %d (of %d): socket thread ACTIVE\n", tnum+1, NTHREADS);} else if(tnum==1) { printf("[--M--] process %d (of %d): socket thread NOT LOADED\n", tnum+1, NTHREADS);} if ( (tnum==2) && (tinfo[tnum].thread_num==3 )){ printf("[--M--] process %d (of %d): oscilo thread ACTIVE\n", tnum+1, NTHREADS);} else if(tnum==2) { printf("[--M--] process %d (of %d): oscilo thread NOT LOADED\n", tnum+1, NTHREADS);} if ( (tnum==3) && (tinfo[tnum].thread_num==4 )){ printf("[--M--] process %d (of %d): Countr thread ACTIVE\n", tnum+1, NTHREADS);} else if(tnum==3) { printf("[--M--] process %d (of %d): Countr thread NOT LOADED\n", tnum+1, NTHREADS);} /* if (tinfo[tnum].thread_num>0){ printf(" process %d (of %d): ACTIVE\n", tnum+1, NTHREADS); // printf(" file size %d MB\n", 0 ); }else{ if (tinfo[tnum].thread_num==1){ printf(" process %d (of %d): measurement thread NOT LOADED\n", tnum+1, NTHREADS);} else if (tinfo[tnum].thread_num==2){ printf(" process %d (of %d): socket thread NOT LOADED\n", tnum+1, NTHREADS);} else {printf(" process %d (of %d): socket thread NOT LOADED\n", tnum+1, NTHREADS);} } */ }// NTHREADS printf("[--M--] last message:\n %s\n", mmap_file2 ); char text[100]; time_t now = time(NULL); struct tm *t = localtime(&now); strftime(text, sizeof(text)-1, "%Y/%m/%d_%H:%M:%S ", t); printf("%s ...\n", text); fflush(stdin); global_flag_list=1; /* //======= THIS IS A WAY TO PRINT ON PORT 7777 ======= int socket_fd=atoi(mmap_fileS); if (socket_fd != -1) { if (send(socket_fd, "\nAHOJ\n" , 6, 0) == -1) perror("ls"); } */ } // .ls list............. if ( strcmp(cmd_buffer,".l")==0 ){ // .l LOAD // printf("%s LOADing %s\n", prefix, posfix ); int tnum, pth_res; for (tnum = 0; tnum < NTHREADS; tnum++) { if (tinfo[tnum].thread_num<0){ tinfo[tnum].thread_num = tnum + 1; // if (tnum==0){ pth_res = pthread_create(&tinfo[tnum].thread_id, NULL, &loop_thread, &tinfo[tnum] ); // } // if (tnum==1){ // pth_res = pthread_create(&tinfo[tnum].thread_id, NULL, // &loop_thread2, &tinfo[tnum] ); // } if ( pth_res != 0){printf("pthread_create failed%s\n","");return 1;} }// _num<0 == not active thread=> you can reload else{ printf("%s thread %d is already active== %d %s no action\n", prefix,tnum, tinfo[tnum].thread_num, posfix ); // printf(" thread %d is already active== %d (no action)\n", tnum, tinfo[tnum].thread_num); }// else already active }//for all threads } // .. LOAD /* if ( strcmp(cmd_buffer,".s")==0 ){ // .s LOAD SERVER */ /* printf("%s loading network Server %s\n", prefix, posfix ); */ /* int tnum, pth_res; */ /* for (tnum = 0; tnum < NTHREADS; tnum++) { */ /* if (tinfo[tnum].thread_num<0){ */ /* tinfo[tnum].thread_num = tnum + 1; */ /* pth_res = pthread_create(&tinfo[tnum].thread_id, NULL, */ /* &loop_thread, &tinfo[tnum] ); */ /* if ( pth_res != 0){printf("pthread_create failed%s\n","");return 1;} */ /* }// _num<0 == not active thread=> you can reload */ /* else{ */ /* printf("%s thread %d is already active== %d %s no action\n", prefix,tnum, tinfo[tnum].thread_num, posfix ); */ /* // printf(" thread %d is already active== %d (no action)\n", tnum, tinfo[tnum].thread_num); */ /* }// else already active */ /* }//for all threads */ /* } // .. LOAD SERVER */ if ( strcmp(cmd_buffer,".h")==0 ){ // .h // printf("%s help %s\n", prefix, posfix ); printf("%s .h %s help\n", prefix, posfix ); printf("%s .l %s LOAD ALL THREADS\n", prefix, posfix ); printf("%s .s %s TEST network server on port %s\n", prefix, posfix , PORT ); printf("%s .r %s look at run number\n", prefix, posfix ); printf("%s .ls %s list\n", prefix, posfix ); printf("%s .q %s QUIT\n", prefix, posfix ); printf("%s ------ %s measurement thread commands ------:\n" , prefix, posfix ); printf("%s qu %s quit \n" , prefix, posfix); printf("%s sta %s start \n" , prefix, posfix ); printf("%s te %s test = start +no save\n" , prefix, posfix ); printf("%s sto %s STOP \n" , prefix, posfix ); printf("%s sts %s status \n" , prefix, posfix ); printf("%s cl %s clear histo \n" , prefix, posfix ); printf("%s hi %s histogram (save histogram to txt) \n" , prefix, posfix ); printf("%s wa %s waveform (save waveform to txt,mmap) \n" , prefix, posfix ); //not used anymore printf("%s tr %s trigger \n" , prefix, posfix ); printf("%s in %s init \n" , prefix, posfix ); // printf("%s aon %s autosaveON \n" , prefix, posfix ); // printf("%s aof %s autosaveOFF\n" , prefix, posfix ); printf("%s won %s wavesaveON\n" , prefix, posfix ); printf("%s wof %s wavesaveOFF\n" , prefix, posfix ); printf("%s pd %s probe_down \n" , prefix, posfix ); printf("%s pu %s probe_up \n" , prefix, posfix ); printf("%s re %s restart \n" , prefix, posfix ); printf("%s don %s displayON \n" , prefix, posfix ); printf("%s dof %s displayOFF \n" , prefix, posfix ); } // .h ==============================================================HELP } // was an internal command============================== else{ if (DEBUGGREG>0) printf(" cmd_name=%s\n", cmd_name); // strcpy( mmap_file, cmd_buffer ); //command directly to mmap_file........ //translate to better phrases ..................... if (strstr(cmd_buffer,"qu")!=NULL) strcpy( mmap_file, "quit" ); if (strstr(cmd_buffer,"qu")!=NULL) strcpy( mmap_fileO, "quit" ); // if (strstr(cmd_buffer,"qu")!=NULL) strcpy( mmap_fileS, "quit" ); if (strstr(cmd_buffer,"qu")!=NULL) strcpy( mmap_fileC, "quit" ); if (strstr(cmd_buffer,"run")!=NULL) strcpy( mmap_file, cmd_buffer ); // send the number if (strstr(cmd_buffer,"sta")!=NULL) strcpy( mmap_file, "start" ); if (strstr(cmd_buffer,"sta")!=NULL) strcpy( mmap_fileO, "start" ); //Oscilo if (strstr(cmd_buffer,"sta")!=NULL) strcpy( mmap_fileC, "start" ); //Oscilo if (strstr(cmd_buffer,"te")!=NULL) strcpy( mmap_file, "test" ); //must do wa if (strstr(cmd_buffer,"te")!=NULL) strcpy( mmap_fileO, "test" ); //Oscilo if (strstr(cmd_buffer,"te")!=NULL) strcpy( mmap_fileC, "test" ); //Oscilo if (strstr(cmd_buffer,"go")!=NULL) printf(".. not programmed yet\n%s",""); if (strstr(cmd_buffer,"go")!=NULL) strcpy( mmap_fileO, "go" ); //Oscilo if (strstr(cmd_buffer,"go")!=NULL) strcpy( mmap_fileC, "go" ); //Oscilo if (strstr(cmd_buffer,"sto")!=NULL) strcpy( mmap_file, "STOP" ); if (strstr(cmd_buffer,"sto")!=NULL) strcpy( mmap_fileO, "stop" ); //Oscilo if (strstr(cmd_buffer,"sto")!=NULL) strcpy( mmap_fileC, "stop" ); //Oscilo if (strstr(cmd_buffer,"stat")!=NULL)strcpy( mmap_file, "status" ); if (strstr(cmd_buffer,"sts")!=NULL) strcpy( mmap_file, "status" ); if (strstr(cmd_buffer,"cl")!=NULL) strcpy( mmap_file, "clear" ); if (strstr(cmd_buffer,"hi")!=NULL) strcpy( mmap_file, "histogram" ); // not used anymore if (strstr(cmd_buffer,"wa")!=NULL) strcpy( mmap_file, "waveform" ); // ? is it? if (strstr(cmd_buffer,"tr")!=NULL) strcpy( mmap_file, "trigger" ); if (strstr(cmd_buffer,"in")!=NULL) strcpy( mmap_file, "init" ); //notused anymore ... autosave==1 if (strstr(cmd_buffer,"aon")!=NULL) strcpy( mmap_file, "autosaveON" ); if (strstr(cmd_buffer,"aof")!=NULL) strcpy( mmap_file, "autosaveOFF" ); //NOW autosave==111 ! wav file if (strstr(cmd_buffer,"won")!=NULL) strcpy( mmap_file, "wavesaveON" ); if (strstr(cmd_buffer,"wof")!=NULL) strcpy( mmap_file, "wavesaveOFF" ); if (strstr(cmd_buffer,"pd")!=NULL) strcpy( mmap_file, "probe_down" ); if (strstr(cmd_buffer,"pu")!=NULL) strcpy( mmap_file, "probe_up" ); if (strstr(cmd_buffer,"re")!=NULL) strcpy( mmap_file, "restart" ); if (strstr(cmd_buffer,"don")!=NULL) strcpy( mmap_file, "displayON" ); if (strstr(cmd_buffer,"dof")!=NULL) strcpy( mmap_file, "displayOFF" ); if (strstr(cmd_buffer,"ac")!=NULL) strcpy( mmap_fileO, "accumulateXMGR" ); // if (strstr(cmd_buffer,"")!=NULL) strcpy( mmap_file, "" ); // if (strstr(cmd_buffer,"")!=NULL) strcpy( mmap_file, "" ); // NO this would spam the output printf("%s\n", mmap_file2 ); fflush(stdin); /* for (icc=0;icc<ic;icc++){ */ /* if ( strcmp(cmd_name,compile_table[icc].name)==0){ */ /* if (DEBUGGREG>0) */ /* printf(" matches =%d\n", icc); */ /* compile_table[icc].addr( cmd_param[0] ); */ /* }//match */ /* } //for icc=0--- */ /* //PERFORM ON YOUR OWN */ }// else ===== real command }// INF.WHILE. //==========================================CORE // NOW QUITTING ROUTINES =========================== global_flag_quit=-1; // SEND SIGNAL TO THREAD printf("[##M##] ........master is waiting for threads\n");fflush(stdin); // printf("%s\n","------------------------------Thread-close-begin");fflush(stdin); for (int tnum = 0; tnum < NTHREADS; tnum++) { printf("[##M##]... waiting thread %d finish ...\n", tnum+1);fflush(stdin); int pth_res = pthread_join(tinfo[tnum].thread_id, NULL ); if (pth_res != 0){printf("pthread_join failed%s'\n",""); //exit(1); // if no thread => quit to socat doesnot work } printf("[##M##] master join : thread %d (of %d) arrived\n", tnum+1, NTHREADS); // tinfo[tnum].thread_num, NTHREADS); fflush(stdin); // printf("thread %d/%d\n", tnum+1, NTHREADS);fflush(stdin); } if (tinfo!=NULL){ free(tinfo);} printf("%s\n","------------------------------Thread-close-end");fflush(stdin); // REMOVE LOCKFILE IS EXISTT ******************************** // this is important to let the script know "gregory has ended" // ................................socat has a problem with kill if ( filexists(lockfile)==1 ) { printf("File %s exist\n", lockfile );fflush(stdin); if( remove( lockfile ) != 0 ){ perror( "Error deleting file" ); }else{ puts( "File successfully deleted" ); } } exit(0); }//===================================================================MAIN
static void get_args(int argc, char *argv[], parameters *params, int processID) { int i, k, res; int number; #define NUM_OPT 11 char *options[NUM_OPT]= {"-n1", "-n2", "-n3", "-n4", "-A", "-B", "-C", "-p", "-n", "-t", "-h"}; char fileName[1024]; char runName[1024]; int set[NUM_OPT]; /* init */ params->n1 = 0; params->n2 = 0; params->n3 = 0; params->n4 = 0; params->useExternalTraceFile = 0; params->permutations = 0; params->computeTracefileOnly = 0; /*params->randomizedSelection = 0;*/ strcpy(params->outFileName, "outfile"); /***************/ for(i = 0; i < NUM_OPT; i++) set[i] = 0; for(i = 1; i < argc; i++) { int found = 0; for(k = 0; k < NUM_OPT && !found; k++) if(strcmp(options[k], argv[i]) == 0) found = 1; k--; if(found) { switch(k) { case 0: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { res = sscanf(argv[++i],"%d", &number); if(res == 0 || res == EOF) { printf("argument of %s must be an integer number\n", options[k]); exit(-1); } } params->n1 = number; set[k] = 1; break; case 1: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { res = sscanf(argv[++i],"%d", &number); if(res == 0 || res == EOF) { printf("argument of %s must be an integer number\n", options[k]); exit(-1); } } params->n2 = number; set[k] = 1; break; case 2: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { res = sscanf(argv[++i],"%d", &number); if(res == 0 || res == EOF) { printf("argument of %s must be an integer number\n", options[k]); exit(-1); } } params->n3 = number; set[k] = 1; break; case 3: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { res = sscanf(argv[++i],"%d", &number); if(res == 0 || res == EOF) { printf("argument of %s must be an integer number\n", options[k]); exit(-1); } } params->n4 = number; set[k] = 1; break; case 4: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { strcpy(fileName, argv[++i]); if(!filexists(fileName)) { printf("file %s does not exist\n", fileName); exit(-1); } } strcpy(params->fileNameA, fileName); set[k] = 1; break; case 5: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { strcpy(fileName, argv[++i]); if(!filexists(fileName)) { printf("file %s does not exist\n", fileName); exit(-1); } } strcpy(params->fileNameB, fileName); set[k] = 1; break; case 6: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { strcpy(fileName, argv[++i]); if(!filexists(fileName)) { printf("file %s does not exist\n", fileName); exit(-1); } } strcpy(params->fileNameC, fileName); set[k] = 1; break; case 7: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { res = sscanf(argv[++i],"%d", &number); if(res == 0 || res == EOF) { printf("argument of %s must be an integer number\n", options[k]); exit(-1); } } params->permutations = number; set[k] = 1; break; case 8: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { strcpy(runName, argv[++i]); strcat(params->outFileName, "."); strcat(params->outFileName, runName); } set[k] = 1; break; /*case 9: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { res = sscanf(argv[++i],"%d", &number); if(res == 0 || res == EOF) { printf("argument of %s must be an integer number\n", options[k]); exit(-1); } } if(number <= 0) { printf("Randomized Selection must be a positive Integer Value\n"); exit(-1); } params->randomizedSelection = number; break; */ case 9: if(i == argc - 1) { printf("Error, argument expected after option %s\n", options[k]); exit(-1); } else { strcpy(fileName, argv[++i]); if(!filexists(fileName)) { printf("file %s does not exist\n", fileName); exit(-1); } } strcpy(params->externalTraceFileName, fileName); params->useExternalTraceFile = 1; set[k] = 1; break; case 10: if(processID == 0) printHelp(); exit(0); break; default: printf("unknown option %s\n", options[k]); exit(-1); } } else { printf("unknown option %s\n", argv[i]); exit(-1); } } for(i = 0; i < 10; i++) { if(set[i] == 0) { printf("Error option %s must be specified!\n", options[i]); exit(-1); } } if(params->useExternalTraceFile == 1 && params->computeTracefileOnly == 1) { printf("Conflicting Options, you are trying to read in a tracfile with \"-t\" while\n"); printf("you only want to compute the global significance with \"-g\" \n"); exit(-1); } if(processID == 0 && filexists(params->outFileName)) { printf("Output File %s already exists\n", params->outFileName); exit(-1); } }
/* -------------------------------------------------------------------- */ void doLogin(char moreYet) { int foundIt; char InitPw[NAMESIZE+NAMESIZE+2]; char password[NAMESIZE+NAMESIZE+2]; char initials[NAMESIZE+NAMESIZE+2]; char *semicolon; Mflush(); if (!CARRIER) return; if (login_user || login_pw) /* handle command line log-ins */ { if (!modStat) if (cfg.offhook) offhook(); /* login using initials and pw */ if (login_pw) { normalizepw(cmd_login, initials, password); login_pw = FALSE; } else if (login_user) { normalizeString(cmd_login); if (findPerson(cmd_login, &logBuf) != ERROR) { strcpy(initials, logBuf.lbin); strcpy(password, logBuf.lbpw); } login_user = FALSE; } } else /* ask user for initials and password */ { if (moreYet == 2) moreYet = FALSE; else { /* dont print Login when hitting 'L' from console mode */ if (!(!moreYet && !loggedIn && !modStat)) { mPrintf("Login "); } } if (loggedIn) { mPrintf("\n Already logged in!\n "); return; } if (!modStat) if (cfg.offhook) offhook(); getNormStr((moreYet) ? "" : "your initials", InitPw, NAMESIZE+NAMESIZE+1, NO_ECHO); if (!CARRIER) return; dospCR(); semicolon = strchr(InitPw, ';'); if (!semicolon) { strcpy(initials, InitPw); getNormStr( "password", password, NAMESIZE, NO_ECHO); dospCR(); } else { normalizepw(InitPw, initials, password); } /* dont allow anything over 19 characters */ initials[NAMESIZE] = '\0'; } /* reset transmitted & received */ transmitted = 0l; received = 0l; /* reset read & entered */ mread = 0; entered = 0; foundIt = ((pwslot(initials, password)) != ERROR); if (foundIt && *password) { loggedIn = TRUE; update25(); /* trap it */ if (!logBuf.lbflags.NODE) { sprintf( msgBuf->mbtext, "Login %s", logBuf.lbname); if (onConsole) strcat(msgBuf->mbtext, " (Console)"); trap(msgBuf->mbtext, T_LOGIN); } else { sprintf( msgBuf->mbtext, "NetLogin %s", logBuf.lbname); trap(msgBuf->mbtext, T_NETWORK); } } else { loginNew(initials, password); } if (!loggedIn) return; heldMessage = FALSE; setsysconfig(); setgroupgen(); setroomgen(); setlbvisit(); slideLTab(thisSlot); /* cant log in now. */ if (cfg.accounting && !logBuf.lbflags.NOACCOUNT) { negotiate(); logincrement(); if (!logincheck()) { Hangup(); return; } } /* can't log in now. */ if (logBuf.VERIFIED && !onConsole) { tutorial("verified.blb"); Hangup(); return; } if (logBuf.lbflags.NODE) { #ifdef TRASH if (debug) { readnode(); cPrintf("Node: \"%s\" \"%s\"", node.ndname, node.ndregion); doccr(); cPrintf("Phone: \"%s\" %d", node.ndphone, node.nddialto); doccr(); cPrintf("Login: \"%s\" %d", node.ndlogin, node.ndwaitto); doccr(); cPrintf("Baud: %d Protocol: \"%s\"\n ", node.ndbaud, node.ndprotocol); cPrintf("Expire:%d Waitout: %d", node.ndexpire, node.ndwaitto); doccr(); cPrintf("Network: %d ZIP: %s UNZIP: %s", node.network, node.zip, node.unzip); doccr(); } #endif time(&logtimestamp); return; } if (logBuf.PSYCHO) { backout = TRUE; } /* reverse engineering Minibin?!?! */ if (logBuf.MINIBIN) { minibin(); } changedir(cfg.helppath); if ( filexists("bulletin.blb") ) { tutorial("bulletin.blb"); } gotodefaulthall(); roomtalley(); mf.mfLim = 0; /* just to make sure. */ mf.mfMai = 0; mf.mfPub = 0; mf.mfUser[0]=0; nochat(TRUE); /* reset chats */ /* verbose = FALSE; */ verbose = logBuf.VERBOSE; /* hmmm... where to put this */ if (roomBuf.rbflags.APLIC && roomBuf.rbflags.AUTOAPP ) ExeAplic(); showMessages(NEWoNLY, FALSE); verbose = FALSE; if (expert) listRooms(NEWRMS, FALSE); else listRooms(OLDNEW, FALSE); outFlag = OUTOK; setio(whichIO, echo, outFlag); /* record login time, date */ time(&logtimestamp); cfg.callno++; storeLog(); }
static char * EXTRACT_main( PLUGIN_interface * plint ) { extract_data uda,*ud; MRI_IMAGE * tsim; MCW_idcode * idc ; /* input dataset idcode */ THD_3dim_dataset * old_dset , * new_dset ; /* input and output datasets */ char *tmpstr , * str , *nprfxstr; int ntime, nvec ,nprfx, Err=0 , itmp; float * vec , fs , T ; char * tag; /* plugin option tag */ /* Allocate as much character space as Bob specifies in afni.h + a bit more */ tmpstr = (char *) calloc (PLUGIN_MAX_STRING_RANGE+10,sizeof(char)); nprfxstr = (char *) calloc (PLUGIN_MAX_STRING_RANGE+10,sizeof(char)); if (tmpstr == NULL || nprfxstr == NULL) return "********************\n" "Could not Allocate\n" "a teeni weeni bit of\n" "Memory ! Go complain\n" "to yer Mamma ! \n" "********************\n"; ud = &uda; /* ud now points to an allocated space */ ud->errcode = 0; /*reset error flag */ /*--------------------------------------------------------------------*/ /*----- Check inputs from AFNI to see if they are reasonable-ish -----*/ /*--------- go to first input line ---------*/ tag = PLUTO_get_optiontag(plint) ; if (tag == NULL) { return "************************\n" "Bad 1st line option \n" "************************" ; } idc = PLUTO_get_idcode(plint) ; /* get dataset item */ old_dset = PLUTO_find_dset(idc) ; /* get ptr to dataset */ if( old_dset == NULL ) return "*************************\n" "Cannot find Input Dataset\n" "*************************" ; ud->dsetname = DSET_FILECODE (old_dset); ud->ignore = PLUTO_get_number(plint) ; /* get number item */ str = PLUTO_get_string(plint) ; ud->dtrnd = (int)PLUTO_string_index( str , NUM_YN_STRINGS , yn_strings ); /*--------- loop over ramining options ---------*/ ud->iloc = -1; ud->xloc = -1; ud->yloc = -1; ud->zloc = -1; do { tag = PLUTO_get_optiontag(plint) ; if (tag == NULL) break; if (strcmp (tag, "Mask") == 0) { ud->strin = PLUTO_get_string(plint) ; ud->ncols = PLUTO_get_number(plint) ; ud->pass = PLUTO_get_number(plint) ; ud->fail = 0; /* Set voxels that don't make it to 0 */ continue; } if (strcmp (tag, "Index") == 0) { ud->iloc = PLUTO_get_number(plint) ; /* get number item */ continue; } if (strcmp (tag, "XYZ") == 0) { ud->xloc = PLUTO_get_number(plint) ; /* get number item */ ud->yloc = PLUTO_get_number(plint) ; /* get number item */ ud->zloc = PLUTO_get_number(plint) ; /* get number item */ continue; } if (strcmp (tag, "Output") == 0) { ud->new_prefix = PLUTO_get_string(plint) ; /* get string item (the output prefix) */ /* check to see if the field is empty */ if (ud->new_prefix == NULL) nprfx = 0; else nprfx = 1; /* check if the size is larger than 0. I did not want to check for this unless it's allocated */ if (nprfx == 1 && (int)strlen (ud->new_prefix) == 0) nprfx = 0; if (nprfx == 0) /* now create the new name and make new_prefix point to it */ { sprintf (nprfxstr,"%s.XTRCT",DSET_PREFIX (old_dset)); ud->new_prefix = nprfxstr; /*printf ("New prefix is set to be : %s\n\a",ud->new_prefix);*/ } if( ! PLUTO_prefix_ok(ud->new_prefix) ) /* check if it is OK */ return "************************\n" "Output Prefix is illegal\n" "************************" ; ud->strout = PLUTO_get_string(plint) ; str = PLUTO_get_string(plint) ; ud->format = (int)PLUTO_string_index( str , NUM_FORMAT_STRINGS , format_strings ); continue; } } while (1); /* ------------------ Check for some errorsor inconsistencies ------------- */ if (ud->iloc == -1 && ud->xloc == -1) { return "**************************\n" "At least iloc or x/y/zloc\n" "must be specified\n" "**************************\n" ; } if (ud->iloc != -1 && ud->xloc != -1) { return "***************************\n" "iloc AND x/y/zloc can not\n" "be simultaneously specified\n" "***************************\n" ; } /* ------------------Done with user parameters ---------------------------- */ /* Now loadup that index list or the xyz list */ if (ud->iloc != -1) { itmp = 0; /* might want to give option of setting it to number of rows if*/ /* the users know it, otherwise, it is automatically determined*/ ud->indvect = extract_index (ud->strin, ud->iloc, ud->ncols, &itmp, &Err); } else /* assuming the only other case is that x y z are specified */ { itmp = 0; ud->xyzvect = extract_xyz (ud->strin , ud->xloc , ud->yloc , ud->zloc , ud->ncols, &itmp, &Err); } ud->nrows = itmp; switch (Err) { case (0): break; case (1): return "****************************************\n" "index location should be > 0 and < ncols\n" "****************************************\n"; case (2): return "********************************************\n" "file size and number of columns do not match\n" "********************************************\n"; case (3): return "**********************\n" "Can't find matrix file\n" "**********************\n"; case (4): return "*****************\n" "ncols must be > 0\n" "*****************\n"; case (5): return "****************************************\n" "x/y/z column numbers can NOT be the same\n" "****************************************\n"; default: return "****************************************\n" "Should not have gotten here .....\n" "****************************************\n"; } if (strcmp (ud->strout,"") == 0) /* no output file is specified */ { sprintf ( tmpstr , "%s" , ud->new_prefix); ud->strout = tmpstr; } if (filexists(ud->strout) == 1) { return "*******************************\n" "Outfile exists, won't overwrite\n" "*******************************\n"; } ud->outwritets = fopen (ud->strout ,"w"); sprintf ( tmpstr , "%s.log" , ud->strout); if (filexists(tmpstr) == 1) { return "*******************************\n" "Outfile.log exists, won't overwrite\n" "*******************************\n"; } ud->outlogfile = fopen (tmpstr ,"w"); if ((ud->outwritets == NULL) || (ud->outlogfile == NULL) ) { ud->errcode = ERROR_FILEWRITE; return "***********************\n" "Could Not Write Outfile\n" "***********************\n"; } ud->nxx = (int)old_dset->daxes->nxx; /* get data set dimensions */ ud->nyy = (int)old_dset->daxes->nyy; ud->nzz = (int)old_dset->daxes->nzz; /* ready to dump the log file */ write_ud (ud); /*------------- ready to compute new dataset -----------*/ new_dset = PLUTO_4D_to_typed_fim( old_dset , /* input dataset */ ud->new_prefix , /* output prefix */ -1, /* negative value indicating data type is like original brick */ ud->ignore , /* ignore count */ ud->dtrnd , /* detrend */ EXTRACT_tsfunc , /* timeseries processor */ (void *)ud /* data for tsfunc */ ) ; PLUTO_add_dset( plint , new_dset , DSET_ACTION_MAKE_CURRENT ) ; fclose (ud->outlogfile); fclose (ud->outwritets); free (tmpstr); free (nprfxstr); return NULL ; /* null string returned means all was OK */ }
BOOL fedit(char *filename) { FILE *fp; char *buf; unsigned int lim; /* can't edit more then a segment anyway */ long filesize; int rc = FALSE; int err; char path[64]; getcwd(path,64); err = errno = 0; /* set the message entry flags and buffer */ clearmsgbuf(); setmem(msgBuf, sizeof(struct msgB), 0); mailFlag = FALSE; oldFlag = FALSE; limitFlag = FALSE; linkMess = FALSE; if (loggedIn) strcpy(msgBuf->mbauth,logBuf.lbname); /* try to edit an existing file */ if (filexists(filename)) { fp = fopen(filename,"rt"); if (fp) { filesize = filelength(fileno(fp)); if ((unsigned int) (filesize + (long) cfg.maxtext) > UINT_MAX) { err = -2; cPrintf("\nFile too long\n"); } else { lim = cfg.maxtext + (int) filesize; buf = calloc(1,lim); if (buf) { errno = 0; if (!fread(buf,1,lim,fp)) { cPrintf("\nFile read error\n"); err = errno; } if (fclose(fp) && !err) {/* we need to 'recreate' later */ cPrintf("\nFile close error\n"); err = errno; } if (!err) mFormat(buf); /* display the file */ oldFlag = TRUE; } } } else { lim = cfg.maxtext; buf = calloc(1,lim); oldFlag = FALSE; } } if (buf && !err && editBuf(buf,lim)) { changedir(path); /* because silly edit routines loose path */ if (!strblank(buf)) { rc = TRUE; lim = strlen(buf); errno = 0; /* because silly video routines set it */ fp = fopen(filename,"wt"); if (!fp && !err) { cPrintf("\nFile open error 2\n"); err = errno; } if (fp) { /* because silly DOS doesn't 'error' on disk full */ if(!fwrite(buf,1,lim,fp) && !errno) { cPrintf("\nFile write error\n"); err = -1; } errno = 0; if (!fclose(fp)&& !err) { cPrintf("\nFile close error 2\n"); err = errno; } } } else { /* we won't save empty files */ rc = FALSE; } } if (!buf) { /* out of memory condition */ mtPrintf(TERM_BOLD," \n Out of memory editing file %s.\n",filename); rc = FALSE; } else { switch (err) { case 0: /* no error */ break; case -1: /* disk full condition */ mtPrintf(TERM_BOLD, " \n Disk full saving %s, file truncated.\n",filename); rc = FALSE; break; case -2: /* file >64k condition */ mtPrintf(TERM_BOLD, " \n File %s is too large to edit.\n",filename); rc = FALSE; break; default: /* DOS error condition */ mtPrintf(TERM_BOLD, " \n DOS error '%s' editing %s: \n", strerror(err),filename); rc = FALSE; break; } } if (buf) { free(buf); buf = NULL; } return rc; }
static void analyzeIdentifier(char **ch, int modelNumber, tree *tr) { char *start = *ch, ident[2048] = "", model[2048] = "", thisModel[2048] = ""; int i = 0, n, j, containsComma = 0; while(**ch != '=') { if(**ch == '\n' || **ch == '\r') { printf("\nPartition file parsing error!\n"); printf("Each line must contain a \"=\" character\n"); printf("Offending line: %s\n", start); printf("RAxML will exit now.\n\n"); errorExit(-1); } if(**ch != ' ' && **ch != '\t') { ident[i] = **ch; i++; } *ch = *ch + 1; } ident[i] = '\0'; n = i; i = 0; for(i = 0; i < n; i++) if(ident[i] == ',') containsComma = 1; if(!containsComma) { printf("Error, model file must have format: Substitution model, then a comma, and then the partition name\n"); exit(-1); } else { boolean analyzeRest = TRUE, useExternalFile = FALSE, found = FALSE; int openBracket = 0, closeBracket = 0, openPos = 0, closePos = 0; i = 0; while(ident[i] != ',') { if(ident[i] == '[') { openPos = i; openBracket++; } if(ident[i] == ']') { closePos = i; closeBracket++; } model[i] = ident[i]; i++; } if(closeBracket > 0 || openBracket > 0) { if((closeBracket == 1) && (openBracket == 1) && (openPos < closePos)) useExternalFile = TRUE; else { printf("\nError: Apparently you want to specify a user-defined protein substitution model\n"); printf("or ascertainment bias correction model that shall be read from file\n"); printf("It must be enclosed in opening and closing bracktes like this: [prot=fileName] or [asc=fileName]\n\n"); printf("you specified: %s\n\n", model); exit(-1); } } if(useExternalFile) { char designator[2048] = "", fileName[2048] = ""; int pos, index, lower = 0, upper = i - 1; boolean isProteinFile = TRUE; while(model[lower] == '[') lower++; while(model[upper] == ']') upper--; assert(lower < upper); index = lower; pos = 0; while(model[index] != '~') { designator[pos] = model[index]; pos++; index++; } designator[pos] = '\0'; if(strcmp(designator, "asc") == 0) isProteinFile = FALSE; else { if(strcmp(designator, "prot") == 0) isProteinFile = TRUE; else { printf("Error external partition file type %s does not exist\n", designator); printf("Available file types: asc and prot\n"); exit(-1); } } while(model[index] == '~') index++; pos = 0; while(model[index] != ']') { fileName[pos] = model[index]; index++; pos++; } fileName[pos] = '\0'; if(!filexists(fileName)) { printf("\n\ncustom protein substitution or ascertainment bias file [%s] you want to use does not exist!\n", fileName); printf("you need to specify the full path\n"); printf("the file name shall not contain blanks!\n\n"); exit(-1); } if(isProteinFile) { strcpy(tr->initialPartitionData[modelNumber].proteinSubstitutionFileName, fileName); /*printf("%s \n", tr->initialPartitionData[modelNumber].proteinSubstitutionFileName);*/ tr->initialPartitionData[modelNumber].protModels = PROT_FILE; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = TRUE; tr->initialPartitionData[modelNumber].dataType = AA_DATA; analyzeRest = FALSE; } else { int newIndex = 0; strcpy(tr->initialPartitionData[modelNumber].ascFileName, fileName); i = 0; while(ident[i] != ',') { if(ident[i] == '\0') { printf("Expecting two commas in string %s\n", ident); exit(-1); } i++; } i++; while(ident[i] != ',') { if(ident[i] == '\0') { printf("Expecting two commas in string %s\n", ident); exit(-1); } model[newIndex] = ident[i]; i++; newIndex++; } model[newIndex] = '\0'; } } if(analyzeRest) { /* AA */ tr->initialPartitionData[modelNumber].ascBias = FALSE; for(i = 0; i < NUM_PROT_MODELS && !found; i++) { strcpy(thisModel, protModels[i]); if(strcasecmp(model, thisModel) == 0) { tr->initialPartitionData[modelNumber].protModels = i; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = TRUE; tr->initialPartitionData[modelNumber].dataType = AA_DATA; found = TRUE; } if(!found) { if(i != GTR && i != GTR_UNLINKED) { strcpy(thisModel, protModels[i]); strcat(thisModel, "F"); if(strcasecmp(model, thisModel) == 0) { tr->initialPartitionData[modelNumber].protModels = i; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = AA_DATA; found = TRUE; if(tr->initialPartitionData[modelNumber].protModels == AUTO) { printf("\nError: Option AUTOF has been deprecated, exiting\n\n"); errorExit(-1); } } } } if(!found) { strcpy(thisModel, protModels[i]); strcat(thisModel, "X"); if(strcasecmp(model, thisModel) == 0) { tr->initialPartitionData[modelNumber].protModels = i; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = AA_DATA; tr->initialPartitionData[modelNumber].optimizeBaseFrequencies = TRUE; found = TRUE; if(tr->initialPartitionData[modelNumber].protModels == AUTO) { printf("\nError: Option AUTOX has been deprecated, exiting\n\n"); errorExit(-1); } } } if(found && (tr->initialPartitionData[modelNumber].protModels == GTR || tr->initialPartitionData[modelNumber].protModels == GTR_UNLINKED)) tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; } /* AA with Asc bias*/ if(!found) { for(i = 0; i < NUM_PROT_MODELS && !found; i++) { strcpy(thisModel, "ASC_"); strcat(thisModel, protModels[i]); if(strcasecmp(model, thisModel) == 0) { tr->initialPartitionData[modelNumber].protModels = i; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = TRUE; tr->initialPartitionData[modelNumber].dataType = AA_DATA; found = TRUE; } if(!found) { if(i != GTR && i != GTR_UNLINKED) { strcpy(thisModel, protModels[i]); strcat(thisModel, "F"); if(strcasecmp(model, thisModel) == 0) { tr->initialPartitionData[modelNumber].protModels = i; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = AA_DATA; found = TRUE; } } } if(!found) { strcpy(thisModel, protModels[i]); strcat(thisModel, "X"); if(strcasecmp(model, thisModel) == 0) { tr->initialPartitionData[modelNumber].protModels = i; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = AA_DATA; tr->initialPartitionData[modelNumber].optimizeBaseFrequencies = TRUE; found = TRUE; } } if(found) tr->initialPartitionData[modelNumber].ascBias = TRUE; if(found && (tr->initialPartitionData[modelNumber].protModels == GTR || tr->initialPartitionData[modelNumber].protModels == GTR_UNLINKED)) tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; } } if(!found) { if(strcasecmp(model, "DNA") == 0 || strcasecmp(model, "DNAX") == 0 || strcasecmp(model, "ASC_DNA") == 0 || strcasecmp(model, "ASC_DNAX") == 0) { tr->initialPartitionData[modelNumber].protModels = -1; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = DNA_DATA; if(strcasecmp(model, "DNAX") == 0 || strcasecmp(model, "ASC_DNAX") == 0) { if(strcasecmp(model, "ASC_DNAX") == 0) tr->initialPartitionData[modelNumber].ascBias = TRUE; else tr->initialPartitionData[modelNumber].ascBias = FALSE; tr->initialPartitionData[modelNumber].optimizeBaseFrequencies = TRUE; } else { if(strcasecmp(model, "ASC_DNA") == 0) tr->initialPartitionData[modelNumber].ascBias = TRUE; else tr->initialPartitionData[modelNumber].ascBias = FALSE; tr->initialPartitionData[modelNumber].optimizeBaseFrequencies = FALSE; } found = TRUE; } else { if(strcasecmp(model, "BIN") == 0 || strcasecmp(model, "BINX") == 0 || strcasecmp(model, "ASC_BIN") == 0 || strcasecmp(model, "ASC_BINX") == 0) { tr->initialPartitionData[modelNumber].protModels = -1; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = BINARY_DATA; if(strcasecmp(model, "BINX") == 0 || strcasecmp(model, "ASC_BINX") == 0) { if(strcasecmp(model, "ASC_BINX") == 0) tr->initialPartitionData[modelNumber].ascBias = TRUE; else tr->initialPartitionData[modelNumber].ascBias = FALSE; tr->initialPartitionData[modelNumber].optimizeBaseFrequencies = TRUE; } else { if(strcasecmp(model, "ASC_BIN") == 0) tr->initialPartitionData[modelNumber].ascBias = TRUE; else tr->initialPartitionData[modelNumber].ascBias = FALSE; tr->initialPartitionData[modelNumber].optimizeBaseFrequencies = FALSE; } found = TRUE; } else { if(strcasecmp(model, "MULTI") == 0 || strcasecmp(model, "MULTIX") == 0 || strcasecmp(model, "ASC_MULTI") == 0 || strcasecmp(model, "ASC_MULTIX") == 0) { tr->initialPartitionData[modelNumber].protModels = -1; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = GENERIC_32; if(strcasecmp(model, "MULTIX") == 0 || strcasecmp(model, "ASC_MULTIX") == 0) { if(strcasecmp(model, "ASC_MULTIX") == 0) tr->initialPartitionData[modelNumber].ascBias = TRUE; else tr->initialPartitionData[modelNumber].ascBias = FALSE; tr->initialPartitionData[modelNumber].optimizeBaseFrequencies = TRUE; } else { if(strcasecmp(model, "ASC_MULTI") == 0) tr->initialPartitionData[modelNumber].ascBias = TRUE; else tr->initialPartitionData[modelNumber].ascBias = FALSE; tr->initialPartitionData[modelNumber].optimizeBaseFrequencies = FALSE; } found = TRUE; } else { if(strcasecmp(model, "CODON") == 0 || strcasecmp(model, "CODONX") == 0 || strcasecmp(model, "ASC_CODON") == 0 || strcasecmp(model, "ASC_CODONX") == 0) { tr->initialPartitionData[modelNumber].protModels = -1; tr->initialPartitionData[modelNumber].usePredefinedProtFreqs = FALSE; tr->initialPartitionData[modelNumber].dataType = GENERIC_64; if(strcasecmp(model, "CODONX") == 0 || strcasecmp(model, "ASC_CODONX") == 0) { if(strcasecmp(model, "ASC_CODONX") == 0) tr->initialPartitionData[modelNumber].ascBias = TRUE; else tr->initialPartitionData[modelNumber].ascBias = FALSE; tr->initialPartitionData[modelNumber].optimizeBaseFrequencies = TRUE; } else { if(strcasecmp(model, "ASC_CODON") == 0) tr->initialPartitionData[modelNumber].ascBias = TRUE; else tr->initialPartitionData[modelNumber].ascBias = FALSE; tr->initialPartitionData[modelNumber].optimizeBaseFrequencies = FALSE; } found = TRUE; } } } } } if(!found) { printf("ERROR: you specified the unknown model %s for partition %d\n", model, modelNumber); exit(-1); } } i = 0; while(ident[i++] != ','); tr->initialPartitionData[modelNumber].partitionName = (char*)rax_malloc((n - i + 1) * sizeof(char)); j = 0; while(i < n) tr->initialPartitionData[modelNumber].partitionName[j++] = ident[i++]; tr->initialPartitionData[modelNumber].partitionName[j] = '\0'; } }
main (int argc,char *argv[]) {/* Main */ char outfile[300]; int N_FaceSetList, *FaceSetList ,writeout,CountOnly,paramnum; if (argc < 2) { usage (); exit (1); } writeout = 0; /* check out second option */ CountOnly = 0; /* Set to 1 if you want to Count the number of triplets only */ paramnum = 2; while (paramnum < argc) { if (equal_strings (argv[paramnum],"-o") == 1) { if ((paramnum + 1) >= argc) { SUMA_error_message ("SUMA_IV_FaceSetsextract","No Output file name specified with -o option",1); exit (1); } if (filexists (argv[paramnum+1]) == 1) { SUMA_error_message ("SUMA_IV_FaceSetsextract","Output file exists, will not overwrite",1); exit (1); } else { sprintf(outfile,"%s",argv[paramnum+1]); writeout = 1; } ++ paramnum; } if (equal_strings (argv[paramnum],"-co") == 1) { CountOnly = 1; } ++ paramnum; } FaceSetList = SUMA_IV_FaceSetsextract (argv[1], &N_FaceSetList); if (CountOnly) printf ("%d FaceSets sets read\n",N_FaceSetList); if (writeout == 1) { FILE *outfid; outfid = fopen (outfile, "w"); if (outfid == NULL) { fprintf (SUMA_STDERR, "Error %s: Could not open %s for writing.\n", FuncName, outfile); }else { i = 0; cntlim = N_FaceSetList*3; while (i < cntlim) { j = 0; while (j < 3) { fprintf (outfid, "%d\t", FaceSetList[i]); ++i; ++j; } fprintf (outfid, "\n"); } fclose (outfid); } } else if (!CountOnly) { i = 0; cntlim = N_FaceSetList*3; while (i < cntlim) { j = 0; while (j < 3) { fprintf (SUMA_STDOUT, "%d\t", FaceSetList[i]); ++i; ++j; } fprintf (SUMA_STDOUT, "\n"); } } SUMA_free(FaceSetList); }/* Main */