Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
ListSetsNTagsF90.F90
Go to the documentation of this file.
1  ! ListSetsNTags: list sets & tags from a mesh
2  !
3  ! This program shows how to read and list sets and tags from a mesh
4  !
5  ! Usage: SetsNTags <mesh_file_name>
6 
7 
8 
9 #define ERRORR(a) if (0 .ne. err) print *, a
10 
11  program listsetsntags
12 
13 #include "iMesh_f.h"
14 
15  imesh_instance mesh
16  ibase_entitysethandle root_set
17  integer err
18 
19  ibase_handle_t rpsets, rptags
20  pointer(rpsets, sets(0:*))
21  pointer(rptags, tags(0:*))
22  ibase_entitysethandle sets
23  ibase_taghandle tags
24  integer sets_alloc, sets_size, tags_alloc, tags_size
25 
26  real*8 dbl_val
27  integer int_val, tag_type
28  character*128 tname, fname
29  character*1024 tname2
30 
31  integer i, j, num_hops, num_commands, tname_len
32  logical read_par
33  data read_par/.false./
34 
35  num_commands = command_argument_count()
36  if (num_commands .eq. 0) then
37  fname = "../MeshFiles/125hex.vtk"
38  else
39  call get_command_argument(1, tname, tname_len, err)
40  if (err .ne. 0) then
41  errorr("Problem getting filename argument.")
42  call exit
43  endif
44  fname = tname
45  if (num_commands .eq. 2) then
46  call get_command_argument(2, tname, tname_len, err)
47  if (err .ne. 0) then
48  errorr("Problem getting filename argument.")
49  call exit
50  endif
51  if (tname(1:1) .eq. 'p' .or. tname(1:1) .eq. 'P') then
52  read_par = .true.
53  endif
54  endif
55  endif
56 
57  ! create the Mesh instance
58  call imesh_newmesh("", mesh, err)
59  errorr("Error creating new mesh.")
60 
61 
62  call imesh_getrootset(%VAL(mesh), root_set, err)
63  errorr("Couldn't get root set.")
64 
65  ! load the mesh
66  if (read_par) then
67  call imesh_load(%VAL(mesh), %VAL(root_set), fname, &
68  " moab:PARALLEL=READ_PART moab:PARTITION=PARALLEL_PARTITION moab:PARTITION_DISTRIBUTE moab:PARALLEL_RESOLVE_SHARED_ENTS " &
69  , err)
70  else
71  call imesh_load(%VAL(mesh), %VAL(root_set), fname, "", err)
72  endif
73  errorr("Couldn't load mesh.")
74 
75  ! get all sets
76  sets_alloc = 0
77  num_hops = 1
78  call imesh_getentsets(%VAL(mesh), %VAL(root_set), %VAL(num_hops), &
79  rpsets, sets_alloc, sets_size, err)
80  errorr("Couldn't get all sets.")
81 
82  ! iterate through them, checking whether they have tags
83  do i = 0, sets_size-1
84  ! get connectivity
85  tags_alloc = 0
86  call imesh_getallentsettags(%VAL(mesh), %VAL(sets(i)), &
87  rptags, tags_alloc, tags_size, err)
88  errorr("Failed to get ent set tags.")
89 
90  if (0 .ne. tags_size) then
91  print *, "Set ", sets(i), " Tags:"
92  end if
93 
94  ! list tag names on this set
95  do j = 0, tags_size-1
96  call imesh_gettagname(%VAL(mesh), %VAL(tags(j)), tname, err)
97  call imesh_gettagtype(%VAL(mesh), %VAL(tags(j)), tag_type, err)
98  errorr("Failed to get tag type.")
99  if (ibase_integer .eq. tag_type) then
100  call imesh_getentsetintdata(%VAL(mesh), %VAL(sets(i)), &
101  %VAL(tags(j)), int_val, err)
102  errorr("Failed to get int data type.")
103  print *, tname, int_val
104  else if (ibase_double .eq. tag_type) then
105  call imesh_getentsetdbldata(%VAL(mesh), %VAL(sets(i)), &
106  %VAL(tags(j)), dbl_val, err)
107  print *, tname, dbl_val
108  else
109  print *, tname
110  end if
111 
112  end do
113 
114  if (tags_size .ne. 0) call free(rptags)
115  tags_alloc = 0
116  end do
117 
118  if (sets_size .ne. 0) call free(rpsets)
119 
120  call imesh_dtor(%VAL(mesh), err)
121  errorr("Failed to destruct interface.")
122 
123 ! return
124  end program listsetsntags
125