Пример #1
0
int dsel(struct dirent *dp) {
#else 
int dsel(const struct dirent *dp) {
#endif
  if (dp->d_name[0]=='.') return 0;
  return 1;
}

int test_file_epoch(char *fname,double stime,double etime) {
  long yr,mo,dy,hr,mt,sc,ms;
  double fstime=0,fetime=0;
  int max=0;  
  CDFid id;
  CDFstatus status;
  double *dptr;
  char *varlist[]={"Epoch",NULL};


  status=CDFopen(fname,&id);
  if (status !=CDF_OK) return -1;

  
  max=RCDFMaxRecR(id,varlist[0]);
  if (max>0) {
     status=RCDFReadR(id,0,varlist,data);
     dptr=(double *) data[0].data;
     EPOCHbreakdown(dptr[0],&yr,&mo,&dy,&hr,&mt,&sc,&ms); 
     fstime=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc+(ms/1000.0));
     status=RCDFReadR(id,max-1,varlist,data);
     dptr=(double *) data[0].data;
     EPOCHbreakdown(dptr[0],&yr,&mo,&dy,&hr,&mt,&sc,&ms); 
     fetime=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc+(ms/1000.0));
  }
  max=RCDFMaxRecZ(id,varlist[0]);
  if (max>0) {
     status=RCDFReadZ(id,0,varlist,data);
     dptr=(double *) data[0].data;
     EPOCHbreakdown(dptr[0],&yr,&mo,&dy,&hr,&mt,&sc,&ms); 
     fstime=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc+(ms/1000.0));
     status=RCDFReadZ(id,max-1,varlist,data);
     dptr=(double *) data[0].data;
     EPOCHbreakdown(dptr[0],&yr,&mo,&dy,&hr,&mt,&sc,&ms); 
     fetime=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc+(ms/1000.0));
  }
  CDFclose(&id);

  if (stime>fetime) return 0;
  if (etime<fstime) return 0;
  return 1;
}
Пример #2
0
	Time TimeInterpolator::parseTime(const std::string& timeString)
	{
		std::cout << "timeString inside parseTime: " << timeString << std::endl;
		std::cout << "before declaring string" << std::endl;
		char timeString_c_str[EPOCH3_STRING_LEN+1];
		std::cout << "before string copy" << std::endl;
		strncpy(timeString_c_str, (char *)timeString.c_str(), EPOCH_STRING_LEN);
		std::cout << "after string copy" << std::endl;
		timeString_c_str[4] = '-';
		timeString_c_str[7] = '-';
		std::cout << "before creating epoch time with parseEPOCH3" << std::endl;
		double epoch = parseEPOCH3(timeString_c_str);
		std::cout << "epoch value in parseTime: " << epoch << std::endl;
		long year, month, day, hour, minute, second, msec;
		year = month = day = hour = minute = second = msec = 1;
		EPOCHbreakdown(epoch, &year, &month, &day, &hour, &minute, &second, &msec);
		Time time;
		time.setYear((short)year);
		time.setMonth((short)month);
		time.setDay((short)day);
		time.setHour((short)hour);
		time.setMinute((short)minute);
		time.setSeconds((short)second);
		time.setMilliseconds((short)msec);
		return time;

	}
