<?xml version="1.0" encoding="ISO-8859-1"?>

<menu name="TOPAS_Durham_Menus">

<menu name="Help/General/Links">
	<item name="Durham Rietveld School Tutorials" type="macro">
			runInSystemShell(view, "start \"http:\\\\www.dur.ac.uk\\john.evans\\topas_workshop\\pcg_workshop_menu.htm\"&amp;");
		</item>
	<item name="Tutorials general - www" type="macro">
			runInSystemShell(view, "start \"http:\\\\www.dur.ac.uk\\john.evans\\topas_workshop\\tutorial_menu.htm\"&amp;");
		</item>
		<item name="Help - Topas Wiki" type="macro">
			runInSystemShell(view, "start \"http:\\\\topas.dur.ac.uk\\topaswiki\\doku.php\"&amp;");
		</item>
		<item name="Help - Technical Reference" type="macro">
			runInSystemShell(view, "start /D\""+ jEdit.getProperty("ta.main.dir") +"\" Technical_Reference.pdf&amp;");
			waitForConsole(view);
		</item>
		<item name="Help - Users Manual" type="macro">
			runInSystemShell(view, "start /D\""+ jEdit.getProperty("ta.main.dir") +"\" Users_Manual.pdf&amp;");
			waitForConsole(view);
		</item>
		<item name="Help - TOPAS Academic - www" type="macro">
			runInSystemShell(view, "start \"http:\\\\www.dur.ac.uk\\john.evans\\topas_academic\\topas_main.htm\"&amp;");
		</item>
		<item name="Local macros - local.inc" type="macro">jEdit.openFile(editPane.getView(), jEdit.getProperty("ta.main.dir") + "local.inc");</item>
		<item name="Alans macros - topas.inc" type="macro">jEdit.openFile(editPane.getView(), jEdit.getProperty("ta.main.dir") + "topas.inc");</item>
		<item name="Macro library - macros.inc" type="macro">
      runInSystemShell(view, "start \"http:\\\\www.dur.ac.uk\\john.evans\\topas_academic\\topas_macros.htm\"&amp;");
		</item>
		<item name="Log file - topas.log" type="macro">jEdit.openFile(editPane.getView(), jEdit.getProperty("ta.main.dir") + "topas.log");</item>
		<item name="Space Groups - www" type="macro">
			runInSystemShell(view, "start \"http:\\\\img.chem.ucl.ac.uk\\sgp\\mainmenu.htm\"&amp;");
		</item>

		<item name="Run TOPAS-Academic" type="macro">
			do_ta(v) {
				runInSystemShell(v, jEdit.getProperty("ta.main.dir"));
				waitForConsole(v);
				runInSystemShell(v, "ta&amp;");
			}
			do_ta(view);
		</item>
		
	<item name="Save this file and send to TA" type="macro">
		Buffer b = jEdit.openTemporary(view,null,jEdit.getProperty("ta.main.dir") + "launch_file.txt",false);
		try {
			if (buffer.isDirty()) {
				buffer.save(view,null,true);
			}
			if (b != null) {
				while(!b.isLoaded())	VFSManager.waitForRequests();
				b.remove(0,b.getLength());
				b.insert(0, '"'+buffer.getPath()+'"');
				b.save(view, b.getPath());
			}
		} finally {
			if(b != null) {
				//b.close();
			}
		}
	</item>
