Changeset 2643

Show
Ignore:
Timestamp:
02/16/09 15:10:57 (18 hours ago)
Author:
janehu
Message:

Updated to be able to update the coordinates on copy of the DB exodus file as defined in the FileOption::destination, and keep the original coordinates if the node map are not matching.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • MOAB/trunk/ReadNCDF.cpp

    r2642 r2643  
    19271927  //currently support 'sum' 
    19281928  //destination shows where to store the updated info, currently assume it is 
    1929   //stored in the same database by replacing the old info. 
     1929  //stored in the same database by replacing the old info if there's no input 
     1930  //for destination, or the destination data is given in exodus format and just 
     1931  //need to update the coordinates. 
    19301932  //Assumptions: 
    1931   //Since the exodus_file will not have a node_num_map, so the strategies are following, this is expected to be very slow. 
    19321933  //1. Assume the num_el_blk's in both DB and update exodus file are the same.  
    19331934  //2. Assume num_el_in_blk1...num_el_in_blk(num_el_blk) numbers are matching, may in  
     
    19741975 
    19751976  std::string filename( exodus_file_name ); 
     1977 
     1978  //3. check for destination, current only generates exodus file 
     1979  const char* des ; 
     1980  if(tokens.size() > 3 && !tokens[3].empty()) 
     1981    des = tokens[3].c_str(); 
     1982  else 
     1983    des = ""; 
    19761984 
    19771985  //a. Deal with DB file first: get the node_num_map.  
     
    19972005    arrays[2] = new double[numberNodes_loading]; 
    19982006 
    1999   for (int i = 0; i < numberNodes_loading; i++) 
    2000   { 
    2001     arrays[0][i] = 0.0; 
    2002     arrays[1][i] = 0.0; 
    2003     if( numberDimensions_loading == 3 ) 
    2004       arrays[2][i] = 0.0; 
    2005   } 
    2006    
     2007  //get original nodal coordinates, in case of not matching in node id's, 
     2008  //those coordinate will be kept. 
     2009  NcVar *coord = ncFile->get_var("coord"); 
     2010  if (NULL == coord || !coord->is_valid() ) 
     2011  { 
     2012    readMeshIface->report_error("MBCN:: Problem getting coords variable."); 
     2013    do_delete(ptr1, NULL, NULL, NULL, arrays); 
     2014    return MB_FAILURE; 
     2015  } 
     2016 
     2017  NcBool status = coord->get(arrays[0], 1, numberNodes_loading); 
     2018  if (0 == status) { 
     2019    readMeshIface->report_error("MBCN:: Problem getting x coord array."); 
     2020    do_delete(ptr1, NULL, NULL, NULL, arrays); 
     2021    return MB_FAILURE; 
     2022  } 
     2023  
     2024  status = coord->set_cur(1, 0); 
     2025  if (0 == status) { 
     2026    readMeshIface->report_error("MBCN:: Problem getting x deformation array."); 
     2027    do_delete(ptr1, NULL, NULL, NULL, arrays); 
     2028    return MB_FAILURE; 
     2029  } 
     2030 
     2031  status = coord->get(arrays[1], 1, numberNodes_loading); 
     2032  if (0 == status) { 
     2033    readMeshIface->report_error("MBCN:: Problem getting y coord array."); 
     2034    do_delete(ptr1, NULL, NULL, NULL, arrays); 
     2035    return MB_FAILURE; 
     2036  } 
     2037  if (numberDimensions_loading == 3 ) 
     2038  { 
     2039    status = coord->set_cur(2, 0); 
     2040    if (0 == status) { 
     2041      readMeshIface->report_error("MBCN:: Problem getting x deformation array."); 
     2042      do_delete(ptr1, NULL, NULL, NULL, arrays); 
     2043      return MB_FAILURE; 
     2044    } 
     2045    status = coord->get(arrays[2], 1,  numberNodes_loading); 
     2046    if (0 == status) { 
     2047      readMeshIface->report_error("MBCN:: Problem getting z coord array."); 
     2048      do_delete(ptr1, NULL, NULL, NULL, arrays); 
     2049      return MB_FAILURE; 
     2050    } 
     2051  } 
     2052 
     2053  //remember the original numberNodes_loading, the later one is expected to 
     2054  //be larger than this one. 
     2055  const int init_numberNodes = numberNodes_loading; 
     2056 
    20072057  // b. read in the node_num_map and coords from the input exodus file. 
    20082058  reset(); 
     
    20272077      if (0 == status) { 
    20282078        readMeshIface->report_error("ReadNCDF:: Problem getting node number map data."); 
    2029         delete [] ptr2
     2079        do_delete(ptr1, ptr2, NULL, NULL, arrays)
    20302080        return MB_FAILURE; 
    20312081      } 
     
    20562106        (numberDimensions_loading == 3 && (NULL == coordz || !coordz->is_valid())) ) { 
    20572107      readMeshIface->report_error("MBCN:: Problem getting coords variable."); 
    2058       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
    2059       return MB_FAILURE; 
    2060     } 
    2061  
    2062     NcBool status = coordx->set_cur(time_step-1, 0); 
     2108      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
     2109      return MB_FAILURE; 
     2110    } 
     2111 
     2112    status = coordx->set_cur(time_step-1, 0); 
    20632113    if (0 == status) { 
    20642114      readMeshIface->report_error("MBCN:: Problem getting x deformation array."); 
    2065       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2115      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    20662116      return MB_FAILURE; 
    20672117    } 
     
    20692119    if (0 == status) { 
    20702120      readMeshIface->report_error("MBCN:: Problem getting x deformation array."); 
    2071       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2121      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    20722122      return MB_FAILURE; 
    20732123    } 
     
    20752125    if (0 == status) { 
    20762126      readMeshIface->report_error("MBCN:: Problem getting y deformation array."); 
    2077       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2127      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    20782128      return MB_FAILURE; 
    20792129    } 
     
    20812131    if (0 == status) { 
    20822132      readMeshIface->report_error("MBCN:: Problem getting y deformation array."); 
    2083       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2133      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    20842134      return MB_FAILURE; 
    20852135    } 
     
    20892139      if (0 == status) { 
    20902140        readMeshIface->report_error("MBCN:: Problem getting z deformation array."); 
    2091         do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2141        do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    20922142        return MB_FAILURE; 
    20932143      } 
     
    20952145      if (0 == status) { 
    20962146        readMeshIface->report_error("MBCN:: Problem getting z deformation array."); 
    2097         do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2147        do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    20982148        return MB_FAILURE; 
    20992149      } 
     
    21092159        (numberDimensions_loading == 3 && (NULL == coord3 || !coord3->is_valid())) ) { 
    21102160      readMeshIface->report_error("MBCN:: Problem getting coords variable."); 
    2111       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2161      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    21122162      return MB_FAILURE; 
    21132163    } 
     
    21162166    if (0 == status) { 
    21172167      readMeshIface->report_error("MBCN:: Problem getting x coord array."); 
    2118       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2168      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    21192169      return MB_FAILURE; 
    21202170    } 
     
    21222172    if (0 == status) { 
    21232173      readMeshIface->report_error("MBCN:: Problem getting y coord array."); 
    2124       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2174      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    21252175      return MB_FAILURE; 
    21262176    } 
     
    21302180      if (0 == status) { 
    21312181        readMeshIface->report_error("MBCN:: Problem getting z coord array."); 
    2132         do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2182        do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    21332183        return MB_FAILURE; 
    21342184      } 
     
    21362186 
    21372187    //c. match node_num_map for DB and exodus file. 
    2138     for(int node_num = 0; node_num < numberNodes_loading; ) 
     2188    for(int node_num = 0; node_num < init_numberNodes; ) 
    21392189    { 
    21402190      NcBool found = 0; 
     
    21532203      if(!found) 
    21542204      { 
    2155         readMeshIface->report_error("MBCN:: node maps do not match."); 
    2156         do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
    2157         return MB_FAILURE; 
    2158       } 
    2159       
     2205        node_num++; 
     2206        continue;  
     2207      } 
     2208  
    21602209      for(int j = 1;j <= numberNodes_loading ; j++) 
    21612210      { 
     
    21822231    } 
    21832232 
    2184     ncFile = new NcFile(exodusFile.c_str(), NcFile::Write); 
     2233    if(strcmp (des, "")) 
     2234    { 
     2235      std::string destinate(des); 
     2236      if(destinate.substr(0,1) == " ") 
     2237        destinate = destinate.substr(1);  
     2238      ncFile = new NcFile(destinate.c_str(), NcFile::Write); 
     2239      if (NULL == ncFile || !ncFile->is_valid()) 
     2240        readMeshIface->report_error("MBCN:: problem opening Netcdf/Exodus II file %s", des); 
     2241    } 
     2242 
     2243    else 
     2244    { 
     2245      ncFile = new NcFile(exodusFile.c_str(), NcFile::Write); 
     2246      if (NULL == ncFile || !ncFile->is_valid()) 
     2247        readMeshIface->report_error("MBCN:: problem opening Netcdf/Exodus II file %s", exodusFile.c_str()); 
     2248    } 
    21852249 
    21862250    if (NULL == ncFile || !ncFile->is_valid()) 
    21872251    { 
    2188       readMeshIface->report_error("MBCN:: problem opening Netcdf/Exodus II file %s",exodus_file_name); 
    2189       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2252      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    21902253      return MB_FAILURE; 
    21912254    } 
     
    21942257    if (NULL == coords || !coords->is_valid()) { 
    21952258      readMeshIface->report_error("MBCN:: Problem getting coords variable."); 
    2196        
    2197       return MB_FAILURE; 
    2198     } 
    2199     status = coords->put(arrays[0], 1, numberNodes_loading); 
     2259      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays);  
     2260      return MB_FAILURE; 
     2261    } 
     2262    status = coords->put(arrays[0], 1, init_numberNodes); 
    22002263    if (0 == status) { 
    22012264      readMeshIface->report_error("MBCN:: Problem saving x coord array."); 
    2202       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2265      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    22032266      return MB_FAILURE; 
    22042267    } 
     
    22062269    if (0 == status) { 
    22072270      readMeshIface->report_error("MBCN:: Problem getting y coord array."); 
    2208       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
    2209       return MB_FAILURE; 
    2210     } 
    2211  
    2212     status = coords->put(arrays[1], 1,  numberNodes_loading); 
     2271      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
     2272      return MB_FAILURE; 
     2273    } 
     2274 
     2275    status = coords->put(arrays[1], 1,  init_numberNodes); 
    22132276    if (0 == status) { 
    22142277      readMeshIface->report_error("MBCN:: Problem saving y coord array."); 
    2215       do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2278      do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    22162279      return MB_FAILURE; 
    22172280    } 
     
    22222285      if (0 == status) { 
    22232286        readMeshIface->report_error("MBCN:: Problem getting y coord array."); 
    2224         do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
    2225         return MB_FAILURE; 
    2226       } 
    2227  
    2228       status = coords->put(arrays[2], 1, numberNodes_loading); 
     2287        do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
     2288        return MB_FAILURE; 
     2289      } 
     2290 
     2291      status = coords->put(arrays[2], 1, init_numberNodes); 
    22292292      if (0 == status) { 
    22302293        readMeshIface->report_error("MBCN:: Problem saving z coord array."); 
    2231         do_delete(ptr1, ptr2, deformed_arrays, orig_coords, arrays); 
     2294        do_delete(ptr1, ptr2, &deformed_arrays, &orig_coords, arrays); 
    22322295        return MB_FAILURE; 
    22332296      } 
     
    22532316  
    22542317void ReadNCDF::do_delete(int *ptr1, int *ptr2, 
    2255                       std::vector<double*> deformed_arrays,  
    2256                       std::vector<double*>  orig_coords ,  
     2318                      std::vector<double*>* deformed_arrays,  
     2319                      std::vector<double*>*  orig_coords ,  
    22572320                      std::vector<double*> arrays) 
    22582321{ 
    22592322  delete ptr1; 
    2260   delete ptr2; 
     2323  if(ptr2) 
     2324    delete ptr2; 
    22612325  delete [] arrays[0]; 
    22622326  delete [] arrays[1]; 
    2263   delete [] deformed_arrays[0]; 
    2264   delete [] deformed_arrays[1]; 
    2265   delete [] orig_coords[0]; 
    2266   delete [] orig_coords[1]; 
     2327  if(deformed_arrays) 
     2328  { 
     2329    delete [] (*deformed_arrays)[0]; 
     2330    delete [] (*deformed_arrays)[1]; 
     2331  } 
     2332  if(orig_coords) 
     2333  { 
     2334    delete [] (*orig_coords)[0]; 
     2335    delete [] (*orig_coords)[1]; 
     2336  } 
    22672337  if(numberDimensions_loading == 3 ) 
    22682338  {  
    22692339    delete [] arrays[2]; 
    2270     delete [] deformed_arrays[2]; 
    2271     delete [] orig_coords[2]; 
     2340    if(deformed_arrays) 
     2341      delete [] (*deformed_arrays)[2]; 
     2342    if(orig_coords) 
     2343      delete [] (*orig_coords)[2]; 
    22722344  } 
    22732345}