예제 #1
0
// ---------------------------------------------------------------------------
/// Converts given file to legacy vtk format: extracts separate data chunks
/// into tmp files and than merges all of them using 'append_to_file'.
// ---------------------------------------------------------------------------
static void
convert_to_vtk (const char *name_in, const char *name_out)
{
   FILE *fin     = cfg_open(name_in,   "rt", __func__),
        *fpoints = cfg_open(".points", "wt", __func__),
        *fspeeds = cfg_open(".speeds", "wt", __func__),
        *fcharge = cfg_open(".charge", "wt", __func__);

   int  N = 0;
   char x[31], y[31], z[31], u[31], v[31], w[31], rho[31];
   while (7 == fscanf(fin, "%30s %30s %30s %30s %30s %30s %30s ",
			   x, y, z, u, v, w, rho)) {
      fprintf(fpoints, "%s %s %s\n", x, y, z);
      fprintf(fspeeds, "%s %s %s\n", u, v, w);
      fprintf(fcharge, "%s\n", rho);
      N++;
   }
   fclose(fin);
   fclose(fpoints);
   fclose(fspeeds);
   fclose(fcharge);
   fflush(NULL);

   FILE *res = cfg_open(name_out, "wt", __func__);
   fprintf(res, "# vtk DataFile Version 2.0\n"
		"Particles distribution.\n"
		"ASCII\n"
		"\n"
		"DATASET UNSTRUCTURED_GRID\n"
		"POINTS %d float\n", N);
   append_to_file(res, ".points");

   fprintf(res, "\n\n"
                "CELL_TYPES 2\n"
	        "1\n"
	        "1\n"
	        "\n"
	        "POINT_DATA %d\n"
	        "VECTORS speed float\n", N);
   append_to_file(res, ".speeds");

   fprintf(res, "\n\n"
                "SCALARS charge float 1\n"
	        "LOOKUP_TABLE default\n");
   append_to_file(res, ".charge");

   fclose(res);
}
예제 #2
0
// ---------------------------------------------------------------------------
/// More advanced tester of the mapper (uses maxwellian distribution function to generate mapper).
// ---------------------------------------------------------------------------
void
mapper_testMaxwell (void)
{
  int i;
  FILE *fp;
  double y, dy;
  mapper_t *mapper;

  say ("Testing of the distribution function mapper using Maxwell function with known inverse mapping.");
  say ("See file output/test_mapper2.dat for results.");

  mapper = mapper_create (func_maxwell, - 10.0, 10.0, 5000);								// Creates mapper.

  const double norm = 1.0/(erf (mapper->arg[mapper->N]) - erf (mapper->arg[0]));					// Normalization for analitic result.
  fp = cfg_open ("output/test_mapper2.dat", "wt", __func__);
  fprintf (fp, "variables = x yGood yNum delta\nzone t=\"test\", f = point\n");
  for (y = 0.0, dy = 0.01 ; y <= 1.0 + 1e-7 ; y += dy)
  {
    double x = mapper_invoke (y, mapper);
    double analitic = norm*(erf(x) - erf (mapper->arg[0]));
    fprintf (fp, "%e %e %e %e\n", x, y, analitic, y - analitic);
  }

  fprintf (fp, "zone t=\"integral\", f = point\n");
  for (i = 0 ; i <= mapper->N ; i++)
  {
    double analitic = norm*(erf (mapper->arg[i]) - erf (mapper->arg[0]));
    fprintf (fp, "%e %e %e %e\n", mapper->arg[i], analitic, mapper->func[i], mapper->func[i] - analitic);
  }
  fclose (fp);

  mapper_destroy (mapper);
}
예제 #3
0
// ---------------------------------------------------------------------------
/// Simple tester of the mapper (uses linear distribution function to generate mapper).
// ---------------------------------------------------------------------------
void
mapper_testLinear (void)
{
  int i;
  FILE *fp;
  double y, dy;
  mapper_t *mapper;

  say ("Testing of the distribution function mapper using linear function with known inverse mapping.");
  say ("See file output/test_mapper.dat for results.");

  mapper = mapper_create (func_lin, 0, sqrt (2.0), 20);

  fp = cfg_open ("output/test_mapper.dat", "wt", __func__);
  fprintf (fp, "variables = y invGood invNum delta\nzone t=\"test\", f = point\n");
  for (y = 0, dy = 0.01 ; y <= 1.0 ; y += dy)
  {
    double x1 = mapper_invoke (y, mapper);
    fprintf (fp, "%e %e %e %e\n", y, sqrt (2*y), x1, x1 - sqrt (2*y));
  }

  fprintf (fp, "zone t=\"integral\", f = point\n");
  for (i = 0 ; i < mapper->N ; i++)
    fprintf (fp, "%e %e %e %e\n", mapper->arg[i], mapper->func[i], 0.5*mapper->arg[i]*mapper->arg[i], mapper->func[i] - 0.5*mapper->arg[i]*mapper->arg[i]);
  fclose (fp);

  mapper_destroy (mapper);
}
예제 #4
0
파일: main.c 프로젝트: hongwozai/emms
static void load_config(void)
{
    cfg_t *cfg;
    char listen_port_str[128];
    char ip[128];
    char servername[128];
    char num[128];
    char thresold[128];

    cfg_open(&cfg, CONFIG_FILENAME);
    cfg_read(cfg, "server", "ip", listen_ip);
    cfg_read(cfg, "server", "listen", listen_port_str);
    cfg_read(cfg, "server", "netcard", netcard);
    cfg_read(cfg, "server", "thread num", num);
    cfg_read(cfg, "oracle", "ip", ip);
    cfg_read(cfg, "oracle", "servername", servername);
    cfg_read(cfg, "oracle", "username", oracle_username);
    cfg_read(cfg, "oracle", "password", oracle_password);
    cfg_read(cfg, "spam", "thresold", thresold);
    cfg_read(cfg, "spam", "data file", spam_data);
    cfg_close(cfg);

    /* 处理,应该在此进行正确性判断 */
    sprintf(oracle_servername, "%s/%s", ip, servername);
    listen_port = atoi(listen_port_str);
    nthread = atoi(num);
    spam_thresold = atof(thresold);
    DEBUG("listen ip: %s:%s\n"
          "oracle user: %s, password: %s\n"
          "thread count: %d\nspam_data: %s\n"
          "thresold: %lf\n",
          listen_ip, listen_port_str,
          oracle_username, oracle_password,
          nthread, spam_data, spam_thresold);
}
예제 #5
0
// ---------------------------------------------------------------------------
/// Gets all units from disk (recorded by units_save).
// ---------------------------------------------------------------------------
void
units_load (void)
{
   ENSURE (!initialized, "double initialization");

   FILE *fp = cfg_open ("binData/units.bin", "rt", __func__);
   fread (&units_lambda,          sizeof (double), 1, fp);
   fread (&units_v,               sizeof (double), 1, fp);
   fread (&units_t,               sizeof (double), 1, fp);
   fread (&units_omega,           sizeof (double), 1, fp);
   fread (&units_E,               sizeof (double), 1, fp);
   fread (&units_S,               sizeof (double), 1, fp);
   fread (&units_A,               sizeof (double), 1, fp);
   fread (&units_n,               sizeof (double), 1, fp);
   fread (&units_rho,             sizeof (double), 1, fp);
   fread (&units_criticalElectronsConcentration, sizeof (double), 1, fp);
   fread (&units_debayScale,      sizeof (double), 1, fp);
   fread (&units_micron,          sizeof (double), 1, fp);
   fread (&units_femtosecond,     sizeof (double), 1, fp);
   fread (&units_plasmaFrequency, sizeof (double), 1, fp);
   fread (&units_plasmaPeriod,    sizeof (double), 1, fp);
   fclose (fp);

   initialized = 1;
}
예제 #6
0
파일: test2.c 프로젝트: 3ki5tj/zcom
int main(void)
{
  int   nr = 1, cnt = 0;
  float tmin = 0.5f, tmax = 1.0f;
  char  *p = NULL;
  cfg_t *cfg;

  if ((cfg = cfg_open("foo.cfg")) == NULL) {
    printf("error reading\n");
    return 1;
  }
  cfg_add(cfg, "nrtemp", "%d", &nr, "# of T.");
  cfg_add(cfg, "tmin", "%f", &tmin, "T min");
  cfg_add(cfg, "tmax", "%f", &tmax, "T max");
  cfg_add(cfg, "mystr",  "%s", &p, "some string");
  cfg_add(cfg, "arrcnt", "%d", &cnt, "array count");
  cfg_match(cfg, CFG_CHECKUSE);
  cfg_dump(cfg);

  printf("nr=%d, (%g,%g), cnt=%d\n", nr, tmin, tmax, cnt);
  printf("mystr=\"%s\"\n", p);
  cfg_close(cfg);
  ssdelall();
  return 0;
}
예제 #7
0
/**
  * \brief Loads entire mesh and updates mapper to access loaded data. Pointer to the allocated array is returned.
  */
