Find npnts in text wave

I don't know if I'm being stupid but I figure out how to find the number of points in a textwave. I want to add an extra point to the text wave which contains the names of the loaded waves every time a wave is loaded through a loading routine. I had planned to do the following (where the text wave DataWaveList is predefined but empty before any data has been loaded):

Function UpdateDataWaveList(matOutput)
    Wave matOutput
    String exptDF = GetDataFolder(1)
    Wave/T DataWaveList = $(exptDF+":All_data:DataWaveList")

    If ( waveDims(DataWaveList) == 0 )
        InsertPoints 0,1, DataWaveList
        DataWaveList[0]=NameOfWave(matOutput)
    else
        WaveStats/Q DataWaveList
        InsertPoints (V_endRow),1, DataWaveList
        DataWaveList[V_npnts]=NameOfWave(matOutput)
    endif
End


But wavestats doesn't work on textwaves. Perhaps a feature for IP7? Obviously numerical values like V_max won't work but it could still return V_npnts etc.

Many thanks,
Tom

Update: I've figured out that numpnts can be used in this instance. If anyone has a better way of doing what I want to do though I would be very grateful for any input.

Function UpdateDataWaveList(matOutput)
    Wave matOutput
    String exptDF = GetDataFolder(1)
    Wave/T DataWaveList = $(exptDF+":All_data:DataWaveList")

    If ( waveDims(DataWaveList) == 0 )
        InsertPoints 0,1, DataWaveList
        DataWaveList[0]=NameOfWave(matOutput)
    else
        InsertPoints (numpnts(DataWaveList)),1, DataWaveList
        DataWaveList[numpnts(DataWaveList)]=NameOfWave(matOutput)
    endif
End
I'm not sure if I understand your task correctly: basically, you want to generate a wave as a list of the names of the loaded data so far?
You say that DataWaveList is predefined, but what are the dimension, points etc. at time of execution? Can I assume that the wave has one dimension and one empty row entry at start?
First, I'm not sure if your if-else statement is useful at all since I don't see any statement modifying the wave dimension (could be somewhere else though). This way, the function fills the name into the first row entry if the wave is one-dimensional and into the last row entry if the wave is multidimensional. But then you should be careful with the use of numpnts.

If you only want a one-dimensional list of names, I'd suggest something like (this is not tested though. Counting could be off):
Function UpdateDataWaveList(matOutput)
    Wave matOutput
    String exptDF = GetDataFolder(1)
    Wave/T DataWaveList = $(exptDF+":All_data:DataWaveList")
 
    Variable NewSize = DimSize(DataWaveList, 0)     // get the number of row points (same as numpnts for 1D)
    NewSize = strlen(DataWaveList[NewSize-1]) == 0? NewSize-1 : NewSize // decide if last element has something stored
                                        // no need to extend wave if not (especially for a fresh wave)
    Redimension/N=(NewSize+1) DataWaveList          // extend the wave
    DataWaveList[NewSize] = NameOfWave(matOutput)       // write the name
End
I agree with chozo that the first part of your if..else..endif block is unnecessary.

A few other notes:
1. Instead of storing the names in a text wave, you might find using a list contained in a string to be easier. It depends on what you are doing with the text wave later on. If you want to use a string list, look at the AddListItem, StringFromList, and ItemsInList functions.

2. Instead of using NameOfWave, I suggest you use GetWavesDataFolder(matOutput, 2). This will give you the full path to the wave, including its name. You may not be using data folders much now, but if you decide to do so in the future you won't have to change this code to support the waves being in different data folders.

3. Depending on what you are doing with the text wave containing wave names, you might be better off using a wave that contains wave references to the loaded waves. Execute DisplayHelpTopic "Wave Reference Waves" on the command line for more info.
Thanks for the help. The function I have listed is embedded in the loading routine. This loading routine can be called any number of times from a GUI loading panel. As a file is loaded I want to add the file name to the text wave DataWaveList. The DataWaveList is created on initialization of the GUI panel when all global strings and variables are prepared. I defined the text wave to have no points at the start i.e. WaveDims = 0, but I am happy to use Make/T/N=1 so that there is one empty space to start with.

aclight wrote:
Instead of storing the names in a text wave, you might find using a list contained in a string to be easier. It depends on what you are doing with the text wave later on.


Using a string list would be a lot simpler but I need a text wave as it will be used for a list box in a data browsing panel.

aclight wrote:
Instead of using NameOfWave, I suggest you use GetWavesDataFolder(matOutput, 2). This will give you the full path to the wave, including its name. You may not be using data folders much now, but if you decide to do so in the future you won't have to change this code to support the waves being in different data folders.


The package uses a hierachical data folder system to store all waves but I don't think I will need the full path as I define the path the text wave on creation of the list box.

I was not aware of the syntax:
NewSize = strlen(DataWaveList[NewSize-1]) == 0? NewSize-1 : NewSize

but I like this method and will try and implement that.

I'll look into the wave reference waves route too.
Thomas.Dane wrote:
... I defined the text wave to have no points at the start i.e. WaveDims = 0, but I am happy to use Make/T/N=1 so that there is one empty space to start with. ...


I may be wrong, but from this I get the strong feeling that you are mixing up dimensions and size of the wave. A wave can have up to four dimensions and many items in each dimension. Please be careful what you do with WaveDims(...) != DimSize(...).

Also, you haven't written it in your post, but please consider that calling make/T without the N flag results not in zero rows but 128(!) empty entries as a default value.