nodes: 0, module; 1, function_definition; 2, function_name:_read_elem_nodes; 3, parameters; 4, block; 5, identifier:self; 6, identifier:fid; 7, expression_statement; 8, expression_statement; 9, comment:#   # prepare nodes; 10, comment:#   nodes_sorted = np.zeros((number_of_nodes, 3), dtype=float); 11, comment:#   nodes = np.zeros((number_of_nodes, 3), dtype=float); 12, comment:# read in nodes; 13, expression_statement; 14, for_statement; 15, comment:# round node coordinates to 5th decimal point. Sometimes this is; 16, comment:# important when we deal with mal-formatted node data; 17, expression_statement; 18, comment:# check for CutMcK; 19, comment:# The check is based on the first node, but if one node was renumbered,; 20, comment:# so were all the others.; 21, if_statement; 22, comment:# Rearrange nodes when CutMcK was used.; 23, if_statement; 24, comment:# prepare node dict; 25, expression_statement; 26, expression_statement; 27, expression_statement; 28, expression_statement; 29, comment:""" Read the nodes from an opened elem.dat file. Correct for CutMcK
          transformations.
  
          We store three typed of nodes in the dict 'nodes':
  
              * "raw" : as read from the elem.dat file
              * "presort" : pre-sorted so we can directly read node numbers from
                a elec.dat file and use them as indices.
              * "sorted" : completely sorted as in the original grid (before any
                         CutMcK)
  
          For completeness, we also store the following keys:
  
              * "cutmck_index" : Array containing the indices in "presort" to
                obtain the "sorted" values:
                nodes['sorted'] = nodes['presort'] [nodes['cutmck_index'], :]
              * "rev_cutmck_index" : argsort(cutmck_index)
          """; 30, assignment; 31, assignment; 32, identifier:nr; 33, call; 34, block; 35, assignment; 36, parenthesized_expression; 37, block; 38, else_clause; 39, parenthesized_expression; 40, block; 41, else_clause; 42, assignment; 43, assignment; 44, assignment; 45, assignment; 46, identifier:nodes; 47, dictionary; 48, identifier:nodes_raw; 49, call; 50, identifier:range; 51, argument_list; 52, expression_statement; 53, expression_statement; 54, subscript; 55, call; 56, comparison_operator:nodes_raw[:, 0] != list(range(1, nodes_raw.shape[0])); 57, expression_statement; 58, expression_statement; 59, block; 60, subscript; 61, expression_statement; 62, expression_statement; 63, for_statement; 64, comment:# sort them; 65, expression_statement; 66, expression_statement; 67, expression_statement; 68, expression_statement; 69, block; 70, subscript; 71, identifier:nodes_raw; 72, subscript; 73, identifier:nodes_sorted; 74, attribute; 75, identifier:nodes; 76, attribute; 77, subscript; 78, attribute; 79, argument_list; 80, integer:0; 81, subscript; 82, assignment; 83, assignment; 84, identifier:nodes_raw; 85, slice; 86, slice; 87, attribute; 88, argument_list; 89, subscript; 90, call; 91, assignment; 92, call; 93, expression_statement; 94, attribute; 95, string; 96, assignment; 97, assignment; 98, identifier:node; 99, call; 100, block; 101, assignment; 102, assignment; 103, assignment; 104, assignment; 105, expression_statement; 106, expression_statement; 107, identifier:nodes; 108, string; 109, identifier:nodes; 110, string; 111, identifier:self; 112, identifier:nodes; 113, identifier:self; 114, identifier:nr_of_nodes; 115, attribute; 116, integer:0; 117, identifier:np; 118, identifier:empty; 119, tuple; 120, keyword_argument; 121, attribute; 122, string; 123, identifier:node_line; 124, call; 125, subscript; 126, call; 127, integer:1; 128, integer:3; 129, identifier:np; 130, identifier:round; 131, subscript; 132, integer:5; 133, identifier:nodes_raw; 134, slice; 135, integer:0; 136, identifier:list; 137, argument_list; 138, subscript; 139, True; 140, identifier:print; 141, argument_list; 142, assignment; 143, identifier:self; 144, identifier:header; 145, string_content:cutmck; 146, identifier:nodes_cutmck; 147, call; 148, identifier:nodes_cutmck_index; 149, call; 150, identifier:range; 151, argument_list; 152, expression_statement; 153, expression_statement; 154, expression_statement; 155, expression_statement; 156, identifier:nodes_sorted; 157, subscript; 158, subscript; 159, identifier:nodes_cutmck; 160, subscript; 161, identifier:nodes_cutmck_index; 162, subscript; 163, call; 164, assignment; 165, assignment; 166, string_content:raw; 167, string_content:sorted; 168, subscript; 169, identifier:shape; 170, subscript; 171, integer:3; 172, identifier:dtype; 173, identifier:float; 174, identifier:self; 175, identifier:header; 176, string_content:nr_nodes; 177, attribute; 178, argument_list; 179, identifier:nodes_raw; 180, identifier:nr; 181, slice; 182, attribute; 183, argument_list; 184, identifier:nodes_raw; 185, slice; 186, slice; 187, call; 188, attribute; 189, string; 190, string; 191, subscript; 192, False; 193, attribute; 194, argument_list; 195, attribute; 196, argument_list; 197, integer:0; 198, subscript; 199, assignment; 200, assignment; 201, assignment; 202, assignment; 203, identifier:nodes_cutmck; 204, identifier:nodes_cutmck_index; 205, slice; 206, identifier:nodes; 207, string; 208, identifier:nodes; 209, string; 210, identifier:nodes; 211, string; 212, attribute; 213, argument_list; 214, identifier:nodes_sorted; 215, identifier:nodes_raw; 216, subscript; 217, identifier:nodes_raw; 218, identifier:nodes; 219, string; 220, attribute; 221, string; 222, call; 223, identifier:lstrip; 224, identifier:np; 225, identifier:fromstring; 226, identifier:node_line; 227, keyword_argument; 228, keyword_argument; 229, integer:1; 230, integer:3; 231, identifier:range; 232, argument_list; 233, identifier:self; 234, identifier:header; 235, string_content:cutmck; 236, string_content:This grid was sorted using CutMcK. The nodes were resorted!; 237, attribute; 238, string; 239, identifier:np; 240, identifier:empty_like; 241, identifier:nodes_raw; 242, identifier:np; 243, identifier:zeros; 244, subscript; 245, keyword_argument; 246, attribute; 247, string; 248, identifier:new_index; 249, call; 250, subscript; 251, subscript; 252, subscript; 253, subscript; 254, subscript; 255, subscript; 256, string_content:presort; 257, string_content:cutmck_index; 258, string_content:rev_cutmck_index; 259, identifier:np; 260, identifier:argsort; 261, identifier:nodes_cutmck_index; 262, identifier:nodes; 263, string; 264, string_content:raw; 265, identifier:self; 266, identifier:header; 267, string_content:nr_nodes; 268, attribute; 269, argument_list; 270, identifier:dtype; 271, identifier:float; 272, identifier:sep; 273, string; 274, integer:1; 275, subscript; 276, identifier:self; 277, identifier:header; 278, string_content:cutmck; 279, attribute; 280, integer:0; 281, identifier:dtype; 282, identifier:int; 283, identifier:self; 284, identifier:header; 285, string_content:nr_nodes; 286, attribute; 287, argument_list; 288, identifier:nodes_cutmck; 289, subscript; 290, slice; 291, identifier:nodes_raw; 292, identifier:node; 293, slice; 294, identifier:nodes_cutmck; 295, subscript; 296, integer:0; 297, identifier:new_index; 298, integer:0; 299, identifier:nodes_cutmck_index; 300, identifier:node; 301, identifier:new_index; 302, integer:0; 303, string_content:presort; 304, identifier:fid; 305, identifier:readline; 306, string_content:; 307, attribute; 308, integer:0; 309, identifier:nodes_raw; 310, identifier:shape; 311, identifier:np; 312, identifier:where; 313, comparison_operator:nodes_raw[:, 0].astype(int) == (node + 1); 314, identifier:new_index; 315, integer:0; 316, integer:1; 317, integer:3; 318, integer:1; 319, integer:3; 320, identifier:new_index; 321, integer:0; 322, identifier:nodes_raw; 323, identifier:shape; 324, call; 325, parenthesized_expression; 326, attribute; 327, argument_list; 328, binary_operator:node + 1; 329, subscript; 330, identifier:astype; 331, identifier:int; 332, identifier:node; 333, integer:1; 334, identifier:nodes_raw; 335, slice; 336, integer:0
code: def _read_elem_nodes(self, fid):
          """ Read the nodes from an opened elem.dat file. Correct for CutMcK
          transformations.
  
          We store three typed of nodes in the dict 'nodes':
  
              * "raw" : as read from the elem.dat file
              * "presort" : pre-sorted so we can directly read node numbers from
                a elec.dat file and use them as indices.
              * "sorted" : completely sorted as in the original grid (before any
                         CutMcK)
  
          For completeness, we also store the following keys:
  
              * "cutmck_index" : Array containing the indices in "presort" to
                obtain the "sorted" values:
                nodes['sorted'] = nodes['presort'] [nodes['cutmck_index'], :]
              * "rev_cutmck_index" : argsort(cutmck_index)
          """
          nodes = {}
  
          #   # prepare nodes
          #   nodes_sorted = np.zeros((number_of_nodes, 3), dtype=float)
          #   nodes = np.zeros((number_of_nodes, 3), dtype=float)
  
          # read in nodes
          nodes_raw = np.empty((self.header['nr_nodes'], 3), dtype=float)
          for nr in range(0, self.header['nr_nodes']):
              node_line = fid.readline().lstrip()
              nodes_raw[nr, :] = np.fromstring(
                  node_line, dtype=float, sep='    ')
  
          # round node coordinates to 5th decimal point. Sometimes this is
          # important when we deal with mal-formatted node data
          nodes_raw[:, 1:3] = np.round(nodes_raw[:, 1:3], 5)
  
          # check for CutMcK
          # The check is based on the first node, but if one node was renumbered,
          # so were all the others.
          if(nodes_raw[:, 0] != list(range(1, nodes_raw.shape[0]))):
              self.header['cutmck'] = True
              print(
                  'This grid was sorted using CutMcK. The nodes were resorted!')
          else:
              self.header['cutmck'] = False
  
          # Rearrange nodes when CutMcK was used.
          if(self.header['cutmck']):
              nodes_cutmck = np.empty_like(nodes_raw)
              nodes_cutmck_index = np.zeros(nodes_raw.shape[0], dtype=int)
              for node in range(0, self.header['nr_nodes']):
                  new_index = np.where(nodes_raw[:, 0].astype(int) == (node + 1))
                  nodes_cutmck[new_index[0], 1:3] = nodes_raw[node, 1:3]
                  nodes_cutmck[new_index[0], 0] = new_index[0]
                  nodes_cutmck_index[node] = new_index[0]
              # sort them
              nodes_sorted = nodes_cutmck[nodes_cutmck_index, :]
              nodes['presort'] = nodes_cutmck
              nodes['cutmck_index'] = nodes_cutmck_index
              nodes['rev_cutmck_index'] = np.argsort(nodes_cutmck_index)
          else:
              nodes_sorted = nodes_raw
              nodes['presort'] = nodes_raw
  
          # prepare node dict
          nodes['raw'] = nodes_raw
          nodes['sorted'] = nodes_sorted
  
          self.nodes = nodes
          self.nr_of_nodes = nodes['raw'].shape[0]