Пример #1
0
Файл: main.c Проект: ivartj/tpl
int main(int argc, char *argv[])
{
	parseargs(argc, argv);
	openfiles();
	filter();
	exit(EXIT_SUCCESS);
}
Пример #2
0
int main(int argc, char* argv[]) {

	long int i, *r;

	openfiles();

	fscanf(fin, "%ld", &N);
	strings = (char*) malloc(N * LENGTH);
	if (strings == NULL) {
		perror("malloc strings");
		exit(EXIT_FAILURE);
	}

	for (i = 0; i < N; i++)
		fscanf(fin, "%s", strings + (i * LENGTH));

	fflush(stdout);

	r = bucket_sort(strings, LENGTH, N);

	fflush(stdout);

	for (i = 0; i < N; i++)
		fprintf(fout, "%s\n", strings + (r[i] * LENGTH));

	free(r);
	free(strings);
	closefiles();

	return EXIT_SUCCESS;
}
Пример #3
0
int main(int argc, char **argv)
{
	opt_nopeep = FALSE;
	uctran_off = 0;
	optimize =1;
	exceptions=1;
//	printf("c64 starting...\r\n");
	while(--argc) {
    if( **++argv == '-')
      options(*argv);
		else {
			if (PreProcessFile(*argv) == -1)
				break;
			if( openfiles(*argv)) {
				lineno = 0;
				initsym();
	compiler.compile();
//				compile();
				summary();
				MBlk::ReleaseAll();
//				ReleaseGlobalMemory();
				closefiles();
			}
    }
    dfs.printf("Next on command line (%d).\n", argc);
  }
	//getchar();
	dfs.printf("Exiting\n");
	dfs.close();
 	exit(0);
	return (0);
}
Пример #4
0
loadmix(char *fnames[], int nscores, double *weights) {
	if(nscores<2 || nscores>NSCORES) error("Bad number of files\n");
	
	double xty[NSCORES+1];
	if(weights) {
		int j;
		for(j=0;j<=nscores;j++)
			xty[j]=weights[j];
	} else
		computemix(fnames, nscores, xty);
	lg("Mixing coeeficients\n");
	int f;
	for(f=0;f<=nscores;f++)
		lg("-lew %f ",xty[f]);
	lg("\n");
		
	FILE *fp[NSCORES];
	openfiles(fp,fnames,nscores);
	int i;
	for(i=0; i<NENTRIES; i++) {
		PROGRESS(i,NENTRIES);
		int r=(userent[i]>>USER_LMOVIEMASK)&7;
		float s[NSCORES];
		readfiles(fp,s,nscores);
		float stotal=0.;
		int j;
		for(j=0;j<nscores;j++)
			stotal+=xty[j]*(r-s[j]);
		stotal+=xty[nscores];
		err[i]=r-stotal;
	}
	closefiles(fp,nscores);
}
Пример #5
0
static int linopen(Aflinst *t)
{
	afprintv(t->rq->verbose, 4, "Locking database");
	if (getlock(t->rq->db) < 0)
		return -1;

	afprintv(t->rq->verbose, 4, "Opening database files");
	if (openfiles(t->rq->db, &(t->f)) < 0)
		return -1;

	afprintv(t->rq->verbose, 4, "Reading database information");
	if (afreadinfo(t->f.info, &(t->info)) < 0)
		return -1;

	afprintv(t->rq->verbose, 4, "Checking file sizes");
	if (getfsizes(t) < 0)
		return -1;

	if (!t->rq->nobuffer) {
		if (aflinbuf(t->f.upost, t->rq->memory) < 0)
			return -1;
	}

	return 0;
}
Пример #6
0
int main(int argc, char *argv[])
{
    struct parms parms;		/* command line parms */
    struct files files;		/* file descriptors, io, buffers */
    struct Signature S;
    struct GModule *module;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("imagery"));
    G_add_keyword(_("classification"));
    G_add_keyword(_("supervised"));
    G_add_keyword(_("MLC"));
    module->description =
	_("Generates statistics for i.maxlik from raster map.");

    parse(argc, argv, &parms);
    openfiles(&parms, &files);
    read_training_labels(&parms, &files);

    get_training_classes(&files, &S);
    compute_means(&files, &S);
    compute_covariances(&files, &S);
    check_signatures(&S);
    write_sigfile(&parms, &S);

    G_done_msg(" ");
    
    exit(EXIT_SUCCESS);
}
Пример #7
0
int main(int argc, char **argv)
{
	uctran_off = 0;
	optimize =1;
	exceptions=1;
//	printf("c64 starting...\r\n");
	while(--argc) {
        if( **++argv == '-')
            options(*argv);
		else {
			if (PreProcessFile(*argv) == -1)
				break;
			if( openfiles(*argv)) {
				lineno = 0;
				initsym();
				memset(gsyms,0,sizeof(gsyms));
				memset(&defsyms,0,sizeof(defsyms));
				memset(&tagtable,0,sizeof(tagtable));
				getch();
				lstackptr = 0;
				lastst = 0;
				NextToken();
				compile();
				summary();
				ReleaseGlobalMemory();
				closefiles();
			}
        }
    }
	//getchar();
	return 0;
}
Пример #8
0
int Compiler::main2(int argc, char **argv)
{
	uctran_off = 0;
	optimize =1;
	exceptions=1;
	dfs.printf("c64 starting...\r\n");
	while(--argc) {
        if( **++argv == '-')
            options(*argv);
		else {
			if (PreprocessFile(*argv) == -1)
				break;
			if( openfiles(*argv)) {
				lineno = 0;
				initsym();
				lstackptr = 0;
				lastst = 0;
				NextToken();
				compile();
				summary();
//				MBlk::ReleaseAll();
//				ReleaseGlobalMemory();
				CloseFiles();
			}
        }
    }
	//getchar();
	return 0;
}
Пример #9
0
int
main (int argc, char *argv[])
{
  program_name = argv[0];
#ifdef __LINUX__
  if (readlink ("/proc/self/exe", program_name_buf, 1024) != -1)
  {
    program_name=&program_name_buf;    
  }
#endif
  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);

  failure = 0;
  lineno = 0;


  getargs(argc, argv);
  openfiles();


  /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
     In file reader.c.
     The other parts are recorded in the grammar; see gram.h.  */
  reader();
  if (failure)
        done(failure);

  /* find useless nonterminals and productions and reduce the grammar.  In
     file reduce.c */
  reduce_grammar();

  /* record other info about the grammar.  In files derives and nullable.  */
  set_derives();
  set_nullable();

  /* convert to nondeterministic finite state machine.  In file LR0.
     See state.h for more info.  */
  generate_states();

  /* make it deterministic.  In file lalr.  */
  lalr();

  /* Find and record any conflicts: places where one token of lookahead is not
     enough to disambiguate the parsing.  In file conflicts.
     Also resolve s/r conflicts based on precedence declarations.  */
  initialize_conflicts();

  /* print information about results, if requested.  In file print. */
  if (verboseflag)
    verbose();
  else
    terse();

  /* output the tables and the parser to ftable.  In file output. */
  output();
  done(failure);
  return failure;
}
Пример #10
0
int main(int argc, char *argv[]) {
  assert(("Usage: ./3sat_seq [output path] [record_time file]") && argc == 3);
  openfiles(argv[1], argv[2]);
  
  int nClauses;
  int nVar;

  scanf("%d %d", &nClauses, &nVar);

  short **clauses = readClauses(nClauses, nVar);
  double st = omp_get_wtime();
  long solution = solveClauses(clauses, nClauses, nVar);
  double ed = omp_get_wtime();
  int i;
	
  if (solution >= 0) {
    printf("Solution found [%ld]: ", solution);
    fprintf(fout, "Solution found [%ld]: ", solution);
    for (i = 0; i < nVar; i++) {
      printf("%d ", (int) ((solution & (long) exp2(i)) / exp2(i)));
      fprintf(fout, "%d ", (int) ((solution & (long) exp2(i)) / exp2(i)));
    }
    printf("\n");
  } else {
    printf("Solution not found.\n");
    fprintf(fout, "Solution not found.\n");
  }
  printf("take %.4lfs\n", ed - st);
  fprintf(ftime, "%.4lf\n", ed - st);

  closefiles();
	
  return EXIT_SUCCESS;
}
Пример #11
0
/*
 * NAME:	cpo->raw()
 * DESCRIPTION:	copy the data fork of an HFS file to a UNIX file
 */