Пример #3
0
int impmag_pos(CDFid id,struct posdata *ptr,double stime,double etime) {
  long yr,mo,dy,hr,mt,sc,ms;
  double rtime;
  int i,cnt=0;
  char *varlist[]={"Epoch","SC_pos_sm","SC_pos_se",0,NULL};
  struct RCDFData *data=NULL;
  int max;
  int rmax;
  int status;

  double *dptr;
  float *fptr;

  strcpy(ptr->sat,"i8");
  strcpy(ptr->ins,"mag");

  cnt=ptr->cnt;
  rmax=RCDFMaxRecR(id,varlist[0]);
  max=cnt+rmax;   

  if (max==0) return -1;
  data=RCDFMake(3);

  if (ptr->time==NULL) ptr->time=malloc(sizeof(double)*max);
  else ptr->time=realloc(ptr->time,sizeof(double)*max);

  if (ptr->PGSM==NULL) ptr->PGSM=malloc(3*sizeof(float)*max);
  else ptr->PGSM=realloc(ptr->PGSM,3*sizeof(float)*max);

  if (ptr->PGSE==NULL) ptr->PGSE=malloc(3*sizeof(float)*max);
  else ptr->PGSE=realloc(ptr->PGSE,3*sizeof(float)*max);

  for (i=0;i<rmax;i++) {
    status=RCDFReadR(id,i,varlist,data);
    
    if (status==0) {
       dptr=(double *) data[0].data;
       EPOCHbreakdown(dptr[0],&yr,&mo,&dy,&hr,&mt,&sc,&ms); 
      
       rtime=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc+(ms/1000.0));
       if (rtime<stime) continue;
       if (rtime>etime) break;
       ptr->time[cnt]=rtime;

      
       fptr=(float *) data[1].data;
       ptr->PGSM[cnt*3]=fptr[0]/6370.0;
       ptr->PGSM[cnt*3+1]=fptr[1]/6370.0;
       ptr->PGSM[cnt*3+2]=fptr[2]/6370.0;
       fptr=(float *) data[2].data;
       ptr->PGSE[cnt*3]=fptr[0]/6370.0;
       ptr->PGSE[cnt*3+1]=fptr[1]/6370.0;
       ptr->PGSE[cnt*3+2]=fptr[1]/6370.0;
       cnt++;
    }
  }
  RCDFFree(data,3);
  ptr->cnt=cnt;
  return 0;
}
Пример #4
0
int windmfi_imf(CDFid id,struct imfdata *ptr,double stime,double etime) {
  long yr,mo,dy,hr,mt,sc,ms;
  double rtime;
  int i,cnt=0;
  char *varlist[]={"Epoch3","B3GSM","B3GSE",NULL};
  struct RCDFData *data=NULL;


  int max;
  int rmax;
  int status;

  double *dptr;
  float *fptr;

  strcpy(ptr->sat,"we");
  strcpy(ptr->ins,"mfi");

  cnt=ptr->cnt;
  rmax=RCDFMaxRecZ(id,varlist[0]);
  max=cnt+rmax;

  if (rmax==0) return -1;

  data=RCDFMake(3);

  if (ptr->time==NULL) ptr->time=malloc(sizeof(double)*max);
  else ptr->time=realloc(ptr->time,sizeof(double)*max);

  if (ptr->BGSMc==NULL) ptr->BGSMc=malloc(3*sizeof(float)*max);
  else ptr->BGSMc=realloc(ptr->BGSMc,3*sizeof(float)*max);

  if (ptr->BGSEc==NULL) ptr->BGSEc=malloc(3*sizeof(float)*max);
  else ptr->BGSEc=realloc(ptr->BGSEc,3*sizeof(float)*max);

  for (i=0;i<rmax;i++) {
    status=RCDFReadZ(id,i,varlist,data);
    if (status==0) {
       dptr=(double *) data[0].data;
       EPOCHbreakdown(dptr[0],&yr,&mo,&dy,&hr,&mt,&sc,&ms); 
       rtime=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc+(ms/1000.0));
       if (rtime<stime) continue;
       if (rtime>etime) break;

       ptr->time[cnt]=rtime;
       fptr=(float *) data[1].data;
       ptr->BGSMc[cnt*3]=fptr[0];
       ptr->BGSMc[cnt*3+1]=fptr[1];
       ptr->BGSMc[cnt*3+2]=fptr[2];
       fptr=(float *) data[2].data;
       ptr->BGSEc[cnt*3]=fptr[0];
       ptr->BGSEc[cnt*3+1]=fptr[1];
       ptr->BGSEc[cnt*3+2]=fptr[2];
       cnt++;
    }
  }
  RCDFFree(data,3);
  ptr->cnt=cnt;
  return 0;
}
Пример #5
0
void epoch_to_str(double epoch, char *date)
{
    long year;
    long month;
    long day;
    long hour;
    long minute;
    long second;
    long msec;

    EPOCHbreakdown(epoch, &year, &month, &day, &hour, &minute, &second, &msec);
    sprintf(date,"%4d-%02d-%02d/%02d:%02d:%02d",year,month,day,hour,minute,second);
}
Пример #6
0
VISIBLE_PREFIX long long CDF_TT2000_from_UTC_EPOCH (double epoch)
{
  long long nanosecSinceJ2000;
  double millisec;
  long yy, mm, dd, hh, nn, ss, ll;
  if (epoch == -1.0E31 || epoch == -1.0E-31)
    return FILLED_TT2000_VALUE; 
  if (epoch == 0.0 || NegativeZeroReal8 (&epoch))
    return DEFAULT_TT2000_PADVALUE;; 
  EPOCHbreakdown (epoch, &yy, &mm, &dd, &hh, &nn, &ss, &ll);
  if (!YearWithin(yy) && !ValidateYMD(yy,mm,dd)) return ILLEGAL_TT2000_VALUE;
  return CDF_TT2000_from_UTC_parts ((double)yy, (double)mm, (double)dd,
                                    (double)hh, (double)nn, (double)ss,
                                    (double)ll, 0.0, 0.0);
}
Пример #7
0
	Time::Time(const std::string& timeString)
	{
		//extern "C" double parseEPOCH3(char epString[EPOCH3_STRING_LEN+1]);
		//extern "C" void encodeEPOCH3(double epoch, char epString[EPOCH3_STRING_LEN+1]);
		//ensure that it uses '-' instead of '/'
		char timeString_c_str[EPOCH3_STRING_LEN+1];
		strcpy(timeString_c_str, (char *)timeString.c_str());
		timeString_c_str[4] = '-';
		timeString_c_str[7] = '-';
		epoch = parseEPOCH3(timeString_c_str);
		//std::cout << "epoch value in parseTime: " << epoch << std::endl;
		long lyear, lmonth, lday, lhour, lminute, lsecond, lmsec;
		lyear = lmonth = lday = lhour = lminute = lsecond = lmsec = 1;
		EPOCHbreakdown(epoch, &lyear, &lmonth, &lday, &lhour, &lminute, &lsecond, &lmsec);
		year = ((short)lyear);
		month = ((short)lmonth);
		day = ((short)lday);
		hour = ((short)lhour);
		minute = ((short)lminute);
		seconds = ((short)lsecond);
		milliseconds = ((short)lmsec);
	}
