#include <stdio.h>
main(ac,av)
int ac; char *av[];
{
  FILE *fp;
  char f1[50],c,d[70],a[72][80];
  int i,j,ipos;
  if(ac==2){
    strcpy(f1,av[1]);
    goto l02;
  }
l10:
  printf("\n edit fits_head, input filename: ");
  gets(f1);
l02:
  if((fp=fopen(f1,"r+b"))==0){
    printf("file not found!\n");
    fclose(fp);
    goto l10;
  }
  fread(a,80,72,fp);
l20:
  printf("\n--------- look, modify, write, abort  (l/m/w/a)  ");
  gets(d); c=d[0];
  if(c=='l'){
    for(i=0;i<72;i++){
      if(a[i][0]==32)break;
      if((i+1)%23==0){
        printf("-- more <cr> --");
        gets(d);
        if(d[0]=='q' || d[0]=='a')exit(0);
      }
      for(j=0;j<79;j++)printf("%c",a[i][j]); printf("\n");
      if(a[i][0]=='E' && a[i][1]=='N' && a[i][2]=='D')break;
    }
  }
  if(c=='a' || c=='q')exit(0);
  if(c=='m'){
    printf("input KEYWORDS:   ");
    gets(d);
    j=0;
    for(i=0;i<9;i++){ if(d[i]<14)j=1; if(j==1)d[i]=32; }
    ipos=indexpos(a,d,72);
    if(ipos==72){ printf("not found !"); goto l20; }
    for(i=0;i<79;i++)printf("%c",a[ipos][i]); printf("\n");
    for(i=0;i<10;i++)printf("%c",a[ipos][i]);
    gets(d);
    j=strlen(d);
    if(j<20){ printf("not long enough!"); goto l20; }
    for(i=0;i<j;i++)a[ipos][i+10]=d[i];   
  }
  if(c=='w'){
    fseek(fp,0l,0);
    fwrite(a,80,72,fp);
    fclose(fp);
    printf("re_write fits_head ! OK\n");
    exit(0);
  }
  goto l20;
}
