Home| superdarn |src.lib|tk|oldfit| OldFitInxFclose Index

OldFitInxFclose

Syntax
int OldFitInxFclose(FILE *inxfp,struct RadarParm *prm,int irec);
Header
superdarn/oldfitwrite.h
Library
oldfit
Description

The OldFitInxFclose function prepares an index of a fit data file for closure.

The index is written to the open stream pointed to by the argument inxfp. The argument prm point to the last radar parameter block stored in the fit file and the argument irec is the index of the last record stored in the index file.

The first record of an index file contains information about the start and end times of the fit file and the total number of index records in the file. Consequently the first record of the file is actually written last.

This function must be called before the index file is closed.

Returns
Returns zero on success. On error, (-1) is returned.
Errors
On error, (-1) is returned.
Example

Source Code: OldFitInxFclose.c

/* OldFitInxFclose.c
   =================
   Author: R.J.Barnes

Copyright (c) 2012 The Johns Hopkins University/Applied Physics Laboratory

This file is part of the Radar Software Toolkit (RST).

RST 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 3 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, see <https://www.gnu.org/licenses/>.

Modifications:


*/


#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "rtypes.h"
#include "dmap.h"
#include "limit.h"
#include "rprm.h"
#include "fitdata.h"
#include "oldfitread.h"
#include "oldfitwrite.h"

struct RadarParm pbuf[2];
struct FitData fbuf[2];

struct FitData *fptr;
struct RadarParm *pptr;

int fnum=0;

int main(int argc,char *argv[]) {
 
  int irec=1;
  int drec=2,dnum;

  struct OldFitFp *fitfp;
  FILE *inxfp=0;


  fitfp=OldFitOpen(argv[1],NULL);

  if (fitfp==NULL) {
    fprintf(stderr,"File not found.'n");
    exit(-1);
  }


  inxfp=fopen(argv[2],"w");
  if (inxfp==NULL) {
    fprintf(stderr,"could not create index file.'n");
    exit(-1);  
  }

 
  while(OldFitRead(fitfp,&pbuf[fnum],&fbuf[fnum]) !=-1) {
  


    fptr=&fbuf[fnum];
    pptr=&pbuf[fnum];
    fnum=(fnum+1) % 2;
    if (irec==1) OldFitInxHeaderFwrite(inxfp,pptr);
    dnum=OldFitFwrite(NULL,pptr,fptr,NULL);
    OldFitInxFwrite(inxfp,drec,dnum,pptr);
    fprintf(stderr,"%.4d-%.2d-%.2d %.2d:%.2d:%.2d'n",
            pptr->time.yr,
            pptr->time.mo,pptr->time.dy,pptr->time.hr,pptr->time.mt,
            pptr->time.sc);


    drec+=dnum;
    irec++;
  }
 
  OldFitClose(fitfp);
  fclose(inxfp);
  inxfp=fopen(argv[2],"r+");
  OldFitInxFclose(inxfp,pptr,irec-1);
  fclose(inxfp);

  return 0;
}