Пример #8
0
int acemfi_imf(CDFid id,struct imfdata *ptr,double stime,double etime,
               int cnv) {
  long  yr,mo,dy,hr,mt,sc,ms;
  double rtime;
  int i,cnt=0;
  char *varlist[]={"Epoch","BGSEc","BGSM",NULL};
  struct RCDFData *data=NULL;

  int max;
  int rmax;
  int status;

  double *dptr;
  float *fptr;
  
  double gsex,gsey,gsez;
  double gsmx,gsmy,gsmz;
  

  if (cnv==1) varlist[2]=NULL;

  strcpy(ptr->sat,"ac");
  strcpy(ptr->ins,"mfi");

  cnt=ptr->cnt;
  rmax=RCDFMaxRecR(id,varlist[0]);
  max=cnt+rmax;

  if (rmax==0) return -1;

  data=RCDFMake(3);


  if (ptr->time==NULL) ptr->time=malloc(sizeof(double)*max);
  else ptr->time=realloc(ptr->time,sizeof(double)*max);

  if (ptr->BGSMc==NULL) ptr->BGSMc=malloc(3*sizeof(float)*max);
  else ptr->BGSMc=realloc(ptr->BGSMc,3*sizeof(float)*max);

  if (ptr->BGSEc==NULL) ptr->BGSEc=malloc(3*sizeof(float)*max);
  else ptr->BGSEc=realloc(ptr->BGSEc,3*sizeof(float)*max);

  for (i=0;i<rmax;i++) {
    status=RCDFReadR(id,i,varlist,data);
    if (status==0) {
       dptr=(double *) data[0].data;
       EPOCHbreakdown(dptr[0],&yr,&mo,&dy,&hr,&mt,&sc,&ms); 
       rtime=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc+(ms/1000.0));
       if (rtime<stime) continue;
       if (rtime>etime) break;
       ptr->time[cnt]=rtime;
       fptr=(float *) data[1].data;
          
       ptr->BGSEc[cnt*3]=fptr[0];
       ptr->BGSEc[cnt*3+1]=fptr[1];
       ptr->BGSEc[cnt*3+2]=fptr[2];

       if (cnv==1) {
         gsex=fptr[0];
         gsey=fptr[1];
         gsez=fptr[2];

         GeoPackRecalc(yr,mo,dy,hr,mt,(sc+1.0*ms/1000.0));
         GeoPackGseGsm(gsex,gsey,gsez,&gsmx,&gsmy,&gsmz);

         ptr->BGSMc[cnt*3]=gsmx;
         ptr->BGSMc[cnt*3+1]=gsmy;
         ptr->BGSMc[cnt*3+2]=gsmz;
       } else {
         fptr=(float *) data[2].data;
         ptr->BGSMc[cnt*3]=fptr[0];
         ptr->BGSMc[cnt*3+1]=fptr[1];
         ptr->BGSMc[cnt*3+2]=fptr[2];
       }
       cnt++;
    }
  }

  RCDFFree(data,3); 
  ptr->cnt=cnt;
  return 0;
}
Пример #9
0
int windswe_plasma(CDFid id,struct plasmadata *ptr,double stime,double etime) {
  long yr,mo,dy,hr,mt,sc,ms;
  double rtime;
  int i,cnt=0;
  char *varlist[]={"Epoch","V_GSM","V_GSE","THERMAL_SPD","Np",NULL};
  struct RCDFData *data=NULL;

  int max;
  int rmax;
  int status;

  double *dptr;
  float *fptr;
  float Mp=1.6e-27;
  float Vx;
  int pcnt=0;

  strcpy(ptr->sat,"we");
  strcpy(ptr->ins,"swe");

  cnt=ptr->cnt;
  rmax=RCDFMaxRecR(id,varlist[0]);
  max=cnt+rmax;     

  if (rmax==0) return -1;
  data=RCDFMake(5);


  if (ptr->time==NULL) ptr->time=malloc(sizeof(double)*max);
  else ptr->time=realloc(ptr->time,sizeof(double)*max);

  if (ptr->VGSM==NULL) ptr->VGSM=malloc(3*sizeof(float)*max);
  else ptr->VGSM=realloc(ptr->VGSM,3*sizeof(float)*max);

  if (ptr->VGSE==NULL) ptr->VGSE=malloc(3*sizeof(float)*max);
  else ptr->VGSE=realloc(ptr->VGSE,3*sizeof(float)*max);

  if (ptr->vth==NULL) ptr->vth=malloc(sizeof(float)*max);
  else ptr->vth=realloc(ptr->vth,sizeof(float)*max);

  if (ptr->den==NULL) ptr->den=malloc(sizeof(float)*max);
  else ptr->den=realloc(ptr->den,sizeof(float)*max);

 if (ptr->pre==NULL) ptr->pre=malloc(sizeof(float)*max);
  else ptr->pre=realloc(ptr->pre,sizeof(float)*max);


  for (i=0;i<rmax;i++) {
  
    status=RCDFReadR(id,i,varlist,data);
    
    if (status==0) {
       dptr=(double *) data[0].data;
       EPOCHbreakdown(dptr[0],&yr,&mo,&dy,&hr,&mt,&sc,&ms); 
       rtime=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc+(ms/1000.0));
       if (rtime<stime) continue;
       if (rtime>etime) break;

       ptr->time[cnt]=rtime;
       fptr=(float *) data[1].data;
       ptr->VGSM[cnt*3]=fptr[0];
       ptr->VGSM[cnt*3+1]=fptr[1];
       ptr->VGSM[cnt*3+2]=fptr[2];
       fptr=(float *) data[2].data;
       ptr->VGSE[cnt*3]=fptr[0];
       ptr->VGSE[cnt*3+1]=fptr[1];
       ptr->VGSE[cnt*3+2]=fptr[2];
       fptr=(float *) data[3].data;
       ptr->vth[cnt]=fptr[0];
       fptr=(float *) data[4].data;
       ptr->den[cnt]=fptr[0];
       
       Vx=ptr->VGSM[3*cnt];
       if ((ptr->den[cnt]>0) && (Vx > -10000)) {
          ptr->pre[cnt]=(ptr->den[cnt]*Mp*1e6)*
                     fabs(Vx*1e3)*fabs(Vx*1e3)*1e9;
          pcnt++;
       } else ptr->pre[cnt]=ptr->den[cnt];
       

       
       cnt++;
    }
  }
  if (pcnt==0) memset(ptr->pre,0,sizeof(float)*cnt);


  ptr->cnt=cnt;
  return 0;
}
Пример #10
0
int imppla_plasma(CDFid id,struct plasmadata *ptr,double stime,double etime) {
  long yr,mo,dy,hr,mt,sc,ms;
  double rtime;
  int i,cnt=0;
  char *varlist[]={"Epoch","V_GSE","Np",NULL};
  struct RCDFData *data=NULL;
  int max;
  int rmax;
  int status;

  double gsex,gsey,gsez;
  double gsmx,gsmy,gsmz;

  double *dptr;
  float *fptr;
  float Mp=1.6e-27;
  float Vx;
  int pcnt=0;

  cnt=ptr->cnt;
  rmax=RCDFMaxRecZ(id,varlist[0]);
  max=rmax+cnt;   

  if (max==0) return -1;
  data=RCDFMake(3);

  if (ptr->time==NULL) ptr->time=malloc(sizeof(double)*max);
  else ptr->time=realloc(ptr->time,sizeof(double)*max);

  if (ptr->VGSM==NULL) ptr->VGSM=malloc(3*sizeof(float)*max);
  else ptr->VGSM=realloc(ptr->VGSM,3*sizeof(float)*max);

  if (ptr->VGSE==NULL) ptr->VGSE=malloc(3*sizeof(float)*max);
  else ptr->VGSE=realloc(ptr->VGSE,3*sizeof(float)*max);

  if (ptr->vth==NULL) ptr->vth=malloc(sizeof(float)*max);
  else ptr->vth=realloc(ptr->vth,sizeof(float)*max);

  if (ptr->den==NULL) ptr->den=malloc(sizeof(float)*max);
  else ptr->den=realloc(ptr->den,sizeof(float)*max);

 if (ptr->pre==NULL) ptr->pre=malloc(sizeof(float)*max);
  else ptr->pre=realloc(ptr->pre,sizeof(float)*max);


  for (i=0;i<rmax;i++) {
  
    status=RCDFReadZ(id,i,varlist,data);
    
    if (status==0) {
       dptr=(double *) data[0].data;
       EPOCHbreakdown(dptr[0],&yr,&mo,&dy,&hr,&mt,&sc,&ms);

       rtime=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc+(ms/1000.0));
       if (rtime<stime) continue;
       if (rtime>etime) break;
       ptr->time[cnt]=rtime;
 
       fptr=(float *) data[1].data;
   
       if (fptr[0]>9999) { 
           ptr->VGSE[cnt*3]=1e31;
           ptr->VGSE[cnt*3+1]=1e31;
           ptr->VGSE[cnt*3+2]=1e31;
           ptr->VGSM[cnt*3]=1e31;
           ptr->VGSM[cnt*3+1]=1e31;
           ptr->VGSM[cnt*3+2]=1e31;
           ptr->vth[cnt]=1e31;
           ptr->den[cnt]=1e31;
           ptr->pre[cnt]=1e31;
           cnt++;
           continue;
       }
      
       ptr->VGSE[cnt*3]=fptr[0];
       ptr->VGSE[cnt*3+1]=fptr[1];
       ptr->VGSE[cnt*3+2]=fptr[2];

       gsex=fptr[0];
       gsey=fptr[1];
       gsez=fptr[2];

       GeoPackRecalc(yr,mo,dy,hr,mt,(sc+1.0*ms/1000.0));
       GeoPackGseGsm(gsex,gsey,gsez,&gsmx,&gsmy,&gsmz);

       ptr->VGSM[cnt*3]=gsmx;
       ptr->VGSM[cnt*3+1]=gsmy;
       ptr->VGSM[cnt*3+2]=gsmz;

       ptr->vth[cnt]=0;
       fptr=(float *) data[2].data;
       ptr->den[cnt]=fptr[0];
       
       Vx=ptr->VGSM[3*cnt];
       if ((ptr->den[cnt]>0) && (Vx > -10000)) {
          ptr->pre[cnt]=(ptr->den[cnt]*Mp*1e6)*
                     fabs(Vx*1e3)*fabs(Vx*1e3)*1e9;
          pcnt++;
       } else ptr->pre[cnt]=ptr->den[cnt];
       
       cnt++;
    }
  }
  if (pcnt==0) memset(ptr->pre,0,sizeof(float)*cnt);
  RCDFFree(data,3);

  ptr->cnt=cnt;
  return 0;
}
Пример #11
0
	Time::Time(double epochTime)
	{
		EPOCHbreakdown(epochTime, (long*)&year, (long *)&month, (long*)&day, (long*)&hour, (long*)&minute, (long*)&seconds, (long*)&milliseconds);
		this->epoch = epochTime;
	}