!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Convert from GDFV1 to GDFV2.
! Also patches the UVDAT to UVFIL issue for UV Tables if needed.
!
! S.Guilloteau 2012, cloned from uvdat2uvfil.greg by 
! J.Pety and S.Guilloteau 2004
! 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
on error return base
!
! Input parameters
!
define character gildasdata*6 gildasdatatype*5 gildaskind*1 key*6
define character old_uvt*256 new_uvt*256
let old_uvt &1 /prompt "old Gildas file name (with extension)"
let new_uvt &2 /prompt "new Gildas file name (with extension)"
!
!
! Check file existence
!
if file(old_uvt) then
   ! Check that it is a GILDAS binary file
   accept gildasdata /col 'old_uvt' /format (a)
   if (gildasdata.eq."GILDAS") then
      ! Check GILDAS data type
      accept gildasdatatype /col 'old_uvt' /format (7x,a)
      if (gildasdatatype.eq."IMAGE") then
         key = "IMAGE"
      else if (gildasdatatype.eq."UVFIL") then
         key = "UV"
      else if ((gildasdatatype.eq."UVDAT").or.(gildasdatatype.eq."UVSOR")) then
         message i gdf_convert ""'old_uvt'" is a UV table using OLD format: converting"
         vector\transpose 'old_uvt' "gag-temp-old_uvt.tuv" 21
         vector\transpose "gag-temp-old_uvt.tuv" 'new_uvt' 21
         sic delete "gag-temp-old_uvt.tuv"
         message i gdf_convert "Success"
         return
      else
         message w gdf_convert ""'old_uvt'" is of special type "'gildasdatatype'
         message w gdf_convert "Please report to gildas@iram.fr"
         return
      endif
      accept gildaskind /col 'old_uvt' /format (6x,a)
      if (gildaskind.eq."<".or.gildaskind.eq.">") then
         message w gdf_convert ""'old_uvt'" is already in GDFV2 format, Nothing done"
      else
        define 'key' a 'old_uvt' read
        define 'key' b 'new_uvt' real /like a
        let b% a%
        let b a 
        delete /var a
        delete /var b
      endif
   else
      message e gdf_convert ""'old_uvt'" is not a GILDAS data file"
   endif
else
   message e gdf_convert ""'old_uvt'" does not exist"
endif
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