void *mesh2_load(const char *name, reg_t * map, int *elemSize)
{
	int activator[3];
	FILE *fp = cfg_open(name, "rb", __func__);	// Opens file.

	fseek(fp, -10 * sizeof(int), SEEK_END);	// Gets info added to the tail of file.
	fread(activator, sizeof(int), 3, fp);
	fread(map->min, sizeof(int), 3, fp);	// Loads region limits.
	fread(map->max, sizeof(int), 3, fp);
	fread(elemSize, sizeof(int), 1, fp);

	if(activator[0] != mc_have_x || activator[1] != mc_have_y || activator[2] != mc_have_z)
		error("mesh_load: inconsistent dimensionality of the simulation.");

	mf_mesh_initUnroll(map);

	const int volume = reg_volume(map);
	void *array = malloc((*elemSize) * volume);
	if(!array) error("mesh_load: cannot allocate %.3f Kb for array.", (*elemSize) * volume / 1024.0);

	fseek(fp, 0, SEEK_SET);	// Gets body of the array.
	fread(array, *elemSize, volume, fp);
	fclose(fp);

	return array;
}
예제 #8
0
// ---------------------------------------------------------------------------
/// Saves meshes for tecplot.out.
// ---------------------------------------------------------------------------
void
tecIO_saveFields (double time, meshVec_RO_p E, meshVec_RO_p H)
{
    parameter_save ();
    int fileMap = fileMap_save ();

    // Saving region.
    reg_t reg = {{cpu_min[0], cpu_min[1], cpu_min[2]},
                 {cpu_max[0], cpu_max[1], cpu_max[2]}, 0};

    // Saves interpolated vector fields.
    tecIO_saveVec (IO_nameCpuRec (name_E_full, cpu_here, tecplotNum), E, &reg, tecIO_interpE);
    tecIO_saveVec (IO_nameCpuRec (name_H_full, cpu_here, tecplotNum), H, &reg, tecIO_interpH);

    if (cpu_here)
        return;

    // Saves header and descriptor.
    FILE *fp = cfg_open (IO_nameRec (name_info, tecplotNum), "wb", __func__);
    fwrite (&time, sizeof (double), 1, fp);
    fwrite (&cpu_total, sizeof (int), 1, fp);
    fwrite (&fileMap, sizeof (int), 1, fp);
    fclose (fp);

    // Saves partition.
    partition_save (IO_nameRec (name_prtn_full, tecplotNum));
}
예제 #9
0
/**
  * Tag entry point.
  */
