nodes: 0, module; 1, function_definition; 2, function_name:main; 3, parameters; 4, block; 5, expression_statement; 6, expression_statement; 7, expression_statement; 8, if_statement; 9, if_statement; 10, if_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, comment:#; 15, comment:# read in data; 16, comment:#; 17, expression_statement; 18, if_statement; 19, comment:# get list of specimens in file, components, coordinate systems available; 20, expression_statement; 21, for_statement; 22, comment:# work on separating out components, coordinate systems by specimen; 23, for_statement; 24, comment:"""
      NAME
          sort_specimens.py
  
      DESCRIPTION
          Reads in a pmag_specimen formatted file and separates it into different components (A,B...etc.)
  
      SYNTAX 
          sort_specimens.py [-h] [command line options]
  
      INPUT
          takes pmag_specimens.txt formatted input file
  
      OPTIONS
          -h: prints help message and quits
          -f FILE: specify input file, default is 'pmag_specimens.txt'
  
      OUTPUT
          makes pmag_specimen formatted files with input filename plus _X_Y 
          where X is the component name and Y is s,g,t for coordinate system
      """; 25, assignment; 26, assignment; 27, comparison_operator:'-WD' in sys.argv; 28, block; 29, comparison_operator:'-h' in sys.argv; 30, block; 31, comparison_operator:'-f' in sys.argv; 32, block; 33, assignment; 34, assignment; 35, assignment; 36, assignment; 37, comparison_operator:file_type != 'pmag_specimens'; 38, block; 39, assignment; 40, identifier:spec; 41, identifier:prior_spec_data; 42, block; 43, identifier:coord; 44, identifier:coords; 45, block; 46, identifier:dir_path; 47, string; 48, identifier:inspec; 49, string:"pmag_specimens.txt"; 50, string; 51, attribute; 52, expression_statement; 53, expression_statement; 54, string; 55, attribute; 56, expression_statement; 57, expression_statement; 58, string; 59, attribute; 60, expression_statement; 61, expression_statement; 62, identifier:basename; 63, subscript; 64, identifier:inspec; 65, binary_operator:dir_path+"/"+inspec; 66, identifier:ofile_base; 67, binary_operator:dir_path+"/"+basename[0]; 68, pattern_list; 69, call; 70, identifier:file_type; 71, string; 72, expression_statement; 73, expression_statement; 74, pattern_list; 75, expression_list; 76, if_statement; 77, if_statement; 78, if_statement; 79, if_statement; 80, if_statement; 81, expression_statement; 82, for_statement; 83, string_content:.; 84, string_content:-WD; 85, identifier:sys; 86, identifier:argv; 87, assignment; 88, assignment; 89, string_content:-h; 90, identifier:sys; 91, identifier:argv; 92, call; 93, call; 94, string_content:-f; 95, identifier:sys; 96, identifier:argv; 97, assignment; 98, assignment; 99, call; 100, slice; 101, binary_operator:dir_path+"/"; 102, identifier:inspec; 103, binary_operator:dir_path+"/"; 104, subscript; 105, identifier:prior_spec_data; 106, identifier:file_type; 107, attribute; 108, argument_list; 109, string_content:pmag_specimens; 110, call; 111, call; 112, identifier:specs; 113, identifier:comps; 114, identifier:coords; 115, list; 116, list; 117, list; 118, comparison_operator:spec['er_specimen_name'] not in specs; 119, block; 120, comparison_operator:'specimen_comp_name' not in list(spec.keys()); 121, block; 122, comparison_operator:'specimen_tilt_correction'  not in list(spec.keys()); 123, block; 124, comparison_operator:spec['specimen_comp_name'] not in comps; 125, block; 126, comparison_operator:spec['specimen_tilt_correction'] not in coords; 127, block; 128, call; 129, identifier:comp; 130, identifier:comps; 131, block; 132, identifier:ind; 133, call; 134, identifier:dir_path; 135, subscript; 136, identifier:print; 137, argument_list; 138, attribute; 139, argument_list; 140, identifier:ind; 141, call; 142, identifier:inspec; 143, subscript; 144, attribute; 145, argument_list; 146, unary_operator; 147, identifier:dir_path; 148, string:"/"; 149, identifier:dir_path; 150, string:"/"; 151, identifier:basename; 152, integer:0; 153, identifier:pmag; 154, identifier:magic_read; 155, identifier:inspec; 156, identifier:print; 157, argument_list; 158, attribute; 159, argument_list; 160, subscript; 161, identifier:specs; 162, expression_statement; 163, string; 164, call; 165, expression_statement; 166, string; 167, call; 168, expression_statement; 169, comment:# assume specimen coordinates; 170, subscript; 171, identifier:comps; 172, expression_statement; 173, subscript; 174, identifier:coords; 175, expression_statement; 176, identifier:print; 177, argument_list; 178, expression_statement; 179, expression_statement; 180, for_statement; 181, expression_statement; 182, expression_statement; 183, expression_statement; 184, attribute; 185, argument_list; 186, attribute; 187, binary_operator:ind+1; 188, attribute; 189, identifier:sys; 190, identifier:exit; 191, attribute; 192, argument_list; 193, attribute; 194, binary_operator:ind+1; 195, identifier:inspec; 196, identifier:split; 197, string; 198, integer:1; 199, identifier:file_type; 200, string:" this is not a valid pmag_specimens file"; 201, identifier:sys; 202, identifier:exit; 203, identifier:spec; 204, string; 205, call; 206, string_content:specimen_comp_name; 207, identifier:list; 208, argument_list; 209, assignment; 210, string_content:specimen_tilt_correction; 211, identifier:list; 212, argument_list; 213, assignment; 214, identifier:spec; 215, string; 216, call; 217, identifier:spec; 218, string; 219, call; 220, identifier:coord; 221, call; 222, assignment; 223, identifier:spec; 224, identifier:prior_spec_data; 225, block; 226, assignment; 227, call; 228, call; 229, attribute; 230, identifier:index; 231, string; 232, identifier:sys; 233, identifier:argv; 234, identifier:ind; 235, integer:1; 236, identifier:main; 237, identifier:__doc__; 238, attribute; 239, identifier:index; 240, string; 241, identifier:sys; 242, identifier:argv; 243, identifier:ind; 244, integer:1; 245, string_content:.; 246, string_content:er_specimen_name; 247, attribute; 248, argument_list; 249, call; 250, subscript; 251, string; 252, call; 253, subscript; 254, string; 255, string_content:specimen_comp_name; 256, attribute; 257, argument_list; 258, string_content:specimen_tilt_correction; 259, attribute; 260, argument_list; 261, identifier:print; 262, argument_list; 263, identifier:speclist; 264, list; 265, if_statement; 266, identifier:ofile; 267, binary_operator:ofile_base+'_'+coord+'_'+comp+'.txt'; 268, attribute; 269, argument_list; 270, identifier:print; 271, argument_list; 272, identifier:sys; 273, identifier:argv; 274, string_content:-WD; 275, identifier:sys; 276, identifier:argv; 277, string_content:-f; 278, identifier:specs; 279, identifier:append; 280, subscript; 281, attribute; 282, argument_list; 283, identifier:spec; 284, string; 285, string_content:A; 286, attribute; 287, argument_list; 288, identifier:spec; 289, string; 290, string_content:-1; 291, identifier:comps; 292, identifier:append; 293, subscript; 294, identifier:coords; 295, identifier:append; 296, subscript; 297, identifier:comp; 298, boolean_operator; 299, block; 300, binary_operator:ofile_base+'_'+coord+'_'+comp; 301, string; 302, identifier:pmag; 303, identifier:magic_write; 304, identifier:ofile; 305, identifier:speclist; 306, string; 307, string; 308, identifier:coord; 309, string; 310, identifier:comp; 311, string; 312, identifier:ofile; 313, identifier:spec; 314, string; 315, identifier:spec; 316, identifier:keys; 317, string_content:specimen_comp_name; 318, identifier:spec; 319, identifier:keys; 320, string_content:tilt_correction; 321, identifier:spec; 322, string; 323, identifier:spec; 324, string; 325, comparison_operator:spec['specimen_tilt_correction']==coord; 326, comparison_operator:spec['specimen_comp_name']==comp; 327, expression_statement; 328, binary_operator:ofile_base+'_'+coord+'_'; 329, identifier:comp; 330, string_content:.txt; 331, string_content:pmag_specimens; 332, string_content:coordinate system:; 333, string_content:component name:; 334, string_content:saved in; 335, string_content:er_specimen_name; 336, string_content:specimen_comp_name; 337, string_content:specimen_tilt_correction; 338, subscript; 339, identifier:coord; 340, subscript; 341, identifier:comp; 342, call; 343, binary_operator:ofile_base+'_'+coord; 344, string; 345, identifier:spec; 346, string; 347, identifier:spec; 348, string; 349, attribute; 350, argument_list; 351, binary_operator:ofile_base+'_'; 352, identifier:coord; 353, string_content:_; 354, string_content:specimen_tilt_correction; 355, string_content:specimen_comp_name; 356, identifier:speclist; 357, identifier:append; 358, identifier:spec; 359, identifier:ofile_base; 360, string; 361, string_content:_
code: def main():
      """
      NAME
          sort_specimens.py
  
      DESCRIPTION
          Reads in a pmag_specimen formatted file and separates it into different components (A,B...etc.)
  
      SYNTAX 
          sort_specimens.py [-h] [command line options]
  
      INPUT
          takes pmag_specimens.txt formatted input file
  
      OPTIONS
          -h: prints help message and quits
          -f FILE: specify input file, default is 'pmag_specimens.txt'
  
      OUTPUT
          makes pmag_specimen formatted files with input filename plus _X_Y 
          where X is the component name and Y is s,g,t for coordinate system
      """
      dir_path='.'
      inspec="pmag_specimens.txt"
      if '-WD' in sys.argv:
          ind=sys.argv.index('-WD')
          dir_path=sys.argv[ind+1]
      if '-h' in sys.argv:
          print(main.__doc__)
          sys.exit()
      if '-f' in sys.argv:
          ind=sys.argv.index('-f')
          inspec=sys.argv[ind+1]
      basename=inspec.split('.')[:-1]
      inspec=dir_path+"/"+inspec
      ofile_base=dir_path+"/"+basename[0]
  #
  # read in data
  #
      prior_spec_data,file_type=pmag.magic_read(inspec)
      if file_type != 'pmag_specimens':
          print(file_type, " this is not a valid pmag_specimens file")
          sys.exit()
  # get list of specimens in file, components, coordinate systems available
      specs,comps,coords=[],[],[]
      for spec in prior_spec_data:
          if spec['er_specimen_name'] not in specs:specs.append(spec['er_specimen_name'])
          if 'specimen_comp_name' not in list(spec.keys()):spec['specimen_comp_name']='A'
          if 'specimen_tilt_correction'  not in list(spec.keys()):spec['tilt_correction']='-1' # assume specimen coordinates
          if spec['specimen_comp_name'] not in comps:comps.append(spec['specimen_comp_name'])
          if spec['specimen_tilt_correction'] not in coords:coords.append(spec['specimen_tilt_correction'])
  # work on separating out components, coordinate systems by specimen
      for coord in coords:
          print(coord)
          for comp in comps:
              print(comp)
              speclist=[]
              for spec in prior_spec_data:
                  if spec['specimen_tilt_correction']==coord and spec['specimen_comp_name']==comp:speclist.append(spec)
              ofile=ofile_base+'_'+coord+'_'+comp+'.txt'
              pmag.magic_write(ofile,speclist,'pmag_specimens')
              print('coordinate system: ',coord,' component name: ',comp,' saved in ',ofile)