示例#1
0
template <typename INT> std::string ExoII_Read<INT>::Load_Elmt_Map()
{
  SMART_ASSERT(Check_State());

  if (!Open())
    return "WARNING:  File not open!";

  delete[] elmt_map;
  elmt_map = nullptr;

  if (num_elmts == 0)
    return "WARNING:  There are no elements!";

  elmt_map = new INT[num_elmts];
  SMART_ASSERT(elmt_map != nullptr);

  ex_opts(0); // Temporarily turn off error reporting in case map isn't stored.
  int err = ex_get_elem_num_map(file_id, elmt_map);
  ex_opts(EX_VERBOSE);

  if (err < 0) {
    std::cout << "EXODIFF ERROR: Unable to load element map; "
              << "Exodus error = " << err << ".  Aborting..." << '\n';
    exit(1);
  }
  else if (err > 0)
    return "WARNING: Default element map being used.";

  return "";
}
示例#2
0
static void set_ex_opts()
{
  if (!ex_opts_set)
  {
    if (log_level() == LOG_DEBUG)
      ex_opts(EX_DEBUG | EX_VERBOSE);
    else if (log_level() == LOG_DETAIL)
      ex_opts(EX_VERBOSE);
    ex_opts_set = true;
  }
}
示例#3
0
int main (int argc, char **argv)
{
   int exoid, exoid1, error, idum;
   int CPU_word_size,IO_word_size;

   float version;

   char *cdum = 0;

   ex_opts(EX_VERBOSE | EX_ABORT);

/* open EXODUS II files */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 0;                    /* use size in file */

   exoid = ex_open ("test.exo",         /* filename path */
                     EX_READ,           /* access mode = READ */
                     &CPU_word_size,    /* CPU word size */
                     &IO_word_size,     /* IO word size */
                     &version);         /* ExodusII library version */

   printf ("\nafter ex_open\n");
   if (exoid < 0) exit(1);

   printf ("test.exo is an EXODUSII file; version %4.2f\n",
            version);
   printf ("         CPU word size %1d\n",CPU_word_size);
   printf ("         I/O word size %1d\n",IO_word_size);
   ex_inquire(exoid,EX_INQ_API_VERS, &idum, &version, cdum);
   printf ("EXODUSII API; version %4.2f\n", version);

   CPU_word_size = 8;                   /* this really shouldn't matter for
                                           the copy but tests the conversion
                                           routines */
   IO_word_size = 4;

   exoid1 = ex_create ("testcp.exo",    /* filename */
                        EX_CLOBBER|EX_NORMAL_MODEL,     /* OK to overwrite, normal */
                        &CPU_word_size, /* CPU float word size in bytes */
                        &IO_word_size); /* I/O float word size in bytes */

   printf ("\nafter ex_create, exoid = %3d\n",exoid1);
   if (exoid1 < 0) exit(1);

   printf ("         CPU word size %1d\n",CPU_word_size);
   printf ("         I/O word size %1d\n",IO_word_size);

   /* ncopts = NC_VERBOSE; */

   error = ex_copy (exoid, exoid1);
   printf ("\nafter ex_copy, error = %3d\n", error);

   error = ex_close (exoid);
   printf ("\nafter ex_close, error = %3d\n", error);

   error = ex_close (exoid1);
   printf ("\nafter ex_close, error = %3d\n", error);
   return 0;
}
示例#4
0
int main()
{
  float version = 0.0;

  ex_opts(EX_VERBOSE | EX_ABORT);
  int CPU_word_size = 0; /* sizeof(float) */
  int IO_word_size  = 4; /* (4 bytes) */

  /* ======================================== */
  /* Create an empty exodus file             */
  /* ====================================== */
  int exoid = ex_create("test.exo", EX_CLOBBER, &CPU_word_size, &IO_word_size);
  ex_close(exoid);

  /* ======================================== */
  /* Now try to open and read the empty file */
  /* ====================================== */

  exoid = ex_open("test.exo",     /* filename path */
                  EX_READ,        /* access mode = READ */
                  &CPU_word_size, /* CPU word size */
                  &IO_word_size,  /* IO word size */
                  &version);      /* ExodusII library version */

  printf("test.exo exoid = %d\n", exoid);

  {
    char title[MAX_LINE_LENGTH + 1];
    int  num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets;
    int  error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk,
                            &num_node_sets, &num_side_sets);
    printf("after ex_get_init, error = %3d\n", error);
    if (error)
      exit(-1);
    else
      exit(0);
  }
}
示例#5
0
int nem_spread(NemSpread<T,INT> &spreader, const char *salsa_cmd_file, int subcycles, int cycle)
{
  static char yo[] = "nem_spread";
  /* Local declarations. */
  double start_t, end_t;

  printf("Using "ST_ZU" byte integers and "ST_ZU" byte floating point values.\n", sizeof(INT), sizeof(T));
  
  /*
   * Read in the ASCII input file from the front end.
   * NOTE: In this case we read only the information needed to create the
   *       parallel exodus files.
   */
    printf("Reading the command file, %s\n", salsa_cmd_file);
    if(read_pexoII_info(spreader, salsa_cmd_file) < 0)
    {
      fprintf(stderr,"%s ERROR: Could not read in the the I/O command file"
              " \"%s\"!\n", yo, salsa_cmd_file);
      exit(1);
    }

    if (!spreader.check_inp()) {
      fprintf(stderr, "%s ERROR: Error in user specified parameters.\n", yo);
      exit(1);
    }

  strcpy(PIO_Info.Scalar_LB_File_Name, Exo_LB_File);
  strcpy(PIO_Info.Scalar_Exo_File_Name, ExoFile);

  /* If debug is on the turn on netCDF/Exodus information as well */
  if(Debug_Flag > 0)
     ex_opts(EX_VERBOSE | EX_DEBUG);
  else
    ex_opts(EX_VERBOSE);

  /*
   * Read initial information from the mesh file.
   *  - This provides error checking against the load balance file
   *  - Broadcast the information
   */
  spreader.read_mesh_param();

  /*
   * Process the load balance information
   *  - Read info from the lb file with Proc 0
   *  - Distribute the information to all processors
   */
  start_t = second();
  spreader.load_lb_info();
  end_t   = second () - start_t;
  printf ("\nLoad load balance information time: %f (sec.)\n\n", end_t);

  /* Process subcycle and cycle if specified. */
  if ((subcycles > 0 && cycle == -1) || (cycle != -1 && subcycles == 0)) {
    fprintf(stderr, "ERROR: Only one of the -subcycle and -cycle options was specified.\n");
    fprintf(stderr, "       Either both or neither are required.\n");
    exit(1);
  }

  if (subcycles > 0) {
    /* Determine number of processors per subcycle. */
    int part_count = (spreader.Proc_Info[0] + subcycles - 1) / subcycles;
    int start_part = part_count * cycle;
    spreader.Proc_Info[4] = start_part;
    spreader.Proc_Info[5] = part_count;
  }

  /*
   * Verify parameters in case spreading a subset of mesh...
   */
  if (spreader.Proc_Info[4] < 0)
    spreader.Proc_Info[4] = 0;
  if (spreader.Proc_Info[5] <= 0)
    spreader.Proc_Info[5] = spreader.Proc_Info[0];
  
  if (spreader.Proc_Info[4] + spreader.Proc_Info[5] > spreader.Proc_Info[0])
   spreader.Proc_Info[5] = spreader.Proc_Info[0] - spreader.Proc_Info[4];
  
  if (spreader.Proc_Info[4] != 0 || spreader.Proc_Info[5] != spreader.Proc_Info[0]) {
    printf("\nSpreading subset of mesh.  Starting with processor %d and outputting %d processors.\n",
	   spreader.Proc_Info[4], spreader.Proc_Info[5]);
  }

  /*
   * Get any restart parameter information
   *  - Read the parameters from the input ExodusII file
   */
  if(spreader.Restart_Info.Flag > 0) {
    printf ("Load exoII restart param info to each proc.\n\n");
    start_t = second ();
    spreader.read_restart_params();
    end_t   = second () - start_t;
    printf ("Load restart parameters time: %f (sec.)\n\n", end_t);
  }


  /*
   * Read the ExodusII mesh file and distribute information
   * contained in it to all processors
   *  - Each processor only gets the information that it needs
   *    to solve its piece of the mesh
   */
  printf ("Load exoII mesh info to each proc.\n\n");
  start_t = second ();
  spreader.load_mesh();
  end_t   = second () - start_t;

  printf ("Load mesh time: %f (sec.)\n\n", end_t);

  /*
   * Get any restart variable data
   *  - Read the restart data from the input ExodusII file, distribute
   *    it to the processors, and write it to the parallel files
   */
  if(spreader.Restart_Info.Flag > 0) {
    printf ("Load exoII restart data info to each proc.\n\n");
    start_t = second ();
    spreader.read_restart_data();
    end_t   = second () - start_t;
    printf ("Load restart data time: %f (sec.)\n\n", end_t);
  }

  printf ("Write of parallel exodus complete\n");

  safe_free((void**)&(spreader.Proc_Ids));
  safe_free((void**)&(PIO_Info.RDsk_List));
  
  for (int i=0; i < spreader.Proc_Info[0]; i++) {
    safe_free((void**) &spreader.globals.GNodes[i]);
    if (spreader.globals.Elem_Type != NULL)
      safe_free((void**) &spreader.globals.Elem_Type[i]);
    if (spreader.globals.Proc_Global_Node_Id_Map != NULL)
      safe_free((void**) &spreader.globals.Proc_Global_Node_Id_Map[i]);
    safe_free((void**) &spreader.globals.Proc_SS_Ids[i]);
    safe_free((void**) &spreader.globals.Proc_SS_GEMap_List[i]);
    safe_free((void**) &spreader.globals.Proc_NS_Ids[i]);
    safe_free((void**) &spreader.globals.Proc_NS_GNMap_List[i]);
    safe_free((void**) &spreader.globals.Proc_Nodes_Per_Elem[i]);
    safe_free((void**) &spreader.globals.GElem_Blks[i]);
    safe_free((void**) &spreader.globals.Proc_Global_Elem_Id_Map[i]);
  }
  safe_free((void**) &spreader.globals.Elem_Type);
  safe_free((void**) &spreader.globals.GNodes);
  return 0;
}
示例#6
0
int main (int argc, char *argv[])
{

  char  
    *str,**str2,*(*qa_records)[4],*line, *oname, *dot, *filename;

  const char* ext=EXT;

  int   
    i,j,k,n,n1,n2,cpu_word_size,io_word_size,exo_file,err,
    num_axes,num_nodes,num_elements,num_blocks,
    num_side_sets,num_node_sets,num_time_steps,
    num_qa_lines,num_info_lines,num_global_vars,
    num_nodal_vars,num_element_vars,num_nodeset_vars, num_sideset_vars,
    *ids,*iscr,*num_elem_in_block,*junk,
    *elem_list,*side_list,
    *nsssides,*nssdfac,
    *nnsnodes,*nnsdfac,
    nstr2, has_ss_dfac;
    
  float
    exo_version;

  double
    *scr,*x,*y,*z;

  oname=0;

  /* process arguments */
  for (j=1; j< argc; j++){
    if ( strcmp(argv[j],"-t")==0){    /* write text file (*.m) */
      del_arg(&argc,argv,j);
      textfile=1;
      j--;
      continue;
    }
    if ( strcmp(argv[j],"-o")==0){    /* specify output file name */
      del_arg(&argc,argv,j);
      if ( argv[j] ){
         oname=(char*)calloc(strlen(argv[j])+10,sizeof(char));
	 strcpy(oname,argv[j]);
	 del_arg(&argc,argv,j);
	 printf("output file: %s\n",oname);
      }
      else {
         fprintf(stderr,"Invalid output file specification.\n");
	 return 2;
      }
      j--;

      continue;
    }
  }

   /* QA Info */
  printf("%s: %s, %s\n", qainfo[0], qainfo[2], qainfo[1]);
  
  /* usage message*/
  if(argc != 2){
    printf("%s [options] exodus_file_name.\n",argv[0]);
    printf("   the exodus_file_name is required (exodusII only).\n");
    printf("   Options:\n");
    printf("     -t write a text (.m) file rather than a binary .mat\n");
    printf("     -o output file name (rather than auto generate)\n");
    printf(" ** note **\n");
    printf("Binary files are written by default on all platforms with");
    printf(" available libraries.\n");
    exit(1);
  }

  /* open output file */
  if ( textfile )
    ext=".m";

  if ( !oname ){
      filename = (char*)malloc( strlen(argv[1])+10);
      strcpy(filename,argv[1]);
      dot=strrchr(filename,'.');
      if ( dot ) *dot=0;
      strcat(filename,ext);
  }
  else {
      filename=oname;
  }

  if ( textfile ){
    m_file = fopen(filename,"w");
    if (!m_file ){
      fprintf(stderr,"Unable to open %s\n",filename);
      exit(1);
    }
  }
  else {
    mat_file = Mat_CreateVer(filename, NULL, MAT_FT_MAT5);
    if (mat_file == NULL) {
      fprintf(stderr,"Unable to create matlab file %s\n",filename);
      exit(1);
    }
  }

  /* word sizes */
  cpu_word_size=sizeof(double);
  io_word_size=0;

  /* open exodus file */
  exo_file=ex_open(argv[1],EX_READ,&cpu_word_size,&io_word_size,&exo_version);
  if (exo_file < 0){
    printf("error opening %s\n",argv[1]);
    exit(1);
  }

  /* print */
  fprintf(stderr,"translating %s to %s ...\n",argv[1],filename);

  /* read database paramters */
  line=(char *) calloc ((MAX_LINE_LENGTH+1),sizeof(char));
  err = ex_get_init(exo_file,line,
	&num_axes,&num_nodes,&num_elements,&num_blocks,
        &num_node_sets,&num_side_sets);
  num_qa_lines   = ex_inquire_int(exo_file,EX_INQ_QA);
  num_info_lines = ex_inquire_int(exo_file,EX_INQ_INFO);
  num_time_steps = ex_inquire_int(exo_file,EX_INQ_TIME);
  err=ex_get_variable_param(exo_file,EX_GLOBAL,&num_global_vars);
  err=ex_get_variable_param(exo_file,EX_NODAL,&num_nodal_vars);
  err=ex_get_variable_param(exo_file,EX_ELEM_BLOCK,&num_element_vars);
  err=ex_get_variable_param(exo_file,EX_NODE_SET,&num_nodeset_vars);
  err=ex_get_variable_param(exo_file,EX_SIDE_SET,&num_sideset_vars);


  /* export paramters */
  PutInt("naxes",  1, 1,&num_axes);
  PutInt("nnodes", 1, 1,&num_nodes);
  PutInt("nelems", 1, 1,&num_elements);
  PutInt("nblks",  1, 1,&num_blocks);
  PutInt("nnsets", 1, 1,&num_node_sets);
  PutInt("nssets", 1, 1,&num_side_sets);
  PutInt("nsteps", 1, 1,&num_time_steps);
  PutInt("ngvars", 1, 1,&num_global_vars);
  PutInt("nnvars", 1, 1,&num_nodal_vars);
  PutInt("nevars", 1, 1,&num_element_vars);
  PutInt("nnsvars", 1, 1,&num_nodeset_vars);
  PutInt("nssvars", 1, 1,&num_sideset_vars);

  /* allocate -char- scratch space*/
  n =                              num_info_lines;
  n = (n > num_global_vars) ?  n : num_global_vars;
  n = (n > num_nodal_vars) ?   n : num_nodal_vars;
  n = (n > num_element_vars) ? n : num_element_vars;
  n = (n > num_blocks) ?       n : num_blocks;
  nstr2 = n;
  str2= (char **) calloc (n,sizeof(char *));
  for (i=0;i<nstr2;i++)
    str2[i]=(char *) calloc ((MAX_LINE_LENGTH+1),sizeof(char));
  str= (char *) calloc ((MAX_LINE_LENGTH+1)*n,sizeof(char));

  /* title */
  PutStr("Title",line);

#if 0
  /* QA records */
  if (num_qa_lines > 0 ){
    qa_records  =(char *(*)[4]) calloc (num_qa_lines*4,sizeof(char **));
    for (i=0;i<num_qa_lines;i++) 
      for (j=0;j<4;j++)
	qa_records[i][j]=(char *) calloc ((MAX_STR_LENGTH+1),sizeof(char));
    err=ex_get_qa(exo_file,qa_records);
    str[0]='\0';
    for (i=0;i<num_qa_lines;i++){
      for (j=0;j<4;j++)
	sprintf(str+strlen(str),"%s ",qa_records[i][j]);
      strcat(str,"\n");
    }
    for (i=0;i<num_qa_lines;i++){
        for (j=0;j<4;j++)
	  free(qa_records[i][j]);
    }
    free(qa_records);
  }

  /* information records */
  if (num_info_lines > 0 ){
    err = ex_get_info(exo_file,str2);
    str[0]='\0';
    for (i=0;i<num_info_lines;i++)
      sprintf(str+strlen(str),"%s\n",str2[i]);
    PutStr("info",str);
    str[0]='\0';
    for (i=0;i<num_info_lines;i++)
      if (strncmp(str2[i],"cavi",4)==0)
	sprintf(str+strlen(str),"%s\n",str2[i]);
    PutStr("cvxp",str);
  }
#endif
  /* nodal coordinates */
  x = (double *) calloc(num_nodes,sizeof(double));
  y = (double *) calloc(num_nodes,sizeof(double));
  if (num_axes == 3) 
    z = (double *) calloc(num_nodes,sizeof(double));
  else 
    z = NULL;
  err = ex_get_coord(exo_file,x,y,z);
  PutDbl("x0", num_nodes, 1, x);
  PutDbl("y0", num_nodes, 1, y);
  free(x);
  free(y);
  if (num_axes == 3){ 
    PutDbl("z0",num_nodes,1, z);
    free(z);
  }
  
   /* side sets */
  if(num_side_sets > 0){
    ids=(int *) calloc(num_side_sets,sizeof(int));
    err = ex_get_ids(exo_file,EX_SIDE_SET,ids);
    PutInt( "ssids",num_side_sets, 1,ids);
    nsssides = (int *) calloc(num_side_sets,sizeof(int)); /*dgriffi */
    nssdfac  = (int *) calloc(num_side_sets,sizeof(int)); /*dgriffi */
    for (i=0;i<num_side_sets;i++){
      err = ex_get_set_param(exo_file,EX_SIDE_SET, ids[i],&n1,&n2);
      nsssides[i]=n1; /* dgriffi */
      nssdfac[i]=n2;  /* dgriffi */
      /*
       * the following provision is from Version 1.6 when there are no
       * distribution factors in exodus file
       */
      has_ss_dfac = (n2 != 0);
      if(n2==0 || n1==n2){
	
	printf(" WARNING: Exodus II file does not contain distribution factors.\n");
	
	/* n1=number of faces, n2=number of df */
	/* using distribution factors to determine number of nodes in the sideset
         causes a lot grief since some codes do not output distribution factors
         if they are all equal to 1. mkbhard: I am using the function call below
         to figure out the total number of nodes in this sideset. Some redundancy
         exists, but it works for now */

	junk = (int*) calloc(n1,sizeof(int)); 
	err = ex_get_side_set_node_count(exo_file,ids[i],junk);
	n2=0; /* n2 will be equal to the total number of nodes in the sideset */
	for (j=0;j<n1;j++) n2+=junk[j];
	free(junk);

      }
	
      iscr = (int *) calloc(n1+n2,sizeof(int));
      err = ex_get_side_set_node_list(exo_file,ids[i],iscr,iscr+n1);
      /* number-of-nodes-per-side list */
      sprintf(str,"ssnum%02d",i+1);
      PutInt(str,n1,1,iscr); 
      /* nodes list */
      sprintf(str,"ssnod%02d",i+1);
      PutInt(str,n2,1,iscr+n1);
      free(iscr);
      /* distribution-factors list */
      scr = (double *) calloc (n2,sizeof(double));
      if (has_ss_dfac) {
	ex_get_side_set_dist_fact(exo_file,ids[i],scr);
      } else {
	for (j=0; j<n2; j++) {
	  scr[j] = 1.0;
	}
      }
      sprintf(str,"ssfac%02d",i+1);
      PutDbl(str,n2,1,scr);
      free(scr);
      /* element and side list for side sets (dgriffi) */
      elem_list = (int *) calloc(n1, sizeof(int));
      side_list = (int *) calloc(n1, sizeof(int));
      err = ex_get_set(exo_file,EX_SIDE_SET,ids[i],elem_list,side_list);
      sprintf(str,"ssside%02d",i+1);
      PutInt(str,n1,1,side_list);
      sprintf(str,"sselem%02d",i+1);
      PutInt(str,n1,1,elem_list);
      free(elem_list);
      free(side_list);

    }
    /* Store # sides and # dis. factors per side set (dgriffi) */
    PutInt("nsssides",num_side_sets,1,nsssides);
    PutInt("nssdfac",num_side_sets,1,nssdfac);
    free(ids);
    free(nsssides);
    free(nssdfac);
  }

  /* node sets (section by dgriffi) */
  if(num_node_sets > 0){
    ids=(int *) calloc(num_node_sets,sizeof(int));
    err = ex_get_ids(exo_file,EX_NODE_SET, ids);
    PutInt( "nsids",num_node_sets, 1,ids);
    nnsnodes = (int *) calloc(num_node_sets,sizeof(int)); 
    nnsdfac  = (int *) calloc(num_node_sets,sizeof(int));
    for (i=0;i<num_node_sets;i++){
      err = ex_get_set_param(exo_file,EX_NODE_SET,ids[i],&n1,&n2);
      iscr = (int *) calloc(n1,sizeof(int));
      err = ex_get_node_set(exo_file,ids[i],iscr);
      /* nodes list */
      sprintf(str,"nsnod%02d",i+1);
      PutInt(str,n1,1,iscr);
      free(iscr);
      /* distribution-factors list */
      scr = (double *) calloc (n2,sizeof(double));
      ex_get_node_set_dist_fact(exo_file,ids[i],scr);  
      sprintf(str,"nsfac%02d",i+1);
      PutDbl(str,n2,1,scr);
      free(scr);

      nnsnodes[i]=n1;
      nnsdfac[i]=n2;

    }

      /* Store # nodes and # dis. factors per node set */
      PutInt("nnsnodes",num_node_sets,1,nnsnodes);
      PutInt("nnsdfac",num_node_sets,1,nnsdfac);
      free(ids);
   
    free(nnsdfac);
    free(nnsnodes);
    
  }

  /* element blocks */
  ids=(int *) calloc(num_blocks,sizeof(int));
  num_elem_in_block=(int *) calloc(num_blocks,sizeof(int));
  err = ex_get_ids(exo_file,EX_ELEM_BLOCK,ids);
  PutInt( "blkids",num_blocks, 1,ids);
  for (i=0;i<num_blocks;i++) {
    err = ex_get_elem_block(exo_file,ids[i],str2[i],&n,&n1,&n2);
    num_elem_in_block[i]=n;
    iscr = (int *) calloc(n*n1,sizeof(int));
    err = ex_get_conn(exo_file,EX_ELEM_BLOCK,ids[i],iscr, NULL, NULL);
    sprintf(str,"blk%02d",i+1);
    PutInt(str,n1,n,iscr);
    free(iscr);
  }
  str[0]='\0';
  for (i=0;i<num_blocks;i++)
    sprintf(str+strlen(str),"%s\n",str2[i]);
  PutStr("blknames",str);  

  /* time values */
  if (num_time_steps > 0 ) {
    scr = (double *) calloc (num_time_steps,sizeof(double));
    err= ex_get_all_times (exo_file,scr);
    PutDbl( "time", num_time_steps, 1,scr);
    free(scr); 
  }

  /* global variables */
  if (num_global_vars > 0 ) {
    err = ex_get_variable_names(exo_file,EX_GLOBAL,num_global_vars,str2);
    str[0]='\0';
    for (i=0;i<num_global_vars;i++)
      sprintf(str+strlen(str),"%s\n",str2[i]);
    PutStr("gnames",str);
    scr = (double *) calloc (num_time_steps,sizeof(double));
    for (i=0;i<num_global_vars;i++){
      sprintf(str,"gvar%02d",i+1);
      err=ex_get_glob_var_time(exo_file,i+1,1,num_time_steps,scr);
      PutDbl(str,num_time_steps,1,scr);
    }
    free(scr);
  }

  /* nodal variables */
  if (num_nodal_vars > 0 ) {
    err = ex_get_variable_names(exo_file,EX_NODAL,num_nodal_vars,str2);
    str[0]='\0';
    for (i=0;i<num_nodal_vars;i++)
      sprintf(str+strlen(str),"%s\n",str2[i]);
    PutStr("nnames",str);
    scr = (double *) calloc (num_nodes*num_time_steps,sizeof(double));
    for (i=0;i<num_nodal_vars;i++){
      sprintf(str,"nvar%02d",i+1);
      for (j=0;j<num_time_steps;j++)
	err=ex_get_nodal_var(exo_file,j+1,i+1,num_nodes,
                                  scr+num_nodes*j);
      PutDbl(str,num_nodes,num_time_steps,scr);
    }
    free(scr);
  }

  /* element variables */
  if (num_element_vars > 0 ) {
    err = ex_get_variable_names(exo_file,EX_ELEM_BLOCK,num_element_vars,str2);
    str[0]='\0';
    for (i=0;i<num_element_vars;i++)
      sprintf(str+strlen(str),"%s\n",str2[i]);
    PutStr("enames",str);
    /* truth table */
    iscr = (int *) calloc(num_element_vars*num_blocks, sizeof(int));
    ex_get_elem_var_tab(exo_file,num_blocks,num_element_vars,iscr);
    for (i=0;i<num_element_vars;i++){
      scr = (double *) calloc (num_elements*num_time_steps,sizeof(double));
      n=0;
      sprintf(str,"evar%02d",i+1);
      for (j=0;j<num_time_steps;j++){
	for (k=0;k<num_blocks;k++){ 
          if(iscr[num_element_vars*k+i]==1)
	      ex_get_elem_var(exo_file,j+1,i+1,ids[k],num_elem_in_block[k],scr+n);
	      n=n+num_elem_in_block[k];
	      
	}
      }
      PutDbl(str,num_elements,num_time_steps,scr);
      free(scr);
    }
    free(iscr);
  }
  free(num_elem_in_block);
  free(ids);
 
  /* node and element number maps */
  ex_opts(0);  /* turn off error reporting. It is not an error to have no map*/
  ids = (int *)malloc(num_nodes*sizeof(int));
  err = ex_get_node_num_map(exo_file,ids);
  if ( err==0 ){
    PutInt("node_num_map",num_nodes,1,ids);
  }
  free(ids);

  ids = (int *)malloc(num_elements*sizeof(int));
  err = ex_get_elem_num_map(exo_file,ids);
  if ( err==0 ){
    PutInt("elem_num_map",num_elements,1,ids);
  }
  free(ids);


  /* close exo file */
  ex_close(exo_file);
  
  /* close mat file */
  if ( textfile )
    fclose(m_file);
  else
    Mat_Close(mat_file);

  /* */
  fprintf(stderr,"done.\n");

  free(filename);
  free(line);
  
  free(str);
  for (i=0;i<nstr2;i++)
    free(str2[i]);
  free(str2);
  

  /* exit status */
  add_to_log("exo2mat", 0);
  return(0);
}
示例#7
0
int ex_open (const char  *path,
             int    mode,
             int   *comp_ws,
             int   *io_ws,
             float *version)
{
   int exoid;
   nclong file_wordsize;
   char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */
 
/* set error handling mode to no messages, non-fatal errors */
  ex_opts(exoptval);    /* call required to set ncopts first time through */


  if (mode == EX_READ)  /* READ ONLY */
  {
#if defined(__LIBCATAMOUNT__)
    if ((exoid = ncopen (path, NC_NOWRITE)) < 0)
#else
    if ((exoid = ncopen (path, NC_NOWRITE|NC_SHARE)) < 0)
#endif
    {
      /* NOTE: netCDF returns an id of -1 on an error - but no error code! */
      if (ncerr == 0)
        exerrval = EX_FATAL;
      else
        exerrval = ncerr;
      sprintf(errmsg,"Error: failed to open %s read only",path);
      ex_err("ex_open",errmsg,exerrval); 
      return(EX_FATAL);
    } 
  }

  else if (mode == EX_WRITE) /* READ/WRITE */
  {
#if defined(__LIBCATAMOUNT__)
    if ((exoid = ncopen (path, NC_WRITE)) < 0)
#else
    if ((exoid = ncopen (path, NC_WRITE|NC_SHARE)) < 0)
#endif
    {
      /* NOTE: netCDF returns an id of -1 on an error - but no error code! */
      if (ncerr == 0)
        exerrval = EX_FATAL;
      else
        exerrval = ncerr;
      sprintf(errmsg,"Error: failed to open %s write only",path);
      ex_err("ex_open",errmsg,exerrval); 
      return(EX_FATAL);
    } 

    /* turn off automatic filling of netCDF variables */

    if (ncsetfill (exoid, NC_NOFILL) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
             "Error: failed to set nofill mode in file id %d",
              exoid);
      ex_err("ex_open", errmsg, exerrval);
      return (EX_FATAL);
    }
  }
  else 
  {
    exerrval = EX_BADFILEMODE;
    sprintf(errmsg,"Error: invalid file open mode: %d",mode);
    ex_err("ex_open",errmsg,exerrval); 
    return (EX_FATAL);
  }

/* determine version of EXODUS II file, and the word size of
 * floating point values stored in the file
 */

   if (ncattget (exoid, NC_GLOBAL, ATT_VERSION, version) == -1)
   {
     exerrval  = ncerr;
     sprintf(errmsg,"Error: failed to get database version for file id: %d",
             exoid);
     ex_err("ex_open",errmsg,exerrval);
     return(EX_FATAL);
   }
   
/* check ExodusII file version - old version 1.x files are not supported */
   if (*version < 2.0)
   {
     exerrval  = EX_FATAL;
     sprintf(errmsg,"Error: Unsupported file version %.2f in file id: %d",
             *version, exoid);
     ex_err("ex_open",errmsg,exerrval);
     return(EX_FATAL);
   }
   
   if (ncattget (exoid, NC_GLOBAL, ATT_FLT_WORDSIZE, &file_wordsize) == -1)
   {  /* try old (prior to db version 2.02) attribute name */
     if (ncattget (exoid,NC_GLOBAL,ATT_FLT_WORDSIZE_BLANK,&file_wordsize) == -1)
     {
       exerrval  = EX_FATAL;
       sprintf(errmsg,"Error: failed to get file wordsize from file id: %d",
             exoid);
       ex_err("ex_open",errmsg,exerrval);
       return(exerrval);
     }
   }

/* initialize floating point size conversion.
 */

   if (ex_conv_ini( exoid, comp_ws, io_ws, file_wordsize ) != EX_NOERR ) {
     exerrval = EX_FATAL;
     sprintf(errmsg,
           "Error: failed to init conversion routines in file id %d",
            exoid);
     ex_err("ex_open", errmsg, exerrval);
     return (EX_FATAL);
   }

   return (exoid);
}
示例#8
0
int main(int argc, char **argv)
{
  int  exoid, num_dim, num_nodes, num_elem, num_elem_blk;
  int  exoid2, num_dim2, num_nodes2, num_elem2, num_elem_blk2;
  int  num_elem_in_block[10], num_node_sets, num_nodes_per_elem[10];
  int  num_elem_in_block2[10], num_node_sets2, num_nodes_per_elem2[10];
  int  num_side_sets, error;
  int  num_side_sets2;
  int  i, j, k, m;
  int *elem_map, *connect, node_list[100], elem_list[100], side_list[100];
  int *elem_map2, *connect2, node_list2[100], elem_list2[100], side_list2[100];
  int  ebids[10];
  int  ebids2[10];
  int  num_qa_rec, num_info;
  int  num_qa_rec2, num_info2;
  int  num_glo_vars, num_nod_vars, num_ele_vars;
  int  num_glo_vars2, num_nod_vars2, num_ele_vars2;
  int *truth_tab;
  int  whole_time_step, num_time_steps;
  int  CPU_word_size, IO_word_size;
  int  prop_array[2];

  float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
  float  time_value;
  float  time_value2;
  float  x[100], y[100], z[100];
  float  attrib[1], dist_fact[100];
  float  attrib2[1], dist_fact2[100];
  char * coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  char * coord_names2[3], *qa_record2[2][4], *info2[3], *var_names2[3];
  char * prop_names[2];

  ex_opts(EX_VERBOSE | EX_ABORT);

  /* Specify compute and i/o word size */

  CPU_word_size = 0; /* sizeof(float) */
  IO_word_size  = 4; /* (4 bytes) */

  /* create EXODUS II files (a "regular" and a "history") */

  exoid = ex_create("test.exo",     /* filename path */
                    EX_CLOBBER,     /* create mode */
                    &CPU_word_size, /* CPU float word size in bytes */
                    &IO_word_size); /* I/O float word size in bytes */
  printf("after ex_create for test.exo, exoid = %d\n", exoid);
  printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);

  exoid2 = ex_create("test2.exo",    /* filename path */
                     EX_CLOBBER,     /* create mode */
                     &CPU_word_size, /* CPU float word size in bytes */
                     &IO_word_size); /* I/O float word size in bytes */
  printf("after ex_create for test2.exo, exoid = %d\n", exoid2);

  /* initialize file with parameters */

  num_dim       = 3;
  num_nodes     = 26;
  num_elem      = 5;
  num_elem_blk  = 5;
  num_node_sets = 2;
  num_side_sets = 5;

  error = ex_put_init(exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk,
                      num_node_sets, num_side_sets);

  printf("after ex_put_init, error = %d\n", error);

  /* initialize file 2 with parameters */

  num_dim2       = 3;
  num_nodes2     = 26;
  num_elem2      = 5;
  num_elem_blk2  = 5;
  num_node_sets2 = 2;
  num_side_sets2 = 5;

  error = ex_put_init(exoid2, "This is test 2", num_dim2, num_nodes2, num_elem2, num_elem_blk2,
                      num_node_sets2, num_side_sets2);

  printf("after ex_put_init (2), error = %d\n", error);

  /* write nodal coordinates values and names to database */

  /* Quad #1 */
  x[0] = 0.0;
  y[0] = 0.0;
  z[0] = 0.0;
  x[1] = 1.0;
  y[1] = 0.0;
  z[1] = 0.0;
  x[2] = 1.0;
  y[2] = 1.0;
  z[2] = 0.0;
  x[3] = 0.0;
  y[3] = 1.0;
  z[3] = 0.0;

  /* Quad #2 */
  x[4] = 1.0;
  y[4] = 0.0;
  z[4] = 0.0;
  x[5] = 2.0;
  y[5] = 0.0;
  z[5] = 0.0;
  x[6] = 2.0;
  y[6] = 1.0;
  z[6] = 0.0;
  x[7] = 1.0;
  y[7] = 1.0;
  z[7] = 0.0;

  /* Hex #1 */
  x[8]  = 0.0;
  y[8]  = 0.0;
  z[8]  = 0.0;
  x[9]  = 10.0;
  y[9]  = 0.0;
  z[9]  = 0.0;
  x[10] = 10.0;
  y[10] = 0.0;
  z[10] = -10.0;
  x[11] = 1.0;
  y[11] = 0.0;
  z[11] = -10.0;
  x[12] = 1.0;
  y[12] = 10.0;
  z[12] = 0.0;
  x[13] = 10.0;
  y[13] = 10.0;
  z[13] = 0.0;
  x[14] = 10.0;
  y[14] = 10.0;
  z[14] = -10.0;
  x[15] = 1.0;
  y[15] = 10.0;
  z[15] = -10.0;

  /* Tetra #1 */
  x[16] = 0.0;
  y[16] = 0.0;
  z[16] = 0.0;
  x[17] = 1.0;
  y[17] = 0.0;
  z[17] = 5.0;
  x[18] = 10.0;
  y[18] = 0.0;
  z[18] = 2.0;
  x[19] = 7.0;
  y[19] = 5.0;
  z[19] = 3.0;

  /* Wedge #1 */
  x[20] = 3.0;
  y[20] = 0.0;
  z[20] = 6.0;
  x[21] = 6.0;
  y[21] = 0.0;
  z[21] = 0.0;
  x[22] = 0.0;
  y[22] = 0.0;
  z[22] = 0.0;
  x[23] = 3.0;
  y[23] = 2.0;
  z[23] = 6.0;
  x[24] = 6.0;
  y[24] = 2.0;
  z[24] = 2.0;
  x[25] = 0.0;
  y[25] = 2.0;
  z[25] = 0.0;

  error = ex_put_coord(exoid, x, y, z);
  printf("after ex_put_coord, error = %d\n", error);

  /* write nodal coordinates values and names to database 2 */

  error = ex_put_coord(exoid2, x, y, z);
  printf("after ex_put_coord (2), error = %d\n", error);

  coord_names[0] = "xcoor";
  coord_names[1] = "ycoor";
  coord_names[2] = "zcoor";

  error = ex_put_coord_names(exoid, coord_names);
  printf("after ex_put_coord_names, error = %d\n", error);

  coord_names2[0] = "xcoor";
  coord_names2[1] = "ycoor";
  coord_names2[2] = "zcoor";

  error = ex_put_coord_names(exoid2, coord_names2);
  printf("after ex_put_coord_names (2), error = %d\n", error);

  /* write element order map */

  elem_map = (int *)calloc(num_elem, sizeof(int));

  for (i = 1; i <= num_elem; i++) {
    elem_map[i - 1] = i;
  }

  error = ex_put_map(exoid, elem_map);
  printf("after ex_put_map, error = %d\n", error);

  free(elem_map);

  elem_map2 = (int *)calloc(num_elem2, sizeof(int));

  for (i = 1; i <= num_elem2; i++) {
    elem_map2[i - 1] = i;
  }

  error = ex_put_map(exoid2, elem_map2);
  printf("after ex_put_map (2), error = %d\n", error);

  free(elem_map2);

  /* write element block parameters */

  num_elem_in_block[0] = 1;
  num_elem_in_block[1] = 1;
  num_elem_in_block[2] = 1;
  num_elem_in_block[3] = 1;
  num_elem_in_block[4] = 1;

  num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */
  num_nodes_per_elem[4] = 6; /* elements in block #3 are 6-node wedges */

  ebids[0] = 10;
  ebids[1] = 11;
  ebids[2] = 12;
  ebids[3] = 13;
  ebids[4] = 14;

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "quad", num_elem_in_block[0],
                       num_nodes_per_elem[0], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[1], "quad", num_elem_in_block[1],
                       num_nodes_per_elem[1], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[2], "hex", num_elem_in_block[2],
                       num_nodes_per_elem[2], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[3], "tetra", num_elem_in_block[3],
                       num_nodes_per_elem[3], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[4], "wedge", num_elem_in_block[4],
                       num_nodes_per_elem[4], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  /* write element block properties */

  prop_names[0] = "MATL";
  prop_names[1] = "DENSITY";
  error         = ex_put_prop_names(exoid, EX_ELEM_BLOCK, 2, prop_names);
  printf("after ex_put_prop_names, error = %d\n", error);

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
  printf("after ex_put_prop, error = %d\n", error);

  num_elem_in_block2[0] = 1;
  num_elem_in_block2[1] = 1;
  num_elem_in_block2[2] = 1;
  num_elem_in_block2[3] = 1;
  num_elem_in_block2[4] = 1;

  num_nodes_per_elem2[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem2[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem2[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem2[3] = 4; /* elements in block #3 are 4-node tetras */
  num_nodes_per_elem2[4] = 6; /* elements in block #3 are 6-node wedges */

  ebids2[0] = 10;
  ebids2[1] = 11;
  ebids2[2] = 12;
  ebids2[3] = 13;
  ebids2[4] = 14;

  error = ex_put_block(exoid2, EX_ELEM_BLOCK, ebids2[0], "quad", num_elem_in_block2[0],
                       num_nodes_per_elem2[0], 0, 0, 1);
  printf("after ex_put_elem_block (2), error = %d\n", error);

  error = ex_put_block(exoid2, EX_ELEM_BLOCK, ebids2[1], "quad", num_elem_in_block2[1],
                       num_nodes_per_elem2[1], 0, 0, 1);
  printf("after ex_put_elem_blocki (2), error = %d\n", error);

  error = ex_put_block(exoid2, EX_ELEM_BLOCK, ebids2[2], "hex", num_elem_in_block2[2],
                       num_nodes_per_elem2[2], 0, 0, 1);
  printf("after ex_put_elem_blocki (2), error = %d\n", error);

  error = ex_put_block(exoid2, EX_ELEM_BLOCK, ebids2[3], "tetra", num_elem_in_block2[3],
                       num_nodes_per_elem2[3], 0, 0, 1);
  printf("after ex_put_elem_block (2), error = %d\n", error);

  error = ex_put_block(exoid2, EX_ELEM_BLOCK, ebids2[4], "wedge", num_elem_in_block2[4],
                       num_nodes_per_elem2[4], 0, 0, 1);
  printf("after ex_put_elem_block (2), error = %d\n", error);

  /* write element block properties for file 2 */

  prop_names[0] = "MATL";
  prop_names[1] = "DENSITY";
  error         = ex_put_prop_names(exoid2, EX_ELEM_BLOCK, 2, prop_names);
  printf("after ex_put_prop_names (2), error = %d\n", error);

  error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ebids[0], "MATL", 100);
  printf("after ex_put_prop (2), error = %d\n", error);
  error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ebids[1], "MATL", 200);
  printf("after ex_put_prop (2), error = %d\n", error);
  error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ebids[2], "MATL", 300);
  printf("after ex_put_prop (2), error = %d\n", error);
  error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ebids[3], "MATL", 400);
  printf("after ex_put_prop (2), error = %d\n", error);
  error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ebids[4], "MATL", 500);
  printf("after ex_put_prop (2), error = %d\n", error);

  /* write element connectivity */

  connect    = (int *)calloc(8, sizeof(int));
  connect[0] = 1;
  connect[1] = 2;
  connect[2] = 3;
  connect[3] = 4;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 5;
  connect[1] = 6;
  connect[2] = 7;
  connect[3] = 8;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[1], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 9;
  connect[1] = 10;
  connect[2] = 11;
  connect[3] = 12;
  connect[4] = 13;
  connect[5] = 14;
  connect[6] = 15;
  connect[7] = 16;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 17;
  connect[1] = 18;
  connect[2] = 19;
  connect[3] = 20;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[3], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 21;
  connect[1] = 22;
  connect[2] = 23;
  connect[3] = 24;
  connect[4] = 25;
  connect[5] = 26;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[4], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  free(connect);

  connect2    = (int *)calloc(8, sizeof(int));
  connect2[0] = 1;
  connect2[1] = 2;
  connect2[2] = 3;
  connect2[3] = 4;

  error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ebids2[0], connect2, NULL, NULL);
  printf("after ex_put_elem_conn (2), error = %d\n", error);

  connect2[0] = 5;
  connect2[1] = 6;
  connect2[2] = 7;
  connect2[3] = 8;

  error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ebids2[1], connect2, NULL, NULL);
  printf("after ex_put_elem_conn (2), error = %d\n", error);

  connect2[0] = 9;
  connect2[1] = 10;
  connect2[2] = 11;
  connect2[3] = 12;
  connect2[4] = 13;
  connect2[5] = 14;
  connect2[6] = 15;
  connect2[7] = 16;

  error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ebids2[2], connect2, NULL, NULL);
  printf("after ex_put_elem_conn (2), error = %d\n", error);

  connect2[0] = 17;
  connect2[1] = 18;
  connect2[2] = 19;
  connect2[3] = 20;

  error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ebids2[3], connect2, NULL, NULL);
  printf("after ex_put_elem_conn (2), error = %d\n", error);

  connect2[0] = 21;
  connect2[1] = 22;
  connect2[2] = 23;
  connect2[3] = 24;
  connect2[4] = 25;
  connect2[5] = 26;

  error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ebids2[4], connect2, NULL, NULL);
  printf("after ex_put_elem_conn (2), error = %d\n", error);

  free(connect2);

  /* write element block attributes */

  attrib[0] = 3.14159;
  error     = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  attrib[0] = 6.14159;
  error     = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[1], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[2], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[3], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[4], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  attrib2[0] = 3.;
  error      = ex_put_attr(exoid2, EX_ELEM_BLOCK, ebids2[0], attrib2);
  printf("after ex_put_elem_attr (2), error = %d\n", error);

  attrib2[0] = 6.;
  error      = ex_put_attr(exoid2, EX_ELEM_BLOCK, ebids2[1], attrib2);
  printf("after ex_put_elem_attr (2), error = %d\n", error);

  error = ex_put_attr(exoid2, EX_ELEM_BLOCK, ebids2[2], attrib2);
  printf("after ex_put_elem_attr (2), error = %d\n", error);

  error = ex_put_attr(exoid2, EX_ELEM_BLOCK, ebids2[3], attrib2);
  printf("after ex_put_elem_attr (2), error = %d\n", error);

  error = ex_put_attr(exoid2, EX_ELEM_BLOCK, ebids2[4], attrib2);
  printf("after ex_put_elem_attr (2), error = %d\n", error);

  /* write individual node sets */

  error = ex_put_set_param(exoid, EX_NODE_SET, 20, 5, 5);
  printf("after ex_put_node_set_param, error = %d\n", error);

  node_list[0] = 10;
  node_list[1] = 11;
  node_list[2] = 12;
  node_list[3] = 13;
  node_list[4] = 14;

  dist_fact[0] = 1.0;
  dist_fact[1] = 2.0;
  dist_fact[2] = 3.0;
  dist_fact[3] = 4.0;
  dist_fact[4] = 5.0;

  error = ex_put_set(exoid, EX_NODE_SET, 20, node_list, NULL);
  printf("after ex_put_node_set, error = %d\n", error);
  error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 20, dist_fact);
  printf("after ex_put_node_set, error = %d\n", error);

  error = ex_put_set_param(exoid, EX_NODE_SET, 21, 3, 3);
  printf("after ex_put_node_set_param, error = %d\n", error);

  node_list[0] = 20;
  node_list[1] = 21;
  node_list[2] = 22;

  dist_fact[0] = 1.1;
  dist_fact[1] = 2.1;
  dist_fact[2] = 3.1;

  error = ex_put_set(exoid, EX_NODE_SET, 21, node_list, NULL);
  printf("after ex_put_node_set, error = %d\n", error);
  error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 21, dist_fact);
  printf("after ex_put_node_set, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  printf("after ex_put_prop, error = %d\n", error);

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  printf("after ex_put_prop_array, error = %d\n", error);

  /* file 2 */
  error = ex_put_set_param(exoid2, EX_NODE_SET, 20, 5, 5);
  printf("after ex_put_node_set_param (2), error = %d\n", error);

  node_list2[0] = 10;
  node_list2[1] = 11;
  node_list2[2] = 12;
  node_list2[3] = 13;
  node_list2[4] = 14;

  dist_fact2[0] = 1.0;
  dist_fact2[1] = 2.0;
  dist_fact2[2] = 3.0;
  dist_fact2[3] = 4.0;
  dist_fact2[4] = 5.0;

  error = ex_put_set(exoid2, EX_NODE_SET, 20, node_list2, NULL);
  printf("after ex_put_node_set (2), error = %d\n", error);
  error = ex_put_set_dist_fact(exoid2, EX_NODE_SET, 20, dist_fact2);
  printf("after ex_put_node_set (2), error = %d\n", error);

  error = ex_put_set_param(exoid2, EX_NODE_SET, 21, 3, 3);
  printf("after ex_put_node_set_param (2), error = %d\n", error);

  node_list2[0] = 20;
  node_list2[1] = 21;
  node_list2[2] = 22;

  dist_fact2[0] = 1.1;
  dist_fact2[1] = 2.1;
  dist_fact2[2] = 3.1;

  error = ex_put_set(exoid2, EX_NODE_SET, 21, node_list2, NULL);
  printf("after ex_put_node_set (2), error = %d\n", error);
  error = ex_put_set_dist_fact(exoid2, EX_NODE_SET, 21, dist_fact2);
  printf("after ex_put_node_set (2), error = %d\n", error);

  error = ex_put_prop(exoid2, EX_NODE_SET, 20, "FACE", 4);
  printf("after ex_put_prop (2), error = %d\n", error);

  error = ex_put_prop(exoid2, EX_NODE_SET, 21, "FACE", 5);
  printf("after ex_put_prop (2), error = %d\n", error);

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid2, EX_NODE_SET, "VELOCITY", prop_array);
  printf("after ex_put_prop (2), error = %d\n", error);

  /* write individual side sets */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 30, 2, 4);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 2;
  elem_list[1] = 2;

  side_list[0] = 4;
  side_list[1] = 2;

  dist_fact[0] = 30.0;
  dist_fact[1] = 30.1;
  dist_fact[2] = 30.2;
  dist_fact[3] = 30.3;

  error = ex_put_set(exoid, EX_SIDE_SET, 30, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 30, dist_fact);
  printf("after ex_put_side_set_dist_fact, error = %d\n", error);

  error = ex_put_set_param(exoid, EX_SIDE_SET, 31, 2, 4);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 1;
  elem_list[1] = 2;

  side_list[0] = 2;
  side_list[1] = 3;

  dist_fact[0] = 31.0;
  dist_fact[1] = 31.1;
  dist_fact[2] = 31.2;
  dist_fact[3] = 31.3;

  error = ex_put_set(exoid, EX_SIDE_SET, 31, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 31, dist_fact);
  printf("after ex_put_side_set_dist_fact, error = %d\n", error);

  /* side set #3  - hex */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 32, 7, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 3;
  elem_list[1] = 3;
  elem_list[2] = 3;
  elem_list[3] = 3;
  elem_list[4] = 3;
  elem_list[5] = 3;
  elem_list[6] = 3;

  side_list[0] = 5;
  side_list[1] = 3;
  side_list[2] = 3;
  side_list[3] = 2;
  side_list[4] = 4;
  side_list[5] = 1;
  side_list[6] = 6;

  error = ex_put_set(exoid, EX_SIDE_SET, 32, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  /* side set #4  - tetras */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 33, 4, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 4;
  elem_list[1] = 4;
  elem_list[2] = 4;
  elem_list[3] = 4;

  side_list[0] = 1;
  side_list[1] = 2;
  side_list[2] = 3;
  side_list[3] = 4;

  error = ex_put_set(exoid, EX_SIDE_SET, 33, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  /* side set #5  - wedges */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 34, 5, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 5;
  elem_list[1] = 5;
  elem_list[2] = 5;
  elem_list[3] = 5;
  elem_list[4] = 5;

  side_list[0] = 1;
  side_list[1] = 2;
  side_list[2] = 3;
  side_list[3] = 4;
  side_list[4] = 5;

  error = ex_put_set(exoid, EX_SIDE_SET, 34, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  /* file 2 */
  error = ex_put_set_param(exoid2, EX_SIDE_SET, 30, 2, 4);
  printf("after ex_put_side_set_param (2), error = %d\n", error);

  elem_list2[0] = 2;
  elem_list2[1] = 2;

  side_list2[0] = 4;
  side_list2[1] = 2;

  dist_fact2[0] = 30.0;
  dist_fact2[1] = 30.1;
  dist_fact2[2] = 30.2;
  dist_fact2[3] = 30.3;

  error = ex_put_set(exoid2, EX_SIDE_SET, 30, elem_list2, side_list2);
  printf("after ex_put_side_set (2), error = %d\n", error);

  error = ex_put_set_dist_fact(exoid2, EX_SIDE_SET, 30, dist_fact2);
  printf("after ex_put_side_set_dist_fact (2), error = %d\n", error);

  error = ex_put_set_param(exoid2, EX_SIDE_SET, 31, 2, 4);
  printf("after ex_put_side_set_param (2), error = %d\n", error);

  elem_list2[0] = 1;
  elem_list2[1] = 2;

  side_list2[0] = 2;
  side_list2[1] = 3;

  dist_fact2[0] = 31.0;
  dist_fact2[1] = 31.1;
  dist_fact2[2] = 31.2;
  dist_fact2[3] = 31.3;

  error = ex_put_set(exoid2, EX_SIDE_SET, 31, elem_list2, side_list2);
  printf("after ex_put_side_set (2), error = %d\n", error);

  error = ex_put_set_dist_fact(exoid2, EX_SIDE_SET, 31, dist_fact2);
  printf("after ex_put_side_set_dist_fact (2), error = %d\n", error);

  /* side set #3  - hex */

  error = ex_put_set_param(exoid2, EX_SIDE_SET, 32, 7, 0);
  printf("after ex_put_side_set_param (2), error = %d\n", error);

  elem_list2[0] = 3;
  elem_list2[1] = 3;
  elem_list2[2] = 3;
  elem_list2[3] = 3;
  elem_list2[4] = 3;
  elem_list2[5] = 3;
  elem_list2[6] = 3;

  side_list2[0] = 5;
  side_list2[1] = 3;
  side_list2[2] = 3;
  side_list2[3] = 2;
  side_list2[4] = 4;
  side_list2[5] = 1;
  side_list2[6] = 6;

  error = ex_put_set(exoid2, EX_SIDE_SET, 32, elem_list2, side_list2);
  printf("after ex_put_side_set (2), error = %d\n", error);

  /* side set #4  - tetras */

  error = ex_put_set_param(exoid2, EX_SIDE_SET, 33, 4, 0);
  printf("after ex_put_side_set_param (2), error = %d\n", error);

  elem_list2[0] = 4;
  elem_list2[1] = 4;
  elem_list2[2] = 4;
  elem_list2[3] = 4;

  side_list2[0] = 1;
  side_list2[1] = 2;
  side_list2[2] = 3;
  side_list2[3] = 4;

  error = ex_put_set(exoid2, EX_SIDE_SET, 33, elem_list2, side_list2);
  printf("after ex_put_side_set (2), error = %d\n", error);

  /* side set #5  - wedges */

  error = ex_put_set_param(exoid2, EX_SIDE_SET, 34, 5, 0);
  printf("after ex_put_side_set_param (2), error = %d\n", error);

  elem_list2[0] = 5;
  elem_list2[1] = 5;
  elem_list2[2] = 5;
  elem_list2[3] = 5;
  elem_list2[4] = 5;

  side_list2[0] = 1;
  side_list2[1] = 2;
  side_list2[2] = 3;
  side_list2[3] = 4;
  side_list2[4] = 5;

  error = ex_put_set(exoid2, EX_SIDE_SET, 34, elem_list2, side_list2);
  printf("after ex_put_side_set (2), error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid2, EX_SIDE_SET, 30, "COLOR", 100);
  printf("after ex_put_prop (2), error = %d\n", error);

  error = ex_put_prop(exoid2, EX_SIDE_SET, 31, "COLOR", 101);
  printf("after ex_put_prop (2), error = %d\n", error);

  /* write QA records */

  num_qa_rec = 2;

  qa_record[0][0] = "TESTWT2";
  qa_record[0][1] = "testwt2";
  qa_record[0][2] = "07/07/93";
  qa_record[0][3] = "15:41:33";
  qa_record[1][0] = "FASTQ";
  qa_record[1][1] = "fastq";
  qa_record[1][2] = "07/07/93";
  qa_record[1][3] = "16:41:33";

  error = ex_put_qa(exoid, num_qa_rec, qa_record);
  printf("after ex_put_qa, error = %d\n", error);

  num_qa_rec2 = 2;

  qa_record2[0][0] = "TESTWT2";
  qa_record2[0][1] = "testwt2";
  qa_record2[0][2] = "07/07/93";
  qa_record2[0][3] = "15:41:33";
  qa_record2[1][0] = "FASTQ";
  qa_record2[1][1] = "fastq";
  qa_record2[1][2] = "07/07/93";
  qa_record2[1][3] = "16:41:33";

  error = ex_put_qa(exoid2, num_qa_rec2, qa_record2);
  printf("after ex_put_qa (2), error = %d\n", error);

  /* write information records */

  num_info = 3;

  info[0] = "This is the first information record.";
  info[1] = "This is the second information record.";
  info[2] = "This is the third information record.";

  error = ex_put_info(exoid, num_info, info);
  printf("after ex_put_info, error = %d\n", error);

  num_info2 = 3;

  info2[0] = "This is the first information record.";
  info2[1] = "This is the second information record.";
  info2[2] = "This is the third information record.";

  error = ex_put_info(exoid2, num_info2, info2);
  printf("after ex_put_info (2), error = %d\n", error);

  /* write results variables parameters and names */

  num_glo_vars = 1;

  var_names[0] = "glo_vars";

  error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_glo_vars2 = 1;

  var_names2[0] = "glo_vars";

  error = ex_put_variable_param(exoid2, EX_GLOBAL, num_glo_vars2);
  printf("after ex_put_variable_param (2), error = %d\n", error);
  error = ex_put_variable_names(exoid2, EX_GLOBAL, num_glo_vars2, var_names2);
  printf("after ex_put_variable_names (2), error = %d\n", error);

  num_nod_vars = 2;

  var_names[0] = "nod_var0";
  var_names[1] = "nod_var1";

  error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_nod_vars2 = 2;

  var_names2[0] = "nod_var0";
  var_names2[1] = "nod_var1";

  error = ex_put_variable_param(exoid2, EX_NODAL, num_nod_vars2);
  printf("after ex_put_variable_param (2), error = %d\n", error);
  error = ex_put_variable_names(exoid2, EX_NODAL, num_nod_vars2, var_names2);
  printf("after ex_put_variable_names (2), error = %d\n", error);

  num_ele_vars = 3;

  var_names[0] = "ele_var0";
  var_names[1] = "ele_var1";
  var_names[2] = "ele_var2";

  error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_ele_vars2 = 3;

  var_names2[0] = "ele_var20";
  var_names2[1] = "ele_var21";
  var_names2[2] = "ele_var22";

  error = ex_put_variable_param(exoid2, EX_ELEM_BLOCK, num_ele_vars2);
  printf("after ex_put_variable_param (2), error = %d\n", error);
  error = ex_put_variable_names(exoid2, EX_ELEM_BLOCK, num_ele_vars, var_names);
  printf("after ex_put_variable_names (2), error = %d\n", error);

  /* write element variable truth table */

  truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int));

  k = 0;
  for (i = 0; i < num_elem_blk; i++) {
    for (j = 0; j < num_ele_vars; j++) {
      truth_tab[k++] = 1;
    }
  }

  error = ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab);
  printf("after ex_put_elem_var_tab, error = %d\n", error);

  error = ex_put_truth_table(exoid2, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab);
  printf("after ex_put_elem_var_tab (2), error = %d\n", error);

  free(truth_tab);

  /* for each time step, write the analysis results;
   * the code below fills the arrays hist_var_vals, glob_var_vals,
   * nodal_var_vals, and elem_var_vals with values for debugging purposes;
   * obviously the analysis code will populate these arrays
   */

  whole_time_step = 1;
  num_time_steps  = 10;

  glob_var_vals  = (float *)calloc(num_glo_vars, sizeof(CPU_word_size));
  nodal_var_vals = (float *)calloc(num_nodes, sizeof(CPU_word_size));
  elem_var_vals  = (float *)calloc(4, sizeof(CPU_word_size));

  for (i = 0; i < num_time_steps; i++) {
    time_value  = (float)(i + 1) / 100.;
    time_value2 = (float)(i + 1) / 100.;

    /* write time value to regular file */

    error = ex_put_time(exoid, whole_time_step, &time_value);
    printf("after ex_put_time, error = %d\n", error);

    error = ex_put_time(exoid2, whole_time_step, &time_value2);
    printf("after ex_put_time (2), error = %d\n", error);

    /* write global variables */

    for (j = 0; j < num_glo_vars; j++) {
      glob_var_vals[j] = (float)(j + 2) * time_value;
    }

    error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
    printf("after ex_put_glob_vars, error = %d\n", error);

    error = ex_put_var(exoid2, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
    printf("after ex_put_glob_vars (2), error = %d\n", error);

    /* write nodal variables */

    for (k = 1; k <= num_nod_vars; k++) {
      for (j = 0; j < num_nodes; j++) {
        nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
      }

      error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
      printf("after ex_put_nodal_var, error = %d\n", error);

      error = ex_put_var(exoid2, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
      printf("after ex_put_nodal_var (2), error = %d\n", error);
    }

    /* write element variables */

    for (k = 1; k <= num_ele_vars; k++) {
      for (j = 0; j < num_elem_blk; j++) {
        for (m = 0; m < num_elem_in_block[j]; m++) {
          elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
          /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
        }
        error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j],
                           elem_var_vals);
        printf("after ex_put_elem_var, error = %d\n", error);

        error = ex_put_var(exoid2, whole_time_step, EX_ELEM_BLOCK, k, ebids[j],
                           num_elem_in_block[j], elem_var_vals);
        printf("after ex_put_elem_var (2), error = %d\n", error);
      }
    }

    whole_time_step++;

    /* update the data file; this should be done at the end of every time step
     * to ensure that no data is lost if the analysis dies
     */
    error = ex_update(exoid);
    printf("after ex_update, error = %d\n", error);
    error = ex_update(exoid2);
    printf("after ex_update (2), error = %d\n", error);
  }
  free(glob_var_vals);
  free(nodal_var_vals);
  free(elem_var_vals);

  /* close the EXODUS files
   */
  error = ex_close(exoid);
  printf("after ex_close, error = %d\n", error);
  error = ex_close(exoid2);
  printf("after ex_close (2), error = %d\n", error);
  return 0;
}
示例#9
0
int main(int argc, char **argv)
{
  int  exoid, exoid2, num_dim, num_nodes, num_elem, num_elem_blk;
  int  num_elem_in_block, num_node_sets, num_nodes_per_elem, num_attr;
  int  num_side_sets, error;
  int  i, j;
  int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list;
  int *ids;
  int  num_nodes_in_set, num_elem_in_set;
  int  num_sides_in_set, num_df_in_set;
  int  num_qa_rec, num_info;
  int  CPU_word_size, IO_word_size;
  int  num_props, prop_value, *prop_values;

  float *x, *y, *z;
  float *dist_fact;
  float  version, fdum;
  float attrib[1];

  char *coord_names[3], *qa_record[2][4], *info[3];
  char  title[MAX_LINE_LENGTH + 1], elem_type[MAX_STR_LENGTH + 1];
  char *prop_names[3];
  char *cdum = 0;

  /* Specify compute and i/o word size */

  CPU_word_size = 0; /* sizeof(float) */
  IO_word_size  = 4; /* float */

  /* open EXODUS II file for reading */

  ex_opts(EX_VERBOSE | EX_ABORT);

  exoid = ex_open("test.exo",     /* filename path */
                  EX_READ,        /* access mode */
                  &CPU_word_size, /* CPU float word size in bytes */
                  &IO_word_size,  /* I/O float word size in bytes */
                  &version);      /* returned version number */
  printf("after ex_open for test.exo\n");
  printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);

  /* create EXODUS II file for writing */

  exoid2 = ex_create("test2.exo",    /* filename path */
                     EX_CLOBBER,     /* create mode */
                     &CPU_word_size, /* CPU float word size in bytes */
                     &IO_word_size); /* I/O float word size in bytes */
  printf("after ex_create for test2.exo, exoid = %d\n", exoid2);

  /* read initialization parameters */

  error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets,
                      &num_side_sets);

  printf("after ex_get_init, error = %d\n", error);

  /* write initialization parameters */

  error = ex_put_init(exoid2, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets,
                      num_side_sets);

  printf("after ex_put_init, error = %d\n", error);

  /* read nodal coordinate values */

  x = (float *)calloc(num_nodes, sizeof(float));
  y = (float *)calloc(num_nodes, sizeof(float));
  if (num_dim >= 3)
    z = (float *)calloc(num_nodes, sizeof(float));
  else
    z = 0;

  error = ex_get_coord(exoid, x, y, z);
  printf("\nafter ex_get_coord, error = %3d\n", error);

  /* write nodal coordinate values */

  error = ex_put_coord(exoid2, x, y, z);
  printf("after ex_put_coord, error = %d\n", error);

  free(x);
  free(y);
  if (num_dim >= 3)
    free(z);

  /* read nodal coordinate names */

  for (i = 0; i < num_dim; i++) {
    coord_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }

  error = ex_get_coord_names(exoid, coord_names);
  printf("\nafter ex_get_coord_names, error = %3d\n", error);

  /* write nodal coordinate names */

  error = ex_put_coord_names(exoid2, coord_names);
  printf("after ex_put_coord_names, error = %d\n", error);

  for (i = 0; i < num_dim; i++) {
    free(coord_names[i]);
  }

  /* read element order map */

  elem_map = (int *)calloc(num_elem, sizeof(int));

  error = ex_get_map(exoid, elem_map);
  printf("\nafter ex_get_map, error = %3d\n", error);

  /* write element order map */

  error = ex_put_map(exoid2, elem_map);
  printf("after ex_put_map, error = %d\n", error);

  free(elem_map);

  /* read and write element block parameters and element connectivity */

  ids   = (int *)calloc(num_elem_blk, sizeof(int));
  error = ex_get_elem_blk_ids(exoid, ids);
  printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error);

  attrib[0] = 3.14159;
  for (i = 0; i < num_elem_blk; i++) {
    error = ex_get_elem_block(exoid, ids[i], elem_type, &num_elem_in_block, &num_nodes_per_elem,
                              &num_attr);
    printf("\nafter ex_get_elem_block, error = %d\n", error);

    error = ex_put_elem_block(exoid2, ids[i], elem_type, num_elem_in_block, num_nodes_per_elem,
                              num_attr);
    printf("after ex_put_elem_block, error = %d\n", error);

    connect = (int *)calloc((num_nodes_per_elem * num_elem_in_block), sizeof(int));

    error = ex_get_elem_conn(exoid, ids[i], connect);
    printf("\nafter ex_get_elem_conn, error = %d\n", error);

    error = ex_put_elem_conn(exoid2, ids[i], connect);
    printf("after ex_put_elem_conn, error = %d\n", error);

    /* write element block attributes */
    error = ex_put_attr(exoid2, EX_ELEM_BLOCK, ids[i], attrib);
    printf("after ex_put_elem_attr, error = %d\n", error);

    free(connect);
  }

  /* read and write element block properties */

  error = ex_inquire(exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum);
  printf("\nafter ex_inquire, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }

  error = ex_get_prop_names(exoid, EX_ELEM_BLOCK, prop_names);
  printf("after ex_get_prop_names, error = %d\n", error);

  error = ex_put_prop_names(exoid2, EX_ELEM_BLOCK, num_props, prop_names);
  printf("after ex_put_prop_names, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    for (j = 0; j < num_elem_blk; j++) {
      error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i], &prop_value);
      printf("after ex_get_prop, error = %d\n", error);

      if (i > 0) { /* first property is the ID which is already stored */
        error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ids[j], prop_names[i], prop_value);
        printf("after ex_put_prop, error = %d\n", error);
      }
    }
  }

  for (i = 0; i < num_props; i++)
    free(prop_names[i]);

  free(ids);

  /* read and write individual node sets */

  ids = (int *)calloc(num_node_sets, sizeof(int));

  error = ex_get_node_set_ids(exoid, ids);
  printf("\nafter ex_get_node_set_ids, error = %3d\n", error);

  for (i = 0; i < num_node_sets; i++) {
    error = ex_get_node_set_param(exoid, ids[i], &num_nodes_in_set, &num_df_in_set);
    printf("\nafter ex_get_node_set_param, error = %3d\n", error);

    error = ex_put_node_set_param(exoid2, ids[i], num_nodes_in_set, num_df_in_set);
    printf("after ex_put_node_set_param, error = %d\n", error);

    node_list = (int *)calloc(num_nodes_in_set, sizeof(int));
    dist_fact = (float *)calloc(num_nodes_in_set, sizeof(float));

    error = ex_get_node_set(exoid, ids[i], node_list);
    printf("\nafter ex_get_node_set, error = %3d\n", error);

    error = ex_put_node_set(exoid2, ids[i], node_list);
    printf("after ex_put_node_set, error = %d\n", error);

    if (num_df_in_set > 0) {
      error = ex_get_node_set_dist_fact(exoid, ids[i], dist_fact);
      printf("\nafter ex_get_node_set_dist_fact, error = %3d\n", error);

      error = ex_put_node_set_dist_fact(exoid2, ids[i], dist_fact);
      printf("after ex_put_node_set, error = %d\n", error);
    }

    free(node_list);
    free(dist_fact);
  }
  free(ids);

  /* read node set properties */
  error = ex_inquire(exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum);
  printf("\nafter ex_inquire, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }
  prop_values = (int *)calloc(num_node_sets, sizeof(int));

  error = ex_get_prop_names(exoid, EX_NODE_SET, prop_names);
  printf("after ex_get_prop_names, error = %d\n", error);

  error = ex_put_prop_names(exoid2, EX_NODE_SET, num_props, prop_names);
  printf("after ex_put_prop_names, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i], prop_values);
    printf("after ex_get_prop_array, error = %d\n", error);

    error = ex_put_prop_array(exoid2, EX_NODE_SET, prop_names[i], prop_values);
    printf("after ex_put_prop_array, error = %d\n", error);
  }
  for (i = 0; i < num_props; i++)
    free(prop_names[i]);
  free(prop_values);

  /* read and write individual side sets */

  ids = (int *)calloc(num_side_sets, sizeof(int));

  error = ex_get_side_set_ids(exoid, ids);
  printf("\nafter ex_get_side_set_ids, error = %3d\n", error);

  for (i = 0; i < num_side_sets; i++) {
    error = ex_get_side_set_param(exoid, ids[i], &num_sides_in_set, &num_df_in_set);
    printf("\nafter ex_get_side_set_param, error = %3d\n", error);

    error = ex_put_side_set_param(exoid2, ids[i], num_sides_in_set, num_df_in_set);
    printf("after ex_put_side_set_param, error = %d\n", error);

    /* Note: The # of elements is same as # of sides!  */
    num_elem_in_set = num_sides_in_set;
    elem_list       = (int *)calloc(num_elem_in_set, sizeof(int));
    side_list       = (int *)calloc(num_sides_in_set, sizeof(int));
    node_ctr_list   = (int *)calloc(num_elem_in_set, sizeof(int));
    node_list       = (int *)calloc(num_elem_in_set * 21, sizeof(int));
    dist_fact       = (float *)calloc(num_df_in_set, sizeof(float));

    error = ex_get_side_set(exoid, ids[i], elem_list, side_list);
    printf("\nafter ex_get_side_set, error = %3d\n", error);

    error = ex_put_side_set(exoid2, ids[i], elem_list, side_list);
    printf("after ex_put_side_set, error = %d\n", error);

    error = ex_get_side_set_node_list(exoid, ids[i], node_ctr_list, node_list);
    printf("\nafter ex_get_side_set_node_list, error = %3d\n", error);

    if (num_df_in_set > 0) {
      error = ex_get_side_set_dist_fact(exoid, ids[i], dist_fact);
      printf("\nafter ex_get_side_set_dist_fact, error = %3d\n", error);

      error = ex_put_side_set_dist_fact(exoid2, ids[i], dist_fact);
      printf("after ex_put_side_set_dist_fact, error = %d\n", error);
    }

    free(elem_list);
    free(side_list);
    free(node_ctr_list);
    free(node_list);
    free(dist_fact);
  }

  /* read side set properties */
  error = ex_inquire(exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum);
  printf("\nafter ex_inquire, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }

  error = ex_get_prop_names(exoid, EX_SIDE_SET, prop_names);
  printf("after ex_get_prop_names, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    for (j = 0; j < num_side_sets; j++) {
      error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i], &prop_value);
      printf("after ex_get_prop, error = %d\n", error);

      if (i > 0) { /* first property is ID so it is already stored */
        error = ex_put_prop(exoid2, EX_SIDE_SET, ids[j], prop_names[i], prop_value);
        printf("after ex_put_prop, error = %d\n", error);
      }
    }
  }
  for (i = 0; i < num_props; i++)
    free(prop_names[i]);
  free(ids);

  /* read and write QA records */

  ex_inquire(exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum);

  for (i = 0; i < num_qa_rec; i++) {
    for (j = 0; j < 4; j++) {
      qa_record[i][j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }
  }

  error = ex_get_qa(exoid, qa_record);
  printf("\nafter ex_get_qa, error = %3d\n", error);

  error = ex_put_qa(exoid2, num_qa_rec, qa_record);
  printf("after ex_put_qa, error = %d\n", error);

  for (i = 0; i < num_qa_rec; i++) {
    for (j = 0; j < 4; j++) {
      free(qa_record[i][j]);
    }
  }
  /* read and write information records */

  error = ex_inquire(exoid, EX_INQ_INFO, &num_info, &fdum, cdum);
  printf("\nafter ex_inquire, error = %3d\n", error);

  for (i = 0; i < num_info; i++) {
    info[i] = (char *)calloc((MAX_LINE_LENGTH + 1), sizeof(char));
  }

  error = ex_get_info(exoid, info);
  printf("\nafter ex_get_info, error = %3d\n", error);

  error = ex_put_info(exoid2, num_info, info);
  printf("after ex_put_info, error = %d\n", error);

  for (i = 0; i < num_info; i++) {
    free(info[i]);
  }

  /* close the EXODUS files */

  error = ex_close(exoid);
  printf("after ex_close, error = %d\n", error);
  error = ex_close(exoid2);
  printf("after ex_close (2), error = %d\n", error);
  return 0;
}
示例#10
0
文件: excre.c 项目: hpcdev/xdm
int ex_create_int (const char *path,
		   int   cmode,
		   int  *comp_ws,
		   int  *io_ws,
		   int   run_version)
{
  int exoid, time_dim, dims[1];
  int status;
  int dimid;
  int old_fill;
  int lio_ws;
  int filesiz;
  float vers;
  char errmsg[MAX_ERR_LENGTH];
  char *mode_name;
  int mode = 0;
#if defined(NC_NETCDF4)
  static int netcdf4_mode = -1;
  char *option;
#endif /* NC_NETCDF4 */
   
  exerrval = 0; /* clear error code */

  if (run_version != EX_API_VERS_NODOT) {
    int run_version_major = run_version / 100;
    int run_version_minor = run_version % 100;
    int lib_version_major = EX_API_VERS_NODOT / 100;
    int lib_version_minor = EX_API_VERS_NODOT % 100;
    fprintf(stderr, "EXODUSII: Warning: This code was compiled with exodusII version %d.%02d,\n          but was linked with exodusII library version %d.%02d\n          This is probably an error in the build process of this code.\n",
	    run_version_major, run_version_minor, lib_version_major, lib_version_minor);
  }
#if defined(NC_NETCDF4)
  if (cmode & EX_NETCDF4) {
    mode |= (NC_NETCDF4|NC_CLASSIC_MODEL);
  } else {
    if (netcdf4_mode == -1) {
      option = getenv("EXODUS_NETCDF4");
      if (option != NULL) {
	fprintf(stderr, "EXODUSII: Using netcdf version 4 selected via EXODUS_NETCDF4 environment variable\n");
	netcdf4_mode = NC_NETCDF4|NC_CLASSIC_MODEL;
      } else {
	netcdf4_mode = 0;
      }
    }
    mode |= netcdf4_mode;
  }
#endif

  /*
   * See if "large file" mode was specified in a ex_create cmode. If
   * so, then pass the NC_64BIT_OFFSET flag down to netcdf.
   * If netcdf4 mode specified, don't use NC_64BIT_OFFSET mode.
   */
  if ( (cmode & EX_LARGE_MODEL) && (cmode & EX_NORMAL_MODEL)) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg,
	    "Warning: conflicting mode specification for file %s, mode %d. Using normal",
	    path, cmode);
    ex_err("ex_create",errmsg,exerrval);
  }
  if ((cmode & EX_NORMAL_MODEL) != 0)
    filesiz = 0;
#if defined(NC_NETCDF4)
  else if ((mode & NC_NETCDF4) != 0)
    filesiz = 1;
#endif
  else 
    filesiz = (int)(((cmode & EX_LARGE_MODEL) != 0) || (ex_large_model(-1) == 1));

  if (
#if defined(NC_NETCDF4)
      !(mode & NC_NETCDF4) &&
#endif
      filesiz == 1) {
    mode |= NC_64BIT_OFFSET;
  }

  if (cmode & EX_SHARE) {
    mode |= NC_SHARE;
  }

  /*
   * set error handling mode to no messages, non-fatal errors
   */
  ex_opts(exoptval);    /* call required to set ncopts first time through */

  if (cmode & EX_CLOBBER) {
    mode |= NC_CLOBBER;
    mode_name = "CLOBBER";
  } else {
    mode |= NC_NOCLOBBER;
    mode_name = "NOCLOBBER";
  }

  if ((status = nc_create (path, mode, &exoid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: file create failed for %s, mode: %s",
	    path, mode_name);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* turn off automatic filling of netCDF variables
   */

  if ((status = nc_set_fill (exoid, NC_NOFILL, &old_fill)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to set nofill mode in file id %d",
	    exoid);
    ex_err("ex_create", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* initialize floating point size conversion.  since creating new file, 
   * i/o wordsize attribute from file is zero.
   */

  if (ex_conv_ini( exoid, comp_ws, io_ws, 0 ) != EX_NOERR) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: failed to init conversion routines in file id %d",
            exoid);
    ex_err("ex_create", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* put the EXODUS version number, and i/o floating point word size as
   * netcdf global attributes
   */

  /* store Exodus API version # as an attribute */
  vers = EX_API_VERS;
  if ((status=nc_put_att_float(exoid, NC_GLOBAL, ATT_API_VERSION,
			       NC_FLOAT, 1, &vers)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store Exodus II API version attribute in file id %d",
	    exoid);
    ex_err("ex_create",errmsg, exerrval);
    return (EX_FATAL);
  }
   
  /* store Exodus file version # as an attribute */
  vers = EX_VERS;
  if ((status=nc_put_att_float(exoid, NC_GLOBAL, ATT_VERSION, NC_FLOAT, 1, &vers)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store Exodus II file version attribute in file id %d",
	    exoid);
    ex_err("ex_create",errmsg, exerrval);
    return (EX_FATAL);
  }

  /* store Exodus file float word size  as an attribute */
  lio_ws = (int)(*io_ws);
  if ((status=nc_put_att_int (exoid, NC_GLOBAL, ATT_FLT_WORDSIZE, NC_INT, 1, &lio_ws)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store Exodus II file float word size attribute in file id %d",
	    exoid);
    ex_err("ex_create",errmsg, exerrval);
    return (EX_FATAL);
  }

  /* store Exodus file size (1=large, 0=normal) as an attribute */
  if ((status = nc_put_att_int (exoid, NC_GLOBAL, ATT_FILESIZE, NC_INT, 1, &filesiz)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store Exodus II file size attribute in file id %d",
	    exoid);
    ex_err("ex_create",errmsg, exerrval);
    return (EX_FATAL);
  }
  
  /* define some dimensions and variables
   */
  
  /* create string length dimension */
  if ((status=nc_def_dim (exoid, DIM_STR, (MAX_STR_LENGTH+1), &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to define string length in file id %d",exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }


  /* create line length dimension */
  if ((status = nc_def_dim(exoid, DIM_LIN, (MAX_LINE_LENGTH+1), &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to define line length in file id %d",exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* create number "4" dimension; must be of type long */
  if ((status = nc_def_dim(exoid, DIM_N4, 4L, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to define number \"4\" dimension in file id %d",exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }


  if ((status = nc_def_dim(exoid, DIM_TIME, NC_UNLIMITED, &time_dim)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to define time dimension in file id %d", exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }

  dims[0] = time_dim;
  if ((status = nc_def_var(exoid, VAR_WHOLE_TIME, nc_flt_code(exoid), 1, dims, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to define whole time step variable in file id %d",
	    exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_enddef (exoid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d", exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }

  return (exoid);
}
示例#11
0
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_node_sets, num_side_sets, error;
   int i, j;
   int  num_qa_rec, num_info;
   int num_glo_vars;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;

   float *glob_var_vals;
   float time_value;
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];

   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("test.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   /* ncopts = NC_VERBOSE; */

/* initialize file with parameters */

   num_dim = 1;
   num_nodes = 0;
   num_elem = 0;
   num_elem_blk = 0;
   num_node_sets = 0;
   num_side_sets = 0;

   error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem,
                        num_elem_blk, num_node_sets, num_side_sets);

   printf ("after ex_put_init, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   coord_names[0] = "xcoor";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write QA records; test empty and just blank-filled records */

   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write information records; test empty and just blank-filled records */

   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }



/* write results variables parameters and names */

   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   error = ex_put_var_param (exoid, "g", num_glo_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }



/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 * obviously the analysis code will populate these arrays
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);

   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

/* write time value */

     error = ex_put_time (exoid, whole_time_step, &time_value);
     printf ("after ex_put_time, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

/* write global variables */

     for (j=0; j<num_glo_vars; j++)
     {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
                               glob_var_vals);
     printf ("after ex_put_glob_vars, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

     whole_time_step++;

/* update the data file; this should be done at the end of every time step
 * to ensure that no data is lost if the analysis dies
 */
     error = ex_update (exoid);
     printf ("after ex_update, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   free(glob_var_vals);


/* close the EXODUS files
 */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   return 0;
}
示例#12
0
文件: testrd.c 项目: agrippa/Trilinos
int main(int argc, char **argv)
{
  int  exoid, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets;
  int  num_side_sets, error;
  int  i, j, k, node_ctr;
  int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list;
  int *ids;
  int *num_nodes_per_set = NULL;
  int *num_elem_per_set  = NULL;
  int *num_df_per_set    = NULL;
  int *node_ind          = NULL;
  int *elem_ind          = NULL;
  int *df_ind            = NULL;
  int  num_qa_rec, num_info;
  int  num_glo_vars, num_nod_vars, num_ele_vars;
  int  num_nset_vars, num_sset_vars;
  int *truth_tab;
  int  num_time_steps;
  int *num_elem_in_block  = NULL;
  int *num_nodes_per_elem = NULL;
  int *num_attr           = NULL;
  int  num_nodes_in_set, num_elem_in_set;
  int  num_sides_in_set, num_df_in_set;
  int  list_len, elem_list_len, node_list_len, df_list_len;
  int  node_num, time_step, var_index, beg_time, end_time, elem_num;
  int  CPU_word_size, IO_word_size;
  int  num_props, prop_value, *prop_values;
  int  idum;

  float  time_value, *time_values, *var_values;
  float *x, *y, *z;
  float *attrib, *dist_fact;
  float  version, fdum;

  char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  char *block_names[10], *nset_names[10], *sset_names[10];
  char *attrib_names[10];
  char  name[MAX_STR_LENGTH + 1];
  char  title[MAX_LINE_LENGTH + 1], elem_type[MAX_STR_LENGTH + 1];
  char  title_chk[MAX_LINE_LENGTH + 1];
  char *cdum = 0;
  char *prop_names[3];

  CPU_word_size = 0; /* sizeof(float) */
  IO_word_size  = 0; /* use what is stored in file */

  ex_opts(EX_VERBOSE | EX_ABORT);

  /* open EXODUS II files */
  exoid = ex_open("test.exo",     /* filename path */
                  EX_READ,        /* access mode = READ */
                  &CPU_word_size, /* CPU word size */
                  &IO_word_size,  /* IO word size */
                  &version);      /* ExodusII library version */

  printf("\nafter ex_open\n");
  if (exoid < 0)
    exit(1);

  printf("test.exo is an EXODUSII file; version %4.2f\n", version);
  /*   printf ("         CPU word size %1d\n",CPU_word_size);  */
  printf("         I/O word size %1d\n", IO_word_size);
  ex_inquire(exoid, EX_INQ_API_VERS, &idum, &version, cdum);
  printf("EXODUSII API; version %4.2f\n", version);

  ex_inquire(exoid, EX_INQ_LIB_VERS, &idum, &version, cdum);
  printf("EXODUSII Library API; version %4.2f (%d)\n", version, idum);

  /* read database parameters */

  error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets,
                      &num_side_sets);

  printf("after ex_get_init, error = %3d\n", error);

  printf("database parameters:\n");
  printf("title =  '%s'\n", title);
  printf("num_dim = %3d\n", num_dim);
  printf("num_nodes = %3d\n", num_nodes);
  printf("num_elem = %3d\n", num_elem);
  printf("num_elem_blk = %3d\n", num_elem_blk);
  printf("num_node_sets = %3d\n", num_node_sets);
  printf("num_side_sets = %3d\n", num_side_sets);

  /* Check that ex_inquire gives same title */
  error = ex_inquire(exoid, EX_INQ_TITLE, &idum, &fdum, title_chk);
  printf(" after ex_inquire, error = %d\n", error);
  if (strcmp(title, title_chk) != 0) {
    printf("error in ex_inquire for EX_INQ_TITLE\n");
  }

  /* read nodal coordinates values and names from database */

  x = (float *)calloc(num_nodes, sizeof(float));
  if (num_dim >= 2)
    y = (float *)calloc(num_nodes, sizeof(float));
  else
    y = 0;

  if (num_dim >= 3)
    z = (float *)calloc(num_nodes, sizeof(float));
  else
    z = 0;

  error = ex_get_coord(exoid, x, y, z);
  printf("\nafter ex_get_coord, error = %3d\n", error);

  printf("x coords = \n");
  for (i = 0; i < num_nodes; i++) {
    printf("%5.1f\n", x[i]);
  }

  if (num_dim >= 2) {
    printf("y coords = \n");
    for (i = 0; i < num_nodes; i++) {
      printf("%5.1f\n", y[i]);
    }
  }
  if (num_dim >= 3) {
    printf("z coords = \n");
    for (i = 0; i < num_nodes; i++) {
      printf("%5.1f\n", z[i]);
    }
  }

  /*
    error = ex_get_1_coord (exoid, 2, x, y, z);
    printf ("\nafter ex_get_1_coord, error = %3d\n", error);

    printf ("x coord of node 2 = \n");
    printf ("%f \n", x[0]);

    printf ("y coord of node 2 = \n");
    printf ("%f \n", y[0]);
  */
  free(x);
  if (num_dim >= 2)
    free(y);
  if (num_dim >= 3)
    free(z);

  for (i = 0; i < num_dim; i++) {
    coord_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }

  error = ex_get_coord_names(exoid, coord_names);
  printf("\nafter ex_get_coord_names, error = %3d\n", error);
  printf("x coord name = '%s'\n", coord_names[0]);
  if (num_dim > 1)
    printf("y coord name = '%s'\n", coord_names[1]);
  if (num_dim > 2)
    printf("z coord name = '%s'\n", coord_names[2]);

  for (i = 0; i < num_dim; i++)
    free(coord_names[i]);

  {
    int num_attrs = 0;
    error         = ex_get_attr_param(exoid, EX_NODAL, 0, &num_attrs);
    printf(" after ex_get_attr_param, error = %d\n", error);
    printf("num nodal attributes = %d\n", num_attrs);
    if (num_attrs > 0) {
      for (j = 0; j < num_attrs; j++) {
        attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
      }
      error = ex_get_attr_names(exoid, EX_NODAL, 0, attrib_names);
      printf(" after ex_get_attr_names, error = %d\n", error);

      if (error == 0) {
        attrib = (float *)calloc(num_nodes, sizeof(float));
        for (j = 0; j < num_attrs; j++) {
          printf("nodal attribute %d = '%s'\n", j, attrib_names[j]);
          error = ex_get_one_attr(exoid, EX_NODAL, 0, j + 1, attrib);
          printf(" after ex_get_one_attr, error = %d\n", error);
          for (i = 0; i < num_nodes; i++) {
            printf("%5.1f\n", attrib[i]);
          }
          free(attrib_names[j]);
        }
        free(attrib);
      }
    }
  }

  /* read element order map */

  elem_map = (int *)calloc(num_elem, sizeof(int));

  error = ex_get_map(exoid, elem_map);
  printf("\nafter ex_get_map, error = %3d\n", error);

  for (i = 0; i < num_elem; i++) {
    printf("elem_map(%d) = %d \n", i, elem_map[i]);
  }

  free(elem_map);

  /* read element block parameters */

  if (num_elem_blk > 0) {
    ids                = (int *)calloc(num_elem_blk, sizeof(int));
    num_elem_in_block  = (int *)calloc(num_elem_blk, sizeof(int));
    num_nodes_per_elem = (int *)calloc(num_elem_blk, sizeof(int));
    num_attr           = (int *)calloc(num_elem_blk, sizeof(int));

    error = ex_get_elem_blk_ids(exoid, ids);
    printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error);

    for (i = 0; i < num_elem_blk; i++) {
      block_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_names(exoid, EX_ELEM_BLOCK, block_names);
    printf("\nafter ex_get_names, error = %3d\n", error);

    for (i = 0; i < num_elem_blk; i++) {
      ex_get_name(exoid, EX_ELEM_BLOCK, ids[i], name);
      if (strcmp(name, block_names[i]) != 0) {
        printf("error in ex_get_name for block id %d\n", ids[i]);
      }
      error = ex_get_elem_block(exoid, ids[i], elem_type, &(num_elem_in_block[i]),
                                &(num_nodes_per_elem[i]), &(num_attr[i]));
      printf("\nafter ex_get_elem_block, error = %d\n", error);

      printf("element block id = %2d\n", ids[i]);
      printf("element type = '%s'\n", elem_type);
      printf("num_elem_in_block = %2d\n", num_elem_in_block[i]);
      printf("num_nodes_per_elem = %2d\n", num_nodes_per_elem[i]);
      printf("num_attr = %2d\n", num_attr[i]);
      printf("name = '%s'\n", block_names[i]);
      free(block_names[i]);
    }

    /* read element block properties */
    error = ex_inquire(exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum);
    printf("\nafter ex_inquire, error = %d\n", error);
    printf("\nThere are %2d properties for each element block\n", num_props);

    for (i = 0; i < num_props; i++) {
      prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_prop_names(exoid, EX_ELEM_BLOCK, prop_names);
    printf("after ex_get_prop_names, error = %d\n", error);

    for (i = 1; i < num_props; i++) /* Prop 1 is id; skip that here */
    {
      for (j = 0; j < num_elem_blk; j++) {
        error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i], &prop_value);
        if (error == 0)
          printf("element block %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i],
                 prop_value);
        else
          printf("after ex_get_prop, error = %d\n", error);
      }
    }

    for (i = 0; i < num_props; i++)
      free(prop_names[i]);
  }

  /* read element connectivity */

  for (i = 0; i < num_elem_blk; i++) {
    if (num_elem_in_block[i] > 0) {
      connect = (int *)calloc((num_nodes_per_elem[i] * num_elem_in_block[i]), sizeof(int));

      error = ex_get_elem_conn(exoid, ids[i], connect);
      printf("\nafter ex_get_elem_conn, error = %d\n", error);

      printf("connect array for elem block %2d\n", ids[i]);

      for (j = 0; j < num_nodes_per_elem[i]; j++) {
        printf("%3d\n", connect[j]);
      }
      /*
        error = ex_get_1_elem_conn (exoid, 1, ids[i], connect);
        printf ("\nafter ex_get_elem_conn, error = %d\n", error);

        printf ("node list for first element of element block %d \n ", ids[i]);
        for (j=0; j<num_nodes_per_elem[i]; j++)
        {
        printf ("%d \n", connect[j]);
        }
      */
      free(connect);
    }
  }

  /* read element block attributes */

  for (i = 0; i < num_elem_blk; i++) {
    if (num_elem_in_block[i] > 0) {
      for (j            = 0; j < num_attr[i]; j++)
        attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));

      attrib = (float *)calloc(num_attr[i] * num_elem_in_block[i], sizeof(float));
      error  = ex_get_elem_attr(exoid, ids[i], attrib);
      printf("\n after ex_get_elem_attr, error = %d\n", error);

      if (error == 0) {
        error = ex_get_elem_attr_names(exoid, ids[i], attrib_names);
        printf(" after ex_get_elem_attr_names, error = %d\n", error);

        if (error == 0) {
          printf("element block %d attribute '%s' = %6.4f\n", ids[i], attrib_names[0], *attrib);
        }
      }
      free(attrib);
      for (j = 0; j < num_attr[i]; j++)
        free(attrib_names[j]);
    }
  }

  if (num_elem_blk > 0) {
    free(ids);
    free(num_nodes_per_elem);
    free(num_attr);
  }

  /* read individual node sets */
  if (num_node_sets > 0) {
    ids = (int *)calloc(num_node_sets, sizeof(int));

    error = ex_get_node_set_ids(exoid, ids);
    printf("\nafter ex_get_node_set_ids, error = %3d\n", error);

    for (i = 0; i < num_node_sets; i++) {
      nset_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_names(exoid, EX_NODE_SET, nset_names);
    printf("\nafter ex_get_names, error = %3d\n", error);

    for (i = 0; i < num_node_sets; i++) {
      ex_get_name(exoid, EX_NODE_SET, ids[i], name);
      if (strcmp(name, nset_names[i]) != 0) {
        printf("error in ex_get_name for nodeset id %d\n", ids[i]);
      }

      error = ex_get_node_set_param(exoid, ids[i], &num_nodes_in_set, &num_df_in_set);
      printf("\nafter ex_get_node_set_param, error = %3d\n", error);

      printf("\nnode set %2d parameters: \n", ids[i]);
      printf("num_nodes = %2d\n", num_nodes_in_set);
      printf("name = '%s'\n", nset_names[i]);
      free(nset_names[i]);
      node_list = (int *)calloc(num_nodes_in_set, sizeof(int));
      dist_fact = (float *)calloc(num_nodes_in_set, sizeof(float));

      error = ex_get_node_set(exoid, ids[i], node_list);
      printf("\nafter ex_get_node_set, error = %3d\n", error);

      if (num_df_in_set > 0) {
        error = ex_get_node_set_dist_fact(exoid, ids[i], dist_fact);
        printf("\nafter ex_get_node_set_dist_fact, error = %3d\n", error);
      }

      printf("\nnode list for node set %2d\n", ids[i]);

      for (j = 0; j < num_nodes_in_set; j++) {
        printf("%3d\n", node_list[j]);
      }

      if (num_df_in_set > 0) {
        printf("dist factors for node set %2d\n", ids[i]);

        for (j = 0; j < num_df_in_set; j++) {
          printf("%5.2f\n", dist_fact[j]);
        }
      }
      else
        printf("no dist factors for node set %2d\n", ids[i]);

      free(node_list);
      free(dist_fact);

      {
        int num_attrs = 0;
        error         = ex_get_attr_param(exoid, EX_NODE_SET, ids[i], &num_attrs);
        printf(" after ex_get_attr_param, error = %d\n", error);
        printf("num nodeset attributes for nodeset %d = %d\n", ids[i], num_attrs);
        if (num_attrs > 0) {
          for (j = 0; j < num_attrs; j++) {
            attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
          }
          error = ex_get_attr_names(exoid, EX_NODE_SET, ids[i], attrib_names);
          printf(" after ex_get_attr_names, error = %d\n", error);

          if (error == 0) {
            attrib = (float *)calloc(num_nodes_in_set, sizeof(float));
            for (j = 0; j < num_attrs; j++) {
              printf("nodeset attribute %d = '%s'\n", j, attrib_names[j]);
              error = ex_get_one_attr(exoid, EX_NODE_SET, ids[i], j + 1, attrib);
              printf(" after ex_get_one_attr, error = %d\n", error);
              for (k = 0; k < num_nodes_in_set; k++) {
                printf("%5.1f\n", attrib[k]);
              }
              free(attrib_names[j]);
            }
            free(attrib);
          }
        }
      }
    }
    free(ids);

    /* read node set properties */
    error = ex_inquire(exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum);
    printf("\nafter ex_inquire, error = %d\n", error);
    printf("\nThere are %2d properties for each node set\n", num_props);

    for (i = 0; i < num_props; i++) {
      prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }
    prop_values = (int *)calloc(num_node_sets, sizeof(int));

    error = ex_get_prop_names(exoid, EX_NODE_SET, prop_names);
    printf("after ex_get_prop_names, error = %d\n", error);

    for (i = 0; i < num_props; i++) {
      error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i], prop_values);
      if (error == 0)
        for (j = 0; j < num_node_sets; j++)
          printf("node set %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i],
                 prop_values[j]);
      else
        printf("after ex_get_prop_array, error = %d\n", error);
    }
    for (i = 0; i < num_props; i++)
      free(prop_names[i]);
    free(prop_values);

    /* read concatenated node sets; this produces the same information as
     * the above code which reads individual node sets
     */

    error = ex_inquire(exoid, EX_INQ_NODE_SETS, &num_node_sets, &fdum, cdum);
    printf("\nafter ex_inquire, error = %3d\n", error);

    ids               = (int *)calloc(num_node_sets, sizeof(int));
    num_nodes_per_set = (int *)calloc(num_node_sets, sizeof(int));
    num_df_per_set    = (int *)calloc(num_node_sets, sizeof(int));
    node_ind          = (int *)calloc(num_node_sets, sizeof(int));
    df_ind            = (int *)calloc(num_node_sets, sizeof(int));

    error = ex_inquire(exoid, EX_INQ_NS_NODE_LEN, &list_len, &fdum, cdum);
    printf("\nafter ex_inquire: EX_INQ_NS_NODE_LEN = %d, error = %3d\n", list_len, error);
    node_list = (int *)calloc(list_len, sizeof(int));

    error = ex_inquire(exoid, EX_INQ_NS_DF_LEN, &list_len, &fdum, cdum);
    printf("\nafter ex_inquire: EX_INQ_NS_DF_LEN = %d, error = %3d\n", list_len, error);
    dist_fact = (float *)calloc(list_len, sizeof(float));

    error = ex_get_concat_node_sets(exoid, ids, num_nodes_per_set, num_df_per_set, node_ind, df_ind,
                                    node_list, dist_fact);
    printf("\nafter ex_get_concat_node_sets, error = %3d\n", error);

    printf("\nconcatenated node set info\n");

    printf("ids = \n");
    for (i = 0; i < num_node_sets; i++)
      printf("%3d\n", ids[i]);

    printf("num_nodes_per_set = \n");
    for (i = 0; i < num_node_sets; i++)
      printf("%3d\n", num_nodes_per_set[i]);

    printf("node_ind = \n");
    for (i = 0; i < num_node_sets; i++)
      printf("%3d\n", node_ind[i]);

    printf("node_list = \n");
    for (i = 0; i < list_len; i++)
      printf("%3d\n", node_list[i]);

    printf("dist_fact = \n");
    for (i = 0; i < list_len; i++)
      printf("%5.3f\n", dist_fact[i]);

    free(ids);
    free(df_ind);
    free(node_ind);
    free(num_df_per_set);
    free(node_list);
    free(dist_fact);
  }

  /* read individual side sets */

  if (num_side_sets > 0) {
    ids = (int *)calloc(num_side_sets, sizeof(int));

    error = ex_get_side_set_ids(exoid, ids);
    printf("\nafter ex_get_side_set_ids, error = %3d\n", error);

    for (i = 0; i < num_side_sets; i++) {
      sset_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_names(exoid, EX_SIDE_SET, sset_names);
    printf("\nafter ex_get_names, error = %3d\n", error);

    for (i = 0; i < num_side_sets; i++) {
      ex_get_name(exoid, EX_SIDE_SET, ids[i], name);
      if (strcmp(name, sset_names[i]) != 0) {
        printf("error in ex_get_name for sideset id %d\n", ids[i]);
      }

      error = ex_get_side_set_param(exoid, ids[i], &num_sides_in_set, &num_df_in_set);
      printf("\nafter ex_get_side_set_param, error = %3d\n", error);

      printf("side set %2d parameters:\n", ids[i]);
      printf("name = '%s'\n", sset_names[i]);
      printf("num_sides = %3d\n", num_sides_in_set);
      printf("num_dist_factors = %3d\n", num_df_in_set);
      free(sset_names[i]);

      /* Note: The # of elements is same as # of sides!  */
      num_elem_in_set = num_sides_in_set;
      elem_list       = (int *)calloc(num_elem_in_set, sizeof(int));
      side_list       = (int *)calloc(num_sides_in_set, sizeof(int));
      node_ctr_list   = (int *)calloc(num_elem_in_set, sizeof(int));
      node_list       = (int *)calloc(num_elem_in_set * 21, sizeof(int));
      dist_fact       = (float *)calloc(num_df_in_set, sizeof(float));

      error = ex_get_side_set(exoid, ids[i], elem_list, side_list);
      printf("\nafter ex_get_side_set, error = %3d\n", error);

      error = ex_get_side_set_node_list(exoid, ids[i], node_ctr_list, node_list);
      printf("\nafter ex_get_side_set_node_list, error = %3d\n", error);

      if (num_df_in_set > 0) {
        error = ex_get_side_set_dist_fact(exoid, ids[i], dist_fact);
        printf("\nafter ex_get_side_set_dist_fact, error = %3d\n", error);
      }

      printf("element list for side set %2d\n", ids[i]);
      for (j = 0; j < num_elem_in_set; j++) {
        printf("%3d\n", elem_list[j]);
      }

      printf("side list for side set %2d\n", ids[i]);
      for (j = 0; j < num_sides_in_set; j++) {
        printf("%3d\n", side_list[j]);
      }

      node_ctr = 0;
      printf("node list for side set %2d\n", ids[i]);
      for (k = 0; k < num_elem_in_set; k++) {
        for (j = 0; j < node_ctr_list[k]; j++) {
          printf("%3d\n", node_list[node_ctr + j]);
        }
        node_ctr += node_ctr_list[k];
      }

      if (num_df_in_set > 0) {
        printf("dist factors for side set %2d\n", ids[i]);

        for (j = 0; j < num_df_in_set; j++) {
          printf("%5.3f\n", dist_fact[j]);
        }
      }
      else
        printf("no dist factors for side set %2d\n", ids[i]);

      free(elem_list);
      free(side_list);
      free(node_ctr_list);
      free(node_list);
      free(dist_fact);
    }

    /* read side set properties */
    error = ex_inquire(exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum);
    printf("\nafter ex_inquire, error = %d\n", error);
    printf("\nThere are %2d properties for each side set\n", num_props);

    for (i = 0; i < num_props; i++) {
      prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_prop_names(exoid, EX_SIDE_SET, prop_names);
    printf("after ex_get_prop_names, error = %d\n", error);

    for (i = 0; i < num_props; i++) {
      for (j = 0; j < num_side_sets; j++) {
        error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i], &prop_value);
        if (error == 0)
          printf("side set %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i],
                 prop_value);
        else
          printf("after ex_get_prop, error = %d\n", error);
      }
    }
    for (i = 0; i < num_props; i++)
      free(prop_names[i]);
    free(ids);

    error = ex_inquire(exoid, EX_INQ_SIDE_SETS, &num_side_sets, &fdum, cdum);
    printf("\nafter ex_inquire: EX_INQ_SIDE_SETS = %d,  error = %d\n", num_side_sets, error);

    if (num_side_sets > 0) {
      error = ex_inquire(exoid, EX_INQ_SS_ELEM_LEN, &elem_list_len, &fdum, cdum);
      printf("\nafter ex_inquire: EX_INQ_SS_ELEM_LEN = %d,  error = %d\n", elem_list_len, error);

      error = ex_inquire(exoid, EX_INQ_SS_NODE_LEN, &node_list_len, &fdum, cdum);
      printf("\nafter ex_inquire: EX_INQ_SS_NODE_LEN = %d,  error = %d\n", node_list_len, error);

      error = ex_inquire(exoid, EX_INQ_SS_DF_LEN, &df_list_len, &fdum, cdum);
      printf("\nafter ex_inquire: EX_INQ_SS_DF_LEN = %d,  error = %d\n", df_list_len, error);
    }

    /* read concatenated side sets; this produces the same information as
     * the above code which reads individual side sets
     */

    /* concatenated side set read */

    if (num_side_sets > 0) {
      ids              = (int *)calloc(num_side_sets, sizeof(int));
      num_elem_per_set = (int *)calloc(num_side_sets, sizeof(int));
      num_df_per_set   = (int *)calloc(num_side_sets, sizeof(int));
      elem_ind         = (int *)calloc(num_side_sets, sizeof(int));
      df_ind           = (int *)calloc(num_side_sets, sizeof(int));
      elem_list        = (int *)calloc(elem_list_len, sizeof(int));
      side_list        = (int *)calloc(elem_list_len, sizeof(int));
      dist_fact        = (float *)calloc(df_list_len, sizeof(float));

      error = ex_get_concat_side_sets(exoid, ids, num_elem_per_set, num_df_per_set, elem_ind,
                                      df_ind, elem_list, side_list, dist_fact);
      printf("\nafter ex_get_concat_side_sets, error = %3d\n", error);

      printf("concatenated side set info\n");

      printf("ids = \n");
      for (i = 0; i < num_side_sets; i++)
        printf("%3d\n", ids[i]);

      printf("num_elem_per_set = \n");
      for (i = 0; i < num_side_sets; i++)
        printf("%3d\n", num_elem_per_set[i]);

      printf("num_dist_per_set = \n");
      for (i = 0; i < num_side_sets; i++)
        printf("%3d\n", num_df_per_set[i]);

      printf("elem_ind = \n");
      for (i = 0; i < num_side_sets; i++)
        printf("%3d\n", elem_ind[i]);

      printf("dist_ind = \n");
      for (i = 0; i < num_side_sets; i++)
        printf("%3d\n", df_ind[i]);

      printf("elem_list = \n");
      for (i = 0; i < elem_list_len; i++)
        printf("%3d\n", elem_list[i]);

      printf("side_list = \n");
      for (i = 0; i < elem_list_len; i++)
        printf("%3d\n", side_list[i]);

      printf("dist_fact = \n");
      for (i = 0; i < df_list_len; i++)
        printf("%5.3f\n", dist_fact[i]);

      free(ids);
      free(num_df_per_set);
      free(df_ind);
      free(elem_ind);
      free(elem_list);
      free(side_list);
      free(dist_fact);
    }
  }
  /* end of concatenated side set read */

  /* read QA records */

  ex_inquire(exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum);

  for (i = 0; i < num_qa_rec; i++) {
    for (j = 0; j < 4; j++) {
      qa_record[i][j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }
  }

  error = ex_get_qa(exoid, qa_record);
  printf("\nafter ex_get_qa, error = %3d\n", error);

  printf("QA records = \n");
  for (i = 0; i < num_qa_rec; i++) {
    for (j = 0; j < 4; j++) {
      printf(" '%s'\n", qa_record[i][j]);
      free(qa_record[i][j]);
    }
  }

  /* read information records */

  error = ex_inquire(exoid, EX_INQ_INFO, &num_info, &fdum, cdum);
  printf("\nafter ex_inquire, error = %3d\n", error);

  for (i = 0; i < num_info; i++) {
    info[i] = (char *)calloc((MAX_LINE_LENGTH + 1), sizeof(char));
  }

  error = ex_get_info(exoid, info);
  printf("\nafter ex_get_info, error = %3d\n", error);

  printf("info records = \n");
  for (i = 0; i < num_info; i++) {
    printf(" '%s'\n", info[i]);
    free(info[i]);
  }

  /* read global variables parameters and names */

  error = ex_get_var_param(exoid, "g", &num_glo_vars);
  printf("\nafter ex_get_var_param, error = %3d\n", error);

  for (i = 0; i < num_glo_vars; i++) {
    var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }

  error = ex_get_var_names(exoid, "g", num_glo_vars, var_names);
  printf("\nafter ex_get_var_names, error = %3d\n", error);

  printf("There are %2d global variables; their names are :\n", num_glo_vars);
  for (i = 0; i < num_glo_vars; i++) {
    printf(" '%s'\n", var_names[i]);
    free(var_names[i]);
  }

  /* read nodal variables parameters and names */
  num_nod_vars = 0;
  if (num_nodes > 0) {
    error = ex_get_var_param(exoid, "n", &num_nod_vars);
    printf("\nafter ex_get_var_param, error = %3d\n", error);

    for (i = 0; i < num_nod_vars; i++) {
      var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_var_names(exoid, "n", num_nod_vars, var_names);
    printf("\nafter ex_get_var_names, error = %3d\n", error);

    printf("There are %2d nodal variables; their names are :\n", num_nod_vars);
    for (i = 0; i < num_nod_vars; i++) {
      printf(" '%s'\n", var_names[i]);
      free(var_names[i]);
    }
  }

  /* read element variables parameters and names */

  num_ele_vars = 0;
  if (num_elem > 0) {
    error = ex_get_var_param(exoid, "e", &num_ele_vars);
    printf("\nafter ex_get_var_param, error = %3d\n", error);

    for (i = 0; i < num_ele_vars; i++) {
      var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_var_names(exoid, "e", num_ele_vars, var_names);
    printf("\nafter ex_get_var_names, error = %3d\n", error);

    printf("There are %2d element variables; their names are :\n", num_ele_vars);
    for (i = 0; i < num_ele_vars; i++) {
      printf(" '%s'\n", var_names[i]);
      free(var_names[i]);
    }

    /* read element variable truth table */

    if (num_ele_vars > 0) {
      truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int));

      error = ex_get_elem_var_tab(exoid, num_elem_blk, num_ele_vars, truth_tab);
      printf("\nafter ex_get_elem_var_tab, error = %3d\n", error);

      printf("This is the element variable truth table:\n");

      k = 0;
      for (i = 0; i < num_elem_blk * num_ele_vars; i++) {
        printf("%2d\n", truth_tab[k++]);
      }
      free(truth_tab);
    }
  }

  /* read nodeset variables parameters and names */

  num_nset_vars = 0;
  if (num_node_sets > 0) {
    error = ex_get_var_param(exoid, "m", &num_nset_vars);
    printf("\nafter ex_get_var_param, error = %3d\n", error);

    if (num_nset_vars > 0) {
      for (i = 0; i < num_nset_vars; i++) {
        var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
      }

      error = ex_get_var_names(exoid, "m", num_nset_vars, var_names);
      printf("\nafter ex_get_var_names, error = %3d\n", error);

      printf("There are %2d nodeset variables; their names are :\n", num_nset_vars);
      for (i = 0; i < num_nset_vars; i++) {
        printf(" '%s'\n", var_names[i]);
        free(var_names[i]);
      }

      /* read nodeset variable truth table */

      if (num_nset_vars > 0) {
        truth_tab = (int *)calloc((num_node_sets * num_nset_vars), sizeof(int));

        error = ex_get_nset_var_tab(exoid, num_node_sets, num_nset_vars, truth_tab);
        printf("\nafter ex_get_nset_var_tab, error = %3d\n", error);

        printf("This is the nodeset variable truth table:\n");

        k = 0;
        for (i = 0; i < num_node_sets * num_nset_vars; i++) {
          printf("%2d\n", truth_tab[k++]);
        }
        free(truth_tab);
      }
    }
  }

  /* read sideset variables parameters and names */

  num_sset_vars = 0;
  if (num_side_sets > 0) {
    error = ex_get_var_param(exoid, "s", &num_sset_vars);
    printf("\nafter ex_get_var_param, error = %3d\n", error);

    if (num_sset_vars > 0) {
      for (i = 0; i < num_sset_vars; i++) {
        var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
      }

      error = ex_get_var_names(exoid, "s", num_sset_vars, var_names);
      printf("\nafter ex_get_var_names, error = %3d\n", error);

      printf("There are %2d sideset variables; their names are :\n", num_sset_vars);
      for (i = 0; i < num_sset_vars; i++) {
        printf(" '%s'\n", var_names[i]);
        free(var_names[i]);
      }

      /* read sideset variable truth table */

      if (num_sset_vars > 0) {
        truth_tab = (int *)calloc((num_side_sets * num_sset_vars), sizeof(int));

        error = ex_get_sset_var_tab(exoid, num_side_sets, num_sset_vars, truth_tab);
        printf("\nafter ex_get_sset_var_tab, error = %3d\n", error);

        printf("This is the sideset variable truth table:\n");

        k = 0;
        for (i = 0; i < num_side_sets * num_sset_vars; i++) {
          printf("%2d\n", truth_tab[k++]);
        }
        free(truth_tab);
      }
    }
  }

  /* determine how many time steps are stored */

  error = ex_inquire(exoid, EX_INQ_TIME, &num_time_steps, &fdum, cdum);
  printf("\nafter ex_inquire, error = %3d\n", error);
  printf("There are %2d time steps in the database.\n", num_time_steps);

  /* read time value at one time step */

  time_step = 3;
  error     = ex_get_time(exoid, time_step, &time_value);
  printf("\nafter ex_get_time, error = %3d\n", error);

  printf("time value at time step %2d = %5.3f\n", time_step, time_value);

  /* read time values at all time steps */

  time_values = (float *)calloc(num_time_steps, sizeof(float));

  error = ex_get_all_times(exoid, time_values);
  printf("\nafter ex_get_all_times, error = %3d\n", error);

  printf("time values at all time steps are:\n");
  for (i = 0; i < num_time_steps; i++)
    printf("%5.3f\n", time_values[i]);

  free(time_values);

  /* read all global variables at one time step */

  var_values = (float *)calloc(num_glo_vars, sizeof(float));

  error = ex_get_glob_vars(exoid, time_step, num_glo_vars, var_values);
  printf("\nafter ex_get_glob_vars, error = %3d\n", error);

  printf("global variable values at time step %2d\n", time_step);
  for (i = 0; i < num_glo_vars; i++)
    printf("%5.3f\n", var_values[i]);

  free(var_values);

  /* read a single global variable through time */

  var_index = 1;
  beg_time  = 1;
  end_time  = -1;

  var_values = (float *)calloc(num_time_steps, sizeof(float));

  error = ex_get_glob_var_time(exoid, var_index, beg_time, end_time, var_values);
  printf("\nafter ex_get_glob_var_time, error = %3d\n", error);

  printf("global variable %2d values through time:\n", var_index);
  for (i = 0; i < num_time_steps; i++)
    printf("%5.3f\n", var_values[i]);

  free(var_values);

  /* read a nodal variable at one time step */

  if (num_nodes > 0) {
    var_values = (float *)calloc(num_nodes, sizeof(float));

    error = ex_get_nodal_var(exoid, time_step, var_index, num_nodes, var_values);
    printf("\nafter ex_get_nodal_var, error = %3d\n", error);

    printf("nodal variable %2d values at time step %2d\n", var_index, time_step);
    for (i = 0; i < num_nodes; i++)
      printf("%5.3f\n", var_values[i]);

    free(var_values);

    /* read a nodal variable through time */

    var_values = (float *)calloc(num_time_steps, sizeof(float));

    node_num = 1;
    error    = ex_get_nodal_var_time(exoid, var_index, node_num, beg_time, end_time, var_values);
    printf("\nafter ex_get_nodal_var_time, error = %3d\n", error);

    printf("nodal variable %2d values for node %2d through time:\n", var_index, node_num);
    for (i = 0; i < num_time_steps; i++)
      printf("%5.3f\n", var_values[i]);

    free(var_values);
  }
  /* read an element variable at one time step */

  if (num_elem_blk > 0) {
    ids = (int *)calloc(num_elem_blk, sizeof(int));

    error = ex_get_elem_blk_ids(exoid, ids);
    printf("\n after ex_get_elem_blk_ids, error = %3d\n", error);

    for (i = 0; i < num_elem_blk; i++) {
      if (num_elem_in_block[i] > 0) {
        var_values = (float *)calloc(num_elem_in_block[i], sizeof(float));

        error =
            ex_get_elem_var(exoid, time_step, var_index, ids[i], num_elem_in_block[i], var_values);
        printf("\nafter ex_get_elem_var, error = %3d\n", error);

        if (!error) {
          printf("element variable %2d values of element block %2d at time step %2d\n", var_index,
                 ids[i], time_step);
          for (j = 0; j < num_elem_in_block[i]; j++)
            printf("%5.3f\n", var_values[j]);
        }

        free(var_values);
      }
    }
    free(num_elem_in_block);
    free(ids);
  }
  /* read an element variable through time */

  if (num_ele_vars > 0) {
    var_values = (float *)calloc(num_time_steps, sizeof(float));

    var_index = 2;
    elem_num  = 2;
    error     = ex_get_elem_var_time(exoid, var_index, elem_num, beg_time, end_time, var_values);
    printf("\nafter ex_get_elem_var_time, error = %3d\n", error);

    printf("element variable %2d values for element %2d through time:\n", var_index, elem_num);
    for (i = 0; i < num_time_steps; i++)
      printf("%5.3f\n", var_values[i]);

    free(var_values);
  }

  /* read a sideset variable at one time step */

  if (num_sset_vars > 0) {
    ids = (int *)calloc(num_side_sets, sizeof(int));

    error = ex_get_side_set_ids(exoid, ids);
    printf("\n after ex_get_side_set_ids, error = %3d\n", error);

    for (i = 0; i < num_side_sets; i++) {
      var_values = (float *)calloc(num_elem_per_set[i], sizeof(float));

      error = ex_get_sset_var(exoid, time_step, var_index, ids[i], num_elem_per_set[i], var_values);
      printf("\nafter ex_get_sset_var, error = %3d\n", error);

      if (!error) {
        printf("sideset variable %2d values of sideset %2d at time step %2d\n", var_index, ids[i],
               time_step);
        for (j = 0; j < num_elem_per_set[i]; j++)
          printf("%5.3f\n", var_values[j]);
      }

      free(var_values);
    }
    free(num_elem_per_set);
    free(ids);
  }

  /* read a nodeset variable at one time step */

  if (num_nset_vars > 0) {
    ids = (int *)calloc(num_node_sets, sizeof(int));

    error = ex_get_node_set_ids(exoid, ids);
    printf("\n after ex_get_node_set_ids, error = %3d\n", error);

    for (i = 0; i < num_node_sets; i++) {
      var_values = (float *)calloc(num_nodes_per_set[i], sizeof(float));

      error =
          ex_get_nset_var(exoid, time_step, var_index, ids[i], num_nodes_per_set[i], var_values);
      printf("\nafter ex_get_nset_var, error = %3d\n", error);

      if (!error) {
        printf("nodeset variable %2d values of nodeset %2d at time step %2d\n", var_index, ids[i],
               time_step);
        for (j = 0; j < num_nodes_per_set[i]; j++)
          printf("%5.3f\n", var_values[j]);
      }

      free(var_values);
    }
    free(ids);
  }
  if (num_node_sets > 0)
    free(num_nodes_per_set);

  error = ex_close(exoid);
  printf("\nafter ex_close, error = %3d\n", error);
  return 0;
}
示例#13
0
文件: oned.c 项目: certik/exodus
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_nodes_per_elem[10];
   int num_nodes_in_nset[10];
   int num_node_sets, num_side_sets;
   int i, j, k, m, *elem_map, *connect;
   int node_list[100];
   int ebids[10], nsids[10];
   int  num_qa_rec, num_info;
   int num_glo_vars, num_nod_vars, num_ele_vars, num_nset_vars;
   int *truth_tab;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;
   int prop_array[2];

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float *nset_var_vals;
   float time_value;
   float x[100];
   float attrib[10], dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
   char *block_names[10], *nset_names[10];
   char *prop_names[2], *attrib_names[2];
   char *title = "This is a test";
   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("oned.e",         /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for oned.e, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   EXCHECK(ex_set_max_name_length(exoid, 40));
   /* ncopts = NC_VERBOSE; */

/* initialize file with parameters */

   num_dim = 1;
   num_nodes = 10;
   num_elem = 10; /* 9 lines plus a point */
   num_elem_blk = 3;
   num_node_sets = 2;
   num_side_sets = 0;

   
   EXCHECK(ex_put_init (exoid, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets));

   for (i=0; i < num_nodes; i++) {
     x[i] = exp((float)i/10.0);
   }
   
   EXCHECK(ex_put_coord (exoid, x, NULL, NULL));
   
   coord_names[0] = "xcoor";
   EXCHECK(ex_put_coord_names (exoid, coord_names));
   
   /* Add nodal attributes */
   EXCHECK(ex_put_attr_param(exoid, EX_NODAL, 0, 1));
   
   EXCHECK(ex_put_one_attr(exoid, EX_NODAL, 0, 1, x));
   
   attrib_names[0] = "Node_attr_1";
   EXCHECK(ex_put_attr_names (exoid, EX_NODAL, 0, attrib_names));

   /* write element order map */
   elem_map = (int *) calloc(num_elem, sizeof(int));

   for (i=1; i<=num_elem; i++) {
     elem_map[i-1] = 10*i;
   }

   EXCHECK(ex_put_map (exoid, elem_map));
   free (elem_map);

   /* write element block parameters */
   block_names[0] = "left_side";
   block_names[1] = "right_side";
   block_names[2] = "center";

   num_elem_in_block[0] = 4;
   num_elem_in_block[1] = 5;
   num_elem_in_block[2] = 1;

   num_nodes_per_elem[0] = 2;
   num_nodes_per_elem[1] = 2;
   num_nodes_per_elem[2] = 1;

   ebids[0] = 10;
   ebids[1] = 20;
   ebids[2] = 30;

   EXCHECK(ex_put_elem_block (exoid, ebids[0], "line",  num_elem_in_block[0], num_nodes_per_elem[0], 1));
   EXCHECK(ex_put_elem_block (exoid, ebids[1], "line",  num_elem_in_block[1], num_nodes_per_elem[1], 1));
   EXCHECK(ex_put_elem_block (exoid, ebids[2], "point", num_elem_in_block[2], num_nodes_per_elem[2], 0));

   /* Write element block names */
   EXCHECK(ex_put_names(exoid, EX_ELEM_BLOCK, block_names));
   
   /* write element block properties */
   prop_names[0] = "DENSITY";
   EXCHECK(ex_put_prop_names(exoid,EX_ELEM_BLOCK,1,prop_names));
   EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 1.345));
   EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 10.995));
   EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 0.001));


   /* write element connectivity */
   connect = (int *) calloc(18, sizeof(int));
   for (i=0; i < num_elem*2; i+=2) {
     connect[i]   = i/2+1;
     connect[i+1] = i/2+2;
   }

   EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL));
   EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[1], connect+8, NULL, NULL));

   /* Circle */
   connect[0] = 5;
   EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL));

   /* write element block attributes */
   for (i=0; i < num_elem; i++) {
     attrib[i] = 3.14159 * i;
   }
   EXCHECK(ex_put_attr (exoid, EX_ELEM_BLOCK, ebids[0], attrib));
   EXCHECK(ex_put_attr (exoid, EX_ELEM_BLOCK, ebids[1], attrib+num_elem_in_block[0]));

   attrib_names[0] = "THICKNESS";
   EXCHECK(ex_put_attr_names (exoid, EX_ELEM_BLOCK, ebids[0], attrib_names));
   attrib_names[0] = "WIDTH";
   EXCHECK(ex_put_attr_names (exoid, EX_ELEM_BLOCK, ebids[1], attrib_names));

   /* write individual node sets */
   num_nodes_in_nset[0] = 5;
   num_nodes_in_nset[1] = 3;

   nsids[0] = 20;
   nsids[1] = 21;

   EXCHECK(ex_put_node_set_param (exoid, nsids[0], 5, 5));

   node_list[0] = 1;
   node_list[1] = 3;
   node_list[2] = 5;
   node_list[3] = 7;
   node_list[4] = 9;

   dist_fact[0] = 1.0;
   dist_fact[1] = 2.0;
   dist_fact[2] = 3.0;
   dist_fact[3] = 4.0;
   dist_fact[4] = 5.0;

   EXCHECK(ex_put_node_set (exoid, nsids[0], node_list));
   EXCHECK(ex_put_node_set_dist_fact (exoid, nsids[0], dist_fact));

   EXCHECK(ex_put_node_set_param (exoid, nsids[1], 3, 3));

   node_list[0] = 2;
   node_list[1] = 4;
   node_list[2] = 6;

   dist_fact[0] = 1.0;
   dist_fact[1] = 2.0;
   dist_fact[2] = 3.0;

   EXCHECK(ex_put_node_set (exoid, nsids[1], node_list));
   EXCHECK(ex_put_node_set_dist_fact (exoid, nsids[1], dist_fact));

   /* Write node set names */
   nset_names[0] = "all_odd_nodes";
   nset_names[1] = "some_even_nodes";

   EXCHECK(ex_put_names(exoid, EX_NODE_SET, nset_names));
   EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4));

   EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5));

   prop_array[0] = 1000;
   prop_array[1] = 2000;

   EXCHECK(ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array));
   /* Add nodeset attributes */
   EXCHECK(ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1));
   
   EXCHECK(ex_put_attr(exoid, EX_NODE_SET, nsids[0], x));
   
   attrib_names[0] = "Nodeset_attribute";
   EXCHECK(ex_put_attr_names (exoid, EX_NODE_SET, nsids[0], attrib_names));

   /* write QA records; test empty and just blank-filled records */
   num_qa_rec = 2;

   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   EXCHECK(ex_put_qa (exoid, num_qa_rec, qa_record));

   /* write information records; test empty and just blank-filled records */
   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   EXCHECK(ex_put_info (exoid, num_info, info));


   /* write results variables parameters and names */
   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   EXCHECK(ex_put_variable_param (exoid, EX_GLOBAL, num_glo_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_GLOBAL, num_glo_vars, var_names));

   num_nod_vars = 2;
   /*              12345678901234567890123456789012 */
   var_names[0] = "node_variable_a_very_long_name_0";
   var_names[1] = "nod_var1";

   EXCHECK(ex_put_variable_param (exoid, EX_NODAL, num_nod_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, var_names));

   num_ele_vars = 3;
   /*              0        1         2         3   */
   /*              12345678901234567890123456789012 */
   var_names[0] = "this_variable_name_is_short";
   var_names[1] = "this_variable_name_is_just_right";
   var_names[2] = "this_variable_name_is_tooooo_long";

   EXCHECK(ex_put_variable_param (exoid, EX_ELEM_BLOCK, num_ele_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_ELEM_BLOCK, num_ele_vars, var_names));

   num_nset_vars = 3;
     
   var_names[0] = "ns_var0";
   var_names[1] = "ns_var1";
   var_names[2] = "ns_var2";
     
   EXCHECK(ex_put_variable_param (exoid, EX_NODE_SET, num_nset_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_NODE_SET, num_nset_vars, var_names));
   

   /* write element variable truth table */
   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));

   k = 0;
   for (i=0; i<num_elem_blk; i++)
   {
      for (j=0; j<num_ele_vars; j++)
      {
         truth_tab[k++] = 1;
      }
   }

   EXCHECK(ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab));

   free (truth_tab);


/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (num_elem, CPU_word_size);
   nset_var_vals = (float *) calloc (10, CPU_word_size);
   
   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

     /* write time value */
     EXCHECK(ex_put_time (exoid, whole_time_step, &time_value));

     /* write global variables */
     for (j=0; j<num_glo_vars; j++) {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     EXCHECK(ex_put_var (exoid, whole_time_step, EX_GLOBAL, 0, 0, num_glo_vars, glob_var_vals));

     /* write nodal variables */
     for (k=1; k<=num_nod_vars; k++) {
       for (j=0; j<num_nodes; j++) {
         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
       }
       EXCHECK(ex_put_var (exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals));
     }

     /* write element variables */
     for (k=1; k<=num_ele_vars; k++) {
       for (j=0; j<num_elem_blk; j++) {
         for (m=0; m<num_elem_in_block[j]; m++) {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
         }
         EXCHECK(ex_put_var (exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j], elem_var_vals));
       }
     }

     /* write nodeset variables */
     for (k=1; k<=num_nset_vars; k++) {
       for (j=0; j<num_node_sets; j++) {
         for (m=0; m<num_nodes_in_nset[j]; m++) {
           nset_var_vals[m] = (float)(k+3) + (float)(j+4) + 
                              ((float)(m+1)*time_value);
         }
         EXCHECK(ex_put_var (exoid, whole_time_step, EX_NODE_SET, k, nsids[j],  num_nodes_in_nset[j], nset_var_vals));
       }
     }

     whole_time_step++;

     /* update the data file; this should be done at the end of every time step
      * to ensure that no data is lost if the analysis dies
      */
     EXCHECK(ex_update (exoid));
   }

   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);
   free(nset_var_vals);


/* close the EXODUS files */
   EXCHECK(ex_close (exoid));
   return 0;
}
示例#14
0
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_total_nodes_per_blk[10];
   int num_face_in_block[10], num_total_faces_per_blk[10];
   int num_face_in_sset[10], num_nodes_in_nset[10];
   int num_node_sets, num_side_sets, error;
   int i, j, k, m, *elem_map, *connect;
   int node_list[100],elem_list[100],side_list[100];
   int bids[10], ssids[10], nsids[10], nnpe[10];
   int  num_qa_rec, num_info;
   int num_glo_vars, num_nod_vars, num_ele_vars, num_sset_vars, num_nset_vars;
   int *truth_tab;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;
   int prop_array[2];

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float *sset_var_vals, *nset_var_vals;
   float time_value;
   float x[100], y[100], z[100];
   float dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
   char *block_names[10], *nset_names[10], *sset_names[10];
   char *prop_names[2], *attrib_names[2];
   char *title = "This is a test";
   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("test-nfaced.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   /* ncopts = NC_VERBOSE; */

   /* initialize file with parameters */
   {
     ex_init_params par;
     
     num_dim = 3;
     num_nodes = 14;
     num_elem = 1;
     num_elem_blk = 1;
     num_node_sets = 0;

     strcpy( par.title, title );
     par.num_dim = num_dim;
     par.num_nodes = num_nodes;
     par.num_edge = 0;
     par.num_edge_blk = 0;
     par.num_face = 5;
     par.num_face_blk = 1;
     par.num_elem = num_elem;
     par.num_elem_blk = num_elem_blk;
     par.num_node_sets = num_node_sets;
     par.num_edge_sets = 0;
     par.num_face_sets = 0;
     par.num_side_sets = 0;
     par.num_elem_sets = 0;
     par.num_node_maps = 0;
     par.num_edge_maps = 0;
     par.num_face_maps = 0;
     par.num_elem_maps = 0;
     
     error = ex_put_init_ext (exoid, &par);
     
     printf ("after ex_put_init_ext, error = %d\n", error);
     
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }

/* write nodal coordinates values and names to database */
   x[ 0] =  0.00000e+00 ;    y[ 0] = 0.00000e+00 ;   z[ 0] =  0.00000e+00 ;
   x[ 1] =  2.00000e+00 ;    y[ 1] = 0.00000e+00 ;   z[ 1] =  0.00000e+00 ;
   x[ 2] =  0.00000e+00 ;    y[ 2] = 2.00000e+00 ;   z[ 2] =  0.00000e+00 ;
   x[ 3] =  2.00000e+00 ;    y[ 3] = 2.00000e+00 ;   z[ 3] =  0.00000e+00 ;
   x[ 4] =  0.00000e+00 ;    y[ 4] = 0.00000e+00 ;   z[ 4] =  2.00000e+00 ;
   x[ 5] =  2.00000e+00 ;    y[ 5] = 0.00000e+00 ;   z[ 5] =  2.00000e+00 ;
   x[ 6] =  0.00000e+00 ;    y[ 6] = 2.00000e+00 ;   z[ 6] =  2.00000e+00 ;
   x[ 7] =  2.00000e+00 ;    y[ 7] = 2.00000e+00 ;   z[ 7] =  2.00000e+00 ;
   x[ 8] =  0.00000e+00 ;    y[ 8] = 3.50000e+00 ;   z[ 8] =  1.00000e+00 ;
   x[ 9] =  2.00000e+00 ;    y[ 9] = 3.50000e+00 ;   z[ 9] =  1.00000e+00 ;
   x[10] =  0.00000e+00 ;    y[10] = 3.00000e+00 ;   z[10] =  1.50000e+00 ;
   x[11] =  2.00000e+00 ;    y[11] = 3.00000e+00 ;   z[11] =  1.50000e+00 ;
   x[12] =  0.00000e+00 ;    y[12] = 3.00000e+00 ;   z[12] =  0.50000e+00 ;
   x[13] =  2.00000e+00 ;    y[13] = 3.00000e+00 ;   z[13] =  0.50000e+00 ;

   error = ex_put_coord (exoid, x, y, z);
   printf ("after ex_put_coord, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   coord_names[0] = "x";
   coord_names[1] = "y";
   coord_names[2] = "z";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* Write the face block parameters */
   block_names[0] = "face_block_1";
   num_face_in_block[0] = 15;
   num_total_nodes_per_blk[0] = 54;
   bids[0] = 10;

   error = ex_put_block (exoid, EX_FACE_BLOCK, bids[0], "nsided",
			 num_face_in_block[0],
			 num_total_nodes_per_blk[0],
			 0, 0, 0);
   printf ("after ex_put_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   
    
   /* write face connectivity */

   connect = (int *) calloc(num_total_nodes_per_blk[0], sizeof(int));

   i = 0;
   j = 0;

   connect[i++] = 5;
   connect[i++] = 6;
   connect[i++] = 8; /* connectivity of face 1 of element 1 */


   connect[i++] = 2;
   connect[i++] = 1;
   connect[i++] = 4; /* face 2 of element 1 */


   connect[i++] = 6;
   connect[i++] = 2;
   connect[i++] = 4;
   connect[i++] = 8; /* face 3 of element 1 */


   connect[i++] = 8;
   connect[i++] = 4;
   connect[i++] = 1;
   connect[i++] = 5; /* face 4 of element 1 */

   connect[i++] = 1;
   connect[i++] = 2;
   connect[i++] = 6;
   connect[i++] = 5; /*  face 5 of element 1 */

   connect[i++] = 5;
   connect[i++] = 8;
   connect[i++] = 7; /* connectivity of face 1 of element 2 */

   connect[i++] = 1; connect[i++] = 2; connect[i++] = 3; connect[i++] = 4;
   nnpe[j++] = 4;

   connect[i++] = 5; connect[i++] = 3; connect[i++] = 4; connect[i++] = 6;
   nnpe[j++] = 4;

   connect[i++] = 5; connect[i++] = 1; connect[i++] = 2; connect[i++] = 6;
   nnpe[j++] = 4;

   connect[i++] = 6; connect[i++] = 2; connect[i++] = 4;
   nnpe[j++] = 3;

   connect[i++] = 5; connect[i++] = 3; connect[i++] = 1;
   nnpe[j++] = 3;

   assert(i == num_total_nodes_per_blk[0]);
   assert(j == num_face_in_block[0]);

   error = ex_put_conn (exoid, EX_FACE_BLOCK, bids[0], connect, NULL, NULL);
   printf ("after ex_put_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (connect);
   connect = NULL;

   error = ex_put_entity_count_per_polyhedra(exoid, EX_FACE_BLOCK, bids[0], nnpe);
   printf ("after ex_put_entity_count_per_polyhedra, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* write element block parameters */
   block_names[0] = "nfaced_1";

   num_elem_in_block[0] = 1;
   num_total_nodes_per_blk[0] = 6;   /* Do we need this; does it make sense... */
   num_total_faces_per_blk[0] = 5;

   bids[0] = 10;

   error = ex_put_block (exoid, EX_ELEM_BLOCK, bids[0], "nfaced",
			 num_elem_in_block[0],
			 0, 
			 0,
			 num_total_faces_per_blk[0],
			 0);
   printf ("after ex_put_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Write face block names */
   error = ex_put_names(exoid, EX_FACE_BLOCK, block_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   /* Write element block names */
   error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   /* write element-face connectivity */
   connect = (int *) calloc(num_total_faces_per_blk[0], sizeof(int));

   i = 0;
   j = 0;
   connect[i++] = 1; connect[i++] = 2; connect[i++] = 3; connect[i++] = 4;
   connect[i++] = 5;
   nnpe[j++] = 5;  /* Number of faces per element */
   
   assert(i == num_total_faces_per_blk[0]);
   assert(j == num_elem_in_block[0]);

   error = ex_put_conn (exoid, EX_ELEM_BLOCK, bids[0], NULL, NULL, connect);
   printf ("after ex_put_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (connect);

   error = ex_put_entity_count_per_polyhedra(exoid, EX_ELEM_BLOCK, bids[0], nnpe);
   printf ("after ex_put_entity_count_per_polyhedra, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* write QA records; test empty and just blank-filled records */
   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT-NFACED";
   qa_record[0][1] = "testwt-nfaced";
   qa_record[0][2] = "2010/02/15";
   qa_record[0][3] = "06:35:15";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* write information records; test empty and just blank-filled records */
   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }



   /* write results variables parameters and names */
   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   error = ex_put_var_param (exoid, "g", num_glo_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }



   num_nod_vars = 2;
   /*              12345678901234567890123456789012 */
   var_names[0] = "node_variable_a_very_long_name_0";
   var_names[1] = "n";

   error = ex_put_var_param (exoid, "n", num_nod_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "n", num_nod_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   num_ele_vars = 3;

   var_names[0] = "ele_var0";
   var_names[1] = "ele_var1";
   var_names[2] = "ele_var2";

   error = ex_put_var_param (exoid, "e", num_ele_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "e", num_ele_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* write element variable truth table */
   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));

   k = 0;
   for (i=0; i<num_elem_blk; i++)
   {
      for (j=0; j<num_ele_vars; j++)
      {
         truth_tab[k++] = 1;
      }
   }

   error = ex_put_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
   printf ("after ex_put_elem_var_tab, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (truth_tab);


/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 * obviously the analysis code will populate these arrays
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (8, CPU_word_size);
   
   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

     /* write time value */
     error = ex_put_time (exoid, whole_time_step, &time_value);
     printf ("after ex_put_time, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

     /* write global variables */
     for (j=0; j<num_glo_vars; j++)
     {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
                               glob_var_vals);
     printf ("after ex_put_glob_vars, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

     /* write nodal variables */
     for (k=1; k<=num_nod_vars; k++)
     {
       for (j=0; j<num_nodes; j++)
       {
         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
       }

       error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
                                 nodal_var_vals);
       printf ("after ex_put_nodal_var, error = %d\n", error);
       if (error) {
         ex_close (exoid);
         exit(-1);
       }

     }

     /* write element variables */
     for (k=1; k<=num_ele_vars; k++)
     {
       for (j=0; j<num_elem_blk; j++)
       {
         for (m=0; m<num_elem_in_block[j]; m++)
         {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
         }
         error = ex_put_elem_var (exoid, whole_time_step, k, bids[j],
                                  num_elem_in_block[j], elem_var_vals);
         printf ("after ex_put_elem_var, error = %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

     whole_time_step++;
     
     /* update the data file; this should be done at the end of every time step
      * to ensure that no data is lost if the analysis dies
      */
     error = ex_update (exoid);
     printf ("after ex_update, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);
   
   /* close the EXODUS files
    */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   return 0;
}
示例#15
0
int main(int argc, char **argv)
{
  int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
  int num_elem_in_block[10], num_nodes_per_elem[10], num_attr[10];
  int num_node_sets, num_side_sets, error;
  int i, j, k, m, *elem_map, *connect, *node_map;
  int node_list[100], elem_list[100], side_list[100];
  int ebids[10], ids[10];
  int num_nodes_per_set[10], num_elem_per_set[10];
  int num_df_per_set[10];
  int df_ind[10], node_ind[10], elem_ind[10];
  int num_qa_rec, num_info;
  int num_glo_vars, num_nod_vars, num_ele_vars;
  int whole_time_step, num_time_steps;
  int CPU_word_size, IO_word_size;
  int prop_array[2];

  float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
  float  time_value;
  float  x[100], y[100], z[100];
  float  attrib[100], dist_fact[100];
  char * coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  char * prop_names[2];

  ex_opts(EX_VERBOSE | EX_ABORT);

  /* Specify compute and i/o word size */

  CPU_word_size = 0; /* float or double */
  IO_word_size  = 0; /* use system default (4 bytes) */

  /* create EXODUS II file */

  exoid = ex_create("test.exo",     /* filename path */
                    EX_CLOBBER,     /* create mode */
                    &CPU_word_size, /* CPU float word size in bytes */
                    &IO_word_size); /* I/O float word size in bytes */
  printf("after ex_create for test.exo, exoid = %d\n", exoid);
  printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);

  /* initialize file with parameters */

  num_dim       = 3;
  num_nodes     = 28;
  num_elem      = 8;
  num_elem_blk  = 7;
  num_node_sets = 2;
  num_side_sets = 5;
  /* num_side_sets = 6; Uncomment to test NULL side sets */

  error = ex_put_init(exoid, "This is testwt1", num_dim, num_nodes, num_elem, num_elem_blk,
                      num_node_sets, num_side_sets);

  printf("after ex_put_init, error = %d\n", error);

  /* write nodal coordinates values and names to database */

  /* Quad #1 */
  x[0] = 0.0;
  y[0] = 0.0;
  z[0] = 0.0;
  x[1] = 1.0;
  y[1] = 0.0;
  z[1] = 0.0;
  x[2] = 1.0;
  y[2] = 1.0;
  z[2] = 0.0;
  x[3] = 0.0;
  y[3] = 1.0;
  z[3] = 0.0;

  /* Quad #2 */
  x[4] = 1.0;
  y[4] = 0.0;
  z[4] = 0.0;
  x[5] = 2.0;
  y[5] = 0.0;
  z[5] = 0.0;
  x[6] = 2.0;
  y[6] = 1.0;
  z[6] = 0.0;
  x[7] = 1.0;
  y[7] = 1.0;
  z[7] = 0.0;

  /* Hex #1 */
  x[8]  = 0.0;
  y[8]  = 0.0;
  z[8]  = 0.0;
  x[9]  = 10.0;
  y[9]  = 0.0;
  z[9]  = 0.0;
  x[10] = 10.0;
  y[10] = 0.0;
  z[10] = -10.0;
  x[11] = 1.0;
  y[11] = 0.0;
  z[11] = -10.0;
  x[12] = 1.0;
  y[12] = 10.0;
  z[12] = 0.0;
  x[13] = 10.0;
  y[13] = 10.0;
  z[13] = 0.0;
  x[14] = 10.0;
  y[14] = 10.0;
  z[14] = -10.0;
  x[15] = 1.0;
  y[15] = 10.0;
  z[15] = -10.0;

  /* Tetra #1 */
  x[16] = 0.0;
  y[16] = 0.0;
  z[16] = 0.0;
  x[17] = 1.0;
  y[17] = 0.0;
  z[17] = 5.0;
  x[18] = 10.0;
  y[18] = 0.0;
  z[18] = 2.0;
  x[19] = 7.0;
  y[19] = 5.0;
  z[19] = 3.0;

  /* Circle #1 */
  x[20] = 100.0;
  y[20] = 100.0;
  z[20] = 0.0;

  /* Sphere #1 */
  x[21] = 50.0;
  y[21] = 50.0;
  z[21] = 20.0;

  /* Wedge #1 */
  x[22] = 3.0;
  y[22] = 0.0;
  z[22] = 6.0;
  x[23] = 6.0;
  y[23] = 0.0;
  z[23] = 0.0;
  x[24] = 0.0;
  y[24] = 0.0;
  z[24] = 0.0;
  x[25] = 3.0;
  y[25] = 2.0;
  z[25] = 6.0;
  x[26] = 6.0;
  y[26] = 2.0;
  z[26] = 2.0;
  x[27] = 0.0;
  y[27] = 2.0;
  z[27] = 0.0;

  error = ex_put_coord(exoid, x, y, z);
  printf("after ex_put_coord, error = %d\n", error);

  coord_names[0] = "xcoor";
  coord_names[1] = "ycoor";
  coord_names[2] = "zcoor";

  error = ex_put_coord_names(exoid, coord_names);
  printf("after ex_put_coord_names, error = %d\n", error);

  /* write element order map */

  elem_map = (int *)calloc(num_elem, sizeof(int));

  for (i = 1; i <= num_elem; i++) {
    elem_map[i - 1] = i;
  }

  error = ex_put_map(exoid, elem_map);
  printf("after ex_put_map, error = %d\n", error);

  free(elem_map);

  /* write element numbering map */

  elem_map = (int *)calloc(num_elem, sizeof(int));

  for (i = 1; i <= num_elem; i++) {
    elem_map[i - 1] = i * 2;
  }

  error = ex_put_id_map(exoid, EX_ELEM_MAP, elem_map);
  printf("after ex_put_elem_num_map, error = %d\n", error);

  free(elem_map);

  /* write node numbering map */

  node_map = (int *)calloc(num_nodes, sizeof(int));

  for (i = 1; i <= num_nodes; i++) {
    node_map[i - 1] = i * 3;
  }

  error = ex_put_id_map(exoid, EX_NODE_MAP, node_map);
  printf("after ex_put_node_num_map, error = %d\n", error);

  free(node_map);

  /* write element block parameters */

  num_elem_in_block[0] = 1; /* element 1: Quad 1 */
  num_elem_in_block[1] = 2; /* elements 2, 3: Quad 1 & 2 */
  num_elem_in_block[2] = 1; /* element 4: Hex    */
  num_elem_in_block[3] = 1; /* element 5: Tetra  */
  num_elem_in_block[4] = 1; /* element 6: Circle */
  num_elem_in_block[5] = 1; /* element 7: Sphere */
  num_elem_in_block[6] = 1; /* element 8: Wedge  */

  num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */
  num_nodes_per_elem[4] = 1; /* elements in block #4 are 1-node circles */
  num_nodes_per_elem[5] = 1; /* elements in block #5 are 1-node spheres */
  num_nodes_per_elem[6] = 6; /* elements in block #6 are 6-node wedges */

  ebids[0] = 10;
  ebids[1] = 11;
  ebids[2] = 12;
  ebids[3] = 13;
  ebids[4] = 14;
  ebids[5] = 15;
  ebids[6] = 16;

  num_attr[0] = 3;
  num_attr[1] = 3;
  num_attr[2] = 3;
  num_attr[3] = 3;
  num_attr[4] = 3;
  num_attr[5] = 3;
  num_attr[6] = 3;

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "quad", num_elem_in_block[0],
                       num_nodes_per_elem[0], 0, 0, num_attr[0]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[1], "quad", num_elem_in_block[1],
                       num_nodes_per_elem[1], 0, 0, num_attr[1]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[2], "hex", num_elem_in_block[2],
                       num_nodes_per_elem[2], 0, 0, num_attr[2]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[3], "tetra", num_elem_in_block[3],
                       num_nodes_per_elem[3], 0, 0, num_attr[3]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[4], "circle", num_elem_in_block[4],
                       num_nodes_per_elem[4], 0, 0, num_attr[4]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[5], "sphere", num_elem_in_block[5],
                       num_nodes_per_elem[5], 0, 0, num_attr[5]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[6], "wedge", num_elem_in_block[6],
                       num_nodes_per_elem[6], 0, 0, num_attr[6]);
  printf("after ex_put_elem_block, error = %d\n", error);

  /* write element block properties */

  prop_names[0] = "MATL";
  prop_names[1] = "DENSITY";
  error         = ex_put_prop_names(exoid, EX_ELEM_BLOCK, 2, prop_names);
  printf("after ex_put_prop_names, error = %d\n", error);

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], "MATL", 60);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], "MATL", 70);
  printf("after ex_put_prop, error = %d\n", error);

  /* write element connectivity */

  connect    = (int *)calloc(8, sizeof(int));
  connect[0] = 1;
  connect[1] = 2;
  connect[2] = 3;
  connect[3] = 4;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 1;
  connect[1] = 2;
  connect[2] = 3;
  connect[3] = 4;
  connect[4] = 5;
  connect[5] = 6;
  connect[6] = 7;
  connect[7] = 8;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[1], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 9;
  connect[1] = 10;
  connect[2] = 11;
  connect[3] = 12;
  connect[4] = 13;
  connect[5] = 14;
  connect[6] = 15;
  connect[7] = 16;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 17;
  connect[1] = 18;
  connect[2] = 19;
  connect[3] = 20;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[3], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 21;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[4], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 22;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[5], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 23;
  connect[1] = 24;
  connect[2] = 25;
  connect[3] = 26;
  connect[4] = 27;
  connect[5] = 28;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[6], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  free(connect);

  /* write element block attributes  (3 per block) */

  attrib[0]  = 1.0;
  attrib[1]  = 2.0;
  attrib[2]  = 3.0;
  attrib[3]  = 1.11;
  attrib[4]  = 2.11;
  attrib[5]  = 3.11;
  attrib[6]  = 1.12;
  attrib[7]  = 2.12;
  attrib[8]  = 3.12;
  attrib[9]  = 1.2;
  attrib[10] = 2.2;
  attrib[11] = 3.2;
  attrib[12] = 1.3;
  attrib[13] = 2.3;
  attrib[14] = 3.3;
  attrib[15] = 1.4;
  attrib[16] = 2.4;
  attrib[17] = 3.4;
  attrib[18] = 1.5;
  attrib[19] = 2.5;
  attrib[20] = 3.5;
  attrib[21] = 1.6;
  attrib[22] = 2.6;
  attrib[23] = 3.6;

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], &attrib[0]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[1], &attrib[3]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[2], &attrib[9]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[3], &attrib[12]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[4], &attrib[15]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[5], &attrib[18]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[6], &attrib[21]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  /* write individual node sets */

  ids[0] = 20;
  ids[1] = 21;

  num_nodes_per_set[0] = 5;
  num_nodes_per_set[1] = 3;
  /* num_nodes_per_set[1] = 0; Uncomment to test NULL node sets */

  node_ind[0] = 0;
  node_ind[1] = 5;

  node_list[0] = 10;
  node_list[1] = 11;
  node_list[2] = 12;
  node_list[3] = 13;
  node_list[4] = 14;
  node_list[5] = 20;
  node_list[6] = 21;
  node_list[7] = 22;

  num_df_per_set[0] = 5;
  num_df_per_set[1] = 3;

  df_ind[0] = 0;
  df_ind[1] = 5;

  dist_fact[0] = 1.0;
  dist_fact[1] = 2.0;
  dist_fact[2] = 3.0;
  dist_fact[3] = 4.0;
  dist_fact[4] = 5.0;
  dist_fact[5] = 1.1;
  dist_fact[6] = 2.1;
  dist_fact[7] = 3.1;

  {
    struct ex_set_specs set_specs;

    set_specs.sets_ids            = ids;
    set_specs.num_entries_per_set = num_nodes_per_set;
    set_specs.num_dist_per_set    = num_df_per_set;
    set_specs.sets_entry_index    = node_ind;
    set_specs.sets_dist_index     = df_ind;
    set_specs.sets_entry_list     = node_list;
    set_specs.sets_extra_list     = NULL;
    set_specs.sets_dist_fact      = dist_fact;
    error                         = ex_put_concat_sets(exoid, EX_NODE_SET, &set_specs);
  }

  printf("after ex_put_concat_node_sets, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  printf("after ex_put_prop, error = %d\n", error);

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  printf("after ex_put_prop_array, error = %d\n", error);

  ids[0] = 30;
  ids[1] = 31;
  ids[2] = 32;
  ids[3] = 33;
  ids[4] = 34;
  ids[5] = 35;

  /* side set #1  - quad */
  node_list[0] = 8;
  node_list[1] = 5;
  node_list[2] = 6;
  node_list[3] = 7;

  /* side set #2  - quad/hex, spanning 2 element types  */
  node_list[4] = 2;
  node_list[5] = 3;
  node_list[6] = 7;
  node_list[7] = 8;

  /* side set #3  - hex */
  node_list[8]  = 9;
  node_list[9]  = 12;
  node_list[10] = 11;
  node_list[11] = 10;

  node_list[12] = 11;
  node_list[13] = 12;
  node_list[14] = 16;
  node_list[15] = 15;

  node_list[16] = 16;
  node_list[17] = 15;
  node_list[18] = 11;
  node_list[19] = 12;

  node_list[20] = 10;
  node_list[21] = 11;
  node_list[22] = 15;
  node_list[23] = 14;

  node_list[24] = 13;
  node_list[25] = 16;
  node_list[26] = 12;
  node_list[27] = 9;

  node_list[28] = 14;
  node_list[29] = 13;
  node_list[30] = 9;
  node_list[31] = 10;

  node_list[32] = 16;
  node_list[33] = 13;
  node_list[34] = 14;
  node_list[35] = 15;

  /* side set #4  - tetras */
  node_list[36] = 17;
  node_list[37] = 18;
  node_list[38] = 20;

  node_list[39] = 18;
  node_list[40] = 19;
  node_list[41] = 20;

  node_list[42] = 20;
  node_list[43] = 19;
  node_list[44] = 17;

  node_list[45] = 19;
  node_list[46] = 18;
  node_list[47] = 17;

  /* side set #5  - circle and sphere */
  node_list[48] = 21;
  node_list[49] = 22;

  /* side set #6  - wedges */
  node_list[50] = 27;
  node_list[51] = 26;
  node_list[52] = 23;
  node_list[53] = 24;

  node_list[54] = 28;
  node_list[55] = 27;
  node_list[56] = 24;
  node_list[57] = 25;

  node_list[58] = 28;
  node_list[59] = 25;
  node_list[60] = 23;
  node_list[61] = 26;

  node_list[62] = 25;
  node_list[63] = 24;
  node_list[64] = 23;

  node_list[65] = 26;
  node_list[66] = 27;
  node_list[67] = 28;

  node_ind[0] = 0;
  node_ind[1] = 4;
  node_ind[2] = 8;
  node_ind[3] = 36;
  node_ind[4] = 47;
  node_ind[5] = 49;

  num_elem_per_set[0] = 2; /* two sides uses 2 elements */
  num_elem_per_set[1] = 2;
  num_elem_per_set[2] = 7;
  num_elem_per_set[3] = 4;
  num_elem_per_set[4] = 2;
  num_elem_per_set[5] = 5;
  /* num_elem_per_set[5] = 0; Uncomment to test NULL side sets */

  num_nodes_per_set[0] = 4;
  num_nodes_per_set[1] = 4;
  num_nodes_per_set[2] = 28;
  num_nodes_per_set[3] = 12;
  num_nodes_per_set[4] = 2;
  num_nodes_per_set[5] = 18;

  elem_ind[0] = 0;
  elem_ind[1] = 2;
  elem_ind[2] = 4;
  elem_ind[3] = 11;
  elem_ind[4] = 15;
  elem_ind[5] = 17;

  elem_list[0]  = 3;
  elem_list[1]  = 3; /* side set 1: Quad #2 */
  elem_list[2]  = 1;
  elem_list[3]  = 3; /* side set 2: Quad #1 & #2 */
  elem_list[4]  = 4;
  elem_list[5]  = 4; /* side set 3: Hex */
  elem_list[6]  = 4;
  elem_list[7]  = 4;
  elem_list[8]  = 4;
  elem_list[9]  = 4;
  elem_list[10] = 4;
  elem_list[11] = 5;
  elem_list[12] = 5; /* side set 4: Tetra */
  elem_list[13] = 5;
  elem_list[14] = 5;
  elem_list[15] = 6;
  elem_list[16] = 7; /* side set 5: Circle & Sphere */
  elem_list[17] = 8;
  elem_list[18] = 8; /* side set 6: Wedge  */
  elem_list[19] = 8;
  elem_list[20] = 8;
  elem_list[21] = 8;

  error = ex_cvt_nodes_to_sides(exoid, num_elem_per_set, num_nodes_per_set, elem_ind, node_ind,
                                elem_list, node_list, side_list);
  printf("after ex_cvt_nodes_to_sides, error = %d\n", error);

  num_df_per_set[0] = 4;
  num_df_per_set[1] = 4;
  num_df_per_set[2] = 0;
  num_df_per_set[3] = 0;
  num_df_per_set[4] = 0;
  num_df_per_set[5] = 0;

  df_ind[0] = 0;
  df_ind[1] = 4;

  /* side set #1 df */
  dist_fact[0] = 30.0;
  dist_fact[1] = 30.1;
  dist_fact[2] = 30.2;
  dist_fact[3] = 30.3;

  /* side set #2 df */
  dist_fact[4] = 31.0;
  dist_fact[5] = 31.1;
  dist_fact[6] = 31.2;
  dist_fact[7] = 31.3;

  {
    struct ex_set_specs set_specs;

    set_specs.sets_ids            = ids;
    set_specs.num_entries_per_set = num_elem_per_set;
    set_specs.num_dist_per_set    = num_df_per_set;
    set_specs.sets_entry_index    = elem_ind;
    set_specs.sets_dist_index     = df_ind;
    set_specs.sets_entry_list     = elem_list;
    set_specs.sets_extra_list     = side_list;
    set_specs.sets_dist_fact      = dist_fact;
    error                         = ex_put_concat_sets(exoid, EX_SIDE_SET, &set_specs);
  }
  printf("after ex_put_concat_side_sets, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  printf("after ex_put_prop, error = %d\n", error);

  /* write QA records */

  num_qa_rec = 2;

  qa_record[0][0] = "TESTWT1";
  qa_record[0][1] = "testwt1";
  qa_record[0][2] = "03/16/94";
  qa_record[0][3] = "15:41:33";
  qa_record[1][0] = "FASTQ";
  qa_record[1][1] = "fastq";
  qa_record[1][2] = "07/07/93";
  qa_record[1][3] = "16:41:33";

  error = ex_put_qa(exoid, num_qa_rec, qa_record);
  printf("after ex_put_qa, error = %d\n", error);

  /* write information records */

  num_info = 3;

  info[0] = "This is the first information record.";
  info[1] = "This is the second information record.";
  info[2] = "This is the third information record.";

  error = ex_put_info(exoid, num_info, info);
  printf("after ex_put_info, error = %d\n", error);

  /* write results variables parameters and names */

  num_glo_vars = 1;

  var_names[0] = "glo vars";

  error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_name(exoid, EX_GLOBAL, 1, var_names[0]);
  printf("after ex_put_variable_name, error = %d\n", error);

  num_nod_vars = 2;

  var_names[0] = "nod_var0";
  var_names[1] = "nod_var1";

  error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_ele_vars = 3;

  var_names[0] = "ele_var0";
  var_names[1] = "ele_var1";
  var_names[2] = "ele_var2";

  error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  /* for each time step, write the analysis results;
   * the code below fills the arrays glob_var_vals,
   * nodal_var_vals, and elem_var_vals with values for debugging purposes;
   * obviously the analysis code will populate these arrays
   */

  whole_time_step = 1;
  num_time_steps  = 10;

  glob_var_vals  = (float *)calloc(num_glo_vars, CPU_word_size);
  nodal_var_vals = (float *)calloc(num_nodes, CPU_word_size);
  elem_var_vals  = (float *)calloc(4, CPU_word_size);

  for (i = 0; i < num_time_steps; i++) {
    time_value = (float)(i + 1) / 100.;

    /* write time value */

    error = ex_put_time(exoid, whole_time_step, &time_value);
    printf("after ex_put_time, error = %d\n", error);

    /* write global variables */

    for (j = 0; j < num_glo_vars; j++) {
      glob_var_vals[j] = (float)(j + 2) * time_value;
    }

    error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
    printf("after ex_put_glob_vars, error = %d\n", error);

    /* write nodal variables */

    for (k = 1; k <= num_nod_vars; k++) {
      for (j = 0; j < num_nodes; j++) {
        nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
      }

      error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
      printf("after ex_put_nodal_var, error = %d\n", error);
    }

    /* write element variables */

    for (k = 1; k <= num_ele_vars; k++) {
      for (j = 0; j < num_elem_blk; j++) {
        for (m = 0; m < num_elem_in_block[j]; m++) {
          elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
          /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
        }
        if (k == 1 && j == 2)
          continue; /* skip element block 3, variable 1 */
        else {
          error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j],
                             num_elem_in_block[j], elem_var_vals);
          printf("after ex_put_elem_var, error = %d\n", error);
        }
      }
    }

    whole_time_step++;

    /* update the data file; this should be done at the end of every time step
     * to ensure that no data is lost if the analysis dies
     */
    error = ex_update(exoid);
    printf("after ex_update, error = %d\n", error);
  }
  free(glob_var_vals);
  free(nodal_var_vals);
  free(elem_var_vals);

  /* close the EXODUS files
   */
  error = ex_close(exoid);
  printf("after ex_close, error = %d\n", error);
  return 0;
}
示例#16
0
int ex_create (const char *path,
               int   cmode,
               int  *comp_ws,
               int  *io_ws)
{
   int exoid, time_dim, dims[1];
   nclong lio_ws;
   nclong filesiz;
   float vers;
   char errmsg[MAX_ERR_LENGTH];
   char *mode_name;
   int mode = 0;
   
   exerrval = 0; /* clear error code */

   /*
    * See if "large file" mode was specified in a ex_create cmode. If
    * so, then pass the NC_64BIT_OFFSET flag down to netcdf.
    */
   if (cmode & EX_LARGE_MODEL || ex_large_model(-1) == 1) {
     mode |= NC_64BIT_OFFSET;
   }

/*
 * set error handling mode to no messages, non-fatal errors
 */
  ex_opts(exoptval);    /* call required to set ncopts first time through */

   if (cmode & EX_NOCLOBBER) {
     mode |= NC_NOCLOBBER;
     mode_name = "NOCLOBBER";
   } else if (cmode & EX_CLOBBER) {
     mode |= NC_CLOBBER;
     mode_name = "CLOBBER";
   } else {
     exerrval = EX_BADFILEMODE;
     sprintf(errmsg,"Error: invalid file create mode: %d, for file %s",
             cmode,path);
     ex_err("ex_create",errmsg,exerrval);
     return (EX_FATAL);
   }

#ifndef TFLOP
   mode |= NC_SHARE;
#endif
   
   if ((exoid = nccreate (path, mode)) == -1) {
     exerrval = ncerr;
     sprintf(errmsg,
             "Error: file create failed for %s, mode: %s",
             path, mode_name);
     ex_err("ex_create",errmsg,exerrval);
     return (EX_FATAL);
   }

/* turn off automatic filling of netCDF variables
 */

  if (ncsetfill (exoid, NC_NOFILL) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to set nofill mode in file id %d",
            exoid);
    ex_err("ex_create", errmsg, exerrval);
    return (EX_FATAL);
  }

/* initialize floating point size conversion.  since creating new file, 
 * i/o wordsize attribute from file is zero.
 */

   if (ex_conv_ini( exoid, comp_ws, io_ws, 0 ) != EX_NOERR) {
     exerrval = EX_FATAL;
     sprintf(errmsg,
           "Error: failed to init conversion routines in file id %d",
            exoid);
     ex_err("ex_create", errmsg, exerrval);
     return (EX_FATAL);
   }

/* put the EXODUS version number, and i/o floating point word size as
 * netcdf global attributes
 */

/* store Exodus API version # as an attribute */
  vers = (float)(EX_API_VERS);
  if (ncattput (exoid, NC_GLOBAL, ATT_API_VERSION, NC_FLOAT, 1, &vers) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
         "Error: failed to store Exodus II API version attribute in file id %d",
            exoid);
    ex_err("ex_create",errmsg, exerrval);
    return (EX_FATAL);
  }

/* store Exodus file version # as an attribute */
  vers = (float)(EX_VERS);
  if (ncattput (exoid, NC_GLOBAL, ATT_VERSION, NC_FLOAT, 1, &vers) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
        "Error: failed to store Exodus II file version attribute in file id %d",
            exoid);
    ex_err("ex_create",errmsg, exerrval);
    return (EX_FATAL);
  }

/* store Exodus file float word size  as an attribute */
  lio_ws = (nclong)(*io_ws);
  if (ncattput (exoid, NC_GLOBAL, ATT_FLT_WORDSIZE, NC_LONG, 1, &lio_ws) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
 "Error: failed to store Exodus II file float word size attribute in file id %d",
           exoid);
    ex_err("ex_create",errmsg, exerrval);
    return (EX_FATAL);
  }

  /* store Exodus file size (1=large, 0=normal) as an attribute */
  filesiz = (nclong)(((cmode & EX_LARGE_MODEL) != 0) || (ex_large_model(-1) == 1));
  if (ncattput (exoid, NC_GLOBAL, ATT_FILESIZE, NC_LONG, 1, &filesiz) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to store Exodus II file size attribute in file id %d",
              exoid);
      ex_err("ex_create",errmsg, exerrval);
      return (EX_FATAL);
    }
  
  /* define some dimensions and variables
   */
  
  /* create string length dimension */
  if (ncdimdef (exoid, DIM_STR, (MAX_STR_LENGTH+1)) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to define string length in file id %d",exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }


  /* create line length dimension */
  if (ncdimdef (exoid, DIM_LIN, (MAX_LINE_LENGTH+1)) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to define line length in file id %d",exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* create number "4" dimension; must be of type long */
  if (ncdimdef (exoid, DIM_N4, 4L) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to define number \"4\" dimension in file id %d",exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }


  if ((time_dim = ncdimdef (exoid, DIM_TIME, NC_UNLIMITED)) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to define time dimension in file id %d", exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }

  dims[0] = time_dim;
  if ((ncvardef (exoid, VAR_WHOLE_TIME, nc_flt_code(exoid), 1, dims)) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to define whole time step variable in file id %d",
            exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ncendef (exoid) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to complete definition for file id %d", exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }

  return (exoid);
}
示例#17
0
int read_exoII_file(int Proc,
                    int Num_Proc,
                    PROB_INFO_PTR prob,
                    PARIO_INFO_PTR pio_info,
                    MESH_INFO_PTR mesh)
{
#ifndef ZOLTAN_NEMESIS
  Gen_Error(0, "Fatal:  Nemesis requested but not linked with driver.");
  return 0;

#else /* ZOLTAN_NEMESIS */
  /* Local declarations. */
  char  *yo = "read_exoII_mesh";
  char   par_nem_fname[FILENAME_MAX+1], title[MAX_LINE_LENGTH+1];
  char   cmesg[256];

  float  ver;

  int    i, pexoid, cpu_ws = 0, io_ws = 0;
  int   *nnodes = NULL, *etypes = NULL;
#ifdef DEBUG_EXO
  int    j, k, elem;
#endif
  FILE  *fdtmp;

/***************************** BEGIN EXECUTION ******************************/

  DEBUG_TRACE_START(Proc, yo);

  /* since this is a test driver, set error reporting in exodus */
  ex_opts(EX_VERBOSE | EX_DEBUG);

  /* generate the parallel filename for this processor */
  gen_par_filename(pio_info->pexo_fname, par_nem_fname, pio_info, Proc,
                   Num_Proc);

  /* 
   * check whether parallel file exists.  do the check with fopen 
   * as ex_open coredumps on the paragon when files do not exist.
   */

  if ((fdtmp = fopen(par_nem_fname, "r")) == NULL) {
    sprintf(cmesg,"fatal: parallel Exodus II file %s does not exist",
            par_nem_fname);
    Gen_Error(0, cmesg);
    return 0;
  }
  else
    fclose(fdtmp);

  /*
   * now open the existing parallel file using Exodus calls.
   */

  if ((pexoid = ex_open(par_nem_fname, EX_READ, &cpu_ws, &io_ws,
                        &ver)) < 0) {
    sprintf(cmesg,"fatal: could not open parallel Exodus II file %s",
            par_nem_fname);
    Gen_Error(0, cmesg);
    return 0;
  }

  /* and get initial information */
  if (ex_get_init(pexoid, title, &(mesh->num_dims),
                  &(mesh->num_nodes), &(mesh->num_elems),
                  &(mesh->num_el_blks), &(mesh->num_node_sets),
                  &(mesh->num_side_sets)) < 0) {
    Gen_Error(0, "fatal: Error returned from ex_get_init");
    return 0;
  }


  /* alocate some memory for the element blocks */
  mesh->data_type = MESH;
  mesh->vwgt_dim = 1;  /* One weight for now. */
  mesh->ewgt_dim = 1;  /* One weight for now. */
  mesh->eb_etypes = (int *) malloc (5 * mesh->num_el_blks * sizeof(int));
  if (!mesh->eb_etypes) {
    Gen_Error(0, "fatal: insufficient memory");
    return 0;
  }
  mesh->eb_ids = mesh->eb_etypes + mesh->num_el_blks;
  mesh->eb_cnts = mesh->eb_ids + mesh->num_el_blks;
  mesh->eb_nnodes = mesh->eb_cnts + mesh->num_el_blks;
  mesh->eb_nattrs = mesh->eb_nnodes + mesh->num_el_blks;

  mesh->eb_names = (char **) malloc (mesh->num_el_blks * sizeof(char *));
  if (!mesh->eb_names) {
    Gen_Error(0, "fatal: insufficient memory");
    return 0;
  }

  mesh->hindex = (int *) malloc(sizeof(int));
  mesh->hindex[0] = 0;

  if (ex_get_elem_blk_ids(pexoid, mesh->eb_ids) < 0) {
    Gen_Error(0, "fatal: Error returned from ex_get_elem_blk_ids");
    return 0;
  }

  /* allocate temporary storage for items needing global reduction.   */
  /* nemesis does not store most element block info about blocks for  */
  /* which the processor owns no elements.                            */
  /* we, however, use this information in migration, so we need to    */
  /* accumulate it for all element blocks.    kdd 2/2001              */

  if (mesh->num_el_blks > 0) {
    nnodes = (int *) malloc(2 * mesh->num_el_blks * sizeof(int));
    if (!nnodes) {
      Gen_Error(0, "fatal: insufficient memory");
      return 0;
    }
    etypes = nnodes + mesh->num_el_blks;
  }

  /* get the element block information */
  for (i = 0; i < mesh->num_el_blks; i++) {

    /* allocate space for name */
    mesh->eb_names[i] = (char *) malloc((MAX_STR_LENGTH+1) * sizeof(char));
    if (!mesh->eb_names[i]) {
      Gen_Error(0, "fatal: insufficient memory");
      return 0;
    }

    if (ex_get_elem_block(pexoid, mesh->eb_ids[i], mesh->eb_names[i],
                          &(mesh->eb_cnts[i]), &(nnodes[i]),
                          &(mesh->eb_nattrs[i])) < 0) {
      Gen_Error(0, "fatal: Error returned from ex_get_elem_block");
      return 0;
    }

    if (mesh->eb_cnts[i] > 0) {
      if ((etypes[i] =  (int) get_elem_type(mesh->eb_names[i],
                                            nnodes[i],
                                            mesh->num_dims)) == E_TYPE_ERROR) {
        Gen_Error(0, "fatal: could not get element type");
        return 0;
      }
    }
    else etypes[i] = (int) NULL_EL;
  }

  /* Perform reduction on necessary fields of element blocks.  kdd 2/2001 */
  MPI_Allreduce(nnodes, mesh->eb_nnodes, mesh->num_el_blks, MPI_INT, MPI_MAX, 
                MPI_COMM_WORLD);
  MPI_Allreduce(etypes, mesh->eb_etypes, mesh->num_el_blks, MPI_INT, MPI_MIN, 
                MPI_COMM_WORLD);
  for (i = 0; i < mesh->num_el_blks; i++) {
    strcpy(mesh->eb_names[i], get_elem_name(mesh->eb_etypes[i]));
  }
  free(nnodes);

  /*
   * allocate memory for the elements
   * allocate a little extra for element migration latter
   */
  mesh->elem_array_len = mesh->num_elems + 5;
  mesh->elements = (ELEM_INFO_PTR) malloc (mesh->elem_array_len 
                                         * sizeof(ELEM_INFO));
  if (!(mesh->elements)) {
    Gen_Error(0, "fatal: insufficient memory");
    return 0;
  }

  /*
   * intialize all of the element structs as unused by
   * setting the globalID to -1
   */
  for (i = 0; i < mesh->elem_array_len; i++) 
    initialize_element(&(mesh->elements[i]));

  /* read the information for the individual elements */
  if (!read_elem_info(pexoid, Proc, prob, mesh)) {
    Gen_Error(0, "fatal: Error returned from read_elem_info");
    return 0;
  }

  /* read the communication information */
  if (!read_comm_map_info(pexoid, Proc, prob, mesh)) {
    Gen_Error(0, "fatal: Error returned from read_comm_map_info");
    return 0;
  }

  /* Close the parallel file */
  if(ex_close (pexoid) < 0) {
    Gen_Error(0, "fatal: Error returned from ex_close");
    return 0;
  }

  /* print out the distributed mesh */
  if (Debug_Driver > 3)
    print_distributed_mesh(Proc, Num_Proc, mesh);

  DEBUG_TRACE_END(Proc, yo);
  return 1;

#endif /* ZOLTAN_NEMESIS */
}
示例#18
0
int main(int argc, char *argv[])
{

  /* Local function calls */
  int   ne_test_glbp(int);
  int   ne_test_piinf(int);
  int   ne_test_pinig(int);
  int   ne_test_pelbid(int);
  int	ne_test_pnsp(int);
  int	ne_test_pssp(int);
  int	ne_test_pnm(int);
  int	ne_test_pem(int);
  int	ne_test_pcmp(int);
  int	ne_test_pncm(int);
  int	ne_test_pecm(int);

  int   ne_test_giinf(int);
  int	ne_test_ginig(int);
  int   ne_test_gelbid(int);
  int   ne_test_gnsp(int);
  int   ne_test_gssp(int);
  int	ne_test_gnm(int);
  int	ne_test_gem(int);
  int   ne_test_gncm(int);
  int 	ne_test_gecm(int);

  int	ne_test_plbpc(int);
  int   ne_test_pcmpc(int);

  /* Unitialized local variables */
  int     ne_file_id;
  char    test_direc[256], file_name[256];
  float	  version;

  /* Initialized local variables */
  int    mode3 = EX_CLOBBER;
  int    mode4 = EX_CLOBBER|EX_NETCDF4|EX_NOCLASSIC;

  char  *yo="main";
  int    io_ws=0, cpu_ws=0, t_pass=0, t_fail=0;
  int    debug_flag=0;

/*-----------------------------Execution Begins-----------------------------*/

  /* Get the location of the temporary file to use for the test */
  if (argc <= 1) {
    /* Nothing specified. Use defaults. */
    strcpy(file_name, "./ne_test.exoII");
  }
  else if (argc == 2) {
    /* Test for the help flag */
    if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-?") == 0) {
      /* Output the help line */
      printf("Usage:\n\tne_test <optional directory> <optional file name>\n");
      exit(0);
    }
    /* Test for the debug flag */
    else if (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "-d") == 0) {
      printf("****DEBUG MODE****\n");
      ex_opts(EX_VERBOSE | EX_DEBUG);
      strcpy(file_name, "./ne_test.exoII");
      debug_flag = 1;
    }
    /* Else get the directory name and assign default name */
    else {
      strcpy(test_direc, argv[1]);
      if (test_direc[strlen(test_direc)-1] != '/') {
        strcpy(file_name, test_direc);
        strcat(file_name, "/ne_test.exoII");
      }
      else {
        strcpy(file_name, test_direc);
        strcat(file_name, "ne_test.exoII");
      }
    }
  }
  else if (argc == 3) {
    /* Both directory and file name specified */
    strcpy(test_direc, argv[1]);
    if (test_direc[strlen(test_direc)-1] == '/') {
      strcpy(file_name, test_direc);
      strcat(file_name, "/");
      strcat(file_name, argv[2]);
    }
    else {
      strcpy(file_name, test_direc);
      strcat(file_name, argv[2]);
    }
  }

/*---------------------------------------------------------------------------*/
/*                      OUTPUT TEST SECTION                                  */
/*---------------------------------------------------------------------------*/

  printf("*********************Output Tests***********************\n");

  /* Create the ExodusII/Nemesis file */
  printf("creating ExodusII file..."); fflush(stdout);

  /* Attempt to create a netcdf4-format file; if it fails, then assume
     that the netcdf library does not support that mode and fall back
     to classic netcdf3 format.  If that fails, issue an error and
     die.
  */
  if ((ne_file_id=ex_create(file_name, mode4, &cpu_ws, &io_ws)) < 0) {
    /* netcdf4 create failed, try netcdf3 */
    if ((ne_file_id=ex_create(file_name, mode3, &cpu_ws, &io_ws)) < 0) {
      printf("FAILED\n");
      t_fail++;
      fprintf(stderr, "[%s]: ERROR, unable to create test file \"%s\"!\n",
	      yo, file_name);
      exit(-1);
    } else {
      printf(" (netcdf3 format) ");
    }
  } else {
    printf(" (netcdf4 format) ");
  }
  printf("successful\n"); fflush(stdout);
  t_pass++;

  /* Test the output of initial information */
  printf("testing init info output..."); fflush(stdout);
  if (ne_test_piinf(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test the output of initial global information */
  printf("testing global init info output..."); fflush(stdout);
  if (ne_test_pinig(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test the output of the global element block IDs */
  printf("testing global element block ID output..."); fflush(stdout);
  if (ne_test_pelbid(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test the output of the global node-set info */
  printf("testing global node-set params output..."); fflush(stdout);
  if (ne_test_pnsp(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test the output of the global side-set info */
  printf("testing global side-set params output..."); fflush(stdout);
  if (ne_test_pssp(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test the output of the concatenated load-balance parameters */
  printf("testing concatenated load balance info output...");
  fflush(stdout);
  if (ne_test_plbpc(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
  }
  else {
    printf("succesful\n"); fflush(stdout);
  }

  /* Test the output of the node map */
  printf("testing node map output..."); fflush(stdout);
  if (ne_test_pnm(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test the output of the element map */
  printf("testing element map output..."); fflush(stdout);
  if (ne_test_pem(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test the output of the concatenated communication map params */
  printf("testing concatenated communication map params output...");
  fflush(stdout);
  if (ne_test_pcmpc(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test nodal communication map output */
  printf("testing nodal communication map output..."); fflush(stdout);
  if (ne_test_pncm(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test elemental communication map output */
  printf("testing elemental communication map output..."); fflush(stdout);
  if (ne_test_pecm(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Close the ExodusII/Nemesis test file */
  printf("closing ExodusII file..."); fflush(stdout);
  if (ex_close(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
    fprintf(stderr, "[%s]: ERROR, unable to close test file \"%s\"!\n",
            yo, file_name);
    exit(-1);
  }
  printf("successful\n"); fflush(stdout);
  t_pass++;

/*---------------------------------------------------------------------------*/
/*                       INPUT TEST SECTION                                  */
/*---------------------------------------------------------------------------*/

  printf("**********************Input Tests***********************\n");

  /* Re-open the ExodusII/NemesisI file */
  printf("reopening ExodusII file..."); fflush(stdout);
  if (ex_open(file_name, EX_READ, &cpu_ws, &io_ws, &version) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test read of of the initial information */
  printf("testing init info input..."); fflush(stdout);
  if (ne_test_giinf(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test read of initial global information */
  printf("testing global init info input..."); fflush(stdout);
  if (ne_test_ginig(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test read of global element block IDs */
  printf("testing global element block IDs input..."); fflush(stdout);
  if (ne_test_gelbid(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test read of global node-set params */
  printf("testing global node-set params input..."); fflush(stdout);
  if (ne_test_gnsp(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test read of global side-set params */
  printf("testing global side-set params input..."); fflush(stdout);
  if (ne_test_gssp(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test read of load-balance params */
  printf("testing load-balance params input..."); fflush(stdout);
  if (ne_test_glbp(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test read of the node map */
  printf("testing node map input..."); fflush(stdout);
  if (ne_test_gnm(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test read of element map */
  printf("testing element map input..."); fflush(stdout);
  if (ne_test_gem(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test read of nodal communication maps */
  printf("testing nodal communication map input..."); fflush(stdout);
  if (ne_test_gncm(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Test read of elemental communication maps */
  printf("testing elemental communication map input..."); fflush(stdout);
  if (ne_test_gecm(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    if (debug_flag == 1)
      return 1;
  }
  else {
    printf("successful\n"); fflush(stdout);
    t_pass++;
  }

  /* Close the ExodusII/Nemesis test file */
  printf("closing ExodusII file..."); fflush(stdout);
  if (ex_close(ne_file_id) < 0) {
    printf("FAILED\n"); fflush(stdout);
    t_fail++;
    fprintf(stderr, "[%s]: ERROR, unable to close test file \"%s\"!\n",
            yo, file_name);
    exit(-1);
  }
  printf("successful\n"); fflush(stdout);
  t_pass++;

  /* Output a test summary */
  printf("\n");
  printf("Tests Passed: %d\n", t_pass);
  printf("Tests Failed: %d\n", t_fail);

  return 0;
}
示例#19
0
文件: ex_open.c 项目: jpouderoux/VTK
int ex_open_int(const char *path, int mode, int *comp_ws, int *io_ws, float *version,
                int run_version)
{
  int     exoid;
  int     status, stat_att, stat_dim;
  nc_type att_type = NC_NAT;
  size_t  att_len  = 0;
  int     old_fill;
  int     file_wordsize;
  int     dim_str_name;
  int     int64_status = 0;
  int     nc_mode      = 0;

  char errmsg[MAX_ERR_LENGTH];

  EX_FUNC_ENTER();

  /* set error handling mode to no messages, non-fatal errors */
  ex_opts(exoptval); /* call required to set ncopts first time through */

  if (run_version != EX_API_VERS_NODOT && warning_output == 0) {
    int run_version_major = run_version / 100;
    int run_version_minor = run_version % 100;
    int lib_version_major = EX_API_VERS_NODOT / 100;
    int lib_version_minor = EX_API_VERS_NODOT % 100;
    fprintf(stderr,
            "EXODUS: Warning: This code was compiled with exodus "
            "version %d.%02d,\n          but was linked with exodus "
            "library version %d.%02d\n          This is probably an "
            "error in the build process of this code.\n",
            run_version_major, run_version_minor, lib_version_major, lib_version_minor);
    warning_output = 1;
  }

  if ((mode & EX_READ) && (mode & EX_WRITE)) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Cannot specify both EX_READ and EX_WRITE");
    ex_err(__func__, errmsg, EX_BADFILEMODE);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  /* The EX_READ mode is the default if EX_WRITE is not specified... */
  if (!(mode & EX_WRITE)) { /* READ ONLY */
    nc_mode = NC_NOWRITE | NC_SHARE;

#if NC_HAS_DISKLESS
    if (mode & EX_DISKLESS) {
      nc_mode |= NC_DISKLESS;
    }
#endif

    if ((status = nc_open(path, nc_mode, &exoid)) != NC_NOERR) {
      /* NOTE: netCDF returns an id of -1 on an error - but no error code! */
      /* It is possible that the user is trying to open a netcdf4
         file, but the netcdf4 capabilities aren't available in the
         netcdf linked to this library. Note that we can't just use a
         compile-time define since we could be using a shareable
         netcdf library, so the netcdf4 capabilities aren't known
         until runtime...

         Later versions of netcdf-4.X have a function that can be
         queried to determine whether the library being used was
         compiled with --enable-netcdf4, but not everyone is using that
         version yet, so we may have to do some guessing...

         At this time, query the beginning of the file and see if it
         is an HDF-5 file and if it is assume that the open failure
         is due to the netcdf library not enabling netcdf4 features unless
         we have the define that shows it is enabled, then assume other error...
      */
      int type = 0;
      ex_check_file_type(path, &type);

      if (type == 5) {
#if NC_HAS_HDF5
        fprintf(stderr,
                "EXODUS: ERROR: Attempting to open the netcdf-4 "
                "file:\n\t'%s'\n\t failed. The netcdf library supports "
                "netcdf-4 so there must be a filesystem or some other "
                "issue \n",
                path);
#else
        /* This is an hdf5 (netcdf4) file. If NC_HAS_HDF5 is not defined,
           then we either don't have hdf5 support in this netcdf version,
           OR this is an older netcdf version that doesn't provide that define.

           In either case, we don't have enough information, so we
           assume that the netcdf doesn't have netcdf4 capabilities
           enabled.  Tell the user...
        */
        fprintf(stderr,
                "EXODUS: ERROR: Attempting to open the netcdf-4 "
                "file:\n\t'%s'\n\t. Either the netcdf library does not "
                "support netcdf-4 or there is a filesystem or some "
                "other issue \n",
                path);

#endif
      }
      else if (type == 4) {
#if defined(NC_64BIT_DATA)
        fprintf(stderr,
                "EXODUS: ERROR: Attempting to open the CDF5 "
                "file:\n\t'%s'\n\t failed. The netcdf library supports "
                "CDF5-type files so there must be a filesystem or some other "
                "issue \n",
                path);
#else
        /* This is an cdf5 (64BIT_DATA) file. If NC_64BIT_DATA is not defined,
           then we either don't have cdf5 support in this netcdf version,
           OR this is an older netcdf version that doesn't provide that define.

           In either case, we don't have enough information, so we
           assume that the netcdf doesn't have cdf5 capabilities
           enabled.  Tell the user...
        */
        fprintf(stderr,
                "EXODUS: ERROR: Attempting to open the CDF5 "
                "file:\n\t'%s'\n\t. Either the netcdf library does not "
                "support CDF5 or there is a filesystem or some "
                "other issue \n",
                path);

#endif
      }
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to open %s read only", path);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }
  }
  else { /* (mode & EX_WRITE) READ/WRITE */
    nc_mode = NC_WRITE | NC_SHARE;
#if NC_HAS_DISKLESS
    if (mode & EX_DISKLESS) {
      nc_mode |= NC_DISKLESS;
    }
#endif
    if ((status = nc_open(path, nc_mode, &exoid)) != NC_NOERR) {
      /* NOTE: netCDF returns an id of -1 on an error - but no error code! */
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to open %s write only", path);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    /* turn off automatic filling of netCDF variables */
    if ((status = nc_set_fill(exoid, NC_NOFILL, &old_fill)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to set nofill mode in file id %d", exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    stat_att = nc_inq_att(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, &att_type, &att_len);
    stat_dim = nc_inq_dimid(exoid, DIM_STR_NAME, &dim_str_name);
    if (stat_att != NC_NOERR || stat_dim != NC_NOERR) {
      if ((status = nc_redef(exoid)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to place file id %d into define mode",
                 exoid);
        ex_err(__func__, errmsg, status);
        EX_FUNC_LEAVE(EX_FATAL);
      }

      if (stat_att != NC_NOERR) {
        int max_so_far = 32;
        nc_put_att_int(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, NC_INT, 1, &max_so_far);
      }

      /* If the DIM_STR_NAME variable does not exist on the database, we need to
       * add it now. */
      if (stat_dim != NC_NOERR) {
        /* Not found; set to default value of 32+1. */
        int max_name = ex_default_max_name_length < 32 ? 32 : ex_default_max_name_length;
        if ((status = nc_def_dim(exoid, DIM_STR_NAME, max_name + 1, &dim_str_name)) != NC_NOERR) {
          snprintf(errmsg, MAX_ERR_LENGTH,
                   "ERROR: failed to define string name dimension in file id %d", exoid);
          ex_err(__func__, errmsg, status);
          EX_FUNC_LEAVE(EX_FATAL);
        }
      }
      if ((status = nc_enddef(exoid)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition in file id %d",
                 exoid);
        ex_err(__func__, errmsg, status);
        EX_FUNC_LEAVE(EX_FATAL);
      }
    }
  }

  /* determine version of EXODUS file, and the word size of
   * floating point and integer values stored in the file
   */

  if ((status = nc_get_att_float(exoid, NC_GLOBAL, ATT_VERSION, version)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get database version for file id: %d",
             exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  /* check ExodusII file version - old version 1.x files are not supported */
  if (*version < 2.0) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Unsupported file version %.2f in file id: %d",
             *version, exoid);
    ex_err(__func__, errmsg, EX_BADPARAM);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  if (nc_get_att_int(exoid, NC_GLOBAL, ATT_FLT_WORDSIZE, &file_wordsize) != NC_NOERR) {
    /* try old (prior to db version 2.02) attribute name */
    if ((status = nc_get_att_int(exoid, NC_GLOBAL, ATT_FLT_WORDSIZE_BLANK, &file_wordsize)) !=
        NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get file wordsize from file id: %d",
               exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }
  }

  /* See if int64 status attribute exists and if so, what data is stored as
   * int64
   * Older files don't have the attribute, so it is not an error if it is
   * missing
   */
  if (nc_get_att_int(exoid, NC_GLOBAL, ATT_INT64_STATUS, &int64_status) != NC_NOERR) {
    int64_status = 0; /* Just in case it gets munged by a failed get_att_int call */
  }

  /* Merge in API int64 status flags as specified by caller of function... */
  int64_status |= (mode & EX_ALL_INT64_API);

  /* Verify that there is not an existing file_item struct for this
     exoid This could happen (and has) when application calls
     ex_open(), but then closes file using nc_close() and then reopens
     file.  NetCDF will possibly reuse the exoid which results in
     internal corruption in exodus data structures since exodus does
     not know that file was closed and possibly new file opened for
     this exoid
  */
  if (ex_find_file_item(exoid) != NULL) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: There is an existing file already using the file "
             "id %d which was also assigned to file %s.\n\tWas "
             "nc_close() called instead of ex_close() on an open Exodus "
             "file?\n",
             exoid, path);
    ex_err(__func__, errmsg, EX_BADFILEID);
    nc_close(exoid);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  /* initialize floating point and integer size conversion. */
  if (ex_conv_ini(exoid, comp_ws, io_ws, file_wordsize, int64_status, 0, 0, 0) != EX_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to initialize conversion routines in file id %d", exoid);
    ex_err(__func__, errmsg, EX_LASTERR);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  EX_FUNC_LEAVE(exoid);
}
示例#20
0
void NemSpread<T,INT>::read_lb_init(int lb_exoid,
				    INT *Int_Space,
				    INT *Int_Node_Num,
				    INT *Bor_Node_Num,
				    INT *Ext_Node_Num,
				    INT *Int_Elem_Num,
				    INT *Bor_Elem_Num,
				    INT *Node_Comm_Num,
				    INT *Elem_Comm_Num,
				    char *Title
				    )

/*
 *    read_lb_init:
 *
 *         This function reads the initial information contained in the
 * load balance file
 *
 *
 */
{
  const char *yo = "read_lb_init";

  /*********************BEGIN EXECUTABLE STATEMENTS****************************/

  /* Read Set-up information from the load-balance file on Proc 0 */

  /*
   * If debugging is not on go ahead and report errors from init. This
   * will show version mismatch information by default.
   */
  if(Debug_Flag == 0)
    ex_opts(EX_VERBOSE);

  /* Read the title of the LB File and about the size of the mesh */
  INT   num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets;
  int error = ex_get_init_global(lb_exoid, &num_nodes, &num_elem,
				 &num_elem_blk, &num_node_sets, &num_side_sets);

  check_exodus_error (error, "ex_get_init");

  if(Debug_Flag == 0)
    ex_opts(!EX_VERBOSE);

#ifdef DEBUG
  if(Debug_Flag >= 2) {
    printf("---------------------------------------------------------\n");
    printf("\t\tLoad balance file global information\n");
    printf("---------------------------------------------------------\n");
    printf("\tNumber of nodes: %d\n", num_nodes);
    printf("\tNumber of elements: %d\n", num_elem);
    printf("\tNumber of element blocks: %d\n", num_elem_blk);
    printf("---------------------------------------------------------\n");
  }
#endif

  /* Cross-check the load balance file info against the mesh info */
  if(((size_t)num_nodes != globals.Num_Node) || ((size_t)num_elem != globals.Num_Elem) ||
     (num_elem_blk != globals.Num_Elem_Blk)) {
    fprintf(stderr,
	    "%s: ERROR: Problem dimensions in the LB File don't match with those \
in mesh file",yo);
    exit(1);
  }
示例#21
0
int main (int argc, char **argv)
{
  int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
  int num_elem_in_block[10], num_nodes_per_elem[10];
  int num_node_sets, num_side_sets, error;
  int i, j, k, kk, m, *elem_map, *connect;
  int node_list[100],elem_list[100],side_list[100];
  int ebids[10], ssids[10], nsids[10], nattr[10];
  int num_nodes_per_set[10], num_elem_per_set[10];
  int num_df_per_set[10];
  int  num_qa_rec, num_info;
  int num_glo_vars, num_nod_vars, num_ele_vars, num_nset_vars, num_sset_vars;
  int *truth_tab, *nset_tab, *sset_tab;
  int whole_time_step, num_time_steps;
  int CPU_word_size,IO_word_size;
  int prop_array[2];

  float *glob_var_vals, *nodal_var_vals, *elem_var_vals, *nset_var_vals, *sset_var_vals;
  float time_value;
  float x[100], y[100], z[100];
  float attrib[1], dist_fact[100];
  char *coord_names[3], *qa_record[2][4], *info[3], *var_names[7];
  char *prop_names[2];
  char *eb_type[10];
   
  ex_opts (EX_VERBOSE|EX_ABORT);

  /* Specify compute and i/o word size */

  CPU_word_size = 0;                   /* sizeof(float) */
  IO_word_size = 4;                    /* (4 bytes) */

  /* create EXODUS II file */

  exoid = ex_create ("test.exo",       /* filename path */
		     EX_CLOBBER,      /* create mode */
		     &CPU_word_size,  /* CPU float word size in bytes */
		     &IO_word_size);  /* I/O float word size in bytes */
  printf ("after ex_create for test.exo, exoid = %d\n", exoid);
  printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

  /* ncopts = NC_VERBOSE; */

  /* initialize file with parameters */

  num_dim = 3;
  num_nodes = 33;
  num_elem = 7;
  num_elem_blk = 7;
  num_node_sets = 2;
  num_side_sets = 5;

  error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem,
		       num_elem_blk, num_node_sets, num_side_sets);

  printf ("after ex_put_init, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /* write nodal coordinates values and names to database */

  /* Quad #1 */
  x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
  x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
  x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
  x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;

  /* Quad #2 */
  x[4]  =  1.0; y[4]  =  0.0; z[4]  =  0.0;
  x[5]  =  2.0; y[5]  =  0.0; z[5]  =  0.0;
  x[6]  =  2.0; y[6]  =  1.0; z[6]  =  0.0;
  x[7]  =  1.0; y[7]  =  1.0; z[7]  =  0.0;

  /* Hex #1 */
  x[8]  =  0.0; y[8]  =  0.0; z[8]  =  0.0;
  x[9]  = 10.0; y[9]  =  0.0; z[9]  =  0.0;
  x[10] = 10.0; y[10] =  0.0; z[10] =-10.0;
  x[11] =  1.0; y[11] =  0.0; z[11] =-10.0;
  x[12] =  1.0; y[12] = 10.0; z[12] =  0.0;
  x[13] = 10.0; y[13] = 10.0; z[13] =  0.0;
  x[14] = 10.0; y[14] = 10.0; z[14] =-10.0;
  x[15] =  1.0; y[15] = 10.0; z[15] =-10.0;

  /* Tetra #1 */
  x[16] =  0.0; y[16] =  0.0; z[16] =  0.0;
  x[17] =  1.0; y[17] =  0.0; z[17] =  5.0;
  x[18] = 10.0; y[18] =  0.0; z[18] =  2.0;
  x[19] =  7.0; y[19] =  5.0; z[19] =  3.0;

  /* Wedge #1 */
  x[20] =  3.0; y[20] =  0.0; z[20] =  6.0;
  x[21] =  6.0; y[21] =  0.0; z[21] =  0.0;
  x[22] =  0.0; y[22] =  0.0; z[22] =  0.0;
  x[23] =  3.0; y[23] =  2.0; z[23] =  6.0;
  x[24] =  6.0; y[24] =  2.0; z[24] =  2.0;
  x[25] =  0.0; y[25] =  2.0; z[25] =  0.0;

  /* Tetra #2 */
  x[26] =  2.7; y[26] =  1.7; z[26] =  2.7;
  x[27] =  6.0; y[27] =  1.7; z[27] =  3.3;
  x[28] =  5.7; y[28] =  1.7; z[28] =  1.7;
  x[29] =  3.7; y[29] =  0.0; z[29] =  2.3;

  /* 3d Tri */
  x[30] =  0.0; y[30] =  0.0; z[30] =  0.0;
  x[31] = 10.0; y[31] =  0.0; z[31] =  0.0;
  x[32] = 10.0; y[32] = 10.0; z[32] = 10.0;

  error = ex_put_coord (exoid, x, y, z);
  printf ("after ex_put_coord, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  coord_names[0] = "xcoor";
  coord_names[1] = "ycoor";
  coord_names[2] = "zcoor";

  error = ex_put_coord_names (exoid, coord_names);
  printf ("after ex_put_coord_names, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /* write element order map */

  elem_map = (int *) calloc(num_elem, sizeof(int));

  for (i=1; i<=num_elem; i++)
    {
      elem_map[i-1] = i;
    }

  error = ex_put_map (exoid, elem_map);
  printf ("after ex_put_map, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  free (elem_map);


  /* write element block parameters */

  num_elem_in_block[0] = 1;
  num_elem_in_block[1] = 1;
  num_elem_in_block[2] = 1;
  num_elem_in_block[3] = 1;
  num_elem_in_block[4] = 1;
  num_elem_in_block[5] = 1;
  num_elem_in_block[6] = 1;

  num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */
  num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */
  num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */
  num_nodes_per_elem[6] = 3; /* elements in block #7 are 3-node tris   */

  ebids[0] = 10;
  ebids[1] = 11;
  ebids[2] = 12;
  ebids[3] = 13;
  ebids[4] = 14;
  ebids[5] = 15;
  ebids[6] = 16;

  nattr[0] = nattr[1] = nattr[2] = nattr[3] = 1;
  nattr[4] = nattr[5] = nattr[6] = 1;
   
  eb_type[0] = "quad";
  eb_type[1] = "quad";
  eb_type[2] = "hex";
  eb_type[3] = "tetra";
  eb_type[4] = "wedge";
  eb_type[5] = "tetra";
  eb_type[6] = "tri";
     
  error = ex_put_concat_elem_block (exoid, ebids, eb_type,
				    num_elem_in_block, num_nodes_per_elem,
				    nattr, 0);
  printf ("after ex_put_concat_elem_block, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /* write element block properties */

  prop_names[0] = "MATL";
  prop_names[1] = "DENSITY";
  error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names);
  printf ("after ex_put_prop_names, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], "MATL", 60);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], "MATL", 70);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* write element connectivity */

  connect = (int *) calloc(8, sizeof(int));
  connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;

  error = ex_put_elem_conn (exoid, ebids[0], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8;

  error = ex_put_elem_conn (exoid, ebids[1], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12;
  connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16;

  error = ex_put_elem_conn (exoid, ebids[2], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;

  error = ex_put_elem_conn (exoid, ebids[3], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  connect[0] = 21; connect[1] = 22; connect[2] = 23;
  connect[3] = 24; connect[4] = 25; connect[5] = 26;

  error = ex_put_elem_conn (exoid, ebids[4], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;
  connect[4] = 27; connect[5] = 28; connect[6] = 30; connect[7] = 29;

  error = ex_put_elem_conn (exoid, ebids[5], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  connect[0] = 31; connect[1] = 32; connect[2] = 33;

  error = ex_put_elem_conn (exoid, ebids[6], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  free (connect);


  /* write element block attributes */

  attrib[0] = 3.14159;
  error = ex_put_elem_attr (exoid, ebids[0], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  attrib[0] = 6.14159;
  error = ex_put_elem_attr (exoid, ebids[1], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_elem_attr (exoid, ebids[2], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_elem_attr (exoid, ebids[3], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_elem_attr (exoid, ebids[4], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_elem_attr (exoid, ebids[5], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_elem_attr (exoid, ebids[6], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /* write individual node sets */


  nsids[0] = 20; nsids[1] = 21;
  num_nodes_per_set[0] = 5; num_nodes_per_set[1] = 3;
  num_df_per_set[0] = 5; num_df_per_set[1] = 3;

  error = ex_put_concat_node_sets (exoid, nsids, num_nodes_per_set,
				   num_df_per_set, 0, 0, 0, 0);

  printf ("after ex_put_concat_node_sets, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
  node_list[3] = 13; node_list[4] = 14; 

  dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0;
  dist_fact[3] = 4.0; dist_fact[4] = 5.0;

  error = ex_put_node_set (exoid, 20, node_list);
  printf ("after ex_put_node_set, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_node_set_dist_fact (exoid, 20, dist_fact);
  printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; 

  dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1;

  error = ex_put_node_set (exoid, 21, node_list);
  printf ("after ex_put_node_set, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_node_set_dist_fact (exoid, 21, dist_fact);
  printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  printf ("after ex_put_prop, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  printf ("after ex_put_prop_array, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /* Define the sideset params at one time, then write individually */
  ssids[0] = 30;
  ssids[1] = 31;
  ssids[2] = 32;
  ssids[3] = 33;
  ssids[4] = 34;

  num_elem_per_set[0] = 2;
  num_elem_per_set[1] = 2;
  num_elem_per_set[2] = 7;
  num_elem_per_set[3] = 8;
  num_elem_per_set[4] = 10;

  num_df_per_set[0] = 4;
  num_df_per_set[1] = 4;
  num_df_per_set[2] = 0;
  num_df_per_set[3] = 0;
  num_df_per_set[4] = 0;

  error = ex_put_concat_side_sets (exoid, ssids, num_elem_per_set,
				   num_df_per_set, 0, 0, 0, 0, 0);
  printf ("after ex_put_concat_side_sets, error = %d\n", error);

  /* write individual side sets */

  /* side set #1  - quad */

  elem_list[0] = 2; elem_list[1] = 2;

  side_list[0] = 4; side_list[1] = 2;

  dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2;
  dist_fact[3] = 30.3;

  error = ex_put_side_set (exoid, 30, elem_list, side_list);
  printf ("after ex_put_side_set, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_side_set_dist_fact (exoid, 30, dist_fact);
  printf ("after ex_put_side_set_dist_fact, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* side set #2  - quad, spanning 2 elements  */

  elem_list[0] = 1; elem_list[1] = 2;

  side_list[0] = 2; side_list[1] = 3;

  dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2;
  dist_fact[3] = 31.3;

  error = ex_put_side_set (exoid, 31, elem_list, side_list);
  printf ("after ex_put_side_set, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_side_set_dist_fact (exoid, 31, dist_fact);
  printf ("after ex_put_side_set_dist_fact, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* side set #3  - hex */

  elem_list[0] = 3; elem_list[1] = 3;
  elem_list[2] = 3; elem_list[3] = 3;
  elem_list[4] = 3; elem_list[5] = 3;
  elem_list[6] = 3;

  side_list[0] = 5; side_list[1] = 3;
  side_list[2] = 3; side_list[3] = 2;
  side_list[4] = 4; side_list[5] = 1;
  side_list[6] = 6;

  error = ex_put_side_set (exoid, 32, elem_list, side_list);
  printf ("after ex_put_side_set, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* side set #4  - tetras */

  elem_list[0] = 4; elem_list[1] = 4;
  elem_list[2] = 4; elem_list[3] = 4;
  elem_list[4] = 6; elem_list[5] = 6;
  elem_list[6] = 6; elem_list[7] = 6;

  side_list[0] = 1; side_list[1] = 2;
  side_list[2] = 3; side_list[3] = 4;
  side_list[4] = 1; side_list[5] = 2;
  side_list[6] = 3; side_list[7] = 4;

  error = ex_put_side_set (exoid, 33, elem_list, side_list);
  printf ("after ex_put_side_set, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* side set #5  - wedges and tris */

  elem_list[0] = 5; elem_list[1] = 5;
  elem_list[2] = 5; elem_list[3] = 5;
  elem_list[4] = 5; elem_list[5] = 7;
  elem_list[6] = 7; elem_list[7] = 7;
  elem_list[8] = 7; elem_list[9] = 7;

  side_list[0] = 1; side_list[1] = 2;
  side_list[2] = 3; side_list[3] = 4;
  side_list[4] = 5; side_list[5] = 1;
  side_list[6] = 2; side_list[7] = 3;
  side_list[8] = 4; side_list[9] = 5;

  error = ex_put_side_set (exoid, 34, elem_list, side_list);
  printf ("after ex_put_side_set, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  printf ("after ex_put_prop, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  printf ("after ex_put_prop, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* write QA records; test empty and just blank-filled records */

  num_qa_rec = 2;


  qa_record[0][0] = "TESTWT";
  qa_record[0][1] = "testwt";
  qa_record[0][2] = "07/07/93";
  qa_record[0][3] = "15:41:33";
  qa_record[1][0] = "";
  qa_record[1][1] = "                            ";
  qa_record[1][2] = "";
  qa_record[1][3] = "                        ";

  error = ex_put_qa (exoid, num_qa_rec, qa_record);
  printf ("after ex_put_qa, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* write information records; test empty and just blank-filled records */

  num_info = 3;


  info[0] = "This is the first information record.";
  info[1] = "";
  info[2] = "                                     ";

  error = ex_put_info (exoid, num_info, info);
  printf ("after ex_put_info, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }



  /* write results variables parameters and names */
  num_glo_vars  = 1;
  num_nod_vars  = 2;
  num_ele_vars  = 3;
  num_nset_vars = 4;
  num_sset_vars = 7;

  truth_tab = (int *) calloc ((num_elem_blk  * num_ele_vars),  sizeof(int));
  nset_tab  = (int *) calloc ((num_node_sets * num_nset_vars), sizeof(int));
  sset_tab  = (int *) calloc ((num_side_sets * num_sset_vars), sizeof(int));

  k = 0;
  for (i=0; i<num_elem_blk; i++) {
    for (j=0; j<num_ele_vars; j++) {
      truth_tab[k++] = 1;
    }
  }
   
  k = 0;
  for (i=0; i<num_node_sets; i++) {
    for (j=0; j<num_nset_vars; j++) {
      if (k%2 == 0)
	nset_tab[k++] = 1;
      else
	nset_tab[k++] = 0;
    }
  }
   
  k = 0;
  for (i=0; i<num_side_sets; i++) {
    for (j=0; j<num_sset_vars; j++) {
      if (k%2 == 0)
	sset_tab[k++] = 0;
      else
	sset_tab[k++] = 1;
    }
  }
   
  ex_put_all_var_param(exoid, num_glo_vars, num_nod_vars, num_ele_vars, truth_tab,
		       num_nset_vars, nset_tab, num_sset_vars, sset_tab);
  printf ("after ex_put_all_var_param, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  free (truth_tab);
  free (nset_tab);
  free (sset_tab);
   
  var_names[0] = "glo_vars";
  error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
  printf ("after ex_put_var_names, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /*              12345678901234567890123456789012 */
  var_names[0] = "node_variable_a_very_long_name_0";
  var_names[1] = "nod_var1";
  error = ex_put_var_names (exoid, "n", num_nod_vars, var_names);
  printf ("after ex_put_var_names, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }



  var_names[0] = "ele_var0";
  var_names[1] = "ele_var1";
  var_names[2] = "ele_var2";
  error = ex_put_var_names (exoid, "e", num_ele_vars, var_names);
  printf ("after ex_put_var_names, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  var_names[0] = "nset_var0";
  var_names[1] = "nset_var1";
  var_names[2] = "nset_var2";
  var_names[3] = "nset_var3";
  error = ex_put_var_names (exoid, "m", num_nset_vars, var_names);
  printf ("after ex_put_var_names, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  var_names[0] = "sset_var0";
  var_names[1] = "sset_var1";
  var_names[2] = "sset_var2";
  var_names[3] = "sset_var3";
  var_names[4] = "sset_var4";
  var_names[5] = "sset_var5";
  var_names[6] = "sset_var6";
  error = ex_put_var_names (exoid, "s", num_sset_vars, var_names);
  printf ("after ex_put_var_names, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* for each time step, write the analysis results;
   * the code below fills the arrays glob_var_vals, 
   * nodal_var_vals, and elem_var_vals with values for debugging purposes;
   * obviously the analysis code will populate these arrays
   */

  whole_time_step = 1;
  num_time_steps = 10;

  glob_var_vals =  (float *) calloc (num_glo_vars, CPU_word_size);
  nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
  elem_var_vals =  (float *) calloc (4, CPU_word_size);
  nset_var_vals =  (float *) calloc (5, CPU_word_size);
  sset_var_vals =  (float *) calloc (10, CPU_word_size);

  for (i=0; i<num_time_steps; i++)
    {
      time_value = (float)(i+1)/100.;

      /* write time value */

      error = ex_put_time (exoid, whole_time_step, &time_value);
      printf ("after ex_put_time, error = %d\n", error);

      if (error) {
	ex_close (exoid);
	exit(-1);
      }

      /* write global variables */

      for (j=0; j<num_glo_vars; j++) {
	glob_var_vals[j] = (float)(j+2) * time_value;
      }

      error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
				glob_var_vals);
      printf ("after ex_put_glob_vars, error = %d\n", error);

      if (error) {
	ex_close (exoid);
	exit(-1);
      }

      /* write nodal variables */

      for (k=1; k<=num_nod_vars; k++) {
	for (j=0; j<num_nodes; j++) {
	  nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
	}

	error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
				  nodal_var_vals);
	printf ("after ex_put_nodal_var, error = %d\n", error);
	if (error) {
	  ex_close (exoid);
	  exit(-1);
	}

      }

      /* write element variables */

      for (k=1; k<=num_ele_vars; k++) {
	for (j=0; j<num_elem_blk; j++) {
	  for (m=0; m<num_elem_in_block[j]; m++) {
	    elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
	      ((float)(m+1)*time_value);
	  }
	  error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
				   num_elem_in_block[j], elem_var_vals);
	  printf ("after ex_put_elem_var, error = %d\n", error);
	  if (error) {
	    ex_close (exoid);
	    exit(-1);
	  }
	}
      }

      /* write nodeset variables */

      kk = 0;
      for (j=0; j<num_node_sets; j++) {
	for (k=0; k<num_nset_vars; k++) {
	  if (kk++ % 2 == 0) {
	    for (m=0; m<num_nodes_per_set[j]; m++) {
	      nset_var_vals[m] = (float)(k+1) + (float)(j+2) + 
		((float)(m+1)*time_value);
	    }
	    error = ex_put_nset_var (exoid, whole_time_step, k+1, nsids[j],
				     num_nodes_per_set[j], nset_var_vals);
	    printf ("after ex_put_nset_var, error = %d\n", error);
	    if (error) {
	      ex_close (exoid);
	      exit(-1);
	    }
	  }
	}
      }

      /* write sideset variables */

      kk = 0;
      for (j=0; j<num_side_sets; j++) {
	for (k=0; k<num_sset_vars; k++) {
	  if (kk++ % 2 != 0) {
	    for (m=0; m<num_elem_per_set[j]; m++) {
	      sset_var_vals[m] = (float)(k+1) + (float)(j+2) + 
		((float)(m+1)*time_value);
	    }
	    error = ex_put_sset_var (exoid, whole_time_step, k+1, ssids[j],
				     num_elem_per_set[j], sset_var_vals);
	    printf ("after ex_put_sset_var, error = %d\n", error);
	    if (error) {
	      ex_close (exoid);
	      exit(-1);
	    }
	  }
	}
      }

      whole_time_step++;

      /* update the data file; this should be done at the end of every time step
       * to ensure that no data is lost if the analysis dies
       */
      error = ex_update (exoid);
      printf ("after ex_update, error = %d\n", error);
      if (error) {
	ex_close (exoid);
	exit(-1);
      }
    }
  free(glob_var_vals);
  free(nodal_var_vals);
  free(elem_var_vals);
  free(nset_var_vals);
  free(sset_var_vals);

  /* close the EXODUS files
   */
  error = ex_close (exoid);
  printf ("after ex_close, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }
  return 0;
}
示例#22
0
文件: twod.c 项目: 00liujj/trilinos
int main (int argc, char **argv)
{
  int num_glo_vars = 10;
  int num_nod_vars = 2;
  int CPU_word_size = 8; 
  int IO_word_size = 8;
  const char* title = "This is a 2D mesh example with tri, quad, beam, truss, circle";
  int ebids[] = {100, 200, 300, 400, 500};
  int num_dim   =  2;
  int num_nodes = 13;
  int num_elem  = 20;
  int num_elem_blk = 5;
  int num_node_sets = 2;
  int num_side_sets = 2;

  /* create EXODUS II file */
  int exoid = ex_create ("twod.e",       /* filename path */
			 EX_CLOBBER,      /* create mode */
			 &CPU_word_size,  /* CPU float word size in bytes */
			 &IO_word_size);  /* I/O float word size in bytes */

   ex_opts(EX_VERBOSE);

   /* initialize file with parameters */
     ex_put_init (exoid, title, num_dim, num_nodes, num_elem,
			  num_elem_blk, num_node_sets, num_side_sets);

     /* write nodal coordinates values and names to database */
     {
       double x[13], y[13];
       x[0]  =  0.0; y[0]  =  0.0;
       x[1]  = -0.5; y[1]  = -0.5;
       x[2]  =  0.5; y[2]  = -0.5;
       x[3]  =  0.5; y[3]  =  0.5;
       x[4]  = -0.5; y[4]  =  0.5;
       x[5]  = -1.0; y[5]  = -1.0;
       x[6]  =  1.0; y[6]  = -1.0;
       x[7]  =  1.0; y[7]  =  1.0;
       x[8]  = -1.0; y[8]  =  1.0;
       x[9]  = -2.0; y[9]  =  0.0;
       x[10] =  0.0; y[10] = -2.0;
       x[11] =  2.0; y[11] =  0.0;
       x[12] =  0.0; y[12] =  2.0;

       ex_put_coord (exoid, x, y, 0);
     }

     {
       const char* coord_names[] = {"xcoor", "ycoor"};
       ex_put_coord_names (exoid, (char**)coord_names);
     }


     {
       int node_map[] = {10,20,30,40,50,60,70,80,90,100,110,120,130};
       ex_put_node_num_map(exoid, node_map);
     }

     /* write element order map */
     {
       int elem_map[] = {11,21,31,41, 52, 62, 72, 82, 93,103,113,123,133,143,153,163,  174,184,194,204};
       ex_put_elem_num_map (exoid, elem_map);
     }

     /* write element block parameters */
     {
       const char* block_names[] = {"Triangles", "Quadrilaterals", "", "Trusses", "Circles"};
       int num_elem_in_block[] = {4, 4, 4, 4, 4};
       int num_nodes_per_elem[] = {3, 4, 2, 2, 1};

       ex_put_elem_block (exoid, ebids[0], "triangle", num_elem_in_block[0], num_nodes_per_elem[0], 0);
       ex_put_elem_block (exoid, ebids[1], "quad",     num_elem_in_block[1], num_nodes_per_elem[1], 0);
       ex_put_elem_block (exoid, ebids[2], "beam",     num_elem_in_block[2], num_nodes_per_elem[2], 3);
       ex_put_elem_block (exoid, ebids[3], "truss",    num_elem_in_block[3], num_nodes_per_elem[3], 1);
       ex_put_elem_block (exoid, ebids[4], "circle",   num_elem_in_block[4], num_nodes_per_elem[4], 2);

       /* Write element block names */
       ex_put_names(exoid, EX_ELEM_BLOCK, (char**)block_names);
     }

     /* write element connectivity */
     {
       int conn_t[] = {2,3,1,  3,4,1,  4,5,1,  5,2,1};
       int conn_q[] = {6,7,3,2,  7,8,4,3,  8,9,5,4,  9,6,2,5};
       int conn_B[] = {11,7,  8,13,  13,9,  6,11};
       int conn_T[] = {10,6,  9,10,  7,12,  12,8};
       int conn_c[] = {6,7,8,9};
       
       ex_put_elem_conn (exoid, ebids[0], conn_t);
       ex_put_elem_conn (exoid, ebids[1], conn_q);
       ex_put_elem_conn (exoid, ebids[2], conn_B);
       ex_put_elem_conn (exoid, ebids[3], conn_T);
       ex_put_elem_conn (exoid, ebids[4], conn_c);
     }

     /* write element block attributes */
     {
       const char* attn_T[] = {"Area"};
       double attr_T[] = {1.0, 1.1, 1.2, 1.3};

       const char* attn_B[] = {"A", "I", "J"};
       double attr_B[] = {1.0, 100.0, 200.0,   1.1, 100.1, 200.1,  1.2, 100.2, 200.2,  1.3, 100.3, 200.3};

       const char* attn_c[] = {"Radius", "A"};
       double attr_c[] = {1.0, 3.14, 1.1, 4.14, 1.2, 5.14, 1.3, 6.14};
     
       ex_put_elem_attr (exoid, ebids[2], attr_B);
       ex_put_elem_attr (exoid, ebids[3], attr_T);
       ex_put_elem_attr (exoid, ebids[4], attr_c);

       ex_put_elem_attr_names (exoid, ebids[2], (char**)attn_B);
       ex_put_elem_attr_names (exoid, ebids[3], (char**)attn_T);
       ex_put_elem_attr_names (exoid, ebids[4], (char**)attn_c);
     }

     /* write individual node sets */
     {
       int num_nodes_in_nset[] = {5, 8};
       int nsids[] = {20, 22};
       int nod1[] = {5,4,3,2,1};
       int nod2[] = {6,7,8,9,2,3,4,5};
       const char* nset_names[] = {"Triangle_Nodes", "Quadrilateral_Nodes"};

       ex_put_set_param (exoid, EX_NODE_SET, nsids[0], num_nodes_in_nset[0], 0);
       ex_put_set_param (exoid, EX_NODE_SET, nsids[1], num_nodes_in_nset[1], 0);

       ex_put_set (exoid, EX_NODE_SET, nsids[0], nod1, 0);
       ex_put_set (exoid, EX_NODE_SET, nsids[1], nod2, 0);
       ex_put_names(exoid, EX_NODE_SET, (char**)nset_names);
     }

     {
       /* write individual side sets */
       int num_face_in_sset[] =  {4,4};
       int ssids[] = {100,200};
       int ss1el[] = {1,2,3,4};
       int ss1si[] = {1,1,1,1};
       
       int ss2el[] = {5,7,6,8};
       int ss2si[] = {1,1,1,1};
       const char* sset_names[] = {"A", "B"};
       
       ex_put_set_param (exoid, EX_SIDE_SET, ssids[0], num_face_in_sset[0], 0);
       ex_put_set_param (exoid, EX_SIDE_SET, ssids[1], num_face_in_sset[1], 0);
       
       ex_put_set (exoid, EX_SIDE_SET, ssids[0], ss1el, ss1si);
       ex_put_set (exoid, EX_SIDE_SET, ssids[1], ss2el, ss2si);
       ex_put_names(exoid, EX_SIDE_SET, (char**)sset_names);
     }


     /* write results variables parameters and names */
     {
       const char* gvarn[] = {"g_01", "g_02", "g_03", "g_04", "g_05", "g_06", "g_07", "g_08", "g_09", "g_10"};
       ex_put_variable_param (exoid, EX_GLOBAL, num_glo_vars);
       ex_put_variable_names (exoid, EX_GLOBAL, num_glo_vars, (char**)gvarn);
     }

     {
       const char* nvarn[] = {"disp_x", "disp_y"};
       ex_put_variable_param (exoid, EX_NODAL, num_nod_vars);
       ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, (char**)nvarn);
     }

     
#if 0
   num_ele_vars = 3;
   /*              0        1         2         3   */
   /*              12345678901234567890123456789012 */
   var_names[0] = "this_variable_name_is_short";
   var_names[1] = "this_variable_name_is_just_right";
   var_names[2] = "this_variable_name_is_tooooo_long";

   ex_put_var_param (exoid, "e", num_ele_vars);
   printf ("after ex_put_var_param, %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   ex_put_var_names (exoid, "e", num_ele_vars, var_names);
   printf ("after ex_put_var_names, %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   {
     num_nset_vars = 3;
     
     var_names[0] = "ns_var0";
     var_names[1] = "ns_var1";
     var_names[2] = "ns_var2";
     
     ex_put_var_param (exoid, "m", num_nset_vars);
     printf ("after ex_put_var_param, %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
     
     ex_put_var_names (exoid, "m", num_nset_vars, var_names);
     printf ("after ex_put_var_names, %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   
   {
     num_sset_vars = 3;

     var_names[0] = "ss_var0";
     var_names[1] = "ss_var1";
     var_names[2] = "ss_var2";
     
     ex_put_var_param (exoid, "s", num_sset_vars);
     printf ("after ex_put_var_param, %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
     
     ex_put_var_names (exoid, "s", num_sset_vars, var_names);
     printf ("after ex_put_var_names, %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
#endif
   
   /* for each time step, write the analysis results;
    * the code below fills the arrays glob_var_vals, 
    * nodal_var_vals, and elem_var_vals with values for debugging purposes;
    * obviously the analysis code will populate these arrays
    */

   {
     int i, j, k;
     int whole_time_step = 1;
     int num_time_steps = 10;

     double gvar[10];
     double nvar[20];
   
     for (i=0; i<num_time_steps; i++) {
       double time_value = (double)(i)/100.;

       ex_put_time (exoid, whole_time_step, &time_value);

       for (j=0; j<num_glo_vars; j++) {
	 gvar[j] = (double)(j+2) * time_value;
       }
       ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, gvar);

       /* write nodal variables */
       for (k=0; k < num_nod_vars; k++) {
	 for (j=0; j<num_nodes; j++) {
	   nvar[j] = (double)k + ((double)(j+1) * time_value);
	 }
	 
	 ex_put_nodal_var (exoid, whole_time_step, k+1, num_nodes, nvar);
       }
       
#if 0
/* write element variables */

     for (k=1; k<=num_ele_vars; k++)
     {
       for (j=0; j<num_elem_blk; j++)
       {
         for (m=0; m<num_elem_in_block[j]; m++)
         {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
         }
         ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
                                  num_elem_in_block[j], elem_var_vals);
         printf ("after ex_put_elem_var, %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

/* write sideset variables */

     for (k=1; k<=num_sset_vars; k++)
     {
       for (j=0; j<num_side_sets; j++)
       {
         for (m=0; m<num_face_in_sset[j]; m++)
         {
           sset_var_vals[m] = (float)(k+2) + (float)(j+3) + 
                              ((float)(m+1)*time_value);
           /* printf("sset_var_vals[%d]: %f\n",m,sset_var_vals[m]); */
         }
         ex_put_sset_var (exoid, whole_time_step, k, ssids[j],
                                  num_face_in_sset[j], sset_var_vals);
         printf ("after ex_put_sset_var, %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

/* write nodeset variables */

     for (k=1; k<=num_nset_vars; k++)
     {
       for (j=0; j<num_node_sets; j++)
       {
         for (m=0; m<num_nodes_in_nset[j]; m++)
         {
           nset_var_vals[m] = (float)(k+3) + (float)(j+4) + 
                              ((float)(m+1)*time_value);
           /* printf("nset_var_vals[%d]: %f\n",m,nset_var_vals[m]); */
         }
         ex_put_nset_var (exoid, whole_time_step, k, nsids[j],
                                  num_nodes_in_nset[j], nset_var_vals);
         printf ("after ex_put_nset_var, %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }
#endif

     whole_time_step++;
   }
   }
   ex_close (exoid);
   return 0;
}
示例#23
0
文件: testwt_ss.c 项目: certik/exodus
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_nodes_per_elem[10];
   int num_node_sets, num_side_sets, error;
   int *connect;
   int node_list[100],elem_list[100],side_list[100];
   int ebids[10], ids[10];
   int num_nodes_per_set[10], num_elem_per_set[10];
   int num_df_per_set[10];
   int df_ind[10], node_ind[10], elem_ind[10]; 
   int  num_qa_rec, num_info;
   int CPU_word_size,IO_word_size;

   float x[100], y[100], z[100];
   float dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3];

   ex_opts (EX_VERBOSE|EX_ABORT); 

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("test.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   /* ncopts = NC_VERBOSE; */

/* initialize file with parameters */

   num_dim = 3;
   num_nodes = 33;
   num_elem = 8;
   num_elem_blk = 8;
   num_node_sets = 2;
   num_side_sets = 9;

   error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem,
                        num_elem_blk, num_node_sets, num_side_sets);

   printf ("after ex_put_init, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write nodal coordinates values and names to database */

/* Quad #1 */
   x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
   x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
   x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
   x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;

/* Quad #2 */
   x[4]  =  1.0; y[4]  =  0.0; z[4]  =  0.0;
   x[5]  =  2.0; y[5]  =  0.0; z[5]  =  0.0;
   x[6]  =  2.0; y[6]  =  1.0; z[6]  =  0.0;
   x[7]  =  1.0; y[7]  =  1.0; z[7]  =  0.0;

/* Hex #1 */
   x[8]  =  0.0; y[8]  =  0.0; z[8]  =  0.0;
   x[9]  = 10.0; y[9]  =  0.0; z[9]  =  0.0;
   x[10] = 10.0; y[10] =  0.0; z[10] =-10.0;
   x[11] =  1.0; y[11] =  0.0; z[11] =-10.0;
   x[12] =  1.0; y[12] = 10.0; z[12] =  0.0;
   x[13] = 10.0; y[13] = 10.0; z[13] =  0.0;
   x[14] = 10.0; y[14] = 10.0; z[14] =-10.0;
   x[15] =  1.0; y[15] = 10.0; z[15] =-10.0;

/* Tetra #1 */
   x[16] =  0.0; y[16] =  0.0; z[16] =  0.0;
   x[17] =  1.0; y[17] =  0.0; z[17] =  5.0;
   x[18] = 10.0; y[18] =  0.0; z[18] =  2.0;
   x[19] =  7.0; y[19] =  5.0; z[19] =  3.0;

/* Wedge #1 */
   x[20] =  3.0; y[20] =  0.0; z[20] =  6.0;
   x[21] =  6.0; y[21] =  0.0; z[21] =  0.0;
   x[22] =  0.0; y[22] =  0.0; z[22] =  0.0;
   x[23] =  3.0; y[23] =  2.0; z[23] =  6.0;
   x[24] =  6.0; y[24] =  2.0; z[24] =  2.0;
   x[25] =  0.0; y[25] =  2.0; z[25] =  0.0;

/* Tetra #2 */
   x[26] =  2.7; y[26] =  1.7; z[26] =  2.7;
   x[27] =  6.0; y[27] =  1.7; z[27] =  3.3;
   x[28] =  5.7; y[28] =  1.7; z[28] =  1.7;
   x[29] =  3.7; y[29] =  0.0; z[29] =  2.3;

/* TriShell #1 */
   x[30] =  2.7; y[30] =  1.7; z[30] =  2.7;
   x[31] =  6.0; y[31] =  1.7; z[31] =  3.3;
   x[32] =  5.7; y[32] =  1.7; z[32] =  1.7;

   error = ex_put_coord (exoid, x, y, z);
   printf ("after ex_put_coord, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   coord_names[0] = "xcoor";
   coord_names[1] = "ycoor";
   coord_names[2] = "zcoor";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write element block parameters */

   num_elem_in_block[0] = 1;
   num_elem_in_block[1] = 1;
   num_elem_in_block[2] = 1;
   num_elem_in_block[3] = 1;
   num_elem_in_block[4] = 1;
   num_elem_in_block[5] = 1;
   num_elem_in_block[6] = 1;
   num_elem_in_block[7] = 1;

   num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
   num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
   num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
   num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */
   num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */
   num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */
   num_nodes_per_elem[6] = 4; /* elements in block #7 are 4-node shells */
   num_nodes_per_elem[7] = 3; /* elements in block #8 are 3-node shells */

   ebids[0] = 10;
   ebids[1] = 11;
   ebids[2] = 12;
   ebids[3] = 13;
   ebids[4] = 14;
   ebids[5] = 15;
   ebids[6] = 16;
   ebids[7] = 17;

   error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0],
                              num_nodes_per_elem[0], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1],
                               num_nodes_per_elem[1], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2],
                               num_nodes_per_elem[2], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3],
                               num_nodes_per_elem[3], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[4], "wedge", num_elem_in_block[4],
                               num_nodes_per_elem[4], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[5], "tetra", num_elem_in_block[5],
                               num_nodes_per_elem[5], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[6], "shell", num_elem_in_block[6],
                               num_nodes_per_elem[6], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[7], "triangle",
                              num_elem_in_block[7], num_nodes_per_elem[7], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write element connectivity */

   connect = (int *) calloc(8, sizeof(int));
   connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;

   error = ex_put_elem_conn (exoid, ebids[0], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8;

   error = ex_put_elem_conn (exoid, ebids[1], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12;
   connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16;

   error = ex_put_elem_conn (exoid, ebids[2], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;

   error = ex_put_elem_conn (exoid, ebids[3], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 21; connect[1] = 22; connect[2] = 23;
   connect[3] = 24; connect[4] = 25; connect[5] = 26;

   error = ex_put_elem_conn (exoid, ebids[4], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;
   connect[4] = 27; connect[5] = 28; connect[6] = 30; connect[7] = 29;

   error = ex_put_elem_conn (exoid, ebids[5], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;

   error = ex_put_elem_conn (exoid, ebids[6], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 30; connect[1] = 31; connect[2] = 32;

   error = ex_put_elem_conn (exoid, ebids[7], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (connect);


/* write individual side sets */

   /* side set #1  - quad */

/* THIS SECTION IS COMMENTED OUT

   error = ex_put_side_set_param (exoid, 30, 2, 4);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 2; elem_list[1] = 2;

   side_list[0] = 4; side_list[1] = 2;

   dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2;
   dist_fact[3] = 30.3;

   error = ex_put_side_set (exoid, 30, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_side_set_dist_fact (exoid, 30, dist_fact);
   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

    END COMMENTED OUT SECTION */

   /* side set #2  - quad, spanning 2 elements  */

/* THIS SECTION IS COMMENTED OUT

   error = ex_put_side_set_param (exoid, 31, 2, 4);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 1; elem_list[1] = 2;

   side_list[0] = 2; side_list[1] = 3;

   dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2;
   dist_fact[3] = 31.3;

   error = ex_put_side_set (exoid, 31, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_side_set_dist_fact (exoid, 31, dist_fact);
   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

    END COMMENTED OUT SECTION */

   /* side set #3  - hex */

/* THIS SECTION IS COMMENTED OUT

   error = ex_put_side_set_param (exoid, 32, 7, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 3; elem_list[1] = 3;
   elem_list[2] = 3; elem_list[3] = 3;
   elem_list[4] = 3; elem_list[5] = 3;
   elem_list[6] = 3;

   side_list[0] = 5; side_list[1] = 3;
   side_list[2] = 3; side_list[3] = 2;
   side_list[4] = 4; side_list[5] = 1;
   side_list[6] = 6;

   error = ex_put_side_set (exoid, 32, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

    END COMMENTED OUT SECTION */

   /* side set #4  - 4-node tetras */

/* THIS SECTION IS COMMENTED OUT

   error = ex_put_side_set_param (exoid, 33, 4, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 4; elem_list[1] = 4;
   elem_list[2] = 4; elem_list[3] = 4;

   side_list[0] = 1; side_list[1] = 2;
   side_list[2] = 3; side_list[3] = 4;

   error = ex_put_side_set (exoid, 33, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

    END COMMENTED OUT SECTION */

   /* side set #5  - shells; front and back faces */

/* THIS SECTION IS COMMENTED OUT

   error = ex_put_side_set_param (exoid, 34, 2, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 7; elem_list[1] = 7;

   side_list[0] = 1; side_list[1] = 2;

   error = ex_put_side_set (exoid, 34, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

    END COMMENTED OUT SECTION */

   /* side set #6  - shells; edges */

/* THIS SECTION IS COMMENTED OUT

   error = ex_put_side_set_param (exoid, 35, 4, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 7; elem_list[1] = 7;
   elem_list[2] = 7; elem_list[3] = 7;

   side_list[0] = 3; side_list[1] = 4;
   side_list[2] = 5; side_list[3] = 6;

   error = ex_put_side_set (exoid, 35, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

    END COMMENTED OUT SECTION */

/* write concatenated side sets; this produces the same information as
 * the above code which writes individual side sets
 */


   ids[0] = 30;
   ids[1] = 31;
   ids[2] = 32;
   ids[3] = 33;
   ids[4] = 34;
   ids[5] = 35;
   ids[6] = 36;
   ids[7] = 37;
   ids[8] = 38;

   /* side set #1  - NULL side set */
   /* do nothing except set num_elem_per_set to 0 */
 
   /* side set #2  - NULL side set */
   /* do nothing except set num_elem_per_set to 0 */
 
   /* side set #3  - quad; 2 sides */

   node_list[0] = 8; node_list[1] = 5;
   elem_list[0] = 2; 

   node_list[2] = 6; node_list[3] = 7;
   elem_list[1] = 2;

   /* side set #4  - quad; 2 sides spanning 2 elements  */

   node_list[4] = 2; node_list[5] = 3;
   elem_list[2] = 1; 

   node_list[6] = 7; node_list[7] = 8;
   elem_list[3] = 2;

   /* side set #5  - hex; 7 sides */

   node_list[8] = 9; node_list[9] = 12;
   node_list[10] = 11; node_list[11] = 10;
   elem_list[4] = 3; 

   node_list[12] = 11; node_list[13] = 12;
   node_list[14] = 16; node_list[15] = 15;
   elem_list[5] = 3;
 
   node_list[16] = 16; node_list[17] = 15;
   node_list[18] = 11; node_list[19] = 12;
   elem_list[6] = 3; 

   node_list[20] = 10; node_list[21] = 11;
   node_list[22] = 15; node_list[23] = 14;
   elem_list[7] = 3;

   node_list[24] = 13; node_list[25] = 16;
   node_list[26] = 12; node_list[27] =  9;
   elem_list[8] = 3; 

   node_list[28] = 14; node_list[29] = 13;
   node_list[30] =  9; node_list[31] = 10;
   elem_list[9] = 3;

   node_list[32] = 16; node_list[33] = 13;
   node_list[34] = 14; node_list[35] = 15;
   elem_list[10] = 3; 

   /* side set #6  - 4-node tetras; 4 sides */

   node_list[36] = 17; node_list[37] = 18;
   node_list[38] = 20;
   elem_list[11] = 4; 

   node_list[39] = 18; node_list[40] = 19;
   node_list[41] = 20;
   elem_list[12] = 4; 

   node_list[42] = 17; node_list[43] = 20;
   node_list[44] = 19;
   elem_list[13] = 4; 

   node_list[45] = 17; node_list[46] = 19;
   node_list[47] = 18;
   elem_list[14] = 4; 

   /* side set #7  - shells; front and back faces */

   node_list[48] = 1; node_list[49] = 2;
   node_list[50] = 3; node_list[51] = 4;
   elem_list[15] = 7; 

   node_list[52] = 4; node_list[53] = 3;
   node_list[54] = 2; node_list[55] = 1;
   elem_list[16] = 7; 

   /* side set #8  - shells; 4 edges */

   node_list[56] = 1; node_list[57] = 2;
   elem_list[17] = 7; 

   node_list[58] = 2; node_list[59] = 3;
   elem_list[18] = 7; 

   node_list[60] = 3; node_list[61] = 4;
   elem_list[19] = 7; 

   node_list[62] = 4; node_list[63] = 1;
   elem_list[20] = 7;

   /* side set #9 --  3-node shells -- front and back */

   node_list[64] = 30;
   node_list[65] = 31;
   node_list[66] = 32; 
   elem_list[21] = 8; 

   node_list[67] = 32;
   node_list[68] = 31;
   node_list[69] = 30; 
   elem_list[22] = 8; 

   /* set up indices */
   node_ind[0] = 0;
   node_ind[1] = 0;
   node_ind[2] = 0;
   node_ind[3] = 4;
   node_ind[4] = 8;
   node_ind[5] = 36;
   node_ind[6] = 48;
   node_ind[7] = 56;
   node_ind[8] = 64;
     
   num_elem_per_set[0] = 0;
   num_elem_per_set[1] = 0;
   num_elem_per_set[2] = 2;
   num_elem_per_set[3] = 2;
   num_elem_per_set[4] = 7;
   num_elem_per_set[5] = 4;
   num_elem_per_set[6] = 2;
   num_elem_per_set[7] = 4;
   num_elem_per_set[8] = 2;
   
   num_nodes_per_set[0] = 0;
   num_nodes_per_set[1] = 0;
   num_nodes_per_set[2] = 4;
   num_nodes_per_set[3] = 4;
   num_nodes_per_set[4] = 28;
   num_nodes_per_set[5] = 12;
   num_nodes_per_set[6] = 8;
   num_nodes_per_set[7] = 8;
   num_nodes_per_set[8] = 6;

   elem_ind[0] = 0;
   elem_ind[1] = 0;
   elem_ind[2] = 0;
   elem_ind[3] = 2;
   elem_ind[4] = 4;
   elem_ind[5] = 11;
   elem_ind[6] = 15;
   elem_ind[7] = 17;
   elem_ind[8] = 21;

   error = ex_cvt_nodes_to_sides(exoid,
                         num_elem_per_set,
                         num_nodes_per_set,
                         elem_ind,
                         node_ind,
                         elem_list,
                         node_list,
                         side_list);
   printf ("after ex_cvt_nodes_to_sides, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   num_df_per_set[0] = 0;
   num_df_per_set[1] = 0;
   num_df_per_set[2] = 4;
   num_df_per_set[3] = 4;
   num_df_per_set[4] = 0;
   num_df_per_set[5] = 0;
   num_df_per_set[6] = 0;
   num_df_per_set[7] = 0;
   num_df_per_set[8] = 0;

   df_ind[0] = 0;
   df_ind[1] = 0;
   df_ind[2] = 0;
   df_ind[3] = 4;
   df_ind[4] = 0;
   df_ind[5] = 0;
   df_ind[6] = 0;
   df_ind[7] = 0;
   df_ind[8] = 0;

   dist_fact[0] = 30.0; dist_fact[1] = 30.1;
   dist_fact[2] = 30.2; dist_fact[3] = 30.3;

   dist_fact[4] = 31.0; dist_fact[5] = 31.1;
   dist_fact[6] = 31.2; dist_fact[7] = 31.3;


   error = ex_put_concat_side_sets (exoid, ids, num_elem_per_set,
                                    num_df_per_set, elem_ind, df_ind,
                                    elem_list, side_list, dist_fact);
   printf ("after ex_put_concat_side_sets, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* THIS SECTION IS COMMENTED OUT
    END COMMENTED OUT SECTION */


/* write QA records; test empty and just blank-filled records */

   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write information records; test empty and just blank-filled records */

   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* close the EXODUS files
 */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   return 0;
}
示例#24
0
int ex_open_int (const char  *path,
		 int    mode,
		 int   *comp_ws,
		 int   *io_ws,
		 float *version,
		 int    run_version)
{
  int exoid;
  int status, stat_att, stat_dim;
  nc_type att_type = NC_NAT;
  size_t att_len = 0;
  int old_fill;
  int file_wordsize;
  int dim_str_name;
  int int64_status = 0;
  
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */
 
  /* set error handling mode to no messages, non-fatal errors */
  ex_opts(exoptval);    /* call required to set ncopts first time through */

  if (run_version != EX_API_VERS_NODOT && warning_output == 0) {
    int run_version_major = run_version / 100;
    int run_version_minor = run_version % 100;
    int lib_version_major = EX_API_VERS_NODOT / 100;
    int lib_version_minor = EX_API_VERS_NODOT % 100;
    fprintf(stderr, "EXODUS: Warning: This code was compiled with exodus version %d.%02d,\n          but was linked with exodus library version %d.%02d\n          This is probably an error in the build process of this code.\n",
	    run_version_major, run_version_minor, lib_version_major, lib_version_minor);
    warning_output = 1;
  }
  

  if ((mode & EX_READ) && (mode & EX_WRITE)) {
    exerrval = EX_BADFILEMODE;
    sprintf(errmsg,"Error: Cannot specify both EX_READ and EX_WRITE");
    ex_err("ex_open",errmsg,exerrval); 
    return (EX_FATAL);
  }

  /* The EX_READ mode is the default if EX_WRITE is not specified... */
  if (!(mode & EX_WRITE)) { /* READ ONLY */
#if defined(__LIBCATAMOUNT__)
    if ((status = nc_open (path, NC_NOWRITE, &exoid)) != NC_NOERR)
#else
      if ((status = nc_open (path, NC_NOWRITE|NC_SHARE, &exoid)) != NC_NOERR)
#endif
	{
	  /* NOTE: netCDF returns an id of -1 on an error - but no error code! */
	  if (status == 0) {
	    exerrval = EX_FATAL;
	  }
	  else {
	    /* It is possible that the user is trying to open a netcdf4
	       file, but the netcdf4 capabilities aren't available in the
	       netcdf linked to this library. Note that we can't just use a
	       compile-time define since we could be using a shareable
	       netcdf library, so the netcdf4 capabilities aren't known
	       until runtime...
	  
	       Netcdf-4.X does not (yet?) have a function that can be
	       queried to determine whether the library being used was
	       compiled with --enable-netcdf4, so that isn't very
	       helpful.. 

	       At this time, query the beginning of the file and see if it
	       is an HDF-5 file and if it is assume that the open failure
	       is due to the netcdf library not enabling netcdf4 features...
	    */
	    int type = 0;
	    ex_check_file_type(path, &type);
	  
	    if (type == 5) {
	      /* This is an hdf5 (netcdf4) file. Since the nc_open failed,
		 the assumption is that the netcdf doesn't have netcdf4
		 capabilities enabled.  Tell the user...
	      */
	      fprintf(stderr,
		      "EXODUS: Error: Attempting to open the netcdf-4 file:\n\t'%s'\n\twith a netcdf library that does not support netcdf-4\n",
		      path);
	    }
	    exerrval = status;
	  }
	  sprintf(errmsg,"Error: failed to open %s read only",path);
	  ex_err("ex_open",errmsg,exerrval); 
	  return(EX_FATAL);
	} 
  }
  else /* (mode & EX_WRITE) READ/WRITE */
    {
#if defined(__LIBCATAMOUNT__)
      if ((status = nc_open (path, NC_WRITE, &exoid)) != NC_NOERR)
#else
	if ((status = nc_open (path, NC_WRITE|NC_SHARE, &exoid)) != NC_NOERR)
#endif
	  {
	    /* NOTE: netCDF returns an id of -1 on an error - but no error code! */
	    if (status == 0)
	      exerrval = EX_FATAL;
	    else
	      exerrval = status;
	    sprintf(errmsg,"Error: failed to open %s write only",path);
	    ex_err("ex_open",errmsg,exerrval); 
	    return(EX_FATAL);
	  } 

      /* turn off automatic filling of netCDF variables */
      if ((status = nc_set_fill (exoid, NC_NOFILL, &old_fill)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to set nofill mode in file id %d",
		exoid);
	ex_err("ex_open", errmsg, exerrval);
	return (EX_FATAL);
      }

      stat_att = nc_inq_att(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, &att_type, &att_len);
      stat_dim = nc_inq_dimid(exoid, DIM_STR_NAME, &dim_str_name);
      if(stat_att != NC_NOERR || stat_dim != NC_NOERR) {
	nc_redef(exoid);
	if (stat_att != NC_NOERR) {
	  int max_so_far = 32;
	  nc_put_att_int(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, NC_INT, 1, &max_so_far);
	}

	/* If the DIM_STR_NAME variable does not exist on the database, we need to add it now. */
	if(stat_dim != NC_NOERR) {
	  /* Not found; set to default value of 32+1. */
	  int max_name = ex_default_max_name_length < 32 ? 32 : ex_default_max_name_length;
	  nc_def_dim(exoid, DIM_STR_NAME, max_name+1, &dim_str_name);
	}
	nc_enddef (exoid);
      }
    }

  /* determine version of EXODUS II file, and the word size of
   * floating point and integer values stored in the file
   */

  if ((status = nc_get_att_float(exoid, NC_GLOBAL, ATT_VERSION, version)) != NC_NOERR) {
    exerrval  = status;
    sprintf(errmsg,"Error: failed to get database version for file id: %d",
	    exoid);
    ex_err("ex_open",errmsg,exerrval);
    return(EX_FATAL);
  }
   
  /* check ExodusII file version - old version 1.x files are not supported */
  if (*version < 2.0) {
    exerrval  = EX_FATAL;
    sprintf(errmsg,"Error: Unsupported file version %.2f in file id: %d",
	    *version, exoid);
    ex_err("ex_open",errmsg,exerrval);
    return(EX_FATAL);
  }
   
  if (nc_get_att_int (exoid, NC_GLOBAL, ATT_FLT_WORDSIZE, &file_wordsize) != NC_NOERR)
    {  /* try old (prior to db version 2.02) attribute name */
      if (nc_get_att_int (exoid,NC_GLOBAL,ATT_FLT_WORDSIZE_BLANK,&file_wordsize) != NC_NOERR)
	{
	  exerrval  = EX_FATAL;
	  sprintf(errmsg,"Error: failed to get file wordsize from file id: %d",
		  exoid);
	  ex_err("ex_open",errmsg,exerrval);
	  return(exerrval);
	}
    }

  /* See if int64 status attribute exists and if so, what data is stored as int64 
   * Older files don't have the attribute, so it is not an error if it is missing
   */
  if (nc_get_att_int (exoid, NC_GLOBAL, ATT_INT64_STATUS, &int64_status) != NC_NOERR) {
    int64_status = 0; /* Just in case it gets munged by a failed get_att_int call */
  }
  
  /* Merge in API int64 status flags as specified by caller of function... */
  int64_status |= (mode & EX_ALL_INT64_API);
  
  /* initialize floating point and integer size conversion. */
  if (ex_conv_ini( exoid, comp_ws, io_ws, file_wordsize, int64_status ) != EX_NOERR ) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: failed to initialize conversion routines in file id %d",
            exoid);
    ex_err("ex_open", errmsg, exerrval);
    return (EX_FATAL);
  }

  return (exoid);
}
示例#25
0
int write_nemesis(std::string &nemI_out_file,
                  Machine_Description* machine,
                  Problem_Description* problem,
                  Mesh_Description<INT>* mesh,
                  LB_Description<INT>* lb,
                  Sphere_Info* sphere)
{
  int     exoid;
  char    title[MAX_LINE_LENGTH+1], method1[MAX_LINE_LENGTH+1];
  char    method2[MAX_LINE_LENGTH+1];

  int cpu_ws = sizeof(float);
  int io_ws  = sizeof(float);

  printf("Outputting load balance to file %s\n", nemI_out_file.c_str());

  /* Create the load balance file */
  /* Attempt to create a netcdf4-format file; if it fails, then assume
     that the netcdf library does not support that mode and fall back
     to classic netcdf3 format.  If that fails, issue an error and
     return failure.
  */
  int mode3 = EX_CLOBBER;
  int mode4 = mode3|EX_NETCDF4|EX_NOCLASSIC|problem->int64db|problem->int64api;

  ex_opts(EX_DEFAULT); // Eliminate misleading error if the first ex_create fails, but the second succeeds.
  if((exoid=ex_create(nemI_out_file.c_str(), mode4, &cpu_ws, &io_ws)) < 0) {
    /* If int64api or int64db non-zero, then netcdf-4 format is required, so
       fail now...
    */
    if (problem->int64db|problem->int64api) {
      Gen_Error(0, "fatal: failed to create Nemesis netcdf-4 file");
      return 0;
    }
    if((exoid=ex_create(nemI_out_file.c_str(), mode3, &cpu_ws, &io_ws)) < 0) {
      Gen_Error(0, "fatal: failed to create Nemesis file");
      return 0;
    }
  }
  ON_BLOCK_EXIT(ex_close, exoid);
  
  /* Set the error reporting value */
  if (error_lev > 1)
    ex_opts(EX_VERBOSE | EX_DEBUG);
  else
    ex_opts(EX_VERBOSE);

  /* Enable compression (if netcdf-4) */
  ex_set_option(exoid, EX_OPT_COMPRESSION_LEVEL, 1);
  ex_set_option(exoid, EX_OPT_COMPRESSION_SHUFFLE, 1);

  /* Create the title */
  if(problem->type == NODAL)
    strcpy(method1, "nodal");
  else
    strcpy(method1, "elemental");

  sprintf(title, "nem_slice %s load balance file", method1);

  strcpy(method1, "method1: ");
  strcpy(method2, "method2: ");

  switch(lb->type)
    {
    case MULTIKL:
      strcat(method1, "Multilevel-KL decomposition");
      strcat(method2, "With Kernighan-Lin refinement");
      break;
    case SPECTRAL:
      strcat(method1, "Spectral decomposition");
      break;
    case INERTIAL:
      strcat(method1, "Inertial decomposition");
      break;
    case ZPINCH:
      strcat(method1, "ZPINCH decomposition");
      break;
    case BRICK:
      strcat(method1, "BRICK decomposition");
      break;
    case ZOLTAN_RCB:
      strcat(method1, "RCB decomposition");
      break;
    case ZOLTAN_RIB:
      strcat(method1, "RIB decomposition");
      break;
    case ZOLTAN_HSFC:
      strcat(method1, "HSFC decomposition");
      break;
    case LINEAR:
      strcat(method1, "Linear decomposition");
      break;
    case RANDOM:
      strcat(method1, "Random decomposition");
      break;
    case SCATTERED:
      strcat(method1, "Scattered decomposition");
      break;
    }

  if(lb->refine == KL_REFINE && lb->type != MULTIKL)
    strcat(method2, "with Kernighan-Lin refinement");
  else if(lb->type != MULTIKL)
    strcat(method2, "no refinement");

  switch(lb->num_sects)
    {
    case 1:
      strcat(method1, " via bisection");
      break;
    case 2:
      strcat(method1, " via quadrasection");
      break;
    case 3:
      strcat(method1, " via octasection");
      break;
    }

  /* Do some sorting */
  for(int proc=0; proc < machine->num_procs; proc++) {

    /* Sort node maps */
    gds_qsort(TOPTR(lb->int_nodes[proc]), lb->int_nodes[proc].size());
    if(problem->type == NODAL) {
      sort2(lb->ext_nodes[proc].size(), TOPTR(lb->ext_nodes[proc]),
	    TOPTR(lb->ext_procs[proc]));
    }

    /* Sort element maps */
    gds_qsort(TOPTR(lb->int_elems[proc]), lb->int_elems[proc].size());
  }

  /* Output the info records */
  char *info[3];
  info[0] = title;
  info[1] = method1;
  info[2] = method2;

  if(ex_put_info(exoid, 3, info) < 0)
    Gen_Error(0, "warning: output of info records failed");

  /* Generate a QA record for the utility */
  time_t time_val = time(nullptr);
  char *ct_ptr   = asctime(localtime(&time_val));
  char tm_date[30];
  strcpy(tm_date, ct_ptr);

  /* Break string with null characters */
  tm_date[3]  = '\0';
  tm_date[7]  = '\0';
  tm_date[10] = '\0';
  tm_date[19] = '\0';

  char    qa_date[15], qa_time[10], qa_name[MAX_STR_LENGTH];
  char    qa_vers[10];

  sprintf(qa_date, "%s %s %s", &tm_date[8], &tm_date[4], &tm_date[20]);
  sprintf(qa_time, "%s", &tm_date[11]);
  strcpy(qa_name, UTIL_NAME);
  strcpy(qa_vers, ELB_VERSION);

  if(qa_date[strlen(qa_date)-1] == '\n')
    qa_date[strlen(qa_date)-1] = '\0';

  char **lqa_record = (char **)array_alloc(1, 4, sizeof(char *));
  for(int i2=0; i2 < 4; i2++)
    lqa_record[i2] = (char *)array_alloc(1, MAX_STR_LENGTH+1, sizeof(char));

  strcpy(lqa_record[0], qa_name);
  strcpy(lqa_record[1], qa_vers);
  strcpy(lqa_record[2], qa_date);
  strcpy(lqa_record[3], qa_time);

  printf("QA Record:\n");
  for(int i2=0; i2 < 4; i2++) {
    printf("\t%s\n", lqa_record[i2]);
  }

  if(ex_put_qa(exoid, 1, (char *(*)[4]) &lqa_record[0]) < 0) {
    Gen_Error(0, "fatal: unable to output QA records");
    return 0;
  }

  /* free up memory */
  for(int i2=0; i2 < 4; i2++)
    free(lqa_record[i2]);

  free(lqa_record);

  /* Output the the initial Nemesis global information */
  if(ex_put_init_global(exoid, mesh->num_nodes, mesh->num_elems,
                        mesh->num_el_blks, 0, 0) < 0) {
    Gen_Error(0, "fatal: failed to output initial Nemesis parameters");
    return 0;
  }
  
  /* Set up dummy arrays for ouput */
  std::vector<INT> num_nmap_cnts(machine->num_procs);
  std::vector<INT> num_emap_cnts(machine->num_procs);
  
  if(problem->type == NODAL) {
    /* need to check and make sure that there really are comm maps */
    for(int cnt=0; cnt < machine->num_procs; cnt++) {
      if (!lb->bor_nodes[cnt].empty())
	num_nmap_cnts[cnt] = 1;
    }
  }
  else {	/* Elemental load balance */
    if(((problem->num_vertices)-(sphere->num)) > 0) {
      /* need to check and make sure that there really are comm maps */
      for(int cnt=0; cnt < machine->num_procs; cnt++) {
        if (!lb->bor_nodes[cnt].empty()) num_nmap_cnts[cnt] = 1;
      }
      for(int cnt=0; cnt < machine->num_procs; cnt++) {
        if (!lb->bor_elems[cnt].empty()) num_emap_cnts[cnt] = 1;
      }
    }
  }

  if(ex_put_init_info(exoid, machine->num_procs, machine->num_procs, (char*)"s") < 0) {
    Gen_Error(0, "fatal: unable to output init info");
    return 0;
  }

  // Need to create 5 arrays with the sizes of lb->int_nodes[i].size()...
  {
    std::vector<INT> ins(machine->num_procs);
    std::vector<INT> bns(machine->num_procs);
    std::vector<INT> ens(machine->num_procs);
    std::vector<INT> ies(machine->num_procs);
    std::vector<INT> bes(machine->num_procs);

    for (int iproc = 0; iproc < machine->num_procs; iproc++) {
      ins[iproc] = lb->int_nodes[iproc].size();
      bns[iproc] = lb->bor_nodes[iproc].size();
      ens[iproc] = lb->ext_nodes[iproc].size();
      ies[iproc] = lb->int_elems[iproc].size();
      bes[iproc] = lb->bor_elems[iproc].size();
    }

    if(ex_put_loadbal_param_cc(exoid,
			       TOPTR(ins), TOPTR(bns), TOPTR(ens),
			       TOPTR(ies), TOPTR(bes), TOPTR(num_nmap_cnts),
			       TOPTR(num_emap_cnts)) < 0)
      {
	Gen_Error(0, "fatal: unable to output load-balance parameters");
	return 0;
      }
  }

  if(problem->type == NODAL)		/* Nodal load balance output */
    {
      /* Set up for the concatenated communication map parameters */
      std::vector<INT> node_proc_ptr(machine->num_procs+1);
      std::vector<INT> node_cmap_ids_cc(machine->num_procs);
      std::vector<INT> node_cmap_cnts_cc(machine->num_procs);

      node_proc_ptr[0] = 0;
      for(int proc=0; proc < machine->num_procs; proc++) {
	node_proc_ptr[proc+1]   = node_proc_ptr[proc] + 1;
	node_cmap_cnts_cc[proc] = lb->ext_nodes[proc].size();
	node_cmap_ids_cc[proc]  = 1;
      }

      /* Output the communication map parameters */
      if(ex_put_cmap_params_cc(exoid, TOPTR(node_cmap_ids_cc),
			       TOPTR(node_cmap_cnts_cc),
			       TOPTR(node_proc_ptr), nullptr, nullptr, nullptr) < 0)
	{
	  Gen_Error(0, "fatal: unable to output communication map parameters");
	  return 0;
	}

      /* Output the node and element maps */
      for(int proc=0; proc < machine->num_procs; proc++) {
	/* Output the nodal map */
	if(ex_put_processor_node_maps(exoid,
				      TOPTR(lb->int_nodes[proc]),
				      TOPTR(lb->bor_nodes[proc]),
				      TOPTR(lb->ext_nodes[proc]), proc) < 0)
	  {
	    Gen_Error(0, "fatal: failed to output node map");
	    return 0;
	  }

	/* Output the elemental map */
	if(ex_put_processor_elem_maps(exoid, TOPTR(lb->int_elems[proc]), nullptr, proc) < 0)
	  {
	    Gen_Error(0, "fatal: failed to output element map");
	    return 0;
	  }

	/*
	 * Reorder the nodal communication maps so that they are ordered
	 * by processor and then by global ID.
	 */

	/* This is a 2-key sort */
	qsort2(TOPTR(lb->ext_procs[proc]), TOPTR(lb->ext_nodes[proc]), lb->ext_nodes[proc].size());

	/* Output the nodal communication map */
	if(ex_put_node_cmap(exoid, 1,
			    TOPTR(lb->ext_nodes[proc]),
			    TOPTR(lb->ext_procs[proc]), proc) < 0)
	  {
	    Gen_Error(0, "fatal: failed to output nodal communication map");
	    return 0;
	  }

      } /* End "for(proc=0; proc < machine->num_procs; proc++)" */
    }
  else if(problem->type == ELEMENTAL)	/* Elemental load balance output */
    {
      std::vector<INT> node_proc_ptr(machine->num_procs+1);
      std::vector<INT> node_cmap_ids_cc(machine->num_procs);
      std::vector<INT> node_cmap_cnts_cc(machine->num_procs);

      node_proc_ptr[0] = 0;
      for(int proc=0; proc < machine->num_procs; proc++) {
	node_proc_ptr[proc+1]   = node_proc_ptr[proc] + 1;

	node_cmap_cnts_cc[proc] = 0;
	for(size_t cnt=0; cnt < lb->bor_nodes[proc].size(); cnt++)
	  node_cmap_cnts_cc[proc] += lb->born_procs[proc][cnt].size();

	node_cmap_ids_cc[proc]  = 1;
      }

      std::vector<INT> elem_proc_ptr(machine->num_procs+1);
      std::vector<INT> elem_cmap_ids_cc(machine->num_procs);
      std::vector<INT> elem_cmap_cnts_cc(machine->num_procs);

      elem_proc_ptr[0] = 0;
      for(int proc=0; proc < machine->num_procs; proc++) {
	elem_proc_ptr[proc+1]   = elem_proc_ptr[proc] + 1;
	elem_cmap_cnts_cc[proc] = lb->e_cmap_elems[proc].size();
	elem_cmap_ids_cc[proc]  = 1;
      }

      /* Output the communication map parameters */
      if(ex_put_cmap_params_cc(exoid, TOPTR(node_cmap_ids_cc), TOPTR(node_cmap_cnts_cc),
			       TOPTR(node_proc_ptr), TOPTR(elem_cmap_ids_cc),
			       TOPTR(elem_cmap_cnts_cc), TOPTR(elem_proc_ptr)) < 0)
	{
	  Gen_Error(0, "fatal: unable to output communication map parameters");
	  return 0;
	}

      /* Output the node and element maps */
      for(int proc=0; proc < machine->num_procs; proc++)
	{
	  /* Output the nodal map */
	  if(ex_put_processor_node_maps(exoid,
					TOPTR(lb->int_nodes[proc]),
					TOPTR(lb->bor_nodes[proc]),
					nullptr, proc) < 0)
	    {
	      Gen_Error(0, "fatal: failed to output node map");
	      return 0;
	    }

	  /* Output the elemental map */
	  if(ex_put_processor_elem_maps(exoid,
					TOPTR(lb->int_elems[proc]),
					TOPTR(lb->bor_elems[proc]),
					proc) < 0)
	    {
	      Gen_Error(0, "fatal: failed to output element map");
	      return 0;
	    }

	  /*
	   * Build a nodal communication map from the list of border nodes
	   * and their associated processors and side IDs.
	   */
	  size_t nsize = 0;
	  for(size_t cnt=0; cnt < lb->bor_nodes[proc].size(); cnt++)
	    nsize += lb->born_procs[proc][cnt].size();

	  if (nsize > 0) {
	    std::vector<INT> n_cmap_nodes(nsize);
	    std::vector<INT> n_cmap_procs(nsize);

	    size_t cnt3 = 0;
	    for(size_t cnt=0; cnt < lb->bor_nodes[proc].size(); cnt++) {
	      for(size_t cnt2=0; cnt2 < lb->born_procs[proc][cnt].size(); cnt2++) {
		n_cmap_nodes[cnt3]   = lb->bor_nodes[proc][cnt];
		n_cmap_procs[cnt3++] = lb->born_procs[proc][cnt][cnt2];
	      }
	    }

	    /*
	     * Reorder the nodal communication maps so that they are ordered
	     * by processor and then by global ID.
	     */
	    /* This is a 2-key sort */
	    qsort2(TOPTR(n_cmap_procs), TOPTR(n_cmap_nodes), cnt3);

	    /* Output the nodal communication map */
	    if(ex_put_node_cmap(exoid, 1, TOPTR(n_cmap_nodes), TOPTR(n_cmap_procs), proc) < 0) {
	      Gen_Error(0, "fatal: unable to output nodal communication map");
	      return 0;
	    }
	  } /* End "if (nsize > 0)" */

	    /* Output the elemental communication map */
	  if(!lb->e_cmap_elems[proc].empty()) {
	    if(ex_put_elem_cmap(exoid, 1,
				TOPTR(lb->e_cmap_elems[proc]),
				TOPTR(lb->e_cmap_sides[proc]),
				TOPTR(lb->e_cmap_procs[proc]), proc) < 0)
	      {
		Gen_Error(0, "fatal: unable to output elemental communication map");
		return 0;
	      }
	  }

	} /* End "for(proc=0; proc < machine->num_procs; proc++)" */

    }
  return 1;
} /*------------------------End write_nemesis()------------------------------*/
示例#26
0
int main(int argc, char *argv[])
{
  INT *connect;
  int  debug = EX_FALSE; /* EX_TRUE, display debug information; EX_FALSE       */
  /* otherwise.                                 */
  static char device_name[MAX_STRING_LEN];
  static char file_name[MAX_STRING_LEN] = DEFAULT_FILE_NAME;
  int         exodus                    = EX_TRUE;
  INT         map_origin                = DEFAULT_MAP_ORIGIN;
  INT         num_domains               = DEFAULT_NUM_DOMAINS;
  INT         num_elements_1d;
  INT         num_elements       = DEFAULT_NUM_ELEMENTS;
  INT         num_nodal_fields   = DEFAULT_NUM_FIELDS;
  INT         num_global_fields  = DEFAULT_NUM_FIELDS;
  INT         num_element_fields = DEFAULT_NUM_FIELDS;
  INT         num_timesteps      = DEFAULT_NUM_TIMESTEPS;
  INT         num_nodes;
  int         compression_level = 0;
  int         shuffle           = 0;
  int         int64bit          = 0;
  size_t      size;

  realtyp *x;
  realtyp *y;
  realtyp *z;

  ex_opts(EX_VERBOSE | EX_ABORT);

  /* Parse Input */
  parse_input(argc, argv, &debug, &map_origin, &num_elements, &num_domains, &num_nodal_fields,
              &num_global_fields, &num_element_fields, &num_timesteps, device_name, file_name,
              &exodus, &compression_level, &shuffle, &int64bit);

  /* Create Coordinates and Connectivity Array */
  num_elements_1d = icbrt(num_elements);
  num_nodes       = (num_elements_1d + 1) * (num_elements_1d + 1) * (num_elements_1d + 1);
  x               = malloc(num_nodes * sizeof(realtyp));
  y               = malloc(num_nodes * sizeof(realtyp));
  z               = malloc(num_nodes * sizeof(realtyp));
  assert(x != NULL && y != NULL && z != NULL);

  num_elements = num_elements_1d * num_elements_1d * num_elements_1d;
  size         = (size_t)NUM_NODES_PER_ELEM * num_elements * sizeof(INT);
  assert(size > 0);
  connect = malloc(size);
  assert(connect != NULL);

  fprintf(stderr, "Creating a 3D mesh of %" PRId64 " hex elements and %" PRId64 " nodes.\n",
          num_elements, num_nodes);

  make_mesh(x, y, z, connect, map_origin, num_elements_1d);
  fprintf(stderr, "\t...Mesh topology created.\n");

  /*
   *    Write Out Mesh
   */

  if (exodus) {
    write_exo_mesh(debug, file_name, map_origin, num_nodes, num_elements, num_domains,
                   num_nodal_fields, num_global_fields, num_element_fields, num_timesteps, x, y, z,
                   connect, compression_level, shuffle, int64bit);
  }

  free(x);
  free(y);
  free(z);
  free(connect);
  return 0;
} /* end of main() */
示例#27
0
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_nodes_per_elem[10];
   int num_face_in_sset[10], num_nodes_in_nset[10];
   int num_node_sets, num_side_sets, error;
   int i, j, k, m, *elem_map, *connect;
   int node_list[100],elem_list[100],side_list[100];
   int ebids[10], ssids[10], nsids[10];
   int  num_qa_rec, num_info;
   int num_glo_vars, num_nod_vars, num_ele_vars, num_sset_vars, num_nset_vars;
   int *truth_tab;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;
   int prop_array[2];

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float *sset_var_vals, *nset_var_vals;
   float time_value;
   float x[100], y[100], z[100];
   float attrib[1], dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *variable_names[3];
   char *block_names[10], *nset_names[10], *sset_names[10];
   char *prop_names[2], *attrib_names[2];
   char *title = "This is a test";
   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   
   exoid = ex_create ("test.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   ex_set_option(exoid, EX_OPT_MAX_NAME_LENGTH, 127); /* Using long names */

   /* initialize file with parameters */

   num_dim = 3;
   num_nodes = 33;
   num_elem = 7;
   num_elem_blk = 7;
   num_node_sets = 2;
   num_side_sets = 5;

   
   error = ex_put_init (exoid, title, num_dim, num_nodes, num_elem,
                        num_elem_blk, num_node_sets, num_side_sets);

   printf ("after ex_put_init, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write nodal coordinates values and names to database */

/* Quad #1 */
   x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
   x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
   x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
   x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;

/* Quad #2 */
   x[4]  =  1.0; y[4]  =  0.0; z[4]  =  0.0;
   x[5]  =  2.0; y[5]  =  0.0; z[5]  =  0.0;
   x[6]  =  2.0; y[6]  =  1.0; z[6]  =  0.0;
   x[7]  =  1.0; y[7]  =  1.0; z[7]  =  0.0;

/* Hex #1 */
   x[8]  =  0.0; y[8]  =  0.0; z[8]  =  0.0;
   x[9]  = 10.0; y[9]  =  0.0; z[9]  =  0.0;
   x[10] = 10.0; y[10] =  0.0; z[10] =-10.0;
   x[11] =  1.0; y[11] =  0.0; z[11] =-10.0;
   x[12] =  1.0; y[12] = 10.0; z[12] =  0.0;
   x[13] = 10.0; y[13] = 10.0; z[13] =  0.0;
   x[14] = 10.0; y[14] = 10.0; z[14] =-10.0;
   x[15] =  1.0; y[15] = 10.0; z[15] =-10.0;

/* Tetra #1 */
   x[16] =  0.0; y[16] =  0.0; z[16] =  0.0;
   x[17] =  1.0; y[17] =  0.0; z[17] =  5.0;
   x[18] = 10.0; y[18] =  0.0; z[18] =  2.0;
   x[19] =  7.0; y[19] =  5.0; z[19] =  3.0;

/* Wedge #1 */
   x[20] =  3.0; y[20] =  0.0; z[20] =  6.0;
   x[21] =  6.0; y[21] =  0.0; z[21] =  0.0;
   x[22] =  0.0; y[22] =  0.0; z[22] =  0.0;
   x[23] =  3.0; y[23] =  2.0; z[23] =  6.0;
   x[24] =  6.0; y[24] =  2.0; z[24] =  2.0;
   x[25] =  0.0; y[25] =  2.0; z[25] =  0.0;

/* Tetra #2 */
   x[26] =  2.7; y[26] =  1.7; z[26] =  2.7;
   x[27] =  6.0; y[27] =  1.7; z[27] =  3.3;
   x[28] =  5.7; y[28] =  1.7; z[28] =  1.7;
   x[29] =  3.7; y[29] =  0.0; z[29] =  2.3;

/* 3d Tri */
   x[30] =  0.0; y[30] =  0.0; z[30] =  0.0;
   x[31] = 10.0; y[31] =  0.0; z[31] =  0.0;
   x[32] = 10.0; y[32] = 10.0; z[32] = 10.0;

   error = ex_put_coord (exoid, x, y, z);
   printf ("after ex_put_coord, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   /*                0        1         2         3         4         5         6     */
   /*                1234567890123456789012345678901234567890123456789012345678901234 */
   coord_names[0] = "X coordinate name that is padded to be longer than 32 characters";
   coord_names[1] = "Y coordinate name that is padded to be longer than 32 characters";
   coord_names[2] = "Z coordinate name that is padded to be longer than 32 characters";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Add nodal attributes */
   error = ex_put_attr_param(exoid, EX_NODAL, 0, 2);
   printf ("after ex_put_attr_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   error = ex_put_one_attr(exoid, EX_NODAL, 0, 1, x);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   error = ex_put_one_attr(exoid, EX_NODAL, 0, 2, y);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   {
     attrib_names[0] = "Node_attr_1";
     attrib_names[1] = "Node_attr_2";
     error = ex_put_attr_names (exoid, EX_NODAL, 0, attrib_names);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }

/* write element order map */

   elem_map = (int *) calloc(num_elem, sizeof(int));

   for (i=1; i<=num_elem; i++)
   {
      elem_map[i-1] = i;
   }

   error = ex_put_map (exoid, elem_map);
   printf ("after ex_put_map, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (elem_map);


/* write element block parameters */

   /*                0        1         2         3         4         5         6     */
   /*                1234567890123456789012345678901234567890123456789012345678901234 */
   block_names[0] = "Very long name for block_1 that exceeds 32 characters";
   block_names[1] = "Very long name for block_2 that exceeds 32 characters";
   block_names[2] = "Very long name for block_3 that exceeds 32 characters";
   block_names[3] = "Very long name for block_4 that exceeds 32 characters";
   block_names[4] = "Very long name for block_5 that exceeds 32 characters";
   block_names[5] = "Very long name for block_6 that exceeds 32 characters";
   block_names[6] = "Very long name for block_7 that exceeds 32 characters";
   num_elem_in_block[0] = 1;
   num_elem_in_block[1] = 1;
   num_elem_in_block[2] = 1;
   num_elem_in_block[3] = 1;
   num_elem_in_block[4] = 1;
   num_elem_in_block[5] = 1;
   num_elem_in_block[6] = 1;

   num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
   num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
   num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
   num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */
   num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */
   num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */
   num_nodes_per_elem[6] = 3; /* elements in block #7 are 3-node tris   */

   ebids[0] = 10;
   ebids[1] = 11;
   ebids[2] = 12;
   ebids[3] = 13;
   ebids[4] = 14;
   ebids[5] = 15;
   ebids[6] = 16;

   error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0],
                              num_nodes_per_elem[0], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1],
                               num_nodes_per_elem[1], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2],
                               num_nodes_per_elem[2], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3],
                               num_nodes_per_elem[3], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[4], "wedge", num_elem_in_block[4],
                               num_nodes_per_elem[4], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[5], "tetra", num_elem_in_block[5],
                               num_nodes_per_elem[5], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[6], "tri", num_elem_in_block[6],
                               num_nodes_per_elem[6], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Write element block names */
   error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
/* write element block properties */

   /*               0        1         2         3         4         5         6     */
   /*               1234567890123456789012345678901234567890123456789012345678901234 */
   prop_names[0] = "MATERIAL_PROPERTY_LONG_NAME_32CH";
   prop_names[1] = "DENSITY";
   error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names);
   printf ("after ex_put_prop_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 10);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 20);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 30);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], prop_names[0], 40);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], prop_names[0], 50);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], prop_names[0], 60);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], prop_names[0], 70);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write element connectivity */

   connect = (int *) calloc(8, sizeof(int));
   connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;

   error = ex_put_elem_conn (exoid, ebids[0], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8;

   error = ex_put_elem_conn (exoid, ebids[1], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12;
   connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16;

   error = ex_put_elem_conn (exoid, ebids[2], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;

   error = ex_put_elem_conn (exoid, ebids[3], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 21; connect[1] = 22; connect[2] = 23;
   connect[3] = 24; connect[4] = 25; connect[5] = 26;

   error = ex_put_elem_conn (exoid, ebids[4], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;
   connect[4] = 27; connect[5] = 28; connect[6] = 30; connect[7] = 29;

   error = ex_put_elem_conn (exoid, ebids[5], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 31; connect[1] = 32; connect[2] = 33;

   error = ex_put_elem_conn (exoid, ebids[6], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (connect);


/* write element block attributes */

   attrib[0] = 3.14159;
   error = ex_put_elem_attr (exoid, ebids[0], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[0], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   attrib[0] = 6.14159;
   error = ex_put_elem_attr (exoid, ebids[1], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[2], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[3], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[4], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[5], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[6], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /*                 0        1         2         3         4         5         6     */
   /*                 1234567890123456789012345678901234567890123456789012345678901234 */
   attrib_names[0] = "The name for the attribute representing the shell thickness";
   for (i=0; i < 7; i++) {
     error = ex_put_elem_attr_names (exoid, ebids[i], attrib_names);
     printf ("after ex_put_elem_attr_names, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }

/* write individual node sets */


   num_nodes_in_nset[0] = 5;
   num_nodes_in_nset[1] = 3;

   nsids[0] = 20;
   nsids[1] = 21;

   error = ex_put_node_set_param (exoid, nsids[0], 5, 5);
   printf ("after ex_put_node_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
   node_list[3] = 13; node_list[4] = 14; 

   dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0;
   dist_fact[3] = 4.0; dist_fact[4] = 5.0;

   error = ex_put_node_set (exoid, nsids[0], node_list);
   printf ("after ex_put_node_set, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_node_set_dist_fact (exoid, nsids[0], dist_fact);
   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   error = ex_put_node_set_param (exoid, nsids[1], 3, 3);
   printf ("after ex_put_node_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; 

   dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1;

   error = ex_put_node_set (exoid, nsids[1], node_list);
   printf ("after ex_put_node_set, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_node_set_dist_fact (exoid, nsids[1], dist_fact);
   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* Write node set names */
   nset_names[0] = "nset_1";
   nset_names[1] = "nset_2";

   error = ex_put_names(exoid, EX_NODE_SET, nset_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   error = ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5);
   printf ("after ex_put_prop, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   prop_array[0] = 1000;
   prop_array[1] = 2000;

   error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
   printf ("after ex_put_prop_array, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Add nodeset attributes */
   error = ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1);
   printf ("after ex_put_attr_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   error = ex_put_attr(exoid, EX_NODE_SET, nsids[0], x);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   {
     attrib_names[0] = "Nodeset_attribute";
     error = ex_put_attr_names (exoid, EX_NODE_SET, nsids[0], attrib_names);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }

/* write individual side sets */
   num_face_in_sset[0] =  2;
   num_face_in_sset[1] =  2;
   num_face_in_sset[2] =  7;
   num_face_in_sset[3] =  8;
   num_face_in_sset[4] = 10;
   
   ssids[0] = 30;
   ssids[1] = 31;
   ssids[2] = 32;
   ssids[3] = 33;
   ssids[4] = 34;

   /* side set #1  - quad */

   error = ex_put_side_set_param (exoid, ssids[0], 2, 4);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 2; elem_list[1] = 2;

   side_list[0] = 4; side_list[1] = 2;

   dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2;
   dist_fact[3] = 30.3;

   error = ex_put_side_set (exoid, 30, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_side_set_dist_fact (exoid, 30, dist_fact);
   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* side set #2  - quad, spanning 2 elements  */

   error = ex_put_side_set_param (exoid, 31, 2, 4);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 1; elem_list[1] = 2;

   side_list[0] = 2; side_list[1] = 3;

   dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2;
   dist_fact[3] = 31.3;

   error = ex_put_side_set (exoid, 31, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_side_set_dist_fact (exoid, 31, dist_fact);
   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* side set #3  - hex */

   error = ex_put_side_set_param (exoid, 32, 7, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 3; elem_list[1] = 3;
   elem_list[2] = 3; elem_list[3] = 3;
   elem_list[4] = 3; elem_list[5] = 3;
   elem_list[6] = 3;

   side_list[0] = 5; side_list[1] = 3;
   side_list[2] = 3; side_list[3] = 2;
   side_list[4] = 4; side_list[5] = 1;
   side_list[6] = 6;

   error = ex_put_side_set (exoid, 32, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* side set #4  - tetras */

   error = ex_put_side_set_param (exoid, 33, 8, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 4; elem_list[1] = 4;
   elem_list[2] = 4; elem_list[3] = 4;
   elem_list[4] = 6; elem_list[5] = 6;
   elem_list[6] = 6; elem_list[7] = 6;

   side_list[0] = 1; side_list[1] = 2;
   side_list[2] = 3; side_list[3] = 4;
   side_list[4] = 1; side_list[5] = 2;
   side_list[6] = 3; side_list[7] = 4;

   error = ex_put_side_set (exoid, 33, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* side set #5  - wedges and tris */

   error = ex_put_side_set_param (exoid, 34, 10, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 5; elem_list[1] = 5;
   elem_list[2] = 5; elem_list[3] = 5;
   elem_list[4] = 5; elem_list[5] = 7;
   elem_list[6] = 7; elem_list[7] = 7;
   elem_list[8] = 7; elem_list[9] = 7;

   side_list[0] = 1; side_list[1] = 2;
   side_list[2] = 3; side_list[3] = 4;
   side_list[4] = 5; side_list[5] = 1;
   side_list[6] = 2; side_list[7] = 3;
   side_list[8] = 4; side_list[9] = 5;

   error = ex_put_side_set (exoid, 34, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Write side set names */
   sset_names[0] = "sset_1";
   sset_names[1] = "sset_2";
   sset_names[2] = "sset_3";
   sset_names[3] = "sset_4";
   sset_names[4] = "sset_5";

   error = ex_put_names(exoid, EX_SIDE_SET, sset_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
   printf ("after ex_put_prop, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
   printf ("after ex_put_prop, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write QA records; test empty and just blank-filled records */

   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write information records; test empty and just blank-filled records */

   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }



/* write results variables parameters and names */

   num_glo_vars = 1;

   variable_names[0] = "glo_vars";

   error = ex_put_variable_param (exoid, EX_GLOBAL, num_glo_vars);
   printf ("after ex_put_variable_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_variable_names (exoid, EX_GLOBAL, num_glo_vars, variable_names);
   printf ("after ex_put_variable_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }



   num_nod_vars = 2;
   /*              0        1         2         3         4         5         6     */
   /*              1234567890123456789012345678901234567890123456789012345678901234 */
   variable_names[0] = "node_variable_a_somewhat_long_name_0";
   variable_names[1] = "node_variable_a_much_longer_name_that_is_not_too_long_name";

   error = ex_put_variable_param (exoid, EX_NODAL, num_nod_vars);
   printf ("after ex_put_variable_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, variable_names);
   printf ("after ex_put_variable_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   num_ele_vars = 3;

   /*              0        1         2         3         4         5         6     */
   /*              1234567890123456789012345678901234567890123456789012345678901234 */
   variable_names[0] = "the_stress_on_the_elements_in_this_block_that_are_active_now";
   variable_names[1] = "ele_var1";
   variable_names[2] = "ele_var2";

   error = ex_put_variable_param (exoid, EX_ELEM_BLOCK, num_ele_vars);
   printf ("after ex_put_variable_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_variable_names (exoid, EX_ELEM_BLOCK, num_ele_vars, variable_names);
   printf ("after ex_put_variable_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   {
     num_nset_vars = 3;
     
     variable_names[0] = "ns_var0";
     variable_names[1] = "ns_var1";
     variable_names[2] = "ns_var2";
     
     error = ex_put_variable_param (exoid, EX_NODE_SET, num_nset_vars);
     printf ("after ex_put_variable_param, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
     
     error = ex_put_variable_names (exoid, EX_NODE_SET, num_nset_vars, variable_names);
     printf ("after ex_put_variable_names, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   
   {
     num_sset_vars = 3;

     variable_names[0] = "ss_var0";
     variable_names[1] = "ss_var1";
     variable_names[2] = "ss_var2";
     
     error = ex_put_variable_param (exoid, EX_SIDE_SET, num_sset_vars);
     printf ("after ex_put_variable_param, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
     
     error = ex_put_variable_names (exoid, EX_SIDE_SET, num_sset_vars, variable_names);
     printf ("after ex_put_variable_names, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }



/* write element variable truth table */

   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));

   k = 0;
   for (i=0; i<num_elem_blk; i++)
   {
      for (j=0; j<num_ele_vars; j++)
      {
         truth_tab[k++] = 1;
      }
   }

   error = ex_put_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
   printf ("after ex_put_elem_var_tab, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (truth_tab);


/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 * obviously the analysis code will populate these arrays
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (4, CPU_word_size);
   sset_var_vals = (float *) calloc (10, CPU_word_size);
   nset_var_vals = (float *) calloc (10, CPU_word_size);
   
   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

/* write time value */

     error = ex_put_time (exoid, whole_time_step, &time_value);
     printf ("after ex_put_time, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

/* write global variables */

     for (j=0; j<num_glo_vars; j++)
     {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
                               glob_var_vals);
     printf ("after ex_put_glob_vars, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

/* write nodal variables */

     for (k=1; k<=num_nod_vars; k++)
     {
       for (j=0; j<num_nodes; j++)
       {
         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
       }

       error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
                                 nodal_var_vals);
       printf ("after ex_put_nodal_var, error = %d\n", error);
       if (error) {
         ex_close (exoid);
         exit(-1);
       }

     }

/* write element variables */

     for (k=1; k<=num_ele_vars; k++)
     {
       for (j=0; j<num_elem_blk; j++)
       {
         for (m=0; m<num_elem_in_block[j]; m++)
         {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
         }
         error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
                                  num_elem_in_block[j], elem_var_vals);
         printf ("after ex_put_elem_var, error = %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

/* write sideset variables */

     for (k=1; k<=num_sset_vars; k++)
     {
       for (j=0; j<num_side_sets; j++)
       {
         for (m=0; m<num_face_in_sset[j]; m++)
         {
           sset_var_vals[m] = (float)(k+2) + (float)(j+3) + 
                              ((float)(m+1)*time_value);
           /* printf("sset_var_vals[%d]: %f\n",m,sset_var_vals[m]); */
         }
         error = ex_put_sset_var (exoid, whole_time_step, k, ssids[j],
                                  num_face_in_sset[j], sset_var_vals);
         printf ("after ex_put_sset_var, error = %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

/* write nodeset variables */

     for (k=1; k<=num_nset_vars; k++)
     {
       for (j=0; j<num_node_sets; j++)
       {
         for (m=0; m<num_nodes_in_nset[j]; m++)
         {
           nset_var_vals[m] = (float)(k+3) + (float)(j+4) + 
                              ((float)(m+1)*time_value);
           /* printf("nset_var_vals[%d]: %f\n",m,nset_var_vals[m]); */
         }
         error = ex_put_nset_var (exoid, whole_time_step, k, nsids[j],
                                  num_nodes_in_nset[j], nset_var_vals);
         printf ("after ex_put_nset_var, error = %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

     whole_time_step++;

/* update the data file; this should be done at the end of every time step
 * to ensure that no data is lost if the analysis dies
 */
     error = ex_update (exoid);
     printf ("after ex_update, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);
   free(sset_var_vals);
   free(nset_var_vals);


/* close the EXODUS files
 */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   return 0;
}
示例#28
0
int main(int argc, char **argv)
{
  int  exoid, num_dim, num_nodes, num_elem, num_elem_blk;
  int  exoidm[10], num_dim2, num_nodes2, num_elem2, num_elem_blk2;
  int  num_elem_in_block[10], num_node_sets, num_nodes_per_elem[10];
  int  num_elem_in_block2[10], num_node_sets2, num_nodes_per_elem2[10];
  int  num_side_sets, error;
  int  num_side_sets2, nexofiles = 5;
  int  i, j, k, m, n;
  int *elem_map, *connect, node_list[100], elem_list[100], side_list[100];
  int *elem_map2, *connect2, node_list2[100], elem_list2[100], side_list2[100];
  int  ebids[10], ids[10];
  int  ebids2[10], ids2[10];
  int  num_nodes_per_set[10], num_elem_per_set[10];
  int  num_nodes_per_set2[10], num_elem_per_set2[10];
  int  num_df_per_set[10], num_df_per_set2[10];
  int  df_ind[10], node_ind[10], elem_ind[10];
  int  df_ind2[10], node_ind2[10], elem_ind2[10];
  int  num_qa_rec, num_info;
  int  num_qa_rec2, num_info2;
  int  num_glo_vars, num_nod_vars, num_ele_vars;
  int  num_glo_vars2, num_nod_vars2, num_ele_vars2;
  int *truth_tab;
  int  whole_time_step, num_time_steps;
  int  CPU_word_size, IO_word_size;
  int  prop_array[2];

  float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
  float  time_value;
  float  time_value2;
  float  x[100], y[100], z[100];
  float  attrib[1], dist_fact[1008];
  float  attrib2[1], dist_fact2[100];
  char * coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  char * coord_names2[3], *qa_record2[2][4], *info2[3], *var_names2[3];
  char   tmpstr[80];
  char * prop_names[2];
  char   exofname[256];

  ex_opts(EX_VERBOSE | EX_ABORT);

  /* Specify compute and i/o word size */

  CPU_word_size = 0; /* sizeof(float) */
  IO_word_size  = 4; /* (4 bytes) */

  /* create EXODUS II files */

  exoid = ex_create("test.exo",     /* filename path */
                    EX_CLOBBER,     /* create mode */
                    &CPU_word_size, /* CPU float word size in bytes */
                    &IO_word_size); /* I/O float word size in bytes */
  printf("after ex_create for test.exo, exoid = %d\n", exoid);
  printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);

  for (n = 0; n < nexofiles; n++) {
    sprintf(exofname, "test%d.exo", n);
    printf("test file name: %s\n", exofname);
    exoidm[n] = ex_create(exofname,       /* filename path */
                          EX_CLOBBER,     /* create mode */
                          &CPU_word_size, /* CPU float word size in bytes */
                          &IO_word_size); /* I/O float word size in bytes */
    printf("after ex_create for %s, exoid = %d\n", exofname, exoidm[n]);
  }

  /* initialize file with parameters */

  num_dim       = 3;
  num_nodes     = 26;
  num_elem      = 5;
  num_elem_blk  = 5;
  num_node_sets = 2;
  num_side_sets = 5;

  error = ex_put_init(exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk,
                      num_node_sets, num_side_sets);

  printf("after ex_put_init, error = %d\n", error);

  /* initialize file n with parameters */

  num_dim2       = 3;
  num_nodes2     = 26;
  num_elem2      = 5;
  num_elem_blk2  = 5;
  num_node_sets2 = 2;
  num_side_sets2 = 5;

  for (n = 0; n < nexofiles; n++) {
    sprintf(tmpstr, "This is test %d", n);

    error = ex_put_init(exoidm[n], tmpstr, num_dim2, num_nodes2, num_elem2, num_elem_blk2,
                        num_node_sets2, num_side_sets2);

    printf("after ex_put_init (%d), error = %d\n", n, error);
  }

  /* write nodal coordinates values and names to database */

  /* Quad #1 */
  x[0] = 0.0;
  y[0] = 0.0;
  z[0] = 0.0;
  x[1] = 1.0;
  y[1] = 0.0;
  z[1] = 0.0;
  x[2] = 1.0;
  y[2] = 1.0;
  z[2] = 0.0;
  x[3] = 0.0;
  y[3] = 1.0;
  z[3] = 0.0;

  /* Quad #2 */
  x[4] = 1.0;
  y[4] = 0.0;
  z[4] = 0.0;
  x[5] = 2.0;
  y[5] = 0.0;
  z[5] = 0.0;
  x[6] = 2.0;
  y[6] = 1.0;
  z[6] = 0.0;
  x[7] = 1.0;
  y[7] = 1.0;
  z[7] = 0.0;

  /* Hex #1 */
  x[8]  = 0.0;
  y[8]  = 0.0;
  z[8]  = 0.0;
  x[9]  = 10.0;
  y[9]  = 0.0;
  z[9]  = 0.0;
  x[10] = 10.0;
  y[10] = 0.0;
  z[10] = -10.0;
  x[11] = 1.0;
  y[11] = 0.0;
  z[11] = -10.0;
  x[12] = 1.0;
  y[12] = 10.0;
  z[12] = 0.0;
  x[13] = 10.0;
  y[13] = 10.0;
  z[13] = 0.0;
  x[14] = 10.0;
  y[14] = 10.0;
  z[14] = -10.0;
  x[15] = 1.0;
  y[15] = 10.0;
  z[15] = -10.0;

  /* Tetra #1 */
  x[16] = 0.0;
  y[16] = 0.0;
  z[16] = 0.0;
  x[17] = 1.0;
  y[17] = 0.0;
  z[17] = 5.0;
  x[18] = 10.0;
  y[18] = 0.0;
  z[18] = 2.0;
  x[19] = 7.0;
  y[19] = 5.0;
  z[19] = 3.0;

  /* Wedge #1 */
  x[20] = 3.0;
  y[20] = 0.0;
  z[20] = 6.0;
  x[21] = 6.0;
  y[21] = 0.0;
  z[21] = 0.0;
  x[22] = 0.0;
  y[22] = 0.0;
  z[22] = 0.0;
  x[23] = 3.0;
  y[23] = 2.0;
  z[23] = 6.0;
  x[24] = 6.0;
  y[24] = 2.0;
  z[24] = 2.0;
  x[25] = 0.0;
  y[25] = 2.0;
  z[25] = 0.0;

  error = ex_put_coord(exoid, x, y, z);
  printf("after ex_put_coord, error = %d\n", error);

  /* write nodal coordinates values and names to database */

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_coord(exoidm[n], x, y, z);
    printf("after ex_put_coord (%d), error = %d\n", n, error);
  }

  coord_names[0] = "xcoor";
  coord_names[1] = "ycoor";
  coord_names[2] = "zcoor";

  error = ex_put_coord_names(exoid, coord_names);
  printf("after ex_put_coord_names, error = %d\n", error);

  coord_names2[0] = "xcoor";
  coord_names2[1] = "ycoor";
  coord_names2[2] = "zcoor";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_coord_names(exoidm[n], coord_names2);
    printf("after ex_put_coord_names (%d), error = %d\n", n, error);
  }

  /* write element order map */

  elem_map = (int *)calloc(num_elem, sizeof(int));

  for (i = 1; i <= num_elem; i++) {
    elem_map[i - 1] = i;
  }

  error = ex_put_map(exoid, elem_map);
  printf("after ex_put_map, error = %d\n", error);

  free(elem_map);

  elem_map2 = (int *)calloc(num_elem2, sizeof(int));

  for (i = 1; i <= num_elem2; i++) {
    elem_map2[i - 1] = i;
  }

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_map(exoidm[n], elem_map2);
    printf("after ex_put_map (%d), error = %d\n", n, error);
  }

  free(elem_map2);

  /* write element block parameters */

  num_elem_in_block[0] = 1;
  num_elem_in_block[1] = 1;
  num_elem_in_block[2] = 1;
  num_elem_in_block[3] = 1;
  num_elem_in_block[4] = 1;

  num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */
  num_nodes_per_elem[4] = 6; /* elements in block #3 are 6-node wedges */

  ebids[0] = 10;
  ebids[1] = 11;
  ebids[2] = 12;
  ebids[3] = 13;
  ebids[4] = 14;

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "quad", num_elem_in_block[0],
                       num_nodes_per_elem[0], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[1], "quad", num_elem_in_block[1],
                       num_nodes_per_elem[1], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[2], "hex", num_elem_in_block[2],
                       num_nodes_per_elem[2], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[3], "tetra", num_elem_in_block[3],
                       num_nodes_per_elem[3], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[4], "wedge", num_elem_in_block[4],
                       num_nodes_per_elem[4], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  /* write element block properties */

  prop_names[0] = "MATL";
  prop_names[1] = "DENSITY";
  error         = ex_put_prop_names(exoid, EX_ELEM_BLOCK, 2, prop_names);
  printf("after ex_put_prop_names, error = %d\n", error);

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
  printf("after ex_put_prop, error = %d\n", error);

  /* files n */

  num_elem_in_block2[0] = 1;
  num_elem_in_block2[1] = 1;
  num_elem_in_block2[2] = 1;
  num_elem_in_block2[3] = 1;
  num_elem_in_block2[4] = 1;

  num_nodes_per_elem2[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem2[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem2[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem2[3] = 4; /* elements in block #3 are 4-node tetras */
  num_nodes_per_elem2[4] = 6; /* elements in block #3 are 6-node wedges */

  ebids2[0] = 10;
  ebids2[1] = 11;
  ebids2[2] = 12;
  ebids2[3] = 13;
  ebids2[4] = 14;

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_block(exoidm[n], EX_ELEM_BLOCK, ebids2[0], "quad", num_elem_in_block2[0],
                         num_nodes_per_elem2[0], 0, 0, 1);
    printf("after ex_put_elem_block (%d), error = %d\n", n, error);

    error = ex_put_block(exoidm[n], EX_ELEM_BLOCK, ebids2[1], "quad", num_elem_in_block2[1],
                         num_nodes_per_elem2[1], 0, 0, 1);
    printf("after ex_put_elem_block (%d), error = %d\n", n, error);

    error = ex_put_block(exoidm[n], EX_ELEM_BLOCK, ebids2[2], "hex", num_elem_in_block2[2],
                         num_nodes_per_elem2[2], 0, 0, 1);
    printf("after ex_put_elem_block (%d), error = %d\n", n, error);

    error = ex_put_block(exoidm[n], EX_ELEM_BLOCK, ebids2[3], "tetra", num_elem_in_block2[3],
                         num_nodes_per_elem2[3], 0, 0, 1);
    printf("after ex_put_elem_block (%d), error = %d\n", n, error);

    error = ex_put_block(exoidm[n], EX_ELEM_BLOCK, ebids2[4], "wedge", num_elem_in_block2[4],
                         num_nodes_per_elem2[4], 0, 0, 1);
    printf("after ex_put_elem_block (%d), error = %d\n", n, error);

    /* write element block properties */

    prop_names[0] = "MATL";
    prop_names[1] = "DENSITY";
    error         = ex_put_prop_names(exoidm[n], EX_ELEM_BLOCK, 2, prop_names);
    printf("after ex_put_prop_names (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_ELEM_BLOCK, ebids2[0], "MATL", 100);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
    error = ex_put_prop(exoidm[n], EX_ELEM_BLOCK, ebids2[1], "MATL", 200);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
    error = ex_put_prop(exoidm[n], EX_ELEM_BLOCK, ebids2[2], "MATL", 300);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
    error = ex_put_prop(exoidm[n], EX_ELEM_BLOCK, ebids2[3], "MATL", 400);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
    error = ex_put_prop(exoidm[n], EX_ELEM_BLOCK, ebids2[4], "MATL", 500);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
  }

  /* write element connectivity */

  connect    = (int *)calloc(8, sizeof(int));
  connect[0] = 1;
  connect[1] = 2;
  connect[2] = 3;
  connect[3] = 4;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 5;
  connect[1] = 6;
  connect[2] = 7;
  connect[3] = 8;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[1], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 9;
  connect[1] = 10;
  connect[2] = 11;
  connect[3] = 12;
  connect[4] = 13;
  connect[5] = 14;
  connect[6] = 15;
  connect[7] = 16;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 17;
  connect[1] = 18;
  connect[2] = 19;
  connect[3] = 20;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[3], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 21;
  connect[1] = 22;
  connect[2] = 23;
  connect[3] = 24;
  connect[4] = 25;
  connect[5] = 26;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[4], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  free(connect);

  for (n = 0; n < nexofiles; n++) {
    connect2    = (int *)calloc(8, sizeof(int));
    connect2[0] = 1;
    connect2[1] = 2;
    connect2[2] = 3;
    connect2[3] = 4;

    error = ex_put_conn(exoidm[n], EX_ELEM_BLOCK, ebids[0], connect2, NULL, NULL);
    printf("after ex_put_elem_conn (%d), error = %d\n", n, error);

    connect2[0] = 5;
    connect2[1] = 6;
    connect2[2] = 7;
    connect2[3] = 8;

    error = ex_put_conn(exoidm[n], EX_ELEM_BLOCK, ebids[1], connect2, NULL, NULL);
    printf("after ex_put_elem_conn (%d), error = %d\n", n, error);

    connect2[0] = 9;
    connect2[1] = 10;
    connect2[2] = 11;
    connect2[3] = 12;
    connect2[4] = 13;
    connect2[5] = 14;
    connect2[6] = 15;
    connect2[7] = 16;

    error = ex_put_conn(exoidm[n], EX_ELEM_BLOCK, ebids2[2], connect2, NULL, NULL);
    printf("after ex_put_elem_conn (%d), error = %d\n", n, error);

    connect2[0] = 17;
    connect2[1] = 18;
    connect2[2] = 19;
    connect2[3] = 20;

    error = ex_put_conn(exoidm[n], EX_ELEM_BLOCK, ebids2[3], connect2, NULL, NULL);
    printf("after ex_put_elem_conn (%d), error = %d\n", n, error);

    connect2[0] = 21;
    connect2[1] = 22;
    connect2[2] = 23;
    connect2[3] = 24;
    connect2[4] = 25;
    connect2[5] = 26;

    error = ex_put_conn(exoidm[n], EX_ELEM_BLOCK, ebids2[4], connect2, NULL, NULL);
    printf("after ex_put_elem_conn (%d), error = %d\n", n, error);

    free(connect2);
  }

  /* write element block attributes */

  attrib[0] = 3.14159;
  error     = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  attrib[0] = 6.14159;
  error     = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[1], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[2], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[3], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[4], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  for (n = 0; n < nexofiles; n++) {
    attrib2[0] = 3.;
    error      = ex_put_attr(exoidm[n], EX_ELEM_BLOCK, ebids[0], attrib2);
    printf("after ex_put_elem_attr (%d), error = %d\n", n, error);

    attrib2[0] = 6.;
    error      = ex_put_attr(exoidm[n], EX_ELEM_BLOCK, ebids[1], attrib2);
    printf("after ex_put_elem_attr (%d), error = %d\n", n, error);

    error = ex_put_attr(exoidm[n], EX_ELEM_BLOCK, ebids[2], attrib2);
    printf("after ex_put_elem_attr (%d), error = %d\n", n, error);

    error = ex_put_attr(exoidm[n], EX_ELEM_BLOCK, ebids[3], attrib2);
    printf("after ex_put_elem_attr (%d), error = %d\n", n, error);

    error = ex_put_attr(exoidm[n], EX_ELEM_BLOCK, ebids[4], attrib2);
    printf("after ex_put_elem_attr (%d), error = %d\n", n, error);
  }

#ifdef EX_TEST_INDIV_NODESET
  /* write individual node sets */

  error = ex_put_set_param(exoid, EX_NODE_SET, 20, 5, 5);
  printf("after ex_put_node_set_param, error = %d\n", error);

  node_list[0] = 10;
  node_list[1] = 11;
  node_list[2] = 12;
  node_list[3] = 13;
  node_list[4] = 14;

  dist_fact[0] = 1.0;
  dist_fact[1] = 2.0;
  dist_fact[2] = 3.0;
  dist_fact[3] = 4.0;
  dist_fact[4] = 5.0;

  error = ex_put_set(exoid, EX_NODE_SET, 20, node_list, NULL);
  printf("after ex_put_node_set, error = %d\n", error);
  error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 20, dist_fact);
  printf("after ex_put_node_set, error = %d\n", error);

  error = ex_put_set_param(exoid, EX_NODE_SET, 21, 3, 3);
  printf("after ex_put_node_set_param, error = %d\n", error);

  node_list[0] = 20;
  node_list[1] = 21;
  node_list[2] = 22;

  dist_fact[0] = 1.1;
  dist_fact[1] = 2.1;
  dist_fact[2] = 3.1;

  error = ex_put_set(exoid, EX_NODE_SET, 21, node_list, NULL);
  printf("after ex_put_node_set, error = %d\n", error);
  error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 21, dist_fact);
  printf("after ex_put_node_set, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  printf("after ex_put_prop, error = %d\n", error);

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  printf("after ex_put_prop_array, error = %d\n", error);

  /* file 2 */
  for (n = 0; n < nexofiles; n++) {
    error = ex_put_set_param(exoidm[n], EX_NODE_SET, 20, 5, 5);
    printf("after ex_put_node_set_param (%d), error = %d\n", n, error);

    node_list2[0] = 10;
    node_list2[1] = 11;
    node_list2[2] = 12;
    node_list2[3] = 13;
    node_list2[4] = 14;

    dist_fact2[0] = 1.0;
    dist_fact2[1] = 2.0;
    dist_fact2[2] = 3.0;
    dist_fact2[3] = 4.0;
    dist_fact2[4] = 5.0;

    error = ex_put_set(exoidm[n], EX_NODE_SET, 20, node_list2, NULL);
    printf("after ex_put_node_set (%d), error = %d\n", n, error);
    error = ex_put_set_dist_fact(exoidm[n], EX_NODE_SET, 20, dist_fact2);
    printf("after ex_put_node_set (%d), error = %d\n", n, error);

    error = ex_put_set_param(exoidm[n], EX_NODE_SET, 21, 3, 3);
    printf("after ex_put_node_set_param (%d), error = %d\n", n, error);

    node_list2[0] = 20;
    node_list2[1] = 21;
    node_list2[2] = 22;

    dist_fact2[0] = 1.1;
    dist_fact2[1] = 2.1;
    dist_fact2[2] = 3.1;

    error = ex_put_set(exoidm[n], EX_NODE_SET, 21, node_list2, NULL);
    printf("after ex_put_node_set (%d), error = %d\n", n, error);
    error = ex_put_set_dist_fact(exoidm[n], EX_NODE_SET, 21, dist_fact2);
    printf("after ex_put_node_set (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_NODE_SET, 20, "FACE", 4);
    printf("after ex_put_prop (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_NODE_SET, 21, "FACE", 5);
    printf("after ex_put_prop (%d), error = %d\n", n, error);

    prop_array[0] = 1000;
    prop_array[1] = 2000;

    error = ex_put_prop_array(exoidm[n], EX_NODE_SET, "VELOCITY", prop_array);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
  }

#else /* EX_TEST_INDIV_NODESET */
  /* write concatenated node sets; this produces the same information as
   * the above code which writes individual node sets
   */

  ids[0] = 20;
  ids[1] = 21;

  num_nodes_per_set[0] = 5;
  num_nodes_per_set[1] = 3;

  node_ind[0] = 0;
  node_ind[1] = 5;

  node_list[0] = 10;
  node_list[1] = 11;
  node_list[2] = 12;
  node_list[3] = 13;
  node_list[4] = 14;
  node_list[5] = 20;
  node_list[6] = 21;
  node_list[7] = 22;

  num_df_per_set[0] = 5;
  num_df_per_set[1] = 3;

  df_ind[0] = 0;
  df_ind[1] = 5;

  dist_fact[0] = 1.0;
  dist_fact[1] = 2.0;
  dist_fact[2] = 3.0;
  dist_fact[3] = 4.0;
  dist_fact[4] = 5.0;
  dist_fact[5] = 1.1;
  dist_fact[6] = 2.1;
  dist_fact[7] = 3.1;

  error = ex_put_concat_node_sets(exoid, ids, num_nodes_per_set, node_ind, node_list, dist_fact);
  printf("after ex_put_concat_node_sets, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  printf("after ex_put_prop, error = %d\n", error);

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  printf("after ex_put_prop_array, error = %d\n", error);

  ids2[0] = 20;
  ids2[1] = 21;

  num_nodes_per_set2[0] = 5;
  num_nodes_per_set2[1] = 3;

  node_ind2[0] = 0;
  node_ind2[1] = 5;

  node_list2[0] = 10;
  node_list2[1] = 11;
  node_list2[2] = 12;
  node_list2[3] = 13;
  node_list2[4] = 14;
  node_list2[5] = 20;
  node_list2[6] = 21;
  node_list2[7] = 22;

  num_df_per_set2[0] = 5;
  num_df_per_set2[1] = 3;

  df_ind2[0] = 0;
  df_ind2[1] = 5;

  dist_fact2[0] = 1.0;
  dist_fact2[1] = 2.0;
  dist_fact2[2] = 3.0;
  dist_fact2[3] = 4.0;
  dist_fact2[4] = 5.0;
  dist_fact2[5] = 1.1;
  dist_fact2[6] = 2.1;
  dist_fact2[7] = 3.1;

  prop_array2[0] = 1000;
  prop_array2[1] = 2000;

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_concat_node_sets(exoidm[n], ids2, num_nodes_per_set2, num_df_per_set2, node_ind2,
                                    df_ind2, node_list2, dist_fact2);
    printf("after ex_put_concat_node_sets, error = %d\n", error);

    error = ex_put_prop(exoidm[n], EX_NODE_SET, 20, "FACE", 4);
    printf("after ex_put_prop, error = %d\n", error);
    error = ex_put_prop(exoidm[n], EX_NODE_SET, 21, "FACE", 5);
    printf("after ex_put_prop, error = %d\n", error);

    error = ex_put_prop_array(exoidm[n], EX_NODE_SET, "VELOCITY", prop_array2);
    printf("after ex_put_prop_array, error = %d\n", error);
  }

#endif /* EX_TEST_INDIV_NODESET */

#ifdef TEST_INDIV_SIDESET
  /* write individual side sets */

  /* side set #1  - quad */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 30, 2, 4);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 2;
  elem_list[1] = 2;

  side_list[0] = 4;
  side_list[1] = 2;

  dist_fact[0] = 30.0;
  dist_fact[1] = 30.1;
  dist_fact[2] = 30.2;
  dist_fact[3] = 30.3;

  error = ex_put_set(exoid, EX_SIDE_SET, 30, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 30, dist_fact);
  printf("after ex_put_side_set_dist_fact, error = %d\n", error);

  /* side set #2  - quad  spanning elements */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 31, 2, 4);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 1;
  elem_list[1] = 2;

  side_list[0] = 2;
  side_list[1] = 3;

  dist_fact[0] = 31.0;
  dist_fact[1] = 31.1;
  dist_fact[2] = 31.2;
  dist_fact[3] = 31.3;

  error = ex_put_set(exoid, EX_SIDE_SET, 31, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 31, dist_fact);
  printf("after ex_put_side_set_dist_fact, error = %d\n", error);

  /* side set #3  - hex */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 32, 7, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 3;
  elem_list[1] = 3;
  elem_list[2] = 3;
  elem_list[3] = 3;
  elem_list[4] = 3;
  elem_list[5] = 3;
  elem_list[6] = 3;

  side_list[0] = 5;
  side_list[1] = 3;
  side_list[2] = 3;
  side_list[3] = 2;
  side_list[4] = 4;
  side_list[5] = 1;
  side_list[6] = 6;

  error = ex_put_set(exoid, EX_SIDE_SET, 32, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  /* side set #4  - tetras */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 33, 4, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 4;
  elem_list[1] = 4;
  elem_list[2] = 4;
  elem_list[3] = 4;

  side_list[0] = 1;
  side_list[1] = 2;
  side_list[2] = 3;
  side_list[3] = 4;

  error = ex_put_set(exoid, EX_SIDE_SET, 33, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  /* side set #5  - wedges */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 34, 5, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 5;
  elem_list[1] = 5;
  elem_list[2] = 5;
  elem_list[3] = 5;
  elem_list[4] = 5;

  side_list[0] = 1;
  side_list[1] = 2;
  side_list[2] = 3;
  side_list[3] = 4;
  side_list[4] = 5;

  error = ex_put_set(exoid, EX_SIDE_SET, 34, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  printf("after ex_put_prop, error = %d\n", error);

  /* file 2 */

  for (n = 0; n < nexofiles; n++) {
    /* side set 1 */

    error = ex_put_set_param(exoidm[n], EX_SIDE_SET, 30, 2, 4);
    printf("after ex_put_side_set_param (%d), error = %d\n", n, error);

    elem_list2[0] = 2;
    elem_list2[1] = 2;

    side_list2[0] = 4;
    side_list2[1] = 2;

    dist_fact2[0] = 30.0;
    dist_fact2[1] = 30.1;
    dist_fact2[2] = 30.2;
    dist_fact2[3] = 30.3;

    error = ex_put_set(exoidm[n], EX_SIDE_SET, 30, elem_list2, side_list2);
    printf("after ex_put_side_set (%d), error = %d\n", n, error);

    error = ex_put_set_dist_fact(exoidm[n], EX_SIDE_SET, 30, dist_fact2);
    printf("after ex_put_side_set_dist_fact (%d), error = %d\n", n, error);

    /* side set 2 */

    error = ex_put_set_param(exoidm[n], EX_SIDE_SET, 31, 2, 4);
    printf("after ex_put_side_set_param (%d), error = %d\n", n, error);

    elem_list2[0] = 1;
    elem_list2[1] = 2;

    side_list2[0] = 2;
    side_list2[1] = 3;

    dist_fact2[0] = 31.0;
    dist_fact2[1] = 31.1;
    dist_fact2[2] = 31.2;
    dist_fact2[3] = 31.3;

    error = ex_put_set(exoidm[n], EX_SIDE_SET, 31, elem_list2, side_list2);
    printf("after ex_put_side_set (%d), error = %d\n", n, error);

    error = ex_put_set_dist_fact(exoidm[n], EX_SIDE_SET, 31, dist_fact2);
    printf("after ex_put_side_set_dist_fact (%d), error = %d\n", n, error);

    /* side set #3  - hex */

    error = ex_put_set_param(exoidm[n], EX_SIDE_SET, 32, 7, 0);
    printf("after ex_put_side_set_param (%d), error = %d\n", n, error);

    elem_list2[0] = 3;
    elem_list2[1] = 3;
    elem_list2[2] = 3;
    elem_list2[3] = 3;
    elem_list2[4] = 3;
    elem_list2[5] = 3;
    elem_list2[6] = 3;

    side_list2[0] = 5;
    side_list2[1] = 3;
    side_list2[2] = 3;
    side_list2[3] = 2;
    side_list2[4] = 4;
    side_list2[5] = 1;
    side_list2[6] = 6;

    error = ex_put_set(exoidm[n], EX_SIDE_SET, 32, elem_list2, side_list2);
    printf("after ex_put_side_set (%d), error = %d\n", n, error);

    /* side set #4  - tetras */

    error = ex_put_set_param(exoidm[n], EX_SIDE_SET, 33, 4, 0);
    printf("after ex_put_side_set_param (%d), error = %d\n", n, error);

    elem_list2[0] = 4;
    elem_list2[1] = 4;
    elem_list2[2] = 4;
    elem_list2[3] = 4;

    side_list2[0] = 1;
    side_list2[1] = 2;
    side_list2[2] = 3;
    side_list2[3] = 4;

    error = ex_put_set(exoidm[n], EX_SIDE_SET, 33, elem_list2, side_list2);
    printf("after ex_put_side_set (%d), error = %d\n", n, error);

    /* side set #5  - wedges */

    error = ex_put_set_param(exoidm[n], EX_SIDE_SET, 34, 5, 0);
    printf("after ex_put_side_set_param (%d), error = %d\n", n, error);

    elem_list2[0] = 5;
    elem_list2[1] = 5;
    elem_list2[2] = 5;
    elem_list2[3] = 5;
    elem_list2[4] = 5;

    side_list2[0] = 1;
    side_list2[1] = 2;
    side_list2[2] = 3;
    side_list2[3] = 4;
    side_list2[4] = 5;

    error = ex_put_set(exoidm[n], EX_SIDE_SET, 34, elem_list2, side_list2);
    printf("after ex_put_side_set (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_SIDE_SET, 30, "COLOR", 100);
    printf("after ex_put_prop (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_SIDE_SET, 31, "COLOR", 101);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
  }

#else /* TEST_INDIV_SIDESET */
  /* write concatenated side sets; this produces the same information as
   * the above code which writes individual side sets
   */

  ids[0] = 30;
  ids[1] = 31;
  ids[2] = 32;
  ids[3] = 33;
  ids[4] = 34;

  node_list[0] = 8;
  node_list[1] = 5;
  node_list[2] = 6;
  node_list[3] = 7;

  node_list[4] = 2;
  node_list[5] = 3;
  node_list[6] = 7;
  node_list[7] = 8;

  node_list[8]  = 9;
  node_list[9]  = 12;
  node_list[10] = 11;
  node_list[11] = 10;

  node_list[12] = 11;
  node_list[13] = 12;
  node_list[14] = 16;
  node_list[15] = 15;

  node_list[16] = 16;
  node_list[17] = 15;
  node_list[18] = 11;
  node_list[19] = 12;

  node_list[20] = 10;
  node_list[21] = 11;
  node_list[22] = 15;
  node_list[23] = 14;

  node_list[24] = 13;
  node_list[25] = 16;
  node_list[26] = 12;
  node_list[27] = 9;

  node_list[28] = 14;
  node_list[29] = 13;
  node_list[30] = 9;
  node_list[31] = 10;

  node_list[32] = 16;
  node_list[33] = 13;
  node_list[34] = 14;
  node_list[35] = 15;

  node_list[36] = 17;
  node_list[37] = 18;
  node_list[38] = 20;

  node_list[39] = 18;
  node_list[40] = 19;
  node_list[41] = 20;

  node_list[42] = 20;
  node_list[43] = 19;
  node_list[44] = 17;

  node_list[45] = 19;
  node_list[46] = 18;
  node_list[47] = 17;

  node_list[48] = 25;
  node_list[49] = 24;
  node_list[50] = 21;
  node_list[51] = 22;

  node_list[52] = 26;
  node_list[53] = 25;
  node_list[54] = 22;
  node_list[55] = 23;

  node_list[56] = 26;
  node_list[57] = 23;
  node_list[58] = 21;
  node_list[59] = 24;

  node_list[60] = 23;
  node_list[61] = 22;
  node_list[62] = 21;

  node_list[63] = 24;
  node_list[64] = 25;
  node_list[65] = 26;

  node_ind[0] = 0;
  node_ind[1] = 4;
  node_ind[2] = 8;
  node_ind[3] = 36;
  node_ind[4] = 47;

  num_elem_per_set[0] = 2;
  num_elem_per_set[1] = 2;
  num_elem_per_set[2] = 7;
  num_elem_per_set[3] = 4;
  num_elem_per_set[4] = 5;

  num_nodes_per_set[0] = 4;
  num_nodes_per_set[1] = 4;
  num_nodes_per_set[2] = 28;
  num_nodes_per_set[3] = 12;
  num_nodes_per_set[4] = 18;

  elem_ind[0] = 0;
  elem_ind[1] = 2;
  elem_ind[2] = 4;
  elem_ind[3] = 11;
  elem_ind[4] = 15;

  elem_list[0]  = 2;
  elem_list[1]  = 2;
  elem_list[2]  = 1;
  elem_list[3]  = 2;
  elem_list[4]  = 3;
  elem_list[5]  = 3;
  elem_list[6]  = 3;
  elem_list[7]  = 3;
  elem_list[8]  = 3;
  elem_list[9]  = 3;
  elem_list[10] = 3;
  elem_list[11] = 4;
  elem_list[12] = 4;
  elem_list[13] = 4;
  elem_list[14] = 4;
  elem_list[15] = 5;
  elem_list[16] = 5;
  elem_list[17] = 5;
  elem_list[18] = 5;
  elem_list[19] = 5;

  error = ex_cvt_nodes_to_sides(exoid, num_elem_per_set, num_nodes_per_set, elem_ind, node_ind,
                                elem_list, node_list, side_list);
  printf("after ex_cvt_nodes_to_sides, error = %d\n", error);

  num_df_per_set[0] = 4;
  num_df_per_set[1] = 4;
  num_df_per_set[2] = 0;
  num_df_per_set[3] = 0;
  num_df_per_set[4] = 0;

  df_ind[0] = 0;
  df_ind[1] = 4;

  dist_fact[0] = 30.0;
  dist_fact[1] = 30.1;
  dist_fact[2] = 30.2;
  dist_fact[3] = 30.3;

  dist_fact[4] = 31.0;
  dist_fact[5] = 31.1;
  dist_fact[6] = 31.2;
  dist_fact[7] = 31.3;

  {
    struct ex_set_specs set_specs;

    set_specs.sets_ids            = ids;
    set_specs.num_entries_per_set = num_elem_per_set;
    set_specs.num_dist_per_set    = num_df_per_set;
    set_specs.sets_entry_index    = elem_ind;
    set_specs.sets_dist_index     = df_ind;
    set_specs.sets_entry_list     = elem_list;
    set_specs.sets_extra_list     = side_list;
    set_specs.sets_dist_fact      = dist_fact;
    error                         = ex_put_concat_sets(exoid, EX_SIDE_SET, &set_specs);
  }

  printf("after ex_put_concat_side_sets, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  printf("after ex_put_prop, error = %d\n", error);

  /* file 2 */

  ids2[0] = 30;
  ids2[1] = 31;
  ids2[2] = 32;
  ids2[3] = 33;
  ids2[4] = 34;

  node_list2[0] = 8;
  node_list2[1] = 5;
  node_list2[2] = 6;
  node_list2[3] = 7;

  node_list2[4] = 2;
  node_list2[5] = 3;
  node_list2[6] = 7;
  node_list2[7] = 8;

  node_list2[8]  = 9;
  node_list2[9]  = 12;
  node_list2[10] = 11;
  node_list2[11] = 10;

  node_list2[12] = 11;
  node_list2[13] = 12;
  node_list2[14] = 16;
  node_list2[15] = 15;

  node_list2[16] = 16;
  node_list2[17] = 15;
  node_list2[18] = 11;
  node_list2[19] = 12;

  node_list2[20] = 10;
  node_list2[21] = 11;
  node_list2[22] = 15;
  node_list2[23] = 14;

  node_list2[24] = 13;
  node_list2[25] = 16;
  node_list2[26] = 12;
  node_list2[27] = 9;

  node_list2[28] = 14;
  node_list2[29] = 13;
  node_list2[30] = 9;
  node_list2[31] = 10;

  node_list2[32] = 16;
  node_list2[33] = 13;
  node_list2[34] = 14;
  node_list2[35] = 15;

  node_list2[36] = 17;
  node_list2[37] = 18;
  node_list2[38] = 20;

  node_list2[39] = 18;
  node_list2[40] = 19;
  node_list2[41] = 20;

  node_list2[42] = 20;
  node_list2[43] = 19;
  node_list2[44] = 17;

  node_list2[45] = 19;
  node_list2[46] = 18;
  node_list2[47] = 17;

  node_list2[48] = 25;
  node_list2[49] = 24;
  node_list2[50] = 21;
  node_list2[51] = 22;

  node_list2[52] = 26;
  node_list2[53] = 25;
  node_list2[54] = 22;
  node_list2[55] = 23;

  node_list2[56] = 26;
  node_list2[57] = 23;
  node_list2[58] = 21;
  node_list2[59] = 24;

  node_list2[60] = 23;
  node_list2[61] = 22;
  node_list2[62] = 21;

  node_list2[63] = 24;
  node_list2[64] = 25;
  node_list2[65] = 26;

  node_ind2[0] = 0;
  node_ind2[1] = 4;
  node_ind2[2] = 8;
  node_ind2[3] = 36;
  node_ind2[4] = 47;

  num_elem_per_set2[0] = 2;
  num_elem_per_set2[1] = 2;
  num_elem_per_set2[2] = 7;
  num_elem_per_set2[3] = 4;
  num_elem_per_set2[4] = 5;

  num_nodes_per_set2[0] = 4;
  num_nodes_per_set2[1] = 4;
  num_nodes_per_set2[2] = 28;
  num_nodes_per_set2[3] = 12;
  num_nodes_per_set2[4] = 18;

  elem_ind2[0] = 0;
  elem_ind2[1] = 2;
  elem_ind2[2] = 4;
  elem_ind2[3] = 11;
  elem_ind2[4] = 15;

  elem_list2[0]  = 2;
  elem_list2[1]  = 2;
  elem_list2[2]  = 1;
  elem_list2[3]  = 2;
  elem_list2[4]  = 3;
  elem_list2[5]  = 3;
  elem_list2[6]  = 3;
  elem_list2[7]  = 3;
  elem_list2[8]  = 3;
  elem_list2[9]  = 3;
  elem_list2[10] = 3;
  elem_list2[11] = 4;
  elem_list2[12] = 4;
  elem_list2[13] = 4;
  elem_list2[14] = 4;
  elem_list2[15] = 5;
  elem_list2[16] = 5;
  elem_list2[17] = 5;
  elem_list2[18] = 5;
  elem_list2[19] = 5;

  num_df_per_set2[0] = 4;
  num_df_per_set2[1] = 4;
  num_df_per_set2[2] = 0;
  num_df_per_set2[3] = 0;
  num_df_per_set2[4] = 0;

  df_ind2[0] = 0;
  df_ind2[1] = 4;

  dist_fact2[0] = 30.0;
  dist_fact2[1] = 30.1;
  dist_fact2[2] = 30.2;
  dist_fact2[3] = 30.3;

  dist_fact2[4] = 31.0;
  dist_fact2[5] = 31.1;
  dist_fact2[6] = 31.2;
  dist_fact2[7] = 31.3;

  for (n = 0; n < nexofiles; n++) {
    error = ex_cvt_nodes_to_sides(exoidm[n], num_elem_per_set2, num_nodes_per_set2, elem_ind2,
                                  node_ind2, elem_list2, node_list2, side_list2);
    printf("after ex_cvt_nodes_to_sides (%d), error = %d\n", n, error);

    {
      struct ex_set_specs set_specs;

      set_specs.sets_ids            = ids2;
      set_specs.num_entries_per_set = num_elem_per_set2;
      set_specs.num_dist_per_set    = num_df_per_set2;
      set_specs.sets_entry_index    = elem_ind2;
      set_specs.sets_dist_index     = df_ind2;
      set_specs.sets_entry_list     = elem_list2;
      set_specs.sets_extra_list     = side_list2;
      set_specs.sets_dist_fact      = dist_fact2;
      error                         = ex_put_concat_sets(exoid, EX_SIDE_SET, &set_specs);
    }
    printf("after ex_put_concat_side_sets (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_SIDE_SET, 30, "COLOR", 100);
    printf("after ex_put_prop (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_SIDE_SET, 31, "COLOR", 101);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
  }

/* END COMMENTED OUT SECTION */

#endif /* TEST_INDIV_SIDESET */

  /* write QA records */

  num_qa_rec = 2;

  qa_record[0][0] = "TESTWTM";
  qa_record[0][1] = "testwtm";
  qa_record[0][2] = "07/07/93";
  qa_record[0][3] = "15:41:33";
  qa_record[1][0] = "FASTQ";
  qa_record[1][1] = "fastq";
  qa_record[1][2] = "07/07/93";
  qa_record[1][3] = "16:41:33";

  error = ex_put_qa(exoid, num_qa_rec, qa_record);
  printf("after ex_put_qa, error = %d\n", error);

  num_qa_rec2 = 2;

  qa_record2[0][0] = "TESTWTM";
  qa_record2[0][1] = "testwtm";
  qa_record2[0][2] = "07/07/93";
  qa_record2[0][3] = "15:41:33";
  qa_record2[1][0] = "FASTQ";
  qa_record2[1][1] = "fastq";
  qa_record2[1][2] = "07/07/93";
  qa_record2[1][3] = "16:41:33";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_qa(exoidm[n], num_qa_rec2, qa_record2);
    printf("after ex_put_qa (%d), error = %d\n", n, error);
  }

  /* write information records */

  num_info = 3;

  info[0] = "This is the first information record.";
  info[1] = "This is the second information record.";
  info[2] = "This is the third information record.";

  error = ex_put_info(exoid, num_info, info);
  printf("after ex_put_info, error = %d\n", error);

  num_info2 = 3;

  info2[0] = "This is the first information record.";
  info2[1] = "This is the second information record.";
  info2[2] = "This is the third information record.";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_info(exoidm[n], num_info2, info2);
    printf("after ex_put_info (%d), error = %d\n", n, error);
  }

  /* write results variables parameters and names */

  num_glo_vars = 1;

  var_names[0] = "glo_vars";

  error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_glo_vars2 = 1;

  var_names2[0] = "glo_vars";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_variable_param(exoidm[n], EX_GLOBAL, num_glo_vars2);
    printf("after ex_put_variable_param (%d), error = %d\n", n, error);
    error = ex_put_variable_names(exoidm[n], EX_GLOBAL, num_glo_vars2, var_names2);
    printf("after ex_put_variable_names (%d), error = %d\n", n, error);
  }

  num_nod_vars = 2;

  var_names[0] = "nod_var0";
  var_names[1] = "nod_var1";

  error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_nod_vars2 = 2;

  var_names2[0] = "nod_var0";
  var_names2[1] = "nod_var1";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_variable_param(exoidm[n], EX_NODAL, num_nod_vars2);
    printf("after ex_put_variable_param (%d), error = %d\n", n, error);
    error = ex_put_variable_names(exoidm[n], EX_NODAL, num_nod_vars2, var_names2);
    printf("after ex_put_variable_names (%d), error = %d\n", n, error);
  }

  num_ele_vars = 3;

  var_names[0] = "ele_var0";
  var_names[1] = "ele_var1";
  var_names[2] = "ele_var2";

  error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_ele_vars2 = 3;

  var_names2[0] = "ele_var20";
  var_names2[1] = "ele_var21";
  var_names2[2] = "ele_var22";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_variable_param(exoidm[n], EX_ELEM_BLOCK, num_ele_vars2);
    printf("after ex_put_variable_param (%d), error = %d\n", n, error);
    error = ex_put_variable_names(exoidm[n], EX_ELEM_BLOCK, num_ele_vars, var_names);
    printf("after ex_put_variable_names (%d), error = %d\n", n, error);
  }

  /* write element variable truth table */

  truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int));

  k = 0;
  for (i = 0; i < num_elem_blk; i++) {
    for (j = 0; j < num_ele_vars; j++) {
      truth_tab[k++] = 1;
    }
  }

  error = ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab);
  printf("after ex_put_elem_var_tab, error = %d\n", error);

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_truth_table(exoidm[n], EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab);
    printf("after ex_put_elem_var_tab (%d), error = %d\n", n, error);
  }

  free(truth_tab);

  /* for each time step, write the analysis results;
   * the code below fills the arrays  glob_var_vals,
   * nodal_var_vals, and elem_var_vals with values for debugging purposes;
   * obviously the analysis code will populate these arrays
   */

  whole_time_step = 1;
  num_time_steps  = 10;

  glob_var_vals  = (float *)calloc(num_glo_vars, sizeof(float));
  nodal_var_vals = (float *)calloc(num_nodes, sizeof(float));
  elem_var_vals  = (float *)calloc(4, sizeof(float));

  for (i = 0; i < num_time_steps; i++) {
    time_value  = (float)(i + 1) / 100.;
    time_value2 = (float)(i + 1) / 100.;

    /* write time value */

    error = ex_put_time(exoid, whole_time_step, &time_value);
    printf("after ex_put_time, error = %d\n", error);

    for (n = 0; n < nexofiles; n++) {
      error = ex_put_time(exoidm[n], whole_time_step, &time_value2);
      printf("after ex_put_time (%d), error = %d\n", n, error);
    }

    /* write global variables */

    for (j = 0; j < num_glo_vars; j++) {
      glob_var_vals[j] = (float)(j + 2) * time_value;
    }

    error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
    printf("after ex_put_glob_vars, error = %d\n", error);

    for (n = 0; n < nexofiles; n++) {
      error = ex_put_var(exoidm[n], whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
      printf("after ex_put_glob_vars (%d), error = %d\n", n, error);
    }
    /* write nodal variables */

    for (k = 1; k <= num_nod_vars; k++) {
      for (j = 0; j < num_nodes; j++) {
        nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
      }

      error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
      printf("after ex_put_nodal_var, error = %d\n", error);

      for (n = 0; n < nexofiles; n++) {
        error = ex_put_var(exoidm[n], whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
        printf("after ex_put_nodal_var (%d), error = %d\n", n, error);
      }
    }

    /* write element variables */

    for (k = 1; k <= num_ele_vars; k++) {
      for (j = 0; j < num_elem_blk; j++) {
        for (m = 0; m < num_elem_in_block[j]; m++) {
          elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
          /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
        }
        error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j],
                           elem_var_vals);
        printf("after ex_put_elem_var, error = %d\n", error);

        for (n = 0; n < nexofiles; n++) {
          error = ex_put_var(exoidm[n], whole_time_step, EX_ELEM_BLOCK, k, ebids[j],
                             num_elem_in_block[j], elem_var_vals);
          printf("after ex_put_elem_var (%d), error = %d\n", n, error);
        }
      }
    }

    whole_time_step++;

    /* update the data file; this should be done at the end of every time step
     * to ensure that no data is lost if the analysis dies
     */
    error = ex_update(exoid);
    printf("after ex_update, error = %d\n", error);
    for (n = 0; n < nexofiles; n++) {
      error = ex_update(exoidm[n]);
      printf("after ex_update (%d), error = %d\n", n, error);
    }
  }
  free(glob_var_vals);
  free(nodal_var_vals);
  free(elem_var_vals);

  /* close the EXODUS files
   */
  error = ex_close(exoid);
  printf("after ex_close, error = %d\n", error);
  for (n = 0; n < nexofiles; n++) {
    error = ex_close(exoidm[n]);
    printf("after ex_close (%d), error = %d\n", n, error);
  }
  return 0;
}
示例#29
0
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_nodes_per_elem[10];
   int num_node_sets, num_sides, num_side_sets, error;
   int i, j, k, m, *elem_map, *connect;
   int node_list[100],elem_list[100],side_list[100];
   int ebids[10], ids[10];
   int num_sides_per_set[10], num_nodes_per_set[10], num_elem_per_set[10];
   int num_df_per_set[10];
   int df_ind[10], node_ind[10], elem_ind[10], side_ind[10];
   int  num_qa_rec, num_info;
   int num_glo_vars, num_nod_vars, num_ele_vars;
   int *truth_tab;
   int whole_time_step, num_time_steps;
   int ndims, nvars, ngatts, recdim;
   int CPU_word_size,IO_word_size;
   int prop_array[2];

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float time_value;
   float *x, *y, *z, *dummy;
   float attrib[1], dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
   char tmpstr[80];
   char *prop_names[2];

   ex_opts (EX_VERBOSE | EX_ABORT);

   dummy = 0; /* assign this so the Cray compiler doesn't complain */

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("test.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

/* initialize file with parameters */

   num_dim = 3;
   num_nodes = BIG;
   num_elem = BIG;
   num_elem_blk = 5;
   num_node_sets = 2;
   num_side_sets = 5;

   error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem,
                        num_elem_blk, num_node_sets, num_side_sets);

   printf ("after ex_put_init, error = %d\n", error);

/* write nodal coordinates values and names to database */

   if (!(x = (float *) calloc(BIG, sizeof(float))))
   {
     printf ("couldn't allocate memory for x node array%d\n");
     exit(1);
   }

   if (!(y = (float *) calloc(BIG, sizeof(float))))
   {
     printf ("couldn't allocate memory for y node array%d\n");
     exit(1);
   }

   if (!(z = (float *) calloc(BIG, sizeof(float))))
   {
     printf ("couldn't allocate memory for z node array%d\n");
     exit(1);
   }

   for (i=0; i<num_nodes; i++)
   {
     /* dummy up the coordinate space */
     x[i]=i;
     y[i]=i+.1;
     z[i]=i+.2;
   }

   error = ex_put_coord (exoid, x, y, z);
   printf ("after ex_put_coord, error = %d\n", error);


   coord_names[0] = "xcoor";
   coord_names[1] = "ycoor";
   coord_names[2] = "zcoor";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);


/* write element order map */

   elem_map = (int *) calloc(num_elem, sizeof(int));

   for (i=1; i<=num_elem; i++)
   {
      elem_map[i-1] = i;
   }

   error = ex_put_map (exoid, elem_map);
   printf ("after ex_put_map, error = %d\n", error);

   free (elem_map);


/* write element block parameters */

   num_elem_in_block[0] = 1;
   num_elem_in_block[1] = 1;
   num_elem_in_block[2] = 1;
   num_elem_in_block[3] = 1;
   num_elem_in_block[4] = 1;

   num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
   num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
   num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
   num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */
   num_nodes_per_elem[4] = 6; /* elements in block #3 are 6-node wedges */

   ebids[0] = 10;
   ebids[1] = 11;
   ebids[2] = 12;
   ebids[3] = 13;
   ebids[4] = 14;

   error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0],
                              num_nodes_per_elem[0], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1],
                               num_nodes_per_elem[1], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2],
                               num_nodes_per_elem[2], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3],
                               num_nodes_per_elem[3], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   error = ex_put_elem_block (exoid, ebids[4], "wedge", num_elem_in_block[4],
                               num_nodes_per_elem[4], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

/* write element block properties */

   prop_names[0] = "MATL";
   prop_names[1] = "DENSITY";
   error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names);
   printf ("after ex_put_prop_names, error = %d\n", error);

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
   printf ("after ex_put_prop, error = %d\n", error);

/* write element connectivity */

   connect = (int *) calloc(8, sizeof(int));
   connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;

   error = ex_put_elem_conn (exoid, ebids[0], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8;

   error = ex_put_elem_conn (exoid, ebids[1], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12;
   connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16;

   error = ex_put_elem_conn (exoid, ebids[2], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;

   error = ex_put_elem_conn (exoid, ebids[3], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   connect[0] = 21; connect[1] = 22; connect[2] = 23;
   connect[3] = 24; connect[4] = 25; connect[5] = 26;

   error = ex_put_elem_conn (exoid, ebids[4], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   free (connect);


/* write element block attributes */

   attrib[0] = 3.14159;
   error = ex_put_elem_attr (exoid, ebids[0], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   attrib[0] = 6.14159;
   error = ex_put_elem_attr (exoid, ebids[1], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   error = ex_put_elem_attr (exoid, ebids[2], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   error = ex_put_elem_attr (exoid, ebids[3], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   error = ex_put_elem_attr (exoid, ebids[4], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

/* write individual node sets */


   error = ex_put_node_set_param (exoid, 20, 5, 5);
   printf ("after ex_put_node_set_param, error = %d\n", error);

   node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
   node_list[3] = 13; node_list[4] = 14; 

   dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0;
   dist_fact[3] = 4.0; dist_fact[4] = 5.0;

   error = ex_put_node_set (exoid, 20, node_list);
   printf ("after ex_put_node_set, error = %d\n", error);
   error = ex_put_node_set_dist_fact (exoid, 20, dist_fact);
   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);

   error = ex_put_node_set_param (exoid, 21, 3, 3);
   printf ("after ex_put_node_set_param, error = %d\n", error);

   node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; 

   dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1;

   error = ex_put_node_set (exoid, 21, node_list);
   printf ("after ex_put_node_set, error = %d\n", error);
   error = ex_put_node_set_dist_fact (exoid, 21, dist_fact);
   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);

   error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
   printf ("after ex_put_prop, error = %d\n", error);

   prop_array[0] = 1000;
   prop_array[1] = 2000;

   error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
   printf ("after ex_put_prop_array, error = %d\n", error);


/* write concatenated node sets; this produces the same information as
 * the above code which writes individual node sets
 */

/* THIS SECTION IS COMMENTED OUT

   ids[0] = 20; ids[1] = 21;

   num_nodes_per_set[0] = 5; num_nodes_per_set[1] = 3;

   node_ind[0] = 0; node_ind[1] = 5;

   node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
   node_list[3] = 13; node_list[4] = 14; 
   node_list[5] = 20; node_list[6] = 21; node_list[7] = 22;

   num_df_per_set[0] = 5; num_df_per_set[1] = 3;

   df_ind[0] = 0; df_ind[1] = 5;

   dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0; 
   dist_fact[3] = 4.0; dist_fact[4] = 5.0; 
   dist_fact[5] = 1.1; dist_fact[6] = 2.1; dist_fact[7] = 3.1;

   error = ex_put_concat_node_sets (exoid, ids, num_nodes_per_set,
                                    num_df_per_set, node_ind,
                                    df_ind, node_list, dist_fact);
   printf ("after ex_put_concat_node_sets, error = %d\n", error);

   error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
   printf ("after ex_put_prop, error = %d\n", error);

   prop_array[0] = 1000;
   prop_array[1] = 2000;

   error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
   printf ("after ex_put_prop_array, error = %d\n", error);

   END COMMENTED OUT SECTION */


/* write individual side sets */

   /* side set #1  - quad */

   error = ex_put_side_set_param (exoid, 30, 2, 4);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   elem_list[0] = 2; elem_list[1] = 2;

   side_list[0] = 4; side_list[1] = 2;

   dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2;
   dist_fact[3] = 30.3;

   error = ex_put_side_set (exoid, 30, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   error = ex_put_side_set_dist_fact (exoid, 30, dist_fact);
   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);


   /* side set #2  - quad, spanning 2 elements  */

   error = ex_put_side_set_param (exoid, 31, 2, 4);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   elem_list[0] = 1; elem_list[1] = 2;

   side_list[0] = 2; side_list[1] = 3;

   dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2;
   dist_fact[3] = 31.3;

   error = ex_put_side_set (exoid, 31, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   error = ex_put_side_set_dist_fact (exoid, 31, dist_fact);
   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);


   /* side set #3  - hex */

   error = ex_put_side_set_param (exoid, 32, 7, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   elem_list[0] = 3; elem_list[1] = 3;
   elem_list[2] = 3; elem_list[3] = 3;
   elem_list[4] = 3; elem_list[5] = 3;
   elem_list[6] = 3;

   side_list[0] = 5; side_list[1] = 3;
   side_list[2] = 3; side_list[3] = 2;
   side_list[4] = 4; side_list[5] = 1;
   side_list[6] = 6;

   error = ex_put_side_set (exoid, 32, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);


   /* side set #4  - tetras */

   error = ex_put_side_set_param (exoid, 33, 4, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   elem_list[0] = 4; elem_list[1] = 4;
   elem_list[2] = 4; elem_list[3] = 4;

   side_list[0] = 1; side_list[1] = 2;
   side_list[2] = 3; side_list[3] = 4;

   error = ex_put_side_set (exoid, 33, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);


   /* side set #5  - wedges */

   error = ex_put_side_set_param (exoid, 34, 5, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   elem_list[0] = 5; elem_list[1] = 5;
   elem_list[2] = 5; elem_list[3] = 5;
   elem_list[4] = 5;

   side_list[0] = 1; side_list[1] = 2;
   side_list[2] = 3; side_list[3] = 4;
   side_list[4] = 5;

   error = ex_put_side_set (exoid, 34, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   /* END COMMENTED OUT SECTION */

/* write concatenated side sets; this produces the same information as
 * the above code which writes individual side sets
 */

/* THIS SECTION IS COMMENTED OUT

   ids[0] = 30;
   ids[1] = 31;
   ids[2] = 32;
   ids[3] = 33;
   ids[4] = 34;

   node_list[0] = 8; node_list[1] = 5;
   node_list[2] = 6; node_list[3] = 7;

   node_list[4] = 2; node_list[5] = 3;
   node_list[6] = 7; node_list[7] = 8;

   node_list[8] = 9; node_list[9] = 12;
   node_list[10] = 11; node_list[11] = 10;

   node_list[12] = 11; node_list[13] = 12;
   node_list[14] = 16; node_list[15] = 15;
 
   node_list[16] = 16; node_list[17] = 15;
   node_list[18] = 11; node_list[19] = 12;

   node_list[20] = 10; node_list[21] = 11;
   node_list[22] = 15; node_list[23] = 14;

   node_list[24] = 13; node_list[25] = 16;
   node_list[26] = 12; node_list[27] =  9;

   node_list[28] = 14; node_list[29] = 13;
   node_list[30] =  9; node_list[31] = 10;

   node_list[32] = 16; node_list[33] = 13;
   node_list[34] = 14; node_list[35] = 15;

   node_list[36] = 17; node_list[37] = 18;
   node_list[38] = 20;

   node_list[39] = 18; node_list[40] = 19;
   node_list[41] = 20;

   node_list[42] = 20; node_list[43] = 19;
   node_list[44] = 17;

   node_list[45] = 19; node_list[46] = 18;
   node_list[47] = 17;

   node_list[48] = 25; node_list[49] = 24;
   node_list[50] = 21; node_list[51] = 22;

   node_list[52] = 26; node_list[53] = 25;
   node_list[54] = 22; node_list[55] = 23;

   node_list[56] = 26; node_list[57] = 23;
   node_list[58] = 21; node_list[59] = 24;

   node_list[60] = 23; node_list[61] = 22;
   node_list[62] = 21;

   node_list[63] = 24; node_list[64] = 25;
   node_list[65] = 26;

   node_ind[0] = 0;
   node_ind[1] = 4;
   node_ind[2] = 8;
   node_ind[3] = 36;
   node_ind[4] = 47;

   num_elem_per_set[0] = 2;
   num_elem_per_set[1] = 2;
   num_elem_per_set[2] = 7;
   num_elem_per_set[3] = 4;
   num_elem_per_set[4] = 5;

   num_nodes_per_set[0] = 4;
   num_nodes_per_set[1] = 4;
   num_nodes_per_set[2] = 28;
   num_nodes_per_set[3] = 12;
   num_nodes_per_set[4] = 18;

   elem_ind[0] = 0;
   elem_ind[1] = 2;
   elem_ind[2] = 4;
   elem_ind[3] = 11;
   elem_ind[4] = 15;

   elem_list[0] = 2; elem_list[1] = 2;
   elem_list[2] = 1; elem_list[3] = 2;
   elem_list[4] = 3; elem_list[5] = 3;
   elem_list[6] = 3; elem_list[7] = 3;
   elem_list[8] = 3; elem_list[9] = 3;
   elem_list[10] = 3; elem_list[11] = 4;
   elem_list[12] = 4; elem_list[13] = 4;
   elem_list[14] = 4; elem_list[15] = 5;
   elem_list[16] = 5; elem_list[17] = 5;
   elem_list[18] = 5; elem_list[19] = 5;

   error = ex_cvt_nodes_to_sides(exoid,
                         num_elem_per_set,
                         num_nodes_per_set,
                         elem_ind,
                         node_ind,
                         elem_list,
                         node_list,
                         side_list);
   printf ("after ex_cvt_nodes_to_sides, error = %d\n", error);

   num_df_per_set[0] = 4;
   num_df_per_set[1] = 4;
   num_df_per_set[2] = 0;
   num_df_per_set[3] = 0;
   num_df_per_set[4] = 0;

   df_ind[0] = 0;
   df_ind[1] = 4;

   dist_fact[0] = 30.0; dist_fact[1] = 30.1;
   dist_fact[2] = 30.2; dist_fact[3] = 30.3;

   dist_fact[4] = 31.0; dist_fact[5] = 31.1;
   dist_fact[6] = 31.2; dist_fact[7] = 31.3;

   error = ex_put_concat_side_sets (exoid, ids, num_elem_per_set,
                                    num_df_per_set, elem_ind, df_ind,
                                    elem_list, side_list, dist_fact);
   printf ("after ex_put_concat_side_sets, error = %d\n", error);

   /* END COMMENTED OUT SECTION */

   error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
   printf ("after ex_put_prop, error = %d\n", error);

   error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
   printf ("after ex_put_prop, error = %d\n", error);


/* write QA records */

   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "FASTQ";
   qa_record[1][1] = "fastq";
   qa_record[1][2] = "07/07/93";
   qa_record[1][3] = "16:41:33";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);


/* write information records */

   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "This is the second information record.";
   info[2] = "This is the third information record.";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);



/* write results variables parameters and names */

   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   error = ex_put_var_param (exoid, "g", num_glo_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);


   num_nod_vars = 2;

   var_names[0] = "nod_var0";
   var_names[1] = "nod_var1";

   error = ex_put_var_param (exoid, "n", num_nod_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   error = ex_put_var_names (exoid, "n", num_nod_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);

   num_ele_vars = 3;

   var_names[0] = "ele_var0";
   var_names[1] = "ele_var1";
   var_names[2] = "ele_var2";

   error = ex_put_var_param (exoid, "e", num_ele_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   error = ex_put_var_names (exoid, "e", num_ele_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);


/* write element variable truth table */

   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));

   k = 0;
   for (i=0; i<num_elem_blk; i++)
   {
      for (j=0; j<num_ele_vars; j++)
      {
         truth_tab[k++] = 1;
      }
   }

   error = ex_put_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
   printf ("after ex_put_elem_var_tab, error = %d\n", error);

   free (truth_tab);


/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 * obviously the analysis code will populate these arrays
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (4, CPU_word_size);

   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

/* write time value */

     error = ex_put_time (exoid, whole_time_step, &time_value);
     printf ("after ex_put_time, error = %d\n", error);

/* write global variables */

     for (j=0; j<num_glo_vars; j++)
     {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
                               glob_var_vals);
     printf ("after ex_put_glob_vars, error = %d\n", error);

/* write nodal variables */

     for (k=1; k<=num_nod_vars; k++)
     {
       for (j=0; j<num_nodes; j++)
       {
         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
       }

       error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
                                 nodal_var_vals);
       printf ("after ex_put_nodal_var, error = %d\n", error);
     }

/* write element variables */

     for (k=1; k<=num_ele_vars; k++)
     {
       for (j=0; j<num_elem_blk; j++)
       {
         for (m=0; m<num_elem_in_block[j]; m++)
         {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
         }
         error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
                                  num_elem_in_block[j], elem_var_vals);
         printf ("after ex_put_elem_var, error = %d\n", error);
       }
     }

     whole_time_step++;

/* update the data file; this should be done at the end of every time step
 * to ensure that no data is lost if the analysis dies
 */
     error = ex_update (exoid);
     printf ("after ex_update, error = %d\n", error);
   }
   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);


/* close the EXODUS files
 */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   return 0;
}
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_total_nodes_per_blk[10];
   int num_face_in_block[10], num_total_faces_per_blk[10];
   int num_node_sets, error;
   int i, j, *connect;
   int bids, nnpe[20];
   int  num_qa_rec, num_info;
   int CPU_word_size,IO_word_size;

   float x[100], y[100], z[100];
   char *coord_names[3], *qa_record[2][4], *info[3];
   char *block_names[10];
   char *title = "This is a test";
   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("test-nfaced.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   /* initialize file with parameters */
   {
     ex_init_params par;
     
     num_dim = 3;
     num_nodes = 14;
     num_elem = 3;
     num_elem_blk = 1;
     num_node_sets = 0;

     strcpy( par.title, title );
     par.num_dim = num_dim;
     par.num_nodes = num_nodes;
     par.num_edge = 0;
     par.num_edge_blk = 0;
     par.num_face = 15;
     par.num_face_blk = 1;
     par.num_elem = num_elem;
     par.num_elem_blk = num_elem_blk;
     par.num_node_sets = num_node_sets;
     par.num_edge_sets = 0;
     par.num_face_sets = 0;
     par.num_side_sets = 0;
     par.num_elem_sets = 0;
     par.num_node_maps = 0;
     par.num_edge_maps = 0;
     par.num_face_maps = 0;
     par.num_elem_maps = 0;
     
     error = ex_put_init_ext (exoid, &par);
     
     printf ("after ex_put_init_ext, error = %d\n", error);
     
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }

/* write nodal coordinates values and names to database */
   x[ 0] =  0.00000e+00 ;    y[ 0] = 0.00000e+00 ;   z[ 0] =  0.00000e+00 ;
   x[ 1] =  2.00000e+00 ;    y[ 1] = 0.00000e+00 ;   z[ 1] =  0.00000e+00 ;
   x[ 2] =  0.00000e+00 ;    y[ 2] = 2.00000e+00 ;   z[ 2] =  0.00000e+00 ;
   x[ 3] =  2.00000e+00 ;    y[ 3] = 2.00000e+00 ;   z[ 3] =  0.00000e+00 ;
   x[ 4] =  0.00000e+00 ;    y[ 4] = 0.00000e+00 ;   z[ 4] =  2.00000e+00 ;
   x[ 5] =  2.00000e+00 ;    y[ 5] = 0.00000e+00 ;   z[ 5] =  2.00000e+00 ;
   x[ 6] =  0.00000e+00 ;    y[ 6] = 2.00000e+00 ;   z[ 6] =  2.00000e+00 ;
   x[ 7] =  2.00000e+00 ;    y[ 7] = 2.00000e+00 ;   z[ 7] =  2.00000e+00 ;
   x[ 8] =  0.00000e+00 ;    y[ 8] = 3.50000e+00 ;   z[ 8] =  1.00000e+00 ;
   x[ 9] =  2.00000e+00 ;    y[ 9] = 3.50000e+00 ;   z[ 9] =  1.00000e+00 ;
   x[10] =  0.00000e+00 ;    y[10] = 3.00000e+00 ;   z[10] =  1.50000e+00 ;
   x[11] =  2.00000e+00 ;    y[11] = 3.00000e+00 ;   z[11] =  1.50000e+00 ;
   x[12] =  0.00000e+00 ;    y[12] = 3.00000e+00 ;   z[12] =  0.50000e+00 ;
   x[13] =  2.00000e+00 ;    y[13] = 3.00000e+00 ;   z[13] =  0.50000e+00 ;

   error = ex_put_coord (exoid, x, y, z);
   printf ("after ex_put_coord, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   coord_names[0] = "x";
   coord_names[1] = "y";
   coord_names[2] = "z";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* Write the face block parameters */
   block_names[0] = "face_block_1";
   num_face_in_block[0] = 15;
   num_total_nodes_per_blk[0] = 58;
   bids = 10;

   error = ex_put_block (exoid, EX_FACE_BLOCK, bids, "nsided",
			 num_face_in_block[0],
			 num_total_nodes_per_blk[0],
			 0, 0, 0);
   printf ("after ex_put_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Write face block names */
   error = ex_put_names(exoid, EX_FACE_BLOCK, block_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   
    
   /* write face connectivity */

   connect = (int *) calloc(num_total_nodes_per_blk[0], sizeof(int));

   i = 0;
   j = 0;

   connect[i++] = 5;
   connect[i++] = 6;
   connect[i++] = 8; /* connectivity of face 1 of element 1 */
   nnpe[j++] = 3;

   connect[i++] = 2;
   connect[i++] = 1;
   connect[i++] = 4; /* face 2 of element 1 */
   nnpe[j++] = 3;

   connect[i++] = 6;
   connect[i++] = 2;
   connect[i++] = 4;
   connect[i++] = 8; /* face 3 of element 1 */
   nnpe[j++] = 4;

   connect[i++] = 8;
   connect[i++] = 4;
   connect[i++] = 1;
   connect[i++] = 5; /* face 4 of element 1 */
   nnpe[j++] = 4;

   connect[i++] = 1;
   connect[i++] = 2;
   connect[i++] = 6;
   connect[i++] = 5; /*  face 5 of element 1 */
   nnpe[j++] = 4;

   connect[i++] = 5;
   connect[i++] = 8;
   connect[i++] = 7; /* connectivity of face 1 of element 2 */
   nnpe[j++] = 3;

   connect[i++] = 1;
   connect[i++] = 3;
   connect[i++] = 4; /*  face 2 of element 2 */
   nnpe[j++] = 3;

   connect[i++] = 7;
   connect[i++] = 8;
   connect[i++] = 4;
   connect[i++] = 3; /*  face 3 of element 2 */
   nnpe[j++] = 4;

   connect[i++] = 7;
   connect[i++] = 3;
   connect[i++] = 1;
   connect[i++] = 5; /*  face 4 of element 2 */
   nnpe[j++] = 4;

   connect[i++] = 8;
   connect[i++] = 4;
   connect[i++] = 14;
   connect[i++] = 10;
   connect[i++] = 12; /* connectivity of face 1 of element 3 */
   nnpe[j++] = 5;

   connect[i++] = 7;
   connect[i++] = 11;
   connect[i++] = 9;
   connect[i++] = 13;
   connect[i++] = 3; /*  face 2 of element 3 */
   nnpe[j++] = 5;

   connect[i++] = 7;
   connect[i++] = 8;
   connect[i++] = 12;
   connect[i++] = 11; /* face 3 of element 3 */
   nnpe[j++] = 4;

   connect[i++] = 11;
   connect[i++] = 12;
   connect[i++] = 10;
   connect[i++] = 9;  /* face 4 of element 3 */
   nnpe[j++] = 4;

   connect[i++] = 9;
   connect[i++] = 10;
   connect[i++] = 14;
   connect[i++] = 13; /*  face 5 of element 3 */
   nnpe[j++] = 4;

   connect[i++] = 13;
   connect[i++] = 14;
   connect[i++] = 4;
   connect[i++] = 3; /* face 6 of element 3 */
   nnpe[j++] = 4;
   
   assert(i == num_total_nodes_per_blk[0]);
   assert(j == num_face_in_block[0]);

   error = ex_put_conn (exoid, EX_FACE_BLOCK, bids, connect, NULL, NULL);
   printf ("after ex_put_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (connect);
   connect = NULL;

   error = ex_put_entity_count_per_polyhedra(exoid, EX_FACE_BLOCK, bids, nnpe);
   printf ("after ex_put_entity_count_per_polyhedra, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* write element block parameters */
   block_names[0] = "nfaced_1";

   num_elem_in_block[0] = 3;
   num_total_faces_per_blk[0] = 5 + 5 + 7;

   bids = 10;

   error = ex_put_block (exoid, EX_ELEM_BLOCK, bids, "nfaced",
			 num_elem_in_block[0],
			 0, 
			 0,
			 num_total_faces_per_blk[0],
			 0);
   printf ("after ex_put_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Write element block names */
   error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   /* write element-face connectivity */
   connect = (int *) calloc(num_total_faces_per_blk[0], sizeof(int));

   i = 0;
   j = 0;
   connect[i++] = 1;
   connect[i++] = 2;
   connect[i++] = 3;
   connect[i++] = 4;
   connect[i++] = 5;
   nnpe[j++] = 5;  /* Number of faces per element 1 */
   
   connect[i++] = 4;
   connect[i++] = 6;
   connect[i++] = 7;
   connect[i++] = 8;
   connect[i++] = 9;
   nnpe[j++] = 5;  /* Number of faces per element 2 */
   

   connect[i++] = 8;
   connect[i++] = 10;
   connect[i++] = 11;
   connect[i++] = 12;
   connect[i++] = 13;
   connect[i++] = 14;
   connect[i++] = 15;
   nnpe[j++] = 7;  /* Number of faces per element 3 */

   assert(i == num_total_faces_per_blk[0]);
   assert(j == num_elem_in_block[0]);

   error = ex_put_conn (exoid, EX_ELEM_BLOCK, bids, NULL, NULL, connect);
   printf ("after ex_put_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (connect);

   error = ex_put_entity_count_per_polyhedra(exoid, EX_ELEM_BLOCK, bids, nnpe);
   printf ("after ex_put_entity_count_per_polyhedra, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* write QA records; test empty and just blank-filled records */
   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT-NFACED";
   qa_record[0][1] = "testwt-nfaced";
   qa_record[0][2] = "2010/02/15";
   qa_record[0][3] = "06:35:15";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* write information records; test empty and just blank-filled records */
   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* close the EXODUS files
    */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   return 0;
}