'---------------------------------------------------------------
'
' ***  create.vbs ***
'
' Usage:   cscript create.vbs <image file>
' Example: cscript create.vbs testimage.fit
'
' Uses the ASCOM FITS image driver
' --> http://www.easysky.de/ASCOM/Image/FITS.htm
' to create a new FITS file from scratch
' and sets some example properties.
'
' A pseudo image is obtained from the CCD camera simulator
' --> http://www.easysky.de/ASCOM/Camera/Simulator.htm
' which implements the current Camera standard proposal
' at http://ascom-standards.org/CamProp3.html
'
' Matthias Busch (matthias.busch@easysky.de) 2003-07-20
'---------------------------------------------------------------

Sub Main
   If WScript.Arguments.Count = 0 Then
      WScript.Echo "please specify an output filename as argument"
      Exit Sub
   End If

   ' First argument is the FITS file to create
   filename = WScript.Arguments.Item(0)

   exposuretime = 2  ' seconds

   ' Create the CCD simulator object
   Set camera = CreateObject("CCDSimulator.Camera")

   camera.Connected = True

   ' "expose" with the simulator
   WScript.Echo "exposing " & exposuretime & " seconds..."
   exposurestarttime = now
   camera.StartExposure exposuretime, True
   While Not camera.ImageReady
      WScript.Sleep 100
   Wend
   WScript.Echo "shutter closed."
   WScript.Echo

   WScript.Echo "creating " & filename & "..."

   ' Create the ASCOM FITS driver object
   Set image = CreateObject("FITS.Image")

   ' Fetch image array (raw pixel data) from the camera
   ' and feed it directly to our image object
   image.ImageArrayVariant = camera.ImageArrayVariant

   ' Set some properties for our new FITS file
   image.Camera = "Apogee AP7b"
   image.CCDTemperature = camera.CCDTemperature
   image.CreationSoftware = "Test VBS script"
   image.EMail = "matthias.busch@easysky.de"
   image.Equinox = 2000.0
   image.ExposureInterval = exposuretime
   image.ExposureStartTime =  exposurestarttime
   image.FilterName = "Johnson V"
   image.Observatory = "611 Starkenburg"
   image.Observer = "M. Busch"
   image.TargetDeclination = 28.3
   image.TargetName = "2002 NY40"
   image.TargetRightAscension = 5.6734
   image.Telescope = "0.45-m f/4.4 reflector"
   image.Temperature = camera.HeatSinkTemperature

   ' Finally create the new FITS file
   image.WriteToFile filename
   WScript.Echo "done."

End Sub

'---
Main
'---