</menu>



	
   <menu name="Simple Rietveld Refinement">
		<item name="Select Data File" type="macro">
			TAnewINP(v)
			{
				String w_ext = jEdit.getProperty("ta.last_xdd_type");
				if (w_ext == null) w_ext = "*.raw";
				jEdit.setProperty("vfs.browser.last-filter", w_ext);
			
				String w_path = jEdit.getProperty("ta.last_new_inp_dir");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"test_examples\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
			
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {
					String w_dir = MiscUtilities.getParentOfPath(files[0]);
					String w_fn_no_ext = MiscUtilities.getFileNameNoExtension(files[0]);
					jEdit.setProperty("ta.last_new_inp_dir", w_dir);
					
					String w_path_inp = w_dir + w_fn_no_ext + "_riet_01.inp";
					b = jEdit.openFile(v, w_path_inp);
					if (b != null) {
			
		
					if (b.isNewFile()) {
							t = v.getTextArea();
							int i = 0;
							while(true) {
								t.goToEndOfLine(false);
								String w_path = MiscUtilities.getFileName(files[i]);
								if (w_path.indexOf(' ') != -1) {
									w_path = "\"" + w_path + "\"";
								}
								b.insert(t.getCaretPosition(), "'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Input File for simple Rietveld Refinement"); 
								b.insert(t.getCaretPosition(), "\n'Replace any $, # or text after ---> as needed"); 
								b.insert(t.getCaretPosition(), "\n'Use Ta-> button to save/send to topas; Ta button to launch topas; run in topas with red arrow"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\nr_wp 0 r_exp 0 r_p 0 r_wp_dash 0 r_p_dash 0 r_exp_dash 0 weighted_Durbin_Watson 0 gof 0"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'General information about refinement here\n'Remove commented lines as required"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\niters 100000"); 
								b.insert(t.getCaretPosition(), "\nchi2_convergence_criteria 0.001"); 
								b.insert(t.getCaretPosition(), "\n'do_errors"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Information on datafile etc here"); 
								b.insert(t.getCaretPosition(), "\n'Check that default weighting is appropriate for your data"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\nxdd " + w_path); 
								b.insert(t.getCaretPosition(), "\n\tx_calculation_step = Yobs_dx_at(Xo); convolution_step 4");
								b.insert(t.getCaretPosition(), "\n\tbkg @ 0 0 0 0 0 0"); 
								b.insert(t.getCaretPosition(), "\n\tSimple_Axial_Model(axial,10)"); 
			
								i++;
								if (i == files.length) break;
							}
							jEdit.setProperty("ta.last_xdd_type", "*" + MiscUtilities.getFileExtension(files[0]));
						} else {
							String wmes = "INP file " + w_path_inp + " already exists";
							Macros.message(v, wmes);
						}
					}
				}
			}
			TAnewINP(view);
		</item>

		<menu name="Instrument/Corrections">
			<item name="Durham_d5000_scint" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Bragg Brentano graphite diffracted beam monochromator Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 26.6)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Durham_d5000_solx" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Bragg Brentano Sol-X Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Durham_d6" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Ge(111) monochromator Capillary Braun PSD Cu Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d6b" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Ge(111) monochromator capillary Lynxeye Mo Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 12.46)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tla 1.0 lo 0.70930 lh 0.2695"); 
			</item>
			<item name="Durham_d8" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Ge(111) monochromator Vantec Cu Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d9" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Lynx Eye Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Synchrotron" type="xinsert_script">{%wavelength "Enter Wavelength:"}{@
			textArea.goToEndOfLine(false);
			}\n\tlam ymin_on_ymax 0.0001 la 1.0 lo {$$wavelength} lh 0.1\n\tLP_Factor( 90) 'change the LP correction  or lh value if required
			</item>
			<item name="Neutron CW" type="xinsert_script">{%wavelength "Enter Wavelength:"}{@
			textArea.goToEndOfLine(false);
			}\n\tlam ymin_on_ymax 0.0001 la 1.0 lo {$$wavelength} lh 0.5\n\tneutron_data\n\tLP_Factor( 90)
			</item>
         <menu name="Other lab diffractometer">
			<item name="Monochromator angle" type="xinsert_script">{%mono "Enter Monochromator angle (e.g. 26.6 graphite/Cu; 27.26 Ge/Cu; 0 for energy dispersive): "}{@
			textArea.goToEndOfLine(false);
			}\n\tLP_Factor(!th2_monochromator, {$$mono}) 
         </item>
         <item name="Emission profile(s)" type="macro">
			Macros.getMacro("TAInsertLAM").invoke(view);
         </item>
         </menu>
         
			<item name="Variable Slits used" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tVariable_Divergence_Intensity"); 
			</item>
			<item name="Refine zero point" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tZero_Error(zero,0)"); 
			</item>
			<item name="Refine sample height" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tSpecimen_Displacement(height,0)"); 
			</item>
		</menu>
		
		<menu name="Structure - cif">
				<item name="Read a CIF file" type="macro">
			do_cif(v) {
				t = v.getTextArea();
				b = t.getBuffer();

				t.goToEndOfLine(false);					
				b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
				b.insert(t.getCaretPosition(), "\n'Information on structure");
				b.insert(t.getCaretPosition(), "\n'Change recurring numbers in coordinates as required e.g. 0.3333 to =1/3;");
				b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 

				jEdit.setProperty("vfs.browser.last-filter", "*.cif");
				w_path = jEdit.getProperty("ta.last_cif_path");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"cif\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
				waitForConsole(v);								
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {					
					int i = 0;
					b.beginCompoundEdit();
					while(true) {
						runInSystemShell(v, jEdit.getProperty("ta.main.dir"));			
						waitForConsole(v);								
						runInSystemShell(v, "cif1 " + "\"" + files[i] + "\" cif1.tmp");
						waitForConsole(v);								
						t.goToEndOfLine(false);					
						b.insert(t.getCaretPosition(), "\n");
						b.insertFile(v, jEdit.getProperty("ta.main.dir") + "cif1.tmp");
						VFSManager.waitForRequests();
						i++;
						if (i == files.length) break;
						b.insert(t.getCaretPosition(), "\n");
					}
					b.endCompoundEdit();
					jEdit.setProperty("ta.last_cif_path", files[0]);
				}
				t.goToEndOfLine(false);
				b.insert(t.getCaretPosition(), "\n\t\tscale @ 0.0001"); 
				b.insert(t.getCaretPosition(), "\n\t\tr_bragg 0"); 
				b.insert(t.getCaretPosition(), "\n\t\tTCHZ_Peak_Type(pku, 0.00039,pkv, -0.00221,pkw, -0.00146,!pkz, 0.0000,pkx, 0.00957, pky, 0.0001)"); 
				b.insert(t.getCaretPosition(), "\n\t\tPhase_Density_g_on_cm3(0)"); 
			}
			do_cif(view);
			</item>

		</menu>
		
		<menu name="Structure - no cif">
		<item name="Structural Information" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Information on structure");
			buffer.insert(textArea.getCaretPosition(), "\n'Type in phase/space group/cell etc");
			buffer.insert(textArea.getCaretPosition(), "\n'Comment in/out sections as needed");
			buffer.insert(textArea.getCaretPosition(), "\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n\n\tstr"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tscale @ 0.0001"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tr_bragg 0"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tTCHZ_Peak_Type(pku, 0.00039,pkv, -0.00221,pkw, -0.00146,!pkz, 0.0000,pkx, 0.00957,!pky, 0.0000)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tSimple_Axial_Model(axial,10)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPhase_Density_g_on_cm3(0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\t'append_bond_lengths"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\t\t'consider_lattice_parameters"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\t'Out_FCF(" + buffer.getPath() + ".cif)"); 
		</item>
		<item name="Space group" type="xinsert_script">{%sgrp "Enter Space Group:"}{@	
			textArea.goToEndOfLine(false)
			}\n\t\tspace_group {$$sgrp}</item>		
		<item name="Phase Name" type="xinsert_script">{%phname "Enter Phase Name:"}{@
			textArea.goToEndOfLine(false)
			}\n\t\tphase_name {$$phname}</item>
		<menu name="Lattice parameters">
			<item name="Cubic" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tCubic(@ #)"); 
		</item>
			<item name="Tetragonal" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tTetragonal(@ #, @ #)"); 
		</item>
			<item name="Hexagonal" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tHexagonal(@ #, @ #)"); 
		</item>
			<item name="Rhombohedral" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tRhombohedral(@ #, @ #)"); 
		</item>
			<item name="Triclinic" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\ta @ #\n\t\tb @ #\n\t\tc @ #\n\t\tal @ #\n\t\tbe @ #\n\t\tga @ #"); 
		</item>
		</menu>

			<item name="site with beq" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tsite $site  x #  y #  z #  occ $atom # beq #"); 
		</item>
			<item name="site with adps" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tsite $site  x #  y #  z #  occ $atom # adps"); 
		</item>
		</menu>
		<item name="view structure" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tview_structure"); 
		</item>
		
		<menu name="Preferred orientation">
			<item name="PO-March Dollase - 1 Dir" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPreferred_Orientation(@, 1,, #h #k #l)"); 
		</item>
			<item name="PO-March Dollase - 2 Dirs" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPO_Two_Directions(@, 1,, 1 1 1,@, 1,, ,@, 0.5)"); 
		</item>
			<item name="PO_Spherical_Harmonics" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPO_Spherical_Harmonics(sh, 4)"); 
		</item>
		</menu>			
 </menu>
	   <menu name="Simple Pawley Refinement">
		<item name="Select Data File" type="macro">
			TAnewINP(v)
			{
				String w_ext = jEdit.getProperty("ta.last_xdd_type");
				if (w_ext == null) w_ext = "*.raw";
				jEdit.setProperty("vfs.browser.last-filter", w_ext);
			
				String w_path = jEdit.getProperty("ta.last_new_inp_dir");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"test_examples\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
			
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {
					String w_dir = MiscUtilities.getParentOfPath(files[0]);
					String w_fn_no_ext = MiscUtilities.getFileNameNoExtension(files[0]);
					jEdit.setProperty("ta.last_new_inp_dir", w_dir);
					
					String w_path_inp = w_dir + w_fn_no_ext + "_pawley_01.inp";
					b = jEdit.openFile(v, w_path_inp);
					if (b != null) {
						if (b.isNewFile()) {
							t = v.getTextArea();
							int i = 0;
							while(true) {
								t.goToEndOfLine(false);
								String w_path = MiscUtilities.getFileName(files[i]);
								if (w_path.indexOf(' ') != -1) {
									w_path = "\"" + w_path + "\"";
								}
								b.insert(t.getCaretPosition(), "'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Input File for simple Pawley Refinement"); 
								b.insert(t.getCaretPosition(), "\n'Replace any $, # or text after ---> as needed"); 
								b.insert(t.getCaretPosition(), "\n'Use Ta-> button to save/send to topas; Ta button to launch topas; run in topas with red arrow"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\nr_wp 0 r_exp 0 r_p 0 r_wp_dash 0 r_p_dash 0 r_exp_dash 0 weighted_Durbin_Watson 0 gof 0"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'General information about refinement here\n'Remove commented lines as required"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\niters 100000"); 
								b.insert(t.getCaretPosition(), "\nchi2_convergence_criteria 0.001"); 
								b.insert(t.getCaretPosition(), "\n'do_errors"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Information on datafile etc here"); 
								b.insert(t.getCaretPosition(), "\n'Check that default weighting is appropriate for your data"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\nxdd " + w_path); 
								b.insert(t.getCaretPosition(), "\n\tx_calculation_step = Yobs_dx_at(Xo); convolution_step 4");
								b.insert(t.getCaretPosition(), "\n\tbkg @ 0 0 0 0 0 0"); 
								b.insert(t.getCaretPosition(), "\n\tSimple_Axial_Model(axial,10)"); 
			
								i++;
								if (i == files.length) break;
							}
							jEdit.setProperty("ta.last_xdd_type", "*" + MiscUtilities.getFileExtension(files[0]));
						} else {
							String wmes = "INP file " + w_path_inp + " already exists";
							Macros.message(v, wmes);
						}
					}
				}
			}
			TAnewINP(view);
		</item>

		<menu name="Instrument/Corrections">
	<item name="Durham_d5000_scint" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Bragg Brentano graphite diffracted beam monochromator Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 26.6)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Durham_d5000_solx" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Bragg Brentano Sol-X Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Durham_d6" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Ge(111) monochromator Capillary Braun PSD Cu Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d6b" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Ge(111) monochromator capillary Lynxeye Mo Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 12.46)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tla 1.0 lo 0.70930 lh 0.2695"); 
			</item>
			<item name="Durham_d8" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Ge(111) monochromator Vantec Cu Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d9" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Lynx Eye Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Synchrotron" type="xinsert_script">{%wavelength "Enter Wavelength:"}{@
			textArea.goToEndOfLine(false);
			}\n\tlam ymin_on_ymax 0.0001 la 1.0 lo {$$wavelength} lh 0.1\n\tLP_Factor( 90) 'change the LP correction  or lh value if required
			</item>
			<item name="Neutron CW" type="xinsert_script">{%wavelength "Enter Wavelength:"}{@
			textArea.goToEndOfLine(false);
			}\n\tlam ymin_on_ymax 0.0001 la 1.0 lo {$$wavelength} lh 0.5 
			\tneutron_data
			\tLP_Factor( 90)
			</item>
         <menu name="Other lab diffractometer">
			<item name="Monochromator angle" type="xinsert_script">{%mono "Enter Monochromator angle (e.g. 26.6 graphite/Cu; 27.26 Ge/Cu; 0 for energy dispersive): "}{@
			textArea.goToEndOfLine(false);
			}\n\tLP_Factor(!th2_monochromator, {$$mono}) 
         </item>
         <item name="Emission profile(s)" type="macro">
			Macros.getMacro("TAInsertLAM").invoke(view);
         </item>
         </menu>
			<item name="Variable Slits used" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tVariable_Divergence_Intensity"); 
			</item>
			<item name="Refine zero point" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tZero_Error(zero,0)"); 
			</item>
			<item name="Refine sample height" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tSpecimen_Displacement(height,0)"); 
			</item>
		</menu>
		
		
		<menu name="Pawley fit phase">
		<item name="Structural Information" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\n\thkl_Is"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tTCHZ_Peak_Type(pku, 0.00039,pkv, -0.00221,pkw, -0.00146,!pkz, 0.0000,pkx, 0.00957,!pky, 0.0000)"); 
		</item>
		<item name="Phase Name" type="xinsert_script">{%phname "Enter Phase Name:"}{@
			textArea.goToEndOfLine(false)
			}\n\t\tphase_name {$$phname}</item>


		<menu name="Lattice parameters">
			<item name="Cubic" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tCubic(@ #)"); 
		</item>
			<item name="Tetragonal" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tTetragonal(@ #, @ #)"); 
		</item>
			<item name="Hexagonal" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tHexagonal(@ #, @ #)"); 
		</item>
			<item name="Rhombohedral" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tRhombohedral(@ #, @ #)"); 
		</item>
			<item name="Triclinic" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\ta @ #\n\t\tb @ #\n\t\tc @ #\n\t\tal @ #\n\t\tbe @ #\n\t\tga @ #"); 
		</item>
		</menu>
		
		<item name="Space group" type="xinsert_script">{%sgrp "Enter Space Group:"}{@	
			textArea.goToEndOfLine(false)
			}\n\t\tspace_group {$$sgrp}</item>		
 		</menu>
</menu>
 
   <menu name="Simple tof Rietveld">
		<item name="Select Data File" type="macro">
			TAnewINP(v)
			{
				String w_ext = jEdit.getProperty("ta.last_xdd_type");
				if (w_ext == null) w_ext = "*.raw";
				jEdit.setProperty("vfs.browser.last-filter", w_ext);
			
				String w_path = jEdit.getProperty("ta.last_new_inp_dir");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"test_examples\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
			
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {
					String w_dir = MiscUtilities.getParentOfPath(files[0]);
					String w_fn_no_ext = MiscUtilities.getFileNameNoExtension(files[0]);
					jEdit.setProperty("ta.last_new_inp_dir", w_dir);
					
					String w_path_inp = w_dir + w_fn_no_ext + "_riet_01.inp";
					b = jEdit.openFile(v, w_path_inp);
					if (b != null) {
						if (b.isNewFile()) {
							t = v.getTextArea();
							int i = 0;
							while(true) {
								t.goToEndOfLine(false);
								String w_path = MiscUtilities.getFileName(files[i]);
								if (w_path.indexOf(' ') != -1) {
									w_path = "\"" + w_path + "\"";
								}
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Input File for simple tof Rietveld Refinement"); 
								b.insert(t.getCaretPosition(), "\n'Use Ta-> button to save/send to topas; Ta button to launch topas; run in topas with red arrow"); 
								b.insert(t.getCaretPosition(), "\n'Replace $ and # symbols with text/numbers as needed"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n\nr_wp 0 r_exp 0 r_p 0 r_wp_dash 0 r_p_dash 0 r_exp_dash 0 weighted_Durbin_Watson 0 gof 0"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'General information about refinement here\n'Remove comments as required"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n\niters 100000"); 
								b.insert(t.getCaretPosition(), "\nchi2_convergence_criteria 0.001"); 
								b.insert(t.getCaretPosition(), "\n'do_errors"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Information on datafile etc here"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\nTOF_XYE( " + w_path + ", 3)"); 
								b.insert(t.getCaretPosition(), "\n\tx_calculation_step = Yobs_dx_at(Xo);  convolution_step 4");
								b.insert(t.getCaretPosition(), "\n\tTOF_LAM(0.001)"); 
								b.insert(t.getCaretPosition(), "\n\tscale_pks = D_spacing^4;"); 
								b.insert(t.getCaretPosition(), "\n\tbkg @ 0 0 0 0 0 0"); 
								b.insert(t.getCaretPosition(), "\n\tstart_X ->#"); 
								b.insert(t.getCaretPosition(), "\n\tfinish_X ->#"); 
								b.insert(t.getCaretPosition(), "\n"); 
								b.insert(t.getCaretPosition(), "\n\tbkg @ 0 0 0 0 0 0"); 
			
								i++;
								if (i == files.length) break;
							}
							jEdit.setProperty("ta.last_xdd_type", "*" + MiscUtilities.getFileExtension(files[0]));
						} else {
							String wmes = "INP file " + w_path_inp + " already exists";
							Macros.message(v, wmes);
						}
					}
				}
			}
			TAnewINP(view);
		</item>

		
			<!--
		<item name="xye File" type="xinsert_script">{%xyefile "Enter xye file name with extension, calculation step (e.g. zx0002.xye,5): "}{@
			textArea.goToEndOfLine(false)
			}\nTOF_XYE({$$xyefile})
\tbkg @ 0 0 0 0 0 0
\tstart_X 40000
\tfinish_X 120000
\tscale_pks = D_spacing^4;</item>
-->
		<menu name="Instrument/Corrections">
			<item name="hrpd_bs" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Change instrument/peak shape constants from a recent silicon calibration");
			buffer.insert(textArea.getCaretPosition(), "\n'Only refine these parameters if you're sure what you're doing"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Peak shape macro courtesy of Bill David"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Get macros you need from http://www.dur.ac.uk/john.evans/topas_academic/topas_macros.htm"); 
			buffer.insert(textArea.getCaretPosition(), "\n'or use the alternate peak shape description currently commented out"); 
			buffer.insert(textArea.getCaretPosition(), "\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tTOF_LAM(0.001)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tTOF_x_axis_calibration(!t0_bs,   0.27394, !difc_bs, 48213.48769, !difa_bs, -5.50739)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\twifd_pkshape(!two_theta, 168.657, !aprm, 2.50000, !tauf_2, 9.80744, !tauf_1, 0.43977, !tauf_0, 0.000, !taus_0, 25.27420, !taus_1, 2.66797, !t_eff, 144.41296, !hhh, 3.58595, !hhh_0, 11.61348)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t'TOF_Exponential(!a1_bs, 230.98670,!a2_bs, 27.018, 4, difc_hrpd_bs, +)"); 
			</item>
			<item name="hrpd_90" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Change instrument/peak shape constants from a recent silicon calibration");
			buffer.insert(textArea.getCaretPosition(), "\n'Only refine these parameters if you're sure what you're doing"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Peak shape macro courtesy of Bill David"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Get macros you need from http://www.dur.ac.uk/john.evans/topas_academic/topas_macros.htm"); 
			buffer.insert(textArea.getCaretPosition(), "\n'or use the alternate peak shape description currently commented out"); 
			buffer.insert(textArea.getCaretPosition(), "\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tTOF_LAM(0.001)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tTOF_x_axis_calibration(!t0_90,   7.60, !difc_90, 34729.97, !difa_90, 0.296)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\twifd_pkshape(!two_theta, 90.2481, !aprm, 2.50000, !tauf_2, 9.80744, !tauf_1, 0.43977, !tauf_0, 0.000, !taus_0, 25.27420, !taus_1, 2.66797, !t_eff, 144.41296, !hhh, 3.58595, !hhh_0, 11.61348)"); 
			</item>
			<item name="hrpd_30" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Change instrument/peak shape constants from a recent silicon calibration");
			buffer.insert(textArea.getCaretPosition(), "\n'Only refine these parameters if you're sure what you're doing"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Peak shape macro courtesy of Bill David"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Get macros you need from http://www.dur.ac.uk/john.evans/topas_academic/topas_macros.htm"); 
			buffer.insert(textArea.getCaretPosition(), "\n'or use the alternate peak shape description currently commented out"); 
			buffer.insert(textArea.getCaretPosition(), "\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tTOF_LAM(0.001)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tTOF_x_axis_calibration(!t0_30,   12.09, !difc_30, 12897.29, !difa_30, 1.44)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\twifd_pkshape(!two_theta, 29.93, !aprm, 2.50000, !tauf_2, 9.80744, !tauf_1, 0.43977, !tauf_0, 0.000, !taus_0, 25.27420, !taus_1, 2.66797, !t_eff, 144.41296, !hhh, 3.58595, !hhh_0, 11.61348)"); 
			</item>
		</menu>
		
		<menu name="Structure - cif">
				<item name="Read a .CIF file" type="macro">
				do_cif(v) {
				t = v.getTextArea();
				b = t.getBuffer();
				b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
				b.insert(t.getCaretPosition(), "\n'Information on structure");
				b.insert(t.getCaretPosition(), "\n'Type in phase/space group/cell etc");
				b.insert(t.getCaretPosition(), "\n'Comment in/out sections as needed");
				b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
				jEdit.setProperty("vfs.browser.last-filter", "*.cif");
				w_path = jEdit.getProperty("ta.last_cif_path");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"cif\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {					
					int i = 0;
					b.beginCompoundEdit();
					while(true) {
						runInSystemShell(v, jEdit.getProperty("ta.main.dir"));			
						waitForConsole(v);								
						runInSystemShell(v, "cif1 " + "\"" + files[i] + "\" cif1.tmp");
						waitForConsole(v);								
						t.goToEndOfLine(false);					
						b.insert(t.getCaretPosition(), "\n");
						b.insertFile(v, jEdit.getProperty("ta.main.dir") + "cif1.tmp");
						VFSManager.waitForRequests();
						i++;
						if (i == files.length) break;
						b.insert(t.getCaretPosition(), "\n");
					}
					b.endCompoundEdit();
					jEdit.setProperty("ta.last_cif_path", files[0]);
				}
				t.goToEndOfLine(false);
				b.insert(t.getCaretPosition(), "\n\t\tscale @ 0.0001"); 
				b.insert(t.getCaretPosition(), "\n\t\tr_bragg 0"); 
				b.insert(t.getCaretPosition(), "\n\t\ttof_sample_peakshape(lor,0.2,dsp,30,dspsq,1)"); 
				b.insert(t.getCaretPosition(), "\n\t\tPhase_Density_g_on_cm3(0)"); 
			}
			do_cif(view);
			</item>

		</menu>

		<item name="view structure" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tview_structure"); 
		</item>
		
		<menu name="Preferred orientation">
			<item name="PO-March Dollase - 1 Dir" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPreferred_Orientation(@, 1,, #h #k #l)"); 
		</item>
			<item name="PO-March Dollase - 2 Dirs" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPO_Two_Directions(@, 1,, 1 1 1,@, 1,, ,@, 0.5)"); 
		</item>
			<item name="PO_Spherical_Harmonics" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPO_Spherical_Harmonics(sh, 4)"); 
		</item>
		</menu>			
   </menu>		



   
   <menu name="Peak Fitting">
		<item name="Select Data File" type="macro">
			TAnewINP(v)
			{
				String w_ext = jEdit.getProperty("ta.last_xdd_type");
				if (w_ext == null) w_ext = "*.raw";
				jEdit.setProperty("vfs.browser.last-filter", w_ext);
			
				String w_path = jEdit.getProperty("ta.last_new_inp_dir");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"test_examples\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
			
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {
					String w_dir = MiscUtilities.getParentOfPath(files[0]);
					String w_fn_no_ext = MiscUtilities.getFileNameNoExtension(files[0]);
					jEdit.setProperty("ta.last_new_inp_dir", w_dir);
					
					String w_path_inp = w_dir + w_fn_no_ext + "_pkfit_01.inp";
					b = jEdit.openFile(v, w_path_inp);
					if (b != null) {
						if (b.isNewFile()) {
							t = v.getTextArea();
							int i = 0;
							while(true) {
								t.goToEndOfLine(false);
								String w_path = MiscUtilities.getFileName(files[i]);
								if (w_path.indexOf(' ') != -1) {
									w_path = "\"" + w_path + "\"";
								}
								b.insert(t.getCaretPosition(), "'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Input File for Peak Fitting with overall TCHz peak shape"); 
								b.insert(t.getCaretPosition(), "\n'To find peaks load experimental data into topas"); 
								b.insert(t.getCaretPosition(), "\n'Use View/search peaks then insert peaks"); 
								b.insert(t.getCaretPosition(), "\n'Click on plus sign by file name"); 
								b.insert(t.getCaretPosition(), "\n'Click on peaks phase"); 
								b.insert(t.getCaretPosition(), "\n'Highlight Position and Area columns, right click to copy then paste below"); 
								b.insert(t.getCaretPosition(), "\n'Use Ta-> button to save/send to topas; Ta button to launch topas; run in topas with red arrow"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\nr_wp 0 r_exp 0 r_p 0 r_wp_dash 0 r_p_dash 0 r_exp_dash 0 weighted_Durbin_Watson 0 gof 0"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'General information about refinement here\n'Remove comments as required"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\niters 100000"); 
								b.insert(t.getCaretPosition(), "\nchi2_convergence_criteria 0.001"); 
								b.insert(t.getCaretPosition(), "\n'do_errors"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Information on datafile etc here"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\nxdd " + w_path); 
								b.insert(t.getCaretPosition(), "\n\tx_calculation_step = Yobs_dx_at(Xo);  convolution_step 4");
								i++;
								if (i == files.length) break;
							}
							jEdit.setProperty("ta.last_xdd_type", "*" + MiscUtilities.getFileExtension(files[0]));
						} else {
							String wmes = "INP file " + w_path_inp + " already exists";
							Macros.message(v, wmes);
						}
					}
				}
			}
			TAnewINP(view);
		</item>

				<menu name="Instrument/Corrections">
	<item name="Durham_d5000_scint" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Bragg Brentano graphite diffracted beam monochromator Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 26.6)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Durham_d5000_solx" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Bragg Brentano Sol-X Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Durham_d6" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Ge(111) monochromator Capillary Braun PSD Cu Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d6b" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Ge(111) monochromator capillary Lynxeye Mo Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 12.46)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tla 1.0 lo 0.70930 lh 0.2695"); 
			</item>
			<item name="Durham_d8" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Ge(111) monochromator Vantec Cu Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d9" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Lynx Eye Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Synchrotron" type="xinsert_script">{%wavelength "Enter Wavelength:"}{@
			textArea.goToEndOfLine(false);
			}\n\tlam ymin_on_ymax 0.0001 la 1.0 lo {$$wavelength} lh 0.1\n\tLP_Factor( 90) 'change the LP correction  or lh value if required
			</item>
			<item name="Neutron CW" type="xinsert_script">{%wavelength "Enter Wavelength:"}{@
			textArea.goToEndOfLine(false);
			}\n\tlam ymin_on_ymax 0.0001 la 1.0 lo {$$wavelength} lh 0.5 
			</item>
         <menu name="Other lab diffractometer">
			<item name="Monochromator angle" type="xinsert_script">{%mono "Enter Monochromator angle (e.g. 26.6 graphite/Cu; 27.26 Ge/Cu; 0 for energy dispersive): "}{@
			textArea.goToEndOfLine(false);
			}\n\tLP_Factor(!th2_monochromator, {$$mono}) 
         </item>
         <item name="Emission profile(s)" type="macro">
			Macros.getMacro("TAInsertLAM").invoke(view);
         </item>
         </menu>
		</menu>
		
		<item name="Peak Information" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tSimple_Axial_Model(axial,10)");
			buffer.insert(textArea.getCaretPosition(), "\n\tbkg @ 0 0 0 0 0 0");
			buffer.insert(textArea.getCaretPosition(), "\n\n\txo_Is");
			buffer.insert(textArea.getCaretPosition(), "\n\tTCHZ_Peak_Type(pku, 0.00039,pkv, -0.00221,pkw, -0.00146,!pkz, 0.0000,pkx, 0.00957,!pky, 0.0000)");
			buffer.insert(textArea.getCaretPosition(), "\n\tload xo I {");
			buffer.insert(textArea.getCaretPosition(), "\n'copy peak position and intensity here");
			buffer.insert(textArea.getCaretPosition(), "\n'insert @'s before 2th and area to refine");
			buffer.insert(textArea.getCaretPosition(), "\n");
			buffer.insert(textArea.getCaretPosition(), "\n\t}");
			buffer.insert(textArea.getCaretPosition(), "\n"); 
		</item>
	
	</menu>	

   <menu name="Indexing">
	<item name="Create Indexing File" type="macro">
			textArea.goToBufferStart(false);
			buffer.insert(textArea.getCaretPosition(), "'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Input File for Indexing powder data"); 
			buffer.insert(textArea.getCaretPosition(), "\n\n'Paste 2theta/Area values from peak fitting"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Comment out header line and any peaks you don't want to include"); 
			buffer.insert(textArea.getCaretPosition(), "\n'e.g. exclude high angle and weak/broad peaks"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Change wavelength as needed"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Comment out any crystal systems not to be checked"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Load filename.ndx after running"); 
			buffer.insert(textArea.getCaretPosition(), "\n\n'Use Ta-> button to save/send to topas; Ta button to launch topas; run in topas with red arrow"); 

			buffer.insert(textArea.getCaretPosition(), "\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\nseed             "); 
			buffer.insert(textArea.getCaretPosition(), "\nindex_zero_error "); 
			buffer.insert(textArea.getCaretPosition(), "\nindex_lam  1.5406"); 
			buffer.insert(textArea.getCaretPosition(), "\nindex_min_lp 1   "); 
			buffer.insert(textArea.getCaretPosition(), "\nindex_max_lp 40  "); 
			buffer.insert(textArea.getCaretPosition(), "\n"); 

			buffer.insert(textArea.getCaretPosition(), "\nBravais_Cubic_sgs              "); 
			buffer.insert(textArea.getCaretPosition(), "\nBravais_Trigonal_Hexagonal_sgs "); 
			buffer.insert(textArea.getCaretPosition(), "\nBravais_Tetragonal_sgs         "); 
			buffer.insert(textArea.getCaretPosition(), "\nBravais_Orthorhombic_sgs       "); 
			buffer.insert(textArea.getCaretPosition(), "\nBravais_Monoclinic_sgs         "); 
			buffer.insert(textArea.getCaretPosition(), "\nBravais_Triclinic_sgs          "); 
			buffer.insert(textArea.getCaretPosition(), "\n"); 
			buffer.insert(textArea.getCaretPosition(), "\nload index_th2 index_I {"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Paste position and area values below here"); 
			buffer.insert(textArea.getCaretPosition(), "\n"); 
			buffer.insert(textArea.getCaretPosition(), "\n"); 
			buffer.insert(textArea.getCaretPosition(), "\n}"); 
	</item>
	</menu>





	
	
   <menu name="Single Crystal Refinement">
		<item name="Select hkl Data File" type="macro">
			TAnewINP(v)
			{
				String w_ext = jEdit.getProperty("ta.last_xdd_type");
				if (w_ext == null) w_ext = "*.raw";
				jEdit.setProperty("vfs.browser.last-filter", w_ext);
			
				String w_path = jEdit.getProperty("ta.last_new_inp_dir");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"test_examples\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
			
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {
					String w_dir = MiscUtilities.getParentOfPath(files[0]);
					String w_fn_no_ext = MiscUtilities.getFileNameNoExtension(files[0]);
					jEdit.setProperty("ta.last_new_inp_dir", w_dir);
					
					String w_path_inp = w_dir + w_fn_no_ext + "_xtal_01.inp";
					b = jEdit.openFile(v, w_path_inp);
					if (b != null) {
						if (b.isNewFile()) {
							t = v.getTextArea();
							int i = 0;
							while(true) {
								t.goToEndOfLine(false);
								String w_path = MiscUtilities.getFileName(files[i]);
								if (w_path.indexOf(' ') != -1) {
									w_path = "\"" + w_path + "\"";
								}
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Input File for simple single crystal refinement"); 
								b.insert(t.getCaretPosition(), "\n'Use Ta-> button to save/send to topas; Ta button to launch topas; run in topas with red arrow"); 
								b.insert(t.getCaretPosition(), "\n'Replace $ and # symbols with text/numbers as needed"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n\nr_wp 0 "); 
								b.insert(t.getCaretPosition(), "\nr_p  0 ");								
								b.insert(t.getCaretPosition(), "\ngof  0 "); 	
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'General information about refinement here\n'Remove comments as required"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n\niters 100000"); 
								b.insert(t.getCaretPosition(), "\nchi2_convergence_criteria 0.001"); 
								b.insert(t.getCaretPosition(), "\n'do_errors"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Information on datafile etc here"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\nxdd_scr " + w_path ); 
								b.insert(t.getCaretPosition(), "\n\tweighting = If(Yobs&lt;1,1,(1/Yobs));");								b.insert(t.getCaretPosition(), "\n\tfinish_X 180"); 
								b.insert(t.getCaretPosition(), "\n\tfinish_X 180"); 
								b.insert(t.getCaretPosition(), "\n"); 
			
								i++;
								if (i == files.length) break;
							}
							jEdit.setProperty("ta.last_xdd_type", "*" + MiscUtilities.getFileExtension(files[0]));
						} else {
							String wmes = "INP file " + w_path_inp + " already exists";
							Macros.message(v, wmes);
						}
					}
				}
			}
			TAnewINP(view);
		</item>
	

		
			<!--
		<item name="xye File" type="xinsert_script">{%xyefile "Enter xye file name with extension, calculation step (e.g. zx0002.xye,5): "}{@
			textArea.goToEndOfLine(false)
			}\nTOF_XYE({$$xyefile})
\tbkg @ 0 0 0 0 0 0
\tstart_X 40000
\tfinish_X 120000
\tscale_pks = D_spacing^4;</item>
-->
		<menu name="Instrument/Wavelength">
			<item name="Molybdenum Radiation" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\tlam  la 1 lo 0.71073 lh 0.5 ymin_on_ymax 0.0001"); 
			</item>
			<item name="Copper Radiation" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\tlam  la 1 lo 1.5406 lh 0.5 ymin_on_ymax 0.0001"); 
			</item>
		</menu>
		
		<menu name="Structure - cif">
				<item name="Read a .CIF file" type="macro">
				do_cif(v) {
				t = v.getTextArea();
				b = t.getBuffer();
				b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
				b.insert(t.getCaretPosition(), "\n'Information on structure");
				b.insert(t.getCaretPosition(), "\n'Type in phase/space group/cell etc");
				b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
				jEdit.setProperty("vfs.browser.last-filter", "*.cif");
				w_path = jEdit.getProperty("ta.last_cif_path");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"cif\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {					
					int i = 0;
					b.beginCompoundEdit();
					while(true) {
						runInSystemShell(v, jEdit.getProperty("ta.main.dir"));			
						waitForConsole(v);								
						runInSystemShell(v, "cif1 " + "\"" + files[i] + "\" cif1.tmp");
						waitForConsole(v);								
						t.goToEndOfLine(false);					
						b.insert(t.getCaretPosition(), "\n");
						b.insertFile(v, jEdit.getProperty("ta.main.dir") + "cif1.tmp");
						VFSManager.waitForRequests();
						i++;
						if (i == files.length) break;
						b.insert(t.getCaretPosition(), "\n");
					}
					b.endCompoundEdit();
					jEdit.setProperty("ta.last_cif_path", files[0]);
				}
				t.goToEndOfLine(false);
				b.insert(t.getCaretPosition(), "\n\t\tscale @ 0.0001"); 
				b.insert(t.getCaretPosition(), "\n\t\tr_bragg 0"); 
				b.insert(t.getCaretPosition(), "\n\t\tPhase_Density_g_on_cm3(0)"); 
			}
			do_cif(view);
			</item>
			</menu>
		<menu name="Structure - no cif">
		<item name="Structural Information" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Information on structure");
			buffer.insert(textArea.getCaretPosition(), "\n'Type in phase/space group/cell etc");
			buffer.insert(textArea.getCaretPosition(), "\n'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n\n\tstr"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tscale @ 0.0001"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPhase_Density_g_on_cm3(0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\t'append_bond_lengths"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\t'Out_FCF(" + buffer.getPath() + ".cif)"); 
		</item>
		<item name="Space group" type="xinsert_script">{%sgrp "Enter Space Group:"}{@	
			textArea.goToEndOfLine(false)
			}\n\t\tspace_group {$$sgrp}</item>		
		<item name="Phase Name" type="xinsert_script">{%phname "Enter Phase Name:"}{@
			textArea.goToEndOfLine(false)
			}\n\t\tphase_name {$$phname}</item>
		<menu name="Lattice parameters">
			<item name="Cubic" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tCubic(@ #)"); 
		</item>
			<item name="Tetragonal" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tTetragonal(@ #, @ #)"); 
		</item>
			<item name="Hexagonal" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tHexagonal(@ #, @ #)"); 
		</item>
			<item name="Rhombohedral" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tRhombohedral(@ #, @ #)"); 
		</item>
			<item name="Triclinic" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\ta @ #\n\t\tb @ #\n\t\tc @ #\n\t\tal @ #\n\t\tbe @ #\n\t\tga @ #"); 
		</item>
		</menu>

			<item name="site with beq" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tsite $site  x #  y #  z #  occ $atom # beq #"); 
		</item>
			<item name="site with adps" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\ttweightingsite $site  x #  y #  z #  occ $atom # adps"); 
		</item>
		</menu>

		<item name="view structure" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tview_structure"); 
		</item>
	
	
   </menu>	
   	
   <menu name="Symmetry Mode Rietveld Refinement">
	<menu name="ISODISTORT Help">
		<item name="General Help" type="xinsert_script">
		{%dummy "Symmetry mode refinements use the matrices produced by ISODISTORT (Campbell et al J. Appl. Cryst., 2006, 39, 607). Go to the isodistort web page for more info. Hit ok to cancel this window!"}
		</item>
		<item name="ISODISTORT www and help" type="macro">
			runInSystemShell(view, "start \"http:\\\\stokes.byu.edu\\isodistort.html\"&amp;");
		</item>
		<item name="ISODISTORT tutorial example" type="macro">
			runInSystemShell(view, "start \"http:\\\\www.dur.ac.uk\\john.evans\\topas_workshop\\tutorial_isoriet.htm\"&amp;");
		</item>
	</menu>
		<item name="Select Data File" type="macro">
			TAnewINP(v)
			{
				String w_ext = jEdit.getProperty("ta.last_xdd_type");
				if (w_ext == null) w_ext = "*.raw";
				jEdit.setProperty("vfs.browser.last-filter", w_ext);
			
				String w_path = jEdit.getProperty("ta.last_new_inp_dir");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"test_examples\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
			
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {
					String w_dir = MiscUtilities.getParentOfPath(files[0]);
					String w_fn_no_ext = MiscUtilities.getFileNameNoExtension(files[0]);
					jEdit.setProperty("ta.last_new_inp_dir", w_dir);
					
					String w_path_inp = w_dir + w_fn_no_ext + "_riet_01.inp";
					b = jEdit.openFile(v, w_path_inp);
					if (b != null) {
						if (b.isNewFile()) {
							t = v.getTextArea();
							int i = 0;
							while(true) {
								t.goToEndOfLine(false);
								String w_path = MiscUtilities.getFileName(files[i]);
								if (w_path.indexOf(' ') != -1) {
									w_path = "\"" + w_path + "\"";
								}
								b.insert(t.getCaretPosition(), "'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Input File for Isodistort Distortion Mode Rietveld Refinement"); 
								b.insert(t.getCaretPosition(), "\n'Use isodistort to produce _distortion.str files"); 
								b.insert(t.getCaretPosition(), "\n'These are automatically read into topas via jedit menus"); 
								b.insert(t.getCaretPosition(), "\n'Modes 1-3 will produce matrices to convert high to low symmetry structures"); 
								b.insert(t.getCaretPosition(), "\n'Mode 4 will produce mode amplitudes from two cif files"); 
								b.insert(t.getCaretPosition(), "\n'Refine on distortion mode amplitudes instead of fractional coordinates"); 
								b.insert(t.getCaretPosition(), "\n'Values of an are summed rms displacements of atom in superstructure"); 
								b.insert(t.getCaretPosition(), "\n'http://stokes.byu.edu/isodistort.html"); 
   							b.insert(t.getCaretPosition(), "\n'http://iucrcomputing.ccp14.ac.uk/iucr-top/comm/ccom/newsletters/2007nov/");                        
								b.insert(t.getCaretPosition(), "\n'Branton J. Campbell, Harold T. Stokes, David E. Tanner, Dorian M. Hatch, J. Appl. Cryst., 2006, 39, 607-614"); 
								b.insert(t.getCaretPosition(), "\n'UUse Ta-> button to save/send to topas; Ta button to launch topas; run in topas with red arrow"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\nr_wp 0 r_exp 0 r_p 0 r_wp_dash 0 r_p_dash 0 r_exp_dash 0 weighted_Durbin_Watson 0 gof 0"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'General information about refinement here\n'Remove comments as required"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\niters 100000"); 
								b.insert(t.getCaretPosition(), "\nchi2_convergence_criteria 0.001"); 
								b.insert(t.getCaretPosition(), "\n'randomize_on_errors"); 
								b.insert(t.getCaretPosition(), "\n'continue_after_convergence"); 
								b.insert(t.getCaretPosition(), "\n'do_errors"); 
								b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Information on datafile etc here"); 
								b.insert(t.getCaretPosition(), "\n'Check that default weighting is appropriate for your data"); 
								b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\nxdd " + w_path); 
								b.insert(t.getCaretPosition(), "\n\tx_calculation_step = Yobs_dx_at(Xo); convolution_step 4");
								b.insert(t.getCaretPosition(), "\n\tbkg @ 0 0 0 0 0 0"); 
								b.insert(textArea.getCaretPosition(), "\n\t\tSimple_Axial_Model(axial,10)"); 
			
								i++;
								if (i == files.length) break;
							}
							jEdit.setProperty("ta.last_xdd_type", "*" + MiscUtilities.getFileExtension(files[0]));
						} else {
							String wmes = "INP file " + w_path_inp + " already exists";
							Macros.message(v, wmes);
						}
					}
				}
			}
			TAnewINP(view);
		</item>

		<menu name="Instrument/Corrections">
			<item name="Durham_d5000_scint" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Bragg Brentano graphite diffracted beam monochromator Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 26.6)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Durham_d5000_solx" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Bragg Brentano Sol-X Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Durham_d6" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd5000 Ge(111) monochromator Capillary Braun PSD Cu Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d6b" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Ge(111) monochromator capillary Lynxeye Mo Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 12.46)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tla 1.0 lo 0.70930 lh 0.2695"); 
			</item>
			<item name="Durham_d8" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Ge(111) monochromator Vantec Cu Ka1"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d9" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t'd8 Lynx Eye Cu Ka1/a2 2 line emission"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2_analyt(0.0001)"); 
			</item>
			<item name="Synchrotron" type="xinsert_script">{%wavelength "Enter Wavelength:"}{@
			textArea.goToEndOfLine(false);
			}\n\tlam ymin_on_ymax 0.0001 la 1.0 lo {$$wavelength} lh 0.1\n\tLP_Factor( 90) 'change the LP correction  or lh value if required
			</item>
			<item name="Neutron CW" type="xinsert_script">{%wavelength "Enter Wavelength:"}{@
			textArea.goToEndOfLine(false);
			}\n\tlam ymin_on_ymax 0.0001 la 1.0 lo {$$wavelength} lh 0.5\n\tneutron_data\n\tLP_Factor( 90)
			</item>
         <menu name="Other lab diffractometer">
			<item name="Monochromator angle" type="xinsert_script">{%mono "Enter Monochromator angle (e.g. 26.6 graphite/Cu; 27.26 Ge/Cu; 0 for energy dispersive): "}{@
			textArea.goToEndOfLine(false);
			}\n\tLP_Factor(!th2_monochromator, {$$mono}) 
         </item>
         <item name="Emission profile(s)" type="macro">
			Macros.getMacro("TAInsertLAM").invoke(view);
         </item>
         </menu>
         
			<item name="Variable Slits used" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tVariable_Divergence_Intensity"); 
			</item>
			<item name="Refine zero point" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tZero_Error(zero,0)"); 
			</item>
			<item name="Refine sample height" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tSpecimen_Displacement(height,0)"); 
			</item>
		</menu>

		<menu name="Read coordinates">
		<item name="Read ISODISTORT str" type="macro">
			Macros.getMacro("TAInsertSTR").invoke(view);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tscale @ 0.0001"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tr_bragg 0"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tTCHZ_Peak_Type(pku, 0.00039,pkv, -0.00221,pkw, -0.00146,!pkz, 0.0000,pkx, 0.00957,!pky, 0.0000)");
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPhase_Density_g_on_cm3(0)"); 
		</item>		

		<item name="Read ISODISTORT cif" type="macro">
			do_cif(v) {
				t = v.getTextArea();
				b = t.getBuffer();

				t.goToEndOfLine(false);					
				b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
				b.insert(t.getCaretPosition(), "\n'str file as generated by isotropy and isocif2topas.exe");
				b.insert(t.getCaretPosition(), "\n'refine coordinates using mode amplitudes a1....an");
				b.insert(t.getCaretPosition(), "\n'refine occupancies using mode amplitudes b1....bn");
				b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 

				jEdit.setProperty("vfs.browser.last-filter", "*.cif");
				w_path = jEdit.getProperty("ta.last_cif_path");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"cif\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
				waitForConsole(v);								
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {					
					int i = 0;
					b.beginCompoundEdit();
					while(true) {
						runInSystemShell(v, jEdit.getProperty("ta.main.dir"));			
						waitForConsole(v);								
						runInSystemShell(v, "isocif2topas " + "\"" + files[i] + "\" > isocif2topas.str");
						waitForConsole(v);								
						t.goToEndOfLine(false);					
						b.insert(t.getCaretPosition(), "\n");
						b.insertFile(v, jEdit.getProperty("ta.main.dir") + "isocif2topas.str");
						runInSystemShell(v, "del  isocif2topas.str");
						waitForConsole(v);								
						runInSystemShell(v, "del  cifscratch.dat");
						waitForConsole(v);								
						runInSystemShell(v, "del  ciftbx_error.dat");
						waitForConsole(v);								
						VFSManager.waitForRequests();
						i++;
						if (i == files.length) break;
						b.insert(t.getCaretPosition(), "\n");
					}
					b.endCompoundEdit();
					jEdit.setProperty("ta.last_cif_path", files[0]);
				}
				t.goToEndOfLine(false);
				b.insert(t.getCaretPosition(), "\n\t\tscale @ 0.0001"); 
				b.insert(t.getCaretPosition(), "\n\t\tr_bragg 0"); 
				b.insert(t.getCaretPosition(), "\n\t\tTCHZ_Peak_Type(pku, 0.00039,pkv, -0.00221,pkw, -0.00146,!pkz, 0.0000,pkx, 0.00957,!pky, 0.0000)"); 
				b.insert(t.getCaretPosition(), "\n\t\tPhase_Density_g_on_cm3(0)"); 
			}
			do_cif(view);		
			</item>	
		</menu>
		
		<item name="view structure" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tview_structure"); 
		</item>
		
		<menu name="Preferred orientation">
			<item name="PO-March Dollase - 1 Dir" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPreferred_Orientation(@, 1,, #h #k #l)"); 
		</item>
			<item name="PO-March Dollase - 2 Dirs" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPO_Two_Directions(@, 1,, 1 1 1,@, 1,, ,@, 0.5)"); 
		</item>
			<item name="PO_Spherical_Harmonics" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\t\tPO_Spherical_Harmonics(sh, 4)"); 
		</item>
		</menu>			
 </menu>

	
	
   <menu name="Miscellaneous Useful Commands">
		<item name="Change wavelength" type="xinsert_script">{%wavelength "Enter Wavelength:"}{@	
			textArea.goToEndOfLine(false)
			}\n\tlam ymin_on_ymax 0.0001 la 1.0 lo {$$wavelength} lh 0.5 </item>		
		<item name="start_X" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tstart_X #"); 
		</item>
		<item name="finish_X" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tfinish_X #"); 
		</item>
		<item name="Cu Kb and W La contamination" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n'Approximate method - better to add second phase"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tla @ 0.0010 lo 1.39222   lh 0.5      'CU KB"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tla @ 0.0010 lo 1.47639   lh 0.5      'W LA"); 
		</item>
		<item name="calculate bond distances" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tappend_bond_lengths min_r 0 max_r 3.5"); 
		</item>
		<item name="restrain distances" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tDistance_Restrain($site1 $site2, #ideal_dist, 0.000, #tolerance, #weight)"); 
		</item>
		<item name="calculate errors" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tdo_errors"); 
		</item>
		<item name="Phase Name" type="xinsert_script">{%phname "Enter Phase Name:"}{@
			textArea.goToEndOfLine(false)
			}\n\t\tphase_name {$$phname}</item>
		<item name="Dummy Data Set" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tcalc_pattern(10,90,0.02,calc.xy)"); 
		</item>
				<item name="Simulate pattern from cif" type="macro">
			do_cif(v) {
				t = v.getTextArea();
				b = t.getBuffer();

				t.goToEndOfLine(false);					
				b.insert(t.getCaretPosition(), "'--------------------------------------------------------------"); 
				b.insert(t.getCaretPosition(), "\n'Calculated Pattern");
				b.insert(t.getCaretPosition(), "\n'Assumes Cu Ka2, no monochromator");
				b.insert(t.getCaretPosition(), "\n'Change as appropriate");
				b.insert(t.getCaretPosition(), "\n'Youll need Durham calc_pattern macro:");
				b.insert(t.getCaretPosition(), "\n'macro calc_pattern(start,stop,step,filename) {yobs_eqn !aac.xy = 1; min start max stop del step xdd_out filename load out_record out_fmt out_eqn { \" %11.5f  \" = X; \" %11.5f\\n\" = Ycalc;}}");
				b.insert(t.getCaretPosition(), "\n'is similar");
				b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
				b.insert(t.getCaretPosition(), "\niters 0"); 
				b.insert(t.getCaretPosition(), "\ncalc_pattern(10,90,0.02,calc.xy)"); 
				b.insert(t.getCaretPosition(), "\nLP_Factor(!th2_monochromator, 0)");
				b.insert(t.getCaretPosition(), "\nCuKa2_analyt(0.0001)"); 
				b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 
				b.insert(t.getCaretPosition(), "\n'Information on structure - add beq values as needed"); 
				b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 

				jEdit.setProperty("vfs.browser.last-filter", "*.cif");
				w_path = jEdit.getProperty("ta.last_cif_path");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"cif\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
				waitForConsole(v);								
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {					
					int i = 0;
					b.beginCompoundEdit();
					while(true) {
						runInSystemShell(v, jEdit.getProperty("ta.main.dir"));			
						waitForConsole(v);								
						runInSystemShell(v, "cif1 " + "\"" + files[i] + "\" cif1.tmp");
						waitForConsole(v);								
						t.goToEndOfLine(false);					
						b.insert(t.getCaretPosition(), "\n");
						b.insertFile(v, jEdit.getProperty("ta.main.dir") + "cif1.tmp");
						VFSManager.waitForRequests();
						i++;
						if (i == files.length) break;
						b.insert(t.getCaretPosition(), "\n");
					}
					b.endCompoundEdit();
					jEdit.setProperty("ta.last_cif_path", files[0]);
				}
				t.goToEndOfLine(false);
				b.insert(t.getCaretPosition(), "\n\t\tscale  0.001"); 
				b.insert(t.getCaretPosition(), "\n\t\tr_bragg 0"); 
				b.insert(t.getCaretPosition(), "\n\t\tTCHZ_Peak_Type(!pku, 0.00039,!pkv, -0.00221,!pkw, -0.00146,!pkz, 0.0000,!pkx, 0.00957,!pky, 0.0000)"); 
				b.insert(t.getCaretPosition(), "\n\t\tSimple_Axial_Model(!axial,0)"); 
				b.insert(t.getCaretPosition(), "\n\t\tPhase_Density_g_on_cm3(0)"); 
			}
			do_cif(view);
			</item>
		<item name="no_LIMIT_warnings" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\nno_LIMIT_warnings"); 
		</item>
		<item name="CSIRO str database" type="macro">
			Macros.getMacro("TAInsertSTR").invoke(view);
		</item>
      <item name="CSIRO Inel Detector" type="xinsert_script">{%alphaval "Enter Incident Beam Angle in degrees:"}{@	
			textArea.goToEndOfLine(false)
			}\n\tFIXEDTHETA(alpha, {$$alphaval})\n\tSDINEL(!delta,0,!alpha,{$$alphaval})
      </item>
		<item name="Robust refinement xye" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n'Robust refinement for xye file; Stone et al J. Appl. Cryst. (2009). 42, 385 to 391"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Get macro from http://www.dur.ac.uk/john.evans/topas_academic/topas_macros.htm"); 
			buffer.insert(textArea.getCaretPosition(), "\nRobust_refinement_xye"); 
		</item>
		<item name="Robust refinement no esd" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n'Robust refinement; Stone et al J. Appl. Cryst. (2009). 42, 385 to 391"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Use with raw files or xy files with no esd"); 
			buffer.insert(textArea.getCaretPosition(), "\n'Get macro from http://www.dur.ac.uk/john.evans/topas_academic/topas_macros.htm"); 
			buffer.insert(textArea.getCaretPosition(), "\nRobust_refinement_poisson"); 
		</item>
      </menu>	
      <menu name="Templates">
      		<item name="Select template file" type="macro">
			Macros.getMacro("TAtemplate").invoke(view);
		</item>
				<item name="Read a CIF file" type="macro">
			do_cif(v) {
				t = v.getTextArea();
				b = t.getBuffer();

				t.goToEndOfLine(false);					
				b.insert(t.getCaretPosition(), "\n\n'--------------------------------------------------------------"); 
				b.insert(t.getCaretPosition(), "\n'Information on structure");
				b.insert(t.getCaretPosition(), "\n'Type in phase/space group/cell etc");
				b.insert(t.getCaretPosition(), "\n'Comment in/out sections as needed");
				b.insert(t.getCaretPosition(), "\n'--------------------------------------------------------------"); 

				jEdit.setProperty("vfs.browser.last-filter", "*.cif");
				w_path = jEdit.getProperty("ta.last_cif_path");
				if (w_path == null) {
					w_path = jEdit.getProperty("ta.main.dir") +"cif\\";
				}
				jEdit.setProperty("vfs.browser.last-path", w_path);
				waitForConsole(v);								
				VFSFileChooserDialog chooser = new VFSFileChooserDialog(v, w_path, VFSBrowser.OPEN_DIALOG, true);
				String[] files = chooser.getSelectedFiles();
				if (files != null) {					
					int i = 0;
					b.beginCompoundEdit();
					while(true) {
						runInSystemShell(v, jEdit.getProperty("ta.main.dir"));			
						waitForConsole(v);								
						runInSystemShell(v, "cif1 " + "\"" + files[i] + "\" cif1.tmp");
						waitForConsole(v);								
						t.goToEndOfLine(false);					
						b.insert(t.getCaretPosition(), "\n");
						b.insertFile(v, jEdit.getProperty("ta.main.dir") + "cif1.tmp");
						VFSManager.waitForRequests();
						i++;
						if (i == files.length) break;
						b.insert(t.getCaretPosition(), "\n");
					}
					b.endCompoundEdit();
					jEdit.setProperty("ta.last_cif_path", files[0]);
				}
				t.goToEndOfLine(false);
				b.insert(t.getCaretPosition(), "\n\t\tscale @ 0.0001"); 
				b.insert(t.getCaretPosition(), "\n\t\tr_bragg 0"); 
				b.insert(t.getCaretPosition(), "\n\t\tTCHZ_Peak_Type(pku, 0.00039,pkv, -0.00221,pkw, -0.00146,!pkz, 0.0000,pkx, 0.00957,!pky, 0.0000)"); 
				b.insert(t.getCaretPosition(), "\n\t\tSimple_Axial_Model(axial,10)"); 
				b.insert(t.getCaretPosition(), "\n\t\tPhase_Density_g_on_cm3(0)"); 
			}
			do_cif(view);
			</item>

      </menu>	
	</menu>


	
