Beispiel #1
0
int callsyntaxchk(trace_t *tr, char *infn, char *outfn, char *tmpfntmpl) {
  FILE *infile;
  extern char *flushfntmpl;

  /* set some globals */
  INFO_HEADERS_FLAG = CANONICALIZE_OBJS_FLAG = 1;
  flushfntmpl = tmpfntmpl;

  infile = myfopen(tr, infn, "r", "callsyntaxchk(): input file");
  if (infile == NULL)
    return (-1);

  ofile = myfopen(tr, outfn, "w", "callsyntaxchk(): output file");
  if (ofile == NULL) {
    fclose(infile);
    return (-1);
  }

  yyin = infile;
  yyparse(); /* XXX need to set an output fh one of these days in irr_rpsl_check */

  fflush (ofile);
  fclose (ofile);
  fclose (infile);
  return 0;
}
int main(int ac, char *av[])
{ 
  int i, j, k=-1, c, err=0, oclose=0;
  char *ifile=NULL, rdtok[MAXLABLEN], rdfile[MAXLABLEN];
  FILE *fp, *ofp=stdout;
  TreePtr gtree=NULL, ttree=NULL;
  AlPtr align=NULL, zalign;
  SPConf peval=init_peval();
  extern char *optarg;
  extern int optind;
  
  while ((c = getopt(ac, av, "p:a:F:v?")) != -1)
    switch (c) {
    case 'v':
      peval->verbose = 1;
      break;
    case 'p':
      peval->params=optarg;
      break;
    case 'F':
      ofp=myfopen(optarg,"w");
      oclose=1;
      break;
    case '?':
    default:
      err++;
    }
  
  if (err || ac != optind+3) {
    fprintf(stderr, USAGE, av[0]);
    exit(1);
  }
  
  if (peval->params != NULL) config_peval(peval,&rdfile[0],&rdtok[0]);
  strcpy(peval->gfile,av[optind]);
  strcpy(peval->tfile,av[optind+1]);
  fp=myfopen(av[optind],"r");
  while (fgets(rdfile,MAXLABLEN,fp) != NULL) {
    i=0;
    while (ws(rdfile[i])) i++;
    if (rdfile[i]=='\n') continue;
    gtree=load_tree(&rdfile[0],&rdtok[0],&i,NULL,NULL,peval,1,gtree,0,'g');
  }
  fclose(fp);
  i=0;
  fp=myfopen(av[optind+1],"r");
  while (fgets(rdfile,MAXLABLEN,fp) != NULL) {
    i=0;
    while (ws(rdfile[i])) i++;
    if (rdfile[i]=='\n') continue;
    ttree=load_tree(&rdfile[0],&rdtok[0],&i,NULL,NULL,peval,0,ttree,0,'t');
  }
  fclose(fp);
  fp=myfopen(av[optind+2],"r");
  align=get_rawalign(fp,&rdfile[0],&rdtok[0]);
  fclose(fp);
  get_strings(gtree,ttree,align, &rdtok[0],0);
  show_align(ofp,align,peval);
  if (oclose) fclose(ofp);
}
Beispiel #3
0
int main(){
	FILE *fp1;
	FILE *fp2;
	fp1 = myfopen("test1.txt");
	fp2 = myfopen("test2.txt"); // WARN: file is never closed

	fprintf(fp1, "Testing...\n");
	fclose(fp1);
	fprintf(fp2, "Testing...\n");
	// fclose(fp2);
} // WARN: unclosed files: fp2
Beispiel #4
0
void put_picture(struct context *cnt, char *file, unsigned char *image, int ftype)
{
    FILE *picture;

    picture = myfopen(file, "w");
    if (!picture) {
        /* Report to syslog - suggest solution if the problem is access rights to target dir */
        if (errno ==  EACCES) {
            motion_log(LOG_ERR, 1,
                       "Can't write picture to file %s - check access rights to target directory", file);
            motion_log(LOG_ERR, 1, "Thread is going to finish due to this fatal error");
            cnt->finish = 1;
            cnt->restart = 0;
            return;
        } else {
            /* If target dir is temporarily unavailable we may survive */
            motion_log(LOG_ERR, 1, "Can't write picture to file %s", file);
            return;
        }
    }

    put_picture_fd(cnt, picture, image, cnt->conf.quality);
    fclose(picture);
    event(cnt, EVENT_FILECREATE, NULL, file, (void *)(unsigned long)ftype, NULL);
}
Beispiel #5
0
/**
 * file_open_append
 *      Append version of the file open function used in libavformat when opening
 *      an ordinary file. The original file open function truncates an existing
 *      file, but this version appends to it instead.
 *
 *  Returns 0 on success and AVERROR(ENOENT) on error.
 *
 */
