Ejemplo n.º 1
0
int ex_get_var_param (int   exoid,
                      const char *var_type,
                      int  *num_vars)
{
  ex_entity_type obj_type;
  obj_type = ex_var_type_to_ex_entity_type(*var_type);
  return (ex_get_variable_param(exoid, obj_type, num_vars));
}
Ejemplo n.º 2
0
static void fetch_variable_names(int ex_id, ex_entity_type obj_type, string_array_t* var_names)
{
  int num_vars;
  ex_get_variable_param(ex_id, obj_type, &num_vars);
  for (int i = 0; i < num_vars; ++i)
    string_array_append_with_dtor(var_names, (char*)polymec_malloc(sizeof(char) * (MAX_NAME_LENGTH+1)), string_free);
  if (num_vars > 0)
    ex_get_variable_names(ex_id, obj_type, num_vars, var_names->data);
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
int NemSpread<T,INT>::read_var_param (int exoid, int max_name_length)
{
    const char  *yo="read_var_param";

    /* Get the number of time indices contained in the file */
    int ret_int = ex_inquire_int(exoid, EX_INQ_TIME);

    /* see if the user want to get all of the time indices */
    if (Restart_Info.Num_Times == -1) {

        Restart_Info.Num_Times = ret_int;

        if (ret_int > 0) {
            /* allocate array space */
            Restart_Info.Time_Idx.resize(Restart_Info.Num_Times);

            for (int cnt = 0; cnt < Restart_Info.Num_Times; cnt++)
                Restart_Info.Time_Idx[cnt] = cnt + 1;
        }
    }
    else {
        /* Check to see if the requested indeces are valid */
        for (int cnt = 0; cnt < Restart_Info.Num_Times; cnt++) {

            /* if the user wants the last time, then set it */
            if (Restart_Info.Time_Idx[cnt] == 0)
                Restart_Info.Time_Idx[cnt] = ret_int;

            if (Restart_Info.Time_Idx[cnt] > ret_int) {
                fprintf(stderr, "%s: Requested time index, %d, out of range.\n",
                        yo, Restart_Info.Time_Idx[cnt]);
                fprintf(stderr, "%s: Valid time indices in %s are from 1 to %d.\n",
                        yo, Exo_Res_File, ret_int);
                return -1;
            }

        }
    }

    /* if there are not any time steps, then return here without an error */
    if (Restart_Info.Num_Times == 0) {
        Restart_Info.Flag = 0;
        Restart_Info.NVar_Glob = 0;
        Restart_Info.NVar_Node = 0;
        Restart_Info.NVar_Elem = 0;
        return 0;
    }


    /***************** Global Variables ********************/
    if (ex_get_variable_param(exoid, EX_GLOBAL, &(Restart_Info.NVar_Glob)) < 0) {
        fprintf(stderr, "%s: Could not get global variable parameter from file\n",
                yo);
        return -1;
    }

    /* allocate space for the global variable names */
    if (Restart_Info.NVar_Glob > 0) {
        Restart_Info.GV_Name = (char **) array_alloc(__FILE__, __LINE__, 2,
                               Restart_Info.NVar_Glob,
                               max_name_length+1,
                               sizeof(char));

        /* get the global variable names */
        if (ex_get_variable_names(exoid, EX_GLOBAL, Restart_Info.NVar_Glob,
                                  Restart_Info.GV_Name) < 0) {
            fprintf(stderr, "%s: Could not get global variable names from file\n",
                    yo);
            return -1;
        }
    }

    /***************** Elemental Variables ********************/
    if (ex_get_variable_param(exoid, EX_ELEM_BLOCK, &(Restart_Info.NVar_Elem)) < 0) {
        fprintf(stderr, "%s: Could not get elemental variable param from file\n",
                yo);
        return -1;
    }

    /* allocate space for the elemental variable names */
    if (Restart_Info.NVar_Elem > 0) {
        Restart_Info.EV_Name = (char **) array_alloc(__FILE__, __LINE__, 2,
                               Restart_Info.NVar_Elem,
                               max_name_length+1,
                               sizeof(char));

        /* get the elemental variable names */
        if (ex_get_variable_names(exoid, EX_ELEM_BLOCK, Restart_Info.NVar_Elem,
                                  Restart_Info.EV_Name) < 0) {
            fprintf(stderr, "%s: Could not get elemental variable names from file\n",
                    yo);
            return -1;
        }

        /* and get the truth table */
        Restart_Info.GElem_TT.resize(globals.Num_Elem_Blk * Restart_Info.NVar_Elem);

        check_exodus_error(ex_get_truth_table(exoid, EX_ELEM_BLOCK,
                                              globals.Num_Elem_Blk,
                                              Restart_Info.NVar_Elem,
                                              TOPTR(Restart_Info.GElem_TT)),
                           "ex_get_truth_table");
    }

    /******************* Nodal Variables **********************/
    if (ex_get_variable_param(exoid, EX_NODAL, &(Restart_Info.NVar_Node)) < 0) {
        fprintf(stderr, "%s: Could not get nodal variable param from file\n",
                yo);
        return -1;
    }

    /* allocate space for the nodal variable names */
    if (Restart_Info.NVar_Node > 0) {
        Restart_Info.NV_Name = (char **) array_alloc(__FILE__, __LINE__, 2,
                               Restart_Info.NVar_Node,
                               max_name_length+1,
                               sizeof(char));

        /* get the nodal variable names */
        if (ex_get_variable_names(exoid, EX_NODAL, Restart_Info.NVar_Node,
                                  Restart_Info.NV_Name) < 0) {
            fprintf(stderr, "%s: Could not get nodal variable names from file\n",
                    yo);
            return -1;
        }
    }

    /******************* Sideset Variables **********************/
    if (ex_get_variable_param(exoid, EX_SIDE_SET, &(Restart_Info.NVar_Sset)) < 0) {
        fprintf(stderr, "%s: Could not get sideset variable param from file\n",
                yo);
        return -1;
    }

    /* allocate space for the variable names */
    if (Restart_Info.NVar_Sset > 0) {
        Restart_Info.SSV_Name = (char **) array_alloc(__FILE__, __LINE__, 2,
                                Restart_Info.NVar_Sset,
                                max_name_length+1,
                                sizeof(char));

        /* get the variable names */
        if (ex_get_variable_names(exoid, EX_SIDE_SET, Restart_Info.NVar_Sset,
                                  Restart_Info.SSV_Name) < 0) {
            fprintf(stderr, "%s: Could not get sideset variable names from file\n",
                    yo);
            return -1;
        }

        /* and get the truth table */
        Restart_Info.GSset_TT.resize(globals.Num_Side_Set * Restart_Info.NVar_Sset);

        check_exodus_error(ex_get_truth_table(exoid, EX_SIDE_SET,
                                              globals.Num_Side_Set,
                                              Restart_Info.NVar_Sset,
                                              TOPTR(Restart_Info.GSset_TT)),
                           "ex_get_truth_table");
    }

    /******************* Nodeset Variables **********************/
    if (ex_get_variable_param(exoid, EX_NODE_SET, &(Restart_Info.NVar_Nset)) < 0) {
        fprintf(stderr, "%s: Could not get nodeset variable param from file\n",
                yo);
        return -1;
    }

    /* allocate space for the variable names */
    if (Restart_Info.NVar_Nset > 0) {
        Restart_Info.NSV_Name = (char **) array_alloc(__FILE__, __LINE__, 2,
                                Restart_Info.NVar_Nset,
                                max_name_length+1,
                                sizeof(char));

        /* get the variable names */
        if (ex_get_variable_names(exoid, EX_NODE_SET, Restart_Info.NVar_Nset,
                                  Restart_Info.NSV_Name) < 0) {
            fprintf(stderr, "%s: Could not get nodeset variable names from file\n",
                    yo);
            return -1;
        }

        /* and get the truth table */
        Restart_Info.GNset_TT.resize(globals.Num_Node_Set * Restart_Info.NVar_Nset);

        check_exodus_error(ex_get_truth_table(exoid, EX_NODE_SET,
                                              globals.Num_Node_Set,
                                              Restart_Info.NVar_Nset,
                                              TOPTR(Restart_Info.GNset_TT)),
                           "ex_get_var_tab");
    }


#ifdef DEBUG
    if (Debug_Flag >= 2) {
        printf("\n\nRestart Parameters:\n");
        printf("\tNumber of time indices: %d\n", Restart_Info.Num_Times);
        for (int cnt = 0; cnt < Restart_Info.Num_Times; cnt++)
            printf("\t\tTime index: %d\n", Restart_Info.Time_Idx[cnt]);
        printf("\tNumber of global variables: %d\n", Restart_Info.NVar_Glob);
        for (int cnt = 0; cnt < Restart_Info.NVar_Glob; cnt++)
            printf("\t\tGlobal variable %d: %s\n", (cnt+1),
                   Restart_Info.GV_Name[cnt]);
        printf("\tNumber of elental variables: %d\n", Restart_Info.NVar_Elem);
        for (int cnt = 0; cnt < Restart_Info.NVar_Elem; cnt++)
            printf("\t\tElemental variable %d: %s\n", (cnt+1),
                   Restart_Info.EV_Name[cnt]);
        printf("\tNumber of nodal variables: %d\n", Restart_Info.NVar_Node);
        for (int cnt = 0; cnt < Restart_Info.NVar_Node; cnt++)
            printf("\t\tNodal variable %d: %s\n", (cnt+1), Restart_Info.NV_Name[cnt]);
    }
#endif

    return 0;

}
Ejemplo n.º 5
0
template <typename INT> void ExoII_Read<INT>::Get_Init_Data()
{
  SMART_ASSERT(Check_State());
  SMART_ASSERT(file_id >= 0);

  // Determine max size of entity and variable names on the database
  int name_length = ex_inquire_int(file_id, EX_INQ_DB_MAX_USED_NAME_LENGTH);
  ex_set_max_name_length(file_id, name_length);

  ex_init_params info;
  info.title[0] = '\0';

  int err = ex_get_init_ext(file_id, &info);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get init data!"
              << " Error number = " << err << ".  Aborting..." << '\n';
    exit(1);
  }

  dimension       = info.num_dim;
  num_nodes       = info.num_nodes;
  num_elmts       = info.num_elem;
  num_elmt_blocks = info.num_elem_blk;
  num_node_sets   = info.num_node_sets;
  num_side_sets   = info.num_side_sets;
  title           = info.title;

  if (err > 0 && !interface.quiet_flag)
    std::cout << "EXODIFF WARNING: was issued, number = " << err << '\n';
  if (dimension < 1 || dimension > 3 || num_elmt_blocks < 0 || num_node_sets < 0 ||
      num_side_sets < 0) {
    std::cout << "EXODIFF ERROR: Init data appears corrupt:" << '\n'
              << "         dimension = " << dimension << '\n'
              << "         num_nodes = " << num_nodes << '\n'
              << "         num_elmts = " << num_elmts << '\n'
              << "         num_elmt_blocks = " << num_elmt_blocks << '\n'
              << "         num_node_sets = " << num_node_sets << '\n'
              << "         num_side_sets = " << num_side_sets << '\n'
              << " ... Aborting..." << '\n';
    exit(1);
  }

  int num_qa   = ex_inquire_int(file_id, EX_INQ_QA);
  int num_info = ex_inquire_int(file_id, EX_INQ_INFO);

  if (num_qa < 0 || num_info < 0) {
    std::cout << "EXODIFF ERROR: inquire data appears corrupt:" << '\n'
              << "         num_qa = " << num_qa << '\n'
              << "         num_info = " << num_info << '\n'
              << " ... Aborting..." << '\n';
    exit(1);
  }

  //                   Coordinate Names...

  char **coords = get_name_array(3, name_length);
  err           = ex_get_coord_names(file_id, coords);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get coordinate"
              << " names!  Aborting..." << '\n';
    exit(1);
  }

  coord_names.clear();
  for (size_t i = 0; i < dimension; ++i) {
    coord_names.push_back(coords[i]);
  }
  free_name_array(coords, 3);

  //                 Element Block Data...

  if (eblocks)
    delete[] eblocks;
  eblocks = nullptr;
  if (num_elmt_blocks > 0) {
    eblocks = new Exo_Block<INT>[num_elmt_blocks];
    SMART_ASSERT(eblocks != nullptr);
    std::vector<INT> ids(num_elmt_blocks);

    err = ex_get_ids(file_id, EX_ELEM_BLOCK, TOPTR(ids));

    if (err < 0) {
      std::cout << "EXODIFF ERROR: Failed to get element"
                << " block ids!  Aborting..." << '\n';
      exit(1);
    }

    size_t e_count = 0;
    for (size_t b = 0; b < num_elmt_blocks; ++b) {
      if (ids[b] <= EX_INVALID_ID) {
        std::cout << "EXODIFF  WARNING:  Element block Id "
                  << "for block index " << b << " is " << ids[b]
                  << " which is negative. This was returned by call to ex_get_elem_blk_ids()."
                  << '\n';
      }

      eblocks[b].initialize(file_id, ids[b]);
      e_count += eblocks[b].Size();
    }

    if (e_count != num_elmts && !interface.quiet_flag) {
      std::cout << "EXODIFF WARNING: Total number of elements " << num_elmts
                << " does not equal the sum of the number of elements "
                << "in each block " << e_count << '\n';
    }

    // Gather the attribute names (even though not all attributes are on all blocks)
    std::set<std::string> names;
    for (size_t b = 0; b < num_elmt_blocks; ++b) {
      for (int a = 0; a < eblocks[b].attr_count(); a++) {
        names.insert(eblocks[b].Get_Attribute_Name(a));
      }
    }
    elmt_atts.resize(names.size());
    std::copy(names.begin(), names.end(), elmt_atts.begin());
  }

  //                     Node & Side sets...

  if (nsets)
    delete[] nsets;
  nsets = nullptr;
  if (num_node_sets > 0) {
    nsets = new Node_Set<INT>[num_node_sets];
    SMART_ASSERT(nsets != nullptr);
    std::vector<INT> ids(num_node_sets);

    err = ex_get_ids(file_id, EX_NODE_SET, TOPTR(ids));

    if (err < 0) {
      std::cout << "EXODIFF ERROR: Failed to get "
                << "nodeset ids!  Aborting..." << '\n';
      exit(1);
    }

    for (size_t nset = 0; nset < num_node_sets; ++nset) {
      if (ids[nset] <= EX_INVALID_ID) {
        std::cout << "EXODIFF  WARNING: Nodeset Id "
                  << "for nodeset index " << nset << " is " << ids[nset]
                  << " which is negative.  This was returned by call to ex_get_ids()." << '\n';
      }

      nsets[nset].initialize(file_id, ids[nset]);
    }
  }

  if (ssets)
    delete[] ssets;
  ssets = nullptr;
  if (num_side_sets) {
    ssets = new Side_Set<INT>[num_side_sets];
    SMART_ASSERT(ssets != nullptr);
    std::vector<INT> ids(num_side_sets);

    err = ex_get_ids(file_id, EX_SIDE_SET, TOPTR(ids));

    if (err < 0) {
      std::cout << "EXODIFF ERROR: Failed to get "
                << "sideset ids!  Aborting..." << '\n';
      exit(1);
    }

    for (size_t sset = 0; sset < num_side_sets; ++sset) {
      if (ids[sset] <= EX_INVALID_ID) {
        std::cout << "EXODIFF  WARNING:  Sideset Id "
                  << "for sideset index " << sset << " is " << ids[sset]
                  << " which is negative. This was returned by call to ex_get_ids()." << '\n';
      }
      ssets[sset].initialize(file_id, ids[sset]);
    }
  }

  //  **************  RESULTS info  ***************  //

  int num_global_vars, num_nodal_vars, num_elmt_vars, num_ns_vars, num_ss_vars;

  err = ex_get_variable_param(file_id, EX_GLOBAL, &num_global_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " global variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_NODAL, &num_nodal_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " nodal variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_ELEM_BLOCK, &num_elmt_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " element variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_NODE_SET, &num_ns_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " nodeset variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_SIDE_SET, &num_ss_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " sideset variables!  Aborting..." << '\n';
    exit(1);
  }

  if (num_global_vars < 0 || num_nodal_vars < 0 || num_elmt_vars < 0 || num_ns_vars < 0 ||
      num_ss_vars < 0) {
    std::cout << "EXODIFF ERROR: Data appears corrupt for"
              << " number of variables !" << '\n'
              << "\tnum global vars  = " << num_global_vars << '\n'
              << "\tnum nodal vars   = " << num_nodal_vars << '\n'
              << "\tnum element vars = " << num_elmt_vars << '\n'
              << " ... Aborting..." << '\n';
    exit(1);
  }

  read_vars(file_id, EX_GLOBAL, "Global", num_global_vars, global_vars);
  read_vars(file_id, EX_NODAL, "Nodal", num_nodal_vars, nodal_vars);
  read_vars(file_id, EX_ELEM_BLOCK, "Element", num_elmt_vars, elmt_vars);
  read_vars(file_id, EX_NODE_SET, "Nodeset", num_ns_vars, ns_vars);
  read_vars(file_id, EX_SIDE_SET, "Sideset", num_ss_vars, ss_vars);

  // Times:
  num_times = ex_inquire_int(file_id, EX_INQ_TIME);
  if (num_times < 0) {
    std::cout << "EXODIFF ERROR: Number of time steps came"
              << " back negative (" << num_times << ")!  Aborting..." << '\n';
    exit(1);
  }

  if ((num_global_vars > 0 || num_nodal_vars > 0 || num_elmt_vars > 0 || num_ns_vars > 0 ||
       num_ss_vars > 0) &&
      num_times == 0) {
    std::cout << "EXODIFF Consistency error -- The database contains transient variables, but no "
                 "timesteps!"
              << '\n';
    exit(1);
  }

  if (num_times) {
    times = new double[num_times];
    SMART_ASSERT(times != nullptr);
    err = ex_get_all_times(file_id, times);
  }

  if (num_nodal_vars) {
    if (num_times == 0) {
      std::cout << "EXODIFF Consistency error--The database contains " << num_nodal_vars
                << " nodal variables, but there are no time steps defined." << '\n';
    }
    if (num_times) {
      results = new double *[num_nodal_vars];
      for (int i   = 0; i < num_nodal_vars; ++i)
        results[i] = nullptr;
    }
  }

} // End of EXODIFF
Ejemplo n.º 6
0
int cReadEdgeFace(int argc, char *argv[])
{
  int            exoid;
  int            appWordSize  = 8;
  int            diskWordSize = 8;
  float          exoVersion;
  int            itmp[5];
  int *          ids;
  int            nids;
  int            obj;
  int            i, j;
  int            num_timesteps;
  int            ti;
  char **        obj_names;
  char **        var_names;
  int            have_var_names;
  int            num_vars;    /* number of variables per object */
  int            num_entries; /* number of values per variable per object */
  double *       entry_vals;  /* variable values for each entry of an object */
  ex_init_params modelParams;

  exoid = ex_open(EX_TEST_FILENAME, EX_READ, &appWordSize, &diskWordSize, &exoVersion);
  if (exoid <= 0) {
    fprintf(stderr, "Unable to open \"%s\" for reading.\n", EX_TEST_FILENAME);
    return 1;
  }

  EXCHECK(ex_get_init_ext(exoid, &modelParams), "Unable to read database parameters.\n");

  fprintf(stdout, "Title: <%s>\n"
                  "Dimension: %" PRId64 "\n"
                  "Nodes: %" PRId64 "\n"
                  "Edges: %" PRId64 "\n"
                  "Faces: %" PRId64 "\n"
                  "Elements: %" PRId64 "\n"
                  "Edge Blocks: %" PRId64 "\n"
                  "Face Blocks: %" PRId64 "\n"
                  "Element Blocks: %" PRId64 "\n"
                  "Node Sets: %" PRId64 "\n"
                  "Edge Sets: %" PRId64 "\n"
                  "Face Sets: %" PRId64 "\n"
                  "Side Sets: %" PRId64 "\n"
                  "Element Sets: %" PRId64 "\n"
                  "Node Maps: %" PRId64 "\n"
                  "Edge Maps: %" PRId64 "\n"
                  "Face Maps: %" PRId64 "\n"
                  "Element Maps: %" PRId64 "\n",
          modelParams.title, modelParams.num_dim, modelParams.num_nodes, modelParams.num_edge,
          modelParams.num_face, modelParams.num_elem, modelParams.num_edge_blk,
          modelParams.num_face_blk, modelParams.num_elem_blk, modelParams.num_node_sets,
          modelParams.num_edge_sets, modelParams.num_face_sets, modelParams.num_side_sets,
          modelParams.num_elem_sets, modelParams.num_node_maps, modelParams.num_edge_maps,
          modelParams.num_face_maps, modelParams.num_elem_maps);

  num_timesteps = ex_inquire_int(exoid, EX_INQ_TIME);

  /* *** NEW API *** */
  for (i = 0; i < sizeof(obj_types) / sizeof(obj_types[0]); ++i) {
    int *truth_tab = 0;
    have_var_names = 0;

    EXCHECK(ex_inquire(exoid, obj_sizes[i], &nids, 0, 0),
            "Object ID list size could not be determined.\n");

    if (!nids) {
      fprintf(stdout, "=== %ss: none\n\n", obj_typenames[i]);
      continue;
    }
    else {
      fprintf(stdout, "=== %ss: %d\n", obj_typenames[i], nids);
    }

    ids       = (int *)malloc(nids * sizeof(int));
    obj_names = (char **)malloc(nids * sizeof(char *));
    for (obj         = 0; obj < nids; ++obj)
      obj_names[obj] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char));

    EXCHECK(ex_get_ids(exoid, obj_types[i], ids), "Could not read object ids.\n");
    EXCHECK(ex_get_names(exoid, obj_types[i], obj_names), "Could not read object ids.\n");

    if ((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) {
      int *tp;
      EXCHECK(ex_get_variable_param(exoid, obj_types[i], &num_vars),
              "Could not read number of variables.\n");

      if (num_vars && num_timesteps > 0) {
        truth_tab = (int *)malloc(num_vars * nids * sizeof(int));
        EXCHECK(ex_get_truth_table(exoid, obj_types[i], nids, num_vars, truth_tab),
                "Could not read truth table.\n");
        tp = truth_tab;
        fprintf(stdout, "Truth:");
        for (obj = 0; obj < nids; ++obj) {
          for (j = 0; j < num_vars; ++j, ++tp) {
            fprintf(stdout, " %d", *tp);
          }
          fprintf(stdout, "\n      ");
        }
        fprintf(stdout, "\n");

        var_names = (char **)malloc(num_vars * sizeof(char *));
        for (j         = 0; j < num_vars; ++j)
          var_names[j] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char));

        EXCHECK(ex_get_variable_names(exoid, obj_types[i], num_vars, var_names),
                "Could not read variable names.\n");
        have_var_names = 1;
      }
    }

    if (!have_var_names)
      var_names = 0;

    for (obj = 0; obj < nids; ++obj) {
      if (obj_names[obj])
        fprintf(stdout, "%s %3d (%s): ", obj_typenames[i], ids[obj], obj_names[obj]);
      else
        fprintf(stdout, "%s %3d: ", obj_typenames[i], ids[obj]);

      if (OBJECT_IS_BLOCK(i)) {
        int *nconn;
        int *econn;
        int *fconn;
        int  ele;
        int  ctr;
        int  num_attrs;
        if (obj_types[i] == EX_ELEM_BLOCK) {
          EXCHECK(ex_get_block(exoid, obj_types[i], ids[obj], 0, itmp, itmp + 1, itmp + 2, itmp + 3,
                               &num_attrs),
                  "Could not read block params.\n");
          fprintf(stdout,
                  "Entries: %3d Nodes/entry: %d Edges/entry: %d Faces/entry: %d Attributes: %d",
                  itmp[0], itmp[1], itmp[2], itmp[3], num_attrs);
        }
        else {
          EXCHECK(ex_get_block(exoid, obj_types[i], ids[obj], 0, itmp, itmp + 1, 0, 0, &num_attrs),
                  "Could not read block params.\n");
          fprintf(stdout, "Entries: %3d Nodes/entry: %d Attributes: %d", itmp[0], itmp[1],
                  num_attrs);
          itmp[2] = itmp[3] = 0;
        }
        fprintf(stdout, "\n   ");
        num_entries = itmp[0];
        nconn       = itmp[1] ? (int *)malloc(itmp[1] * num_entries * sizeof(int)) : 0;
        econn       = itmp[2] ? (int *)malloc(itmp[2] * num_entries * sizeof(int)) : 0;
        fconn       = itmp[3] ? (int *)malloc(itmp[3] * num_entries * sizeof(int)) : 0;
        EXCHECK(ex_get_conn(exoid, obj_types[i], ids[obj], nconn, econn, fconn),
                "Could not read connectivity.\n");
        for (ele = 0; ele < num_entries; ++ele) {
          for (ctr = 0; ctr < itmp[1]; ++ctr) {
            fprintf(stdout, " %2d", nconn[ele * itmp[1] + ctr]);
          }
          if (itmp[2]) {
            fprintf(stdout, "  ++");
            for (ctr = 0; ctr < itmp[2]; ++ctr) {
              fprintf(stdout, " %2d", econn[ele * itmp[2] + ctr]);
            }
          }
          if (itmp[3]) {
            fprintf(stdout, "  ++");
            for (ctr = 0; ctr < itmp[3]; ++ctr) {
              fprintf(stdout, " %2d", fconn[ele * itmp[3] + ctr]);
            }
          }
          fprintf(stdout, "\n   ");
        }
        free(nconn);
        free(econn);
        free(fconn);

        if (num_attrs) {
          char ** attr_names;
          double *attr;
          attr       = (double *)malloc(num_entries * num_attrs * sizeof(double));
          attr_names = (char **)malloc(num_attrs * sizeof(char *));
          for (j          = 0; j < num_attrs; ++j)
            attr_names[j] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char));

          EXCHECK(ex_get_attr_names(exoid, obj_types[i], ids[obj], attr_names),
                  "Could not read attributes names.\n");
          EXCHECK(ex_get_attr(exoid, obj_types[i], ids[obj], attr),
                  "Could not read attribute values.\n");

          fprintf(stdout, "\n      Attributes:\n      ID ");
          for (j = 0; j < num_attrs; ++j)
            fprintf(stdout, " %s", attr_names[j]);
          fprintf(stdout, "\n");
          for (j = 0; j < num_entries; ++j) {
            int k;
            fprintf(stdout, "      %2d ", j + 1);
            for (k = 0; k < num_attrs; ++k) {
              fprintf(stdout, " %4.1f", attr[j * num_attrs + k]);
            }
            fprintf(stdout, "\n");
          }

          for (j = 0; j < num_attrs; ++j)
            free(attr_names[j]);
          free(attr_names);
          free(attr);
        }
      }
      else if (OBJECT_IS_SET(i)) {
        int     num_df;
        int *   set_entry;
        int *   set_extra;
        double *set_df;
        EXCHECK(ex_get_set_param(exoid, obj_types[i], ids[obj], &num_entries, &num_df),
                "Could not read set parameters.\n");

        set_entry = (int *)malloc(num_entries * sizeof(int));
        set_extra = (obj_types[i] != EX_NODE_SET && obj_types[i] != EX_ELEM_SET)
                        ? (int *)malloc(num_entries * sizeof(int))
                        : 0;
        EXCHECK(ex_get_set(exoid, obj_types[i], ids[obj], set_entry, set_extra),
                "Could not read set.\n");
        fprintf(stdout, "Entries: %3d Distribution factors: %3d\n", num_entries, num_df);
        if (set_extra) {
          for (j = 0; j < num_entries; ++j)
            fprintf(stdout, "      %2d %2d\n", set_entry[j], set_extra[j]);
        }
        else {
          for (j = 0; j < num_entries; ++j)
            fprintf(stdout, "      %2d\n", set_entry[j]);
        }
        free(set_entry);
        free(set_extra);

        set_df = num_df ? (double *)malloc(num_df * sizeof(double)) : 0;
        if (set_df) {
          EXCHECK(ex_get_set_dist_fact(exoid, obj_types[i], ids[obj], set_df),
                  "Could not read set distribution factors.\n");
          fprintf(stdout, "\n    Distribution factors:\n");
          for (j = 0; j < num_df; ++j)
            fprintf(stdout, "      %4.1f\n", set_df[j]);
          free(set_df);
        }
      }
      else { /* object is map */
        int *map;
        switch (obj_types[i]) {
        case EX_NODE_MAP: num_entries = modelParams.num_nodes; break;
        case EX_EDGE_MAP: num_entries = modelParams.num_edge; break;
        case EX_FACE_MAP: num_entries = modelParams.num_face; break;
        case EX_ELEM_MAP: num_entries = modelParams.num_elem; break;
        default: num_entries          = 0;
        }
        if (num_entries) {
          fprintf(stdout, "Entries: %3d\n                :", num_entries);
          map = (int *)malloc(num_entries * sizeof(int));
          EXCHECK(ex_get_num_map(exoid, obj_types[i], ids[obj], map), "Could not read map.\n");
          for (j = 0; j < num_entries; ++j) {
            fprintf(stdout, " %d", map[j]);
          }
        }
        else {
          fprintf(stdout, "Entries: none");
        }
      }
      fprintf(stdout, "\n");

      /* Read results variables */
      if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) {
        /* Print out all the time values to exercise get_var */
        entry_vals = (double *)malloc(num_entries * sizeof(double));
        for (j = 0; j < num_vars; ++j) {
          int k;
          if (!truth_tab[num_vars * obj + j])
            continue;

          fprintf(stdout, "      Variable: %s", var_names[j]);
          for (ti = 1; ti <= num_timesteps; ++ti) {
            EXCHECK(ex_get_var(exoid, ti, obj_types[i], 1 + j, ids[obj], num_entries, entry_vals),
                    "Could not read variable values.\n");

            fprintf(stdout, "\n       @t%d ", ti);
            for (k = 0; k < num_entries; ++k) {
              fprintf(stdout, " %4.1f", entry_vals[k]);
            }
          }
          fprintf(stdout, "\n");
        }
        fprintf(stdout, "\n");
        free(entry_vals);
      }
    }

    if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) {
      /* Print out one element's time values to exercise get_var_time */
      entry_vals = (double *)malloc(num_timesteps * sizeof(double));
      EXCHECK(ex_inquire(exoid, obj_sizeinq[i], itmp, 0, 0), "Inquire failed.\n");
      itmp[1] = 11;
      while (itmp[1] > itmp[0])
        itmp[1] /= 2;
      for (j = 0; j < num_vars; ++j) {
        /* FIXME: This works for the dataset created by CreateEdgeFace, but not for any dataset in
         * general since
         * NULL truth table entries may mean the referenced elements don't have variable values.
         */
        EXCHECK(ex_get_var_time(exoid, obj_types[i], j + 1, itmp[1], 1, num_timesteps, entry_vals),
                "Could not read variable over time.\n");
        fprintf(stdout, "    Variable over time: %s  Entry: %3d ", var_names[j], itmp[1]);
        for (ti = 1; ti <= num_timesteps; ++ti)
          fprintf(stdout, " @t%d: %4.1f", ti, entry_vals[ti - 1]);
        fprintf(stdout, "\n");
      }
      free(entry_vals);
    }

    if (var_names) {
      for (j = 0; j < num_vars; ++j)
        free(var_names[j]);
      free(var_names);
    }
    free(truth_tab);
    free(ids);

    for (obj = 0; obj < nids; ++obj)
      free(obj_names[obj]);
    free(obj_names);

    fprintf(stdout, "\n");
  }

  EXCHECK(ex_close(exoid), "Unable to close database.\n");

  return 0;
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
    MPI_Comm mpi_comm = MPI_COMM_WORLD;
    MPI_Info mpi_info = MPI_INFO_NULL;

    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);

    /* Initialize MPI. */
    MPI_Init(&argc, &argv);

    /* open EXODUS II files */
    exoid = ex_open_par("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 */
                        mpi_comm, mpi_info);

    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_ids(exoid, EX_ELEM_BLOCK, ids);
        printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error);

        for (i = 0; i < num_elem_blk; i++) {
            printf("Block # %d is id %d\n", i, ids[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_block(exoid, EX_ELEM_BLOCK, ids[i], elem_type, &(num_elem_in_block[i]),
                                 &(num_nodes_per_elem[i]), &(num_attr[i]));
            printf("\nafter ex_get_elem_block, id = %d, error = %d\n", ids[i], 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_conn(exoid, EX_ELEM_BLOCK, 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_attr(exoid, EX_ELEM_BLOCK, ids[i], attrib);
            printf("\n after ex_get_elem_attr, error = %d\n", error);

            if (error == 0) {
                error = ex_get_attr_names(exoid, EX_ELEM_BLOCK, 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_ids(exoid, EX_NODE_SET, 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_set_param(exoid, EX_NODE_SET, 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_set(exoid, EX_NODE_SET, ids[i], node_list);
            printf("\nafter ex_get_node_set, error = %3d\n", error);

            if (num_df_in_set > 0) {
                error = ex_get_set_dist_fact(exoid, EX_NODE_SET, 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_nodes_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_ids(exoid, EX_SIDE_SET, 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_set_param(exoid, EX_SIDE_SET, 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_set(exoid, EX_SIDE_SET, 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_set_dist_fact(exoid, EX_SIDE_SET, 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_variable_param(exoid, EX_GLOBAL, &num_glo_vars);
    printf("\nafter ex_get_variable_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_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names);
    printf("\nafter ex_get_variable_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_variable_param(exoid, EX_NODE_SET, &num_nod_vars);
        printf("\nafter ex_get_variable_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_variable_names(exoid, EX_NODAL, num_nod_vars, var_names);
        printf("\nafter ex_get_variable_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_variable_param(exoid, EX_ELEM_BLOCK, &num_ele_vars);
        printf("\nafter ex_get_variable_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_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names);
        printf("\nafter ex_get_variable_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_truth_table(exoid, EX_ELEM_BLOCK, 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_variable_param(exoid, "m", &num_nset_vars);
        printf("\nafter ex_get_variable_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_variable_names(exoid, "m", num_nset_vars, var_names);
            printf("\nafter ex_get_variable_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_truth_table(exoid, EX_NODE_SET, 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_variable_param(exoid, EX_SIDE_SET, &num_sset_vars);
        printf("\nafter ex_get_variable_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_variable_names(exoid, EX_SIDE_SET, num_sset_vars, var_names);
            printf("\nafter ex_get_variable_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_truth_table(exoid, EX_SIDE_SET, 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_var(exoid, time_step, EX_NODAL, var_index, 1, 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_var_time(exoid, EX_NODAL, 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_ids(exoid, EX_ELEM_BLOCK, 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_var(exoid, time_step, EX_ELEM_BLOCK, 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_var_time(exoid, EX_ELEM_BLOCK, 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_ids(exoid, EX_SIDE_SET, 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_var(exoid, time_step, EX_SIDE_SET, 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_ids(exoid, EX_NODE_SET, 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_var(exoid, time_step, EX_NODE_SET, 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);
    MPI_Finalize();
    return 0;
}
Ejemplo n.º 8
0
int main (int argc, char *argv[])
{
  char *oname = nullptr, *dot = nullptr, *filename = nullptr;
  char str[32];

  const char* ext=EXT;

  int
    n, n1,n2,err,
    num_axes,num_blocks,
    num_side_sets,num_node_sets,num_time_steps,
    num_info_lines,num_global_vars,
    num_nodal_vars,num_element_vars,num_nodeset_vars, num_sideset_vars;

  size_t num_nodes = 0;
  size_t num_elements = 0;

  int mat_version = 73;

  /* process arguments */
  for (int 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],"-h")==0){    /* write help info */
      del_arg(&argc,argv,j);
      usage();
      exit(1);
    }
    if ( strcmp(argv[j],"-d")==0){    /* write help info */
      del_arg(&argc,argv,j);
      j--;
      debug = 1;
      continue;
    }
    if ( strcmp(argv[j],"-v73")==0){    /* Version 7.3 */
      del_arg(&argc,argv,j);
      mat_version = 73;
      j--;
      continue;
    }
    // This matches the option used in matlab
    if ( (strcmp(argv[j],"-v7.3")==0) || (strcmp(argv[j],"-V7.3")==0)){    /* Version 7.3 */
      del_arg(&argc,argv,j);
      mat_version = 73;
      j--;
      continue;
    }
    if ( strcmp(argv[j],"-v5")==0){    /* Version 5 (default) */
      del_arg(&argc,argv,j);
      mat_version = 50;
      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);
        std::cout << "output file: " << oname << "\n";
      }
      else {
        std::cerr << "ERROR: 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){
    usage();
    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 ){
      std::cerr << "ERROR: Unable to open " << filename << "\n";
      exit(1);
    }
  }
  else {
    if (mat_version == 50) {
      mat_file = Mat_CreateVer(filename, nullptr, MAT_FT_MAT5);
    }
    else if (mat_version == 73) {
      mat_file = Mat_CreateVer(filename, nullptr, MAT_FT_MAT73);
    }

    if (mat_file == nullptr) {
      std::cerr << "ERROR: Unable to create matlab file " << filename << "\n";
      exit(1);
    }
  }

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

  /* open exodus file */
  float exo_version;
  int exo_file=ex_open(argv[1],EX_READ,&cpu_word_size,&io_word_size,&exo_version);
  if (exo_file < 0){
    std::cerr << "ERROR: Cannot open " << argv[1] << "\n";
    exit(1);
  }

  /* print */
  std::cout << "\ttranslating " << argv[1] << " to " << filename << "...\n";

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


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

  /* allocate -char- scratch space*/
  int nstr2 = num_info_lines;
  nstr2 = std::max(nstr2, num_blocks);
  nstr2 = std::max(nstr2, num_node_sets);
  nstr2 = std::max(nstr2, num_side_sets);
  char **str2 = get_exodus_names(nstr2, 512);

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

  /* information records */
  if (num_info_lines > 0 ){
    ex_get_info(exo_file,str2);
    std::string ostr;
    for (int i=0;i<num_info_lines;i++) {
      if (strlen(str2[i]) > 0) {
        ostr += str2[i];
        ostr += "\n";
      }
    }
    PutStr("info",ostr.c_str());
    ostr = "";
    for (int i=0;i<num_info_lines;i++) {
      if (strlen(str2[i]) > 0 && strncmp(str2[i],"cavi",4)==0) {
        ostr += str2[i];
        ostr += "\n";
      }
    }
    PutStr("cvxp",ostr.c_str());
  }

  /* nodal coordinates */
  {
    if (debug) {logger("Coordinates");}
    std::vector<double> x, y, z;
    x.resize(num_nodes);
    if (num_axes >= 2) y.resize(num_nodes);
    if (num_axes == 3) z.resize(num_nodes);
    ex_get_coord(exo_file,TOPTR(x), TOPTR(y), TOPTR(z));
    PutDbl("x0", num_nodes, 1, TOPTR(x));
    if (num_axes >= 2) {
      PutDbl("y0", num_nodes, 1, TOPTR(y));
    }
    if (num_axes == 3){
      PutDbl("z0",num_nodes,1, TOPTR(z));
    }
  }

  /* side sets */
  std::vector<int> num_sideset_sides(num_side_sets);
  std::vector<int> ids;
  if (num_side_sets > 0) {
    if (debug) {logger("Side Sets");}
    ids.resize(num_side_sets);
    ex_get_ids(exo_file,EX_SIDE_SET,TOPTR(ids));
    PutInt( "ssids",num_side_sets, 1,TOPTR(ids));
    std::vector<int> nssdfac(num_side_sets);
    std::vector<int> iscr;
    std::vector<int> jscr;
    std::vector<double> scr;
    std::vector<int> elem_list;
    std::vector<int> side_list;
    std::vector<int> junk;
    for (int i=0;i<num_side_sets;i++) {
      ex_get_set_param(exo_file,EX_SIDE_SET, ids[i],&n1,&n2);
      num_sideset_sides[i]=n1;
      nssdfac[i]=n2;
      /*
       * the following provision is from Version 1.6 when there are no
       * distribution factors in exodus file
       */
      bool has_ss_dfac = (n2 != 0);
      if (n2==0 || n1==n2){

        std::cerr << "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.resize(n1);
        ex_get_side_set_node_count(exo_file,ids[i],TOPTR(junk));
        n2=0; /* n2 will be equal to the total number of nodes in the sideset */
        for (int j=0; j<n1; j++)
          n2+=junk[j];
      }

      iscr.resize(n1);
      jscr.resize(n2);
      ex_get_side_set_node_list(exo_file,ids[i],TOPTR(iscr),TOPTR(jscr));
      /* number-of-nodes-per-side list */
      sprintf(str,"ssnum%02d",i+1);
      PutInt(str,n1,1,TOPTR(iscr));
      /* nodes list */
      sprintf(str,"ssnod%02d",i+1);
      PutInt(str,n2,1,TOPTR(jscr));

      /* distribution-factors list */
      scr.resize(n2);
      if (has_ss_dfac) {
        ex_get_side_set_dist_fact(exo_file,ids[i], TOPTR(scr));
      } else {
        for (int j=0; j<n2; j++) {
          scr[j] = 1.0;
        }
      }
      sprintf(str,"ssfac%02d",i+1);
      PutDbl(str,n2,1,TOPTR(scr));

      /* element and side list for side sets (dgriffi) */
      elem_list.resize(n1);
      side_list.resize(n1);
      ex_get_set(exo_file,EX_SIDE_SET,ids[i],TOPTR(elem_list),TOPTR(side_list));
      sprintf(str,"ssside%02d",i+1);
      PutInt(str,n1,1,TOPTR(side_list));
      sprintf(str,"sselem%02d",i+1);
      PutInt(str,n1,1,TOPTR(elem_list));
    }
    /* Store # sides and # dis. factors per side set (dgriffi) */
    PutInt("nsssides",num_side_sets,1,TOPTR(num_sideset_sides));
    PutInt("nssdfac",num_side_sets,1,TOPTR(nssdfac));
  }

  /* node sets (section by dgriffi) */
  std::vector<int> num_nodeset_nodes(num_node_sets);
  if (num_node_sets > 0){
    if (debug) {logger("Node Sets");}
    std::vector<int> iscr;
    std::vector<double> scr;
    ids.resize(num_node_sets);
    ex_get_ids(exo_file,EX_NODE_SET, TOPTR(ids));
    PutInt( "nsids",num_node_sets, 1,TOPTR(ids));

    std::vector<int> num_nodeset_df(num_node_sets);
    for (int i=0;i<num_node_sets;i++){
      ex_get_set_param(exo_file,EX_NODE_SET,ids[i],&n1,&n2);
      iscr.resize(n1);
      ex_get_node_set(exo_file,ids[i],TOPTR(iscr));
      /* nodes list */
      sprintf(str,"nsnod%02d",i+1);
      PutInt(str,n1,1,TOPTR(iscr));
      {
        /* distribution-factors list */
        scr.resize(n2);
        ex_get_node_set_dist_fact(exo_file,ids[i],TOPTR(scr));
        sprintf(str,"nsfac%02d",i+1);
        PutDbl(str,n2,1,TOPTR(scr));
      }
      num_nodeset_nodes[i]=n1;
      num_nodeset_df[i]=n2;
    }

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

  /* element blocks */
  if (debug) {logger("Element Blocks");}
  std::vector<int> num_elem_in_block(num_blocks);
  {
    ids.resize(num_blocks);
    std::vector<int> iscr;
    ex_get_ids(exo_file,EX_ELEM_BLOCK,TOPTR(ids));
    PutInt( "blkids",num_blocks, 1,TOPTR(ids));
    for (int i=0;i<num_blocks;i++) {
      ex_get_elem_block(exo_file,ids[i],str2[i],&n,&n1,&n2);
      num_elem_in_block[i]=n;
      iscr.resize(n*n1);
      ex_get_conn(exo_file,EX_ELEM_BLOCK,ids[i],TOPTR(iscr), nullptr, nullptr);
      sprintf(str,"blk%02d",i+1);
      PutInt(str,n1,n,TOPTR(iscr));
    }
    str[0]='\0';
    for (int i=0;i<num_blocks;i++) {
      strcat(str, str2[i]);
      strcat(str, "\n");
    }
    PutStr("blknames",str);
  }

  /* time values */
  if (num_time_steps > 0 ) {
    if (debug) {logger("Time Steps");}
    std::vector<double> scr(num_time_steps);
    ex_get_all_times (exo_file, TOPTR(scr));
    PutDbl( "time", num_time_steps, 1, TOPTR(scr));
  }

  /* global variables */
  if (num_global_vars > 0 ) {
    if (debug) {logger("Global Variables");}
    get_put_names(exo_file, EX_GLOBAL, num_global_vars, "gnames");

    std::vector<double> scr(num_time_steps);
    for (int i=0;i<num_global_vars;i++){
      sprintf(str,"gvar%02d",i+1);
      ex_get_glob_var_time(exo_file,i+1,1,num_time_steps,TOPTR(scr));
      PutDbl(str,num_time_steps,1,TOPTR(scr));
    }
  }

  /* nodal variables */
  if (num_nodal_vars > 0 ) {
    if (debug) {logger("Nodal Variables");}
    if (debug) {logger("\tNames");}
    get_put_names(exo_file, EX_NODAL, num_nodal_vars, "nnames");

    std::vector<double> scr(num_nodes*num_time_steps);
    for (int i=0; i<num_nodal_vars; i++){
      sprintf(str,"nvar%02d",i+1);
      if (debug) {logger("\tReading");}
      for (int j=0; j<num_time_steps; j++) {
        ex_get_nodal_var(exo_file,j+1,i+1,num_nodes,
                         &scr[num_nodes*j]);
      }
      if (debug) {logger("\tWriting");}
      PutDbl(str,num_nodes,num_time_steps,TOPTR(scr));
    }
  }

  /* element variables */
  if (num_element_vars > 0 ) {
    if (debug) {logger("Element Variables");}
    get_put_names(exo_file, EX_ELEM_BLOCK, num_element_vars, "enames");

    get_put_vars(exo_file, EX_ELEM_BLOCK,
                 num_blocks, num_element_vars, num_time_steps, num_elem_in_block, "evar%02d");
  }

  /* nodeset variables */
  if (num_nodeset_vars > 0 ) {
    if (debug) {logger("Nodeset Variables");}
    get_put_names(exo_file, EX_NODE_SET, num_nodeset_vars, "nsnames");

    get_put_vars(exo_file, EX_NODE_SET,
                 num_node_sets, num_nodeset_vars, num_time_steps, num_nodeset_nodes, "nsvar%02d");
  }

  /* sideset variables */
  if (num_sideset_vars > 0 ) {
    if (debug) {logger("Sideset Variables");}
    get_put_names(exo_file, EX_SIDE_SET, num_sideset_vars, "ssnames");

    get_put_vars(exo_file, EX_SIDE_SET,
                 num_side_sets, num_sideset_vars, num_time_steps, num_sideset_sides, "ssvar%02d");
  }

  /* node and element number maps */
  if (debug) {logger("Node and Element Number Maps");}
  ex_opts(0);  /* turn off error reporting. It is not an error to have no map*/
  ids.resize(num_nodes);
  err = ex_get_node_num_map(exo_file,TOPTR(ids));
  if ( err==0 ){
    PutInt("node_num_map",num_nodes,1,TOPTR(ids));
  }

  ids.resize(num_elements);
  err = ex_get_elem_num_map(exo_file,TOPTR(ids));
  if ( err==0 ){
    PutInt("elem_num_map",num_elements,1,TOPTR(ids));
  }

  if (debug) {logger("Closing file");}
  ex_close(exo_file);

  if ( textfile )
    fclose(m_file);
  else
    Mat_Close(mat_file);

  std::cout << "done...\n";

  free(filename);
  free(line);

  delete_exodus_names(str2, nstr2);

  /* exit status */
  add_to_log("exo2mat", 0);
  return(0);
}