Ejemplo n.º 1
0
DWORD   _Day1970 ()
{
    static  struct _dosdate_t ddate;
    _dos_getdate (&ddate);
    return (((ddate.year - 1970) * 365) + ((ddate.year - 1968) / 4)
        + (DayOfYear (ddate.month, ddate.day, ddate.year) - 1));
}
Ejemplo n.º 2
0
WORD CTime::DayOfYear() const
{
	struct tm Time;
	if (localtime_s(&Time,&m_time)!=0)
		return 0;
	return DayOfYear(Time.tm_mday,Time.tm_mon,Time.tm_year+1900);
}
Ejemplo n.º 3
0
DWORD CTime::GetIndex() const
{
	struct tm Time;
	if (localtime_s(&Time,&m_time)!=0)
		return 0;
	return ((Time.tm_year+1900-1)*365+LeapYears(Time.tm_year+1900-1)+DayOfYear());
}
Ejemplo n.º 4
0
	int Date::ToDayIndex() const
	{
		int index = ((year_ - 1) / 400) * DAYS_IN_400_YEARS;

		int y = (year_ - 1) % 400;
		index += y * DAYS_IN_YEAR + (y / 4) - (y / 100);
		index += DayOfYear(year_, month_, day_);

		return index;
	}
Ejemplo n.º 5
0
int main()
{
T=MakeTANGGAL(2,12,1989);
T1=MakeTANGGAL(2,12,1989);
TulisTANGGAL(T);TulisTANGGAL(T1);
printf("Prev Day 2/12/1989 : ");TulisTANGGAL(PrevDay(T));
printf("Next Day 2/12/1989 : ");TulisTANGGAL(NextDay(T));
printf("Next 15 Day 2/12/1989 : ");TulisTANGGAL(NextNday(T,15));
printf("Prev 15 Day 2/12/1989 : ");TulisTANGGAL(PrevNDay(T,15));
printf("Tanggal 2/12/1989 ada : %4d hari",HariKe(T));printf("\n");
printf("hari ke- %4d jatuh pada tanggal :",HariKe(T));TulisTANGGAL(DayOfYear(HariKe(T),Year(T)));printf("\n");
printf("IsEqD T dan T1 ? %s\n",(IsEqD(T,T1)?"true":"false"));
printf("IsBefore T dan T1 ? %s\n",(IsBefore(T,T1)?"true":"false"));
printf("IsAfter T dan T1 ? %s\n",(IsAfter(T,T1)?"true":"false"));
printf("IsKabisat T ?%s\n",(IsKabisat(Year(T))?"true":"false"));
printf("IsKabisat 1972 ? %s\n",(IsKabisat(1972)?"true":"false"));
printf("#hari/tahun : 100/1972 ? ");TulisTANGGAL(DayOfYear(100,1972));
return 0;
}
Ejemplo n.º 6
0
WORD	MTime::AdjustYear(const int nDiffDays)
{
	const int nDay = DayOfYear() + nDiffDays;

	if (nDay > DaysInYear())
		return _SysTime.wYear + 1;
	else if (nDay < 0)
		return _SysTime.wYear - 1;
	return _SysTime.wYear;
}
Ejemplo n.º 7
0
/*****************************************************************************
  NextDate()
*****************************************************************************/
DATE NextDate(DATE * Current, int Interval)
{
  DATE Next;			/* Next date */
  double Sec;

  Next.Julian = Current->Julian + ((double) Interval) / SECPDAY;
  JulianDayToGregorian(Next.Julian, &(Next.Year), &(Next.Month), &(Next.Day),
		       &(Next.Hour), &(Next.Min), &Sec);
  Next.Sec = (int) Sec;
  Next.JDay = DayOfYear(Next.Year, Next.Month, Next.Day);

  return Next;
}
Ejemplo n.º 8
0
/*****************************************************************************
  IncreaseTime()
*****************************************************************************/
void IncreaseTime(TIMESTRUCT * Time)
{
  double Sec;

  (Time->Step)++;
  Time->DayStep = (Time->DayStep + 1) % Time->NDaySteps;
  Time->Current.Julian = Time->Start.Julian +
    ((double) Time->Step) * (((double) Time->Dt) / SECPDAY);
  JulianDayToGregorian(Time->Current.Julian, &(Time->Current.Year),
		       &(Time->Current.Month), &(Time->Current.Day),
		       &(Time->Current.Hour), &(Time->Current.Min), &Sec);
  Time->Current.Sec = (int) Sec;
  Time->Current.JDay = DayOfYear(Time->Current.Year, Time->Current.Month,
				 Time->Current.Day);
}
Ejemplo n.º 9
0
int CCSDateTime::Week( int firstDayOfWeek /*= MONDAY*/ ) const
{
	assert( firstDayOfWeek >= 0 && firstDayOfWeek <= 6 );

	/// find the first firstDayOfWeek.
	int baseDay = 1;
	while ( CCSDateTime( m_year, 1, baseDay ).DayOfWeek() != firstDayOfWeek)
	{
		++baseDay;
	}

	int doy = DayOfYear();
	int offs = baseDay <= 4 ? 0 : 1;
	if ( doy < baseDay )
	{
		return offs;
	}
	else
	{
		return (doy - baseDay)/7 + 1 + offs;
	}
}
Ejemplo n.º 10
0
/*****************************************************************************
  IncreaseVariableTime()
*****************************************************************************/
void IncreaseVariableTime(TIMESTRUCT *Time, float VariableDT, TIMESTRUCT *NextTime)
{
  double Sec;

  Time->Current.Julian = Time->Current.Julian + VariableDT/SECPDAY;

  if(After(&(Time->Current), &(NextTime->Current)) || 
     IsEqualTime(&(Time->Current), &(NextTime->Current))) {

    (Time->Step)++;
    Time->DayStep = (Time->DayStep + 1) % Time->NDaySteps;
  }

  JulianDayToGregorian(Time->Current.Julian, &(Time->Current.Year),
		       &(Time->Current.Month), &(Time->Current.Day),
		       &(Time->Current.Hour), &(Time->Current.Min), 
		       &(Sec));
  Time->Current.Sec = (int) Sec;
  Time->Current.JDay = DayOfYear(Time->Current.Year, Time->Current.Month,
				 Time->Current.Day);
 
}
Ejemplo n.º 11
0
/**
 * name:	CompareDays
 * class:	MAnnivDate
 * desc:	compare the current date with the given one in st
 * param:	mt	- MTime to compare with
 * return:	number of days the mt differs from the class value
 **/ 