static int file_open_append(URLContext *h, const char *filename, int flags)
{
    const char *colon;
    const char *mode;
    FILE *fh;
    size_t bufsize = 0;

    /* Skip past the protocol part of filename. */
    colon = strchr(filename, ':');

    if (colon)
        filename = colon + 1;


    if (flags & URL_RDWR) {
        mode = "ab+";
        bufsize = BUFSIZE_1MEG;
    } else if (flags & URL_WRONLY) {
        mode = "ab";
        bufsize = BUFSIZE_1MEG;
    } else {
        mode = "rb";
    }

    fh = myfopen(filename, mode, bufsize);
    if (fh == NULL)
        return AVERROR(ENOENT);

    h->priv_data = (void *)fh;
    return 0;
}
Beispiel #6
0
/* Open the source file for reading, closing any previously open file.
   If dir_list is not NULL, calls search_file() to search the file in dir_list */
Bool SrcFile_open( SrcFile *self, char *filename, UT_array *dir_list )
{
    char *filename_path;
	
	/* close last file */
	if (self->file != NULL)
	{
		myfclose(self->file);
		self->file = NULL;
	}

	/* search path, add to strpool */
	filename_path = search_file(filename, dir_list);

	/* check for recursive includes, return if found */
	if (!check_recursive_include(self, filename_path))
		return FALSE;
	
	self->filename = filename_path;

    /* open new file in binary mode, for cross-platform newline processing */
    self->file = myfopen( self->filename, "rb" );

	/* init current line */
    str_clear( self->line );
    self->line_nr = 0;

	if (self->file)
		return TRUE;
	else
		return FALSE;		/* error opening file */
}
Beispiel #7
0
void process(FILE *f,long namepos,unsigned long datapos)
{
    byte name[1040];
    byte namelen;
    static int count=0;
    FILE *out;
    int i;
    unsigned long len;
    if(namepos==-1)
        sprintf(name,"%s%d.data",thename,count++);
    else
    {
        myseek(f,namepos);
        namelen=getbyte(f);
        if((int)fread(name,1,namelen,f)!=(int)namelen) err("Error reading resource name\n");
        name[namelen]=0;
        for(i=0;i<namelen;i++)
        {
            if(name[i]>126 || name[i]<32 ||
                name[i]=='\\' || name[i]=='?' || name[i]==':'
                || name[i]=='/' || name[i]=='%' || name[i]=='<'
                || name[i]=='>' || name[i]=='*' || name[i]=='"')
                name[i]='_';
        }
        strcat(name,".data");
    }
    out=myfopen(name,"wb");
    printf("Extracting: %s\n",name);
    myseek(f,datapos);
    len=getdword(f);
    while(len--)
        fputc(myfgetc(f),out);
    fclose(out);
}
void fprint_pdb_nopar(FILE * fop, struct atomgrp *ag, const char *inf)
{
    FILE *fp = myfopen(inf, "r");

    char *line = NULL;
    size_t len = 0;
    char c;

    // read every line of the pdb file
    int atomi = 0;
    while (getline(&line, &len, fp) != -1) {
        if (strncmp(line, "ATOM  ", 6) != 0
                && strncmp(line, "HETATM", 6) != 0) {
            fprintf(fop, "%s", line);
            continue;
        }
        c = line[54];
        sprintf(line + 30, "%8.3f", ag->atoms[atomi].X);
        sprintf(line + 38, "%8.3f", ag->atoms[atomi].Y);
        sprintf(line + 46, "%8.3f", ag->atoms[atomi].Z);
        atomi++;
        line[54] = c;
        fprintf(fop, "%s", line);
    }
    if (line)
        free(line);
    myfclose(fp);
}
Beispiel #9
0
IDatInt *load_PIDs_Sorted()
{
#ifdef HBTPID_RANKSTYLE
  char buf[1024];
  FILE *fd;
  IDatInt *PIDs,np,np2;  
  sprintf(buf,"%s/DM_PIDs_Sorted.dat",SUBCAT_DIR);
  if(!try_readfile(buf))//create the file if it does not exist
  {
	 load_particle_data(0,SNAPSHOT_DIR);
	 free_particle_data();
  }
  myfopen(fd,buf,"r");
  fread(&np,sizeof(IDatInt),1,fd);
  if(np!=NP_DM){fprintf(logfile,"error, file corruption: %s\n",buf);exit(1);}
  
  PIDs=mymalloc(sizeof(IDatInt)*NP_DM);
  fread(PIDs,sizeof(IDatInt),NP_DM,fd);
  
  fread(&np2,sizeof(IDatInt),1,fd);
  if(np2!=NP_DM){fprintf(logfile,"error, file corruption: %s\n",buf);exit(1);}
  fclose(fd);

  return PIDs;
#else
  return NULL;
#endif
}
Beispiel #10
0
int check_grpcat_byteorder(char *filename)
{
	/* to check whether byteswap is needed, return 1 if yes, 0 if no, exit if error*/
	int Nfiles,n,ns;
	long offset;
	FILE *fp;

	n=NFILES_GRP;
	ns=n;
	swap_Nbyte(&ns,1,sizeof(ns));
	
	myfopen(fp,filename,"r");
	#ifdef GRP_V3FORMAT
	offset=5*4;  //3*int+1*longlong
	#else
	offset=3*4;  //3*int
	#endif
	fseek(fp,offset,SEEK_SET);
	fread(&Nfiles,sizeof(int),1,fp);
	fclose(fp);
	
	if(Nfiles==n) return 0;
	if(Nfiles==ns) return 1;

	fprintf(logfile,"endianness check failed for: %s , file format not expected:%d;%d,%d\n", filename,(int)Nfiles,n,ns);
	fflush(logfile);
	exit(1);
}
Beispiel #11
0
BOOL
writerefsfound(void)
{
	if (refsfound == NULL) {
		if ((refsfound = myfopen(temp1, "wb")) == NULL) {
			cannotopen(temp1);
			return(NO);
		}
	} else {
		(void) fclose(refsfound);
		if ( (refsfound = myfopen(temp1, "wb")) == NULL) {
			postmsg("Cannot reopen temporary file");
			return(NO);
		}
	}
	return(YES);
}
void fprint_pdb(struct atomgrp *ag, struct prm *prm, const char *path)
{
    FILE *fp = myfopen(path, "w");

    //struct atomgrp** ags = (struct atomgrp**) _mol_malloc (2 * sizeof (struct atomgrp*));
    struct atomgrp **ags = extract_nitrogen_residues(ag, prm);
    //ags[0] = copy_atomgrp (ag);
    //ags[1] = NULL; // flag the end with NULL

    int sum_atomi = 0;
    int agi = 0;
    while (ags[agi] != NULL) {
        int atomi;
        for (atomi = 0; atomi < ags[agi]->natoms; atomi++, sum_atomi++) {
            char atomname[5];
            fprintf(fp, "%-6s", "ATOM");	// atom number
            fprintf(fp, "%5d", sum_atomi + 1);	// atom number
            //fprintf (fp, "  "); // 2 spaces
            fprintf(fp, " ");	// 1 space

            if (strlen
                    (prm->atoms[ags[agi]->atoms[atomi].atom_typen].
                     typemin) == 4) {
                strcpy(atomname,
                       prm->atoms[ags[agi]->atoms[atomi].
                                  atom_typen].typemin);
            } else {
                atomname[0] = ' ';
                strcpy(atomname + 1,
                       prm->atoms[ags[agi]->atoms[atomi].
                                  atom_typen].typemin);
            }
            fprintf(fp, "%-4.4s", atomname);	// atom typemin
            fprintf(fp, " ");	// Alternate location indicator
            fprintf(fp, "%-3s", prm->atoms[ags[agi]->atoms[atomi].atom_typen].typemaj);	// atom typemaj

            fprintf(fp, " ");	// 1 space
            fprintf(fp, "%1s", "A");	// chain id
            fprintf(fp, "%4d", agi + 1);	// residue number

            fprintf(fp, " ");	// code for insertion of residues
            fprintf(fp, "   ");	// 3 spaces

            fprintf(fp, "%8.3f", ags[agi]->atoms[atomi].X);	// X coordinate
            fprintf(fp, "%8.3f", ags[agi]->atoms[atomi].Y);	// Y coordinate
            fprintf(fp, "%8.3f", ags[agi]->atoms[atomi].Z);	// Z coordinate
            fprintf(fp, "  1.00  1.00      AAAA");	// segid
            fprintf(fp, "\n");	// new line
        }
        agi++;
    }
    fprintf(fp, "END\n");	//END

    //free (ags);
    free_atomgrps(ags);

    myfclose(fp);
}
Beispiel #13
0
static int io_open (lua_State *L) {
  const char *filename = luaL_checkstring(L, 1);
  const char *mode = luaL_optstring(L, 2, "r");
  LStream *p = newfile(L);
  const char *md = mode;  /* to traverse/check mode */
  luaL_argcheck(L, l_checkmode(md), 2, "invalid mode");
  p->f = myfopen(filename, mode);
  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
}
void fprint_ms_nopar (struct atomgrp* ag, const char* inf, const char* ouf)
{
	FILE* fp = myfopen (inf, "r");
	FILE* fop = myfopen (ouf, "w");

	char* line = NULL;
	size_t len = 0;
	
	
	// read every line of the pdb file
	int atomi = 0;
	while (getline (&line, &len, fp) != -1)
	{
		float attl;
		if (strncmp (line, "ATOM  ", 6) != 0 && strncmp (line, "HETATM", 6) != 0)
		{
			fprintf (fop,"%s",line);
			continue;
		}
		sprintf(line+30,"%8.3f",ag->atoms[atomi].X );
		sprintf(line+38,"%8.3f",ag->atoms[atomi].Y );
		sprintf(line+46,"%8.3f",ag->atoms[atomi].Z );
		attl=0.0;
		if (ag->atoms[atomi].attl > 0.0)
		{
			attl += ag->atoms[atomi].attl;
		}
		if (ag->atoms[atomi].sa > 0)
		{
			attl += (float) ag->atoms[atomi].sa;
		}
		if (attl > 9.0)
		{
			fprintf (stderr, "warning: attraction level is > 9.0 for an atom\n");
		}
		sprintf(line+54,"%6.1f   \n",attl );
		atomi++;
		fprintf (fop,"%s",line);
	}
	if (line)
	        free (line);
	myfclose (fp);
	myfclose (fop);
}
Beispiel #15
0
	bool Open(const char *filename, long startpos = 0, long len = -1)
	{
		File = myfopen(filename, "rb");
		if (File == nullptr) return false;
		FilePos = startpos;
		StartPos = startpos;
		Length = CalcFileLen();
		if (len >= 0 && len < Length) Length = len;
		if (startpos > 0) Seek(0, SEEK_SET);
		return true;
	}