void tag_TFSFOpenFaces(FILE * fp)
{
	static int first = 1;

	if(!first)		// Ensures uniqness of the call.
		msg_warning(mf_here, "tag [TFSF: open faces] is used twice.");
	first = 0;

	const char *word = NULL;
	msg_send("tag_TFSFOpenFaces: ");
	while(cfg_isOption(fp))	// Gets all options.
	{
		word = cfg_readOptWord(fp);

		int f = 0;
		for(; f < 6; ++f) if(!strcmp(faces[f].name, word)) break;

		if(f >= 6) error("tag_TFSFOpenFaces: word '%s' is not a valid option here.", word);

		faces[f].opened = 1;
		msg_send("  - removing face %s ...", faces[f].name);
	}

	if(!word) msg_send("  Tag is called but no faces marked to open.");

	if(cpu_here)		// Master will update all files.
		return;

	FILE *file = cfg_open(".TFSF/openFaces.cfg", "wt", __func__);
	for(int f = 0; f < 6; ++f) fprintf(file, "@ %d        state of %s (0 - engaged, 1 - opened/removed)\n", faces[f].opened, faces[f].name);
	fprintf(file, "\n\n  This file is automatically generated by setup.out (tag [TFSF: open faces]).\n");
	fclose(file);
}
예제 #10
0
파일: read_conf.c 프로젝트: emillon/gmpc
int main(int argc, char **argv)
{
    gchar *path= "read_conf_test.db2";
    config_obj *cfg, *cfg2;
    if(argc == 2){
        path = argv[1];
    }
    /* Open the test file */
    cfg = cfg_open(path);
    cfg2 = cfg_open("test-db2");
    print_all_entries(cfg,cfg2);
    /* Close the test file */
    cfg_close(cfg);
    cfg_close(cfg2);
    /* Remove test file */
    g_unlink("test-db2");
    return EXIT_SUCCESS;
}
예제 #11
0
kucode_t gfx_add_image_resources( int resource_type, const char *resfile )
{
	uint i = 0;
	char img_id[CFG_BUFFER],
		img_file[CFG_BUFFER];
	kucode_t code;
	cfg_session_t *cfg;
	pstart();
	
	if ( res_assign(resource_type, RESTYPE_ZFL, gfx_img_control) != KE_NONE )
	{
		plogfn(gettext("Failed to assign an image resource type: %d.\n"), KU_GET_ERROR());
		preturn KU_GET_ERROR();
	}
	
	if ( (cfg = cfg_open(resfile, CFG_STRICT|CFG_STEP)) == NULL )
	{
		if ( KU_GET_ERROR() == KE_IO )
			plogfn(gettext("Failed to open a file: %s.\n"), strerror(errno)); else
			plogfn(gettext("Failed to open a file: %d.\n"), KU_GET_ERROR());
		preturn KU_GET_ERROR();
	}
	
	if ( cfg_query(cfg, "image=ss/r", img_id, img_file) != KE_NONE )
	{
		plogfn(gettext("Failed to add a query for the resource file: %d.\n"), KU_GET_ERROR());
		cfg_close(cfg);
		preturn KU_GET_ERROR();
	}
	
	while ( (code = cfg_process(cfg)) == KE_SIGNAL )
	{
		if ( res_add(img_file, img_id, resource_type, NULL, 0) != KE_NONE )
		{
			plogfn(gettext("Failed to add an image resource (line %d): %d.\n"), \
				cfg->cfg_line, KU_GET_ERROR());
			cfg_close(cfg);
			preturn KU_GET_ERROR();
		}
		i++;
	}
	if ( code != KE_NONE )
	{
		plogfn(gettext("Failed to process a resource file on line %d: %d.\n"), \
			cfg->cfg_line, code);
		cfg_close(cfg);
		preturn code;
	}
	
	if ( cfg_close(cfg) != KE_NONE )
		plogfn(gettext("Warning: failed to close a resource file: %d.\n"), KU_GET_ERROR());
	
	plogfn(gettext("%d images added.\n"), i);
	
	preturn KE_NONE;
}
예제 #12
0
// ---------------------------------------------------------------------------
/// Saves vector field with intermidiate interpolation/unrolling intro fixed
/// size buffer to save RAM (no tmp meshes engaged).
// ---------------------------------------------------------------------------
static void
tecIO_saveVec (const char *name, meshVec_RO_p mesh, const reg_t *reg,
               interpFunc_t combiner)
{
    const int size = sizeof (vec3D_t);
    spanSet_t spans;
    ENSURE (! mf_mesh_pointIsOutside (mesh, reg->min[0], reg->min[1], reg->min[2])
         && ! mf_mesh_pointIsOutside (mesh, reg->max[0], reg->max[1], reg->max[2]),
            "region to save is bigger than mesh");

    ENSURE (mc_tecCapacity > 30*size && size == mf_mesh_sizeofNode (mesh),
            "too small buffer or bad sizeof for tuned packer");

    // Saves valid region.
    FILE *fp = cfg_open (name, "wb", __func__);
    fwrite (&reg->min[0], sizeof (int), 1, fp);
    fwrite (&reg->min[1], sizeof (int), 1, fp);
    fwrite (&reg->min[2], sizeof (int), 1, fp);
    fwrite (&reg->max[0], sizeof (int), 1, fp);
    fwrite (&reg->max[1], sizeof (int), 1, fp);
    fwrite (&reg->max[2], sizeof (int), 1, fp);
    fwrite (mesh, sizeof (mesh_t), 1, fp);

    // Storage domain.
    reg_t domain = {{mesh->imin, mesh->jmin, mesh->kmin},
                    {mesh->imax, mesh->jmax, mesh->kmax}, 0};

    // Forms list of spans to process.
    span_init (&domain, reg, &spans, size);

    // Exports strides for combiner.
    dx = size*mc_have_x*mesh->width_yz;
    dy = size*mc_have_y*mesh->width_z;
    dz = size*mc_have_z;

    while (!span_allTouched (&spans)) {
        // Packs buffer.
        int pos = 0;
        do {
            long int start,
                     length;

            // Gets span ("start + length").
            length = span_iterate (&spans, mc_tecCapacity - pos, &start);

            // Interpolates into buffer.
            for (int l = 0 ; l < length ; l += size, pos += size)
                combiner (mesh, start + l, (vec3D_t*) (tecBuffer + pos));
        } while (mc_tecCapacity - pos - size > 0 && !span_allTouched (&spans));

        fwrite (tecBuffer, 1, pos, fp);
    }
    fclose (fp);
}
예제 #13
0
static void
init()
{
    tty = isatty(0);
    if (tty)
        (void) printf("dscfglockd cli %s\n", "07/06/12");
    if ((cfg = cfg_open(NULL)) == NULL) {
        perror("cfg_open");
        exit(1);
    }
}
예제 #14
0
void settings_init(const char *path)
{

    config_t *cfg;

    cfg = cfg_open(path);

    settings_parse(cfg);

    cfg_close(cfg);

}
예제 #15
0
/**
  * Saves parameters.
  */
