//テキストファイルの読み込み bool TextAnalyseW::load( const char *path ) { FILEPOINTER fp; unsigned char temp[2]; if( enable ) release(); fp = FOPEN( path ); if( fp == 0 ) return false; FREAD( temp, 2, fp ); if( temp[0] != 0xff || temp[1] != 0xfe ) { FCLOSE( fp ); return false; } FSIZE( path, fp, strsize ); strsize = ( strsize - 2 ) / sizeof( wchar_t ); buffer = new wchar_t[strsize + 1]; FREAD( buffer, strsize * sizeof( wchar_t ), fp ); FSEEK( fp, 2, SEEK_SET ); FCLOSE( fp ); buffer[strsize] = L'\0'; enable = true; mem = false; pos = buffer; last = buffer + strsize; return true; }
static int narc_read(void *buf, FILE *fp) { struct NARC *self = buf; assert(self != NULL); /* For efficiency, we stash the file pointer so we can lazily load * the contained files - although i'm not sure this is the best * solution */ self->fp = fp; FREAD(fp, &self->header, 1); assert(self->header.chunk_count == 3); /* read the FATB chunk */ FREAD(fp, &self->fatb.header, 1); assert(self->fatb.header.magic == (magic_t)'FATB'); if (ferror(fp) || feof(fp)) { return FAIL; } CALLOC(self->fatb.records, self->fatb.header.file_count); if (self->fatb.records == NULL) { return NOMEM; } FREAD(fp, self->fatb.records, self->fatb.header.file_count); if (ferror(fp) || feof(fp)) { return FAIL; } /* skip the FNTB chunk */ FREAD(fp, &self->fntb.header, 1); assert(self->fntb.header.magic == (magic_t)'FNTB'); if (ferror(fp) || feof(fp)) { return FAIL; } fseeko(self->fp, (off_t)(self->fntb.header.size - sizeof(self->fntb.header)), SEEK_CUR); /* set the data offset */ struct { magic_t magic; u32 size; } fimg_header; FREAD(fp, &fimg_header, 1); assert(fimg_header.magic == (magic_t)'FIMG'); if (ferror(fp) || feof(fp)) { return FAIL; } self->data_offset = ftello(fp); if (self->data_offset == -1) { return FAIL; } return OKAY; }
int ReadFromFile(FILE *fp) { FREAD(&chunkBytes, 8, fp); FREAD(&formatVersion, 4, fp); FREAD(&formatId, 4, fp); FREAD(&channelType, 4, fp); FREAD(&channelNum, 4, fp); FREAD(&samplingFrequency, 4, fp); FREAD(&bitsPerSample, 4, fp); FREAD(&sampleCount, 8, fp); FREAD(&blockSizePerChannel, 4, fp); FREAD(&reserved, 4, fp); if (chunkBytes != 52) { printf("DSF fmt chunkBytes!=52 %llu\n", chunkBytes); return -1; } if (formatVersion != 1) { printf("DSF fmt version!=1 %u\n", formatVersion); return -1; } if (formatId != 0) { printf("DSF fmt formatId!=0 %u\n", formatId); return -1; } if (channelType != 2) { printf("DSF fmt channelType!=2 %u\n", channelType); return -1; } if (channelNum != 2) { printf("DSF fmt channelNum!=2 %u\n", channelNum); return -1; } if (samplingFrequency != 2822400) { printf("samplingFrequency!=2822400 %u\n", samplingFrequency); return -1; } if (bitsPerSample != 1) { printf("DSF fmt bitsPerSample!=1 %u\n", bitsPerSample); return -1; } if (blockSizePerChannel != 4096) { printf("blockSizePerChannel!=4096 %u\n", blockSizePerChannel); return -1; } return 0; }
int AFreadHead (FILE *fp, void *Buf, int Size, int Nv, int Swapb) { double Lbuf[NBUF]; int Nvr, n, Nreq, status; if (Buf == NULL) { /* Skip data */ n = 0; if (FLseekable (fp)) { status = fseek (fp, Size * Nv, SEEK_CUR); if (status) { UTwarn ("AFreadHead: %s", AFM_FilePosErr); longjmp (AFR_JMPENV, 1); } n = Nv; } else { while (n < Nv) { Nreq = MINV (Nv - n, BSIZE (Lbuf) / Size); Nvr = FREAD (Lbuf, Size, Nreq, fp); n += Nvr; if (Nvr < Nreq) break; } } } else { /* Read the data in file byte order */ n = FREAD (Buf, Size, Nv, fp); /* Swap the data if necessary */ if (Size != 1 && UTswapCode (Swapb) == DS_SWAP) VRswapBytes (Buf, Buf, Size, n); } /* Error messages */ if (n < Nv) { if (ferror (fp)) { UTsysMsg ("AFreadHead - %s", AFM_ReadErr); longjmp (AFR_JMPENV, 2); } else { UTwarn ("AFreadHead - %s", AFM_UEoF); longjmp (AFR_JMPENV, 1); } } return (Size * n); }
size_t aread(void *dst, size_t size) { #ifdef WINDOWS if(buffering) { return FREAD(dst, size, ifile); } else { char *dst2 = (char *)dst; if(size > largest_request_pub) abort("Internal error, aread(%d) with largest_request == %d", (int)size, (int)largest_request_pub); if(size > avail) { size_t pending = size; size_t n = (pending - avail) / AIO_MAX_SECTOR_SIZE; if(n * AIO_MAX_SECTOR_SIZE < pending - avail) n++; size_t read = FREAD(io_commit, n*AIO_MAX_SECTOR_SIZE, ifile); memcpy(dst2, read_buffer, avail); pending -= avail; dst2 += avail; if(pending > read) { size_t ret = read + avail; memcpy(dst2, io_commit, read); avail = 0; return ret; } else { memcpy(dst2, io_commit, pending); memcpy(read_buffer, io_commit + pending, read - pending); avail = read - pending; return size; } } else { memcpy(dst2, read_buffer, size); memmove(read_buffer, read_buffer + size, avail - size); avail -= size; return size; } } #else return FREAD(dst, size, ifile); #endif }
int AFfRdI2 (AFILE *AFp, float Dbuff[], int Nreq) { int is, N, i, Nr; UT_int2_t Buf[NBBUF/LW2]; unsigned char *cp; unsigned char t; double g; for (is = 0; is < Nreq; ) { /* Read data from the audio file */ N = MINV (NBBUF / LW2, Nreq - is); Nr = FREAD (Buf, LW2, N, AFp->fp); /* Byte swap and convert to float */ g = AFp->ScaleF; for (i = 0; i < Nr; ++i) { if (AFp->Swapb == DS_SWAP) { cp = (unsigned char *) &Buf[i]; t = cp[1]; cp[1] = cp[0]; cp[0] = t; } Dbuff[is] = (float) (g * Buf[i]); ++is; } if (Nr < N) break; } return is; }
int get_terrasar_thumbnail_data(int thumb_size_x, int thumb_size_y, meta_parameters *meta, void *read_client_info, void *dest_void, int data_type) { ReadTerrasarClientInfo *info = (ReadTerrasarClientInfo*) read_client_info; int ii, jj; int ns = meta->general->sample_count; int sf = meta->general->line_count / thumb_size_y; if (info->multilook) sf *= meta->sar->look_count; float *dest = (float*)dest_void; // Read in the image short int *shorts = MALLOC(sizeof(short int)*ns*2); for (ii=0; ii<thumb_size_y; ii++) { int line = ii*sf; long long offset = (long long) (info->header + line*info->width); FSEEK(info->fp, offset, SEEK_SET); FREAD(shorts, sizeof(short int), ns*2, info->fp); for (jj=0; jj<thumb_size_x; jj++) dest[jj + ii*thumb_size_x] = hypot(shorts[jj*sf*2], shorts[jj*sf*2+1]); asfPercentMeter((float)ii/(thumb_size_y - 1)); } free(shorts); return TRUE; }
int read_brs_client(int row_start, int n_rows_to_get, void *dest_void, void *read_client_info, meta_parameters *meta, int data_type) { // since we set "require_full_load", we should be reading in the // entire image assert(row_start == 0); assert(n_rows_to_get == meta->general->line_count); unsigned char *dest = (unsigned char*)dest_void; ReadBrsClientInfo *info = (ReadBrsClientInfo*)read_client_info; // these will explode if we ever call this fn a second time on // the same data. Shouldn't happen, because we set "require_full_load" assert(info->fp); int ns = meta->general->sample_count; //unsigned char *brs_buf = MALLOC(ns * sizeof(unsigned char)); int ii; // iterate over all rows in the brs for ( ii = 0; ii < n_rows_to_get; ii++ ) FREAD(dest + ii*ns, sizeof(unsigned char), ns, info->fp); fclose(info->fp); info->fp = NULL; //FREE(brs_buf); return TRUE; }
char* bcLoadTextFile(const char* filename) { FILE* file; fopen_s(&file, filename, "rt"); unsigned int size = 0; char* data; if (file) { FSEEK(file, 0, SEEK_END); size = FTELL(file); FSEEK(file, 0, SEEK_SET); data = new char[size+1]; memset(data, 0, size + 1); FREAD(data, size, file); fclose(file); return data; } else { LOG("Failed To Open File: %s\n", filename); } return nullptr; }
/** Returns the next character from the input buffer and fills the buffer if it is empty (similar to * fgetc()). */ static int my_getc( PPOS* ppos ) { assert(ppos != NULL); assert(ppos->fp != NULL); assert(ppos->pos < LINE_BUF_SIZE); if (ppos->buf[ppos->pos] == '\0') { #if 0 if (NULL == FGETS(ppos->buf, sizeof(ppos->buf), ppos->fp)) return EOF; #else int len = FREAD(ppos->buf, sizeof(ppos->buf) - 1, ppos->fp); if (len <= 0) return EOF; ppos->buf[len] = '\0'; #endif ppos->pos = 0; } return (unsigned char)ppos->buf[ppos->pos++]; }
static int READLONG(FILEP fp, unsigned long *lp) { #ifdef HAVE_FNTGZ_SUPPORT unsigned char buf[4]; if (FREAD(fp, buf, 4) != 4) return 0; *lp = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); #else int c; unsigned long l; if ((c = getc(fp)) == EOF) return 0; l = c & 0xff; if ((c = getc(fp)) == EOF) return 0; l |= (c << 8); if ((c = getc(fp)) == EOF) return 0; l |= (c << 16); if ((c = getc(fp)) == EOF) return 0; *lp = (c << 24) | l; #endif return 1; }
void reverse_files(int nof_vars, char* dirname) { varset_t nof_parsets = 1U<<(nof_vars-1); score_t* buffer = malloc(nof_parsets*sizeof(score_t)); int v; for(v=0; v<nof_vars; ++v){ { FILE* fin = open_file(dirname, v, ".slt", "rb"); FREAD(buffer, sizeof(score_t), nof_parsets, fin); fclose(fin); } { FILE* fout = open_file(dirname, v, "", "wb"); varset_t ps = nof_parsets; do { fwrite(buffer + (--ps), sizeof(score_t), 1, fout); } while(ps); fclose(fout); } } free(buffer); }
int AFfRdMulaw (AFILE *AFp, float Dbuff[], int Nreq) { int is, N, i, Nr; UT_uint1_t Buf[NBBUF/LW]; double g; for (is = 0; is < Nreq; ) { /* Read data from the audio file */ N = MINV (NBBUF / LW, Nreq - is); Nr = FREAD (Buf, LW, N, AFp->fp); /* Convert to float */ g = AFp->ScaleF; for (i = 0; i < Nr; ++i) { Dbuff[is] = (float) (g * Mutab[Buf[i]]); ++is; } if (Nr < N) break; } return is; }
int read_terrasar_client(int row_start, int n_rows_to_get, void *dest_void, void *read_client_info, meta_parameters *meta, int data_type) { ReadTerrasarClientInfo *info = (ReadTerrasarClientInfo*) read_client_info; float *dest = (float*)dest_void; int ii, jj, ns = meta->general->sample_count; int skip = 1; if (info->multilook) { skip = meta->sar->look_count; row_start *= skip; } // Read in the image short int *shorts = MALLOC(sizeof(short int)*ns*2); for (ii=0; ii<n_rows_to_get; ii++) { long long offset = (long long) (info->header + (ii*skip + row_start) * info->width); FSEEK(info->fp, offset, SEEK_SET); FREAD(shorts, sizeof(short int), ns*2, info->fp); for (jj=0; jj<ns; jj++) dest[jj + ii*ns] = hypot(shorts[jj*2], shorts[jj*2+1]); } free(shorts); return TRUE; }
static int read_page(demuxer_priv_tt * ogg, int * stream) { ogg_stream_tt * os; int i, serial, segments; char tmp_header[27]; uint8_t sizes[256]; int len, tot = 0; FREAD(ogg->in, 27, tmp_header); if (strncmp(tmp_header, "OggS", 5)) return err_bad_oggs_magic; // including version serial = (tmp_header[14] << 24) | (tmp_header[15] << 16) | (tmp_header[16] << 8) | (tmp_header[17] ); *stream = find_stream(ogg, serial); os = &ogg->os[*stream]; segments = tmp_header[26]; FREAD(ogg->in, segments, sizes); len = os->leftover; for (i = 0; i < segments; i++) { len += sizes[i]; if (sizes[i] != 255) { packet_tt p; p.buf = malloc(len); p.p.len = len; p.p.stream = *stream; p.p.flags = p.p.pts = p.p.next_pts = 0; // Ogg sucks memcpy(p.buf, os->leftover_buf, os->leftover); FREAD(ogg->in, len - os->leftover, p.buf + os->leftover); push_packet(&ogg->s[*stream], &p); tot++; len = 0; os->leftover = 0; } } if (len) { os->leftover_buf = realloc(os->leftover_buf, len); FREAD(ogg->in, len - os->leftover, os->leftover_buf + os->leftover); os->leftover = len; } if (!tot) return read_page(ogg, stream); // this page gave nothing, move on to next page return 0; }
int ReadFromFile(FILE *fp) { FREAD(&chunkBytes, 8, fp); FREAD(&totalFileBytes, 8, fp); FREAD(&medadataOffset, 8, fp); if (chunkBytes != 28) { printf("DSF DSD chunkBytes!=28 %llu\n", chunkBytes); return -1; } if (0x7fffffff < totalFileBytes) { printf("file too large %llu\n", totalFileBytes); return -1; } return 0; }
STATE *fetch_prc_header(char *file) { FILE *fp; char buf[131]; STATE *tmp; int i; char tmpbuf[10][7]; /* Add null strings to end of temporary buffer */ for (i=0; i< 10; i++) tmpbuf[i][6]='\0'; /* Create structure & Add null characters to string fields */ tmp = (STATE *) MALLOC (sizeof(STATE)); tmp->reckey[6]='\0'; tmp->obstyp[6]='\0'; tmp->obslev[6]='\0'; tmp->cmmnt[78]='\0'; /* Open file & skip over id record */ fp = FOPEN(file,"r"); FREAD(buf,130,1,fp); /* Read the header record */ FREAD(buf,130,1,fp); FCLOSE(fp); /* Convert the input buffer */ sscanf(buf,"%6c%6c%6c%6c%6c%2c%2c%4c%4c%4c%c%5c%78c", tmp->reckey, tmpbuf[0], tmpbuf[1], tmp->obstyp, tmp->obslev, tmpbuf[2], tmpbuf[3], tmpbuf[4], tmpbuf[5], tmpbuf[6], &tmp->qualit, tmpbuf[7], tmp->cmmnt); /* Convert tmpbuf strings into numeric values */ tmp->startDate = atof(tmpbuf[0])/10.0; /* Units are 0.1 days */ tmp->endDate = atof(tmpbuf[1])/10.0; /* Units are 0.1 days */ tmp->modid = atoi(tmpbuf[2]); tmp->relid = atoi(tmpbuf[3]); tmp->rmsfit = atoi(tmpbuf[4]); tmp->sigpos = atoi(tmpbuf[5]); tmp->sigvel = atoi(tmpbuf[6]); tmp->tdtutc = atof(tmpbuf[7])/1000.0; /* Units are 0.001 secs */ return(tmp); }
int ReadFromFile(FILE *fp) { FREAD(&chunkBytes, 8, fp); if (0x7fffffff < chunkBytes) { printf("DsfDataChunk too large %llu\n", chunkBytes); return -1; } return 0; }
int firstRecordLen(char *ceosName) { FILE *f; struct HEADER h; f=FOPEN(ceosName,"rb"); /*Open file.*/ FREAD(&h,1,12,f); /*Read first CEOS header.*/ FCLOSE(f); /*Close file*/ return bigInt32(h.recsiz); /*put recsiz in proper endian format & return*/ }
static void ingest_polarimetry_data(char *inFile, char *inBaseName, char *outFile, char band, int create) { FILE *fpIn, *fpOut; meta_parameters *meta = NULL; char tmp[10]; int ii, kk; float *power = NULL; char *byteBuf = NULL; fpIn = FOPEN(inFile, "rb"); append_ext_if_needed(outFile, ".img", NULL); if (create) fpOut = FOPEN(outFile, "wb"); else fpOut = FOPEN(outFile, "ab"); if (create) { meta = import_airsar_meta(inFile, inBaseName, TRUE); meta->general->data_type = REAL32; meta->general->band_count = 1; sprintf(meta->general->bands, "AMP-%c", band); meta->general->image_data_type = IMAGE_LAYER_STACK; } else { meta = meta_read(outFile); meta->general->band_count += 1; sprintf(tmp, ",AMP-%c", band); strcat(meta->general->bands, tmp); } power = (float *) MALLOC(sizeof(float)*meta->general->sample_count); byteBuf = (char *) MALLOC(sizeof(char)*10); airsar_header *header = read_airsar_header(inFile); long offset = header->first_data_offset; FSEEK(fpIn, offset, SEEK_SET); for (ii=0; ii<meta->general->line_count; ii++) { for (kk=0; kk<meta->general->sample_count; kk++) { FREAD(byteBuf, sizeof(char), 10, fpIn); power[kk] = sqrt(((float)byteBuf[1]/254.0 + 1.5) * pow(2, byteBuf[0])); } put_float_line(fpOut, meta, ii, power); asfLineMeter(ii, meta->general->line_count); } FCLOSE(fpIn); FCLOSE(fpOut); meta_write(meta, outFile); if (power) FREE(power); if (byteBuf) FREE(byteBuf); if (meta) meta_free(meta); }
//指定のテキストファイルがユニコードかどうかを判定する(true:ユニコード false:マルチバイト) bool TextAnalyseW::checkUnicode( const char *path ) { FILEPOINTER fp; unsigned char temp[2]; fp = FOPEN( path ); if( fp == 0 ) return false; FREAD( temp, 2, fp ); FCLOSE( fp ); return temp[0] == 0xff && temp[1] == 0xfe; }
PRC_REC *fetch_prc_rec(char *file, int recnum) { FILE *fp; char buf[131]; PRC_REC *tmp; int offset, i; char tmpbuf[20][20]; /* Add null strings to end of temporary buffer */ for (i=0; i< 20; i++) tmpbuf[i][19]='\0'; /* Create structure & Add null characters to string fields */ tmp = (PRC_REC *) MALLOC (sizeof(PRC_REC)); tmp->reckey[6]='\0'; tmp->spare[2]='\0'; /* Open file, skip id and header, seek to recnum record */ fp = FOPEN(file,"r"); offset = 130 + 130 + 130 * recnum; if (fseek(fp,offset,0)!=0) asfPrintError("No state vector found - read past end of file \n"); /* Read the current record */ FREAD(buf,130,1,fp); FCLOSE(fp); /* Convert the buffer */ sscanf(buf,"%6c%7c%c%6c%11c%12c%12c%12c%11c%11c%11c%6c%6c%6c%2c%3c%c%4c%2c", tmp->reckey, tmpbuf[0], &tmp->orbtyp, tmpbuf[1],tmpbuf[2], tmpbuf[3], tmpbuf[4], tmpbuf[5], tmpbuf[6], tmpbuf[7], tmpbuf[8], tmpbuf[9], tmpbuf[10], tmpbuf[11], tmpbuf[12], tmpbuf[13], &tmp->quali, tmpbuf[14], tmp->spare); /* Convert tmpbuf strings into numeric values */ tmp->satid = atoi(tmpbuf[0]); tmp->ttagd = atof(tmpbuf[1]) / 10.0; /* Units are 0.1 days */ tmp->ttagms = strtoll(tmpbuf[2], (char **)NULL, 10); tmp->xsat = strtoll(tmpbuf[3], (char **)NULL, 10); tmp->ysat = strtoll(tmpbuf[4], (char **)NULL, 10); tmp->zsat = strtoll(tmpbuf[5], (char **)NULL, 10); tmp->xdsat = strtoll(tmpbuf[6], (char **)NULL, 10); tmp->ydsat = strtoll(tmpbuf[7], (char **)NULL, 10); tmp->zdsat = strtoll(tmpbuf[8], (char **)NULL, 10); tmp->roll = atof(tmpbuf[9])/1000.0; /* Units are 0.001 degrees */ tmp->pitch = atof(tmpbuf[10])/1000.0; /* Units are 0.001 degrees */ tmp->yaw = atof(tmpbuf[11])/1000.0; /* Units are 0.001 degrees */ tmp->ascarc = atoi(tmpbuf[12]); tmp->check = atoi(tmpbuf[13]); tmp->radcor = atoi(tmpbuf[14]); return(tmp); }
/* may write 1 past buf[totlen]; removes blank pad*/ static int READSTRPAD(FILEP fp, char *buf, int totlen) { char *p; if (FREAD(fp, buf, totlen) != totlen) return 0; p = &buf[totlen]; *p-- = 0; while (*p == ' ' && p >= buf) *p-- = '\0'; return totlen; }
int AFfRdI3 (AFILE *AFp, float Dbuff[], int Nreq) { int is, N, i, Nr, Hbo; UT_int4_t Iv; unsigned char Buf[NBBUF]; unsigned char *cp; unsigned char t; double g; Hbo = UTbyteOrder (); cp = (unsigned char *) &Iv; for (is = 0; is < Nreq; ) { /* Read data from the audio file */ N = MINV (NBBUF/LW3, Nreq - is); Nr = FREAD (Buf, LW3, N, AFp->fp); /* Byte swap and convert to float */ g = AFp->ScaleF; for (i = 0; i < LW3*Nr; i += LW3) { if (AFp->Swapb == DS_SWAP) { t = Buf[i+2]; Buf[i+2] = Buf[i]; Buf[i] = t; } if (Hbo == DS_EL) { cp[0] = 0; cp[1] = Buf[i]; cp[2] = Buf[i+1]; cp[3] = Buf[i+2]; /* Most significant byte */ } else { cp[0] = Buf[i]; /* Most significant byte */ cp[1] = Buf[i+1]; cp[2] = Buf[i+2]; cp[3] = 0; } Dbuff[is] = (float) (g * (Iv / 256)); ++is; } if (Nr < N) break; } return is; }
//--------------------------- static int sys_load_para(U16 sno) { static int cnt=0, init = 0x38732560; if(sys_mem.bFlag==0x5A) if(sys_mem.pbuf!=NULL && sys_mem.size <= SYS_BUF_SIZE) { if (++cnt < 100) return 1; cnt = 0; if(sys_mem.crc==CHECK_CRC(sys_mem.pbuf,sys_mem.size)) return 1; } //msg_out("\nLoad sys.bin"); if(sys_mem.pbuf==NULL)sys_mem.pbuf=(U8*)mem_sys;//malloc(SYS_BUF_SIZE); if(sys_mem.pbuf!=NULL) { FHANDLE fp; fp=FOPEN("sys.bin","r"); if(fp) { FREAD(sys_mem.pbuf,SYS_BUF_SIZE,1,fp); FCLOSE(fp); } else { if (init == 0x38732560) // 只允许系统上电时创建文件 { FS_MSG("\nCreate sys.bin"); fp=FOPEN("sys.bin","w"); if(fp) { memset(sys_mem.pbuf,0xFF,SYS_BUF_SIZE); FWRITE(sys_mem.pbuf,SYS_BUF_SIZE,1,fp); FCLOSE(fp); } } } sys_mem.rCnt++; sys_mem.size=SYS_BUF_SIZE; sys_mem.crc=CHECK_CRC(sys_mem.pbuf,sys_mem.size); sys_mem.bFlag=0x5A; sys_mem.met=0; init = 0; return 1; } return 0; }
void import_gridfloat(char *inBaseName, char *outBaseName) { int i, j; int column_count, row_count; char *flt_file = appendExt(inBaseName, ".flt"); // create the metadata char *meta_filename = appendExt(outBaseName, ".meta"); asfPrintStatus("Building %s ...\n", meta_filename); meta_parameters *meta = read_meta_gridfloat_ext(inBaseName, flt_file, &column_count, &row_count); meta_write(meta, meta_filename); // Now read/write the actual data. Read as INT16, cast to // floats so we can use put_float_line (which will write // INT16 data, since we asked for it in the metadata) char *data_filename = appendExt(outBaseName, ".img"); asfPrintStatus("Reading %s, writing %s ...\n", flt_file, data_filename); float *floats = MALLOC(sizeof(float)*column_count); FILE *fp = FOPEN(flt_file, "rb"); FILE *out = FOPEN(data_filename, "wb"); for (i=0; i<row_count; ++i) { FREAD(floats, sizeof(float), column_count, fp); //if (msbfirst) { for (j=0; j<column_count; ++j) { big32(floats[j]); } //} put_float_line(out, meta, i, floats); asfLineMeter(i,row_count); } fclose(fp); fclose(out); free(data_filename); free(floats); free(flt_file); }
int deviceConnectHardDiskInsert(const char *fileName) { t_nubitcc count; FILE *image = FOPEN(fileName, "rb"); if (image) { fseek(image, Zero32, SEEK_END); count = ftell(image); vhdd.data.ncyl = (t_nubit16)(count / vhdd.data.nhead / vhdd.data.nsector / vhdd.data.nbyte); fseek(image, Zero32, SEEK_SET); allocate(); count = FREAD((void *) vhdd.connect.pImgBase, sizeof(t_nubit8), vhddGetImageSize, image); vhdd.connect.flagDiskExist = True; FCLOSE(image); return False; } else { return True; } }
void bcLoadRawFile(const char* filename, unsigned char** data, unsigned int* size) { FILE* file; fopen_s(&file, filename, "rb"); if (file) { FSEEK(file, 0, SEEK_END); *size = FTELL(file); FSEEK(file, 0, SEEK_SET); *data = new unsigned char[*size]; FREAD(*data, *size, file); fclose(file); } else { LOG("Failed To Open File: %s\n", filename); } }
static int READBYTE(FILEP fp, unsigned char *cp) { #ifdef HAVE_FNTGZ_SUPPORT unsigned char buf[1]; if (FREAD(fp, buf, 1) != 1) return 0; *cp = buf[0]; #else int c; if ((c = getc(fp)) == EOF) return 0; *cp = (unsigned char)c; #endif return 1; }
// 真正读写操作在这里,这套系统类似于HMI,也是回调函数 //===================================================================================== static int met_load_para(U16 sno) { if(met_mem.bFlag==0x5A) if(met_mem.pbuf!=NULL && met_mem.size <= MET_BUF_SIZE) if(met_mem.crc==CHECK_CRC(met_mem.pbuf,met_mem.size)) { if(!sno || (met_mem.met<=sno&&sno<(met_mem.met+MET_MAX_ITEM))) return 1; met_save_para(1); } // msg_out("\nLoad met.bin"); if(met_mem.pbuf==NULL)met_mem.pbuf=(U8*)mem_met;//malloc(MET_BUF_SIZE); if(met_mem.pbuf!=NULL) { FHANDLE fp; memset(met_mem.pbuf,0xFF,MET_BUF_SIZE); fp=FOPEN("met.bin","r"); //原来如此 if(fp) { met_mem.met=(sno/MET_MAX_ITEM)*MET_MAX_ITEM; //FSEEK(fp,met_mem.met*MET_ITEM_SIZE,SEEK_SET); FREAD(met_mem.pbuf,MET_BUF_SIZE,1,fp); FCLOSE(fp); } else { //msg_out("\nCreate met.bin"); fp=FOPEN("met.bin","w"); if(fp) { FWRITE(met_mem.pbuf,MET_BUF_SIZE,1,fp); FCLOSE(fp); } } met_mem.rCnt++; met_mem.met=(sno/MET_MAX_ITEM)*MET_MAX_ITEM + 1; met_mem.size=MET_BUF_SIZE; met_mem.crc=CHECK_CRC(met_mem.pbuf,met_mem.size); met_mem.bFlag=0x5A; return 1; } return 0; }