Beispiel #16
0
/**
 * set_logfile
 *      Sets logfile to be used instead of syslog.
 *
 * Returns: pointer to log file.
 */
FILE * set_logfile(const char *logfile_name)
{
    log_mode = LOGMODE_SYSLOG;  /* Setup temporary to let log if myfopen fails */
    logfile = myfopen(logfile_name, "a");

    /* If logfile was opened correctly */
    if (logfile)
        log_mode = LOGMODE_FILE;

    return logfile;
}
Beispiel #17
0
struct rotset* read_rotset (const char* path)
{
	FILE* fp = myfopen (path, "r"); // open parms file

	char* line = NULL;
	size_t len = 0;

	int nrots = 0; // number of sets of rots
	while (getline (&line, &len, fp) != -1)
	{
		if (! iswhiteline (line))
		{
			nrots++;
		}
	}
	rewind (fp); // reset the file pointer

	struct rotset* rotset = (struct rotset*) _mol_malloc (sizeof (struct rotset));
	rotset->nrots = nrots; // save the value
	rotset->rmats = (struct rmatrix*) _mol_malloc (rotset->nrots * sizeof (struct rmatrix));

	int i = 0;
	while (getline (&line, &len, fp) != -1)
	{
		int tmpi; // tmp roti
		if (iswhiteline (line))
		{
			continue;
		}
		if (sscanf (line,	"%d %f %f %f %f %f %f %f %f %f",
							&tmpi,
							&rotset->rmats[i].a11, &rotset->rmats[i].a12, &rotset->rmats[i].a13,
							&rotset->rmats[i].a21, &rotset->rmats[i].a22, &rotset->rmats[i].a23,
							&rotset->rmats[i].a31, &rotset->rmats[i].a32, &rotset->rmats[i].a33
							) < 10)
		{
			fprintf (stderr, "read error on file %s\n", path);
			fprintf (stderr, "expecting one index and 9 floats per line %d\n", i);
			exit (EXIT_FAILURE);
		}
		if (tmpi != i)
		{
			fprintf (stderr, "read error on file %s\n", path);
			fprintf (stderr, "expecting index %d, found index %d\n", i, tmpi);
			exit (EXIT_FAILURE);
		}
		i++;
	}
	if (line)
		free (line);
	myfclose (fp);

