⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readmcs_1.c

📁 处理激光雷达数据
💻 C
字号:
/***************************************************************************/
/*        Sample program compatible with Microsoft and Borland C           */
/*	   to read header and channel data from a MCS data file 	               */
/***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define  MCS   -4
void readmcs_1(char *pname,float temp[])
{
   char 	  reserved[100];  /* buffer to skip reserved bytes */
   short int		  f_type;	  /* MCS file type */
   char 	  trigger;	  /* Trigger Flag */
   char		  dwell_flag;	  /* External Dwell Flag */
   char		  dwell_units;	  /* 0=us, 1=ms, 2=sec, 3=ns */
   char		  acq_mode;	  /* Acquisition mode flag 0=replace, 1=sum */
   unsigned long  dwell_913;	  /* Dwell time in old 913 format */
   unsigned short int   pass_length;    /* pass length in channels */
   unsigned long  pass_count;
   unsigned long  pass_count_preset;
   char 	  acq_time[9];    /* buffer for acquisition time */
   char 	  acq_date[9];    /* buffer for acquisition date */
   unsigned short int   mark_chan;	  /* first marker channel */
   char		  mcs_num;        /* 1-8 are valid  */
   char		  cal_flag;	  /* 0=no calibration */
   char		  cal_units[4];	  /* calibration units */
   float	  cal_zero;	  /* calibration zero intercept */
   float	  cal_slope;	  /* calibration slope */
   char		  id_byte;	  /* always 0xaa */
   char		  detector_len;	  /* Detector description length */
   char		  detector[64];	  /* detector description */
   char		  sample_len;	  /* Sample description length */
   char		  sample[64];	  /* Sample description */
   char		  disc_sel;	  /* 0=SCA otherwise Disc */
   char		  disc_edge;	  /* 0=falling else rising */
   float	  disc;		  /* disc setting in volts */
   float	  sca_uld;	  /* sca upper-level in volts */
   float	  sca_lld;	  /* sca lower-level in volts */
   float	  dwell;	  /* dwell time in dwell_units */
   char		  consistant;	  /* settings consistant flag */
   char		  mcs_id[9];	  /* MCS ID string "0914-001" */
   unsigned long  chan_data;      /* stores channel data */

   unsigned short int   count;          /* general purpose loop counter  */

   FILE  *f_pointer, *fout;
//   int argc=2;

//   if (argc != 2) {
//      printf("USAGE:readmcs filename.MCS\n");
//      exit(1);
//   }
//   printf("please input the filename!\n");
//   scanf("%s",filename);


   f_pointer = fopen(pname,"rb");
   fout=fopen("result.dat","w");

/***************************************************************************/
/*                            Header Data                                  */
/*		    Read header info from MCS file			   */
/***************************************************************************/
/* Read filetype -4 (MCS) */
   fread(&f_type,sizeof(short int),1,f_pointer);
