Home| superdarn |src.lib|tk|cfit| CFitReadRadarScan Index

CFitReadRadarScan

Syntax
int CFitReadRadarScan(struct CFitfp *fp,int *state,struct RadarScan *ptr,struct CFitdata *cfit,int tlen, int lock,int chn);
Header
superdarn/cfitscan.h
Library
cfit
Description

The CFitReadRadarScan function reads one full scan of data from a cFit data file.

The data is read from the open file pointed to by the argument fp.

The argument state is a pointer to an integer that is used internally by the function to track progress through the CFit file. Initially this integer should be set to zero, indicating that no data has been read from the file yet. The other possible value of state are (1), indicating that a complete scan was read from the file and data from the next scan is pending, or (2) indicating that a file error occurred.

The scan data is written to the structure pointed to by the argument ptr. Memory is automatically allocated within this structure to store the beam data.

In order for the function to correctly identify a scan boundary, it must read the first beam from the subsequent scan. This data must be preserved so that it can be included in the next block of scan data returned by the next call to the function. This is done by providing storage for the cFit data pointed to by the argument cfit.

If the argument tlen has a non-zero value then the function will ignore the scan flag and instead assume the the scan has a length of tlen seconds. If the argument lock has a non-zero value it is also assumed that the scan boundaries are fixed relative to the start of the day.

If the final argument chn, is compared against the channel number recorded in the radar parameter block, if the two numbers do not match then the data record is excludef from the scan.

Returns
Returns zero on success, or (1) if the end of file was reached. On error, (-1) is returned.
Errors
On error, (-1) is returned.
Example

Source Code: CFitReadRadarScan.c

/* CFitReadRadarScan.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 "rtypes.h"
#include "rtime.h"
#include "limit.h"
#include "cfitdata.h"
#include "cfitread.h"
#include "scandata.h"
#include "cfitscan.h"

struct RadarScan scn;


int main(int argc,char *argv[]) {
 
  struct CFitfp *fp=NULL;
  struct CFitdata cfit;
  int state=0;


  int yr,mo,dy,hr,mt;
  double sc;

  fp=CFitOpen(argv[1]);

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

  while(CFitReadRadarScan(fp,&state,&scn,&cfit,0,0,0) !=-1) {
    TimeEpochToYMDHMS(scn.st_time,&yr,&mo,&dy,&hr,&mt,&sc);

    fprintf(stdout,"%.4d-%.2d-%.2d %.2d:%.2d:%.2d'n",
            yr,mo,dy,hr,mt,(int) sc);

  }

  CFitClose(fp);

  return 0;
}