INT MAnnivDate::CompareDays(MTime mt) const
{
	mt.Year(Year());
	return DayOfYear() - mt.DayOfYear();
}
Ejemplo n.º 12
0
Tanggal PrevNDay (Tanggal D,int N)
{
     int H;
     H=HariKe(D)-N;
     return DayOfYear(H, Year(D));
}
Ejemplo n.º 13
0
Tanggal NextNday (Tanggal D,int N)
{
     int H;
     H=HariKe(D)+N;
     return DayOfYear(H, Year(D));
}
Ejemplo n.º 14
0
/* -------------------------------------------------------------
   channel_save_outflow_cplmt
   Saves the channel outflow using a text string as the time field
   for John's RBM model
   ------------------------------------------------------------- */
int
channel_save_outflow_text_cplmt
(TIMESTRUCT *Time, char *tstring, Channel * net, CHANNEL * netfile , int flag)
{
  int err = 0;
  int Dt;
  FILE * out, *out2, *out4, *out3, *out5,*out9, *out10, *out11, 
	  *out13, *out14, *out6, *out7;

  Dt = Time->Dt;

  out = netfile->streamoutflow;
  out2 = netfile->streaminflow;
  out4 = netfile->streamISW;
  out5 = netfile->streamILW;
  out6 = netfile->streamBeam;
  out7 = netfile->streamDiffuse;
  out9 = netfile->streamVP;
  out10 = netfile->streamWND;
  out11 = netfile->streamATP;
  out13 = netfile->streamNLW;
  out14 = netfile->streamNSW;
  out3 = netfile->streamSkyView;

  /* print the start date and end date. Note that the true start date is a time step behind the 
  user specified date when the model outputs data */
  if (flag == 1) {
  PrintRBMStartDate(Dt, &(Time->Current), out);
  fprintf(out, " ");
  PrintDate(&(Time->End), out);
  fprintf(out, " %d", Dt/3600);
  fprintf(out, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out2);
  fprintf(out2, " ");
  PrintDate(&(Time->End), out2);
  fprintf(out2, " %d", Dt/3600);
  fprintf(out2, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out3);
  fprintf(out3, " ");
  PrintDate(&(Time->End), out3);
  fprintf(out3, " %d", Dt/3600);
  fprintf(out3, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out4);
  fprintf(out4, " ");
  PrintDate(&(Time->End), out4);
  fprintf(out4, " %d", Dt/3600);
  fprintf(out4, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out5);
  fprintf(out5, " ");
  PrintDate(&(Time->End), out5);
  fprintf(out5, " %d", Dt/3600);
  fprintf(out5, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out6);
  fprintf(out6, " ");
  PrintDate(&(Time->End), out6);
  fprintf(out6, " %d", Dt/3600);
  fprintf(out6, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out7);
  fprintf(out7, " ");
  PrintDate(&(Time->End), out7);
  fprintf(out7, " %d", Dt/3600);
  fprintf(out7, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out9);
  fprintf(out9, " ");
  PrintDate(&(Time->End), out9);
  fprintf(out9, " %d", Dt/3600);
  fprintf(out9, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out10);
  fprintf(out10, " ");
  PrintDate(&(Time->End), out10);
  fprintf(out10, " %d", Dt/3600);
  fprintf(out10, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out11);
  fprintf(out11, " ");
  PrintDate(&(Time->End), out11);
  fprintf(out11, " %d", Dt/3600);
  fprintf(out11, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out13);
  fprintf(out13, " ");
  PrintDate(&(Time->End), out13);
  fprintf(out13, " %d", Dt/3600);
  fprintf(out13, "\n");
  PrintRBMStartDate(Dt, &(Time->Current), out14);
  fprintf(out14, " ");
  PrintDate(&(Time->End), out14);
  fprintf(out14, " %d", Dt/3600);
  fprintf(out14, "\n");
  }

  if (flag == 1) {
    fprintf(out, "                    ");
    fprintf(out2, "                    ");
	fprintf(out3, "                    ");
    fprintf(out4, "                    ");
    fprintf(out5, "                    ");
	fprintf(out6, "                    ");
    fprintf(out7, "                    ");
    fprintf(out9, "                    ");
    fprintf(out10, "                    ");
    fprintf(out11, "                    ");
    fprintf(out13, "                    ");
    fprintf(out14, "                    ");

    for (; net != NULL; net = net->next) {
	  fprintf(out, "%12d ", net->id);
      fprintf(out2, "%12d ", net->id);
	  fprintf(out3, "%12d ", net->id);
      fprintf(out4, "%8d ", net->id);
      fprintf(out5, "%8d ", net->id);

	  fprintf(out6, "%8d ", net->id);
      fprintf(out7, "%8d ", net->id);

      fprintf(out9, "%9d ", net->id);
      fprintf(out10, "%8d ", net->id);
      fprintf(out11, "%5d ", net->id);

	  fprintf(out13, "%8d ", net->id);
	  fprintf(out14, "%8d ", net->id);
    }
    fprintf(out, "\n");
    fprintf(out2, "\n");
	fprintf(out3, "\n");
    fprintf(out4, "\n");
    fprintf(out5, "\n");
	
	fprintf(out6, "\n");
    fprintf(out7, "\n");

    fprintf(out9, "\n");
    fprintf(out10, "\n");
    fprintf(out11, "\n");

	fprintf(out13, "\n");
	fprintf(out14, "\n");
  }

  Time->Current.JDay = DayOfYear(Time->Current.Year, Time->Current.Month, Time->Current.Day);
  Time->Start.JDay = DayOfYear(Time->Start.Year, Time->Start.Month, Time->Start.Day);

  if ((Time->Current.JDay>=Time->Start.JDay+1) || 
	  (Time->Current.Year>Time->Start.Year)) {
  if (fprintf(out, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_outflow: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out2, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_inflow: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out3, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_inflow: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out4, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_ISW: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out5, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_ILW: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out9, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_ActualVaporPressure: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out10, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_Wind: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out11, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_AirTemp: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out13, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_NetLW: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out14, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_NetSW: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out6, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_ILW: write error:%s", strerror(errno));
    err++;
  }
  if (fprintf(out7, "%15s ", tstring) == EOF) {
    error_handler(ERRHDL_ERROR,"channel_save_ILW: write error:%s", strerror(errno));
    err++;
  }

  for (; net != NULL; net = net->next) {
    if (fprintf(out, "%12.4f ", net->outflow/Dt) == EOF) {
	  error_handler(ERRHDL_ERROR, "channel_save_outflow: write error:%s", strerror(errno));
	  err++;
	}
    if (fprintf(out2, "%12.4f ", net->inflow/Dt) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_inflow: write error:%s", strerror(errno));
      err++;
	}
    if (fprintf(out4, "%8.2f ", net->ISW ) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_ISW: write error:%s", strerror(errno));
      err++;
    }
    if (fprintf(out5, "%8.2f ", net->ILW ) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_ILW: write error:%s", strerror(errno));
      err++;
    }
    if (fprintf(out9, "%9.2f ", net->VP ) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_ActualVaporPressure: write error:%s", strerror(errno));
      err++;
    }
    if (fprintf(out10, "%8.2f ", net->WND ) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_Wind: write error:%s", strerror(errno));
      err++;
    }
    if (fprintf(out11, "%5.2f ", net->ATP ) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_AirTemp: write error:%s", strerror(errno));
      err++;
    }
	if (fprintf(out13, "%8.2f ", net->NLW) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_NetLW: write error:%s", strerror(errno));
      err++;
    }
	if (fprintf(out14, "%8.2f ", net->NSW) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_NetSW: write error:%s", strerror(errno));
      err++;
    }
	if (fprintf(out6, "%8.2f ", net->Beam ) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_ISW: write error:%s", strerror(errno));
      err++;
    }
	if (fprintf(out7, "%8.2f ", net->Diffuse) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_ILW: write error:%s", strerror(errno));
      err++;
    }
	if (fprintf(out3, "%8.2f ", net->skyview) == EOF) {
      error_handler(ERRHDL_ERROR, "channel_save_ILW: write error:%s", strerror(errno));
      err++;
    }
  }
  fprintf(out, "\n");
  fprintf(out2, "\n");
  fprintf(out3, "\n");
  fprintf(out4, "\n");
  fprintf(out5, "\n");

  fprintf(out6, "\n");
  fprintf(out7, "\n");

  fprintf(out9, "\n");
  fprintf(out10, "\n");
  fprintf(out11, "\n");

  fprintf(out13, "\n");
  fprintf(out14, "\n");
  }

  return (err);
}
Ejemplo n.º 15
0
int main(int argc, char **argv)
{
  FILE   *demfile,*outfile,*outfile2;
  char   demfilename[255],outfilename[255],outfilename2[255];
  int    nRows;                    /* Number of rows */
  int    nCols;                    /* Number of columns */
  float  *temp;
  float  **elev,**slope,**aspect,**hillshade;
  unsigned char **outputgrid;
  int    i;
  int    ny,nx;
  float  lx,ly;
  double max_angle,angle;
  float  saz,sal;
  double theta;
  float  dx;
  float  x,y,sx,sy,dz,dist;
  float  mx,my;
  float  start_elev;
  float  max_elev,min_elev;
  float  target_row,target_col;
  int    stop_flag;
  float  a,b,c,d,e,f,g,h,j;
  float  dzdx,dzdy,rr;
  float  safe_distance;
  int    month,day,year,jday;
  float  hour;
  int    ihour;
  float  dt;
  int    count;
  float  outstep;
  int    stepsperday;
  int    daylight;
  int    sunlight;
  float  standardmeridian,latitude,longitude;
  float  noon_hour,  declination, halfdaylength, solar_hour;
  float  sunrise, sunset, timeadjustment, sunearthdistance;
  float  sinesolaraltitude, solartimestep, sunmax, solarazimuth;
  float  beam,diffuse;


  if(argc<13) {
    printf("usage is: make_dhsvm_shade_maps:  \n");
    printf("demfilename  \n");
    printf("outfilename  \n");
    printf("nrows, ncols \n");
    printf("cellsize (in the same units as the dem elevation)\n");
    printf("longitude and latitude of the site (dd)\n");
    printf("longitude of location for met file time stamp\n");
    printf("year month day output_time_step (hours)\n");
    exit(-1);
  }
  /* note: this program will loop over all time, starting at 0 and advancing */
  /* every hour */
  /* output images ranging from 0 to 255 are made at every output_time_step */
  /* these are in the proper format for DHSVM */

  strcpy(demfilename, argv[1]);   /* name of the binary flo  at dem input file - no header */
  strcpy(outfilename, argv[2]);   /* name of the binary float hillshade output file        */
  nRows = GetNumber(argv[3]);
  nCols = GetNumber(argv[4]);
  dx = GetFloat(argv[5]); /* the cellsize of the dem */                            
  longitude=GetFloat(argv[6])*RADPDEG;
  latitude=GetFloat(argv[7])*RADPDEG;
  standardmeridian=GetFloat(argv[8])*RADPDEG;
  year = GetNumber(argv[9]);
  month = GetNumber(argv[10]);
  day = GetNumber(argv[11]);
  outstep = GetFloat(argv[12]);

  printf("calculating shade map for %d / %d / %d \n",month,day,year);


  temp = calloc(nRows*nCols, sizeof(float));
  if (temp == NULL)
    exit(-1);

  if (!(demfile = fopen(demfilename, "rb"))){
    printf("dem file not found \n");
    exit(-1);
  }

  if (!(outfile = fopen(outfilename, "wb"))){
    printf("output file not opened \n");
    exit(-1);
  }
  /*
  sprintf(outfilename2,"%s.float",outfilename);
  if (!(outfile2 = fopen(outfilename2, "wb"))){
    printf("output file not opened \n");
    exit(-1);
  }
  */
  fread(temp, sizeof(float), nCols*nRows, demfile); 

  if (!((elev) = (float**) calloc(nRows, sizeof(float*))))
    exit(-1);
  for (ny = 0; ny < nRows; ny++) {
    if (!((elev)[ny] = (float*) calloc(nCols, sizeof(float))))
      exit(-1);
  }
  if (!((slope) = (float**) calloc(nRows, sizeof(float*))))
    exit(-1);
  for (ny = 0; ny < nRows; ny++) {
    if (!((slope)[ny] = (float*) calloc(nCols, sizeof(float))))
      exit(-1);
  }
  if (!((aspect) = (float**) calloc(nRows, sizeof(float*))))
    exit(-1);
  for (ny = 0; ny < nRows; ny++) {
    if (!((aspect)[ny] = (float*) calloc(nCols, sizeof(float))))
      exit(-1);
  }
  if (!((hillshade) = (float**) calloc(nRows, sizeof(float*))))
    exit(-1);
  for (ny = 0; ny < nRows; ny++) {
    if (!((hillshade)[ny] = (float*) calloc(nCols, sizeof(float))))
      exit(-1);
  }
  if (!((outputgrid) = (unsigned char**) calloc(nRows, sizeof(unsigned char*))))
    exit(-1);
  for (ny = 0; ny < nRows; ny++) {
    if (!((outputgrid)[ny] = (unsigned char*) calloc(nCols, sizeof(unsigned char))))
      exit(-1);
  }

  max_elev = 0.0;
  for (ny = 0; ny < nRows; ny++) {
    for (nx = 0; nx < nCols; nx++) {
      elev[ny][nx] = temp[ny*nCols + nx]; 
      if(elev[ny][nx]>max_elev) max_elev = elev[ny][nx];
    }
  }

  CalcSlopeAspect(nRows,nCols,dx,elev,&slope,&aspect);


  dt=outstep;
  stepsperday=(int)(24/outstep);
  for(i=0;i<stepsperday;i++){
    hour=(float)i*outstep;
    printf("working on hour %f \n",hour);
    jday=DayOfYear(year,month,day);
  
  SolarDay(jday, longitude, latitude,
           standardmeridian, &noon_hour, 
           &declination, &halfdaylength,
           &sunrise, &sunset, &timeadjustment, &sunearthdistance);

  SolarHour(latitude, hour+dt, dt, noon_hour, &solar_hour,
	    declination,sunrise, sunset,
	    timeadjustment, sunearthdistance,
	    &sinesolaraltitude, &daylight, &solartimestep,
	    &sunmax, &solarazimuth); 
  sal=asin(sinesolaraltitude);
  saz=solarazimuth;

  /*  printf("for %2d/%2d/%4d at met-file-time %5.2f and solar hour %5.2f \n",
	  month,day,year,hour+0.5*dt,solar_hour);
  printf(" sunrise is at %5.2f with sunset at %5.2f and solar alt: %f with azimuth %f \n",
  sunrise,sunset,sal*DEGPRAD,saz*DEGPRAD);*/

  CalcHillShadeWithTerrainBlocking(nRows,nCols,dx,max_elev,elev,
				   sal,saz,slope,aspect,&hillshade);

  /* at this point hillshade is between 0 and 255 */
  /* which is the standard arc-info for the hillshade command */
  /* we need to translate this to the proper dhsvm format */
  /* and output it as an unsigned char */

    for (ny = 0; ny < nRows; ny++) {
      for (nx = 0; nx < nCols; nx++) {
	if(sinesolaraltitude>0)
	if(hillshade[ny][nx]/255/sinesolaraltitude>11.47)
	  outputgrid[ny][nx]=255;
	else
	  outputgrid[ny][nx]=(unsigned char)(hillshade[ny][nx]/sinesolaraltitude/11.47);
	else outputgrid[ny][nx]=0;
      }
    }
 


    /*       for (ny = 0; ny < nRows; ny++) {
     fwrite(hillshade[ny],sizeof(float),nCols,outfile2); 
     }*/
       
	for (ny = 0; ny < nRows; ny++) {
      fwrite(outputgrid[ny],sizeof(unsigned char),nCols,outfile); 
	}
		

      }
    }
Ejemplo n.º 16
0
int InitTime(TIMESTRUCT * Time, DATE * Start, DATE * End, DATE * StartRadar,
	     DATE * StartMM5, int Dt)
{
  const char *Routine = "InitTime";
  int tmpsecond;

  Time->Dt = Dt;		/* timestep in seconds */

  /* Just to be sure, recalculate the Julian and JDay fields of all the dates */
  if (Start != NULL) {
    CopyDate(&(Time->Start), Start);
    Time->Start.JDay = DayOfYear(Time->Start.Year, Time->Start.Month,
				 Time->Start.Day);
    Time->Start.Julian = GregorianToJulianDay(Time->Start.Year,
					      Time->Start.Month,
					      Time->Start.Day,
					      Time->Start.Hour,
					      Time->Start.Min, Time->Start.Sec);
    CopyDate(&(Time->Current), &(Time->Start));
  }

  if (End != NULL) {
    CopyDate(&(Time->End), End);
    Time->End.JDay = DayOfYear(Time->End.Year, Time->End.Month, Time->End.Day);
    Time->End.Julian = GregorianToJulianDay(Time->End.Year, Time->End.Month,
					    Time->End.Day, Time->End.Hour,
					    Time->End.Min, Time->End.Sec);
  }
  if (StartRadar != NULL) {
    CopyDate(&(Time->StartRadar), StartRadar);
    Time->StartRadar.JDay =
      DayOfYear(Time->StartRadar.Year, Time->StartRadar.Month,
		Time->StartRadar.Day);
    Time->StartRadar.Julian =
      GregorianToJulianDay(Time->StartRadar.Year, Time->StartRadar.Month,
			   Time->StartRadar.Day, Time->StartRadar.Hour,
			   Time->StartRadar.Min, Time->StartRadar.Sec);
  }
  if (StartMM5 != NULL) {
    CopyDate(&(Time->StartMM5), StartMM5);
    Time->StartMM5.JDay =
      DayOfYear(Time->StartMM5.Year, Time->StartMM5.Month, Time->StartMM5.Day);
    Time->StartMM5.Julian =
      GregorianToJulianDay(Time->StartMM5.Year, Time->StartMM5.Month,
			   Time->StartMM5.Day, Time->StartMM5.Hour,
			   Time->StartMM5.Min, Time->StartMM5.Sec);
  }

  if (Start != NULL && End != NULL) {
    if (After(&(Time->Start), &(Time->End)))
      return FALSE;
    Time->Step = 0;
    Time->NDaySteps = SECPDAY / Time->Dt;
    if ((SECPDAY - Time->NDaySteps * Time->Dt) != 0)
      ReportError((char *) Routine, 7);
    /* the 0.5 in the next line is because Julian day is measured from midday,
       and  we want since midnight */
    tmpsecond = Round(((Time->Start.Julian - 0.5) -
		       floor(Time->Start.Julian - 0.5)) * SECPDAY);
    Time->DayStep = tmpsecond / Time->Dt;
    /* The following line insures that the first timestep of the day would
       coincide with midnight */
    if (tmpsecond - Time->DayStep * Time->Dt != 0)
      ReportError((char *) Routine, 9);
    Time->NTotalSteps = NumberOfSteps(&(Time->Start), &(Time->End), Time->Dt);
    if (Time->NTotalSteps == FAIL)
      return FALSE;
  }

  return TRUE;
}
Ejemplo n.º 17
0
/*****************************************************************************
  SScanDate()
*****************************************************************************/
int SScanDate(char *DateStr, DATE * Day)
{
  char Str[BUFSIZE + 1];
  int i;
  int j;
  int Length;
  int Number[6];
  int DaysPerMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

  if (Str == NULL)
    return FALSE;

  strcpy(Str, DateStr);

  Length = strlen(Str);

  for (i = Length - 1, j = 0; i > 0; i--) {
    if (!isdigit((int) Str[i])) {
      Number[j] = atoi(&Str[i + 1]);
      Str[i] = '\0';
      j++;
    }
  }

  Number[j] = atoi(Str);

  if (j < 2 || j > 5)
    return FALSE;

  Day->Month = Number[j--];
  Day->Day = Number[j--];
  Day->Year = Number[j--];
  if (j >= 0)
    Day->Hour = Number[j--];
  else
    Day->Hour = 0;
  if (j >= 0)
    Day->Min = Number[j--];
  else
    Day->Min = 0;
  if (j >= 0)
    Day->Sec = Number[j--];
  else
    Day->Sec = 0;

  if (IsLeapYear(Day->Year))
    DaysPerMonth[1] = 29;
  else
    DaysPerMonth[1] = 28;

  if (Day->Month < 1 || Day->Month > MONTHPYEAR)
    return FALSE;
  if (Day->Day < 1 || Day->Day > DaysPerMonth[Day->Month - 1])
    return FALSE;
  if (Day->Hour < 0 || Day->Hour > 23)
    return FALSE;
  if (Day->Min < 0 || Day->Min > 59)
    return FALSE;
  if (Day->Sec < 0 || Day->Sec > 59)
    return FALSE;

  Day->JDay = DayOfYear(Day->Year, Day->Month, Day->Day);
  Day->Julian =
    GregorianToJulianDay(Day->Year, Day->Month, Day->Day, Day->Hour, Day->Min,
			 Day->Sec);

  return TRUE;
}
Ejemplo n.º 18
0
 /**
  * Returns the day of year portion of the time as a string
  *
  * @return string
  */
 QString iTime::DayOfYearString() const {
   return toString(DayOfYear());
 }
/*--------------------------------------------------------------
 * Operates like strftime() except:
 *  a) it returns -1 on error;
 *  b) strftime() expects tm_year to be 2 digits and so always
 *     adds 1900 to the year, while TimeSprintf() believes the
 *     year to be the actual year: 94 is AD 94 and so does not
 *     add 1900.
 *-------------------------------------------------------------*/
int TimeSprintf ( char *string, int max_size,
                  char *format, struct tm *ptm )
{
    char *pf;
    int  i, j;

    int  yy;        /* scratch variable for year */
    int  mon;       /* our internal use of the month is 1-12 */
    char *buffer;   /* where the output string goes */

    mon = ptm->tm_mon + 1;

    buffer = malloc ( 1024 );   /* largest likely output string */
    if ( buffer == NULL )
        return ( -1 );

    i = 0;    /* where we are in the output string */


    for ( pf = format; *pf != '\0' && i < 1024; pf++ )
    {
        if ( *pf != '%' )
            buffer[i++] = *pf;
        else
            switch ( *(++pf) )
            {
                /*--- day of the week: Sunday, Monday...---*/

            case 'a':               /* 3-letter weekday */
                j = DayOfWeek ( ptm );
                strncpy ( buffer + i,
                          Day_name_abbrev[j], 3 );
                i += 3;
                break;

            case 'A':               /* full weekday */
                j = DayOfWeek ( ptm );
                strcpy ( buffer + i, Day_name[j] );
                while ( *(buffer + i) != '\0' )
                    i++;
                break;

            case 'w':               /* weekday as a digit */
                j = DayOfWeek ( ptm );
                buffer[i++] = j + '0';
                break;

                /*--- day of the month: 1, 2, 3...---*/

            case 'd':               /* day as a number */
                buffer[i++] = ptm->tm_mday / 10 + '0';
                buffer[i++] = ptm->tm_mday % 10 + '0';
                break;

            case 'm':               /* month as a number */
                buffer[i++] =  mon  / 10 + '0';
                buffer[i++] =  mon  % 10 + '0';
                break;

                /*--- month ---*/

            case 'b':               /* 3-letter month */
                strncpy ( buffer + i,
                          Month_name_abbrev[mon], 3 );
                i += 3;
                break;

            case 'B':               /* full month name */
                strcpy ( buffer + i, Month_name[mon] );
                while ( *(buffer + i) != '\0' )
                    i++;
                break;

                /*--- year ---*/

            case 'Y':               /* year with century: 1994 */
                yy = ptm->tm_year;

                if ( yy < 0 )
                {
                    buffer[i++] = '-';
                    yy = -yy;
                }

                if ( yy > 9999 )
                {
                    buffer[i++] = yy / 10000 + '0';
                    yy %= 10000;
                }

                if ( yy > 999 )
                {
                    buffer[i++] = yy / 1000 + '0';
                    yy %= 1000;
                }

                if ( yy > 99 )
                {
                    buffer[i++] = yy / 100 + '0';
                    yy %= 100;
                }

                buffer[i++] = yy / 10 + '0';
                buffer[i++] = yy % 10 + '0';
                break;

            case 'y':               /* year without century: 94 */
                yy = ptm->tm_year;

                if ( yy < 0 )
                {
                    buffer[i++] = '-';
                    yy = -yy;
                }

                if ( yy > 100 )
                    yy %= 100;

                buffer[i++] = yy / 10 + '0';
                buffer[i++] = yy % 10 + '0';
                break;

            case 'x':               /* locale-specific date */
            {
                char s[18];

                TimeSprintf ( s, 18, "%a, %b %d, %Y", ptm );
                strcpy ( buffer + i, s );
                i += strlen ( s );
            }
                break;

                /*--- time in numbers ---*/

            case 'I':               /* hour on 12-hr clock */
            {
                int hour;

                if ( ptm->tm_hour > 12 )
                    hour = ptm->tm_hour - 12;
                else
                    hour = ptm->tm_hour;

                buffer[i++] = hour / 10 + '0';
                buffer[i++] = hour % 10 + '0';
            }
                break;

            case 'H':               /* hour on 24-hr clock */
                buffer[i++] = ptm->tm_hour / 10 + '0';
                buffer[i++] = ptm->tm_hour % 10 + '0';
                break;

            case 'M':               /* minute as a number */
                buffer[i++] = ptm->tm_min / 10 + '0';
                buffer[i++] = ptm->tm_min % 10 + '0';
                break;

            case 'S':               /* seconds as a number */
                buffer[i++] = ptm->tm_sec / 10 + '0';
                buffer[i++] = ptm->tm_sec % 10 + '0';
                break;

            case 'X':               /* time string: hh:mm:ss */
            {
                char s[9];

                TimeSprintf ( s, 9, "%H:%M:%S", ptm );
                strcpy ( buffer + i, s );
                i += 8;
            }
                break;

                /*--- miscellaneous ---*/

            case 'c':               /* date and time */
            {
                char s[28];

                TimeSprintf ( s, 28, "%b %d %H:%M:%S %Y", ptm );
                strcpy ( buffer + i, s );
                i += strlen ( s );
            }
                break;

            case 'j':               /* day of the year: 1-366 */
            {
                int day_of_year;

                day_of_year = DayOfYear ( ptm );

                if ( day_of_year < 10 )
                    buffer[i++] = day_of_year + '0';
                else
                {
                    if ( day_of_year > 99 )
                    {
                        buffer[i++] = day_of_year / 100 + '0';
                        day_of_year %= 100;
                    }

                    buffer[i++] = day_of_year / 10 + '0';
                    buffer[i++] = day_of_year % 10 + '0';
                }
            }
                break;

            case 'p':               /* AM or PM */
                if ( ptm->tm_hour < 12 )
                    buffer[i++] = 'A';
                else
                    buffer[i++] = 'P';
                buffer[i++] = 'M';
                break;

            case 'U':               /* Sunday week of year */
            case 'W':               /* Monday week of year */
            {
                int day_of_year,
                    day_of_week,
                    sunday_week;

                struct tm jan1;

                int jan1_dow;       /* jan 1 day of week */

                day_of_year = DayOfYear ( ptm );
                day_of_week = DayOfWeek ( ptm );

                LoadDateStruct ( &jan1, ptm->tm_year, 1, 1 );
                jan1_dow = DayOfWeek ( &jan1 );

                if ( jan1_dow != 0 )
                    day_of_year -= ( 7 - jan1_dow );

                if ( day_of_year < 1 )
                    sunday_week = 0;
                else
                {
                    sunday_week = 1;
                    sunday_week += ( day_of_year - 1 ) / 7;
                }

                if ( *pf == 'W' )   /* if Monday week */
                    if ( day_of_week < 1 )
                        sunday_week -= 1;

                if ( sunday_week > 9 )
                {
                    buffer[i++] = ( sunday_week / 10 ) + '0';
                    sunday_week %= 10;
                }

                buffer[i++] = sunday_week + '0';
            }
                break;

            case 'Z':               /* the time zone */
            {
                char *temp;

                temp = setlocale ( LC_TIME, NULL );
                if ( temp == NULL )
                    buffer[i++] = 'C';
                else
                {
                    strcpy ( buffer + i, temp );
                    i += strlen ( temp );
                }
            }
                break;

            case '%':               /* the percent sign */
                buffer[i++] = '%';
                break;

            default:
                strcpy ( buffer + i, "Error in TimeSprintf() " );
                i += 23;
            }
    }
    buffer[i] = '\0';

    strncpy ( string, buffer, max_size );
    free ( buffer );

    if ( i <= max_size )
        return ( i );
    else
        return ( 0 );
}