void parameter_save(void)
{
	if(cpu_here)		// Only master saves the data.
		return;

	FILE *fp = cfg_open("binData/domain.bin", "wb", __func__);	// Saves parameters.
	double dble[7] = { h1, h2, h3, Lx, Ly, Lz, tau };
	fwrite(dble, sizeof(double), 7, fp);
	fwrite(dmn_mesh_min, sizeof(int), 6, fp);
	fwrite(dmn_bc_min, sizeof(int), 6, fp);
	fclose(fp);
}
예제 #16
0
// ---------------------------------------------------------------------------
/// Appends data from the 'src' file to the 'fdest' and deletes the source.
// ---------------------------------------------------------------------------
static void
append_to_file (FILE *fdest, const char *src)
{
   FILE *fsrc = cfg_open(src, "rt", __func__);
   char  buffer[MERGE_BUFFER_SIZE+1];
   int   fetched;
   while (!feof(fsrc)) {
      fetched = fread(buffer, 1, MERGE_BUFFER_SIZE, fsrc);
      fwrite(buffer, 1, fetched, fdest);
   }
   fclose(fsrc);
   unlink(src);
}
예제 #17
0
파일: edit.c 프로젝트: OPSF/uClinux
static void transfer_params(char *config_file)
{
    int n;
    char *bitmap_file, *opt;
    char *cp;
    int cfd;

    cfg_bitmap_only();		/* disable everything but cf_bitmap */
    
    cfd = cfg_open(config_file);
    if (verbose >= 3) printf("cfg_open returns: %d\n", cfd);
    n = cfg_parse(cf_bitmap);
    if (verbose >= 3) printf("cfg_parse returns: %d\n", n);
    if (n != 0) {
	die("Illegal token in '%s'", config_file);
    }
    if ((bitmap_file = cfg_get_strg(cf_bitmap, "bitmap")) != NULL) {
	opt = "Using";
	cp = strrchr(config_file, '/');
	if (cp && bitmap_file[0] != '/') {
	    *++cp = 0;
	    bitmap_file = strcat(strcpy(alloc(strlen(config_file) + strlen(bitmap_file) + 1),
					config_file),
				 bitmap_file);
	    *cp = '/';
	}
    } else {
	opt = "Assuming";
	cp = strrchr(config_file, '.');
	if (cp) *cp = 0;
	bitmap_file = alloc(strlen(config_file) + strlen(BMP_BMP) + 1);
	strcpy(bitmap_file, config_file);
	strcat(bitmap_file, BMP_BMP);
	if (cp) *cp = '.';
    }

    printf("Transfer parameters from '%s' to '%s'", config_file, bitmap_file);
    if (yesno("?", 0)==0) exit(0);

    if (verbose > 0) printf("%s bitmap file:  %s\n", opt, bitmap_file);
    
    bmp_file_open(bitmap_file);
    
    bmp_do_table(cfg_get_strg(cf_bitmap, "bmp-table"), menu);
    bmp_do_colors(cfg_get_strg(cf_bitmap, "bmp-colors"), menu);
    bmp_do_timer(cfg_get_strg(cf_bitmap, "bmp-timer"), menu);
    
    bmp_file_close(1);  /* update */
    
    exit(0);
}
예제 #18
0
// ---------------------------------------------------------------------------
/// Loads mesh distributed over many nodes and common disk space.
// ---------------------------------------------------------------------------
void
IO_loadMesh (const char *format, mesh_p mesh, const reg_t *reg, fileMap_t *fMap)
{
  regList_t pieces = mc_regList_init;											// List of pieces partitioned by map.
  reg_distributeOnMap (reg, &fMap->map, &pieces);

  for (int claim = 0 ; claim < pieces.N ; ++claim)									// Loads all readable sub-regions.
  {
    FILE *fp = cfg_open (name (format, pieces.list[claim].cpu), "rb", __func__);
    mesh_upload (mesh, pieces.list + claim, fp);
    fclose (fp);
  }
  regList_clean (&pieces);
}
예제 #19
0
파일: main.c 프로젝트: binarycode/mandor3
// ---------------------------------------------------------------------------
/// Checks external termination request or time-out (decision is made <b>by master node only</b> thus everything is coherent).
// ---------------------------------------------------------------------------
static void
main_throwStopFlag (void)
{
   // Workers decide nothing.
   if (cpu_here)
      return;

   static int buffer[2];
   FILE *fp = cfg_open ("tmp/stop.flag", "rt", __func__);
   // "Fire alarm" and time limit in seconds.
   fscanf (fp, "%d %d", buffer, buffer + 1);
   fclose (fp);

   static timeTick_t now,
                     prevCheckTime;
   time_get (&now);

   // Checks if next check-point time < walltime.
   static double dT = 0;
   double estimate = time_elapsed (&stopFlag_startTime, &now)
                   + 1.2*dT + 1.5*stopFlag_saveTime;
   if (estimate >= buffer[1] || buffer[0]) {
      say ("main_throwStopFlag: time limit reached\n"
           "  o time = %f\n  o save time = %f\n"
           "  o interval between checks = %f\n"
           "  o estimate next hit time = %f\n  o time limit = %d\n",
           time_elapsed(&stopFlag_startTime, &now),
           stopFlag_saveTime,
           dT, estimate, buffer[1]);
      buffer[0] = 1;
   }

   // Updates estimate of step duration.
   static int first = 1;
   if (!first)
      dT = 0.8*time_elapsed (&prevCheckTime, &now) + 0.2*dT;
   prevCheckTime = now;

   ENSURE (cpu_total <= 1000,
           "increase 'stopFlag_requests' array at least up to %d", cpu_total);

   // Sends stop flag to everybody.
   buffer[1] = cpu_total;
   for (int cpu = 0 ; cpu < cpu_total ; cpu++) {
      MPI_Isend (buffer, 2, MPI_INT, cpu, TAG_STOP_REQUEST, MPI_COMM_WORLD,
                 stopFlag_requests + cpu);
   }
}
예제 #20
0
/**
  * Loads parameters.
  */
