DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Slashes to backslashes changed

Solved!
Go to solution

Dear,

 

I am facing a problem when converting some data in dataportal to csv. I need to post process the csv latter that the date appears like this “2016/03/04” so I create a string like this :

Dim sDate: sDate = aDate(2)&"/"&aDate(1)&"/"&aDate(0) 'YYYYMMDD “2016\03\04”

But when I open my csv file I get instead os “/” a “\” how can I avoid this behaviour???

 

I read that: DIAdem changes forward slashes in names to backslashes so that there is no ambiguity in the object paths.  This is expected behavior. 
In a TDMS file, every TDMS object is uniquely identified by a path. Each path is a string including the name of the object and the name of its owner in the TDMS hierarchy, separated by a forward slash.
This problem is commonly seen when units are added to channel names, such as "Velocity, m/s."  It is recommended to add the units to the unit channel property instead of putting them in the channel name.

 

 

Thank you for your help

 

Best Regards

0 Kudos
Message 1 of 7
(5,116 Views)
Sub GroupAsciiExport(GroupIdx, FileNamePath, HeaderLines)
  Dim j, jMin, jMax, Ch1, ChN, HdrStr
  jMin = CNoXGet(GroupIdx, 1)
  jMax = CNoXGet(GroupIdx, GroupChnCount(GroupIdx))
  Ch1 = ChnName(jMin)
  ChN = ChnName(jMax)
  ChnName(jMin) = HeaderLines & vbCRLF & Ch1
  ChnName(jMax) = ChN 
  On Error Resume Next
  Call DataFileSave(FileNamePath, "CSV")
  On Error Goto 0
  ChnName(jMin) = Ch1
  ChnName(jMax) = ChN
End Sub ' GroupAsciiExport()

This is the code I am using to convert the files... the date I require is contained in HeaderLines

0 Kudos
Message 2 of 7
(5,112 Views)

Sorry I assume there is no solution for this.

 

The script uses the fact that the first channel name is written to CSV file at start.

 

But there is no ability to change this rule of the channel names. They are always escaped.

0 Kudos
Message 3 of 7
(5,102 Views)

Is not other way to get the header as I need? or some setting that I can change in DIAdem to do so? so I ca block the automatic changing?

0 Kudos
Message 4 of 7
(5,096 Views)

Hi Maria,

 

I recommend that you send the header line you want to preserve to the "Description" property instead.  If you want to query on the datetime information, it should be sent to a datetime property as well-- let me know if you have trouble with that.  The Description property appears automatically in the default VIEW table and can be used in VIEW and REPORT graph legends and REPORT Axis lables.

 

Channel.Properties.Add "Description", HeaderLine

 

There is no way to avoid the "/" to "\" character mapping for Group.Name or Channel.Name properties.  All other properties allow those characters in their property values.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 5 of 7
(5,087 Views)
Solution
Accepted by topic author MariaEsmeral

Hi Maria,

 

Sorry, I didn't read the post chain carefully enough-- I thought you were importing data instead of exporting.  There's no way around the channel name restriction, but here's a different approach to writing an ASCII file with header lines that is just as fast, using DOS copy to concatenate the header lines and the ASCII data fiel the CSV DataPlugin outputs:

 

OPTION EXPLICIT
Dim FileNamePath, DataFilePath, HeaderFilePath, HeaderLines, Group, Delimiter
Delimiter = "," ' "," OR OR ";" OR vbTAB
HeaderFilePath = AutoActPath & "Example Header.txt"
DataFilePath = AutoActPath & "Example Data.txt"
FileNamePath = AutoActPath & "Example.txt"

Call Data.Root.Clear
Call DataFileLoad(AutoActPath & "Example.tdm")
HeaderLines = "Version 1.10" & vbCRLF & RTT(TTR(CurrDateTime), "#yyyy/mm/dd hh:nn:ss.ffff")
Set Group = Data.Root.ActiveChannelGroup
Set Group = Data.Root.ChannelGroups(1)
Call CreateAsciiHeaderFile(HeaderFilePath, HeaderLines)
Call CreateAsciiDataFile(DataFilePath, Delimiter, Group)
Call DOSconcatDataFiles(FileNamePath, Array(HeaderFilePath, DataFilePath))
LogFileWrite "Successfuly exported to file: " & vbCRLF & """" & FileNamePath & """"
MsgBox "Successfuly exported to file: " & vbCRLF & vbCRLF & """" & FileNamePath & """"
Call ExtProgram(FileNamePath)


Sub CreateAsciiHeaderFile(HeaderFilePath, HeaderLines)
  Dim f, fso
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile(HeaderFilePath, 2, True)
  f.WriteLine HeaderLines
  f.Close
End Sub ' CreateAsciiHeaderFile()


Sub CreateAsciiDataFile(DataFilePath, Delimiter, Group)
  Dim FileParameters
  FileParameters = FileParameters & "<filename>"  & DataFilePath  & "</filename>"
  FileParameters = FileParameters & "<delimiter>" & Delimiter     & "</delimiter>"
  Call DataFileSaveSel(FileParameters, "CSV", Group.Channels)
' "filename"             specifies the file that is to be read. 
' "characterset"         can have two possible values: utf16 (bmp) and ansi. Future possible values include UTF8, etc. 
' "delimiter"            is the character used to separate values. Only tab, semi-colon, and comma will be supported in the first version 
' "numstartrow"          is the index of the row to start reading at. 
' "firstrowchannelnames" is true if the first row contains the names of the channels following it. 
' "firstcolumntime"      indicates that the first column contains time data. These times will be interpreted as absolute times. 
' "decimalpoint"         indicates whether a "." or a "," is used to separate the integral part of the number from the fractional part. 
' "timeformat"           indicates what time format to expect in the document and how to write the time format back out again. 
End Sub ' CreateAsciiDataFile()


Sub DOSconcatDataFiles(FileNamePath, OutDataFiles)
  Dim j, jMax, f, fso, WSH, DosDrv, DosFile, DosCop, DosDel, AddFileName
  Set WSH = CreateObject("WScript.Shell")
  Set fso = CreateObject("Scripting.FileSystemObject")
  DosDrv = TmpDrv & "DataCopy Bat Files"
  On Error Resume Next
  IF FolderExist(DosDrv) THEN Call FolderDelete(DosDrv)
  Call FolderCreate(DosDrv)
  Call FileDelete(FileNamePath)
  On Error Goto 0
  jMax = UBound(OutDataFiles)
  FOR j = 0 TO jMax
    AddFileName = OutDataFiles(j)
    IF DosCop = "" THEN
      DosCop = "copy /b """ & AddFileName & """"
    ELSE
      DosCop = DosCop & " + """ & AddFileName & """"
    END IF
    DosDel = DosDel & vbCRLF & "del """ & AddFileName & """"
  NEXT ' j
  DosCop = DosCop & " """ & FileNamePath & """"
  DosFile = DosDrv & "\Data_Files_Concatenate.bat"
  DosDel = DosDel & vbCRLF & "del """ & DosFile & """"
  Set f = fso.OpenTextFile(DosFile, 2, True)
  f.Write DosCop & DosDel
  f.Close
  Call WSH.Run("""" & DosFile & """", 0, FALSE)
End Sub ' DOSconcatDataFiles()

 

You need to save this script to a file first before the AutoActPath variable will work.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 6 of 7
(5,083 Views)

Brad many thanks! As always impecable solution! 

0 Kudos
Message 7 of 7
(5,033 Views)