Results 1 to 3 of 3

Thread: Read binary from file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Read binary from file

    Hello All.
    I have source of already wrote program on Borland C++, but I can't convert it to QT4.
    I need read data from file. I include full overview about file format into zip file and less below.
    I use mdi sample and rewrite function openFile(), and it's work:
    Qt Code:
    1. void MdiChild::openFile(QString curFile){
    2. isUntitled = true;
    3. setWindowTitle(curFile + "[*]");
    4. QFile file(curFile);
    5. QApplication::setOverrideCursor(Qt::WaitCursor); //курсор в режим ожидания
    6. if(!file.open(QIODevice::ReadOnly))
    7. {
    8. QMessageBox::warning(this, tr("Spreadsheet"),
    9. tr("Cannot open file %1:\n%2.")
    10. .arg(curFile)
    11. .arg(file.errorString()));
    12. }
    13. else
    14. {
    15. QDataStream in(&file);
    16. }
    17. QApplication::restoreOverrideCursor(); //курсор в нормальный режим
    18. file.close();
    19. }
    To copy to clipboard, switch view to plain text mode 

    But I don't know how write code witch I have already in Borland. I don't understand how read binary file. Maybe I don't need source on Borland, and I can write other program:
    Qt Code:
    1. void TMainForm::vOpenDSPZdata(){
    2. Chart->Title->Text->Clear();
    3. Chart->Title->Text->Add("Converting to DSP data format");
    4. int NF = OpenMultiDialog->Files->Count;
    5.  
    6. for (int nf=0;nf<NF;nf++){
    7.  
    8. FLName=OpenMultiDialog->Files->Strings[nf];
    9. FH=FileOpen(FLName,fmOpenRead);
    10. if(FH==-1){ShowMessage("Error with FileOpen");return;}
    11.  
    12. FSName = ExtractFileName(OpenMultiDialog->Files->Strings[nf]);
    13. FSName = FSName.SubString(0,FSName.Length()-4)+".dsp";
    14. FSName = ExtractFilePath(FLName) + FSName;
    15. filec = 0;
    16. file_razmer = FileSeek(FH,filec,2);
    17. FileSeek(FH,0,0);
    18. FileRead(FH,&Q.fh, sizeof Q.fh);
    19. Q.fh2dspp(66000,0,0);
    20. Q.allocate_spectr();
    21. n_vib = (file_razmer - (sizeof Q.fh))/(sizeof 4*2*Q.nDSPZ);
    22. Memo->Lines->Add(">Open file name : " + FLName);
    23. Memo->Lines->Add(">Saving file name : " + FSName);
    24. Memo->Lines->Add(">File size : " + IntToStr(file_razmer) + " Byte");
    25. Memo->Lines->Add(">sizeof header : " + IntToStr(sizeof Q.fh) + " Byte");
    26. Memo->Lines->Add(">sizeof spectr : " + IntToStr(sizeof 4*2*Q.nDSPZ) + " Byte");
    27. Memo->Lines->Add(">Count of spectra : " + IntToStr(n_vib));
    28. Memo->Lines->Add(">Count of chanel DSPZ: " + IntToStr(Q.nDSPZ));
    29. Memo->Lines->Add(">Resolution DSPZ: " + FloatToStrF(Q.dspp.NAvr * Q.NDSPZ * 1./ Q.dspp.frcl,ffFixed,8,2) + " ms");
    30. Memo->Lines->Add(">Averaging factor DSPZ: " + IntToStr(Q.dspp.NAvr));
    31. Memo->Lines->Add(">Resolution DSP: " + FloatToStrF(Q.dspp.NAvr * Q.NDSPZ * 1./ Q.dspp.frcl , ffFixed,8,2) + " ms");
    32. Memo->Lines->Add(Q.fh.time);
    33. astr="";
    34. for (i=0;i<16;i++){
    35. astr+= IntToStr(i) + ": " + Q.fh.syst[i] + " ";
    36. }
    37. Memo->Lines->Add("> "+ astr);
    38. Memo->Lines->Add(Q.fh.desc);
    39. int Naver;
    40. if (OF->nAverCB->Checked && n_vib>Naver)
    41. Naver = StrToInt(OF->nAverEdit->Text);
    42. else Naver = n_vib;
    43. Memo->Lines->Add(">Number of spectr for DSP file: " + IntToStr(Naver));
    44. Naver=10;
    45. for(i=0;i<Naver;i++){
    46. FileRead(FH,Q.spectr, sizeof 4*2*Q.nDSPZ);
    47. Q.get_spectrAB_prop();
    48. SeriesShow();
    49. if (!((i+1)%100)){
    50. Caption = CaptInfo + " file# " + IntToStr(nf+1) + "/" + IntToStr(NF) +
    51. " - " + IntToStr(i*100/Naver) + "%";
    52. SeriesShow();
    53. Sleep(20);
    54. Application->ProcessMessages();
    55. }
    56. }
    57.  
    58. Application->ProcessMessages();
    59.  
    60. FileClose(FH);
    61. }//nf
    62. }
    To copy to clipboard, switch view to plain text mode 
    Where DSPZ Q and DSP W
    Qt Code:
    1. class DSP{
    2. public:
    3. DBUFFH fh;
    4. DBUFSP sp;
    5. int nDSP;
    6. DSP::DSP();
    7. DSP::~DSP();
    8. int intLEtoBE(int le);
    9. int intfLEtoBE(float fl);
    10. float floatLEtoBE(int le);
    11. float getchA(int k);
    12. float getchB(int k);
    13. private:
    14. int i,j;
    15. float tmp;
    16.  
    17. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. class DSPZ{
    2. public:
    3. int nDSPZ;
    4. int NDSPZ;
    5. DSP_FH fh;
    6. int *spectr;
    7. float *chA,*chB;
    8. SPECTR_PROP spp;
    9. DSPP_PROP dspp;
    10. DSPZ::DSPZ();
    11. DSPZ::~DSPZ();
    12. void get_spectrAB_prop();
    13. void allocate_spectr();
    14. void fh2dspp(float freqclock, int winchA, int winchB);
    15. private:
    16. int i,j;
    17. float tmp;
    18. };
    To copy to clipboard, switch view to plain text mode 

    The file header is placed at begin of the file (0x0h offset). File header has size 1024 bytes and contains following fields:
    In “C”-language notation header can by considered as structure:
    Qt Code:
    1. typedef struct FHEADER_Tag
    2. {
    3. char name[32];
    4. char time[32];
    5. char gmtt[32];
    6. char sysn[32];
    7. char syst[32];
    8. char place[96];
    9. char desc[256];
    10. DWORD PP[128];
    11. DWORD DSPP[384];
    12. } FHEADER;
    To copy to clipboard, switch view to plain text mode 
    In the “C”-language notation processing parameters structure PP can by considered as following structure:
    Qt Code:
    1. typedef struct UP_EXCH_Tag //DSP parameters
    2. {
    3. DWORD mode; //mode of operation
    4. DWORD size; //size of DMA data block
    5. DWORD prc_mode; //processing parameters
    6. DWORD tst_gen; //not used
    7. DWORD clk; //not used
    8. DWORD fft_size; //used for data trasferering
    9. }UP_EXCH;
    To copy to clipboard, switch view to plain text mode 
    In the “C”-language notation processing parameters structure PP can by considered as following structure:
    Qt Code:
    1. typedef struct DSPP_tag //DSP processing parameetrs
    2. {
    3. int FFT_Size; //for using in the DSP
    4. int MinDSPSize; // for using in the DSP
    5. int MinDMASize; // for using in the DSP
    6. int DMASizeCnt; // for using in the DSP
    7. int DMASize; // for using in the DSP
    8. float CLCfrq;
    9. int Synch;
    10. int SSht;
    11. int Mode;
    12. int Wch;
    13. int Smd;
    14. int Offt,
    15. int Lb;
    16. int Hb;
    17. int Wb;
    18. int NAvr;
    19. BOOL CAvr;
    20. BOOL Weight;
    21. BOOL DCRem;
    22. BOOL ExtSyn;
    23. BOOL Ch1;
    24. BOOL Ch2;
    25. BOOL ExtWin;
    26. int Clip;
    27. //RF parts
    28. int HPF0;
    29. int HPF1;
    30. int LPF0;
    31. int LPF1;
    32. int ATT0;
    33. int ATT1;
    34. } DSPP;
    To copy to clipboard, switch view to plain text mode 

    Just after file header, the data follow. So, the data offset in the file is 0x400h. In the Spectrum Mode (Mode=1) the Wb pair of samples (spectrum lines) are stored. First sample is from A channel, and second sample is from B channel (see (2) and (4) on Fig.I.1). Just after 2*Wb samples of the spectrum the next 2*Wb spectrum samples are stored… and so on.

    Each FFT sample (SSAMPLE) has 4 byte size SSAMPLE is in the DSP floating point format. To get the sample presented in conventional floating point format (FLOAT_NUM) one should apply the following transformation (in “C” notation):
    Fig.1 Data sequence in the “Spectrum” mode
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. cannot execute binary file
    By mgturner in forum Installation and Deployment
    Replies: 1
    Last Post: 16th March 2009, 18:04
  2. QFile can't read a file
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2009, 21:24
  3. can`t read a binary data!
    By blm in forum Qt Programming
    Replies: 8
    Last Post: 18th September 2008, 17:56
  4. Read binary file and convert to QString
    By jaca in forum Qt Programming
    Replies: 12
    Last Post: 14th June 2008, 00:05
  5. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 19:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.