\section{read\_mesh\_to\_memory}
This appendix lists an example of the ``C'' source code that an application linked to \textsc{pamgen}
would use to read a finite element mesh description from \textsc{pamgen}.
\label{sec:read-mesh-to-memory}
%{\ttfamily  

%\newenvironment{smallverbatim}{\endgraf\small\verbatim}{\endverbatim} 
\begin{Verbatim}[fontsize=\small] 
/*****************************************************************************/
void read_mesh_to_memory()
/*****************************************************************************/
{
  int im_exoid = 0;
  int idum = 0;
  float fdum;

  mss.bptr[0] = mss.buffer[0];      
  mss.bptr[1] = mss.buffer[1];      
  mss.bptr[2] = mss.buffer[2];      
  
  for(int i = 0; i < 100; i++)
    for(int j=0; j<4; j++) mss.qaRecord[i][j] = (char*)malloc(MAX_STR_LENGTH+1) ;
  
  
  char * cdum = NULL;
  int error = 0;
  int id = 0;
  error += im_ex_get_init (  id,
			     mss.title,
			     &mss.num_dim,
			     &(mss.num_nodes),
			     &mss.num_elem, 
			     &mss.num_elem_blk,
			     &mss.num_node_sets,
			     &mss.num_side_sets);
  
  
  error += im_ex_inquire(id, IM_EX_INQ_NS_NODE_LEN, (int*)&mss.num_node_set_nodes, 
			 &fdum, cdum);
  error += im_ex_inquire(id, IM_EX_INQ_NS_DF_LEN,   (int*)&mss.num_node_set_dfs, 
			 &fdum, cdum);
  error += im_ex_inquire(id, IM_EX_INQ_SS_ELEM_LEN, (int*)&mss.num_side_set_elements,
			 &fdum, cdum);
  error += im_ex_inquire(id, IM_EX_INQ_SS_NODE_LEN, (int*)&mss.num_side_set_nodes,
			 &fdum, cdum);
  error += im_ex_inquire(id, IM_EX_INQ_SS_DF_LEN,   (int*)&mss.num_side_set_dfs, 
			 &fdum, cdum);
    
  // // get version number
    
  error += im_ex_inquire(id, IM_EX_INQ_API_VERS, &idum, &fdum, cdum);
    
  mss.version_number = (double) fdum;
    
  mss.version = (int) mss.version_number;
    
  // // get genesis-II parameters
    
  error += im_ex_inquire(id, IM_EX_INQ_EB_PROP, 
	                 (int*)&mss.num_block_properties, 
                         &fdum, cdum);
    
  error += im_ex_inquire(id, IM_EX_INQ_NS_PROP, 
                         (int*)&mss.num_node_set_properties, 
			 &fdum, cdum);
    
  error += im_ex_inquire(id, IM_EX_INQ_SS_PROP, 
                         (int*)&mss.num_side_set_properties, 
			 &fdum, cdum);
    
  mss.coord = (double *)malloc(mss.num_nodes*mss.num_dim*sizeof(double));
    
  error += im_ex_get_coord(id,
                           mss.coord,
                           mss.coord+mss.num_nodes,
                           mss.coord+2*mss.num_nodes);

    
  error += im_ex_get_coord_names (id, mss.bptr);
    
  if (mss.num_elem){
    mss.element_order_map = (int *)malloc(mss.num_elem * sizeof(int));
    error += im_ex_get_map(id, mss.element_order_map);
      
    if (mss.num_elem){
      mss.global_element_numbers = (int *)malloc(mss.num_elem*sizeof(int));
      error += im_ex_get_elem_num_map(id, mss.global_element_numbers);
    }
      
    if (mss.num_nodes){
      mss.global_node_numbers = (int *)malloc(mss.num_nodes * sizeof(int));
      error += im_ex_get_node_num_map(id, mss.global_node_numbers);
    }
      
     
    //block info

    mss.block_id           = (int *)malloc(mss.num_elem_blk*sizeof(int));
    mss.nodes_per_element  = (int *)malloc(mss.num_elem_blk*sizeof(int));
    mss.element_attributes = (int *)malloc(mss.num_elem_blk*sizeof(int));
    mss.elements           = (int *)malloc(mss.num_elem_blk*sizeof(int));
    mss.element_types      = (char **)malloc(mss.num_elem_blk*sizeof(char *));
    mss.elmt_node_linkage  = (int **)malloc(mss.num_elem_blk*sizeof(int*));

    error += im_ex_get_elem_blk_ids(id, mss.block_id);

    for(int i = 0; i < mss.num_elem_blk; i ++){
      mss.element_types[i] = (char *)malloc((MAX_STR_LENGTH + 1)*sizeof(char));
      error += im_ex_get_elem_block(id, 
				    mss.block_id[i], 
				    mss.element_types[i],
				    (int*)&(mss.elements[i]),
				    (int*)&(mss.nodes_per_element[i]), 
				    (int*)&(mss.element_attributes[i]));
    }
    
    //connectivity
    for(int b = 0; b < mss.num_elem_blk; b++){
      mss.elmt_node_linkage[b] = (int*)malloc(mss.nodes_per_element[b]*
                                              mss.elements[b]*sizeof(int));
      error += im_ex_get_elem_conn(id,mss.block_id[b],mss.elmt_node_linkage[b]);
    }

      
    if(mss.num_node_sets){
      mss.node_set_id           = (int *) malloc(mss.num_node_sets*sizeof(int));
      mss.num_nodes_in_node_set = (int *) malloc(mss.num_node_sets*sizeof(int));
      mss.node_set_nodes        = (int **)malloc(mss.num_node_sets*sizeof(int*));
      mss.num_df_in_node_set    = (int *) malloc(mss.num_node_sets*sizeof(int*));
      
      error += im_ex_get_node_set_ids(id, mss.node_set_id);


      for(int i = 0; i < mss.num_node_sets; i ++){
	error += im_ex_get_node_set_param(id, mss.node_set_id[i],
					  (int*)&mss.num_nodes_in_node_set[i], 
					  (int*)&mss.num_df_in_node_set[i]);

      	mss.node_set_nodes[i] = NULL;

	if(mss.num_nodes_in_node_set[i]) {
	  mss.node_set_nodes[i] = 
           (int *)malloc(mss.num_nodes_in_node_set[i]*sizeof(int));
	  error += im_ex_get_node_set(id, 
                                      mss.node_set_id[i], 
                                      mss.node_set_nodes[i]);
	}
      }
    }

    //side sets
    if(mss.num_side_sets){
      mss.side_set_id = (int*)malloc(mss.num_side_sets*sizeof(int));
      mss.num_elements_in_side_set = (int*)malloc(mss.num_side_sets*sizeof(int));
      mss.num_df_in_side_set = (int*)malloc(mss.num_side_sets*sizeof(int));
      mss.side_set_elements = (int**)malloc(mss.num_side_sets*sizeof(int *));
      mss.side_set_faces = (int **)malloc(mss.num_side_sets*sizeof(int*));

      error += im_ex_get_side_set_ids(id, mss.side_set_id);
      for(int i = 0; i < mss.num_side_sets; i ++){
	  
	error += im_ex_get_side_set_param(id, mss.side_set_id[i], 
					  (int*)&mss.num_elements_in_side_set[i],
					  (int*)&mss.num_df_in_side_set[i]);

	int ne = mss.num_elements_in_side_set[i];
	mss.side_set_elements[i] = (int*)malloc(ne*sizeof(int));
	mss.side_set_faces[i] = (int*)malloc(ne*sizeof(int));
	if(ne){
	  error += im_ex_get_side_set(id, mss.side_set_id[i], 
				      mss.side_set_elements[i], 
				      mss.side_set_faces[i]);

	}
      }
    }
      
    error += im_ex_inquire(id, IM_EX_INQ_QA, (int*)&mss.num_qa_records, &fdum, cdum);

    if(mss.num_qa_records)error +=  im_ex_get_qa(id,mss.qaRecord);


    error += im_ex_inquire(id, IM_EX_INQ_INFO, (int*)&mss.num_info_records, &fdum, cdum);
    if(mss.num_info_records) { 
      mss.info_records = (char **)malloc(mss.num_info_records*sizeof(char *));
      for(int i = 0; i < mss.num_info_records; i ++){
	mss.info_records[i] = (char *)malloc(MAX_STR_LENGTH+1);
      }
      error += im_ex_get_info(id, mss.info_records);
    }


    //nemesis data
    // global info
    if ( im_ne_get_init_global(id, &mss.num_nodes_global, &mss.num_elems_global,
			       &mss.num_elm_blks_global, &mss.num_node_sets_global,
			       &mss.num_side_sets_global) < 0 )
      ++error;

  

    if ( im_ne_get_init_info(id, 
                             &mss.num_total_proc, 
                             &mss.num_proc_in_file, mss.type) < 0 )
      ++error;

    mss.elem_blk_ids_global = (int*)malloc(mss.num_elm_blks_global*sizeof(int));
    mss.elem_blk_cnts_global = (int*)malloc(mss.num_elm_blks_global*sizeof(int));

    if ( im_ne_get_eb_info_global(id,
                                  mss.elem_blk_ids_global,
                                  mss.elem_blk_cnts_global) < 0 )
      ++error;

    mss.ns_ids_global = (int *)malloc(mss.num_node_sets_global*sizeof(int));
    mss.ns_cnts_global = (int *)malloc(mss.num_node_sets_global*sizeof(int));
    mss.ns_df_cnts_global = (int *)malloc(mss.num_node_sets_global*sizeof(int));
    mss.ss_ids_global = (int *)malloc(mss.num_side_sets_global*sizeof(int));
    mss.ss_cnts_global = (int *)malloc(mss.num_side_sets_global*sizeof(int));
    mss.ss_df_cnts_global = (int *)malloc(mss.num_side_sets_global*sizeof(int));

    
    if ( mss.num_node_sets_global > 0 ) {
      if ( im_ne_get_ns_param_global(id,mss.ns_ids_global,mss.ns_cnts_global,
				     mss.ns_df_cnts_global) < 0 )++error;
    }
    
    if ( mss.num_side_sets_global > 0 ) {
      if ( im_ne_get_ss_param_global(id,mss.ss_ids_global,mss.ss_cnts_global,
				     mss.ss_df_cnts_global) < 0 )  ++error;      
    }
    
    //parallel info
    if ( im_ne_get_loadbal_param( id, 
				  &mss.num_internal_nodes,
				  &mss.num_border_nodes, 
				  &mss.num_external_nodes,
				  &mss.num_internal_elems, 
				  &mss.num_border_elems,
				  &mss.num_node_comm_maps,
				  &mss.num_elem_comm_maps,
				  0/*unused*/ ) < 0 )++error;
    
    mss.internal_elements = (int *)malloc(mss.num_internal_elems*sizeof(int));
    mss.border_elements   = (int *)malloc(mss.num_border_elems*sizeof(int));
    mss.internal_nodes    = (int *)malloc(mss.num_internal_nodes*sizeof(int));
    mss.border_nodes      = (int *)malloc(mss.num_border_nodes*sizeof(int));
    mss.external_nodes    = (int *)malloc(mss.num_external_nodes*sizeof(int));
   
    if ( im_ne_get_elem_map( id, 
			     mss.internal_elements, 
			     mss.border_elements, 
			     0/* not used proc_id*/ ) < 0 )++error;
    
    if ( im_ne_get_node_map( id, 
			     mss.internal_nodes, 
			     mss.border_nodes,
			     mss.external_nodes, 
			     0/* not used proc_id*/ ) < 0 )++error;


    if(mss.num_node_comm_maps > 0){

      mss.node_cmap_node_cnts = (int*) malloc(mss.num_node_comm_maps*sizeof(int));
      mss.node_cmap_ids       = (int*) malloc(mss.num_node_comm_maps*sizeof(int));
      mss.comm_node_ids       = (int**)malloc(mss.num_node_comm_maps*sizeof(int*));
      mss.comm_node_proc_ids  = (int**)malloc(mss.num_node_comm_maps*sizeof(int*));

      mss.elem_cmap_elem_cnts = (int*) malloc(mss.num_elem_comm_maps*sizeof(int));
      mss.elem_cmap_ids       = (int*) malloc(mss.num_elem_comm_maps*sizeof(int));
      mss.comm_elem_ids       = (int**)malloc(mss.num_elem_comm_maps*sizeof(int*));
      mss.comm_side_ids       = (int**)malloc(mss.num_elem_comm_maps*sizeof(int*));
      mss.comm_elem_proc_ids  = (int**)malloc(mss.num_elem_comm_maps*sizeof(int*));

      if ( im_ne_get_cmap_params( id, 
				  mss.node_cmap_ids,
				  (int*)mss.node_cmap_node_cnts, 
				  mss.elem_cmap_ids,
				  (int*)mss.elem_cmap_elem_cnts, 
				  0/*not used proc_id*/ ) < 0 )++error;
      
      for(int j = 0; j < mss.num_node_comm_maps; j++) {
	mss.comm_node_ids[j]       = (int *)malloc(mss.node_cmap_node_cnts[j]*sizeof(int));
	mss.comm_node_proc_ids[j]  = (int *)malloc(mss.node_cmap_node_cnts[j]*sizeof(int));
	if ( im_ne_get_node_cmap( id, 
				  mss.node_cmap_ids[j], 
				  mss.comm_node_ids[j], 
				  mss.comm_node_proc_ids[j],
				  0/*not used proc_id*/ ) < 0 )++error;
	
      }
      
      
      
      for(int j = 0; j < mss.num_elem_comm_maps; j++) {
	mss.comm_elem_ids[j]       = (int *)malloc(mss.elem_cmap_elem_cnts[j]*sizeof(int));
	mss.comm_side_ids[j]       = (int *)malloc(mss.elem_cmap_elem_cnts[j]*sizeof(int));
	mss.comm_elem_proc_ids[j]  = (int *)malloc(mss.elem_cmap_elem_cnts[j]*sizeof(int));
	if ( im_ne_get_elem_cmap( id, 
				  mss.elem_cmap_ids[j], 
				  mss.comm_elem_ids[j], 
				  mss.comm_side_ids[j],
				  mss.comm_elem_proc_ids[j],
				  0 /*not used proc_id*/ ) < 0 )++error;
	

      }//loop over num_elem_co
    }
  }
}
\end{Verbatim}
%}