int cpo_raw(hfsvol *vol, const char *srcname, const char *dstname)
{
  hfsfile *ifile;
  int ofile, result = 0;

  if (openfiles(vol, srcname, dstname, 0, &ifile, &ofile) == -1)
    return -1;

  result = do_raw(ifile, ofile);

  closefiles(ifile, ofile, &result);

  return result;
}
Пример #12
0
/*
 * NAME:	cpo->text()
 * DESCRIPTION:	copy an HFS file to a UNIX file using text translation
 */
int cpo_text(hfsvol *vol, const char *srcname, const char *dstname)
{
  const char *ext = 0;
  hfsfile *ifile;
  int ofile, result = 0;

  if (strchr(srcname, '.') == 0)
    ext = ".txt";

  if (openfiles(vol, srcname, dstname, ext, &ifile, &ofile) == -1)
    return -1;

  result = do_text(ifile, ofile);

  closefiles(ifile, ofile, &result);

  return result;
}
Пример #13
0
int
main(int argc, char *argv[])
{
	int i;

	openfiles();

	if (argc > 1) {
		for (i=1; i<argc; i++) {
			readfile(argv[i]);
		}
	}
	else {
		readfile(NULL);
	}

	dumpdata();

	closefiles();
	return 0;
}
Пример #14
0
int main(int argc,char *argv[])
{
  failure = 0;
  lineno = 0;
  getargs(argc, argv);
  openfiles();

  /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
     In file reader.
     The other parts are recorded in the grammar; see gram.h.  */
  reader();

  /* record other info about the grammar.  In files derives and nullable.  */
  set_derives();
  set_nullable();

  /* convert to nondeterministic finite state machine.  In file LR0.
     See state.h for more info.  */
  generate_states();

  /* make it deterministic.  In file lalr.  */
  lalr();

  /* Find and record any conflicts: places where one token of lookahead is not
     enough to disambiguate the parsing.  In file conflicts.
     Currently this does not do anything to resolve them;
     the trivial form of conflict resolution that exists is done in output.  */
  initialize_conflicts();

  /* print information about results, if requested.  In file print. */
  if (verboseflag)
    verbose();
  else
    terse();

  /* output the tables and the parser to ftable.  In file output. */
  output();
  done(failure);
  return 0;
}
Пример #15
0
int main(int argc, char *argv[])
{
    struct parms parms;		/* command line parms */
    struct files files;		/* file descriptors, io, buffers */
    struct SigSet S;
    int i;
    int junk;
    struct GModule *module;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("imagery"));
    G_add_keyword(_("classification"));
    G_add_keyword(_("supervised classification"));
    G_add_keyword(_("SMAP"));
    G_add_keyword(_("signatures"));
    module->description =
	_("Generates statistics for i.smap from raster map.");

    parse(argc, argv, &parms);
    openfiles(&parms, &files);
    read_training_labels(&parms, &files);

    get_training_classes(&parms, &files, &S);
    read_data(&files, &S);

    for (i = 0; i < S.nclasses; i++) {
	G_message(_("Clustering class %d (%d pixels)..."),
		  i + 1, S.ClassSig[i].ClassData.npixels);
	subcluster(&S, i, &junk, parms.maxsubclasses);
	G_message(_("Number of subclasses is %d"),
		  S.ClassSig[i].nsubclasses);
    }
    write_sigfile(&parms, &S);

    G_done_msg(" ");

    exit(EXIT_SUCCESS);
}
Пример #16
0
int main(int argc, char *argv[]) {

	if (argc != 3) {
		printf("Insufficient number of input files!\nUsage: %s <database file> <query file>\n\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	struct timeval start_computation, end_computation;
	struct timeval start_total, end_total;
	unsigned long int time_computation = 0, time_total;

	gettimeofday(&start_total, NULL);

	openfiles(argv[1], argv[2]);

	char *base = (char*) malloc(sizeof(char) * 1000001);
	if (base == NULL) {
		perror("malloc");
		exit(EXIT_FAILURE);
	}
	char *str = (char*) malloc(sizeof(char) * 1000001);
	if (str == NULL) {
		perror("malloc str");
		exit(EXIT_FAILURE);
	}

	char desc_dna[100], desc_query[100];
	int found, result;



	while (get_next_query_descripton(desc_query)) {
		fprintf(fout, "%s\n", desc_query);

		get_next_query_string(str);

		// read database and search
		found = 0;
		fseek(fdatabase, 0, SEEK_SET);
		while (get_next_base_description(desc_dna)) {

			get_next_base_string(base);

   		gettimeofday(&start_computation, NULL);
			result = bmhs(base, strlen(base), str, strlen(str));
			gettimeofday(&end_computation, NULL);
			time_computation += (end_computation.tv_sec - start_computation.tv_sec) * 1000000 + end_computation.tv_usec - start_computation.tv_usec;

			if (result > 0) {
				fprintf(fout, "%s\n%d\n", desc_dna, result);
				found++;
			}
		}

		if (!found)
			fprintf(fout, "NOT FOUND\n");
	}

	closefiles();

	free(str);
	free(base);

	gettimeofday(&end_total, NULL);
	time_total = (end_total.tv_sec - start_total.tv_sec) * 1000000 + end_total.tv_usec - start_total.tv_usec;

	printf("Elapsed computing time: %ld microseconds.\nI/O time: %ld microseconds\n", time_computation, time_total - time_computation);

	return EXIT_SUCCESS;
}
int main(int argc, char *argv[]) {
  printf("Initializing ... \n");
  initialize();
  if (ictype==2) {
    fcfilename=argv[1];
    FILE *fcfid;
    if ((fcfid=fopen(fcfilename,"rb"))==NULL) {
      printf("Unable to open %s ... \n",fcfilename);
      exit(1);}
    readbrfc();  
  }
  if (stimnum>0) {
    printf("Building stimulus matrix ... \n");
    buildptstim();  
  }
  printf("Opening files ... \n");
  openfiles();
  step=0;
  printf("Writing initial conditions ... \n");
  output();
  printf("Entering time loop ... \n");
  double cpu_start=rtclock();

  while (derivarr[0]<=tfinal && step<=Nsteps + 1 && stable){
    step=step+1;
    derivarr[0]+=dt;        // update time (msec) 
	if (blocktimenum>0)                
    {
      int i,m,n;
	  for (i=0;i<blocktimenum;++i){
	    if ((derivarr[0]>=blocktimes[i][0])&&(blocktimes[i][1]==0.0)){
//	      printf("Changing block conditions: %4.3f msec \n",derivarr[0]);
	      blocktimes[i][1]=1.0;
	      for (m=1;m<Nx+1;++m){
	        for (n=1;n<Ny+1;++n){
	    	  if (block[m][n]==0) block[m][n]=1;
			}
      	  }
    	}
  	  }
    } // blockonoff

    if (step % 2 == 1) {
        brgates_currents_1();
    }
    else {
        brgates_currents_2();
    }

	{
	  int ii;
	  double R0, R1;
	  R0=(D[1][0]/D[0][0])*(dx/dy);
	  R1=(D[1][0]/D[1][1])*(dy/dx);
	  if (BC==1){   // Slab
	    /* First set Vm at ghost nodes */
	    datarr[step%2][0][0][1]=datarr[step%2][0][2][1];
	    datarr[step%2][0][0][0]=datarr[step%2][0][2][2];
	    datarr[step%2][0][1][0]=datarr[step%2][0][1][2];
	    datarr[step%2][0][Nx][0]=datarr[step%2][0][Nx][2];
	    datarr[step%2][0][Nx+1][0]=datarr[step%2][0][Nx-1][2];
	    datarr[step%2][0][Nx+1][1]=datarr[step%2][0][Nx-1][1];
	    datarr[step%2][0][Nx+1][Ny]=datarr[step%2][0][Nx-1][Ny];
	    datarr[step%2][0][Nx+1][Ny+1]=datarr[step%2][0][Nx-1][Ny-1];
	    datarr[step%2][0][Nx][Ny+1]=datarr[step%2][0][Nx][Ny-1];
	    datarr[step%2][0][1][Ny+1]=datarr[step%2][0][1][Ny-1];
	    datarr[step%2][0][0][Ny+1]=datarr[step%2][0][2][Ny-1];
	    datarr[step%2][0][0][Ny]=datarr[step%2][0][2][Ny];  
	    for (ii=2;ii<Nx;++ii){            /* decouple these loops b/c Nx might not equal Ny */
	      datarr[step%2][0][ii][Ny+1]=datarr[step%2][0][ii][Ny-1]+R1*(datarr[step%2][0][ii-1][Ny]-datarr[step%2][0][ii+1][Ny]);  /* Eq 3 in notes */
	      datarr[step%2][0][ii][0]=datarr[step%2][0][ii][2]-R1*(datarr[step%2][0][ii-1][1]-datarr[step%2][0][ii+1][1]);          /* Eq 2 in notes */
	    }
	    for (ii=2;ii<Ny;++ii){           /* decouple these loops b/c Nx might not equal Ny */
	      datarr[step%2][0][0][ii]=datarr[step%2][0][2][ii]-R0*(datarr[step%2][0][1][ii-1]-datarr[step%2][0][1][ii+1]);           /* Eq 1 in notes */
	      datarr[step%2][0][Nx+1][ii]=datarr[step%2][0][Nx-1][ii]+R0*(datarr[step%2][0][Nx][ii-1]-datarr[step%2][0][Nx][ii+1]);   /* Eq 4 in notes */
	    }
	  }
	}


{ 
  if (step % 2 == 1) {
    vmdiff_1();
  }
  else {
    vmdiff_2();
  }
}


    if (step%rpN==0) {          // update user
      printf("%4.4e msec, Vm(%d,%d): %3.2f mV\n",derivarr[0],mNx,mNy,datarr[step%2][0][mNx][mNy]); 
      fflush(stdout);
    } 
    if (step%wN==0) output();   // write data to files
  }  // end time loop
  double cpu_end = rtclock();
  printf("total time is %.2lf\n",(double)(cpu_end-cpu_start));
  if (stable){
    printf("\nSimulation Finished!\n");
  }
  else {
    printf("\nSimulation Aborted!\n");
  }
  printf("Saving final conditions...\n\n");
  brfc();
  printf("         tfinal: %5.3f msec\n",tfinal);
  printf("     Final time: %5.3f msec\n",derivarr[0]);
  printf("         Nsteps: %10.2f\n",Nsteps);
  printf("Number of steps: %d\n",step);
  printf("             Nx: %d\n",Nx);
  printf("             Ny: %d\n",Ny);
  closefiles();
}
Пример #18
0
int main(int argc, char **argv)
{
    long i;
    int band, rows, cols;
    CELL *rowbuffer[3];
    struct Option *opt_hue, *opt_red;
    struct Option *opt_inten, *opt_green;
    struct Option *opt_sat, *opt_blue;
    struct GModule *module;
    int fd_input[3];
    int fd_output[3];

    /* Initialize GIS engine */
    G_gisinit(argv[0]);

    /* Set description */
    module = G_define_module();
    module->keywords = _("imagery, color transformation, RGB, HIS");
    module->description =
	_("Transforms raster maps from RGB (Red-Green-Blue) color space to "
	  "HIS (Hue-Intensity-Saturation) color space.");

    /* Define the different options */
    opt_red = G_define_standard_option(G_OPT_R_INPUT);
    opt_red->key = "red_input";
    opt_red->description = _("Name of input raster map (red)");

    opt_green = G_define_standard_option(G_OPT_R_INPUT);
    opt_green->key = "green_input";
    opt_green->description = _("Name of input raster map (green)");

    opt_blue = G_define_standard_option(G_OPT_R_INPUT);
    opt_blue->key = "blue_input";
    opt_blue->description = _("Name of input raster map (blue)");

    opt_hue = G_define_standard_option(G_OPT_R_OUTPUT);
    opt_hue->key = "hue_output";
    opt_hue->description = _("Name for output raster map (hue)");

    opt_inten = G_define_standard_option(G_OPT_R_OUTPUT);
    opt_inten->key = "intensity_output";
    opt_inten->description = _("Name for output raster map (intensity)");

    opt_sat = G_define_standard_option(G_OPT_R_OUTPUT);
    opt_sat->key = "saturation_output";
    opt_sat->description = _("Name for output raster map (saturation)");

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);


    /* get dimension of the image */
    rows = G_window_rows();
    cols = G_window_cols();

    openfiles(opt_red->answer, opt_green->answer, opt_blue->answer,
	      opt_hue->answer, opt_inten->answer, opt_sat->answer,
	      fd_input, fd_output, rowbuffer);

    for (i = 0; i < rows; i++) {
	/* read in a row from each cell map */
	G_percent(i, rows, 2);

	for (band = 0; band < 3; band++)
	    if (G_get_map_row(fd_input[band], rowbuffer[band], i) < 0)
		G_fatal_error(_("Unable to read raster map row %ld"), i);

	/* process this row of the map */
	rgb2his(rowbuffer, cols);

	/* write out the new row for each cell map */
	for (band = 0; band < 3; band++)
	    if (G_put_raster_row(fd_output[band], rowbuffer[band], CELL_TYPE)
		< 0)
		G_fatal_error(_("Failed writing raster map row %ld"), i);
    }
    G_percent(i, rows, 2);

    closefiles(opt_hue->answer, opt_inten->answer, opt_sat->answer,
	       fd_output, rowbuffer);


    exit(EXIT_SUCCESS);
}
Пример #19
0
int main( int argc, char ** argv )
{

/* -------------------------------------------------------------------- */
/*      Check command line usage.                                       */
/* -------------------------------------------------------------------- */
    if( argc < 2 ) error();
    strcpy(infile, argv[1]);
    if (argc > 2) {
        strcpy(outfile,argv[2]);
        if (strncasecmp2(outfile, "LIST",0) == 0) { ilist = TRUE; }
        if (strncasecmp2(outfile, "ALL",0) == 0)  { iall  = TRUE; }
    } 
    if (ilist || iall || argc == 2 ) {
        setext(infile, "shp");
        printf("DESCRIBE: %s\n",infile);
        strcpy(outfile,"");
    }
/* -------------------------------------------------------------------- */
/*	Look for other functions on the command line. (SELECT, UNIT)  	*/
/* -------------------------------------------------------------------- */
    for (i = 3; i < argc; i++)
    {
    	if ((strncasecmp2(argv[i],  "SEL",3) == 0) ||
            (strncasecmp2(argv[i],  "UNSEL",5) == 0))
    	{
            if (strncasecmp2(argv[i],  "UNSEL",5) == 0) iunselect=TRUE;
    	    i++;
    	    if (i >= argc) error();
    	    strcpy(selectitem,argv[i]);
    	    i++;
    	    if (i >= argc) error();
    	    selcount=0;
    	    strcpy(temp,argv[i]);
    	    cpt=temp;
    	    tj = atoi(cpt);
    	    ti = 0;
    	    while (tj>0) {
                selectvalues[selcount] = tj;
                while( *cpt >= '0' && *cpt <= '9')
                    cpt++; 
                while( *cpt > '\0' && (*cpt < '0' || *cpt > '9') )
                    cpt++; 
                tj=atoi(cpt);
                selcount++;
    	    }
    	    iselect=TRUE;
    	}  /*** End SEL & UNSEL ***/
    	else
            if ((strncasecmp2(argv[i], "CLIP",4) == 0) ||
                (strncasecmp2(argv[i],  "ERASE",5) == 0))
            {
                if (strncasecmp2(argv[i],  "ERASE",5) == 0) ierase=TRUE;
                i++;
                if (i >= argc) error();
                strcpy(clipfile,argv[i]);
                sscanf(argv[i],"%lf",&cxmin);
                i++;
                if (i >= argc) error();
                if (strncasecmp2(argv[i],  "BOUND",5) == 0) {
                    setext(clipfile, "shp");
                    hSHP = SHPOpen( clipfile, "rb" );
                    if( hSHP == NULL )
                    {
                        printf( "ERROR: Unable to open the clip shape file:%s\n", clipfile );
                        exit( 1 );
                    }
                    SHPGetInfo( hSHPappend, NULL, NULL,
                                adfBoundsMin, adfBoundsMax );
                    cxmin = adfBoundsMin[0];
                    cymin = adfBoundsMin[1];
                    cxmax = adfBoundsMax[0];
                    cymax = adfBoundsMax[1];
                    printf("Theme Clip Boundary: (%lf,%lf) - (%lf,%lf)\n",
                           cxmin, cymin, cxmax, cymax);
                    ibound=TRUE;
                } else {  /*** xmin,ymin,xmax,ymax ***/
                    sscanf(argv[i],"%lf",&cymin);
                    i++;
                    if (i >= argc) error();
                    sscanf(argv[i],"%lf",&cxmax);
                    i++;
                    if (i >= argc) error();
                    sscanf(argv[i],"%lf",&cymax);
                    printf("Clip Box: (%lf,%lf) - (%lf,%lf)\n",cxmin, cymin, cxmax, cymax);
                }
                i++;
                if (i >= argc) error();
                if      (strncasecmp2(argv[i], "CUT",3) == 0)    icut=TRUE;
                else if (strncasecmp2(argv[i], "TOUCH",5) == 0)  itouch=TRUE;
                else if (strncasecmp2(argv[i], "INSIDE",6) == 0) iinside=TRUE;
                else error();
                iclip=TRUE;
            } /*** End CLIP & ERASE ***/
            else if (strncasecmp2(argv[i],  "FACTOR",0) == 0)
            {
                i++;
    	        if (i >= argc) error();
    	        infactor=findunit(argv[i]);
    	        if (infactor == 0) error();
                iunit=TRUE;
                i++;
    	        if (i >= argc) error();
    	        outfactor=findunit(argv[i]);
    	        if (outfactor == 0)
    	        {
                    sscanf(argv[i],"%lf",&factor);
                    if (factor == 0) error();
                }
                if (factor == 0)
                {
                    if (infactor ==0)
                    { puts("ERROR: Input unit must be defined before output unit"); exit(1); }
                    factor=infactor/outfactor;
                }
                printf("Output file coordinate values will be factored by %lg\n",factor);
                ifactor=(factor != 1); /* True if a valid factor */
            } /*** End FACTOR ***/
            else if (strncasecmp2(argv[i],"SHIFT",5) == 0)
            {
                i++;
                if (i >= argc) error();
                sscanf(argv[i],"%lf",&xshift);
                i++;
                if (i >= argc) error();
                sscanf(argv[i],"%lf",&yshift);
                iunit=TRUE;
                printf("X Shift: %lg   Y Shift: %lg\n",xshift,yshift);
            } /*** End SHIFT ***/
            else {
                printf("ERROR: Unknown function %s\n",argv[i]);  error();
            }
    }
/* -------------------------------------------------------------------- */
/*	If there is no data in this file let the user know.		*/
/* -------------------------------------------------------------------- */
    openfiles();  /* Open the infile and the outfile for shape and dbf. */
    if( DBFGetFieldCount(hDBF) == 0 )
    {
	puts( "There are no fields in this table!" );
	exit( 1 );
    }
/* -------------------------------------------------------------------- */
/*      Print out the file bounds.                                      */
/* -------------------------------------------------------------------- */
    iRecord = DBFGetRecordCount( hDBF );
    SHPGetInfo( hSHP, NULL, NULL, adfBoundsMin, adfBoundsMax );

    printf( "Input Bounds:  (%lg,%lg) - (%lg,%lg)   Entities: %d   DBF: %d\n",
	    adfBoundsMin[0], adfBoundsMin[1],
            adfBoundsMax[0], adfBoundsMax[1],
            nEntities, iRecord );
	    
    if (strcmp(outfile,"") == 0) /* Describe the shapefile; No other functions */
    {
    	ti = DBFGetFieldCount( hDBF );
	showitems();
	exit(0);
    }
     
    if (iclip) check_theme_bnd();
    
    jRecord = DBFGetRecordCount( hDBFappend );
    SHPGetInfo( hSHPappend, NULL, NULL, adfBoundsMin, adfBoundsMax );
    if (nEntitiesAppend == 0)
        puts("New Output File\n");
    else
        printf( "Append Bounds: (%lg,%lg)-(%lg,%lg)   Entities: %d  DBF: %d\n",
                adfBoundsMin[0], adfBoundsMin[1],
                adfBoundsMax[0], adfBoundsMax[1],
                nEntitiesAppend, jRecord );
    
/* -------------------------------------------------------------------- */
/*	Find matching fields in the append file or add new items.       */
/* -------------------------------------------------------------------- */
    mergefields();
/* -------------------------------------------------------------------- */
/*	Find selection field if needed.                                 */
/* -------------------------------------------------------------------- */
    if (iselect)    findselect();

/* -------------------------------------------------------------------- */
/*  Read all the records 						*/
/* -------------------------------------------------------------------- */
    jRecord = DBFGetRecordCount( hDBFappend );
    for( iRecord = 0; iRecord < nEntities; iRecord++)  /** DBFGetRecordCount(hDBF) **/
    {
/* -------------------------------------------------------------------- */
/*      SELECT for values if needed. (Can the record be skipped.)       */
/* -------------------------------------------------------------------- */
        if (iselect)
            if (selectrec() == 0) goto SKIP_RECORD;   /** SKIP RECORD **/

/* -------------------------------------------------------------------- */
/*      Read a Shape record                                             */
/* -------------------------------------------------------------------- */
        psCShape = SHPReadObject( hSHP, iRecord );

/* -------------------------------------------------------------------- */
/*      Clip coordinates of shapes if needed.                           */
/* -------------------------------------------------------------------- */
        if (iclip)
            if (clip_boundary() == 0) goto SKIP_RECORD; /** SKIP RECORD **/

/* -------------------------------------------------------------------- */
/*      Read a DBF record and copy each field.                          */
/* -------------------------------------------------------------------- */
	for( i = 0; i < DBFGetFieldCount(hDBF); i++ )
	{
/* -------------------------------------------------------------------- */
/*      Store the record according to the type and formatting           */
/*      information implicit in the DBF field description.              */
/* -------------------------------------------------------------------- */
            if (pt[i] > -1)  /* if the current field exists in output file */
            {
                switch( DBFGetFieldInfo( hDBF, i, NULL, &iWidth, &iDecimals ) )
                {
                  case FTString:
                  case FTLogical:
                    DBFWriteStringAttribute(hDBFappend, jRecord, pt[i],
                                            (DBFReadStringAttribute( hDBF, iRecord, i )) );
                    break;

                  case FTInteger:
                    DBFWriteIntegerAttribute(hDBFappend, jRecord, pt[i],
                                             (DBFReadIntegerAttribute( hDBF, iRecord, i )) );
                    break;

                  case FTDouble:
                    DBFWriteDoubleAttribute(hDBFappend, jRecord, pt[i],
                                            (DBFReadDoubleAttribute( hDBF, iRecord, i )) );
                    break;

                  case FTInvalid:
                    break;
                }
            }
	}
	jRecord++;
/* -------------------------------------------------------------------- */
/*      Change FACTOR and SHIFT coordinates of shapes if needed.        */
/* -------------------------------------------------------------------- */
        if (iunit)
        {
	    for( j = 0; j < psCShape->nVertices; j++ ) 
	    {
                psCShape->padfX[j] = psCShape->padfX[j] * factor + xshift;
                psCShape->padfY[j] = psCShape->padfY[j] * factor + yshift;
	    }
        }
        
/* -------------------------------------------------------------------- */
/*      Write the Shape record after recomputing current extents.       */
/* -------------------------------------------------------------------- */
        SHPComputeExtents( psCShape );
        SHPWriteObject( hSHPappend, -1, psCShape );

      SKIP_RECORD:
        SHPDestroyObject( psCShape );
        psCShape = NULL;
        j=0;
    }

/* -------------------------------------------------------------------- */
/*      Print out the # of Entities and the file bounds.                */
/* -------------------------------------------------------------------- */
    jRecord = DBFGetRecordCount( hDBFappend );
    SHPGetInfo( hSHPappend, &nEntitiesAppend, &nShapeTypeAppend,
                adfBoundsMin, adfBoundsMax );
    
    printf( "Output Bounds: (%lg,%lg) - (%lg,%lg)   Entities: %d  DBF: %d\n\n",
	    adfBoundsMin[0], adfBoundsMin[1],
            adfBoundsMax[0], adfBoundsMax[1],
            nEntitiesAppend, jRecord );

/* -------------------------------------------------------------------- */
/*      Close the both shapefiles.                                      */
/* -------------------------------------------------------------------- */
    SHPClose( hSHP );
    SHPClose( hSHPappend );
    DBFClose( hDBF );
    DBFClose( hDBFappend );
    if (nEntitiesAppend == 0) {
        puts("Remove the output files.");
        setext(outfile, "dbf");
        remove(outfile);
        setext(outfile, "shp");
        remove(outfile);
        setext(outfile, "shx");
        remove(outfile);
    }
    return( 0 );
}
Пример #20
0
main()
{
	return(openfiles());
}
int main(int argc, char *argv[]){
  printf("Initializing ... \n");
  initialize();
  if (ictype==2) {
    fcfilename=argv[1];
    FILE *fcfid;
    if ((fcfid=fopen(fcfilename,"rb"))==NULL){
      printf("Unable to open %s ... \n",fcfilename);
      exit(1);}
    readbrfc();  }
  if (stimnum>0) {
    printf("Building stimulus matrix ... \n");
    buildptstim();  }
  printf("Opening files ... \n");

  openfiles();

  step=0;

  printf("Writing initial conditions ... \n");

  output();

  printf("Entering time loop ... \n");

  time_t gpu_start = time(NULL);

  double cpu_start=rtclock();

#pragma acc data copyin(constarr,D,Dp,Afield) copy(datarr)

  while (derivarr[0]<=tfinal && step<=Nsteps + 1 && stable){

    step=step+1;
    derivarr[0]+=dt;        // update time (msec) 
	if (blocktimenum>0)                
      {
  	int i,m,n;
	  for (i=0;i<blocktimenum;++i){
	    if ((derivarr[0]>=blocktimes[i][0])&&(blocktimes[i][1]==0.0)){
//	      printf("Changing block conditions: %4.3f msec \n",derivarr[0]);
	      blocktimes[i][1]=1.0;
	      for (m=1;m<Nx+1;++m){
	        for (n=1;n<Ny+1;++n){
		  if (block[m][n]==0) block[m][n]=1;
			}
      		}
    		}
  		}
       

      } // blockonoff
//#pragma acc parallel num_workers(1) vector_length(128) copyin(block)
#pragma acc kernels copyin(block) 
{  // begin acc
#pragma acc loop independent vector(32) worker(2) gang(256)
    for(Xstep = 1;Xstep<Nx+1;Xstep++){  
#pragma acc loop independent vector(32) worker(2) gang(256)
    for (Ystep = 1; Ystep < Ny+1; Ystep++) {
//	if (stimnum>0)
//     {
//          int i;
//	  datarr[Xstep][Ystep][14][(step-1)%2]=0;
//	  for (i=0;i<stimnum;++i){
//	    if ((stimarr[Xstep-1][Ystep-1][i][0]!=0)&&(derivarr[0]>=stimarr[Xstep-1][Ystep-1][i][0])&&(derivarr[0]<=stimarr[Xstep-1][Ystep-1][i][0]+stimint)){
//	      if (stimarr[Xstep-1][Ystep-1][i][1]==0.0) {
//        //	printf("Applying Stimulus at %4.3f msec to node (%d,%d)\n",derivarr[0],Xstep,Ystep); 
//		stimarr[Xstep-1][Ystep-1][i][1]=1.0;
//	      } //end if
//	      datarr[Xstep][Ystep][14][(step-1)%2]=Istimamp; 
//	    }   //end if
//	  }     //end for
//
//     }  //stimulate
        /* Ix1 */
	double ax1,bx1,tx1,x1inf,dx1dt,x1;
	/* INa */
	double am,bm,tm,minf,ah,bh,th,hinf;
	/* Is */
	double ad,bd,td,dinf,af,bf,tf,finf,dddt,d,dfdt,f;
	/* Cai */
	double kCa,sigma;
        /* Vm */
       double Vm;
       /* IK1 */
       double IK1t1,IK1t2,IK1t3,IK1t4,gK1,IK1;
       /* Ix1 */
       double Ix1t1,Ix1t2,gx1,Ix1;
       /* INa */
       double gNa,ENa,INa,dmdt,m,dhdt,h, A;
       /* Cai */
       double dCaidt,Cai;
       /* Is */
       double Es,gs,Is;
       /* Other currents */
       double Isum,Istim;
       /* Vm */
       double Cm, dVmdt;
       /* Diffusion */
       double Diff;
	/* Need these from datarr to update derivatives in derivarr */

	/* datarr values are not altered here */

	/* these are initial conditions for step=1 */

  Vm=datarr[(step-1)%2][0][Xstep][Ystep];   /* mV */         

  x1=datarr[(step-1)%2][4][Xstep][Ystep];/* unitless */

  m=datarr[(step-1)%2][6][Xstep][Ystep];    /* unitless */

  h=datarr[(step-1)%2][7][Xstep][Ystep];    /* unitless */

  Is=datarr[(step-1)%2][8][Xstep][Ystep];   /* uA/cm^2 */

  d=datarr[(step-1)%2][9][Xstep][Ystep];   /* unitless */

  f=datarr[(step-1)%2][10][Xstep][Ystep];   /* unitless */

  Cai=datarr[(step-1)%2][11][Xstep][Ystep]; /* moles/L */

    /* Constants */

    kCa = constarr[6];      /* msec^-1 */

    sigma = constarr[11];   /* unitless */

    /* Ix1  */ 

    ax1 = abfun_0(Vm);

    bx1 = abfun_1(Vm);

    tx1 = 1 / (ax1+bx1);

    x1inf = ax1 * tx1;

    dx1dt = (x1inf - (x1)) / tx1;

    /* INa */

    am = abfun_2(Vm);

    bm = abfun_3(Vm);

    tm = 1 / (am+bm);

    minf = am * tm;

    dmdt = (minf - (m)) / tm;

    ah = abfun_4(Vm);

    bh = abfun_5(Vm);

    th = 1 / (ah + bh);

    hinf = ah * th;

    dhdt = (hinf - (h)) / th;

    /* Is */

    ad = abfun_8(Vm);

    bd = abfun_9(Vm);

    td = (1 / (ad+bd)) * (sigma);

    dinf = ad * td;

    dddt = (dinf - (d)) / td;

    af = abfun_10(Vm);

    bf = abfun_11(Vm);

    tf = (1 / (af+bf)) * (sigma);

    finf = af * tf;

    dfdt = (finf - (f)) / tf;


    /* Cai */

    dCaidt = (-1e-7)*(Is) + (kCa)*((1e-7)-(Cai));  /* mole/L */

    /* Constants */

    gK1 = constarr[0];            /* mmho/cm^2 */

    gNa = constarr[1];            /* mmho/cm^2 */

    ENa = constarr[2];            /* mV */

    gx1 = constarr[3];            /* mmho/cm^2 */

    gs = constarr[4];             /* mmho/cm^2 */

    Cm = constarr[5];             /* uF/cm^2 */

    //gNaC = &constarr[7];           /* mmho/cm^2 */

    A=Afield[Xstep-1][Ystep-1]; /* unitless */

    /* copy previous timestep data into current datarr */

    /* such that previous Vm is used to update next Vm */

  int jj;
//#pragma acc loop seq
  for (jj=0; jj<varnum-2; jj++)                                               /* varnum-1 b/c don't want to overwrite */
 {
    datarr[step%2][jj][Xstep][Ystep]=datarr[(step-1)%2][jj][Xstep][Ystep];    /* the stimulus and diffusion in last 2 elements of datarr */
 }

  Vm=datarr[step%2][0][Xstep][Ystep];        /* mV */

  dVmdt=datarr[step%2][1][Xstep][Ystep];     /* mV/msec */

  IK1=datarr[step%2][2][Xstep][Ystep];       /* uA/cm^2 */

  Ix1=datarr[step%2][3][Xstep][Ystep];       /* uA/cm^2 */

  x1=datarr[step%2][4][Xstep][Ystep];        /* unitless */

  INa=datarr[step%2][5][Xstep][Ystep];       /* uA/cm^2 */

  m=datarr[step%2][6][Xstep][Ystep];         /* unitless */

  h=datarr[step%2][7][Xstep][Ystep];         /* unitless */

  Is=datarr[step%2][8][Xstep][Ystep];        /* uA/cm^2 */

  d=datarr[step%2][9][Xstep][Ystep];        /* unitless */

  f=datarr[step%2][10][Xstep][Ystep];        /* unitless */

  Cai=datarr[step%2][11][Xstep][Ystep];      /* mole/L */

  Isum=datarr[step%2][12][Xstep][Ystep];    /* uA/cm^2 */

  Diff=datarr[step%2][13][Xstep][Ystep];     /* mV/msec */

  Istim=datarr[step%2][14][Xstep][Ystep];    /* uA/cm^2 */

    /* IK1 */

    IK1t1 = 4 * (exp(0.04*(Vm+85))-1);

    IK1t2 = exp(0.08*(Vm+53)) + exp(0.04*(Vm+53));

    IK1t3 = 0.2 * (Vm+23);

    IK1t4 = 1 - exp(-0.04*(Vm+23));

    /* uA/cm^2  09/07/2005 */

    IK1 = (A) * (gK1) * (IK1t1/IK1t2 + IK1t3/IK1t4);

    datarr[step%2][2][Xstep][Ystep]=IK1 ;       /* uA/cm^2 */	 

    /* Ix1 */

    x1 = x1 + dx1dt*dt;

    datarr[step%2][4][Xstep][Ystep]=x1;        /* unitless */

    Ix1t1 = exp(0.04*(Vm+77)) - 1;

    Ix1t2 = exp(0.04*(Vm+35));

    Ix1 = ((gx1*Ix1t1) / (Ix1t2)) * (x1);        /* uA/cm^2 */

    datarr[step%2][3][Xstep][Ystep]=Ix1;       /* uA/cm^2 */	 

    /* INa */

    m =  m+ dmdt * dt;

    datarr[step%2][6][Xstep][Ystep]=m;         /* unitless */

    h =  h+dhdt * dt;

    datarr[step%2][7][Xstep][Ystep]=h;         /* unitless */

    /* *INa=((gNa)*(pow((m),3.0))*(h)*(*j)+*gNaC)*(Vm-ENa); */

    /* uA/cm^2, BR Na current */

    /* uA/cm^2, no gNaC or j gate in BRDR Na current */

    INa = ((gNa) * block[Xstep][Ystep] * (pow((m),3.0))*(h))*(Vm-ENa); 

    datarr[step%2][5][Xstep][Ystep]=INa;       /* uA/cm^2 */        

    /* Cai */

    Cai = Cai + dCaidt * dt;              /* moles/L */

    datarr[step%2][11][Xstep][Ystep]=Cai;      /* mole/L */	 

    /* Is */

    d = d+dddt * dt;

    datarr[step%2][9][Xstep][Ystep]=d;        /* unitless */

    f = f+dfdt * dt;

    datarr[step%2][10][Xstep][Ystep]=f;        /* unitless */

    Es = -82.3 - 13.0287 * log(Cai);
    Is = (gs) * block[Xstep][Ystep] * (d) * (f) * (Vm-Es);  /* uA/cm^2 */

    datarr[step%2][8][Xstep][Ystep]=Is;        /* uA/cm^2 */	 

    /* Vm */

    Isum = (IK1 + Ix1 + INa + Is);                     /* uA/cm^2 */

    datarr[step%2][12][Xstep][Ystep]=Isum;    /* uA/cm^2 */

    dVmdt = (Diff) - (1/(Cm))*(Isum-Istim);        /* mV/msec */

    datarr[step%2][1][Xstep][Ystep]=dVmdt;     /* mV/msec */   	 

    Vm = Vm + ((dVmdt)*dt);     

    datarr[step%2][0][Xstep][Ystep]= Vm;                       /* mV */


    datarr[step%2][13][Xstep][Ystep]=0.0;   // zero used diffusion terms     

   }  // end Xstep loop
  }    // end Ystep loop
 } //end acc

//bcs();


	#pragma acc parallel vector_length(1) num_workers(1) num_gangs(1)
	{
	  int ii;
	  double R0, R1;
	  
	  R0=(D[1][0]/D[0][0])*(dx/dy);
	  R1=(D[1][0]/D[1][1])*(dy/dx);
	  
	  
	  if (BC==1){   // Slab
	    /* First set Vm at ghost nodes */
	    datarr[step%2][0][0][1]=datarr[step%2][0][2][1];
	    datarr[step%2][0][0][0]=datarr[step%2][0][2][2];
	    datarr[step%2][0][1][0]=datarr[step%2][0][1][2];
	    datarr[step%2][0][Nx][0]=datarr[step%2][0][Nx][2];
	    datarr[step%2][0][Nx+1][0]=datarr[step%2][0][Nx-1][2];
	    datarr[step%2][0][Nx+1][1]=datarr[step%2][0][Nx-1][1];
	    datarr[step%2][0][Nx+1][Ny]=datarr[step%2][0][Nx-1][Ny];
	    datarr[step%2][0][Nx+1][Ny+1]=datarr[step%2][0][Nx-1][Ny-1];
	    datarr[step%2][0][Nx][Ny+1]=datarr[step%2][0][Nx][Ny-1];
	    datarr[step%2][0][1][Ny+1]=datarr[step%2][0][1][Ny-1];
	    datarr[step%2][0][0][Ny+1]=datarr[step%2][0][2][Ny-1];
	    datarr[step%2][0][0][Ny]=datarr[step%2][0][2][Ny];  
	    for (ii=2;ii<Nx;++ii){            /* decouple these loops b/c Nx might not equal Ny */
	      datarr[step%2][0][ii][Ny+1]=datarr[step%2][0][ii][Ny-1]+R1*(datarr[step%2][0][ii-1][Ny]-datarr[step%2][0][ii+1][Ny]);  /* Eq 3 in notes */
	      datarr[step%2][0][ii][0]=datarr[step%2][0][ii][2]-R1*(datarr[step%2][0][ii-1][1]-datarr[step%2][0][ii+1][1]);          /* Eq 2 in notes */
	    }
	    for (ii=2;ii<Ny;++ii){           /* decouple these loops b/c Nx might not equal Ny */
	      datarr[step%2][0][0][ii]=datarr[step%2][0][2][ii]-R0*(datarr[step%2][0][1][ii-1]-datarr[step%2][0][1][ii+1]);           /* Eq 1 in notes */
	      datarr[step%2][0][Nx+1][ii]=datarr[step%2][0][Nx-1][ii]+R0*(datarr[step%2][0][Nx][ii-1]-datarr[step%2][0][Nx][ii+1]);   /* Eq 4 in notes */
	    }
	    
	  }
	}
	


#pragma acc kernels present(datarr, Dp)
{  //begin openacc
#pragma acc loop  independent vector(32) worker(2) gang(256)
    for (Xstep=1; Xstep<Nx+1; ++Xstep) {
#pragma acc loop independent vector(32) worker(2) gang(256)
        for (Ystep=1; Ystep<Ny+1; ++Ystep) {
//Response to MBEC Reviewer: Scattering To Collecting

/* Diffusion: Compute the new Vm's contribution to the next diffusion matrix */
/* (step-1)%2 for next timestep and step%2 for current timestep */
/* Dp stands for Dprime, the Laplacian multiplier form of the diffusion tensor D */
/* Remember: diffusion at ghost points doesn't matter  */

datarr[(step-1)%2][13][Xstep][Ystep] =
        datarr[(step-1)%2][13][Xstep][Ystep]
        - (2*Dp[0][0] + 2*Dp[1][1]) * datarr[step%2][0][Xstep][Ystep]
        - Dp[1][0] * datarr[step%2][0][Xstep-1][Ystep+1]
        + Dp[1][1] * datarr[step%2][0][Xstep][Ystep+1]
        + Dp[1][0] * datarr[step%2][0][Xstep+1][Ystep+1]
        + Dp[0][0] * datarr[step%2][0][Xstep+1][Ystep]
        - Dp[1][0] * datarr[step%2][0][Xstep+1][Ystep-1]
        + Dp[1][1] * datarr[step%2][0][Xstep][Ystep-1]
        + Dp[1][0] * datarr[step%2][0][Xstep-1][Ystep-1]
        + Dp[0][0] * datarr[step%2][0][Xstep-1][Ystep];
        }
    }
}  //end openacc

    if (step%rpN==0) {          // update user
	#pragma acc update host(datarr)
      printf("%4.4e msec, Vm(%d,%d): %3.2f mV\n",derivarr[0],mNx,mNy,datarr[step%2][0][mNx][mNy]); 

      fflush(stdout);

    } 

    if (step%wN==0) output();   // write data to files

  }  // end time loop

  double cpu_end = rtclock();

  time_t gpu_end = time(NULL);    

  printf("total time is %.2lf\n",(double)(cpu_end-cpu_start));

  if (stable){

    printf("\nSimulation Finished!\n");

  }

  else {

    printf("\nSimulation Aborted!\n");

  }

  printf("Saving final conditions...\n\n");

  brfc();

  printf("         tfinal: %5.3f msec\n",tfinal);

  printf("     Final time: %5.3f msec\n",derivarr[0]);

  printf("         Nsteps: %10.2f\n",Nsteps);

  printf("Number of steps: %d\n",step);

  printf("             Nx: %d\n",Nx);

  printf("             Ny: %d\n",Ny);

  closefiles();

}
Пример #22
0
int
main(int argc, char **argv)
{
	int ch, mode, disp, accessmode;
	struct kvmvars kvmvars;
	const char *systemname;
	char *kmemf;

	if (seteuid(getuid()) != 0) {
		err(1, "seteuid failed\n");
	}
	kmemf = NULL;
	systemname = NULL;
	while ((ch = getopt(argc, argv, "M:N:Bbhpr")) != -1) {
		switch((char)ch) {

		case 'M':
			kmemf = optarg;
			kflag = 1;
			break;

		case 'N':
			systemname = optarg;
			break;

		case 'B':
			Bflag = 1;
			break;

		case 'b':
			bflag = 1;
			break;

		case 'h':
			hflag = 1;
			break;

		case 'p':
			pflag = 1;
			break;

		case 'r':
			rflag = 1;
			break;

		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

#define BACKWARD_COMPATIBILITY
#ifdef	BACKWARD_COMPATIBILITY
	if (*argv) {
		systemname = *argv;
		if (*++argv) {
			kmemf = *argv;
			++kflag;
		}
	}
#endif
	if (systemname == NULL)
		systemname = getbootfile();
	accessmode = openfiles(systemname, kmemf, &kvmvars);
	mode = getprof(&kvmvars);
	if (hflag)
		disp = GMON_PROF_OFF;
	else if (Bflag)
		disp = GMON_PROF_HIRES;
	else if (bflag)
		disp = GMON_PROF_ON;
	else
		disp = mode;
	if (pflag)
		dumpstate(&kvmvars);
	if (rflag)
		reset(&kvmvars);
	if (accessmode == O_RDWR)
		setprof(&kvmvars, disp);
	(void)fprintf(stdout, "kgmon: kernel profiling is %s.\n",
		      disp == GMON_PROF_OFF ? "off" :
		      disp == GMON_PROF_HIRES ? "running (high resolution)" :
		      disp == GMON_PROF_ON ? "running" :
		      disp == GMON_PROF_BUSY ? "busy" :
		      disp == GMON_PROF_ERROR ? "off (error)" :
		      "in an unknown state");
	return (0);
}
Пример #23
0
int dopsd(psd_file_t f, char *psdpath, struct psd_header *h){
	int result = 0;

	// file header
	fread(h->sig, 1, 4, f);
	h->version = get2Bu(f);
	get4B(f); get2B(f); // reserved[6];
	h->channels = get2Bu(f);
	h->rows = get4B(f);
	h->cols = get4B(f);
	h->depth = get2Bu(f);
	h->mode = get2Bu(f);

	if(!feof(f) && KEYMATCH(h->sig, "8BPS")){
		if(h->version == 1
#ifdef PSBSUPPORT
		   || h->version == 2
#endif
		){
			openfiles(psdpath, h);

			if(listfile) fprintf(listfile, "-- PSD file: %s\n", psdpath);
			if(xml){
				fputs("<PSD FILE='", xml);
				fputsxml(psdpath, xml);
				fprintf(xml, "' VERSION='%u' CHANNELS='%u' ROWS='%u' COLUMNS='%u' DEPTH='%u' MODE='%u'",
						h->version, h->channels, h->rows, h->cols, h->depth, h->mode);
				if(h->mode >= 0 && h->mode < 16)
					fprintf(xml, " MODENAME='%s'", mode_names[h->mode]);
				fputs(">\n", xml);
			}
			UNQUIET("  PS%c (version %u), %u channels, %u rows x %u cols, %u bit %s\n",
					h->version == 1 ? 'D' : 'B', h->version, h->channels, h->rows, h->cols, h->depth,
					h->mode >= 0 && h->mode < 16 ? mode_names[h->mode] : "???");

			if(h->channels <= 0 || h->channels > 64 || h->rows <= 0
			   || h->cols <= 0 || h->depth <= 0 || h->depth > 32 || h->mode < 0)
			{
				alwayswarn("### something isn't right about that header, giving up now.\n");
			}
			else{
				h->colormodepos = ftello(f);
				if(h->mode == ModeDuotone)
					duotone_data(f, 1);
				else
					skipblock(f, "color mode data");

				h->resourcepos = ftello(f);
				if(rsrc || resdump)
					doimageresources(f);
				else
					skipblock(f, "image resources");

				dolayermaskinfo(f, h);

				h->layerdatapos = ftello(f);
				VERBOSE("## layer data begins @ " LL_L("%lld","%ld") "\n", h->layerdatapos);

				result = 1;
			}
		}else
			alwayswarn("# \"%s\": version %d not supported\n", psdpath, h->version);
	}else
		alwayswarn("# \"%s\": couldn't read header, or is not a PSD/PSB\n", psdpath);

	if(!result)
		alwayswarn("# Try --scavenge (and related options) to see if any layer data can be found.\n");

	return result;
}
Пример #24
0
/*
 ****************************************************************
 *	Programa principal					*
 ****************************************************************
 */
void
main (int argc, const char *argv[])
{
  int opt;

  failure = 0;
  lineno = 0;

  verboseflag = 0;
  definesflag = 0;
  debugflag = 0;
  fixed_outfiles = 0;

	/*
	 *	Analisa as opções
	 */
	while ((opt = getopt (argc, argv, "b:dlo:p:tvVyH")) != EOF)
	{
		switch (opt)
		{
		    case 'b':			/* File prefix */
			spec_file_prefix = optarg;
			break;

		    case 'd':			/* Defines */
			definesflag = 1;
			break;

		    case 'l':			/* No lines */
			nolinesflag = 1;
			break;

		    case 'o':			/* Out file */
			spec_outfile = optarg;
			break;

		    case 'p':			/* Prefix */
			spec_name_prefix = optarg;
			break;

		    case 't':			/* Debug */
			debugflag = 1;
			break;

		    case 'v':			/* Verbose */
			verboseflag = 1;
			break;

		    case 'V':			/* Version */
			printf ("%s", version_string);
			break;

		    case 'y':			/* Fixed output files */
			fixed_outfiles = 1;
			break;

		    case 'H':			/* Help */
			help ();

		    default:			/* Erro */
			putc ('\n', stderr);
			help ();

		}	/* end switch */

	}	/* end while */

  if (optind == argc)
    {
      fprintf(stderr, "%s: no grammar file given\n", pgname);
      exit(1);
    }
  if (optind < argc - 1)
    fprintf(stderr, "%s: warning: extra arguments ignored\n", pgname);

  infile = argv[optind];

  openfiles ();

  /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
     In file reader.c.
     The other parts are recorded in the grammar; see gram.h.  */
  reader();

  /* find useless nonterminals and productions and reduce the grammar.  In
     file reduce.c */
  reduce_grammar();

  /* record other info about the grammar.  In files derives and nullable.  */
  set_derives();
  set_nullable();

  /* convert to nondeterministic finite state machine.  In file LR0.
     See state.h for more info.  */
  generate_states();

  /* make it deterministic.  In file lalr.  */
  lalr();

  /* Find and record any conflicts: places where one token of lookahead is not
     enough to disambiguate the parsing.  In file conflicts.
     Currently this does not do anything to resolve them;
     the trivial form of conflict resolution that exists is done in output.  */
  initialize_conflicts();

  /* print information about results, if requested.  In file print. */
  if (verboseflag)
    verbose();
  else
    terse();

  /* output the tables and the parser to ftable.  In file output. */
  output();
  done(failure);

}	/* end main */
Пример #25
0
computemix(char *fnames[], int nscores, double *xty)
{
#ifdef HOLDOUT
	lg("With holdout\n");
#endif
	int ns2=nscores+2;
	int ns1=nscores+1;
	FILE *fp[NSCORES];
	openfiles(fp,fnames,nscores);

	double xtx[NSCORES+2][NSCORES+2];
	ZERO(xtx);
	
	int u;
	for(u=0; u<NUSERS; u++) {
		PROGRESS(u,NUSERS);
		int base=useridx[u][0];
#ifdef HOLDOUT
		if(aopt) error("cant do holdout with -a");
		int d0=UNTRAIN(u);
		int d1=UNALL(u)-d0;
#else
		int d0=0;
		int d1=UNTRAIN(u);
#endif
		seekfiles(fp,nscores, d0);
		base+=d0;
		int j;			
		for(j=0;j<d1;j++) {
			unsigned int dd=userent[base+j];
			int r = (dd>>USER_LMOVIEMASK)&7;
			float s[NSCORES+2];
			readfiles(fp,s,nscores);
			int f;
			for(f=0;f<nscores;f++)		
				s[f]=r-s[f];
			s[nscores]=1.;
			s[nscores+1]=r;

			int ff;
			for(f=0;f<ns2;f++) {
				for(ff=0;ff<ns2;ff++)
					xtx[f][ff] +=s[f]*s[ff];
			}
		}
		int d2=UNTOTAL(u)-(d1+d0);
		seekfiles(fp,nscores, d2);
	}
	closefiles(fp,nscores);
	int count=xtx[nscores][nscores];
	int j1,j2;
	for(j1=0;j1<nscores;j1++)
		lg("File %d RMSE %f\n",j1,sqrt((xtx[j1][j1]+xtx[ns1][ns1]-2*xtx[ns1][j1])/count));
	double avgs[NSCORES+2],std[NSCORES+2];
	for(j1=0;j1<ns2;j1++) {
		avgs[j1]=xtx[nscores][j1]/count;
		std[j1]=sqrt(xtx[j1][j1]/count-avgs[j1]*avgs[j1]);
	}
	for(j1=0;j1<ns2;j1++)
		lg("%f\t",avgs[j1]);
	lg("\n");
	for(j1=0;j1<ns2;j1++)
		lg("%f\t",std[j1]);
	lg("\n");
	lg("-------------------------------------------------\n");
	for(j1=0;j1<ns2;j1++) {
		for(j2=0;j2<ns2;j2++) {
			lg("%f\t",(xtx[j1][j2]/count-avgs[j1]*avgs[j2])/(std[j1]*std[j2]+1.e-6));
		}
		lg("\n");
	}
	lg("-------------------------------------------------\n");
	double eavgs[NSCORES],estd[NSCORES];
	for(j1=0;j1<nscores;j1++) {
		eavgs[j1]=avgs[ns1]-avgs[j1];
		estd[j1]=sqrt((xtx[ns1][ns1]+ xtx[j1][j1]-2*xtx[j1][ns1])/count);
	}
	for(j1=0;j1<nscores;j1++)
		lg("%f\t",eavgs[j1]);
	lg("\n");
	for(j1=0;j1<nscores;j1++)
		lg("%f\t",estd[j1]);
	lg("\n");
	lg("-------------------------------------------------\n");
	for(j1=0;j1<nscores;j1++) {
		for(j2=0;j2<nscores;j2++) {
			lg("%f\t",((xtx[j1][j2]+xtx[ns1][ns1]-xtx[ns1][j1]-xtx[ns1][j2])/count-eavgs[j1]*eavgs[j2])/(estd[j1]*estd[j2]+1.e-6));
		}
		lg("\n");
	}


	char TRANS='N';
	char UFLO='U';
	int M=ns1;
	int N=ns1;
	int NRHS=1;
	double A[NSCORES+1][NSCORES+1];
	int LDA=NSCORES+1;
	double B[NSCORES+1];
	int LDB=NSCORES+1;
	double S[NSCORES+1];
	double RCOND=0.00001; // singular values below this are treated as zero.
	int RANK;
	double WORK[1000];
	int LWORK=1000;
	int INFO;

	for(j1=0;j1<ns1;j1++) {
		B[j1]=xtx[ns1][j1];
		for(j2=0;j2<ns1;j2++)
			A[j1][j2]=xtx[j1][j2];
	}	
	for(j1=0;j1<ns1;j1++) A[j1][j1]+=LAMBDA;
	/*dgesv_(&N,&NRHS,A,&LDA,IPIV,B,&LDB,&INFO);*/
	/*dgels_(&TRANS,&M,&N,&NRHS,A,&LDA,B,&LDB,WORK,&LWORK,&INFO);*/
	/*dgelss_( &M, &N, &NRHS, A, &LDA, B, &LDB, S, &RCOND, &RANK, WORK, &LWORK, &INFO );*/
	dposv_(&UFLO,&N,&NRHS,A,&LDA,B,&LDB,&INFO);
	if(INFO) error("failed %d\n",INFO);
		
	for(j1=0;j1<=nscores;j1++)
		xty[j1]=B[j1];

	lg("Check that the matrix inversion worked:\n");
	for(j1=0;j1<=nscores;j1++) {
		double sum=LAMBDA*B[j1];
		for(j2=0;j2<=nscores;j2++)
			sum+=xtx[j1][j2]*B[j2];
		lg("%f\t%f\n",sum,xtx[nscores+1][j1]);
	}
}