	return rotset;
}
Beispiel #18
0
struct axisset* read_axisset (const char* path)
{
	FILE* fp = myfopen (path, "r"); // open parms file

	char* line = NULL;
	size_t len = 0;

	int naxes = 0; // number of sets of rots
	while (getline (&line, &len, fp) != -1)
	{
		if (! iswhiteline (line))
		{
			naxes++;
		}
	}
	rewind (fp); // reset the file pointer

	struct axisset* axisset = (struct axisset*) _mol_malloc (sizeof (struct axisset));
	axisset->naxes = naxes; // save the value
	axisset->axes = (struct axis*) _mol_malloc (axisset->naxes * sizeof (struct axis));

	int i = 0;
	while (getline (&line, &len, fp) != -1)
	{
		int tmpi; // tmp roti
		if (iswhiteline (line))
		{
			continue;
		}
		if (sscanf (line,	"%d %f %f %f",
							&tmpi,
							&axisset->axes[i].a,
							&axisset->axes[i].b,
							&axisset->axes[i].c
							) < 4)
		{
			fprintf (stderr, "read error on file %s\n", path);
			fprintf (stderr, "expecting one index and 3 floats per line %d\n", i);
			exit (EXIT_FAILURE);
		}
		if (tmpi != i)
		{
			fprintf (stderr, "read error on file %s\n", path);
			fprintf (stderr, "expecting index %d, found index %d\n", i, tmpi);
			exit (EXIT_FAILURE);
		}
		i++;
	}
	if (line)
		free (line);
	myfclose (fp);

