'---------------------------------------------------------------
'
' ***  read.vbs ***
'
' Usage:   cscript read.vbs <image file>
' Example: cscript read.vbs testimage.fit
'
' Uses the ASCOM FITS image driver
' --> http://www.easysky.de/ASCOM/Image/FITS.htm
' and shows how to access the image array (pixel data).
'
' Matthias Busch (matthias.busch@easysky.de) 2003-10-26
'---------------------------------------------------------------


Sub Main
   If WScript.Arguments.Count = 0 Then
      WScript.Echo "Please specify an input filename as argument."
      Exit Sub
   End If

   ' First argument is the FITS file to read
   filename = WScript.Arguments.Item(0)

   ' Create the ASCOM FITS driver object
   Set image = CreateObject("FITS.Image")

   ' Read the file from disk
   WScript.Echo "Reading " & filename & "..."
   image.ReadFromFile filename
   WScript.Echo "...done"

   ' Read image dimensions
   WScript.Echo
   WScript.Echo "Image dimensions:"
   WScript.Echo image.Columns & " columns"
   WScript.Echo image.Rows    & " rows"

   ' Read min and max pixel values
   WScript.Echo
   WScript.Echo "Maximum pixel value: " & image.MaximumPixelValue
   WScript.Echo "Minimum pixel value: " & image.MinimumPixelValue

   ' Read the whole pixel array (raw image data) into the variable "pixelarray"
   pixelarray = image.ImageArrayVariant

   ' Note: in vbs you don't have to "dim" variables - they can also
   ' carry arrays because they are always VARIANT!
   ' Disadvantage: only arrays of VARIANT are allowed - thus the
   ' ASCOM Image spec defines "ImageArray" and "ImageArrayVariant"

   WScript.Echo
   WScript.Echo "Values of first 5 pixels in the first (topmost) row using ImageArrayVariant:"
   WScript.Echo pixelarray(0,0) ' Note: indices are zero-based
   WScript.Echo pixelarray(1,0)
   WScript.Echo pixelarray(2,0)
   WScript.Echo pixelarray(3,0)
   WScript.Echo pixelarray(4,0)

   WScript.Echo
   WScript.Echo "Values of first 5 pixels in the first (topmost) row using PixelValue:"
   WScript.Echo image.PixelValue(0,0)
   WScript.Echo image.PixelValue(1,0)
   WScript.Echo image.PixelValue(2,0)
   WScript.Echo image.PixelValue(3,0)
   WScript.Echo image.PixelValue(4,0)

   WScript.Echo
   WScript.Echo "Values of first 5 pixels in the first (leftmost) column using ImageArrayVariant:"
   WScript.Echo pixelarray(0,0)
   WScript.Echo pixelarray(0,1)
   WScript.Echo pixelarray(0,2)
   WScript.Echo pixelarray(0,3)
   WScript.Echo pixelarray(0,4)

   WScript.Echo
   WScript.Echo "Values of first 5 pixels in the first (leftmost) column using PixelValue:"
   WScript.Echo image.PixelValue(0,0)
   WScript.Echo image.PixelValue(0,1)
   WScript.Echo image.PixelValue(0,2)
   WScript.Echo image.PixelValue(0,3)
   WScript.Echo image.PixelValue(0,4)

End Sub

'---
Main
'---
