Exemple #1
0
void add_control_point(char *name_cp)
{
FILE *cpf;
cpf = fileopen(NameCPFile,1);
if(cpf==NULL) cpf=fileopen(NameCPFile,0);
fprintf(cpf,"%s\n",name_cp);
fileclose(cpf);
}
Exemple #2
0
void creat_main()
{
	int		ct,BID_ct;
	int		ct_id;
	int		bid_cnt;
	int		total_cnt[2];
	int		edit_cc;
	struct	BN_LIST *BN_ptr;
	unsigned char WKpath[PATHSIZE+1];

	if ( (BATCH_infof =fileopen(BATCH_INFO,"w+")) == 0)	/* DL VT ctrw -> w+ */
	{
		disperr("COULD NOT creat %s",BATCH_INFO);
		pr_exit(-1);
	}
	setmidwin();
	clrscr();

	BN_ptr= BN_list; 
	for (ct =0; BN_cnt > ct; ct++)
	{
		BID_ct= BN_ptr->bnbid_cnt;
		charfill(Pathbuf,PATHSIZE+1,NULL);
		strcatl(Pathbuf,Path_bn,"/",BN_ptr->bnptr_bn,NULL);

		bid_cnt = 0;
		total_cnt[0] = total_cnt[1] = 0;	/* total rec ccount	*/

		for( ct_id=0;BID_ct >ct_id;ct_id++)
		{
			charfill(WKpath,PATHSIZE+1,NULL);
			strcatl(WKpath,Pathbuf,"/.",BN_ptr->bnptr_bid[ct_id],NULL); /* DL VT . added */
			if ((Infile= fileopen(WKpath,"r") ) == NULL)
			{
				disperr("COULD NOT open fci_file(%s)",WKpath);
				continue;
			}
			edit_cc = edit_data(Create_sel, total_cnt);
			if (edit_cc == 1)
			{
				curpos(0,14);
				display("FILE= %s",WKpath);
				rollup();
				edit_out();
				bid_cnt++;
			}
			fileclose(Infile);
		}
		BN_ptr++;
	}
	resetwin();
	fileclose(BATCH_infof);
}
Exemple #3
0
void CopyFile(const char* src, const char* dst) {
  printf("Copy from %s to %s\n", src, dst);
  FILE* fsrc = NULL;
  FILE* fdst = NULL;
  struct stat statbuf;
  int bytes_left;
  int bytes_read;
  int bytes_written;

  fsrc = fileopen(src, "r");
  if (!fsrc) {
    fprintf(stderr, "fopen(%s) failed: %d\n", src, errno);
    goto cleanup;
  }

  fdst = fileopen(dst, "w+");
  if (!fdst) {
    fprintf(stderr, "fopen(%s) failed: %d\n", dst, errno);
    goto cleanup;
  }

  if (fstat(fileno(fsrc), &statbuf) != 0) {
    fprintf(stderr, "fstat(%s) failed: %d\n", src, errno);
    goto cleanup;
  }

  bytes_left = statbuf.st_size;

  while (bytes_left > 0) {
    int bytes_to_read = std::min<size_t>(kCopyBufferSize, bytes_left);
    bytes_read = fread(&g_copy_buffer[0], 1, bytes_to_read, fsrc);
    if (bytes_read != bytes_to_read) {
      fprintf(stderr, "fread(%d) was short, %d.\n", bytes_to_read, bytes_read);
      goto cleanup;
    }

    bytes_written = fwrite(&g_copy_buffer[0], 1, bytes_to_read, fdst);
    if (bytes_written != bytes_to_read) {
      fprintf(stderr, "fwrite(%d) was short, %d.\n",
              bytes_to_read, bytes_written);
      goto cleanup;
    }

    bytes_left -= bytes_read;
  }

cleanup:
  if (fsrc) fclose(fsrc);
  if (fdst) fclose(fdst);
}
Exemple #4
0
int write_all_histograms (const char *fname)
{
   FILE *file;
   HISTOGRAM *histo;
   IO_BUFFER *iobuf = NULL;
   int rc;
   
   if ( (histo = get_first_histogram()) == NULL )
   {
      fprintf(stderr,"No histograms to write.\n");
      return -4;
   }

   if ( (file = fileopen(fname,"w")) == NULL )
   {
      perror(fname);
      return -1;
   }

   if ( (iobuf = allocate_io_buffer(8000000)) == NULL )
      return -1;
   iobuf->max_length = 800000000;
   iobuf->output_file = file;
   
   rc = write_histograms(NULL,-1,iobuf);
   
   free_io_buffer(iobuf);
   fileclose(file);
   
   return rc;
}
Exemple #5
0
void snapshot(double ***f1,double **nu,double t_cur,long count)
{
char str[256];
char message[10]="message";
long tag=count,v;
FILE *fd;

 sprintf(str,"%s_%d_%ld.snp",NameSnapFile,size,count);
 boundary_conditions(f1,nut);

 if(rank!=0) MPI_Recv(message,0,MPI_CHAR,rank-1,tag,MPI_COMM_WORLD,statuses);

 fd=fileopen(str,rank);
 Master nmessage("snap has been started",t_cur,count);
 Master fprintf(fd,"current time = %0.10f \ncurrent iteration = %ld\n",t_cur,count);
 Master fprintf(fd,"number of processors along axes={%d,%d}\n",pp[0],pp[2]);
 Master fprintf(fd,"Number of points along x = %d\n",N1);
 Master fprintf(fd,"Number of points along z = %d\n",N3);
 Master fprintf(fd,"Reynolds number = %lf\n",Re);

 for(v=0;v<nvar;v++)
    print_array2d(fd,f1[v],0,m1,0,m3);
 print_array2d(fd,nu,0,m1,0,m3);
 fileclose(fd);
                  
 if(rank!=size-1) MPI_Send(message,0,MPI_CHAR,rank+1,tag,MPI_COMM_WORLD);
 MPI_Barrier(MPI_COMM_WORLD);
 Master {nmessage("snap is done",t_cur,count);
                   add_control_point(str);}
}
Exemple #6
0
static bool load_wavetable(const char *fname)
{
int wav, sampl;
FILE *fp;
#define BUF_SIZE		(100 * 256)
signed char buffer[BUF_SIZE + 1];
signed char *ptr;

	fp = fileopen(fname, "rb");
	if (!fp)
	{
		stat("Unable to open wavetable.dat!!");
		return 1;
	}
	
	fread(buffer, BUF_SIZE, 1, fp);
	fclose(fp);
	
	ptr = &buffer[0];
	for(wav=0;wav<100;wav++)
	{
		for(sampl=0;sampl<256;sampl++)
		{
			// 256 = (32768 / 128)-- convert to 16-bit
			wavetable[wav].samples[sampl] = (signed short)((int)(*ptr++) << 8);
		}
	}
	
	return 0;
}
Exemple #7
0
void dump(double ****f1,double ***nu,double t_cur,long count)
{
FILE *fd;
char *message="dump";
int tag=1,v;

 boundary_conditions(f1);
 calculate_curl(&f1[4],B,NodeMagn);
 calculate_curl(B,J,NodeMagn);

 if(rank!=0) MPI_Recv(message,0,MPI_CHAR,rank-1,tag,MPI_COMM_WORLD,statuses);

 fd=fileopen(NameDumpFile,rank);

 Master nmessage("dump has been started",t_cur,count);
 Master fprintf(fd,"current time = %0.10f \ncurrent iteration = %ld\n",t_cur,count);
 Master fprintf(fd,"number of processors along axes={%d,%d,%d}\n",pp[0],pp[1],pp[2]);
 Master fprintf(fd,"Number of points along x = %d\n",N1);
 Master fprintf(fd,"Number of points along y = %d\n",N2);
 Master fprintf(fd,"Number of points along z = %d\n",N3);
 Master fprintf(fd,"Reynolds number = %lf\n",Re);

 for(v=0;v<nvar;v++)
    print_array3d(fd,f1[v],0,m1,0,m2,0,m3);
 print_array3d(fd,B[0],0,m1,0,m2,0,m3);
 print_array3d(fd,B[1],0,m1,0,m2,0,m3);
 print_array3d(fd,B[2],0,m1,0,m2,0,m3);
 print_array3d(fd,nu,0,m1,0,m2,0,m3);
 fclose(fd);

 if(rank!=size-1) MPI_Send(message,0,MPI_CHAR,rank+1,tag,MPI_COMM_WORLD);
             else {nmessage("dump is done",t_cur,count);
                   add_control_point(NameDumpFile);}
}
Exemple #8
0
int init_data(double *Re,double *t_cur,long *count)
                          //returns code of error
{
 int error=0;
 int i,j,k,l;
 float tmpd;
 char tmpc;
 int n1,n2,n3;

 FILE *inp = fileopen(NameInitFile,-1);
 read_tilleq(inp,'n');   if(fscanf(inp,"%lf",t_cur)==0) error=1;
 read_tilleq(inp,'n');   if(fscanf(inp,"%ld",count)==0) error=1;
 read_tilleq(inp,'n');   if(fscanf(inp,"%d",&n1)==0) error=1;
 read_tilleq(inp,'n');   if(fscanf(inp,"%d",&n2)==0) error=1;
 read_tilleq(inp,'n');   if(fscanf(inp,"%d",&n3)==0) error=1;
 read_tilleq(inp,'n');   if(fscanf(inp,"%lf",Re)==0) error=1;
 recreate_arrays(n1,n2,n3);
 for(l=0;l<nvar;l++)                    // reading f
        {
        do fscanf(inp,"%c",&tmpc); while (tmpc!='{');
        for(i=0;i<m1;i++)
           {
           do fscanf(inp,"%c",&tmpc); while (tmpc!='{');
           for(j=0;j<m2;j++)
               {
               do fscanf(inp,"%c",&tmpc); while (tmpc!='{');
               for(k=0;k<m3;k++)
                  {
                  if(fscanf(inp,"%g",&tmpd)==0) error=2;
                  fscanf(inp,"%c",&tmpc);
                  f[l][i][j][k]=tmpd;
                  }
               fscanf(inp,"%c",&tmpc);
               }
            fscanf(inp,"%c",&tmpc);
            }
        fscanf(inp,"%c",&tmpc);
        }
 do fscanf(inp,"%c",&tmpc); while (tmpc!='{');   //reading nut
 for(i=0;i<m1;i++)
     {
     do fscanf(inp,"%c",&tmpc); while (tmpc!='{');
     for(j=0;j<m2;j++)
         {
         do fscanf(inp,"%c",&tmpc); while (tmpc!='{');
         for(k=0;k<m3;k++)
             {
             if(fscanf(inp,"%g",&tmpd)==0) error=3;
             fscanf(inp,"%c",&tmpc);
             nut[i][j][k]=tmpd;
             }
         fscanf(inp,"%c",&tmpc);
         }
     fscanf(inp,"%c",&tmpc);
     }
 fscanf(inp,"%c",&tmpc);
fclose(inp);
return(error);
}
Exemple #9
0
void CSettingDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	CString strFilter="MP3文件(*.mp3)|*.mp3";
	CFileDialog fileopen(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,strFilter);
	if(fileopen.DoModal()==IDOK)
		m_strMusicFileName=fileopen.GetPathName();
	UpdateData(FALSE);
}
Exemple #10
0
/*
 * Performs Solaris dependent mapping. Returns a zone ID if
 * found. Otherwise, NULL is returned.  Solaris libc looks up
 * "/etc/default/init" to get the default TZ value if TZ is not defined
 * as an environment variable.
 */
