<?xml version="1.0" encoding="ISO-8859-1"?>

<menu name="TOPAS_Durham_Menus">

<menu name="Help/General/Links">
	<item name="PCG Rietveld Workshop www" type="macro">
			runInSystemShell(view, "start \"http:\\\\www.dur.ac.uk\\john.evans\\topas_workshop\\pcg_workshop_menu.htm\"&amp;");
		</item>
		<item name="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="Log file - topas.log" type="macro">jEdit.openFile(editPane.getView(), jEdit.getProperty("ta.main.dir") + "topas.log");</item>
		<item name="Technical Reference" type="macro">
			runInSystemShell(view, "start /D\""+ jEdit.getProperty("ta.main.dir") +"\" Technical_Reference.pdf&amp;");
			waitForConsole(view);
		</item>
		<item name="Users Manual" type="macro">
			runInSystemShell(view, "start /D\""+ jEdit.getProperty("ta.main.dir") +"\" Users_Manual.pdf&amp;");
			waitForConsole(view);
		</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(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Input File for simple Rietveld Refinement"); 
								b.insert(t.getCaretPosition(), "\n'Use save/set current button then run with F6 in topas"); 
								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'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"); 
			
								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\tLP_Factor(!th2_monochromator, 26.6)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2(0.0001)"); 
			</item>
			<item name="Durham_d5000_solx" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2(0.0001)"); 
			</item>
			<item name="Durham_d6" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d8" type="macro">
			textArea.goToEndOfLine(false);
			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\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2(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.5\n\tLP_Factor( 0) 'change the mono angle as 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 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'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,!pkx, 0.0000,pky, 0.00957,!pkz, 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 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,!pkx, 0.0000,pky, 0.00957,!pkz, 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\t\phase_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(), "\n'--------------------------------------------------------------"); 
								b.insert(t.getCaretPosition(), "\n'Input File for simple Rietveld Refinement"); 
								b.insert(t.getCaretPosition(), "\n'Use save/set current button then run with F6 in topas"); 
								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'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"); 
			
								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\tLP_Factor(!th2_monochromator, 26.6)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2(0.0001)"); 
			</item>
			<item name="Durham_d5000_solx" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2(0.0001)"); 
			</item>
			<item name="Durham_d6" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d8" type="macro">
			textArea.goToEndOfLine(false);
			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\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2(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.5\n\tLP_Factor( 0) 'change the mono angle as 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 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,!pkx, 0.0000,pky, 0.00957,!pkz, 0.0000)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\t\tSimple_Axial_Model(axial,10)");  
		</item>
		<item name="Phase Name" type="xinsert_script">{%phname "Enter Phase Name:"}{@
			textArea.goToEndOfLine(false)
			}\n\t\t\phase_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 save/set current button then run with F6 in topas"); 
								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'--------------------------------------------------------------"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tTOF_LAM(0.001)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tTOF_x_axis_calibration(!t0_hrpd_bs,-16,!difc_hrpd_bs,48262,!difa_hrpd_bs,-8.35)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tTOF_Exponential(!a1_bs, 230.98670,!a2_bs, 27.018, 4, difc_hrpd_bs, +)"); 
			</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(), "\n'--------------------------------------------------------------"); 
								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 save/set current button then run with F6 in topas"); 
								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(), "\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\tLP_Factor(!th2_monochromator, 26.6)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2(0.0001)"); 
			</item>
			<item name="Durham_d5000_solx" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2(0.0001)"); 
			</item>
			<item name="Durham_d6" type="macro">
			textArea.goToEndOfLine(false);
			buffer.insert(textArea.getCaretPosition(), "\n\tLP_Factor(!th2_monochromator, 27.26)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa1(0.0001)"); 
			</item>
			<item name="Durham_d8" type="macro">
			textArea.goToEndOfLine(false);
			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\tLP_Factor(!th2_monochromator, 0)"); 
			buffer.insert(textArea.getCaretPosition(), "\n\tCuKa2(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.5\n\tLP_Factor( 0) 'change the mono angle as 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 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,!pkx, 0.0000,pky, 0.00957,!pkz, 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 save/set current button then run with F6 in TOPAS-Academic"); 

			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 save/set current button then run with F6 in topas"); 
								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'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\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\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\t\phase_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="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"); 
		</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\t\phase_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(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,!pkx, 0.0000,!pky, 0.00957,!pkz, 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>
         </menu>	


	</menu>


	