void parameter_load(void)
{
	FILE *fp = cfg_open("binData/domain.bin", "rb", __func__);	// Loads data from file.
	fread(&h1, sizeof(double), 1, fp);
	fread(&h2, sizeof(double), 1, fp);
	fread(&h3, sizeof(double), 1, fp);
	fread(&Lx, sizeof(double), 1, fp);
	fread(&Ly, sizeof(double), 1, fp);
	fread(&Lz, sizeof(double), 1, fp);
	fread(&tau, sizeof(double), 1, fp);
	fread(dmn_mesh_min, sizeof(int), 6, fp);
	fread(dmn_bc_min, sizeof(int), 6, fp);
	fclose(fp);

	parameter_bcast();	// Syncronizes data over cluster.
}
예제 #21
0
// ----------------------------------------------------------------------------
/// Loads parameters.
// ----------------------------------------------------------------------------
void
parameter_load (void)
{
   FILE *fp = cfg_open ("binData/domain.bin", "rb", __func__);
   fread (&h1,  sizeof (double), 1, fp);
   fread (&h2,  sizeof (double), 1, fp);
   fread (&h3,  sizeof (double), 1, fp);
   fread (&Lx,  sizeof (double), 1, fp);
   fread (&Ly,  sizeof (double), 1, fp);
   fread (&Lz,  sizeof (double), 1, fp);
   fread (&tau, sizeof (double), 1, fp);
   fread (dmn_min,    sizeof (int), 6, fp);
   fread (dmn_bc_min, sizeof (int), 6, fp);
   fclose (fp);

   parameter_bcast ();
}
예제 #22
0
// ---------------------------------------------------------------------------
/// Initializes spectrum using tag_photoDF_parameters(int param, void *pntr) to get parameter of the photo-DF.
// ---------------------------------------------------------------------------
// XXX static
void
modes_init (int m1, int m2, double gamma_cutOff, double phase)
{
  int    mz;
  double V0, omega2_pe; 												// Parameters of the photo-DF.
  char name[50];

  tag_photoDF_parameters (mc_photoDF_V0, &V0);										// Takes photo-DF parameters from creator.
  tag_photoDF_parameters (mc_photoDF_omega2_pe, &omega2_pe);

  modeN = m2 - m1 + 1;
  modeM1 = m1;
  modePhase = (double*) calloc (modeN, sizeof (double));
  modeGamma = (double*) calloc (modeN, sizeof (double));

  const double unit_alpha = units (mc_r0)/(units (mc_t0)*units (mc_v0));						// [omega/kV] with k = 2\pi/\lambda.
  const double omega_pe = sqrt (omega2_pe);
  for (mz = m1 ; mz <= m2 ; mz++)
  {
    double kz, gammaDivOmegaPE;												// Parameters of the mode.
    kz = 2.0*mc_pi*mz/Lz;
    gammaDivOmegaPE = kz*V0/(unit_alpha*omega_pe)*dispFunc_s (unit_alpha*omega_pe/(kz*V0));

    if (gammaDivOmegaPE < gamma_cutOff)
      continue;

    modeGamma[mz-modeM1] = gammaDivOmegaPE;
    modePhase[mz-modeM1] = (phase < 0) ? 2.0*mc_pi*rand ()/(double) RAND_MAX : phase;
  }

  MPI_Bcast (modePhase, modeN, MPI_DOUBLE, 0, MPI_COMM_WORLD);								// Syncronizes global random parameters.

  sprintf (name, "output/tag_seed_PITS(%03d).dat", cpu_here);
  FILE *fp = cfg_open (name, "wt", "tag_seed2Stream_singleMode");
  fprintf (fp, "variables = mode, E<sub>0</sub>, <greek>f/p</greek>, <greek>g/w</greek><sub>pe</sub>, ");
  fprintf (fp, "<greek>g</greek><sub>WE</sub>, k<sub>z</sub>, \"2.0/(h3*kz)*sin (kz*h3/2.0) - 1.0\"\n");
  fprintf (fp, "zone t = \"L_z = %e, `w_p_e = %e\", f = point\n", Lz, sqrt (omega2_pe));
  for (mz = m1 ; mz <= m2 ; mz++)											// Prints spectrum of initial seed.
  {
    double kz, gamma;													// Parameters of the mode.
    kz = 2*mc_pi*mz/Lz;
    gamma = modeGamma[mz-modeM1];
    fprintf (fp, "%d %e %e %e %e %e %e\n", mz, dEz, modePhase[mz-modeM1]/mc_pi, gamma, 2.0*gamma*omega_pe, kz, 2.0/(h3*kz)*sin (kz*h3/2.0) - 1.0);
  }
  fclose (fp);
}
예제 #23
0
// ---------------------------------------------------------------------------
/// Saves particle constributions for tecplot.out.
// ---------------------------------------------------------------------------
void
tecIO_saveCurrents (meshVec_RO_p J, meshDouble_RO_p rho)
{
    // Saving region.
    reg_t reg = {{cpu_min[0], cpu_min[1], cpu_min[2]},
                 {cpu_max[0], cpu_max[1], cpu_max[2]}, 0};

    // Saves interpolated vector field.
    tecIO_saveVec (IO_nameCpuRec (name_J_full, cpu_here, tecplotNum), J, &reg, tecIO_interpE);
    mesh_save (mcast_mesh_RO (rho), IO_nameCpuRec (name_rho_full, cpu_here, tecplotNum), cpu_min[0], cpu_min[1], cpu_min[2], cpu_max[0], cpu_max[1], cpu_max[2]);

    tecplotNum++;

    FILE *fp = cfg_open ("binData/tecplot.N", "wt", __func__);			// Updates total number of records.
    fprintf (fp, "@ %d  tecplots' records written.\n", tecplotNum);
    fclose (fp);
}
예제 #24
0
/**
  * Saves map and header to the file.
  */