//   printf("%d\n",f_type);
   if (f_type != MCS) {
      printf("Not a valid file\n");
      exit(1);
   }
   fread(&trigger,sizeof(char),1,f_pointer);	/* Read Trigger Flag */
   fread(&dwell_flag,sizeof(char),1,f_pointer);	/* Read dwell flag */
   fread(&dwell_units,sizeof(char),1,f_pointer);/* Read dwell units */
   fread(&acq_mode,sizeof(char),1,f_pointer);
   fread(&dwell_913,sizeof(long),1,f_pointer);
   
   fread(&pass_length,sizeof(unsigned short int),1,f_pointer);
   fread(&pass_count,sizeof(long),1,f_pointer);
   fread(&pass_count_preset,sizeof(long),1,f_pointer);
   fread(acq_time,sizeof(char),8,f_pointer);
   fread(acq_date,sizeof(char),8,f_pointer);
   fread(&mark_chan,sizeof(unsigned short int),1,f_pointer);
   fread(&mcs_num,sizeof(char),1,f_pointer);
   fread(&cal_flag,sizeof(char),1,f_pointer);
   fread(cal_units,sizeof(char),4,f_pointer);
   fread(&cal_zero,sizeof(float),1,f_pointer);
   fread(&cal_slope,sizeof(float),1,f_pointer);
   fread(reserved,sizeof(char),10,f_pointer);
   fread(&id_byte,sizeof(char),1,f_pointer);
   fread(reserved,sizeof(char),1,f_pointer);
   fread(&detector_len,sizeof(char),1,f_pointer);
   fread(detector,sizeof(char),63,f_pointer);
   fread(&sample_len,sizeof(char),1,f_pointer);
   fread(sample,sizeof(char),63,f_pointer);
   fread(reserved,sizeof(char),16,f_pointer); /* skip view info & reserved */
   fread(&disc_sel,sizeof(char),1,f_pointer);
   fread(&disc_edge,sizeof(char),1,f_pointer);
   fread(&disc,sizeof(float),1,f_pointer);
   fread(&sca_uld,sizeof(float),1,f_pointer);
   fread(&sca_lld,sizeof(float),1,f_pointer);
   fread(&dwell,sizeof(float),1,f_pointer);
   fread(&consistant,sizeof(char),1,f_pointer);
   fread(reserved,sizeof(char),21,f_pointer);
   fread(mcs_id,sizeof(char),8,f_pointer);

   mcs_id[8]=0;
//   printf("MCS%2i,  MCS_ID = %8s\n",mcs_num+1,mcs_id);

//   printf("Pass Length= %5i, Pass Count = %10li, Pass Count Preset = %10li\n",
//      pass_length,pass_count,pass_count_preset);

/*   if (dwell_flag == 0) {
      printf("Dwell Time = %13.7g",dwell);
      if (dwell_units==0) printf("us\n");
      else if (dwell_units==1) printf("ms\n");
      else if (dwell_units==2) printf("s\n");
      else printf("ns\n");
   } else printf("Dwell Time = External\n");

   if (trigger==0) printf("Trigger = Internal, ");
   else printf("Trigger = External, ");    

   if (acq_mode==0) printf(" Acquisition Mode = Replace\n");
   else printf(" Acquisition Mode = Sum\n");

   acq_time[8]=0;
   acq_date[8]=0;
//   printf("Data collected at %8s on %8s\n",acq_time,acq_date);

   if (cal_flag==0) printf("Spectrum is not Calibrated\n");
   else printf("Calibration Slope = %13.7g,  Offset = %13.7g,  units=%.4s\n",
	cal_slope,cal_zero,cal_units);

   if (detector_len==0) printf("No hardware description\n");
   else {
      printf("Hardware Description:\n");
      for (count=0; count < (unsigned)detector_len; count++)
	 putchar(detector[count]);
      printf("\n");
   }

   if (sample_len==0) printf("No sample description\n");
   else {
      printf("Sample Description:\n");
      for (count=0; count < (unsigned)sample_len; count++)
	 putchar(sample[count]);
      printf("\n");
   }

   if (disc_sel == 0) {
      printf("SCA Selected:  LLD=%13.7gV,  ULD=%13.7gV\n",sca_lld,sca_uld);
   } else {
      printf("Disc Selected: Voltage=%13.7gV,  ",disc);
      if (disc_edge==0) printf("Edge=Falling\n");
      else printf("Edge=Rising\n");
   }*/

   if (consistant==0)
      printf("WARNING:  Settings are not consistant with data\n");

/***************************************************************************/
/*                            Channel Data                                 */
/*		    Output channel data from MCS file			                        */
/***************************************************************************/
   //printf("CHANNEL    DATA\n");
   for (count = 0; count < pass_length; count++)
    {
     // if ((count % 6 ) == 0)
     //   {        /* Every 6 channels do a newline and */
    //	 printf ("\n%7i",count);    /* and print the channel number */
   //	}
      fread(&chan_data,sizeof(long),1,f_pointer);
  //    printf("%11lu",chan_data);
      fprintf(fout,"%7i     %11lu\n",count,
      chan_data);
	  temp[count]=chan_data;
   }
//   printf(" \n   ! Result datafile: result.dat.\n");
   fclose(f_pointer);
   fclose(fout);

}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -