#include <string.h>

int gethead(char *fname)
{
  int     hfact=0;
  FILE    *fp;
  char    *header;
  char    ss[10] = " END ";
  char    *sp;
  int     hflag=1;
  int     headunit=2880;
  char    atama[6];

  header=(char*)malloc(headunit+1);

  if(NULL==(fp=fopen(fname,"rb"))){
    printf("\n [%s] can not be opened \n",fname);
    exit(1);
  }
  while(hflag){
    hfact++;
    fread(header,sizeof(char),headunit,fp);
    memcpy(atama,header,5); atama[5]='\0';
    if(strcmp(atama,"END  ")==0){
      hflag=0;
    } else {
      sp = strstr(header,ss);
      if (sp){
        hflag=0;
      }
    }
  }
  fclose(fp);
  free(header);

  return hfact;
}