void mesh2_save(const char *name, const reg_t * saveReg, const reg_t * map, const char *array, int elemSize)
{
	int min[3] = { saveReg->min[0] * mc_have_x, saveReg->min[1] * mc_have_y, saveReg->min[2] * mc_have_z };
	int max[3] = { saveReg->max[0] * mc_have_x, saveReg->max[1] * mc_have_y, saveReg->max[2] * mc_have_z };

	if(!reg_isInside(saveReg, map))	// Checks boundary violation.
		error("mesh2_save: save region violates domain boundary.");

	FILE *fp = cfg_open(name, "wb", __func__);	// Opens file.
	int span = (max[2] - min[2] + 1);	// Defines size of the continuous chunk.
	for(int i = min[0]; i <= max[0]; ++i)	// Saves body of the mesh.
		for(int j = min[1]; j <= max[1]; ++j)
			fwrite(array + elemSize * mf_mesh2_offset(map, i, j, min[2]), elemSize, span, fp);

	fwrite(ACTIVATOR, sizeof(int), 3, fp);
	fwrite(min, sizeof(int), 3, fp);	// Saves region boundaries and so on.
	fwrite(max, sizeof(int), 3, fp);
	fwrite(&elemSize, sizeof(int), 1, fp);
	fclose(fp);		// Closes file.
}
예제 #25
0
int
read_cfg(struct silo_options *o)
{
	char *tmp;
	if (access(o->conffile, R_OK) && (errno == ENOENT))
		return 0;
	/* If errno != ENOENT, let cfg_open report an error */
	cfg_open(o->conffile);
	cfg_parse(cf_options);
	tmp = cfg_get_strg(cf_options, "ipldevice");
	if ( ! o->ipldevice  && tmp ) 
		o->ipldevice = tmp;
	tmp = cfg_get_strg(cf_options, "image");
	if ( ! strncmp(o-> image,SILO_IMAGE,strlen(SILO_IMAGE)) && tmp ) 
		o->image = tmp;
	tmp = cfg_get_strg(cf_options, "parmfile");
	if ( !strncmp(o->parmfile,SILO_PARMFILE,strlen(SILO_PARMFILE)) && tmp) 
		o->parmfile = tmp;
	if ( ! o -> ramdisk ) 
		o->ramdisk = cfg_get_strg(cf_options, "ramdisk");
	tmp = cfg_get_strg(cf_options, "bootsect");
	if ( !strncmp(o -> bootsect,SILO_BOOTSECT,strlen(SILO_BOOTSECT))&&tmp)
		o->bootsect = tmp;
	tmp = cfg_get_strg(cf_options, "map") ;
	if ( !strncmp(o -> bootmap,SILO_BOOTMAP,strlen(SILO_BOOTMAP)) && tmp) 
		o->bootmap = tmp; 
	tmp = cfg_get_strg(cf_options, "verbose");
	if ( tmp ) {
		unsigned short v;
		sscanf (tmp, "%hu", &v);
		o->verbosity = v;
	}
	tmp = cfg_get_strg(cf_options, "testlevel");
	if ( tmp ) {
		unsigned short t;
		sscanf (tmp, "%hu", &t);
		o->testlevel += t;
	}
	return 1;
}
예제 #26
0
int
get_cfg_setid(CFGFILE *cfg, char *ctag, char *tohost, char *tofile)
{
	int setnum = 0;
	int close_cfg = 0;
	char key[CFG_MAX_KEY];
	char setid[64];

	if (cfg == NULL) {
		close_cfg = 1;
		if ((cfg = cfg_open(NULL)) == NULL) {
			return (-1); /* message printed by caller */
		}
		if (!cfg_lock(cfg, CFG_RDLOCK)) {
			cfg_close(cfg);
			return (-1);
		}
	}
	setnum = find_setnumber_in_libcfg(cfg, ctag, tohost, tofile);
	if (setnum < 0)
		return (setnum);

	(void) snprintf(key, CFG_MAX_KEY, "sndr.set%d.options", setnum);
	if (cfg_get_single_option(cfg, CFG_SEC_CONF, key, "setid",
		    setid, sizeof (setid)) < 0) {
		if (close_cfg)
			cfg_close(cfg);

		spcs_log("sndr", NULL,
		    gettext("%s unable to get unique setid "
		    "for %s:%s"), program, tohost, tofile);
		return (-1);

	}
	if (close_cfg)
		cfg_close(cfg);

	return (atoi(setid));

}
예제 #27
0
파일: svadm.c 프로젝트: 0xffea/illumos-gate
static void
sv_cfg_open(CFGLOCK mode)
{
	if (cfg != NULL)
		return;

	cfg = cfg_open(NULL);
	if (cfg == NULL) {
		error(NULL, gettext("unable to access the configuration"));
		/* NOTREACHED */
	}

	if (cfg_cluster_tag && *cfg_cluster_tag) {
		cfg_resource(cfg, cfg_cluster_tag);
	} else {
		cfg_resource(cfg, NULL);
	}
	if (!cfg_lock(cfg, mode)) {
		error(NULL, gettext("unable to lock the configuration"));
		/* NOTREACHED */
	}
}
예제 #28
0
// ---------------------------------------------------------------------------
/// Gets global parameters of the given record set.
// ---------------------------------------------------------------------------
void
tecIO_parameters (int recordNum, double *time, int *cpuN, int *fileMapID)
{
    struct {
        int    cpuN, fMapID;
        double time;
    } pack;

    if (!cpu_here) {
        FILE *fp = cfg_open (IO_nameRec (name_info, recordNum), "rb", __func__);
        fread (&pack.time, sizeof (double), 1, fp);
        fread (&pack.cpuN, sizeof (int), 1, fp);
        fread (&pack.fMapID, sizeof (int), 1, fp);
        fclose (fp);
    }

    MPI_Bcast (&pack, sizeof (pack), MPI_BYTE, 0, MPI_COMM_WORLD);

    if (time)       *time = pack.time;
    if (cpuN)       *cpuN = pack.cpuN;
    if (fileMapID)  *fileMapID = pack.fMapID;
}
예제 #29
0
// ---------------------------------------------------------------------------
/// Saves units to the disk (normally is done only by 'setup.out' and only in
/// 'create' mode).
// ---------------------------------------------------------------------------
void
units_save (void)
{
   ENSURE (initialized, "units are not prepared to save them");

   FILE *fp = cfg_open ("binData/units.bin", "wt", __func__);
   fwrite (&units_lambda,          sizeof (double), 1, fp);
   fwrite (&units_v,               sizeof (double), 1, fp);
   fwrite (&units_t,               sizeof (double), 1, fp);
   fwrite (&units_omega,           sizeof (double), 1, fp);
   fwrite (&units_E,               sizeof (double), 1, fp);
   fwrite (&units_S,               sizeof (double), 1, fp);
   fwrite (&units_A,               sizeof (double), 1, fp);
   fwrite (&units_n,               sizeof (double), 1, fp);
   fwrite (&units_rho,             sizeof (double), 1, fp);
   fwrite (&units_criticalElectronsConcentration, sizeof (double), 1, fp);
   fwrite (&units_debayScale,      sizeof (double), 1, fp);
   fwrite (&units_micron,          sizeof (double), 1, fp);
   fwrite (&units_femtosecond,     sizeof (double), 1, fp);
   fwrite (&units_plasmaFrequency, sizeof (double), 1, fp);
   fwrite (&units_plasmaPeriod,    sizeof (double), 1, fp);
   fclose (fp);
}
예제 #30
0
파일: main.c 프로젝트: binarycode/mandor3
// ---------------------------------------------------------------------------
/// Reads <b>run_mandor.cfg</b> file and sets all global static parameters (called from main()).
// ---------------------------------------------------------------------------
static void
main_startUp (void)
{
   // Loading time is a first estimate of a saving time.
   timeTick_t startUpStart;
   time_get (&startUpStart);

   main_allocateMeshes ();

   FILE *fp;
   int buffer[6];
   if (!cpu_here) {
      fp = cfg_open ("run_mandor.cfg", "rt", __func__);	// Reads checkpointing steps and startup flags.
      buffer[0] = cfg_readInt (fp);			//  - totalSteps.
      buffer[1] = cfg_readInt (fp);			//  - chPoint_full.
      buffer[2] = cfg_readInt (fp);			//  - chPoint_tecplot.
      buffer[3] = (1 == cfg_readInt (fp));		//  - continueRun.
      buffer[4] = cfg_readInt (fp);			//  - chPoint_stopRequest
      buffer[5] = cfg_readInt (fp);			//  - chPoint_spectr
      fclose (fp);
   }

   // Broadcasts parameters.
   MPI_Bcast (buffer, 6, MPI_INT, 0, MPI_COMM_WORLD);
   totalSteps          = buffer[0];
   chPoint_full        = buffer[1];
   chPoint_tecplot     = buffer[2];
   int continueRun     = buffer[3];
   chPoint_stopRequest = buffer[4];
   chPoint_spectr      = buffer[5];

   // Checks if sizes can be divided by.
   ENSURE (totalSteps*chPoint_full*chPoint_tecplot
                     *chPoint_stopRequest*chPoint_spectr,
           "'run_mandor.cfg' contains zero step(s)");

   // Sets time barrier.
   if (!(fp = fopen ("tmp/stop.flag", "rt"))) {
      fp = cfg_open ("tmp/stop.flag", "wt", __func__);
      // Sets timeout.
      SAY_DEBUG ("Setting timeout to 23h30m.");
      fprintf (fp, "0\n%d\n", 23*60*60 + 30*60);
      fclose  (fp);
   }

   // Record are numbered as 0, .., N - 1.
   int point = sysIO_recordsTotal () - 1;
   MPI_Bcast (&point, 1, MPI_INT, 0, MPI_COMM_WORLD);

   // Chooses start-up mode.
   ENSURE (point >= 0, "initial checkpoint is not prepared");

   if (continueRun && point != 0) {
      fileMap_init (mc_fileMap_contn);
      sysIO_setRecordNum (-1);		// Continues check-pointing.
      tecIO_setRecordNum (-1);		// Continues tecplot output.
      spectr_continueDump ();		// Continues spectr output.
   } else {
      fileMap_init (mc_fileMap_start);
      sysIO_setRecordNum (1);		// Starts to write just after setup record.
      tecIO_setRecordNum (1);		// Starts to write just after setup record.
      spectr_startDump ();		// Starts new spectr output sequence.
      point = 0;
   }

   // Initializes total energy diagnostic.
   wDensity_prepare (!(continueRun && point != 0));

   /// \todo Partitioning options outside.
   SAY_WARNING("Explicit partitioning is blocked.");
   if (/*continueRun && point != 0 &&*/ 0) {
      partition_load ("output/partition_onStart.cfg");	// Loads old partitioning.
   } else {
      partition_init ();				// Initializes partitioning.
      partition_save ("output/partition_onStart.cfg");	// Saves partitioning used.
   }

   // Sets the size of meshes using the partitioning.
   main_reconfigureMeshes ();

   double time;
   const reg_t to_load = {{cpu_min[0], cpu_min[1], cpu_min[2]},
                          {cpu_max[0], cpu_max[1], cpu_max[2]}, 0};
   sysIO_loadEM (point, &time, &to_load, &E, &H);
   plasma_load  (point);

   mf_mesh_clean (&J);
   mf_mesh_clean (&rho);

   parameter_setTime (time);

   parameter_dump ();		// Prints parameters loaded.
   partition_show ();		// Tecplot visualization of partititon.

   // Allocates probes and opens associated files.
   probe_allocate (continueRun && point > 0);

   say ("main_startUp: config file is imported. Parameters of the run are:");
   say ("  - %d total steps",                totalSteps);
   say ("  - %d steps between check-points", chPoint_full);
   if (chPoint_tecplot > 0) {
      say ("  - %d steps between tecplot shots", chPoint_tecplot);
   } else {
      say ("  - tecplot shots are off");
   }
   if (chPoint_spectr > 0) {
      say ("  - %d steps between spectral data dumps", chPoint_spectr);
   } else {
      say ("  - EM spectral energy distribution diagnostic is off");
   }
   say ("  - %d steps between updating a stop request", chPoint_stopRequest);
   say ("  - simulation is %s from check-point #%03d.",
                                    (continueRun && point != 0) ? "continued"
                                                                : "started",
                                    point);

   // Loading time is a good estimate of saving time.
   timeTick_t startUpFinish;
   time_get (&startUpFinish);
   stopFlag_saveTime = time_elapsed (&startUpStart, &startUpFinish);

   // Configures convolutioner.
   double VSP_weight = 1.0;
   if (cl_findDouble ("VSP:weight", &VSP_weight))
      VSP_weight = (VSP_weight > 0.5 && VSP_weight < 1.00001) ? VSP_weight
                                                              : 1.00;
   VSP_configure (VSP_weight);
}