static char *
getPlatformTimeZoneID()
{
    char *tz = NULL;
    FILE *fp;

    /*
     * Try the TZ entry in /etc/default/init.
     */
    if ((fp = fileopen(SYS_INIT_FILE, "r")) != NULL) {
        char line[256];
        char quote = '\0';

        while (filegets(line, sizeof(line), fp) != NULL) {
            char *p = line;
            char *s;
            char c;

            /* quick check for comment lines */
            if (*p == '#') {
                continue;
            }
            if (strncmp(p, "TZ=", 3) == 0) {
                p += 3;
                SKIP_SPACE(p);
                c = *p;
                if (c == '"' || c == '\'') {
                    quote = c;
                    p++;
                }

                /*
                 * PSARC/2001/383: quoted string support
                 */
                for (s = p; (c = *s) != '\0' && c != '\n'; s++) {
                    /* No '\\' is supported here. */
                    if (c == quote) {
                        quote = '\0';
                        break;
                    }
                    if (c == ' ' && quote == '\0') {
                        break;
                    }
                }
                if (quote != '\0') {
                    jio_fprintf(stderr, "ZoneInfo: unterminated time zone name in /etc/TIMEZONE\n");
                }
                *s = '\0';
                tz = strdup(p);
                break;
            }
        }
        (void) fileclose(fp);
    }
    return tz;
}
Exemple #11
0
int init_data(void)                 //returns code of error
{
 int error=0;
 int i,j,k,l,tmpr;
 char fstr[256], pos;
 float tmpf;
 char tmpc;
 double Re1;		  // priority for parameter in snap-file

  FILE *inp;

 pos = strcspn(NameInitFile,"*");
 NameInitFile[pos]=0;
 sprintf(fstr,"%s%d%s",NameInitFile,rank+0*size,NameInitFile+pos+1);

 inp = fileopen(fstr,-1);
 read_tilleq(inp,'=','n');   if(fscanf(inp,"%lf",&t_cur)==0) error=1;
 read_tilleq(inp,'=','n');   if(fscanf(inp,"%ld",&count)==0) error=1;
 read_tilleq(inp,'=','n');   if(fscanf(inp,"%c%d%c%d%c%d%c",&tmpc,&pp[0],&tmpc,&pp[1],&tmpc,&pp[2],&tmpc)<7) error=1;
                         //no need unless process distribution is written
 if(pp[0]*pp[1]*pp[2]!=size) nrerror("Wrong number of processors in data file. Can't read data.",-1,-1);
 read_tilleq(inp,'=','n');   if(fscanf(inp,"%d",&N1)==0) error=1;
 read_tilleq(inp,'=','n');   if(fscanf(inp,"%d",&N2)==0) error=1;
 read_tilleq(inp,'=','n');   if(fscanf(inp,"%d",&N3)==0) error=1;
 read_tilleq(inp,'=','n');   if(fscanf(inp,"%lf",&Re1)==0) error=1;
// fgetc(inp);  fgetc(inp);
 read_tilleq(inp,0x0A,'n');

 init_parallel();
 operate_memory(1);                     // creating arrays

// for(tmpr=0;tmpr<=rank;tmpr++)           //reading until arrays of this process
// {
 for(l=0;l<nvar;l++)                    // reading f
        for(i=0;i<m1;i++)
        for(j=0;j<m2;j++)
        for(k=0;k<m3;k++)
       {
       if(fread(&tmpf,sizeof(float),1,inp)<1) error=2*(k+100*(j+100*i));
       f[l][i][j][k] = tmpf;
       }

for(i=0;i<m1;i++)
     for(j=0;j<m2;j++)
     for(k=0;k<m3;k++)
       {
       if(fread(&tmpf,sizeof(float),1,inp)<1) error=3*(k+100*(j+100*i));
       nut[i][j][k] = tmpf;
       }
// }
fileclose(inp);

if(error) nrerror("Data couldn't have been read from file!!!",-1,error);
     else Master nmessage("Data has been read from file",t_cur,count);
return(error);
}
Exemple #12
0
graph getgraph(void)
 {
  /*inputs a set of vertices from a file specified by the user.
    the vertices are put into a graph structure and returned
  */
  FILE *userfile;
  graph tempgraph;
  ptrtoedge tempedge,tempedge2;
  int tempint,tempint2,count;
  char filename[50];
  /*open the file*/
  printf("\nEnter the name of the file to analyze ");
  gets(filename);
  userfile = fileopen(filename,"r");
  tempgraph = malloc(sizeof(struct graph));
  if(tempgraph == NULL)
   FatalError("out of memory");
  /*input the number of vertices*/
  fscanf(userfile,"%d",&tempint);
  tempgraph->numvertices = tempint;
  /*initialize the array of vertices*/
  tempgraph->array = malloc(sizeof(ptrtoedge) * tempint);
  if(tempgraph->array == NULL)
   FatalError("out of memory");
  for(count = 0;count < tempint;count++)
   {
    tempgraph->array[count] = NULL;
  }
  /*input the vertices from the file*/
  while(fscanf(userfile," %d",&tempint) != EOF)
   {
    fscanf(userfile," %d",&tempint2);
    tempedge = malloc(sizeof(struct edge));
    if(tempedge == NULL)
     FatalError("\nout of memory");
    tempedge->next = NULL;
    tempedge->vertex = tempint2;
    tempedge2 = tempgraph->array[tempint];
    if(tempedge2 == NULL)
     {
      tempgraph->array[tempint] = tempedge;
     }
    else
     {
     while(tempedge2->next != NULL)
      {
       tempedge2 = tempedge2->next;
      }
     tempedge2->next = tempedge;
     }
   }

  fclose(userfile);
  return tempgraph;

 }
