/****************************************************************************** * * NSSDC/ISTP makecdf main * * $Id: makecdf.c,v 2.0 1998/07/27 12:42:44 pwilliam Exp pwilliam $ Raytheon/STX QSS * * Modification History: * * V1.0 ??? R.Burley Original Version * V2.0 07/27/98 P.Williams Made cross platform. Fixed UNIX bugs. * V2.5 10/04/00 H. Leckner, H. K. Hills Numerous fixes and updates. * v3.0 03/12/02 H. Leckner, H. K. Hills Fixes for embedded subcycles. * v3.1 04/24/02 H. Leckner, H. K. Hills New time algorithms: * 8 (for fractional days) and 9 (for daycount after January 1, 1950). * Also fixed to record all of FFD in log if DEBUG is ON. * created new typedefs for multi-platform use (on alpha long is 8 bytes) * UINT32, INT32 for 4 bytes integers (unsigned and signed) * UINT16, INT16 for 2 bytes integers (unsigned and signed) * ******************************************************************************/ #include "makecdf.h" main(argc,argv) int argc; char *argv[]; { /* declare local variables */ INT32 i,j,ierr,ifile,iflag,OLidx,vnum,velem,snum,pvnum,CDFrec; INT32 icerr,app; double depoch; INT32 g,ih; char pname; char lfileid[80]; char newname[80]; int MoreData; INT32 icnt; strcpy(IDENT.version,"MakeCDF, version 3.1 of 24 April, 2002.\n"); printf(IDENT.version); /* 7/25/2000 added initialization because not done before */ FLISTne = 0; CLISTne = 0; VLISTne = 0; OLISTne = 0; SRECSne = 0; icnt = 1; /* 7/25/2000 initialize for special case when Parsers not called, case is when .rflag is FALSE on first try */ EpALG.FirstEp = 0.0; /* 9/29/00 HKH initialized */ EpALG.BaseEp = 0.0; strcpy(lfileid,""); strcpy(newname,""); if (argc != 5) { printf("ERROR: Wrong number of makeCDF command parameters!\n"); printf("ERROR: Translation Aborted.\n"); exit(EXIT_FAILURE); } /* Initialize Run time parameters */ strcpy(RPARMS.infname,""); strcpy(RPARMS.ffdfname,""); strcpy(RPARMS.incdfname,""); RPARMS.progress=0L; RPARMS.debug=0L; RPARMS.sendtolog=0L; RPARMS.sendtoterm=1L; RPARMS.haltateof=1L; RPARMS.numrecs=0L; RPARMS.autocase=1L; RPARMS.autostyle=0L; LOGFILE.maxrecs=100L; /* Initialize output CDF information */ OUTCDF.outCDFid=0L; OUTCDF.encoding=0L; OUTCDF.CDFrec=0L; /* extract command line parameters from calling sequence */ for (i=0;i= 2) LOGFILE.appendlog = 1; /* Show we are past the first CDF. */ if(LOGFILE.big ==1) { /* Reset flag after log of last file exceeded max. */ RPARMS.sendtolog = TRUE; LOGFILE.big = 0; LOGFILE.nrecs = 0; } if (ifile == 0) { /* Here insert new preview code */ ierr = Preview_FFD(); /* Now the Run-Time Parameters are (re)defined according to the FFD file. */ sprintf(LOGFILE.message,"%s %s %s %s\n",RPARMS.infname, RPARMS.ffdfname,RPARMS.incdfname,RPARMS.outcdfname); MSG_control(2,LOGFILE.message,0); ierr=Import_FFD(); /* Import infile description */ if (ierr != 0) exit(EXIT_FAILURE); ierr = Determine_EpGenerator(); /* Find vars which enable Epoch calc*/ if (ierr != 0) exit(EXIT_FAILURE); } MSG_control(1," ",0); MSG_control(1,"----Beginning Translation----",0); ierr = Generate_CDFskeleton(); /* Generate the CDF skeleton. */ if (ierr != 0) exit(EXIT_FAILURE); ierr = Build_OLIST(); /* Build the ordered input list. */ if (ierr != 0) exit(EXIT_FAILURE); if (ifile == 0) { ierr = Match_Variables(); /* Map input vars to CDF variables*/ if (ierr != 0) exit(EXIT_FAILURE); ierr = Allocate_Buffers(); /* Allocate buffer space for vars.*/ if (ierr != 0) exit(EXIT_FAILURE); } ierr = Open_Infile(ifile); /* Open Input File and in-buffer. */ if (ierr != 0) exit(EXIT_FAILURE); ierr = Open_OutCDF(); /* Open the output CDF file */ if (ierr != 0) exit(EXIT_FAILURE); OLidx=0; do { ierr=0; vnum = OLIST[OLidx].vnum; velem = OLIST[OLidx].velem; if (vnum == -1) { /* time to read a new record from the input file */ if (OLIST[OLidx].rflag == TRUE) MoreData = Read_Infile(); /* set rflag for this eol to false if in header section of file */ pvnum = OLIST[OLidx-1].vnum; if (VLIST[pvnum].header == TRUE) OLIST[OLidx].rflag = FALSE; } else { if (OLIST[OLidx].rflag == TRUE) { if (INFILE.format == 0) { icnt=Parser1(vnum,velem); /* freeform */ } else { /* fixedform */ if (INFILE.dtype == 0) /* { */ icnt=Parser2(vnum,velem); /* text */ else icnt=Parser3(vnum,velem); /* binary */ } } if (icnt == 0) { MoreData = Read_Infile(); OLidx=OLISTne+1; } else { if (OLIST[OLidx].pflag == TRUE) { /* process variable */ if (vnum == EpALG.EpGenerator) { ierr = Generate_Epoch(&depoch); sprintf(LOGFILE.message,"depoch(0,0):%lf\n",depoch); MSG_control(0,LOGFILE.message,0); if (ierr == 0) { /* increment CDF rec# and write to CDF */ OUTCDF.CDFrec++; ierr = WriteEpochToCDF(depoch,OUTCDF.CDFrec); } } else if ((VLIST[vnum].bsubr != 0)&&(velem == 0)) { /* first element of first variable in new subrecord */ snum = VLIST[vnum].bsubr-1; /* get subrecord number */ if (SRECS[snum].countr != 0) { /* not first iteration */ if (SRECS[snum].delta > 0.0) { /* involved in time calcs */ /* depoch=depoch+((double)SRECS[snum].countr*SRECS[snum].delta);*/ depoch=EpALG.BaseEp+((double)SRECS[snum].countr*SRECS[snum].delta); sprintf(LOGFILE.message,"depoch(%d,%d):%lf\n",snum,SRECS[snum].countr,depoch); MSG_control(0,LOGFILE.message,0); OUTCDF.CDFrec++; ierr = WriteEpochToCDF(depoch,OUTCDF.CDFrec); } } SRECS[snum].countr++; } if ((VLIST[vnum].cdfvarnum>=0)&&(velem==VLIST[vnum].nelems-1)) { /* Perform data quality checking */ if (VLIST[vnum].autofill > 0) iflag = AutoFiller(vnum); if (iflag == 0) { /* data is not filler - continue QA checks */ if ((VLIST[vnum].autovalids > 0)|| (VLIST[vnum].autoscales > 0)) ierr = AutoMinMax(vnum); } /* Write the data out to the CDF file */ if (vnum < EpALG.EpGenerator) { ierr = WriteToCDF(vnum,OUTCDF.CDFrec+1); } if (vnum >= EpALG.EpGenerator) { ierr = WriteToCDF(vnum,OUTCDF.CDFrec); } } } if (VLIST[vnum].constant == TRUE) OLIST[OLidx].pflag = FALSE; if (VLIST[vnum].header == TRUE) OLIST[OLidx].rflag = FALSE; if (VLIST[vnum].header == TRUE) OLIST[OLidx].pflag = FALSE; } } OLidx = OLidx + 1; if (OLidx >= OLISTne) { OLidx=0; for (i=0;i