From 059831534c7e884f0a607ed86b582fd00d821731 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Sat, 26 Sep 2026 23:24:03 +0200 Subject: New upstream version 3.2.0~rc1+dfsg --- qmap/getfile.cpp | 78 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 38 deletions(-) (limited to 'qmap/getfile.cpp') diff --git a/qmap/getfile.cpp b/qmap/getfile.cpp index 644d4b05..dc29b279 100644 --- a/qmap/getfile.cpp +++ b/qmap/getfile.cpp @@ -1,11 +1,11 @@ #include "getfile.h" -#include -#include +#include +#include +#include +#include #include #include -extern qint16 id[2*60*96000]; - void getfile(QString fname, int dbDgrd) { // int npts=2*56*96000; @@ -16,34 +16,36 @@ void getfile(QString fname, int dbDgrd) if(dbDgrd<0) dgrd = 23.0*sqrt(pow(10.0,-0.1*(double)dbDgrd) - 1.0); float fac=23.0/sqrt(dgrd*dgrd + 23.0*23.0); - memset(id,0,2*npts); - char name[80]; - strcpy(name,fname.toLocal8Bit()); - FILE* fp=fopen(name,"rb"); + QFile file(fname); - if(fp != NULL) { - auto n = fread(&datcom_.fcenter,sizeof(datcom_.fcenter),1,fp); - n=fread(id,2,npts,fp); - n=fread(&datcom_.ntx30a,4,1,fp); - n=fread(&datcom_.ntx30b,4,1,fp); - if(n==0) { - datcom_.ntx30a=0; - datcom_.ntx30b=0; - } + if(file.open(QIODevice::ReadOnly)) { + file.read(reinterpret_cast(&datcom_.fcenter), sizeof(datcom_.fcenter)); + std::array samples; int j=0; - - if(dbDgrd<0) { - for(int i=0; i(samples.size(),npts-j); + qint64 bytes_read=file.read(reinterpret_cast(samples.data()), + want * static_cast(sizeof(qint16))); + size_t n=bytes_read > 0 + ? static_cast(bytes_read / static_cast(sizeof(qint16))) + : 0; + for(size_t i=0; i(want)) break; + } + while(j(sizeof(datcom_.ntx30a)); + bool read_ntx30a=file.read(reinterpret_cast(&datcom_.ntx30a), + ntx30_size) == ntx30_size; + bool read_ntx30b=file.read(reinterpret_cast(&datcom_.ntx30b), + ntx30_size) == ntx30_size; + if(!read_ntx30a || !read_ntx30b) { + datcom_.ntx30a=0; + datcom_.ntx30b=0; } - fclose(fp); datcom_.ndiskdat=1; // int nfreq=(int)datcom_.fcenter; @@ -59,23 +61,23 @@ void getfile(QString fname, int dbDgrd) void save_iq(QString fname) { int npts=2*60*96000; - qint16* buf=(qint16*)malloc(2*npts); - char name[80]; - strcpy(name,fname.toLocal8Bit()); - FILE* fp=fopen(name,"wb"); + std::vector buf(npts); + QFile file(fname); - if(fp != NULL) { - fwrite(&datcom_.fcenter,sizeof(datcom_.fcenter),1,fp); + if(file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + file.write(reinterpret_cast(&datcom_.fcenter), + sizeof(datcom_.fcenter)); int j=0; for(int i=0; i(buf.data()), + static_cast(buf.size() * sizeof(qint16))); + qint64 ntx30_size=static_cast(sizeof(datcom_.ntx30a)); + file.write(reinterpret_cast(&datcom_.ntx30a), + 2 * ntx30_size); } - free(buf); } /* Generate gaussian random float with mean=0 and std_dev=1 */ -- cgit v1.2.3