Exemple #13
0
EXPORT void
setpwent()
{
	if (pwdf == (FILE *)NULL) {
		pwdf = fileopen("/etc/passwd", "r");
		if (pwdf == (FILE *)NULL)
			return;
	}
	fileseek(pwdf, (off_t)0);
}
Exemple #14
0
void nmessage(char msg_text[],double t_cur,long count)
{
   FILE *msg;
   msg=fileopen(NameMessageFile,1);
   time_now = (t_cur<0)?time_begin:MPI_Wtime();
   fprintf(msg,"message of proc#%d at t=%-7.4lf Niter=%-6d time of work=%g sec:\n",rank,
                    t_cur,count,time_now-time_begin);
   fprintf(msg,"%s\n",msg_text);
   fileclose(msg);
}
Exemple #15
0
void nmessage(char msg_text[],double t_cur)
{
   FILE *msg;
   msg=fileopen("message.dat",1);
   time(&time_now);
   fprintf(msg,"message at t=%-7.4lf Niter=%-6d time of work=%ld:\n",
                    t_cur,count,time_now-time_begin);
   fprintf(msg,"%s\n",msg_text);
   fclose(msg);
}
void ScriptHandler::saveKidokuData()
{
    FILE* fp;
    pstring fnam = "kidoku.dat";
    if ((fp = fileopen(fnam, "wb", true)) == NULL) {
        fprintf(stderr, "can't write kidoku.dat\n");
        return;
    }

    fwrite(kidoku_buffer, 1, script_buffer_length / 8, fp);
    fclose(fp);
}
Exemple #17
0
void putlog(char msg_text[],long num)
{
   FILE *log;
   char name[20];
   sprintf(name,"mess%d.log",rank);
   log=fileopen(name,num);
   time_now = (num==0)?time_begin:MPI_Wtime();
   fprintf(log,"message at t=%-7.4lf Niter=%-6d time of work=%g sec\n",
                    t_cur,count,time_now-time_begin);
   fprintf(log,"%s %d\n",msg_text,num);
   fclose(log);
}
Exemple #18
0
void nrerror(char error_text[],double t_cur)
{
   FILE *err;
   nmessage(error_text,t_cur);
   err=fileopen("error.err",0);

	fprintf(err,"Run-time error at t=%-6.4lf:\n",t_cur);
	fprintf(err,"%s\n",error_text);
	fprintf(err,"...now exiting to system...\n");
        fclose(err);
	//exit(1);
}
void ScriptHandler::loadKidokuData()
{
    FILE* fp;
    pstring fnam = "kidoku.dat";
    setKidokuskip(true);
    kidoku_buffer = new char[script_buffer_length / 8 + 1];
    memset(kidoku_buffer, 0, script_buffer_length / 8 + 1);

    if ((fp = fileopen(fnam, "rb", true)) != NULL) {
        fread(kidoku_buffer, 1, script_buffer_length / 8, fp);
        fclose(fp);
    }
}
Exemple #20
0
File *
newfile(void)
{
	File *f;

	f = fileopen();
	inslist(&file, 0, f);
	f->tag = tag++;
	if(downloaded)
		outTs(Hnewname, f->tag);
	/* already sorted; file name is "" */
	return f;
}
Exemple #21
0
void writelog(const char *buf, bool append_cr)
{
FILE *fp;

	fp = fileopen(logfilename, "a+");
	if (fp)
	{
		fputs(buf, fp);
		if (append_cr) fputc('\n', fp);
		
		fclose(fp);
	}
}
Exemple #22
0
Fichier : dio.c Projet : rolk/ug
int Read_OpenDTFile (char *filename)
{

#ifdef __MGIO_USE_IN_UG__
  if (datapathes_set) stream = FileOpenUsingSearchPaths(filename,"r","datapaths");
  else stream = fileopen(filename,"r");
#else
  stream = fopen(filename,"r");
#endif

  if (stream==NULL) return (1);

  return (0);
}
Exemple #23
0
void nrerror(char error_text[],double t_cur,long count)
{
    FILE *err;
    nmessage(error_text,t_cur,count);
    err=fileopen(NameErrorFile,0);

    fprintf(err,"Run-time error of proc#%d at t=%-6.4lf:\n",rank,t_cur);
    fprintf(err,"%s\n",error_text);
    fprintf(err,"...now exiting to system...\n");
    fileclose(err);
    if(f) operate_memory(-1);
    add_control_point("END");
//    MPI_Finalize();
    exit(1);
}
Exemple #24
0
EXPORT struct passwd *
getpwent()
{
	char	*arr[7];

	if (pwdf == (FILE *)NULL) {
		pwdf = fileopen("/etc/passwd", "r");
		if (pwdf == (FILE *)NULL)
			return ((struct passwd *)0);
	}
	if (fgetline(pwdf, pwdbuf, sizeof (pwdbuf)) == EOF)
		return ((struct passwd *)0);
	breakline(pwdbuf, ':', arr, 7);
	return (mkpwd(arr));
}
Exemple #25
0
int main(int argc, const char* argv[] ) {
	char buf[10] = {'1','1','1','1','1','1','1','1','1','\0'};

	int fd = fileopen(argv[1], argv[2]);
	if(fd==-1) {
		perror("error:");
	} else {
		write(fd, buf, 6);
		perror("while write");
		
		read(fd, buf, 1);
		perror("while read");
		printf("%s\n" ,buf);
	}
	return 0;
}
Exemple #26
0
FILE * NS_DIM_PREFIX LGM_WriteOpenFile (const char* name)
{
  FILE *stream;

  /* open file */
  if (lgmdomainpathes_set)
    stream = FileOpenUsingSearchPaths(name,"w","lgmdomainpathes");
  else
    stream = fileopen(name,"w");
  if (stream==NULL)
  {
    UserWriteF("cannot open file %s\n",name);
    return(NULL);
  }

  return (stream);
}
Exemple #27
0
void dump(double ***f1,double **nu,double t_cur,long count)
{
char str[256],str1[256];
FILE *fd;
int v;
struct stat st = {0};

if (stat("dump", &st) == -1) {
	mkdir("dump", 0777);
}
 if(DumpKeep)  sprintf(str,"dump/%s_%d_%ld.dmp",NameSnapFile,rank,count);
	else {
		sprintf(str,"dump/%s%d.dmp",NameSnapFile,rank);
		sprintf(str1,"dump/%s%d.bak",NameSnapFile,rank);
		remove(str1);
		rename(str,str1);
		}
// if(rank!=0) MPI_Recv("dump",0,MPI_CHAR,rank-1,/*tag*/1,MPI_COMM_WORLD,statuses);

 fd=fileopen(str,rank);

//Master { // для вывода в один файл, иначе убрать!! 
// nmessage("dump has been started",t_cur,count);
 fprintf(fd,"current time = %0.10f \ncurrent iteration = %ld\n",t_cur,count);
 fprintf(fd,"number of processors along axes={%d,%d}\n",pp[0],pp[2]);
 fprintf(fd,"Number of points along x = %d\n",N1);
 fprintf(fd,"Number of points along z = %d\n",N3);
 fprintf(fd,"Reynolds number = %lf\n",Re);
//}

 for(v=0;v<nvar;v++)
    print_array2d(fd,f1[v],0,m1,0,m3);
 print_array2d(fd,nu,0,m1,0,m3);
 fileclose(fd);

// if(rank!=size-1) MPI_Send(message,0,MPI_CHAR,rank+1,tag,MPI_COMM_WORLD);
 MPI_Barrier(MPI_COMM_WORLD);
 Master 
    {   
	 nmessage("dump is done",t_cur,count);
	 if(DumpKeep)  sprintf(str,"dump/%s_*_%ld.dmp",NameSnapFile,count);
		else 	sprintf(str,"dump/%s*.dmp",NameSnapFile);
    add_control_point(str);
    }
}
Exemple #28
0
void printcountdata(FILE *fd, checkdef_t *cfg)
{
	int openerr, idx;
	FILE *logfd;
	regex_t *exprs;
	regmatch_t pmatch[1];
	int *counts;
	char l[8192];
	
	logfd = fileopen(cfg->filename, &openerr); 
	if (logfd == NULL) {
		fprintf(fd, "ERROR: Cannot open file %s: %s\n", cfg->filename, strerror(openerr));
		return;
	}

	counts = (int *)calloc(cfg->check.countcheck.patterncount, sizeof(int));
	exprs = (regex_t *)calloc(cfg->check.countcheck.patterncount, sizeof(regex_t));
	for (idx = 0; (idx < cfg->check.countcheck.patterncount); idx++) {
		int status;

		status = regcomp(&exprs[idx], cfg->check.countcheck.patterns[idx], REG_EXTENDED|REG_NOSUB);
		if (status != 0) { /* ... */ };
	}

	while (fgets(l, sizeof(l), logfd)) {
		for (idx = 0; (idx < cfg->check.countcheck.patterncount); idx++) {
			if (regexec(&exprs[idx], l, 1, pmatch, 0) == 0) counts[idx] += 1;
		}
	}

	fclose(logfd);

	for (idx = 0; (idx < cfg->check.countcheck.patterncount); idx++) {
		fprintf(fd, "%s: %d\n", 
			cfg->check.countcheck.patternnames[idx], counts[idx]);

		regfree(&exprs[idx]);
	}

	free(counts);
	free(exprs);
}
Exemple #29
0
void dump(double ****f1,double ***nu,double t_cur,long count)
{
char str[256],str1[256];
FILE *fd;
char message[10]="dump";
int tag=1,v;

if(DumpKeep)  sprintf(str,"%s_%d_%d.dmp",NameSnapFile,rank,count);
	else {
		sprintf(str,"%s%d.dmp",NameSnapFile,rank);
		sprintf(str1,"%s%d.bak",NameSnapFile,rank);
		remove(str1);
		rename(str,str1);
		}
// if(rank!=0) MPI_Recv(message,0,MPI_CHAR,rank-1,tag,MPI_COMM_WORLD,statuses);

 fd=fileopen(str,rank);

 Master nmessage("dump has been started",t_cur,count);
// Master {
  fprintf(fd,"current time = %0.10f \ncurrent iteration = %ld\n",t_cur,count);
  fprintf(fd,"number of processors along axes={%d,%d,%d}\n",pp[0],pp[1],pp[2]);
  fprintf(fd,"Number of points along x = %d\n",N1);
  fprintf(fd,"Number of points along y = %d\n",N2);
  fprintf(fd,"Number of points along z = %d\n",N3);
  fprintf(fd,"Reynolds number = %lf\n",Re);
 //}

 for(v=0;v<nvar;v++)
    printbin_array3d(fd,f1[v],0,m1,0,m2,0,m3);
 printbin_array3d(fd,nu,0,m1,0,m2,0,m3);
 fileclose(fd);

// if(rank!=size-1) MPI_Send(message,0,MPI_CHAR,rank+1,tag,MPI_COMM_WORLD);
 MPI_Barrier(MPI_COMM_WORLD);
 Master 
 {    nmessage("dump is done",t_cur,count);
	  if(DumpKeep)  sprintf(str,"%s_*_%d.dmp",NameSnapFile,count);
			else 	sprintf(str,"%s*.dmp",NameSnapFile);
	  add_control_point(str);
      }
}
Exemple #30
0
char *filesum(char *fn, char *dtype)
{
	static char *result = NULL;
	digestctx_t *ctx;
	FILE *fd;
	unsigned char buf[8192];
	int openerr, buflen;

        if ((ctx = digest_init(dtype)) == NULL) return "";

	fd = fileopen(fn, &openerr); 
	if (fd == NULL) return "";
	while ((buflen = fread(buf, 1, sizeof(buf), fd)) > 0) digest_data(ctx, buf, buflen);
	fclose(fd);

	if (result) xfree(result);
	result = strdup(digest_done(ctx));

	return result;
}