int main(void) { int i,id,idd,im,imm,iy,iyy,n; long j; char dummy[MAXSTR]; static char *name[]={"","january","february","march", "april","may","june","july","august", "september","october","november","december"}; FILE *fp; /* Check whether caldat properly undoes the operation of julday */ if ((fp = fopen("dates1.dat","r")) == NULL) nrerror("Data file dates1.dat not found\n"); fgets(dummy,MAXSTR,fp); fscanf(fp,"%d %*s ",&n); printf("\n %14s %43s\n","original date:","reconstructed date"); printf("%8s %5s %6s %15s %12s %5s %6s\n","month","day","year", "julian day","month","day","year"); for (i=1;i<=n;i++) { fscanf(fp,"%d %d %d ",&im,&id,&iy); fgets(dummy,MAXSTR,fp); j=julday(im,id,iy); caldat(j,&imm,&idd,&iyy); printf("%10s %3d %6d %13ld %16s %3d %6d\n",name[im], id,iy,j,name[imm],idd,iyy); } fclose(fp); return 0; }
void TestDates::benchmarkGetDateFromJulianDayFloatingPoint() { long jd = TJ1; int mm, dd, yy; QBENCHMARK { caldat(jd++, &mm, &dd, &yy); } }
/** * @todo Doesn't take into account the start day of the * week. strftime assumes that weeks start on Monday. */ int icaltime_week_number(const struct icaltimetype ictt) { UTinstant jt; memset(&jt, 0, sizeof(UTinstant)); jt.year = ictt.year; jt.month = ictt.month; jt.day = ictt.day; jt.i_hour = 0; jt.i_minute = 0; jt.i_second = 0; (void)juldat(&jt); (void)caldat(&jt); return (jt.day_of_year - jt.weekday) / 7; }
/** Day of the year that the first day of the week (Sunday) is on. */ int icaltime_start_doy_week(const struct icaltimetype t, int fdow) { UTinstant jt; int delta; memset(&jt, 0, sizeof(UTinstant)); jt.year = t.year; jt.month = t.month; jt.day = t.day; jt.i_hour = 0; jt.i_minute = 0; jt.i_second = 0; (void)juldat(&jt); (void)caldat(&jt); delta = jt.weekday - (fdow - 1); if (delta < 0) { delta += 7; } return jt.day_of_year - delta; }
void execute_tec( struct tec_object *tecfile , struct command_line_object *command_line, struct world_output_file_object *outfile, struct world_output_file_object *growth_outfile, struct world_object *world) { /*--------------------------------------------------------------*/ /* Local Function Declarations. */ /*--------------------------------------------------------------*/ int cal_date_lt(struct date, struct date ); long julday( struct date ); struct date caldat( long ); struct tec_entry *construct_tec_entry( struct date, char * ); void world_daily_I( long, struct world_object *, struct command_line_object *, struct tec_entry *, struct date); void world_hourly( struct world_object *, struct command_line_object *, struct tec_entry *, struct date); void world_daily_F( long, struct world_object *, struct command_line_object *, struct tec_entry *, struct date); void handle_event( struct tec_entry *, struct command_line_object *, struct date, struct world_object *); void execute_yearly_growth_output_event( struct world_object *, struct command_line_object *, struct date, struct world_output_file_object *); void execute_yearly_output_event( struct world_object *, struct command_line_object *, struct date, struct world_output_file_object *); void execute_daily_output_event( struct world_object *, struct command_line_object *, struct date, struct world_output_file_object *); void execute_daily_growth_output_event( struct world_object *, struct command_line_object *, struct date, struct world_output_file_object *); void execute_monthly_output_event( struct world_object *, struct command_line_object *, struct date, struct world_output_file_object *); void execute_hourly_output_event( struct world_object *, struct command_line_object *, struct date, struct world_output_file_object *); void execute_firespread_event( struct world_object *, struct command_line_object *, struct date); /*--------------------------------------------------------------*/ /* Local Variable Definition. */ /*--------------------------------------------------------------*/ int check; long day; long hour; long month; long year; struct date current_date; struct date next_date; struct tec_entry *event; /*--------------------------------------------------------------*/ /* Initialize the indices into the base station clime sequences*/ /*--------------------------------------------------------------*/ year = 0; month = 0; day = 0; hour = 0; /*--------------------------------------------------------------*/ /* Initialize the tec event */ /*--------------------------------------------------------------*/ event = construct_tec_entry(world[0].end_date,"none"); /*--------------------------------------------------------------*/ /* Loop from the start of the world to the end of the world. */ /*--------------------------------------------------------------*/ current_date = world[0].start_date; next_date = current_date; while ( cal_date_lt(current_date,world[0].end_date)){ /*--------------------------------------------------------------*/ /* Perform the tec event. */ /*--------------------------------------------------------------*/ handle_event(event,command_line,current_date,world); /*--------------------------------------------------------------*/ /* read the next tec file entry. */ /* if we are not at the end of the tec file. */ /*--------------------------------------------------------------*/ if ( !(feof(tecfile[0].tfile))){ /*--------------------------------------------------------------*/ /* read in the next tec line. */ /*--------------------------------------------------------------*/ check = fscanf(tecfile[0].tfile,"%d %d %d %d %s\n", &(event[0].cal_date.year), &(event[0].cal_date.month), &(event[0].cal_date.day), &(event[0].cal_date.hour), event[0].command); /*--------------------------------------------------------------*/ /* report an error if for some reason we cant read it */ /*--------------------------------------------------------------*/ if ( !check ){ fprintf(stderr,"\nERROR: the tec file is corrupted."); fclose(tecfile[0].tfile); exit(EXIT_FAILURE); } /*end if*/ } /*end if*/ /*--------------------------------------------------------------*/ /* if end of tec file next event is the end of the world */ /*--------------------------------------------------------------*/ else{ event = construct_tec_entry(world[0].end_date, "none"); } /*end if-else*/ /*--------------------------------------------------------------*/ /* If the next event's date exceeds the end_date then */ /* set the next event to nothing and at a time at the */ /* end of the simulation. */ /*--------------------------------------------------------------*/ if ( cal_date_lt(event[0].cal_date, world[0].end_date) == 0 ){ event = construct_tec_entry(world[0].end_date, "none"); } /*end if*/ /*--------------------------------------------------------------*/ /* Do stuff until the next tec event. */ /*--------------------------------------------------------------*/ while ( cal_date_lt(current_date, event[0].cal_date)){ /*--------------------------------------------------------------*/ /* Simulate the world for the start of this day e */ /*--------------------------------------------------------------*/ if ( current_date.hour == 1 ){ world_daily_I( day, world, command_line, event, current_date); } /*end if*/ /*--------------------------------------------------------------*/ /* Do hourly stuff for the day. */ /*--------------------------------------------------------------*/ world_hourly( world, command_line, event, current_date); /*--------------------------------------------------------------*/ /* Perform any requested hourly output */ /*--------------------------------------------------------------*/ if (command_line[0].output_flags.hourly == 1) execute_hourly_output_event(world,command_line,current_date,outfile); /*--------------------------------------------------------------*/ /* Increment to the next hour. */ /*--------------------------------------------------------------*/ current_date.hour++; /*--------------------------------------------------------------*/ /* Check if this is a day end. */ /*--------------------------------------------------------------*/ if ( current_date.hour == 25 ){ /*--------------------------------------------------------------*/ /* Simulate the world for the end of this day e */ /*--------------------------------------------------------------*/ world_daily_F( day, world, command_line, event, current_date); // printf("%s\n","finish_daily_simulation"); /*--------------------------------------------------------------*/ /* Perform any requested daily output */ /*--------------------------------------------------------------*/ if ((command_line[0].output_flags.daily_growth == 1) && (command_line[0].grow_flag > 0) ) { execute_daily_growth_output_event( world, command_line, current_date, growth_outfile); } if (command_line[0].output_flags.daily == 1) { //printf("%s\n","before_daily_output"); execute_daily_output_event( world, command_line, current_date, outfile); } /*--------------------------------------------------------------*/ /* Perform any requested yearly output */ /*--------------------------------------------------------------*/ if ((command_line[0].output_flags.yearly == 1) && (command_line[0].output_yearly_date.month==current_date.month)&& (command_line[0].output_yearly_date.day == current_date.day)) execute_yearly_output_event( world, command_line, current_date, outfile); if ((command_line[0].output_flags.yearly_growth == 1) && (command_line[0].output_yearly_date.month==current_date.month)&& (command_line[0].output_yearly_date.day == current_date.day) && (command_line[0].grow_flag > 0) ) execute_yearly_growth_output_event( world, command_line, current_date, growth_outfile); /*--------------------------------------------------------------*/ /* Determine the new calendar date if we add 1 day.*/ /* Do this by first conversting the current cal */ /* endar date into a julian day. Then adding one */ /* to the julian day and the converting back to */ /* get tomorrows calendar date. */ /* We assume that it starts at hour 1. */ /*--------------------------------------------------------------*/ day = day + 1; next_date = caldat(julday(current_date)+1); current_date.day = next_date.day; current_date.hour = next_date.hour; if (command_line[0].verbose_flag > 0) fprintf(stderr,"\n\nYEAR %d MONTH %d DAY %d\n\n", current_date.year,current_date.month,current_date.day); } /*end if*/ /*--------------------------------------------------------------*/ /* Check if this is a month end. */ /*--------------------------------------------------------------*/ if ( next_date.month != current_date.month ){ /*--------------------------------------------------------------*/ /* Do monthly stuff. */ /*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/ /* if fire spread is called - initiate fire spread routine */ /*--------------------------------------------------------------*/ if (command_line[0].firespread_flag == 1) { execute_firespread_event( world, command_line, current_date); } /*--------------------------------------------------------------*/ /* Perform any requested monthly output */ /*--------------------------------------------------------------*/ if (command_line[0].output_flags.monthly == 1) execute_monthly_output_event( world, command_line, current_date, outfile); /*--------------------------------------------------------------*/ /* increment month */ /*--------------------------------------------------------------*/ month = month + 1; current_date.month = next_date.month; } /* end if */ /*--------------------------------------------------------------*/ /* Check if this is a year end. */ /*--------------------------------------------------------------*/ if ( next_date.year != current_date.year ){ /*--------------------------------------------------------------*/ /* Do yearly stuff. */ /*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/ /* increment year */ /*-------------------------------------------------------------*/ printf("Year %d\n", current_date.year); year = year + 1; current_date.year= next_date.year; } /*end if*/ } /*end while*/ } /*end while*/ return; } /*end execute_tec.c*/
void getparams_xml(char* parameter_filename, e *E) { xmlDocPtr doc; xmlNodePtr cur; xmlChar *txt, *txt2, *txt3; int mm, dd, yy, hh, min; double sec; const char *month_name[] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; E->numLayers = 0; E->npts = 0; E->totalDuration = 0; setDefaults(E); doc = xmlParseFile(parameter_filename); if (doc == NULL ) { fprintf(stderr,"Could not open input file %s\n", parameter_filename); exit(1); } cur = xmlDocGetRootElement(doc); if (cur == NULL) { fprintf(stderr,"empty input file %s\n", parameter_filename); xmlFreeDoc(doc); exit(1); } if (xmlStrcmp(cur->name, (const xmlChar *) "SlicerData")) { fprintf(stderr,"%s is the wrong type, root node != SlicerData\n", parameter_filename); xmlFreeDoc(doc); exit(1); } // minimal parameters in an input file are: // // 1 sphere geometry // at least 1 layer cur = cur->xmlChildrenNode; while (cur != NULL) { // read in runtime control parameter if ((!xmlStrcmp(cur->name, (const xmlChar *) "params"))){ //printf( "params :\n" ); parseInputFile_params (E, doc, cur); } // read in the layer parameters else if ((!xmlStrcmp(cur->name, (const xmlChar *) "layer"))){ txt = xmlGetProp( cur, (const xmlChar *) "name" ); //printf( "layer %s:\n", txt ); lr_pack( (char *)txt ); // strdup is a GNU extension - don't use it! //E->L[E->numLayers].name = strdup((char*)txt); // malloc memory for the name E->L[E->numLayers].name = (char*)malloc(sizeof(char)*(strlen((char*)txt)+1)); strcpy(E->L[E->numLayers].name, (char*)txt); parseInputFile_layers (E, doc, cur, txt); E->numLayers++; xmlFree( txt ); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "sequence"))){ txt = xmlGetProp( cur, (const xmlChar *) "name" ); //printf( "sequence name = %s\n", txt ); lr_pack( (char *)txt ); E->standard_name = (char*)malloc(sizeof(char)*(strlen((char*)txt)+1)); strcpy(E->standard_name, (char*)txt); //printf("standard_name = %s\n",E->standard_name ); txt2 = xmlGetProp( cur, (const xmlChar *) "start_date" ); lr_pack( (char *)txt2 ); //sscanf(txt,"%lf", &E->start_date); //E->standard_name = (char*)malloc(sizeof(char)*(strlen((char*)txt)+1)); //strcpy(E->standard_name, (char*)txt); E->start_date = strtod((char *)txt2, (char **)NULL); caldat(E->start_date, &mm, &dd, &yy, &hh, &min, &sec); //printf("start_date = %f (%2d %s %4d)\n",E->start_date, dd, month_name[mm], yy ); txt3 = xmlGetProp( cur, (const xmlChar *) "preview" ); lr_pack( (char *)txt3 ); if(strncmp(txt3,"true",4) == 0){ E->preview = 1; } else if(strncmp(txt3,"TRUE",4) == 0){ E->preview = 1; } else{ E->preview = 0; } //printf("Preview = %d\n", E->preview); if(strncmp(E->standard_name,"sea_surface_temperature_anomaly",31) == 0){ E->long_name = (char*)malloc(sizeof(char)*(strlen((char*)txt)+1)); sprintf(E->long_name,"Sea Surface Temperature Anomaly"); } else if(strncmp(E->standard_name,"sea_surface_temperature",23) == 0){ E->long_name = (char*)malloc(sizeof(char)*(strlen((char*)txt)+1)); sprintf(E->long_name,"Sea Surface Temperature"); } else if(strncmp(E->standard_name,"sea_surface_salinity_anomaly",28) == 0){ E->long_name = (char*)malloc(sizeof(char)*(strlen((char*)txt)+1)); sprintf(E->long_name,"Sea Surface Salinity Anomaly"); } else if(strncmp(E->standard_name,"sea_surface_salinity",20) == 0){ E->long_name = (char*)malloc(sizeof(char)*(strlen((char*)txt)+1)); sprintf(E->long_name,"Sea Surface Salinity"); } else if(strncmp(E->standard_name,"sea_surface_velocity",20) == 0){ E->long_name = (char*)malloc(sizeof(char)*(strlen((char*)txt)+11)); sprintf(E->long_name,"Sea Surface Velocity Magnitude"); } else if(strncmp(E->standard_name,"sea_surface_height_anomaly",26) == 0){ E->long_name = (char*)malloc(sizeof(char)*(strlen((char*)txt)+1)); sprintf(E->long_name,"Sea Surface Height Anomaly"); } //printf("long_name = %s\n", E->long_name); //printf("found sequence tag\n"); parseInputFile_motion (E, doc, cur); } cur = cur->next; } xmlFreeDoc(doc); //printf("There are %d layers present in %s\n", E->numLayers, parameter_filename); //printf("There are %d sequences present in %s\n", E->npts, parameter_filename); if(E->npts>0){ // override the camer settings E->theta[0] = E->pts[0].pt[0]; E->theta[1] = E->pts[0].pt[1]; E->theta[2] = E->pts[0].pt[2]; E->viewer[0] = 0.0; E->viewer[1] = 0.0; E->viewer[2] = E->pts[0].zoom; } // if we are in preview mode then set the window size to small if(E->preview == 1){ E->xWinSize = 320; E->yWinSize = 180; } return; }