int main(int argc, char *argv[]) { int n; extern char *optarg; extern int optind; int randVal =0; int number_of_processes =0; int possibilityOfSuccess =0; double percentageOfSuccess =0; double percentageOfFailure =0; int flag_v =0; char strPossibilityOfSuccess[3]; int i; //for pipe() char buf[10]; Getopt(argc, argv, &flag_v, &possibilityOfSuccess); // Fork_n_Exec_n_Rand(number_of_processes, possibilityOfSuccess, flag_v, fd, buf); // close(fd[1]); // close(fd[0]); exit(1); return 0; }
int main(int argc, char **argv) { int c, flags; mqd_t mqd; ssize_t n; uint32_t prio; void *buff; struct mq_attr attr; flags = O_RDONLY; while ( (c = Getopt(argc, argv, "n")) != -1) { switch (c) { case 'n': flags |= O_NONBLOCK; break; } } if (optind != argc - 1) err_quit("usage: mqreceive [ -n ] <name>"); mqd = Mq_open(argv[optind], flags); Mq_getattr(mqd, &attr); // get the max msg size for alloc memory.. buff = Malloc(attr.mq_msgsize); n = Mq_receive(mqd, buff, attr.mq_msgsize, &prio); printf("read %ld bytes, priority = %u\n", (long) n, prio); exit(0); }
int main(int argc, char **argv) { int c, flags; mqd_t mqd; flags = O_RDWR|O_CREAT; while((c=Getopt(argc, argv, "e")) != -1) { switch(c) { case 'e': flags |=O_EXCL; printf("get e ok\n"); break; } } printf("optind %d\n", optind); if(optind != argc - 1) { printf("usage:mqcreate [-e] <name>\n"); exit(1); } mqd = Mq_open(argv[optind], flags, FILE_MODE, NULL); //Mq_close(mqd); exit(0); }
int main(int argc, char *argv[]) { int c, fd, flags; char *ptr; off_t length; flags = O_RDWR | O_CREAT; while( (c = Getopt(argc, argv, "e")) != -1){ switch(c){ case 'e': flags |= O_EXCL; break; } } if(optind != argc - 2) err_quit("usage: shmcreate [-e] <name> <length>"); length = atoi(argv[optind + 1]); fd = Shm_open(argv[optind], flags, FILE_MODE); Ftruncate(fd, length); ptr = Mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); exit(0); }
int main(int argc, char **argv) { int c, flags; sem_t *sem; unsigned int value; flags = O_RDWR | O_CREAT; value = 1; while ((c = Getopt(argc, argv, "ei:")) != -1) { switch (c) { case 'e': flags |= O_EXCL; break; case 'i': value = atoi(optarg); break; } } if (optind != argc - 1) err_quit("Usage: create [-e] [-i arg] <name>"); sem = Sem_open(argv[optind], flags, FILE_MODE, value); Sem_close(sem); exit(0); }
int main(int argc, char **argv) { int c, flag, mqid; long type; ssize_t n; struct msgbuf *buff; type = flag = 0; while ( (c = Getopt(argc, argv, "nt:")) != -1) { switch (c) { case 'n': flag |= IPC_NOWAIT; break; case 't': type = atol(optarg); break; } } if (optind != argc - 1) err_quit("usage: msgrcv [ -n ] [ -t type ] <pathname>"); mqid = Msgget(Ftok(argv[optind], 0), MSG_R); buff = Malloc(MAXMSG); n = Msgrcv(mqid, buff, MAXMSG, type, flag); printf("read %d bytes, type = %ld\n", n, buff->mtype); exit(0); }
int main(int argc, char *argv[]) { int c, flags; mqd_t mqd; flags = O_RDWR | O_CREAT; while( (c = Getopt(argc, argv, "em:z:")) !=-1){/*Getopt命令行参数解析*/ switch(c){ case 'e': flags |= O_EXCL; break; case 'm': attr.mq_maxmsg = atol(optarg); break; case 'z': attr.mq_msgsize = atol(optarg); break; } } if(optind != argc -1) err_quit("usage; mqcreate [-e] [-m maxmsg -z msgsize] <name>"); if((attr.mq_maxmsg != 0 && attr.mq_msgsize == 0) || (attr.mq_maxmsg == 0 && attr.mq_msgsize != 0)) err_quit("must specify both -m maxmsg and -z msgszie"); mqd = Mq_open(argv[optind], flags, FILE_MODE, (attr.mq_maxmsg != 0)? &attr:NULL); Mq_close(mqd); exit(0); }
int main(int argc, char **argv) { int c, id, oflag; char *ptr; size_t length; oflag = SVSHM_MODE | IPC_CREAT; while ( (c = Getopt(argc, argv, "e")) != -1) { switch (c) { case 'e': oflag |= IPC_EXCL; break; } } if (optind != argc - 2) err_quit("usage: shmget [ -e ] <pathname> <length>"); length = atoi(argv[optind + 1]); id = Shmget(Ftok(argv[optind], 0), length, oflag); ptr = Shmat(id, NULL, 0); printf("shm addr : %p\n", ptr); exit(0); }
/********************************************************************* * メイン ********************************************************************* */ int main(int argc,char **argv) { //オプション解析. Getopt(argc,argv,"bl"); optionCheck(); if(IsOpt('p')) { RS_printinfo(1); return 0; } RS_terminal(com_port,baudrate); if(log_fp!=NULL) fclose(log_fp); return 0; }
int GetGetOptions(int argc, char **argv, GetOptionsPtr gopt) { int opt; /* When this is called, we are always writing to disk. * In other words, we have no colon-mode to worry about. */ InitGetOptions(gopt); InitGetOutputMode(gopt, kSaveToDisk); /* Tell Getopt() that we want to start over with a new command. */ GetoptReset(); while ((opt = Getopt(argc, argv, "CfGRn:z")) >= 0) { if (SetGetOption(gopt, opt, gOptArg) == kUsageErr) return (kUsageErr); } return (kNoErr); } /* GetGetOptions */
int main(int argc, char **argv) { int c, oflag, mqid; oflag = SVMSG_MODE | IPC_CREAT; while ( (c = Getopt(argc, argv, "e")) != -1) { switch (c) { case 'e': oflag |= IPC_EXCL; break; } } if (optind != argc - 1) err_quit("usage: msgcreate [ -e ] <pathname>"); mqid = Msgget(Ftok(argv[optind], 0), oflag); exit(0); }
int main(int argc, char **argv) { int c, flags; mqd_t mqd; flags = O_RDWR | O_CREAT; while ( (c = Getopt(argc, argv, "em:z:")) != -1) { switch (c) { case 'e': flags |= O_EXCL; break; case 'm': attr.mq_maxmsg = atol(optarg); break; case 'z': attr.mq_msgsize = atol(optarg); break; } } if (optind != argc - 1) err_quit("usage: mqcreate [ -e ] [ -m maxmsg -z msgsize ] <name>"); if ((attr.mq_maxmsg != 0 && attr.mq_msgsize == 0) || (attr.mq_maxmsg == 0 && attr.mq_msgsize != 0)) err_quit("must specify both -m maxmsg and -z msgsize"); printf("about to sleep for 30 seconds before mq_open\n"); sleep(30); mqd = Mq_open(argv[optind], flags, FILE_MODE, (attr.mq_maxmsg != 0) ? &attr : NULL); printf("mq_open OK, about to sleep for 30 more seconds\n"); sleep(30); Mq_close(mqd); exit(0); }
int main(int argc, char **argv) { int optindex; char *optarg; char *optname; while (Getopt(argc, argv, OPTIONS, NOPTIONS, "Usage/help here", &optindex, &optname, &optarg)) { printf("Option: index: %d name: %s argument: %s\n", optindex, optname, optarg); } while (optindex < argc) { printf("Argument: index: %d name: %s\n", optindex, argv[optindex]); optindex++; } }
int main(int argc, char **argv) { int c, i, flag, semid, nops; struct sembuf *ptr; flag = 0; while ( (c = Getopt(argc, argv, "nu")) != -1) { switch (c) { case 'n': flag |= IPC_NOWAIT; /* for each operation */ break; case 'u': flag |= SEM_UNDO; /* for each operation */ break; } } if (argc - optind < 2) /* argc - optind = #args remaining */ err_quit("usage: semops [ -n ] [ -u ] <id> operation ..."); semid = atol(argv[optind]); optind++; nops = argc - optind; /* 4allocate memory to hold operations, store, and perform */ ptr = Calloc(nops, sizeof(struct sembuf)); for (i = 0; i < nops; i++) { ptr[i].sem_num = i; ptr[i].sem_op = atoi(argv[optind + i]); /* <0, 0, or >0 */ ptr[i].sem_flg = flag; } Semop(semid, ptr, nops); exit(0); }
/* FIX: this wants to become gnu-ish */ void handleArgs(int argc, char *argv[]) { char dummy[10]; date_t greg_today; int option; char *usage = /* not quite sure how compatible this is */ "usage: \n\ hebcal [-acdDehHiMoOrsStTwxy]\n\ [-b candle_lighting_minutes_before_sundown]\n\ [-I input_file]\n\ [-Y yahrtzeit_file]\n\ [-C city]\n\ [-L longitude -l latitude]\n\ [-m havdalah_minutes]\n\ [-z timezone]\n\ [-Z daylight_savings_scheme]\n\ [[month [day]] year]\n\ hebcal help\n\ hebcal info\n\ hebcal DST\n\ hebcal cities\n\ hebcal warranty\n\ hebcal copying\n"; setDate(&greg_today); /* keep the current greg. date here */ Getopt(argc, argv, "", 1); while (EOF != (option = Getopt(argc, argv, "ab:cC:dDeFf:hHI:il:L:m:MoOrsStTwxyY:z:Z:8", 0))) { switch ((char) option) { case 'a': /* ashkenazis hebrew */ ashkenazis_sw = 1; break; case '8': /* ashkenazis hebrew */ iso8859_8_sw = 1; break; case 'b': /* candle_lighting_minutes_before_sundown */ if (!(sscanf(Optarg, "%d", &light_offset) == 1)) die("unable to read candle_lighting_minutes_before_sundown argument: %s", Optarg); light_offset *= -1; break; case 'c': /* calculate candlelighting times on fridays */ candleLighting_sw = 1; break; case 'C': localize_to_city(Optarg); candleLighting_sw = 1; break; case 'd': /* print hebrew date */ printHebDates_sw = 1; break; case 'D': /* print hebrew date when there's */ /* something else to print */ printSomeHebDates_sw = 1; break; case 'I': /* input file */ inputFile_sw = 1; if (!(inFile = fopen(Optarg, "r"))) die("could not open input file %s.", Optarg); break; case 'e': /* european date format */ euroDates_sw = 1; break; case 'f': /* output format */ formatString = strdup(Optarg); break; case 'F': /* Daf Yomi */ dafYomi_sw = 1; break; case 'h': /* suppress internal holidays */ noHolidays_sw = 1; break; case 'H': /* suppress use hebrew range dates */ hebrewDates_sw = 1; break; case 'i': /* use Israeli sedra scheme */ israel_sw = 1; break; case 'l': /* latitude */ latdeg = latmin = 0; latp = 1; if (sscanf(Optarg, "%d,%d", &latdeg, &latmin) < 2) die("unable to read latitude argument: %s", Optarg); if ((abs(latdeg) > 90) || latmin > 60 || latmin < 0) die("latitude argument out of range", ""); latmin = abs(latmin); if (latdeg < 0) latmin = -latmin; break; case 'L': /* longitude */ longdeg = longmin = 0; longp = 1; if (sscanf(Optarg, "%d,%d", &longdeg, &longmin) < 2) die("unable to read longitude argument: %s", Optarg); if ((abs(longdeg) > 180) || longmin > 60 || longmin < 0) die("longitude argument out of range", ""); longmin = abs(longmin); if (longdeg < 0) longmin = -longmin; break; case 'm': /* havdalah_minutes */ if (!(sscanf(Optarg, "%d", &havdalah_minutes) == 1)) die("unable to read havdalah_minutes argument: %s", Optarg); break; case 'M': /* print the molad */ printMolad_sw = 1; break; case 'o': /* print the omer */ printOmer_sw = 1; break; case 'O': /* print sunrise and sunset */ printSunriseSunset_sw = 1; break; case 'r': /* Tab-delineated Format */ tabs_sw = 1; break; case 's': /* print sedrot */ sedrot_sw = 1; break; case 'S': /* print sedra every day. */ sedraAllWeek_sw = 1; break; case 'T': /* do hebcal for today, omit gregorian date. */ noGreg_sw = 1; /*** note this falls through to 't' case ***/ case 't': /* do hebcal for today. */ printHebDates_sw = 1; rangeType = TODAY; theMonth = greg_today.mm; /* year and month specified */ theDay = greg_today.dd; /* printc theDay of theMonth */ yearDirty = 1; printOmer_sw = 1; break; case 'w': /* print days of the week */ weekday_sw = 1; break; case 'y': /* Print only last 2 digits of year */ yearDigits_sw = 1; break; case 'Y': /* input file */ yahrtzeitFile_sw = 1; if (!(yFile = fopen(Optarg, "r"))) die("could not open yahrtzeit input file %s.", Optarg); break; case 'x': /* input file */ suppress_rosh_chodesh_sw = 1; break; case 'Z': schemep = 1; sscanf(Optarg, "%s", dummy); set_DST_scheme(dummy); break; case 'z': /* time zone */ if (!(sscanf(Optarg, "%d", &TZ) == 1)) die("unable to read time zone argument: %s", Optarg); if (!schemep) DST_scheme = DST_NONE; zonep = 1; break; default: die(usage, ""); } } if (latp) cityName = "User Defined City"; if (latp ^ longp) die("You must enter BOTH the latitude and the longitude", ""); if( !strcmp(cityName, "Jerusalem" )) light_offset = -40; /* does everyone hold by this? */ switch (argc - Optind) /* suck up the date */ { case 0: /* process this year */ if (hebrewDates_sw) theYear = abs2hebrew(greg2abs(greg_today)).yy; else theYear = greg_today.yy; break; case 1: if (isAllNums(argv[Optind])) { theYear = atoi(argv[Optind]); /* just year specified */ yearDirty = 1; /* print whole year */ } else if (0 == istrncasecmp(5, argv[Optind], "help")) { size_t lineNumber; for (lineNumber = 0; (lineNumber < sizeof(helpArray) / sizeof(char *)); lineNumber++) { puts(helpArray[lineNumber]); } exit(0); } else if (0 == istrncasecmp(3, argv[Optind], "info")) { print_version_data(); exit(0); } else if (0 == istrncasecmp(3, argv[Optind], "cities")) { print_city_data(); exit(0); } else if (0 == istrncasecmp(3, argv[Optind], "DST")) { print_DST_data(); exit(0); } else if (0 == istrncasecmp(3, argv[Optind], "copying")) { print_copying(); exit(0); } else if (0 == istrncasecmp(3, argv[Optind], "warranty")) { print_warranty(); exit(0); } else die(usage, ""); break; case 2: if (!isAllNums(argv[Optind + 1])) die(usage, ""); theYear = atoi(argv[Optind + 1]); /* print theMonth of theYear */ theMonth = lookup_hebrew_month(argv[Optind]); if (theMonth) { hebrewDates_sw = 1; /* automagically turn it on */ if (theMonth == ADAR_II && !LEAP_YR_HEB(theYear)) theMonth = ADAR_I; /* silently fix this mistake */ } else if (isAllNums(argv[Optind])) if (hebrewDates_sw) die("Don't use numbers to specify hebrew months.", ""); else theMonth = atoi(argv[Optind]); /* gregorian month */ else if (hebrewDates_sw) die("Unknown hebrew month: %s", argv[Optind]); else die(usage, ""); /* bad gregorian month. */ Optind++; yearDirty = 1; rangeType = MONTH; break; case 3: if (!(isAllNums(argv[Optind + 1]) && isAllNums(argv[Optind + 2]))) die(usage, ""); theDay = atoi(argv[Optind + 1]); /* print theDay of theMonth */ theYear = atoi(argv[Optind + 2]); /* print theMonth of theYear */ theMonth = lookup_hebrew_month(argv[Optind]); if (theMonth) { hebrewDates_sw = 1; /* automagically turn it on */ if (theMonth == ADAR_II && !LEAP_YR_HEB(theYear)) theMonth = ADAR_I; /* silently fix this mistake */ } else if (isAllNums(argv[Optind])) if (hebrewDates_sw) die("Don't use numbers to specify hebrew months.", ""); else theMonth = atoi(argv[Optind]); /* gregorian month */ else if (hebrewDates_sw) die("Unknown hebrew month: %s", argv[Optind]); else die("bad month.%s", usage); /* bad gregorian month. */ if (theDay < 1) die("The day of the month must be greater than 0", ""); if (theMonth < 1) die("The month must be greater than 0", ""); if (hebrewDates_sw) { if (theDay > max_days_in_heb_month(theMonth, theYear)) die("Sorry, there aren't that many days in %s (then)", LANGUAGE2(hMonths[LEAP_YR_HEB(theYear)][theMonth].name)); } else { if (theMonth > 12) die("The month must be less than 13", ""); if (theDay > MonthLengths[LEAP(theYear)][theMonth]) die("Sorry, there aren't that many days in %s (then)", eMonths[theMonth]); } rangeType = DAY; yearDirty = 1; break; default: die(usage, ""); } }
int main(int argc,char *argv[]) { char filename[STRING],*path; int opcja,TimeSrand=OFF,i,makebatch=OFF,OldPrn; #ifdef MULTITHREAD /* UWAGA ! Blokowanie sygnalu SIGCLD zapobiega powstawaniu procesow ZOMBI w przypadku wczesniejszego zakonczenia procesu potomnego konstrukcja nieprzenosna dziala pod Linux'em */ if(signal(SIGCLD,SIG_IGN)==SIG_ERR) { fprintf(stderr,"Problems trapping signal SIGCLD !\n"); return 1; } #endif sortAlphabetic(); /* Sortowanie polecen w kolejnosci alfabetycznej */ OldDimRoz=32; /* Liczba atomow do rekonstrukcji */ DimBase=512; /* Wymiar sygnalu */ epsylon=95.0F; /* Dokladniosc rekonstrukcji */ prn=ON; /* Drukowanie informacji */ SamplingRate=1.0; /* Czestotliwosc probkowania */ ConvRate=1.0; /* Wspolczynnik konwersji */ RandomType=NOFUNCRND; /* Sposob generacji atomow */ DiadicStructure=OFF; /* Diadyczna struktura slownika */ FastMode=ON; /* Szybka generacja atomow (wymaga duzo pamieci) */ VeryFastMode=ON; /* Bardzo szybka generacja iloczynow skalarnych */ DictionSize=70000; /* Domyslny rozmiar slownika */ Heuristic=OFF; /* Wspomaganie heurystyczne */ StartDictionSize=25000; /* Rozmiar slownika do probkowania */ MallatDiction=OFF; /* Slownik Mallata */ OverSampling=2; /* Przeprobkowanie slownika */ while((opcja=Getopt(argc,argv,"R:P:E:M:HhB:O:F:C:i:x:dsfN:TS:v:JD:X"))!=EOF) { switch(opcja) { case 'X': debug=1; break; case 'S': OverSampling=atoi(optarg); case 'T': MallatDiction=ON; DiadicStructure=ON; break; case 'N': Heuristic=ON; /* Pozostale parametry domyslne w mp.c */ sscanf(optarg,"%d,%d,%d,%d",&StartDictionSize,&ROctave, &RFreqency,&RPosition); break; case 'v': if(strcmp(optarg,"+")==0) FastMode=VeryFastMode=ON; else if(strcmp(optarg,"-")==0) VeryFastMode=OFF; else { fprintf(stderr,"Available options -v[-|+] !\n"); return 1; } break; case 'P': if(strcmp(optarg,"+")==0) prn=ON; else if(strcmp(optarg,"-")==0) prn=OFF; else { fprintf(stderr,"Available options -P[-|+] !\n"); return 1; } break; case 'f': FastMode=ON; break; case 's': FastMode=OFF; break; case 'd': DiadicStructure=ON; break; case 'R': DictionSize=atoi(optarg); break; case 'x': (void)strcpy((char *)FunctionCode,optarg); RandomType=FUNCRND; MallatDiction=OFF; break; case 'i': if(strcmp(optarg,"+")==0) TimeSrand=ON; else if(strcmp(optarg,"-")==0) TimeSrand=OFF; else { fprintf(stderr,"Available options -i[-|+] !\n"); return 1; } break; case 'O': DimBase=atoi(optarg); break; case 'F': SamplingRate=atof(optarg); break; case 'C': ConvRate=atof(optarg); break; case 'B': (void)strcpy(filename,optarg); makebatch=ON; break; case 'M': OldDimRoz=atoi(optarg); break; case 'E': epsylon=atof(optarg); break; case 'J': /* Wylaczenie buforowania */ javaMode=ON; setvbuf(stdout,(char *)NULL,_IOLBF,0); setvbuf(stderr,(char *)NULL,_IOLBF,0); break; case 'D': AdaptiveConst=(float)atof(optarg); break; case 'H': case 'h': default: PrintHelp(); return 0; } } SetTuneScale(); OldPrn=prn; /* Blokowanie drukowanie inforamcji */ prn=OFF; if(MallatDiction==ON) DictionSize=MakeMallatDictionary(DimBase,OverSampling,OFF); if((path=getenv("MP_PATH"))==NULL) /* Sciezka dla batch'y */ { char path2[10]="."; if(prn==ON) /*PJD fprintf(stderr,"\nWARNING: environment variable MP_PATH not set !\n");*/ fprintf(stderr,"\nPath set to \".\" (HMPP env. var. not set)\n"); SetBatchPath(path2); } else SetBatchPath(path); if(Heuristic==ON) /* Poprawnosc konfiguracji */ { if(StartDictionSize>=DictionSize) Heuristic=OFF; else if(FastMode==OFF) Heuristic=OFF; else if(DiadicStructure==OFF) Heuristic=OFF; } if(Heuristic==OFF) StartDictionSize=DictionSize; if(prn==ON && RandomType==FUNCRND) fprintf(stdout,"VAL= %s\n",FunctionCode); if(InicRandom(TimeSrand)==-1) { fprintf(stderr,"Problem initializing stochastic dictionary:(\n"); return 1; } if((sygnal=MakeVector(3*DimBase))==NULL || (OrgSygnal=MakeVector(DimBase))==NULL) { fprintf(stderr,"Memory allocation error (main:(\n"); return 1; } for(i=0 ; i<3*DimBase ; i++) sygnal[i]=0.0F; for(i=0 ; i<DimBase ; i++) OrgSygnal[i]=0.0F; AllocStatus=ON; if(Batch(commands,"mp.cfg",NULL)==-1) /* Plik konfiguracyjny */ { char name[STRING]; strcmp(name,BatchPath); strcat(name,"mp.cfg"); if(Batch(commands,name,NULL)==-1) if(prn==ON) fprintf(stderr,"\nNo config file (mp.cfg)\n"); } prn=OldPrn; /* mozna ustawic prn */ if(makebatch==ON) { if(Batch(commands,filename,NULL)==-1) /* Wykonanie skryptu */ { fprintf(stderr,"cannot find script file %s\n",filename); return 1; } } if(prn==ON) { SourceVersion(NULL); SetMPP(""); } Shell(commands,help); /* Rozpoczecie trybu iteracyjnego */ CloseRand2D(); free((void *)sygnal); free((void *)OrgSygnal); CloseTune(); return 0; }
main (int argc, char ** argv ) { char *seqfile; /* name of sequence file */ SQINFO sqinfo; /* extra info about sequence */ SQFILE *dbfp; /* open sequence file */ int fmt,ofmt=106; /* format of seqfile */ /* 106 is PHYLIP format in SQUID */ char *seq; /* sequence */ int type; /* kAmino, kDNA, kRNA, or kOtherSeq */ sequence * seqs, * cds_seqs; sequence tmp_seqs[2], tmp_cds_seqs[2]; char *optname; char *optarg, *t; int optind; int be_quiet; int seqct = 0,cdsct = 0; int min_aln_len = 0; int do_oneline = 0; char * output_filename = 0, *submat_file = 0; int showaln = 1; int showheader=1; FILE *ofd, *fd; alignment *cds_aln; alignment * opt_alignment = NULL; /* place for pairwise alignment */ int len,i,j, k, jk,ik,aln_count, rc; pairwise_distances pwMLdist, pwNGdist; int firsttime = 1; struct timeval tp; pwMLdist.N = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwMLdist.dN = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwMLdist.S = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwMLdist.dS = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwMLdist.dNdS = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwMLdist.SEdS = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwMLdist.SEdN = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwMLdist.t = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwMLdist.kappa= make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwNGdist.dN = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwNGdist.dS = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); pwNGdist.dNdS = make_double_matrix(NUM_PW_SEQS,NUM_PW_SEQS); /* pwMLdist.N = pwMLdist.dN = pwMLdist.S = 0; pwMLdist.dS = pwMLdist.dNdS = pwMLdist.SEdS = 0; pwMLdist.SEdN = pwMLdist.t = pwMLdist.kappa= 0; pwNGdist.dN = pwNGdist.dS = pwNGdist.dNdS = 0; */ Alntype = default_aln_type; /* Command line Parse */ fmt = SQFILE_UNKNOWN; /* default: autodetect format */ be_quiet = FALSE; type = kOtherSeq; /* for our purposes this is only pairwise alignments, but * would rather do it correctly in case we move to MSA case */ while (Getopt(argc, argv, OPTIONS, NOPTIONS, usage, &optind, &optname, &optarg)) { if (strcmp(optname, "--matrix") == 0) submat_file = optarg; else if (strcmp(optname, "--quiet") == 0) be_quiet = TRUE; else if (strcmp(optname, "--gapopen") == 0) { Gapopen = atoi(optarg); if( Gapopen < 0 ) Gapopen *= -1; } else if (strcmp(optname, "--gapext") == 0) { Gapext = atoi(optarg); if( Gapext < 0 ) Gapext *= -1; } else if (strcmp(optname, "--informat") == 0) { fmt = String2SeqfileFormat(optarg); if (fmt == SQFILE_UNKNOWN) Die("unrecognized sequence file format \"%s\"", optarg); } else if (strcmp(optname, "--outformat") == 0) { ofmt = String2SeqfileFormat(optarg); if (ofmt == SQFILE_UNKNOWN) Die("unrecognized sequence file format \"%s\"", optarg); } else if( strcmp(optname, "--global") == 0 ) { Alntype = global; } else if (strcmp(optname, "-h") == 0) { puts(usage); puts(experts); exit(EXIT_SUCCESS); } else if ( strcmp(optname, "-v") == 0 ) { Verbose = 1; } else if ( strcmp(optname, "--gapchar") == 0 ) { GapChar = optarg[0]; } else if( strcmp(optname, "--output") == 0 ) { output_filename = optarg; } else if( strcmp(optname, "--showtable" ) == 0 ) { showaln = 0; } else if( strcmp(optname, "--noheader" ) == 0 ) { showheader = 0; } } if (argc - optind < 1) Die("%s\n", usage); if( ! submat_file ) { if( (t = getenv("SUBOPTDIR")) != 0 || (t = getenv("SUBOPT_DIR")) != 0 ) { submat_file = calloc(strlen(t) + 24, sizeof(char)); sprintf(submat_file, "%s/%s",t,Default_submat); } else { submat_file = calloc(strlen((void *)Default_submat) + 24, sizeof(char)); sprintf(submat_file, "../%s",Default_submat); } } /* open matrix */ fd = fopen(submat_file, "r"); if( ! ParsePAMFile(fd,&ScoringMatrix, &MatrixScale) ) { fprintf(stderr, "Cannot parse or open matrix file %s\n",submat_file); free(submat_file); exit(EXIT_SUCCESS); } if( output_filename && strlen(output_filename) != 1 && output_filename[0] != '-') { ofd = fopen(output_filename,"w"); if( ! ofd ) { fprintf(stderr, "could not open file %s",output_filename); goto end; } } else ofd = stdout; while( optind < argc ) { seqfile = argv[optind++]; /* Try to work around inability to autodetect from a pipe or .gz: * assume FASTA format */ if (fmt == SQFILE_UNKNOWN && (Strparse("^.*\\.gz$", seqfile, 0) || strcmp(seqfile, "-") == 0)) fmt = SQFILE_FASTA; if ((dbfp = SeqfileOpen(seqfile, fmt, NULL)) == NULL) Die("Failed to open sequence file %s for reading", seqfile); while (ReadSeq(dbfp, dbfp->format, &seq, &sqinfo)) { FreeSequence(NULL, &sqinfo); seqct++; } cds_seqs = (sequence *)calloc(seqct, sizeof(sequence)); seqs = (sequence *)calloc(seqct, sizeof(sequence)); SeqfileRewind(dbfp); seqct=0; while (ReadSeq(dbfp, dbfp->format, &seq, &sqinfo)) { sqinfo.type = Seqtype(seq); if( sqinfo.type == kDNA || sqinfo.type == kRNA ) { seqs[seqct].seqstr = Translate(seq,stdcode1); /* Let's remove the last codon if it is a stop codon */ len = strlen(seqs[seqct].seqstr); if( Verbose ) fprintf(stderr,"seqct is %d length is %d\n",seqct, len); if( seqs[seqct].seqstr[len-1] == '*' ) { seqs[seqct].seqstr[len-1] = '\0'; seq[strlen(seq) - 3] = '\0'; } cds_seqs[cdsct].seqstr = seq; seqs[seqct].seqname = calloc(strlen(sqinfo.name)+1,sizeof(char)); cds_seqs[cdsct].seqname = calloc(strlen(sqinfo.name)+1,sizeof(char)); strcpy(seqs[seqct].seqname,sqinfo.name ); strcpy(cds_seqs[cdsct].seqname,sqinfo.name); cds_seqs[cdsct].length = sqinfo.len; cds_seqs[cdsct].alphabet = ( sqinfo.type == kDNA ) ? dna : rna; seqs[seqct].length = strlen(seqs[seqct].seqstr); seqs[seqct].alphabet = protein; cdsct++; seqct++; } else { fprintf(stderr,"Expect CDS sequences (DNA or RNA) not Protein\n"); goto end; } FreeSequence(NULL, &sqinfo); if( Verbose && seqct > 3 ) break; } if( seqct < 2 ) { fprintf(stderr,"Must have provided a valid file with at least 2 sequences in it"); goto end; } for( i=0; i < seqct; i++ ) { for(k=i+1; k < seqct; k++ ) { if( (opt_alignment = (alignment *)calloc(1,sizeof(alignment *))) == NULL) { fprintf(stderr,"Could not allocate memory\n"); goto end; } opt_alignment->msa = NULL; rc = optimal_align(&seqs[i],&seqs[k],opt_alignment); if( rc != 1 ) { fprintf(stderr,"Could not make an optimal alignment\n"); goto end; } else { tmp_cds_seqs[0] = cds_seqs[i]; tmp_cds_seqs[1] = cds_seqs[k]; rc = mrtrans(opt_alignment, tmp_cds_seqs, &cds_aln,0); if( rc != 0 ) { fprintf(stderr, "Could not map the coding sequence to the protein alignemnt for aln %d: %d\n",i,rc); goto end; } if( showaln ) { if( ofmt >= 100 ) { MSAFileWrite(ofd,cds_aln->msa, ofmt,do_oneline); } else { for(j=0; j < cds_aln->msa->nseq; j++ ) { WriteSeq(ofd, ofmt, cds_aln->msa->aseq[j], &(cds_aln->sqinfo[j]) ); } } } else { if( showheader && firsttime ) { fprintf(ofd,"SEQ1\tSEQ2\tSCORE\tdN\tdS\tOMEGA\tN\tS\tkappa\tt\tLENGTH\n"); firsttime = 0; } if( do_kaks_yn00(cds_aln->msa, &pwMLdist,&pwNGdist) < 0 ) { fprintf(stderr, "warning: problem with align for %s %s\n", cds_aln->msa->sqname[0], cds_aln->msa->sqname[1]); continue; } for(ik = 0; ik < NUM_PW_SEQS; ik++ ) { for( jk = ik+1; jk < NUM_PW_SEQS; jk++ ) { fprintf(ofd,"%s\t%s\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%d\n", cds_aln->sqinfo[ik].name, cds_aln->sqinfo[jk].name, opt_alignment->score, pwMLdist.dN[ik][jk],pwMLdist.dS[ik][jk], pwMLdist.dNdS[ik][jk], pwMLdist.N[ik][jk], pwMLdist.S[ik][jk], pwMLdist.kappa[ik][jk], pwMLdist.t[ik][jk], opt_alignment->msa->alen); } } } } cleanup_alignment(cds_aln); cleanup_alignment(opt_alignment); } } } if( ofd && ofd != stdout ) fclose(ofd); end: free(submat_file); Free2DArray((void **)ScoringMatrix,27); for(i =0; i< seqct; i++ ) { free(seqs[i].seqstr); free(seqs[i].seqname); seqs[i].seqstr = seqs[i].seqname = 0; } for(i = 0; i < cdsct; i++) { free(cds_seqs[i].seqstr); free(cds_seqs[i].seqname); cds_seqs[i].seqstr = cds_seqs[i].seqname = 0; } cleanup_matrix((void **)pwMLdist.N,NUM_PW_SEQS); cleanup_matrix((void **)pwMLdist.dN,NUM_PW_SEQS); cleanup_matrix((void **)pwMLdist.S,NUM_PW_SEQS); cleanup_matrix((void **)pwMLdist.dS,NUM_PW_SEQS); cleanup_matrix((void **)pwMLdist.SEdS,NUM_PW_SEQS); cleanup_matrix((void **)pwMLdist.SEdN,NUM_PW_SEQS); cleanup_matrix((void **)pwMLdist.t,NUM_PW_SEQS); cleanup_matrix((void **)pwMLdist.dNdS,NUM_PW_SEQS); cleanup_matrix((void **)pwMLdist.kappa,NUM_PW_SEQS); cleanup_matrix((void **)pwNGdist.dN,NUM_PW_SEQS); cleanup_matrix((void **)pwNGdist.dS,NUM_PW_SEQS); cleanup_matrix((void **)pwNGdist.dNdS,NUM_PW_SEQS); free(pwNGdist.dNdS); free(pwNGdist.dN); free(pwNGdist.dS); free(pwMLdist.dNdS); free(pwMLdist.dN); free(pwMLdist.dS); free(pwMLdist.N); free(pwMLdist.S); free(pwMLdist.SEdS); free(pwMLdist.SEdN); free(pwMLdist.t); free(pwMLdist.kappa); return 0; }
int main(int argc, char **argv) { static char *format = "h@vn:E:"; static char *help = "Usage: %s [-h][-v][-n <nb>][-E <epoch>][Script_File1 [Script_File2]...]\n"; int option, rc; int err_flag = 0; int flag_h = 0; int nb_instance = 0; char *prompt = "ganeshell>"; char *script_file = NULL; char *progname = basename(argv[0]); int nb_threads = 0; /* Set the server's boot time and epoch */ ServerBootTime = time(NULL); ServerEpoch = ServerBootTime; /* disables Getopt error message */ Opterr = 0; /* reinits Getopt processing */ Optind = 1; while((option = Getopt(argc, argv, format)) != -1) { switch (option) { case 'h': if(flag_h) fprintf(stderr, "%s: warning: option 'h' has been specified more than once.\n", progname); else flag_h++; break; case '@': /* A litlle backdoor to keep track of binary versions */ printf("%s compiled on %s at %s\n", progname, __DATE__, __TIME__); printf("Release = %s\n", VERSION); printf("Release comment = %s\n", VERSION_COMMENT); exit(0); break; case 'n': if(nb_instance) fprintf(stderr, "%s: warning: option 'n' has been specified more than once.\n", progname); else nb_instance = atoi(Optarg); break; case 'v': if(verbose) fprintf(stderr, "%s: warning: option 'v' has been specified more than once.\n", progname); else verbose++; break; case 'E': ServerEpoch = (time_t) atoll(Optarg); break; case '?': fprintf(stderr, "%s: unknown option : %c\n", progname, Optopt); err_flag++; break; } } /* help flag */ if(flag_h || err_flag) { fprintf(stderr, help, basename(progname)); exit(err_flag); } #ifdef HAVE_LIBREADLINE /* Initialize history */ using_history(); #endif /* case when the 'n' option is specified */ if(nb_instance != 0) { int i; /* case when there two or more threads */ for(i = 0; i < nb_instance; i++) { if(verbose) fprintf(stderr, "Starting thread %d using file %s...\n", nb_threads, argv[Optind]); thrlist[nb_threads].shell_id = nb_threads; snprintf(thrlist[nb_threads].prompt, 32, "ganeshell-%d>", nb_threads); strncpy(thrlist[nb_threads].script_file, argv[Optind], 128); pthread_attr_init(&thrlist[nb_threads].attrs); pthread_attr_setscope(&thrlist[nb_threads].attrs, PTHREAD_SCOPE_SYSTEM); nb_threads++; if(nb_threads >= NBTHRMAX) { fprintf(stderr, "GANESHELL: Too much threads (%d > %d)\n", nb_threads, NBTHRMAX); exit(1); } } /* inits shell barriers */ rc = shell_BarrierInit(nb_threads); if(rc) { fprintf(stderr, "GANESHELL: ERROR %d in shell_BarrierInit\n", rc); exit(1); } /* launching threads */ for(i = 0; i < nb_threads; i++) { rc = pthread_create(&thrlist[i].thread, &thrlist[i].attrs, LaunchShell, &thrlist[i]); if(rc) { fprintf(stderr, "GANESHELL: ERROR %d in pthread_create\n", rc); exit(1); } } /* waiting for thread termination */ for(i = 0; i < nb_threads; i++) { void *ret; pthread_join(thrlist[i].thread, &ret); } exit(0); } /* case when there is only zero or one script file */ else if(Optind >= (argc - 1)) { if(Optind == (argc - 1)) { script_file = argv[Optind]; } rc = shell_Init(verbose, script_file, prompt, 0); if(rc) { fprintf(stderr, "GANESHELL: ERROR %d in shell_Init\n", rc); exit(1); } rc = shell_Launch(); if(rc) { fprintf(stderr, "GANESHELL: ERROR %d in shell_Launch\n", rc); exit(1); } exit(0); } else { int i; /* case when there two or more threads */ for(i = Optind; i < argc; i++) { if(verbose) fprintf(stderr, "Starting thread %d using file %s...\n", nb_threads, argv[i]); thrlist[nb_threads].shell_id = nb_threads; snprintf(thrlist[nb_threads].prompt, 32, "ganeshell-%d>", nb_threads); strncpy(thrlist[nb_threads].script_file, argv[i], 128); pthread_attr_init(&thrlist[nb_threads].attrs); pthread_attr_setscope(&thrlist[nb_threads].attrs, PTHREAD_SCOPE_SYSTEM); nb_threads++; if(nb_threads >= NBTHRMAX) { fprintf(stderr, "GANESHELL: Too much threads (%d > %d)\n", nb_threads, NBTHRMAX); exit(1); } } /* inits shell barriers */ rc = shell_BarrierInit(nb_threads); if(rc) { fprintf(stderr, "GANESHELL: ERROR %d in shell_BarrierInit\n", rc); exit(1); } /* launching threads */ for(i = 0; i < nb_threads; i++) { rc = pthread_create(&thrlist[i].thread, &thrlist[i].attrs, LaunchShell, &thrlist[i]); if(rc) { fprintf(stderr, "GANESHELL: ERROR %d in pthread_create\n", rc); exit(1); } } /* waiting for thread termination */ for(i = 0; i < nb_threads; i++) { void *ret; pthread_join(thrlist[i].thread, &ret); } exit(0); } }
void FloatCanalEEG(char *opt) /* Analiza kanalu z symetrycznymi warunkami brzegowymi */ { static char Common[STRING],*argv[MAXARGS],filename[STRING], Para[STRING],bookname[STRING],tmpstr[STRING]; int argc,opcja,offset=0,ok=0,IleSegmentow,Nkan=1,i,ok2=0,maxseg=-1, k,j,shift=0,ReinicRandomDic=OFF,ascii=OFF; Common[0]='\0'; strcpy(bookname,"-a"); /* Domyslna nazwa ksiazki */ StrToArgv(opt,argv,&argc); opterr=optind=0; sp=1; while((opcja=Getopt(argc,argv,"O:#:c:t:h:I:M:s:R"))!=EOF) switch(opcja) { case 'R': ReinicRandomDic=ON; break; case 'O': (void)strcpy(filename,optarg); if(CzyJestTakiPlik(filename)==-1) { FreeArgv(argv,argc); return; } sprintf(tmpstr,"-O%s ",optarg); (void)strcat(Common,tmpstr); ok=1; break; case 'c': sprintf(tmpstr,"-c%d ",(ChannelNumber=atoi(optarg)-1)+1); (void)strcat(Common,tmpstr); break; case 's': sprintf(tmpstr,"-s%s ",optarg); (void)strcat(Common,tmpstr); shift=atoi(optarg); break; case 'h': sprintf(tmpstr,"-h%d ",ChannelMaxNum=atoi(optarg)); (void)strcat(Common,tmpstr); Nkan=atoi(optarg); break; case '#': offset=atoi(optarg); break; case 'I': /* Zmiana nazwy ksiazki */ sprintf(bookname,"-A %s",optarg); break; case 'M': maxseg=atoi(optarg); /* Maksymalny numer segmentu */ break; case 't': if(strcmp(optarg,"ascii")==0) ascii=ON; else if(strcmp(optarg,"binary")==0) ascii=OFF; else fprintf(stderr,"Opcja -t %s zignorowana !\n",optarg); break; default: fputs("Niezana opcja !\n\r",stderr); FreeArgv(argv,argc); return; } FreeArgv(argv,argc); if(ok==0) { fputs("Nie podano nazwy pliku !\n\r",stderr); return; } setChannel=0; /* Okreslenie liczby segmentow (FLOAT) */ IleSegmentow=(int)(FileSizeChar(filename)/ ((long)Nkan*(long)sizeof(float)*(long)(DimBase+shift))); if(maxseg>0) IleSegmentow=MIN(IleSegmentow,maxseg); if(prn==1) fprintf(stdout,"\t\t<<< ANALIZA KANALU EEG (FLOATROTT WITH SYM) >>>\n" "\t\t (%d SEGMENTOW %d DO ANALIZY)\n", IleSegmentow,IleSegmentow-offset); for(i=offset,k=1 ; i<IleSegmentow ; i++,k++) { const int itmp=2*(int)DimBase; if(prn==1) fprintf(stdout,"\t<<< ANALIZA %d REKORDU >>>\n",i+1); Reset(NULL); /* Zera wszedzie */ LOAD_FLOAT_SIGNAL(i,-C); /* Ladujemy segment centralny */ for(j=0 ; j<(int)DimBase ; j++) /* Asymetryczne warunki brzegowe */ { sygnal[(int)DimBase-1-j]=-sygnal[j]; sygnal[itmp+j]=-sygnal[itmp-1-j]; } REINIC(); AnalizaMP(NULL); file_offset=i; /* Ladowanie zmienia file_offset */ if(ascii==OFF) SaveAllNewAtoms(bookname); /* Zapis ksiazki na dysku */ else { TranslateAtoms(DimBase*i); AscSaveAllAtoms(bookname); } } setChannel=1; if(prn==1) fprintf(stdout,"<<< KONIEC ANALIZY KANALU EEG (FLOATROTT WITH SYM) >>>\n"); }
void MakeCanalEEG(char *opt) /* Analiza EEG (niezalezne warunki brzegowe) */ { static char Common[STRING],*argv[MAXARGS],filename[STRING], Para[STRING],bookname[STRING],tmpstr[STRING]; int argc,opcja,offset=0,ok=0,IleSegmentow,Nkan=1,i, ok2=0,maxseg=-1,k,ReinicRandomDic=OFF,ascii=OFF; Common[0]='\0'; (void)strcpy(bookname,"-a"); /* Domyslna nazwa ksiazki */ StrToArgv(opt,argv,&argc); opterr=optind=0; sp=1; while((opcja=Getopt(argc,argv,"O:#:c:h:s:e:f:I:M:Rt:"))!=EOF) switch(opcja) { /* Podstawowe opcje sa powtarzane */ case 'R': ReinicRandomDic=ON; break; case 'O': strcpy(filename,optarg); if(CzyJestTakiPlik(filename)==-1) { FreeArgv(argv,argc); return; } sprintf(tmpstr,"-O%s ",optarg); strcat(Common,tmpstr); ok=1; break; case 'c': sprintf(tmpstr,"-c%d ",(ChannelNumber=atoi(optarg)-1)+1); strcat(Common,tmpstr); break; case 'h': sprintf(tmpstr,"-h%d ",ChannelMaxNum=atoi(optarg)); strcat(Common,tmpstr); Nkan=atoi(optarg); break; case 's': sprintf(tmpstr,"-s%s ",optarg); strcat(Common,tmpstr); break; case 'e': sprintf(tmpstr,"-e%d ",atoi(optarg)); strcat(Common,tmpstr); break; case 'f': sprintf(tmpstr,"-f%d ",atoi(optarg)); strcat(Common,tmpstr); break; case '#': offset=atoi(optarg); break; case 'I': /* Zmiana nazwy ksiazki */ sprintf(bookname,"-A %s",optarg); break; case 'M': maxseg=atoi(optarg); /* Maksymalny numer segmentu */ break; case 't': if(strcmp(optarg,"ascii")==0) ascii=ON; else if(strcmp(optarg,"binary")==0) ascii=OFF; else fprintf(stderr,"Opcja -t %s zignorowana !\n",optarg); break; default: fputs("Niezana opcja !\n\r",stderr); FreeArgv(argv,argc); return; } FreeArgv(argv,argc); if(ok==0) { fputs("Nie podano nazwy pliku !\n\r",stderr); return; } setChannel=0; IleSegmentow=(int)(FileSizeChar(filename)/ ((long)Nkan*(long)sizeof(short)*(long)DimBase)); if(maxseg>0) IleSegmentow=((IleSegmentow<maxseg) ? IleSegmentow : maxseg); if(IleSegmentow<3) { fputs("Za malo segmentow do analizy (>3) !\n\r",stderr); return; } /* Utworzenie ksiazki z calego kanalu */ if(prn==1) fprintf(stdout,"\t\t<<< ANALIZA KANALU EEG >>>\n" "\t\t (%d SEGMENTOW %d DO ANALIZY)\n",IleSegmentow,IleSegmentow-offset); if(prn==1) fprintf(stdout,"\n\t<<< ANALIZA 1 REKORDU >>>\n"); Reset(NULL); /* Domyslnie lewym warunkiem brzegowym beda 0 */ LOAD_SIGNAL(offset,-C); /* Lodowanie sygnalu */ LOAD_SIGNAL(offset+1,-R); /* Lodowanie prawego warunku brzegowego */ REINIC(); /* Reinicjacja slownika */ AnalizaMP(NULL); /* Analiza sygnalu */ file_offset=offset; /* Ustawiamy offset pliku (ladowanie przekreca) */ if(ascii==OFF) SaveAllNewAtoms(bookname); /* Zapis ksiazki na dysku */ else { TranslateAtoms(DimBase*offset); AscSaveAllAtoms(bookname); } for(i=offset+1,k=1 ; i<IleSegmentow-1 ; i++,k++) { if(prn==1) fprintf(stdout,"\t<<< ANALIZA %d REKORDU >>>\n",i+1); Reset(NULL); LOAD_SIGNAL(i-1,-L); LOAD_SIGNAL(i,-C); LOAD_SIGNAL(i+1,-R); REINIC(); AnalizaMP(NULL); file_offset=i; /* Ladowanie zmienia file_offset */ if(ascii==OFF) SaveAllNewAtoms(bookname); /* Zapis ksiazki na dysku */ else { TranslateAtoms(DimBase*i); AscSaveAllAtoms(bookname); } } if(prn==1) fprintf(stdout,"\t<<< ANALIZA OSTATNIEGO REKORDU >>>\n"); Reset(NULL); /* Domyslnie prawy warunek brzegowy jest 0 */ LOAD_SIGNAL(IleSegmentow-2,-L); LOAD_SIGNAL(IleSegmentow-1,-C); REINIC(); AnalizaMP(NULL); file_offset=i; if(ascii==OFF) SaveAllNewAtoms(bookname); /* Zapis ksiazki na dysku */ else { TranslateAtoms(DimBase*i); AscSaveAllAtoms(bookname); } setChannel=1; if(prn==1) fprintf(stdout,"<<< KONIEC ANALIZY KANALU EEG >>>\n"); }
void WigToGif(char *opt) /* Generacja mapy Wignera w postaci GIF'a */ { char *argv[STRING],filename[STRING]="wigner.gif",title[STRING]="", avrfilename[STRING],bmpfile[STRING]="wigner.bin"; int i,j,argc,x=DimBase,y=DimBase/2,opcja,paleta=COLOR,MaxYpoz, MaxXpoz,avropt=OFF,TmpDimRoz,IncludeSignal=OFF, BitMap=NOGENBITMAP,MakeDyspers=OFF,Laplas=0,reverse=0; float GammaCorect=1.0F,SplitFactor=1.0F,Crop=1.0F; PSBOOK *tmpbook; LogarytmStat=0; StrToArgv(opt,argv,&argc); opterr=optind=0; sp=1; while((opcja=Getopt(argc,argv,"O:X:Y:LF:cgxa:sS:bB:dk:l:Ri"))!=EOF) switch(opcja) { case 'R': reverse=1; break; case 'l': Laplas=atoi(optarg); break; case 'k': Crop=atof(optarg); break; case 'B': (void)strcpy(bmpfile,optarg); case 'b': BitMap=GENBITMAP; break; case 'S': SplitFactor=atof(optarg); break; case 's': IncludeSignal=ON; break; case 'a': (void)strcpy(avrfilename,optarg); avropt=ON; break; case 'x': (void)strcpy(title,Comment); break; case 'c': paleta=COLOR; break; case 'g': paleta=GRAY; break; case 'i': paleta=INVERT_GRAY; break; case 'O': (void)strcpy(filename,optarg); break; case 'F': GammaCorect=atof(optarg); break; case 'X': x=atoi(optarg); break; case 'Y': y=atoi(optarg); break; case 'L': LogarytmStat=1; break; case 'd': MakeDyspers=ON; break; default: fprintf(stderr,"Nieznana opcja !\n"); FreeArgv(argv,argc); return; } FreeArgv(argv,argc); if(avropt==OFF) if(Compute==OFF) { fprintf(stderr,"Nie wykonane obliczenia !\n"); return; } psbook=NULL; if(avropt==OFF) if((psbook=(PSBOOK *)malloc((unsigned)dimroz*sizeof(PSBOOK)))==NULL) { fprintf(stderr,"Brak pamieci (Wig2Gif) !\n"); return; } MaxXpoz=x+100; MaxYpoz=450+((y>256) ? y-256 : 0); if(BitMap==NOGENBITMAP) if(OpenVirtualScreen(MaxXpoz,MaxYpoz)==-1) { fprintf(stderr,"Brak pamieci w OpenVirtualScreen (Wig2Gif) !\n"); if(psbook!=NULL) free((void *)psbook); return; } if(avropt==OFF) for(i=0 ; i<dimroz; i++) /* Konwersja na format funkcji MakeWignerMap */ { psbook[i].s=book[i].param[0]; psbook[i].t=book[i].param[1]; psbook[i].w=book[i].waga; psbook[i].f=book[i].param[2]; } if((ImageTab=MakeTableUChar(x,y))==NULL) /* Obraz mapy Wignera */ { fprintf(stderr,"No memory (Wig2Gif) !\n"); CloseVirtualScreen(); if(psbook!=NULL) free((void *)psbook); return; } if(prn==1) fprintf(stdout,"\n<<< GENERATING TIME-FREQUENCY MAP >>>\n"); if(avropt==OFF) MakeWignerMap(psbook,dimroz,x,y,DimBase, ImageTab,GammaCorect,SplitFactor,bmpfile, BitMap,Crop); else { if((tmpbook=ReadAllAtoms(avrfilename,&TmpDimRoz))==NULL) { fprintf(stderr,"Error (Wig2Gif,ReadAllAtoms) !\n"); CloseVirtualScreen(); if(psbook!=NULL) free((void *)psbook); return; } if(MakeDyspers==OFF) MakeWignerMap(tmpbook,TmpDimRoz,x,y,DimBase,ImageTab, GammaCorect,SplitFactor,bmpfile,BitMap,Crop); else MakeDyspersWignerMap(tmpbook,TmpDimRoz,x,y,DimBase,ImageTab, GammaCorect,SplitFactor,bmpfile,BitMap,Crop); free((void *)tmpbook); } if(BitMap==NOGENBITMAP) { for(i=0 ; i<x ; i++) /* Rysowanie mapy Wignara na ekranie wirtualnym */ for(j=0 ; j<y ; j++) if(ImageTab[i][j]==0) PutPixel(POZX(i),POZY(j),1); else PutPixel(POZX(i),POZY(j),ImageTab[i][j]); if(avropt==OFF || IncludeSignal==ON) SignalToVirtualScreen(MaxYpoz,x,reverse); /* Rysowanie sygnalu */ MakeImageFrame(title,MaxXpoz,MaxYpoz,x,y, ((avropt==OFF || IncludeSignal==ON) ? OFF : ON), SplitFactor); /* Osnowa rysunku */ /* Generacja gif'a */ (void)ImageToGif(VirtualScreen,MaxXpoz,MaxYpoz,filename,paleta,Laplas); CloseVirtualScreen(); } if(psbook!=NULL) free((void *)psbook); FreeTableUChar(ImageTab,x); /* Zwolnienie pamieci jest bezpieczne */ if(prn==1) fprintf(stdout,"<<< KONIEC >>>\n"); }
void FloatRottCanalEEG(char *opt) /* Obliczenia kanalu EEG z dynamicznymi warunkami brzegowymi */ { static char Common[STRING],*argv[MAXARGS],filename[STRING], Para[STRING],bookname[STRING],tmpstr[STRING]; int argc,opcja,offset=0,ok=0,IleSegmentow,Nkan=1,i,ok2=0,maxseg=-1, k,j,itmp,itmp2,shift=0,ReinicRandomDic=OFF,ascii=OFF; Common[0]='\0'; (void)strcpy(bookname,"-a"); /* Domyslna nazwa ksiazki */ StrToArgv(opt,argv,&argc); opterr=optind=0; sp=1; while((opcja=Getopt(argc,argv,"O:#:c:h:I:M:s:Rt:"))!=EOF) switch(opcja) { /* Podstawowe opcje sa powtarzane */ case 'R': ReinicRandomDic=ON; break; case 'O': (void)strcpy(filename,optarg); if(CzyJestTakiPlik(filename)==-1) { FreeArgv(argv,argc); return; } sprintf(tmpstr,"-O%s ",optarg); (void)strcat(Common,tmpstr); ok=1; break; case 'c': sprintf(tmpstr,"-c%d ",(ChannelNumber=atoi(optarg)-1)+1); (void)strcat(Common,tmpstr); break; case 's': sprintf(tmpstr,"-s%s ",optarg); (void)strcat(Common,tmpstr); shift=atoi(optarg); break; case 'h': sprintf(tmpstr,"-h%d ",ChannelMaxNum=atoi(optarg)); (void)strcat(Common,tmpstr); Nkan=atoi(optarg); break; case '#': offset=atoi(optarg); break; case 'I': /* Zmiana nazwy ksiazki */ sprintf(bookname,"-A %s",optarg); break; case 'M': maxseg=atoi(optarg); /* Maksymalny numer segmentu */ break; case 't': if(strcmp(optarg,"ascii")==0) ascii=ON; else if(strcmp(optarg,"binary")==0) ascii=OFF; else fprintf(stderr,"Opcja -t %s zignorowana !\n",optarg); break; default: fputs("Niezana opcja !\n\r",stderr); FreeArgv(argv,argc); return; } FreeArgv(argv,argc); if(ok==0) { fputs("Nie podano nazwy pliku !\n\r",stderr); return; } setChannel=0; /* Okreslenie liczby segmentow (FLOAT) */ IleSegmentow=(int)(FileSizeChar(filename)/ ((long)Nkan*(long)sizeof(float)*(long)(DimBase+shift))); if(maxseg>0) IleSegmentow=MIN(IleSegmentow,maxseg); if(IleSegmentow<3) { fputs("Za malo segmentow do analizy (>3) !\n\r",stderr); return; } /* Utworzenie ksiazki z calego kanalu */ if(prn==1) fprintf(stdout,"\t\t<<< ANALIZA KANALU EEG (FLOATROTT) >>>\n" "\t\t (%d SEGMENTOW %d DO ANALIZY)\n", IleSegmentow,IleSegmentow-offset); if(prn==1) fprintf(stdout,"\n\t<<< ANALIZA 1 REKORDU >>>\n"); Reset(NULL); /* Domyslnie lewym warunkiem brzegowym beda 0 */ LOAD_FLOAT_SIGNAL(offset,-C); /* Lodowanie sygnalu */ LOAD_FLOAT_SIGNAL(offset+1,-R); /* Lodowanie prawego warunku brzegowego */ REINIC(); AnalizaMP(NULL); /* Analiza sygnalu */ file_offset=offset; /* Ustawiamy offset pliku (ladowanie przekreca) */ if(ascii==OFF) SaveAllNewAtoms(bookname); /* Zapis ksiazki na dysku */ else { TranslateAtoms(DimBase*offset); AscSaveAllAtoms(bookname); } for(i=offset+1,k=1 ; i<IleSegmentow-1 ; i++,k++) { if(prn==1) fprintf(stdout,"\t<<< ANALIZA %d REKORDU >>>\n",i+1); for(j=0 ; j<DimBase; j++) /* Przesuniecie ramki sygnalu po */ { /* kanale (dynamiczny warunek brzegowy) */ itmp=DimBase+j; sygnal[j]=sygnal[itmp]; sygnal[itmp]=sygnal[DimBase+itmp]; } LOAD_FLOAT_SIGNAL(i,-C); REINIC(); AnalizaMP(NULL); file_offset=i; /* Ladowanie zmienia file_offset */ if(ascii==OFF) SaveAllNewAtoms(bookname); else { TranslateAtoms(DimBase*i); AscSaveAllAtoms(bookname); } } if(prn==1) fprintf(stdout,"\t<<< ANALIZA OSTATNIEGO REKORDU >>>\n"); for(j=0 ; j<DimBase; j++) /* Przesuniecie z ustawienie prawego */ { /* warunku brzegowego */ itmp=DimBase+j; itmp2=itmp+DimBase; sygnal[j]=sygnal[itmp]; sygnal[itmp]=sygnal[itmp2]; sygnal[itmp2]=0.0F; /* Prawy warunek brzegowy jest rowny 0 */ } REINIC(); AnalizaMP(NULL); file_offset=IleSegmentow-1; if(ascii==OFF) SaveAllNewAtoms(bookname); else { TranslateAtoms(DimBase*(IleSegmentow-1)); AscSaveAllAtoms(bookname); } setChannel=1; if(prn==1) fprintf(stdout,"<<< KONIEC ANALIZY KANALU EEG (FLOATROTT) >>>\n"); }
int main(int argc, char *argv[] ) { int n, i, c, err, max_port = 0; char *portname, *s; struct servent *servent; struct info *in; prog = argv[0]; Opterr = 1; while( (n = Getopt(argc, argv, "dut")) != EOF ){ switch(n){ default: usage(); break; case 'u': use_udp = !use_udp; break; case 't': use_tcp = !use_tcp; break; case 'd': debug = 1; break; } } i = argc - Optind; if( i > 1 ) usage(); if( i == 1 ){ portname = argv[Optind]; n = atoi( portname ); if( n <= 0 ){ servent = getservbyname( portname, "udp" ); if( servent ){ n = ntohs( servent->s_port ); } } if( n <= 0 ){ FPRINTF( STDERR, "udp_open: bad port number '%s'\n",portname ); usage(); } port_num = n; } if( !use_tcp && !use_udp ) use_udp = 1; if( debug ){ FPRINTF(STDERR,"monitor: udp %d, tcp %d, port %d\n", use_udp, use_tcp, port_num ); } max_port = 0; FD_ZERO( &readfds ); if( use_udp && (udp_fd = udp_open( port_num )) >= 0){ if( debug ) FPRINTF(STDERR,"monitor: udp port %d\n", udp_fd ); FD_SET(udp_fd, &readfds); if( udp_fd >= max_port ) max_port = udp_fd+1; } if( use_tcp && (tcp_fd = tcp_open( port_num )) >= 0){ if( debug ) FPRINTF(STDERR,"monitor: tcp port %d\n", tcp_fd ); FD_SET(tcp_fd, &readfds); if( tcp_fd >= max_port ) max_port = tcp_fd+1; } if( debug ){ FPRINTF(STDERR,"monitor: max_port %d\n", max_port ); for( i = 0; i < max_port; ++i ){ if( FD_ISSET(i, &readfds) ){ FPRINTF(STDERR,"monitor: initial on %d\n", i ); } } } while(1){ FD_ZERO( &testfds ); for( i = 0; i < max_port; ++i ){ if( FD_ISSET(i, &readfds) ){ if( debug ) FPRINTF(STDERR,"monitor: waiting on %d\n", i ); FD_SET(i, &testfds); } } if( debug ) FPRINTF(STDERR,"monitor: starting wait, max %d\n", i ); n = select( i, FD_SET_FIX((fd_set *))&testfds, FD_SET_FIX((fd_set *))0, FD_SET_FIX((fd_set *))0, (struct timeval *)0 ); err = errno; if( debug ) FPRINTF(STDERR,"monitor: select returned %d\n", n ); if( n < 0 ){ FPRINTF( STDERR, "select error - %s\n", Errormsg(errno) ); if( err != EINTR ) break; } if( n > 0 ) for( i = 0; i < max_port; ++i ){ if( FD_ISSET(i, &testfds) ){ if( debug ) FPRINTF(STDERR,"monitor: input on %d\n", i ); if( i == tcp_fd ){ #if defined(HAVE_SOCKLEN_T) socklen_t len; #else int len; #endif struct sockaddr_in sinaddr; len = sizeof( sinaddr ); i = accept( tcp_fd, (struct sockaddr *)&sinaddr, &len ); if( i < 0 ){ FPRINTF( STDERR, "accept error - %s\n", Errormsg(errno) ); continue; } FPRINTF( STDOUT, "connection from %s\n", inet_ntoa( sinaddr.sin_addr ) ); if( i >= max_port ) max_port = i+1; FD_SET(i, &readfds); } else { c = read( i, buffer, sizeof(buffer)-1 ); if( c == 0 ){ /* closed connection */ FPRINTF(STDOUT, "closed connection %d\n", i ); close( i ); FD_CLR(i, &readfds ); Clear_buffer(i); } else if( c > 0 ){ buffer[c] = 0; if(debug)FPRINTF( STDOUT, "recv port %d: %s\n", i, buffer ); Add_buffer(i); in = Save_outbuf_len( i, buffer, c ); while( (s = safestrchr(in->buffer,'\n')) ){ *s++ = 0; Decode(in->buffer); memmove(in->buffer,s, safestrlen(s)+1 ); in->len = safestrlen(in->buffer); } } else { FPRINTF( STDERR, "read error - %s\n", Errormsg(errno) ); close( i ); FD_CLR(i, &readfds ); } } } } } return(0); }