public void FixedUpdate()
        {
            if (vesselType == VesselType.Unknown)
            {
                Part p = Utils.getModulePartParent(this);
                if (p != null)
                {
                    vesselType = p.vesselType;

                    Log.Info("FixedUpdate  vesselType: " + vesselType.ToString() +
                             "  name: " + Utils.getModulePartParent(this).name);
                }
            }

            if (HighLogic.LoadedSceneIsFlight)
            {
                //Log.Info ("FixedUpdate partOrigVesselGuid: " + partOrigVesselGuid.ToString () + " id: " + FlightGlobals.ActiveVessel.id.ToString () + " needsManualInput: " + needsManualInput.ToString ()  + " p.partName: " + this.name +" ActiveVessel.vesselName: " + FlightGlobals.ActiveVessel.vesselName);
                //if (FlightGlobals.ActiveVessel.id == Utils.getCurrentVessel (this).id) {
                if (Utils.getCurrentVessel(this).isActiveVessel)
                {
                    if (needsManualInput)
                    {
                        Log.Info("FixedUpdate: needsManualInput: " + vessel.vesselName);
                        Log.Info("FixedUpdate");
                        Log.Info("ActiveVessel.id: " + FlightGlobals.ActiveVessel.id.ToString());
                        Log.Info("Active vessel: " + Utils.getCurrentVessel(this).vesselName);
                        Log.Info("storedVesselName: " + storedVesselName);
                        Log.Info("vesselType: " + vesselType.ToString());
                        Log.Info("priority: " + priority.ToString());
                        Log.Info("needsManualInput: " + needsManualInput.ToString());
                        Log.Info("p.partName: " + this.name);

                        string s = PDPN_SelectionWindow.formatManualEntryName(Utils.getActiveCommandPodModule(vessel.parts), vessel.vesselName, false, true, originalStoredVesselName);
                        if (s != "")
                        {
                            vessel.vesselName = s;
                        }
                        PDPN_SelectionWindow.flightReady = true;
                        PDPN_SelectionWindow.physicsCnt  = 0;
                        needsManualInput         = false;
                        pdpnVesselModule.renamed = true;
                    }
                }
            }
        }
        public static string formatName(PartModule pm2, string templateName, bool fillSelections = false)
        {
            Log.Info("enter formatName:  [" + templateName + "]");
            if (templateName == null || templateName == "")
            {
                return("");
            }
            Log.Info("formatName 0  length: " + templateName.Length.ToString());
            if (templateName.Length < 3 || templateName [0] != '*' || templateName [templateName.Length - 1] != '*')
            {
                return(templateName);
            }
            if (!fillSelections)
            {
                PDPN_SelectionWindow.InitSelectionWindow();
            }

            int[] times = ConvertUT(Planetarium.GetUniversalTime());

            KeyValuePair <string, PDPN.Tuple <string, NameValueCollection, bool> > t = GetFormat(templateName);

            Log.Info("formatName 3");

            string newVesselName = templateName;

            if (fillSelections || t.Key != "")
            {
                string template;
                if (fillSelections)
                {
                    template = templateName;
                }
                else
                {
                    template = t.Value.Second.Get("template");
                }
                Log.Info("formatName:  template: " + template);
                Log.Info("flightStatus: " + PDPN_SelectionWindow.flightStatus.ToString());
                newVesselName = template;
                string pattern = "";
                char   prefix  = ' ';
                char   suffix  = ' ';
                //	int cnt = 0;
                for (int p = 0; p < 2; p++)
                {
                    switch (p)
                    {
                    case 0:
                        // names surrounded by [brackets] are replaced immediately
                        pattern = "\\[.*?\\]";
                        prefix  = '[';
                        suffix  = ']';
                        break;

                    case 1:
                        // names surrounded by <angle brackets> are replaced after launch & at staging
                        pattern = "<.*?>";
                        prefix  = '<';
                        suffix  = '>';
                        break;
                    }
                    Log.Info("p: " + p.ToString() + "   pattern: " + pattern);
                    Regex r = new Regex(pattern);

                    Match m = r.Match(template);
                    while (m.Success)
                    {
                        string id          = m.Value.Substring(1, m.Value.Length - 2);
                        string search      = prefix + id + suffix;
                        string replacement = "";

                        Log.Info("formatName  id: " + id + "   search: " + search);

                        replacement = "";
                        if (fillSelections)
                        {
                            for (int i = 0; i < PDPN_SelectionWindow.selTitleList.Count; i++)
                            {
                                if (PDPN_SelectionWindow.selTitleList [i] == id)
                                {
                                    replacement = PDPN_SelectionWindow.selArList [i] [PDPN_SelectionWindow.selList [i]];
                                    Log.Info("Final replacement: " + PDPN_SelectionWindow.selTitleList [i] + "  replacement: " + replacement);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            // Format the replacement, then do the replace

                            int stageCnt = StageManager.GetStageCount(Utils.getPartList(pm2));
                            switch (id)
                            {
                            case "weightclass":

                                replacement = getWeightClass(pm2, stageCnt - Utils.getCurrentVessel(pm2).currentStage, t);
                                break;

                            case "enginetype":
                                replacement = getEngineTypes(pm2, stageCnt - Utils.getCurrentVessel(pm2).currentStage, t);
                                break;

                            case "fueltype":
                                replacement = getPropellentTypes(pm2, stageCnt - Utils.getCurrentVessel(pm2).currentStage, t);
                                break;

                            case "vesseltype":
                                replacement = getVesselType(pm2, stageCnt - Utils.getCurrentVessel(pm2).currentStage, t);
                                break;

                            case "numstages":
                                replacement = stageCnt.ToString();
                                break;

                            case "curstagenum":
                                replacement = Utils.getCurrentVessel(pm2).currentStage.ToString();
                                break;

                            case "propulsion":
                                replacement = getPropulsion(pm2, stageCnt - Utils.getCurrentVessel(pm2).currentStage, t);
                                break;

                            case "date":
                                replacement = ConvertDateString();
                                break;

                            case "day":
                                replacement = times [1].ToString("D2");
                                break;

                            case "year2":
                                replacement = times [0].ToString("D2");
                                break;

                            case "year3":
                                replacement = times [0].ToString("D3");
                                break;

                            case "year":
                                replacement = times [0].ToString("D");
                                break;

                            case "year4":
                                replacement = times [0].ToString("D4");
                                break;
                            //case "ordinalday":
                            //	break;

                            default:

                                break;
                            }
                        }

                        if (replacement != "")
                        {
                            newVesselName = newVesselName.Replace(search, replacement);
                        }

                        m = m.NextMatch();
                    }
                }
            }
            Log.Info("formatname vesselName: " + newVesselName);
            return(newVesselName);
        }