📄 gdf2scp.c
字号:
/* $Id: gdf2scp.c,v 1.3 2006/05/15 09:57:02 schloegl Exp $ Copyright (C) 2000,2005 Alois Schloegl <a.schloegl@ieee.org> This function is part of the "BioSig for C/C++" repository (biosig4c++) at http://biosig.sf.net/ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* reading and writing of GDF files is demonstrated */#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "biosig.h"/****************************************************************************//** **//** UTILITY FUNCTIONS **//** **//****************************************************************************/ /****************************************************************************//** **//** MAIN FUNCTION **//** **//****************************************************************************/ int main (int argc, char **argv){/* currently, its used for testing SOPEN, SREAD, SWRITE, SEOF, STELL, SCLOSE, SSEEK*/#define NELEM (1<<15) unsigned k; uint32_t k1; uint16_t s[NELEM]; uint8_t tmp; int32_t s32; FILE *fid; HDRTYPE *hdr, hdr2; CHANNEL_TYPE* cp; size_t count; int status; char help[] = "\n Usage of BIOSIG:\n\n\tbiosig -h\t\thelp - this text\n\tbiosig filename\t\tread file if available; if not available generate file\n\n\n"; time_t T0; struct tm t0; if (argc < 2) { fprintf(stderr,"Warning: Invalid number of arguments\n"); return(-1); } if (!strncmp(argv[1],"-h",2)) { fprintf(stdout,"%s",help); return(0); } hdr = sopen(argv[1], "r", NULL); if (hdr==NULL) exit(-1); fprintf(stdout,"FileName:\t%s\nType :\t%i\nVersion:\t%4.2f\nHeadLen:\t%i\n",argv[1],hdr->TYPE,hdr->VERSION,hdr->HeadLen); fprintf(stdout,"NS:\t%i\nSPR:\t%i\nNRec:\t%Li\nDuration[s]:\t%u/%u\nFs:\t%f\n",hdr->NS,hdr->SPR,hdr->NRec,hdr->Dur[0],hdr->Dur[1],hdr->SampleRate); T0 = gdf_time2t_time(hdr->T0); fprintf(stdout,"Date/Time:\t%s\n",asctime(localtime(&T0))); //T0 = gdf_time2t_time(hdr->Patient.Birthday); //fprintf(stdout,"Birthday:\t%s\n",asctime(localtime(&T0))); fprintf(stdout,"Patient:\n\tName:\t%s\n\tId:\t%s\n\tWeigth:\t%i kg\n\tHeigth:\t%i cm\n\tAge:\t%4.1f y\n",hdr->Patient.Name,hdr->Patient.Id,hdr->Patient.Weight,hdr->Patient.Height,(hdr->T0 - hdr->Patient.Birthday)/ldexp(365.25,32)); T0 = gdf_time2t_time(hdr->Patient.Birthday); fprintf(stdout,"\tBirthday:\t%s\n",asctime(localtime(&T0))); fprintf(stdout,"EVENT:\n\tN:\t%i\n\tFs:\t%f\n\t\n",hdr->EVENT.N,hdr->EVENT.SampleRate); fprintf(stdout,"--%i\t%i\n", hdr->FLAG.OVERFLOWDETECTION, hdr->FLAG.UCAL); hdr->FLAG.OVERFLOWDETECTION = 0; // hdr->FLAG.UCAL = 1; fprintf(stdout,"--%i\t%i\n", hdr->FLAG.OVERFLOWDETECTION, hdr->FLAG.UCAL); fprintf(stdout,"2-%u\t%i\t%i\t%i\t%u\t%u\n",hdr->AS.bpb,hdr->FILE.OPEN,(int32_t)hdr->NRec,hdr->HeadLen,hdr->Dur[0],hdr->Dur[1]); for (k=0; k<hdr->NS; k++) { cp = hdr->CHANNEL+k; fprintf(stdout,"\n#%2i: %7s\t%s\t%s\t%i\t%5f\t%5f\t%5f\t%5f\t",k,cp->Label,cp->Transducer,cp->PhysDim,cp->PhysDimCode,cp->PhysMax,cp->PhysMin,cp->DigMax,cp->DigMin); fprintf(stdout,"%4.0f\t%4.0f\t%4.0f\t%5f Ohm",cp->LowPass,cp->HighPass,cp->Notch,cp->Impedance); }fprintf(stdout,"\nGDF OPENED: SUCCESSFULLY\n",ftell(hdr->FILE.FID)); count = sread(hdr,0,hdr->NRec);fprintf(stdout,"m1: %i %f %f %f %f\n",count,hdr->data.block[0],hdr->data.block[1],hdr->data.block[2],hdr->data.block[3]);fprintf(stdout,"GDF CLOSED: SUCCESSFULLY\n");// Must not be closed because fields in hdr must not be de-allocated // status = sclose(hdr); if (hdr->FILE.OPEN) { fclose(hdr->FILE.FID); hdr->FILE.FID = 0; }; //TODO: scaling // OPEN and WRITE SCP FILE hdr->TYPE = SCP_ECG; sopen(argv[2], "w", hdr);fprintf(stdout,"SCP OPEN: SUCCESSFULLY\n");#if 0 //__BYTE_ORDER == __BIG_ENDIAN // fix endianity of the data for (k1=0;k1<hdr->NRec*hdr->SPR*hdr->NS;k1++) { hdr->data.block[k1] = l_endian_f64(hdr->data.block[k1]); *(int32_t*)(hdr->AS.rawdata+k1*4) = l_endian_i32(*(int32_t*)(hdr->AS.rawdata+k1*4)); }#endif // fwrite(hdr->AS.rawdata, 4 ,hdr->NRec*hdr->SPR*hdr->NS, hdr->FILE.FID);fprintf(stdout,"data written\n");// fwrite(hdr->data.block, sizeof(biosig_data_type),hdr->NRec*hdr->SPR*hdr->NS, hdr->FILE.FID);// swrite(&s, NELEM/hdr->NS, hdr); status = sclose(hdr);fprintf(stdout,"SCP CLOSED: SUCCESSFULLY\n"); fprintf(stdout,"1-%i\t%i\t%i\t%i\t%u\t%u\n",sizeof(hdr->EVENT.TYP),sizeof(*hdr->EVENT.TYP),(int32_t)hdr->NRec,hdr->HeadLen,hdr->Dur[0],hdr->Dur[1]); free(hdr); return(status);};/****************************************************************************//** **//** EOF **//** **//****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -