Reading TDMS file's metadata With C

0

I have a question about NI's .tdms file reading....

I read the TDMs File Format Internal Structure on NI Website. and i wrote some codes in order to convert .TDMS files into .txt files.

(http://www.ni.com/white-paper/5696/en/#toc2)

I tried open .tdms file with hex-edit program, Python codes and i got helped by other great people.

(https://github.com/petebachant/pyTDMS/blob/master/pytdms.py)
(https://cboard.cprogramming.com/c-programming/176922-reading-specific-data-tdms-files-save-text-file.html)

Finally, I understand the TDMS file's binary structure. It can be described like this.

(lead data) -> (meta data) -> (raw data) -> (lead data) -> .... -> End of file

Similarly, Meta data has own structure. It would be like this. (number of Object)-> (Object)-> (Properties)

The real problem is... When i read meta data, it goes well until meet below sentence...

"If the raw data index of this object in this segment exactly matches the index the same object had in the previous segment, an unsigned 32-bit integer (0x0000000) will be stored instead of the index information."

I would like to get below codes in C... but i dont know how to... c

from Line 216 ~ (https://github.com/petebachant/pyTDMS/blob/master/pytdms.py)

elif (rawdataindex==0x00000000):
    rawdata = object_rawdata[objectpath]

And this is how i did. I used a lot of 'if'... still it doesn't work..

My question is there any better way to deal with it?

from Line 178 ~

uint32_t rawdataidx;
                    fread(&rawdataidx, sizeof rawdataidx, 1, f);
                    printf("rawdataidx : %" PRIu32 "\n", rawdataidx);

                    printf("af pos rawdataidx : %" PRIu32 "\n", ftell(f));

                    if (rawdataidx == 0xFFFFFFFF)
                    {
                        printf("There is no rawdata for this\n");
                    }
                    else if (rawdataidx == 0) // if the rawdataindex is  0x00000000 this will work....
                    {
                        printf("dataType : %" PRIu32 "\n", prevdatatype);

                        if (prevdatatype == tdsTypeSingleFloat) { // 더블
                            Datatype_Float = 1;
                            fprintf(files[fileidx], "Datatype_Float \n");
                            objrawcnt++;
                        }
                        else if (prevdatatype == tdsTypeDoubleFloat) { // 더블
                            Datatype_Double = 1;
                            fprintf(files[fileidx], "Datatype_Double \n");
                            objrawcnt++;
                        }
                        else {
                            printf("what im gonna do...\n");
                            return 0;
                        }
                        printf("Dimensionrawarray: %" PRIu32 "\n", prevDimensionarray);

                        printf("numrawdata: %" PRIu32 "\n", prevnumrawdata);

                        numraw = prevnumrawdata;

                        fprintf(files[fileidx], "%d \n", numraw);

                    }
                    else
                    {
                        rawobjcnt++;
                        uint32_t dataType = 0;
                        fread(&dataType, sizeof dataType, 1, f);
                        printf("dataType : %" PRIu32 "\n", dataType);
                        prevdatatype = dataType;
                        if (dataType == tdsTypeVoid) {            //보이드
                                                                  //goto TYPEVOID;
                            //TYPEVOID:;

                        }
                        else if (dataType == tdsTypeSingleFloat){ // 더블
                            Datatype_Float = 1;
                            fprintf(files[fileidx], "Datatype_Float \n");
                            objrawcnt++;
                        }
                        else if (dataType == tdsTypeDoubleFloat){ // 더블
                            Datatype_Double = 1;
                            fprintf(files[fileidx], "Datatype_Double \n");
                            objrawcnt++;
                        }
                        else{
                            printf("what im gonna do...\n");
                            return 0;
                        }
                        uint32_t Dimensionrawarray; // must be 1
                        fread(&Dimensionrawarray, sizeof Dimensionrawarray, 1, f);
                        printf("Dimensionrawarray: %" PRIu32 "\n", Dimensionrawarray);
                        prevDimensionarray = Dimensionrawarray;

                        uint64_t numrawdata = 0; //rawdata 갯수
                        fread(&numrawdata, sizeof numrawdata, 1, f);
                        printf("numrawdata: %" PRIu32 "\n", numrawdata);

                        printf("pos numrawdata : %" PRIu32 "\n", ftell(f));

                        numraw = numrawdata;

                        rawarr[rawobjcnt] = numrawdata;

                        fprintf(files[fileidx], "%d \n",numraw);

                        prevnumrawdata = numrawdata;
                    }

I really appreciate with your helps!

Happy new year!

c
labview
asked on Stack Overflow Jan 16, 2019 by Pikle • edited Jan 16, 2019 by Pritamkumar

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0