code: def main():
      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]
      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()
      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'
          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'])
      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)