source: IO_handling/trunk/ppio/modeltime.patch @ 288

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/IO_handling/trunk/ppio/modeltime.patch@288
Revision 288, 6.5 KB checked in by jkettleb, 15 years ago (diff)

Fixes a bug when pp file has model time rather than 360 or Gregorian calendar
Fixes a bug related to assignment of level units

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • libcdms/include/cdunifpp/cdunifpp.h

    diff -Naur cdat-4.0b3/libcdms/include/cdunifpp/cdunifpp.h cdat-4.0b3.1/libcdms/include/cdunifpp/cdunifpp.h
    old new  
    117117typedef enum pp_filetype PPfiletype; 
    118118typedef enum pp_axistype PPaxistype; 
    119119typedef enum pp_lev_val_type PPlevvaltype; 
     120typedef enum pp_calendartype PPcalendartype; 
     121 
     122enum pp_calendartype { 
     123  gregorian,  
     124  cal360day, 
     125  model 
     126}; 
    120127 
    121128enum pp_filetype { 
    122129  pp_type, 
     
    586593PPdata *pp_taxis_to_values(const PPtaxis *, PPlist *); 
    587594PPdata *pp_taxis_to_boundary_values(const PPtaxis *, PPlist *); 
    588595int pp_is_time_mean(Fint); 
    589 int pp_is_360day_calendar(Fint); 
    590596Freal pp_time_diff(Fint, const PPdate *, const PPdate *); 
     597PPcalendartype pp_calendar_type(Fint); 
    591598long long pp_gregorian_to_secs(const PPdate *); 
    592599char *pp_t_units(const PPtaxis *, PPlist *); 
    593600 
  • libcdms/src/cdunif/cdunifpp/cdunifpp_axisvals.c

    diff -Naur cdat-4.0b3/libcdms/src/cdunif/cdunifpp/cdunifpp_axisvals.c cdat-4.0b3.1/libcdms/src/cdunif/cdunifpp/cdunifpp_axisvals.c
    old new  
    211211  return (ib == 2) || (ib == 3); 
    212212} 
    213213 
    214 int pp_is_360day_calendar(Fint LBTIM) { 
    215   int ic; 
    216   ic=LBTIM % 10; 
    217   return (ic == 2); 
    218 } 
    219  
    220214 
    221215/* float_time returns time in days since origin time */ 
    222216 
     
    226220 
    227221  const Freal sec_to_day = 1. / 86400.; 
    228222 
    229   if (pp_is_360day_calendar(LBTIM)) {     
    230  
     223  switch(pp_calendar_type(LBTIM)) { 
     224  case gregorian: 
     225    return (pp_gregorian_to_secs(date) - pp_gregorian_to_secs(orig_date)) * sec_to_day; 
     226    break; /* notreached */ 
     227  case cal360day: 
    231228    secs = 
    232229      date->second - orig_date->second +  
    233230      60 * (date->minute - orig_date->minute +  
     
    237234                              12 * (long long) (date->year - orig_date->year) )))); 
    238235 
    239236    return secs * sec_to_day; 
     237    break; /* notreached */ 
     238  case model: 
     239    secs = 
     240      date->second - orig_date->second +  
     241      60 * (date->minute - orig_date->minute +  
     242            60 * (date->hour - orig_date->hour +  
     243                  24 * (long long) (date->day - orig_date->day))); 
     244 
     245    return secs * sec_to_day; 
     246    break; 
    240247  } 
     248} 
    241249 
    242   else { 
     250PPcalendartype pp_calendar_type(Fint type){ 
    243251 
    244     return (pp_gregorian_to_secs(date) - pp_gregorian_to_secs(orig_date)) * sec_to_day; 
     252  switch(type%10) { 
     253 
     254  case 0: 
     255    /* fallthrough */ 
     256  case 3: 
     257    return model; 
     258    break; /* notreached */ 
     259  case 1: 
     260    return gregorian; 
     261    break; /* notreached */ 
     262  case 2: 
     263    return cal360day; 
     264    break; /* notreached */ 
     265  default: pp_switch_bug(); 
     266     
    245267  } 
    246268} 
    247269 
     270 
    248271long long pp_gregorian_to_secs(const PPdate *date) 
    249272{ 
    250273    /* FIXME: uses builtin time functions; these have a range 1902 - 2038 (approx). 
  • libcdms/src/cdunif/cdunifpp/cdunifpp_error.c

    diff -Naur cdat-4.0b3/libcdms/src/cdunif/cdunifpp/cdunifpp_error.c cdat-4.0b3.1/libcdms/src/cdunif/cdunifpp/cdunifpp_error.c
    old new  
    1111 
    1212int pp_switch_bug() 
    1313{ 
    14   pp_error("no match in switch statement; may indicate coding bug in CDUNIFPP"); 
     14  pp_error("no match in switch statement; may indicate coding bug in CDUNIFPP or unexpected header value"); 
    1515  return 0; 
    1616} 
    1717 
  • libcdms/src/cdunif/cdunifpp/cdunifpp_process.c

    diff -Naur cdat-4.0b3/libcdms/src/cdunif/cdunifpp/cdunifpp_process.c cdat-4.0b3.1/libcdms/src/cdunif/cdunifpp/cdunifpp_process.c
    old new  
    1919  PPzaxis *zaxis; 
    2020  PPtaxis *taxis; 
    2121  PPlevel *lev; 
    22   PPtime *time; 
     22  PPtime *time, *tval; 
    2323  void *oldptr; 
    2424  PPlist *heaplist, *xaxes, *yaxes, *zaxes, *taxes; 
    2525  PPlist *fieldvars; 
    26   PPlistpos handle; 
     26  PPlistpos handle, thandle; 
    2727  PPlist *gatts,*catts; 
    2828 
    2929  int ndims, dimid; 
     
    3838  PPvar *ppvar; 
    3939  PPlist *axislist; 
    4040  void *axis; 
    41   char *tunits; 
     41  char *tunits, *calatt; 
    4242  int have_hybrid=1; 
    4343  PPaxistype axistype; 
    4444 
     
    450450 
    451451    while ((axis=pp_list_walk(axislist,0,&handle))!=NULL) { 
    452452 
     453      units=NULL; /* reset */ 
     454      axisname=NULL; 
     455      standardname=NULL; 
     456      pointspacing=NULL; 
     457      posdir=NULL; 
     458 
    453459      dim=&cudims[dimid]; 
    454460      var=&cuvars[varid]; 
    455461      ppdim=(PPdim*) dim->internp; 
     
    565571        taxis=(PPtaxis*) axis; 
    566572        taxis->dimid = dimid;    
    567573        sprintf(dim->name,"time%d",idim); 
     574 
     575        switch(pp_calendar_type(taxis->type)) { 
     576        case gregorian: 
     577          calatt="gregorian"; 
     578          break; 
     579        case cal360day: 
     580          calatt="360_day"; 
     581          break; 
     582        case model: 
     583          pp_list_startwalk(taxis->values,&thandle); 
     584          tval = pp_list_walk(taxis->values,0,&thandle); 
     585           
     586          taxis->time_orig.year  = tval->time1.year; 
     587          taxis->time_orig.month = tval->time1.month; 
     588          taxis->time_orig.day   = tval->time1.day; 
     589          taxis->time_orig.hour  = tval->time1.hour; 
     590          taxis->time_orig.minute= tval->time1.minute; 
     591          taxis->time_orig.second= tval->time1.second; 
     592          calatt="none"; 
     593          break; 
     594        } 
     595         
     596        if(   pp_add_string_att(ppvar->atts,"calendar", 
     597                                calatt, 
     598                                heaplist)   !=0) goto err; 
     599 
    568600        if((   tunits=pp_t_units(taxis,heaplist)   )==NULL) goto err; 
    569601        dim->len = pp_list_size(taxis->values); 
    570602        if((   ppvar->data = pp_taxis_to_values(taxis,heaplist)   )==NULL) goto err; 
    571         if(   pp_add_string_att(ppvar->atts,"calendar", 
    572                                 pp_is_360day_calendar(taxis->type) ? "360_day" : "gregorian", 
    573                                 heaplist)   !=0) goto err; 
    574603        axisname="T"; 
    575604        standardname="time"; 
    576605        units=tunits; 
     
    585614      var->ndims=1; 
    586615      var->dims[0] = dimid; 
    587616       
    588       if (units) { 
     617      if (units != NULL) { 
    589618        if(   pp_add_string_att(ppvar->atts,"units",units,heaplist)   !=0) goto err; 
    590619        strncpy(dim->units,units,CU_MAX_NAME); 
    591620        dim->units[CU_MAX_NAME]='\0'; 
    592621      } 
    593622 
    594       if (axisname) 
     623      if (axisname != NULL) 
    595624        if(   pp_add_string_att(ppvar->atts,"axis",axisname,heaplist)   !=0) goto err; 
    596625 
    597       if (standardname) 
     626      if (standardname != NULL) 
    598627        if(   pp_add_string_att(ppvar->atts,"standard_name",standardname,heaplist)   !=0) goto err; 
    599628       
    600       if (pointspacing) 
     629      if (pointspacing != NULL) 
    601630        if(  pp_add_string_att(ppvar->atts,"point_spacing",pointspacing,heaplist)   !=0) goto err; 
    602631 
    603       if (posdir) 
     632      if (posdir != NULL) 
    604633        if(   pp_add_string_att(ppvar->atts,"positive",posdir,heaplist)   !=0) goto err; 
    605634 
    606635      varid++; 
Note: See TracBrowser for help on using the repository browser.