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

📄 readme.bison2su

📁 su 的源代码库
💻 BISON2SU
字号:
Hello John,here is my conversion program for the BISON-2 land seismic recordingapparatur. I appended most of the specification below. The other half restsas comments in the program (it is not really much).I tried to be think of all the headers, but I wasn't sure of some of them.I hate to convert a normal date to julian days, so no date, time etc.The extended headers mentioned in the specs are also not covered; franklyI don't understand it. I hope the code is clear, it is not dificult.Here are some remarks:In order to read the characters in the headers I overwrite the carriage returnwith a \0 in the character constants (had nothing better).The trace struct is a combination from a union of 2-byte shorts with 4-bytelongs and the data field, it's the way we did it in the FORTRAN times.In the original data there are 538 bytes of header data followed by channel* 48 bytes channel header data. After that there are two bytes, and afterthat all the data follows.I appended the swapping routines from swapbyte.c. It was quick thing, but Itested it on a SUN with the gcc compiler and it worked, I guess there shouldappear no problems on an IBM.compile > cc bison2su.c -lm -o bison2surun >     bison2su < infile > outfile          PC	  bison2su < infile swap > outfile     SUN,IBMI have one example shot file in two formats, word format and float formatthat I place on our local ftp-server, ftp.dkrz.de (136.172.110.11) in/pub/Incoming/hartmann. The files are named 218.f and 218.w (transfer inbinary mode).Somehow the word format and the float format don't end up the same afterthe conversion, I checked and double checked. I haven't found anything.I guess it has something to do with different overall dynamic between 2-byteshorts and 2-byte+4-bit floats.Unfortunately I have no access to the apparatur at the moment, as this wasa program I made for a friend who used it. I know that the BISON apparatur isvery common, so if You want to use this code there might be other people tohelp out with some more details.If You have questions, feel free to ask.Jens*****************************************************************************BISON-2 RS232 DATA FORMATSThis format is in the spirit of the BISON-1 SEg engeneering data format butgreatly expanded. Each item in the header is variable length and ends with anASCII carriage return (0DH) and line feed (0AH).All header constants are 8 bit ASCII with the most significant bit cleared.All letters are upper case.The BISON format has the following features to make writing software that usesit as painless as possible.	1. The same data and basic header formats are used for all 5000 series	   instruments regardless of their different resolutions.	2. The BISON-2 format is identical to the SEG-I format from the	   beginning up to the manufacturers code and similiar throughout. All	   items not in the BISON-1 format are immediately after the	   manufacturer code (BISON-2) and before the number of channels.	3. The n-nth item in the header is always immediately after the (n-1)th	   CR and LF character (0DH,0AH).	4. The first data sample is always immediately after the first two	   ASCII ETX (03H) characters.	5. The entire header is readable ASCII, there are no encoded values to	    look up.	6. Swith type alphanumerix parameters. For example, data format type	   (L)ong have unique first letters to make string evaluation easier.	7. There is provision for an extended header format where each item	   after the software version number is supplied separately for each	   channel of the record. In this case, each channel header is	   identical to the standard form starting after the version number	   and following CR, LF.***************************************************************************/* program bison2su.c */#include <stdlib.h>#include <stdio.h>#include <math.h>#include <string.h>/*  Jens Hartmann 21.6.93                              *//*  Institut fuer Geophysik Hamburg                    */void swap_short_2(short *tni2);void swap_long_4(long *tni4);main(argc,argv)     int argc;     char *argv[];{  struct {    union {      long d4[60];      short s2[120];    } H;    float Data[8192];  } Trace;/* Bison Header Struct */  struct {              /* each header constant is followed by CR and LF */    char f_num[8];      /* file number 6 digits */    char j_num[14];     /* job number 6 digits */    char date_time[12]; /* date and time mmddyyhhmm */    char op_note[82];   /* operator note 80 alpha */    char man_code[10];  /* manufacturer code BISON-2 */    char rec_name[14];  /* record name 12 alpha */    char head_type[4];  /* header type S/E (standard/extended) */    char data_for[4];   /* data format W/L/F (word/long/float) */    char ins_mod[8];    /* instrument model 6 alpha */    char ins_soft[6];   /* instrument software 4 digits */                        /* instrument digital processing history 12 alpha */    char op1[14];       /* operation #1 12 alpha */    char op2[14];       /* operation #2 12 alpha */    char op3[14];       /* operation #3 12 alpha */    char op4[14];       /* operation #4 12 alpha */    char num_chan[6];   /* number of channels 4 digits always 1 for extended */    char n_r[14];       /* 1-12 normal or revers 12 alpha */    char num_sam[8];    /* number of samples 6 digits 000500-999999 */    char sam_rate[6];   /* sample rate 4 alpha .001 to 99.9 msec */    char delay_time[6]; /* delay time 4 digits 0000 to 9999 msec */    char hi_pass[12];   /* hi-pass analog filter 4 digits and 6 alpha			   examp 0150 BE 03 (150 Hz Bessel 3 pole) */    char low_pass[12];  /* low-pass analog filter 4 digits and 6 alpha */    char notch_fil[10]; /* analog notch filter 2 digits and 6 alpha */    char shot_loc[82];  /* shot location 80 alpha */    char shot_off[82];  /* shot offset 80 alpha */    char geo_note[82];  /* geophone array note 80 alpha */  } Bison_Header;/* Bison Channel Header Struct */  struct {    char num_stack[6];  /* number of stacks chan l 4 digits */    char fixed_gain[6]; /* fixed gain chan l 4 digits (db) */    char pol_stat[6];   /* pol_stat_ ch l 4 alpha */    char dc_low[6];     /* dc low */    char dc_med[6];     /* dc med */    char dc_high[6];    /* dc high */    char ac_lm[6];      /* ac l-m */    char ac_mh[6];      /* ac m-h */  } Bison_Channel;      /* channel specific section repeated for each channel */  char etx_test[2];     /* two test characters */  short channel,samples,delay,w_sample[8192],f_sample[4];  long l_sample[8192],trace_len,j,k,l,swap;  float sample_rate;  unsigned short gain;  if (strcmp(argv[1],"swap") == 0)    {      swap=1;      fprintf(stderr,"bytes are swapped !\n");    }  fread(&Bison_Header,538,1,stdin);  Bison_Header.f_num[6]=*"\0";  Bison_Header.j_num[12]=*"\0";  Bison_Header.date_time[10]=*"\0";  Bison_Header.op_note[80]=*"\0";  Bison_Header.man_code[8]=*"\0";  Bison_Header.rec_name[12]=*"\0";  Bison_Header.head_type[2]=*"\0";  Bison_Header.data_for[2]=*"\0";  Bison_Header.ins_mod[6]=*"\0";  Bison_Header.ins_soft[4]=*"\0";  Bison_Header.op1[12]=*"\0";  Bison_Header.op2[12]=*"\0";  Bison_Header.op3[12]=*"\0";  Bison_Header.op4[12]=*"\0";  Bison_Header.num_chan[4]=*"\0";  Bison_Header.n_r[12]=*"\0";  Bison_Header.num_sam[6]=*"\0";  Bison_Header.sam_rate[4]=*"\0";  Bison_Header.delay_time[4]=*"\0";  Bison_Header.hi_pass[10]=*"\0";  Bison_Header.low_pass[10]=*"\0";  Bison_Header.notch_fil[8]=*"\0";  Bison_Header.shot_loc[80]=*"\0";  Bison_Header.shot_off[80]=*"\0";  Bison_Header.geo_note[80]=*"\0";  channel= atoi(Bison_Header.num_chan);  samples= atoi(Bison_Header.num_sam);  sample_rate=(float) atof(Bison_Header.sam_rate);  delay= atoi(Bison_Header.delay_time);  fprintf(stderr,"Job number :%s\n",&Bison_Header.j_num);  fprintf(stderr,"Date + time :%s\n",&Bison_Header.date_time);  fprintf(stderr,"Manufacturer code :%s\n",&Bison_Header.man_code);  fprintf(stderr,"Record name :%s\n",&Bison_Header.rec_name);  fprintf(stderr,"Header type :%s\n",&Bison_Header.head_type);  fprintf(stderr,"Data format :%s\n",&Bison_Header.data_for);  fprintf(stderr,"Number of channels :%d\n",channel);  fprintf(stderr,"Samples :%d\n",samples);  fprintf(stderr,"Sample rate :%f msec\n",sample_rate);  fprintf(stderr,"Delay :%d\n",delay);/* length of trace */  trace_len=240+4*samples;/* loop over the channel headers */  for (l=0;l<channel;l++)    {      fread(&Bison_Channel,48,1,stdin);      Bison_Channel.num_stack[4]=*"\0";      Bison_Channel.fixed_gain[4]=*"\0";      Bison_Channel.pol_stat[4]=*"\0";      Bison_Channel.dc_low[4]=*"\0";      Bison_Channel.dc_med[4]=*"\0";      Bison_Channel.dc_high[4]=*"\0";      Bison_Channel.ac_lm[4]=*"\0";      Bison_Channel.ac_mh[4]=*"\0";      fprintf(stderr,"Number of stacked traces :%s\n",&Bison_Channel.num_stack);    }  fread(&etx_test,2,1,stdin);  Trace.H.d4[0]=1;                                       /* tracl */  Trace.H.d4[2]=atol(&Bison_Header.rec_name[3]);         /* fldr */  Trace.H.d4[4]=0;                                       /* ep */  Trace.H.s2[16]=1;                                      /* trid */  Trace.H.s2[17]=atoi(Bison_Channel.num_stack);          /* nvs */  Trace.H.s2[19]=1;                                      /* duse */  Trace.H.d4[9]=atol(Bison_Header.shot_off);             /* offset */  Trace.H.s2[44]=1;                                      /* counit */  Trace.H.s2[52]=atoi(Bison_Header.delay_time);          /* delrt */  Trace.H.s2[57]=samples;                                /* ns */  Trace.H.s2[58]=(short) (sample_rate*1000);             /* dt */  Trace.H.s2[78]=(short) (atol(Bison_Header.date_time)); /* year */  Trace.H.s2[79]=(short) (atol(Bison_Header.date_time)); /* day */  Trace.H.s2[80]=(short) (atol(Bison_Header.date_time)); /* hour */  Trace.H.s2[81]=(short) (atol(Bison_Header.date_time)); /* minute */  Trace.H.s2[82]=(short) (atol(Bison_Header.date_time)); /* sec */  Trace.H.s2[83]=1;                                      /* timbas */  for (l=0;l<channel;l++)    {      Trace.H.d4[1]=l+1;                                 /* tracr */      Trace.H.d4[3]=l+1;                                 /* cdpt */      if (Bison_Header.data_for[1]==*"W")	{	  fread(&w_sample,(long) 2*samples,1,stdin);/* Word 16 bit 2's complement fixed gain normalized channel by channel.   Least significant byte is first inrecord. */	  for (j=0;j<samples;j++)	    {	      if (swap) swap_short_2(&w_sample[j]);	      Trace.Data[j]=(float) w_sample[j];	    }	}      else if (Bison_Header.data_for[1]==*"S")	{	  fread(&l_sample,(long) 4*samples,1,stdin);/* Long 32 bit 2's complement fixed gain instrumental format, not normalized,   least significant byte first. */	  for (j=0;j<samples;j++)	    {	      if (swap) swap_long_4(&l_sample[j]);	      Trace.Data[j]=(float) l_sample[j];	    }	}      else if (Bison_Header.data_for[1]==*"F")	{/* Float 16 bit 2's complement mantissa, 4 bit exponent normalized float   generated from 32 bit internal fixed format standard instrument storage   format. Transmitted as follows: in groups of 5 words   LSbyte of first sample mantissa   MSbyte of first sample mantissa   LSbyte of second sample mantissa   MSbyte of second sample mantissa   LSbyte of third sample mantissa   MSbyte of third sample mantissa   LSbyte of fourth sample mantissa   MSbyte of fourth sample mantissa   Exponent word:     Least significant nibble of first byte for fourth word.     Most significant nibble of first byte for third word.     Least significant nibble of second byte for second word.     Most significant nibble of first byte for first word. */	  for (j=0;j<samples;j+=4)	    {	      fread(&f_sample,2,4,stdin);	      fread(&gain,2,1,stdin);	      if (swap)		{		  for(k=0;k<4;k++)		    swap_short_2(&f_sample[k]);		  swap_short_2(&gain);		}	      Trace.Data[j]=((float) f_sample[0])*pow((double) 2,((double) ((gain & 0xf000)>>12)));	      Trace.Data[j+1]=((float) f_sample[1])*pow((double) 2,((double) ((gain & 0x0f00)>>8)));	      Trace.Data[j+2]=((float) f_sample[2])*pow((double) 2,((double) ((gain & 0x00f0)>>4)));	      Trace.Data[j+3]=((float) f_sample[3])*pow((double) 2,((double) ((gain & 0x000f)>>0)));/*	      fprintf(stderr,"%d %d %d %d %d ",gain,(gain&0xf000)>>12,(gain&0x0f00)>>8,(gain&0x00f0)>>4,gain&0x000f);*/	    }	}      else	{	  printf("Error\n");	}      fwrite(&Trace,trace_len,1,stdout);    }}void swap_short_2(short *tni2)/**************************************************************************swap_short_2		swap a short integer***************************************************************************/{ *tni2=(((*tni2>>8)&0xff) | ((*tni2&0xff)<<8));}void swap_long_4(long *tni4)/**************************************************************************swap_long_4		swap a long integer***************************************************************************/{ *tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |	    ((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));}**************************************************************--/                               |                                   \\                  ***    Jens Hartmann    ***                      //                               |                                   \\  Institut fuer Geophysik      |  phone: +49 40 4123-5046          //  Universitaet Hamburg         |  fax: +49 40 4123-5441            \\  Bundesstr. 55                |  e-mail: hartmann@dkrz.d400.de    //  20146 Hamburg, GERMANY       |                                   \\                               |                                   /

⌨️ 快捷键说明

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