	return axisset;
}
Beispiel #19
0
void getStartingTree(tree *tr)
{
  FILE *treeFile = myfopen(tree_file, "rb");

  tr->likelihood = unlikely;
   
  treeReadLen(treeFile, tr, FALSE, FALSE, FALSE);
               
  fclose(treeFile);
 
  tr->start = tr->nodep[1];
}
Beispiel #20
0
/*-----------------------------------------------------------------------------
*	Open file to receive all errors / warnings from now on
*	File is appended, to allow assemble	and link errors to be joined in the same file.
*----------------------------------------------------------------------------*/
void open_error_file( char *src_filename )
{
	char *filename = get_err_filename( src_filename );

    init_module();

    /* close current file if any */
    close_error_file();

    error_file.filename = strpool_add( filename );
	error_file.file = myfopen(error_file.filename, "a");
}
Beispiel #21
0
/* Main function for reading the prmtop file 
 * the amber_prmtop *P should be -already- allocated and initialized 
 * BUT, it should be otherwise empty  */
void read_amber_prmtop_asis(fileset F,amber_prmtop *P){
int aa=0,anl=0,sec=0,ent=0,fld=0; // generic, line, section, entry & field counters
int newflag=0,newline=0; // utility flags
char line[501],over[501],tmp[81],*s1,*s2,*fgets_check; 
fpos_t line_current;


// Open files and initialize some variables
//F.F=myfreopen(F.N,"r",F.F); // don't depend on calling function to have opened
F.F=myfopen(F.N,"r"); // 
P[0].FN=strdup(F.N); // the name of the file from which these data were taken
P[0].nS=0; // the prmtop structure should be empty
P[0].S=(amber_prmtop_section*)calloc(1,sizeof(amber_prmtop_section));
P[0].SN=(char**)calloc(1,sizeof(char*));

//
// Get the first line, which should be the "VERSION"
//
if(fgets(line,500,F.F)==NULL){read_fneek("Problem in read_amber_prmtop",1,0,F.N);}
// See if the first 500 chars includes a newline...
if(strchr(line,'\n')==NULL){ // if we didn't get the whole line
	fld=500;
	fprintf(stderr,"Unusually long VERSION line.\n");
       	fprintf(stderr,"-- Ignoring characters beyond 500.\n");
	if(fgets(over,500,F.F)==NULL){// try to get rest of line
		read_fneek("Problem reading VERSION line in read_amber_prmtop.",1,fld,F.N);}
	while(strchr(over,'\n')==NULL){// try to get rest of line
		fld+=500;
		if(fgets(over,500,F.F)==NULL){
			read_fneek("Problem readin VERSION line in read_amber_prmtop.",1,fld,F.N);}
		}
	} // close lengthy line check...
if(strncmp("\%VERSION",line,8)!=0){
	read_eek("First line not \%VERSION.",F.N);}
P[0].VERSION=strdup(line); 
anl=2;
fld=0;
//
// grab next line, which should be a flag line
//
if(fgets(line,500,F.F)==NULL){ 
	read_fneek("Problem in read_amber_prmtop",anl,fld,F.N);} 
// Check the line -- it should be a short-ish FLAG line

//printf("FLAG line read from top is >>>%s<<<\n",line);

if(strchr(line,'\n')==NULL){// die if line too long
read_eek("FLAG line over 500 chars... \n",F.N);}
//
// Read the FLAG entry
//
if(strncmp("\%FLAG",line,5)!=0){ // must start with %FLAG
read_fneek("Entry not FLAG in read_amber_prmtop",anl,fld,F.N);}
Beispiel #22
0
Datei: util.c Projekt: aosm/X11
FILEPTR FOpenAndCheck(char *name, char *mode)
{
    FILEPTR result;
    result = myfopen(name, mode);
    if (result == NULL) {
	char str[500];
	perror(progName);
	(void)sprintf(str, "Error in FOpenAndCheck(%s, %s)", name, mode);
	Punt(str);
    }
    return result;
}
Beispiel #23
0
static void printStateFile(int iter, state * curstate)
{ 
  FILE *f = myfopen("sampled_states.txt", "ab");
  fprintf(f,"%d\t%f",iter, curstate->tr->likelihood);
  int i;
  for(i = 0;i < curstate->numSubsRates; i++)
  {
    fprintf(f,"\t%f",curstate->curSubsRates[i]);
  }
  fprintf(f,"\t%f",curstate->curAlpha);
  fprintf(f,"\n");
  fclose(f);
}
Beispiel #24
0
int main(){

  printf("**Not fully tested, eg, max of 20 file open and such.\n");
  printf("**Buffering set small so replenishing of buffer is checked.\n");

  int c;

  myFILE *fp1;
  myFILE *fp2;
  char namein[MAXWORD];
  char nameout[MAXWORD];

  strcpy(namein, "8_1.c");
  strcpy(nameout, "testfile");

  myfflush(NULL);
  if ( ( fp1 = myfopen(namein, "r") ) == NULL ){
    fprintf(stderr, "Error: can't open file %s for reading\n", namein);
    exit(1);
  }
  else if ( ( fp2 = myfopen(nameout, "w") ) == NULL ){
    fprintf(stderr, "Error: can't open file %s for writing\n", nameout);
    exit(2);
  }

  while ( ( c = getc(fp1) ) != EOF )
    putc(c, fp2);
	     
  if ( myfclose(fp1) == EOF){
    fprintf(stderr, "Error: can't close file %s.\n", namein); 
    exit(3);
  }
  else if ( myfclose(fp1) == EOF){
    fprintf(stderr, "Error: can't close file %s.\n", nameout);
    exit(4);
  } 

  return 0;
}
Beispiel #25
0
void load_group_catalogue_HBT(HBTInt Nsnap,CATALOGUE *Cat,char *GrpPath)
{
  FILE *fd;
  HBTInt i,NFiles;
  char buf[1024];
  
#ifdef SNAPLIST
Nsnap=snaplist[Nsnap];
#endif

  sprintf(buf, "%s/group_tab_%03d",GrpPath,(int)Nsnap);
  myfopen(fd,buf,"r");

  fread(&Cat->Ngroups, sizeof(HBTInt), 1, fd);
  fread(&Cat->Nids, sizeof(HBTInt), 1, fd);
  fread(&Cat->Ngroups, sizeof(HBTInt), 1, fd);
  fread(&NFiles, sizeof(HBTInt), 1, fd); //useless, just to conform to GADGET's data format
  
  Cat->Len=mymalloc(sizeof(HBTInt)*Cat->Ngroups);
  Cat->Offset=mymalloc(sizeof(HBTInt)*Cat->Ngroups);
  fread(Cat->Len, sizeof(HBTInt), Cat->Ngroups, fd);
  fread(Cat->Offset,sizeof(HBTInt), Cat->Ngroups, fd);
  fclose(fd);

fprintf(logfile,"Snap="HBTIFMT" Ngroups="HBTIFMT" Nids="HBTIFMT"\n", Nsnap, Cat->Ngroups, Cat->Nids);
  sprintf(buf, "%s/group_ids_%03d", GrpPath, (int)Nsnap);
  myfopen(fd,buf,"r");

  fread(&Cat->Ngroups, sizeof(HBTInt), 1, fd);
  fread(&Cat->Nids, sizeof(HBTInt), 1, fd);
  fread(&Cat->Ngroups, sizeof(HBTInt), 1, fd);
  fread(&NFiles, sizeof(HBTInt), 1, fd);

  Cat->PID=mymalloc(sizeof(HBTInt)*Cat->Nids);
  fread(Cat->PID,sizeof(HBTInt),Cat->Nids,fd);
    
  fclose(fd);
}
Beispiel #26
0
static void printRecomTree(tree *tr, boolean printBranchLengths, char *title)
{
  FILE *nwfile;
  nwfile = myfopen("tmp.nw", "w+");
  pllTreeToNewickRecomREC(tr->tree_string, tr, tr->start->back, printBranchLengths);
  fprintf(nwfile,"%s\n", tr->tree_string);
  fclose(nwfile);
  if(title)
    printBothOpen("%s\n", title);
  if (printBranchLengths)
    printBothOpen("%s\n", tr->tree_string);
  printBothOpen("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
  system("bin/nw_display tmp.nw");
}  
Beispiel #27
0
/* _______________________________________________________________ */
int main(int argc, char* argv[]) {
    MY_FILE* fsrc;
    MY_FILE* fdst;
    if (argc != 3 && (argc != 4 || !streq(argv[1], "--append")))
        error("Utilisation: ./mycp [--append] SOURCE DEST");
    if (argc == 3) {
        if ((fsrc = myfopen(argv[1], "r")) == MY_NULL)
            error("Erreur d'ouverture du fichier source.");
        if ((fdst = myfopen(argv[2], "w")) == MY_NULL)
            error("Erreur d'ouverture du fichier destination.");
    } else {
        if ((fsrc = myfopen(argv[2], "r")) == MY_NULL)
            error("Erreur d'ouverture du fichier source.");
        if ((fdst = myfopen(argv[3], "a")) == MY_NULL)
            error("Erreur d'ouverture du fichier destination.");
    }
    copy(fsrc, fdst);
    if (myfclose(fsrc) != 0)
        error("Erreur de fermeture du fichier source.");
    if (myfclose(fdst) != 0)
        error("Erreur de fermeture du fichier destination.");
    return 0;
}
Beispiel #28
0
static void concatenateBSFiles(int processes, char fileName[1024])
{
  if(processID == 0)
    {
      int i;
      
      FILE 
	*destination = myfopen(fileName, "w"),
	*source = (FILE*)NULL;
      
      char 
	sourceName[1024];          
      
      strcpy(sourceName, fileName);
      strcat(sourceName, ".PID.");
      
      for(i = 0; i < processes; i++)
	{
	  char 
	    buf[64],
	    temporary[1024];
	  
	  sprintf(buf, "%d", i);
	  strcpy(temporary, sourceName);
	  strcat(temporary, buf);
	  
	  source = myfopen(temporary, "r");
	  
	  copyFiles(source, destination);
	  
	  fclose(source);
	}
      
      fclose(destination);
    }
}
Beispiel #29
0
static void printStateFileHeader(state * curstate)
{ 
  //DELETE THE FILE IF IT EXISTS, obviously this should be better later
  remove("sampled_states.txt");
  FILE *f = myfopen("sampled_states.txt", "ab");
  fprintf(f,"iter\tlikelihood");
  int i;
  for(i = 0;i < curstate->numSubsRates; i++)
  {
    fprintf(f,"\trate%d",i);
  }
  fprintf(f,"\talpha");
  fprintf(f,"\n");
  fclose(f);
}
Beispiel #30
0
void saveTrie(struct trie *root, char *fprefix){
  char fname[SEQ_LENGTH];
  FILE *indexFile;
  char window[WINDOW_SIZE];
  
  sprintf(fname, "%s.index", fprefix);
  
  indexFile = myfopen(fname, "w");

  //fprintf(indexFile, "WS %d\tSS %d %s %d\n", WINDOW_SIZE, SLIDE_SIZE, fprefix, genomelen);
  window[0] = 0;
  saveIndex(root, indexFile, window);

  fclose(indexFile);
  
}