Changeset 2643
- Timestamp:
- 02/16/09 15:10:57 (18 hours ago)
- Files:
-
- MOAB/trunk/ReadNCDF.cpp (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
MOAB/trunk/ReadNCDF.cpp
r2642 r2643 1927 1927 //currently support 'sum' 1928 1928 //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. 1930 1932 //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.1932 1933 //1. Assume the num_el_blk's in both DB and update exodus file are the same. 1933 1934 //2. Assume num_el_in_blk1...num_el_in_blk(num_el_blk) numbers are matching, may in … … 1974 1975 1975 1976 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 = ""; 1976 1984 1977 1985 //a. Deal with DB file first: get the node_num_map. … … 1997 2005 arrays[2] = new double[numberNodes_loading]; 1998 2006 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 2007 2057 // b. read in the node_num_map and coords from the input exodus file. 2008 2058 reset(); … … 2027 2077 if (0 == status) { 2028 2078 readMeshIface->report_error("ReadNCDF:: Problem getting node number map data."); 2029 d elete [] ptr2;2079 do_delete(ptr1, ptr2, NULL, NULL, arrays); 2030 2080 return MB_FAILURE; 2031 2081 } … … 2056 2106 (numberDimensions_loading == 3 && (NULL == coordz || !coordz->is_valid())) ) { 2057 2107 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 NcBoolstatus = 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); 2063 2113 if (0 == status) { 2064 2114 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); 2066 2116 return MB_FAILURE; 2067 2117 } … … 2069 2119 if (0 == status) { 2070 2120 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); 2072 2122 return MB_FAILURE; 2073 2123 } … … 2075 2125 if (0 == status) { 2076 2126 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); 2078 2128 return MB_FAILURE; 2079 2129 } … … 2081 2131 if (0 == status) { 2082 2132 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); 2084 2134 return MB_FAILURE; 2085 2135 } … … 2089 2139 if (0 == status) { 2090 2140 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); 2092 2142 return MB_FAILURE; 2093 2143 } … … 2095 2145 if (0 == status) { 2096 2146 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); 2098 2148 return MB_FAILURE; 2099 2149 } … … 2109 2159 (numberDimensions_loading == 3 && (NULL == coord3 || !coord3->is_valid())) ) { 2110 2160 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); 2112 2162 return MB_FAILURE; 2113 2163 } … … 2116 2166 if (0 == status) { 2117 2167 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); 2119 2169 return MB_FAILURE; 2120 2170 } … … 2122 2172 if (0 == status) { 2123 2173 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); 2125 2175 return MB_FAILURE; 2126 2176 } … … 2130 2180 if (0 == status) { 2131 2181 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); 2133 2183 return MB_FAILURE; 2134 2184 } … … 2136 2186 2137 2187 //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; ) 2139 2189 { 2140 2190 NcBool found = 0; … … 2153 2203 if(!found) 2154 2204 { 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 2160 2209 for(int j = 1;j <= numberNodes_loading ; j++) 2161 2210 { … … 2182 2231 } 2183 2232 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 } 2185 2249 2186 2250 if (NULL == ncFile || !ncFile->is_valid()) 2187 2251 { 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); 2190 2253 return MB_FAILURE; 2191 2254 } … … 2194 2257 if (NULL == coords || !coords->is_valid()) { 2195 2258 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); 2200 2263 if (0 == status) { 2201 2264 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); 2203 2266 return MB_FAILURE; 2204 2267 } … … 2206 2269 if (0 == status) { 2207 2270 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); 2213 2276 if (0 == status) { 2214 2277 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); 2216 2279 return MB_FAILURE; 2217 2280 } … … 2222 2285 if (0 == status) { 2223 2286 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); 2229 2292 if (0 == status) { 2230 2293 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); 2232 2295 return MB_FAILURE; 2233 2296 } … … 2253 2316 2254 2317 void 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 , 2257 2320 std::vector<double*> arrays) 2258 2321 { 2259 2322 delete ptr1; 2260 delete ptr2; 2323 if(ptr2) 2324 delete ptr2; 2261 2325 delete [] arrays[0]; 2262 2326 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 } 2267 2337 if(numberDimensions_loading == 3 ) 2268 2338 { 2269 2339 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]; 2272 2344 } 2273 2345 }