APSF //################################################################################################################################## // Name : LoadImage // Purpose : Load an image selected from those available in an objects observation list // Requires: AP v1.5.9a5 // Author : Robin Lauryssen-Mitchell // Date : 20th July 2007 // Version : 1.1 // Status : Initial // History : 0.1 - 20070705 - Project inception // 0.2 - 20070708 - Added Edit mode // radio button selection between View and Edit // 0.3 - 20070709 - Added External program list // dispenses with radio button selector // 1.0 - 20070718 - Initial release // 1.1 - 20070720 - Added FileExists checking // IMPORTANT: - YOU MUST MODIFY THE AppName AND AppPath LISTS (SEE BELOW) TO MATCH THE APPLICATIONS YOU WISH TO USE // AND WHERE THEY ARE LOCATED // - If the Observation User1 and User2 fields contain text it is ASSUMED to be a valid image path // Notes : - Tried most of my Windows software library. The following are the titles that did not work for some reason. // - Drew the line at trying the Python, IRAF and CygWin based stuff!!! // - Did not include the StarLink stuff because that is only on my laptop (used desktop/s to write this) // - Cannot try Mac stuff - don't have a Mac (I'd accept a permanent loan :D) // - No reason why this script should be limited to graphics files!!! // Just match an external program to the contents of the User fields // // The following fail to load the image: // Canopus // IRIS - I'll put in a feature request (if I remember!) // Astra Image 2.5MAX // Astrometrica // AstroMix // AstroStack // Blink // Cadet // CCDInspector - not surprising really // DeepSkyStacker // EZphotw // Fits4Win // ImageHEADca - could not try ImageVIEWca (licence expired - rats!) // iMerge - not surprising (needs a stack of images) // Loreal // MicroObservatoryImage - not surprising // PixInsight - submitted a feature request // Reduc // // Loads but does not display properly: // Avis // // Other problems: // K3CCDTools - wouldn't run at all, not sure why // Mirage - needs a modified bat file // NeatImage - possibly requires full version // Pixy - wouldn't run at all, possibly a Java problem // PlanetWarp - probably to old //################################################################################################################################## //================================================================================================================================== // Declarations //================================================================================================================================== //---------------------------------------------------------------------------------------------------------------------------------- // Const declarations //---------------------------------------------------------------------------------------------------------------------------------- //Application const cAppTitle = "LoadImage" //Application title //Application data Save & Restore labels const cSR_AppID = "RLM_LoadImage_AppID" //General const cFlagOn = true const cFlagOff = false //---------------------------------------------------------------------------------------------------------------------------------- // Class declarations //---------------------------------------------------------------------------------------------------------------------------------- class AppStateType dim DoIt as boolean //Do some processing flag (often returned from a sub or function) dim ErrNum as integer //General purpose error number (0=OK) dim ErrText as string //General purpose error text end class class AppDataType dim ObjectID as string //Object ID dim AppID as integer //External program list ID (persistant) dim AppPath as string //Path for external program dim ImagePath as string //Directory path to image file end class //---------------------------------------------------------------------------------------------------------------------------------- // Var declarations //---------------------------------------------------------------------------------------------------------------------------------- dim AppState as AppStateType //Application state (supposed to be) dim AppData as AppDataType //Application data //Initialise Application Type structures AppState = new AppStateType //Globabl application state AppData = new AppDataType //Global application data //---------------------------------------------------------------------------------------------------------------------------------- //Name : IconApp //Purpose : Initialise data structures used by this script //Requires: Global application state and data structures //Returns : Global application state and data structures //Notes : None //---------------------------------------------------------------------------------------------------------------------------------- sub IconApp(byref AppState as AppStateType, byref AppData as AppDataType) //Icon application state AppState.DoIt = cFlagOff //Application processing is off AppState.ErrNum = 0 //No current errors AppState.ErrText = "" //No current errors AppData = RestoreAppData() //Retrive the persistant application data end sub //---------------------------------------------------------------------------------------------------------------------------------- //Name : SanityCheck //Purpose : Check that prerequisites for processing exist //Requires: Current AppState //Returns : - //Notes : None //---------------------------------------------------------------------------------------------------------------------------------- sub SanityCheck(byref AppState as AppStateType) const cNoSelectedObject = -1 //No currently selected object flag const cNoObservations = 0 //No observations for selected object //Default condition AppState.DoIt = cFlagOn //Ready to go AppState.ErrNum = 0 //No errors AppState.ErrText = "" //unless no object is selected if SelectedObject = cNoSelectedObject then AppState.DoIt = cFlagOff AppState.ErrNum = -1 AppState.ErrText = "No Object Selected" else //or the currently selected object has no observations if Obj(SelectedObject).nObservations = cNoObservations then AppState.DoIt = cFlagOff AppState.ErrNum = -2 AppState.ErrText = Obj(SelectedObject).ID + EndOfLine + "No Observations" end if end if end sub //---------------------------------------------------------------------------------------------------------------------------------- // Name : DoDialog // Purpose: Choose an object list to process (must have a selected plan) // Returns: None //---------------------------------------------------------------------------------------------------------------------------------- sub DoDialog (byref AppState as AppStateType, byref AppData as AppDataType) const cExternalLabel = "External program" //Selection list header const cObservationLabel = "Observation" //Selection list header const cFieldAppendOff = false //Don't append dialogue box fields const cPopUpDef = 0 dim ObDates(-1) as string //List of observation for current object dim ImageFiles(-1) as string //List of available images (stashed in object observations) dim ImageFlag as boolean //True if observation records do contain images (in User1 and/or User2) dim AppPath(-1) as string //List of application paths (order MUST match AppName list) dim AppName(-1) as string //List of application names (order MUST match AppPath list) dim Index as integer //General loop index dim UserPath as string //Observation User field text (assumed to be a file path) //Set up the list of applications //I know this list is quite long: // delete the ones you don't want // you can of course add your own entries // these entries MUST be in the same order as the AppPath list (see below) AppName.append "MaxImDL" AppName.append "Photoshop" AppName.append "Mira" AppName.append "ImageAnalyzer" AppName.append "ImageJ" AppName.append "HNS_FITS" AppName.append "ImageToolkit" AppName.append "Aladin" AppName.append "DS9" AppName.append "FV" AppName.append "JSky" AppName.append "CCDSharp" //Only reads FITS and SBIG files (I think) AppName.append "FITSview" AppName.append "FITSX" AppName.append "HDRShop" //Cannot load FITS files AppName.append "Nebulosity" AppName.append "NoiseWare" //Cannot load FITS files AppName.append "PlanetWarp" //Cannot load FITS files - just for FUN anyway! AppName.append "PrimaryImage" AppName.append "IRFanView" //Probably the best for quick viewing graphics files and FITS images AppName.append "PaintShopPro" //Cannot load FITS files AppName.append "PaintNET" //Cannot load FITS files //Modify these paths to match your system //Delete any entries you don't need //These entries MUST be in the same order as the AppName list (see above) AppPath.append "C:\Program Files\Applications\Astronomy\MaxIm DL\MaxIm_DL.exe" AppPath.append "C:\Program Files\Applications\Graphics\Adobe\Photoshop\Photoshop.exe" AppPath.append "C:\Program Files\Applications\Astronomy\Mira\Mira.exe" AppPath.append "C:\Program Files\Applications\Astronomy\ImageAnalyser\Analyzer.exe" AppPath.append "C:\Program Files\Applications\Astronomy\ImageJ\ImageJ.exe" AppPath.append "C:\Program Files\Applications\Astronomy\HNS_FITS\hns_fits.exe" AppPath.append "C:\Program Files\Applications\Astronomy\ImageTool\it.exe" AppPath.append "C:\Program Files\Applications\Astronomy\Aladin\aladin.exe" AppPath.append "C:\Program Files\Applications\Astronomy\DS9\ds9.exe" AppPath.append "C:\Program Files\Applications\Astronomy\FV\bin\fv.exe" AppPath.append "C:\Program Files\Applications\Astronomy\JSky\jsky-2.5\install\jsky_2.5\lib\jsky.jar" AppPath.append "C:\Program Files\Applications\Astronomy\CCDSharp\CCDSharp.exe" AppPath.append "C:\Program Files\Applications\Astronomy\FITSview\FITSview.exe" AppPath.append "C:\Program Files\Applications\Astronomy\FitsX\FitsX.exe" AppPath.append "C:\Program Files\Applications\Astronomy\HDRShop\HDRShop.exe" AppPath.append "C:\Program Files\Applications\Astronomy\Nebulosity\Nebulosity.exe" AppPath.append "C:\Program Files\Applications\Astronomy\NoiseWare\NoiseWare.exe" AppPath.append "C:\Program Files\Applications\Astronomy\PlanetWarp\PlanetWarp.exe" AppPath.append "C:\Program Files\Applications\Astronomy\PrimaryImage\PrimaryImage.exe" AppPath.append "C:\Program Files\Utilities\IrfanView\i_view32.exe" AppPath.append "C:\Program Files\Applications\Graphics\PSP\Paint Shop Pro X.exe" AppPath.append "C:\Program Files\Applications\Graphics\PaintNET\PaintDotNet.exe" //Build observation list AppData.ObjectID = Obj(SelectedObject).ID ImageFlag = cFlagOff for Index = 1 to Obj(SelectedObject).nObservations UserPath = Obj(SelectedObject).Observation(Index).User1 if (UserPath > "") and FileExists(UserPath) then ImageFiles.append UserPath ObDates.append FormatUserData(Index, UserPath) ImageFlag = cFlagOn end if UserPath = Obj(SelectedObject).Observation(Index).User2 if (UserPath > "") and FileExists(UserPath) then ImageFiles.append UserPath ObDates.append FormatUserData(Index, UserPath) ImageFlag = cFlagOn end if next if ImageFlag then SetListChoiceParameter(cFieldAppendOff, cExternalLabel, AppData.AppID, AppName(), false, 6, false) SetListChoiceParameter(cFieldAppendOff, cObservationLabel, cPopUpDef, ObDates(), false, 6, true) if EditParameters (cAppTitle+": "+AppData.ObjectID) then AppData.AppID = GetListChoiceParameter(cExternalLabel) AppData.AppPath = AppPath(AppData.AppID) AppData.ImagePath = ImageFiles(GetListChoiceParameter(cObservationLabel)) AppState.DoIt = cFlagOn else //User clicked Cancel button AppData.AppID = -1 AppData.AppPath = "" AppData.ImagePath = "" AppState.DoIt = cFlagOff //so don't "doit" end if else AppState.DoIt = cFlagOff AppState.ErrNum = -3 AppState.ErrText = "No images to process" end if end sub //---------------------------------------------------------------------------------------------------------------------------------- //Name : FormatUserData //Purpose : Format observation User field data for display in dialogue box //Requires: OIndex - ObservationIndex, UserPath - User field text //Returns : Formatted text //Notes : Should probably pass an Object type rather than rely of 'SelectedObject' //---------------------------------------------------------------------------------------------------------------------------------- function FormatUserData (OIndex as integer, UserPath as string) as string const cColumnSep = " | " //Dialogue box column separator (my attempt to make display more readable) const cPathSep = "\" //Image file path separator return Obj(SelectedObject).Observation(OIndex).Site+cColumnSep+ _ Obj(SelectedObject).Observation(OIndex).Date+cColumnSep+ _ Obj(SelectedObject).Observation(OIndex).Time+cColumnSep+ _ NthField(UserPath, cPathSep, CountFields(UserPath, cPathSep)) end function //---------------------------------------------------------------------------------------------------------------------------------- //Name : DoApp //Purpose : Main application routine //Requires: AppData - contains all the application data, either default or user-defined //Returns : - //Notes : - //---------------------------------------------------------------------------------------------------------------------------------- sub DoApp (AppData as AppDataType) const cShellTimeout = 2000 //Two seconds normally works for me call Shell(chr(34)+AppData.AppPath+chr(34), AppData.ImagePath, cShellTimeout) end sub //---------------------------------------------------------------------------------------------------------------------------------- //Name : RestoreAppData //Purpose : Retrive saved values stored in the Plan file //Requires: Open plan file //Returns : AppDataType //Notes : - //---------------------------------------------------------------------------------------------------------------------------------- function RestoreAppData () as AppDataType dim RestoreData as AppDataType RestoreData = new AppDataType RestoreData.AppID = RestoreIntegerValue(cSR_AppID, 0) return RestoreData end function //---------------------------------------------------------------------------------------------------------------------------------- //Name : SaveAppData //Purpose : Save values to the Plan file //Requires: AppDataType //Returns : None //Notes : None //---------------------------------------------------------------------------------------------------------------------------------- sub SaveAppData (SaveData as AppDataType) SaveintegerValue(cSR_AppID, SaveData.AppID) end sub //---------------------------------------------------------------------------------------------------------------------------------- //Name : TerminateApp //Purpose : Gracefully close the script //Requires: Message - Text to display to the user at close-out //Returns : None //Notes : None //---------------------------------------------------------------------------------------------------------------------------------- sub TerminateApp(AppState as AppStateType) if AppState.ErrNum <> 0 then print AppState.ErrText end if //Destroy data structures AppData = nil AppState = nil end sub //================================================================================================================================== // Main Code //================================================================================================================================== //Initialise the application IconApp(AppState, AppData) //Get the application ready SanityCheck(AppState) //Try to make sure there is something sensible to do if AppState.DoIt then //think there is, so ... DoDialog(AppState, AppData) //ask the user what to do (probably a bad move :) if AppState.DoIt then //user has requested to do something (uh oh! :) SaveAppData(AppData) //save the persistant data DoApp(AppData) //do what the user asked end if end if TerminateApp(AppState) //clean up the mess and get out of here