Changeset 838


Ignore:
Timestamp:
04/11/16 14:48:11 (8 years ago)
Author:
ymipsl
Message:

More flexible management of attributes to initialize "CGenerateRectilinearDomain" filter.

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/generate_rectilinear_domain.cpp

    r836 r838  
    4444    const double defaultBndsLatEnd = 90; 
    4545 
    46     if ((!lon_start.isEmpty() && lon_end.isEmpty()) || 
    47         (lon_start.isEmpty() && !lon_end.isEmpty())) 
    48          ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", 
    49                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    50                << "Only longitude start or longitude end attribute is defined." << std::endl 
    51                << "Must define both: 'lon_start' and 'lon_end'."); 
    5246 
    53     if ((!lat_start.isEmpty() && lat_end.isEmpty()) || 
    54         (lat_start.isEmpty() && !lat_end.isEmpty())) 
    55          ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", 
    56                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    57                << "Only latitude start or latitude end attribute is defined." << std::endl 
    58                << "Must define both: 'lat_start' and 'lat_end'."); 
     47    int niGlo = domainDst->ni_glo; 
     48    int njGlo = domainDst->nj_glo; 
    5949 
    60     if ((!bounds_lon_start.isEmpty() && bounds_lon_end.isEmpty()) || 
    61         (bounds_lon_start.isEmpty() && !bounds_lon_end.isEmpty())) 
    62          ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", 
    63                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    64                << "Only longitude boundary start or longitude boundary end attribute is defined." << std::endl 
    65                << "Must define both: 'bounds_lon_start' and 'bounds_lon_end'."); 
    6650 
    67     if ((!bounds_lat_start.isEmpty() && bounds_lat_end.isEmpty()) || 
    68         (bounds_lat_start.isEmpty() && !bounds_lat_end.isEmpty())) 
    69          ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", 
    70                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    71                << "Only latitude boundary start or latitude boundary end attribute is defined." << std::endl 
    72                << "Must define both: 'bounds_lat_start' and 'bounds_lat_end'."); 
     51    double deltaLon=(defaultBndsLonEnd-defaultBndsLonStart)/niGlo ;  
     52    if (!lon_start.isEmpty() && !lon_end.isEmpty() ) deltaLon=(lon_end-lon_start)/(niGlo-1) ; 
     53    if (!bounds_lon_start.isEmpty() && !bounds_lon_end.isEmpty()) deltaLon=(bounds_lon_end-bounds_lon_start)/niGlo ; 
     54    if (!lon_start.isEmpty() && !bounds_lon_end.isEmpty()) deltaLon=(bounds_lon_end-bounds_lon_start)/(niGlo-0.5) ; 
     55    if (!bounds_lon_start.isEmpty() && !lon_end.isEmpty()) deltaLon=(bounds_lon_end-bounds_lon_start)/(niGlo-0.5) ; 
    7356 
    74     if (!bounds_lon_start.isEmpty() && !lon_start.isEmpty()) 
    75          ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", 
    76                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    77                << "Only one longitude boundary attribute or longitude can be used but both 'bounds_lon_start' and 'lon_start' are defined." << std::endl 
    78                << "Define only one attribute: 'bounds_lon_start' or 'lon_start'."); 
     57    if (lon_start.isEmpty()) 
     58    { 
     59      if (!bounds_lon_start.isEmpty())      domainDst->lon_start=bounds_lon_start+0.5*deltaLon ; 
     60      else if (!lon_end.isEmpty())          domainDst->lon_start= lon_end-(niGlo-1.)*deltaLon ; 
     61      else if (!bounds_lon_end.isEmpty())   domainDst->lon_start=bounds_lon_end-(niGlo-0.5)*deltaLon ; 
     62      else                                  domainDst->lon_start=defaultBndsLonStart+0.5*deltaLon ; 
     63    } 
     64    else domainDst->lon_start=lon_start ; 
    7965 
    80     if (!bounds_lat_start.isEmpty() && !lat_start.isEmpty()) 
    81          ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", 
    82                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    83                << "Only one latitude boundary attribute or latitude can be used but both 'bounds_lat_start' and 'lat_start' are defined." << std::endl 
    84                << "Define only one attribute: 'bounds_lat_start' or 'lat_start'."); 
     66    if (bounds_lon_start.isEmpty()) 
     67    { 
     68      if (!lon_start.isEmpty())           domainDst->bounds_lon_start=lon_start-0.5*deltaLon ; 
     69      else if (!lon_end.isEmpty())        domainDst->bounds_lon_start= lon_end-(niGlo-0.5)*deltaLon ; 
     70      else if (!bounds_lon_end.isEmpty()) domainDst->bounds_lon_start=bounds_lon_end-niGlo*deltaLon ; 
     71      else                                domainDst->bounds_lon_start=defaultBndsLonStart ; 
     72    }  
     73    else domainDst->bounds_lon_start=bounds_lon_start ; 
    8574 
    86     if (bounds_lon_start.isEmpty() && lon_start.isEmpty()) 
     75    if (lon_end.isEmpty()) 
    8776    { 
    88       bounds_lon_start.setValue(defaultBndsLonStart); 
    89       bounds_lon_end.setValue(defaultBndsLonEnd); 
     77      if (!bounds_lon_end.isEmpty())        domainDst->lon_end=bounds_lon_end-0.5*deltaLon ; 
     78      else if (!bounds_lon_start.isEmpty()) domainDst->lon_end=bounds_lon_start+(niGlo-0.5)*deltaLon ; 
     79      else if (!lon_start.isEmpty())        domainDst->lon_end=lon_start+(niGlo-1.)*deltaLon ; 
     80      else                                  domainDst->lon_end=defaultBndsLonEnd-0.5*deltaLon ; 
    9081    } 
     82    else domainDst->lon_end=lon_end ;     
    9183 
    92     if (bounds_lat_start.isEmpty() && lat_start.isEmpty()) 
     84    if (bounds_lon_end.isEmpty()) 
    9385    { 
    94       bounds_lat_start.setValue(defaultBndsLatStart); 
    95       bounds_lat_end.setValue(defaultBndsLatEnd); 
     86      if (!lon_end.isEmpty())               domainDst->bounds_lon_end=lon_end+0.5*deltaLon ; 
     87      else if (!bounds_lon_start.isEmpty()) domainDst->bounds_lon_end=bounds_lon_start+niGlo*deltaLon ; 
     88      else if (!lon_start.isEmpty())        domainDst->bounds_lon_end=lon_start+(niGlo-0.5)*deltaLon ; 
     89      else                                  domainDst->bounds_lon_end=defaultBndsLonEnd ; 
    9690    } 
     91    else domainDst->bounds_lon_end=bounds_lon_end; 
    9792 
    98     if (!bounds_lon_start.isEmpty()) 
     93 
     94 
     95 
     96    double deltaLat=(defaultBndsLatEnd-defaultBndsLatStart)/njGlo ;  
     97    if (!lat_start.isEmpty() && !lat_end.isEmpty() ) deltaLat=(lat_end-lat_start)/(njGlo-1) ; 
     98    if (!bounds_lat_start.isEmpty() && !bounds_lat_end.isEmpty()) deltaLat=(bounds_lat_end-bounds_lat_start)/njGlo ; 
     99    if (!lat_start.isEmpty() && !bounds_lat_end.isEmpty()) deltaLat=(bounds_lat_end-bounds_lat_start)/(njGlo-0.5) ; 
     100    if (!bounds_lat_start.isEmpty() && !lat_end.isEmpty()) deltaLat=(bounds_lat_end-bounds_lat_start)/(njGlo-0.5) ; 
     101 
     102    if (lat_start.isEmpty()) 
    99103    { 
    100       int niGlo = domainDst->ni_glo.getValue(); 
     104      if (!bounds_lat_start.isEmpty())      domainDst->lat_start=bounds_lat_start+0.5*deltaLat ; 
     105      else if (!lat_end.isEmpty())          domainDst->lat_start= lat_end-(njGlo-1.)*deltaLat ; 
     106      else if (!bounds_lat_end.isEmpty())   domainDst->lat_start=bounds_lat_end-(njGlo-0.5)*deltaLat ; 
     107      else                                  domainDst->lat_start=defaultBndsLatStart+0.5*deltaLat ; 
     108    } 
     109    else domainDst->lat_start=lat_start; 
    101110 
    102       double boundsLonRange = bounds_lon_end - bounds_lon_start; 
    103       double boundsLonStep = boundsLonRange/(double(niGlo)); 
    104       domainDst->bounds_lon_start.setValue(bounds_lon_start); 
    105       domainDst->bounds_lon_end.setValue(bounds_lon_end); 
    106       domainDst->lon_start.setValue(bounds_lon_start + boundsLonStep/2); 
    107       domainDst->lon_end.setValue( bounds_lon_end   - boundsLonStep/2); 
     111    if (bounds_lat_start.isEmpty()) 
     112    { 
     113      if (!lat_start.isEmpty())           domainDst->bounds_lat_start=lat_start-0.5*deltaLat ; 
     114      else if (!lat_end.isEmpty())        domainDst->bounds_lat_start= lat_end-(njGlo-0.5)*deltaLat ; 
     115      else if (!bounds_lat_end.isEmpty()) domainDst->bounds_lat_start=bounds_lat_end-njGlo*deltaLat ; 
     116      else                                domainDst->bounds_lat_start=defaultBndsLatStart ; 
     117    }  
     118    else domainDst->bounds_lat_start=bounds_lat_start; 
     119     
     120    if (lat_end.isEmpty()) 
     121    { 
     122      if (!bounds_lat_end.isEmpty())        domainDst->lat_end=bounds_lat_end-0.5*deltaLat ; 
     123      else if (!bounds_lat_start.isEmpty()) domainDst->lat_end=bounds_lat_start+(njGlo-0.5)*deltaLat ; 
     124      else if (!lat_start.isEmpty())        domainDst->lat_end=lat_start+(njGlo-1.)*deltaLat ; 
     125      else                                  domainDst->lat_end=defaultBndsLatEnd-0.5*deltaLat ; 
     126    }     
     127    else domainDst->lat_end=lat_end; 
     128     
     129    if (bounds_lat_end.isEmpty()) 
     130    { 
     131      if (!lat_end.isEmpty())               domainDst->bounds_lat_end=lat_end+0.5*deltaLat ; 
     132      else if (!bounds_lat_start.isEmpty()) domainDst->bounds_lat_end=bounds_lat_start+njGlo*deltaLat ; 
     133      else if (!lat_start.isEmpty())        domainDst->bounds_lat_end=lat_start+(njGlo-0.5)*deltaLat ; 
     134      else                                  domainDst->bounds_lat_end=defaultBndsLatEnd ; 
    108135    } 
     136    else domainDst->bounds_lat_end=bounds_lat_end; 
    109137 
    110     if (!bounds_lat_start.isEmpty()) 
    111     { 
    112       int njGlo = domainDst->nj_glo.getValue(); 
    113  
    114       double boundsLatRange = bounds_lat_end - bounds_lat_start; 
    115       double boundsLatStep = boundsLatRange/(double(njGlo)); 
    116       domainDst->bounds_lat_start.setValue(bounds_lat_start); 
    117       domainDst->bounds_lat_end.setValue(bounds_lat_end); 
    118       domainDst->lat_start.setValue(bounds_lat_start + boundsLatStep/2); 
    119       domainDst->lat_end.setValue(bounds_lat_end   - boundsLatStep/2); 
    120     } 
    121  
    122     if (lon_start.isEmpty() && lat_start.isEmpty()) return; 
    123  
    124     if (!lon_start.isEmpty()) 
    125     { 
    126       int niGlo = domainDst->ni_glo.getValue(); 
    127  
    128       double lonRange = lon_end - lon_start; 
    129       double lonStep = (1 == niGlo) ? lonRange : lonRange/(double(niGlo)-1); 
    130       domainDst->lon_start.setValue(lon_start); 
    131       domainDst->lon_end.setValue(lon_end); 
    132       domainDst->bounds_lon_start.setValue(lon_start - lonStep/2); 
    133       domainDst->bounds_lon_end.setValue(lon_end   + lonStep/2); 
    134     } 
    135  
    136     if (!lat_start.isEmpty()) 
    137     { 
    138       int njGlo = domainDst->nj_glo.getValue(); 
    139  
    140       double latRange = lat_end - lat_start; 
    141       double latStep = (1 == njGlo) ? latRange : latRange/(double(njGlo)-1); 
    142       domainDst->lat_start.setValue(lat_start); 
    143       domainDst->lat_end.setValue(lat_end); 
    144       domainDst->bounds_lat_start.setValue(lat_start - latStep/2); 
    145       domainDst->bounds_lat_end.setValue(lat_end   + latStep/2); 
    146     } 
    147138  } 
    148139 
Note: See TracChangeset for help on using the changeset viewer.