Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 00007 #include <stdio.h> 00008 #include <stdlib.h> 00009 #include <string.h> 00010 #include <hdf.h> 00011 00012 #include "amrsds.h" 00013 #include "sds.h" 00014 00015 /* changed headers to ANSI 96/11/18 RLM */ 00016 00017 /*@@ 00018 @file amrsds.c 00019 @date Wed Feb 26 20:05:00 1996 00020 @author John Shalf 00021 @desc 00022 The AMR routines are used to store Hierarchial Adaptive Mesh 00023 Refinement data in an HDF-compatible format. It is implemented 00024 using the <a href="http://bach.ncsa.uiuc.edu/IO/SDSlibrary.html"> 00025 SDS wrapper routines</a>. (seealso DAGH)<p> 00026 00027 Heirarchial Adaptive Mesh Refinement can be very difficult to 00028 represent in a flattened format. There are many different ways 00029 to represent the grid information. The choices made here are 00030 intended to be applicable to AMR systems which use rectilinear 00031 grids with an unbounded number levels that can vary during the 00032 computation. It also allows for the resolution of the grids 00033 to be independent in each dimension (including time) and 00034 to change upon each regridding. The grids are uniquely 00035 identified by their level, gridID, and timestep. However, the 00036 processor ID is not stored on multiprocessor systems. Processor 00037 information can be stored in a separate NetCDF attribute using 00038 SDSwriteAttrib(). 00039 <hr> 00040 00041 <h4>Taxonomy</h4> 00042 The AMR heirarchy resembles a tree. The root of the tree is level 0 00043 and the lower levels are numbered consecutively. The nodes of this 00044 tree are "grids". A "grid" is a rectilinear array of data at a 00045 particular AMR level. At a particular level there can be multiple 00046 "steps" of the level as it evolves. The grid can be of a different 00047 size and location on every timestep.<p> 00048 00049 <h4>Explanation of AMR-SDS Parameters</h4> 00050 <i>(the same names are used for all function calls)</i> 00051 <dl> 00052 <dt><b>level:</b> <dd>The level in the amr heirarchy, starting from 0. 00053 <dt><b>gridID:</b> <dd>At a particular level, there can be multiple grids. 00054 This is an integer (starting from 0) that differentiates 00055 grids at the same level. There is no other implied meaning 00056 for this number. 00057 <dt><b>step:</b> <dd>This is the current integer step for a particular 00058 level. It need not be associated with time so that the 00059 AMR file can store more than one component as successive 00060 steps in the same graph if they share the same tree structure. 00061 00062 <dt><b>rank:</b> <dd>As with regular HDF, this is the number of dimensions of 00063 the data 00064 00065 <dt><b>dims:</b> <dd>An n-element array of the dimensions of the data where 00066 n=the rank of the data. 00067 00068 <dt><b>origin:</b> <dd>An n-element array locating the origin of the current 00069 grid with respect to the origin of the toplevel grid 00070 (n = rank of the data at top level). The resolution 00071 of the coordinates is with respect to the current level 00072 is with respect to the toplevel. ie. A 1D grid that is 00073 offset by 2 top-level grid points with respect to 00074 the toplevel origin, and has a refinement factor of 5 00075 has its origin[0]=10. 00076 00077 <dt><b>resolution:</b> <dd>This is the integer refinement factor by which the 00078 current level grid has been refined with respect to the 00079 toplevel grid (ie. a refinement factor of 3 means 00080 3 grid points at this level fit in the space of one grid point 00081 at the toplevel. It is an (n+1) element array where n=rank 00082 of the toplevel grid. So each dimension can be of a different 00083 refinement factor. The last element is the refinement 00084 factor for time with respect to the toplevel. 00085 00086 <dt><b>realTime:</b> <dd>Since this may not be derivable from any combination of 00087 the time resolution and level/gridID/step, then we'd best 00088 store this explicitly. Since it is a floating point number, 00089 it can't be relied upon for searching or seeking through 00090 the heirarchy, but it does provide useful information 00091 once the grid is found. 00092 </dl> 00093 @enddesc 00094 @includes amrsds.h sds.h 00095 @seeheader amrsds.h sds.h 00096 @version 0.9a 00097 @@*/ 00098 00099 /*------------------------------------------------------*/ 00100 #define DEFAULT_ANNOTATION_SZ 512 00101 int AmrDebug=1; /* set this flag to TRUE to turn on verbose error messages */ 00102 static AMRinterpolator AMRdefaultInterp=PatchReplace; 00103 /* parses an $amrsds annotation 00104 The annotation has the form 00105 $amrsds=level:gridID:step:rank:origin[0],origin[1],..origin[N]: 00106 resolution[0],resultion[1],..resolution[N],resolution[N+1]: 00107 realtime 00108 resolution[N+1] is the time-resolution for the grid. 00109 all items are integers except for "realtime" which is a float. 00110 */ 00111 /*@@ 00112 @routine AMRgetLocation 00113 @date Wed Feb 26 20:05:00 1996 00114 @author John Shalf 00115 @desc Reads the minimum subset of the AMR attributes necessary to 00116 uniquely identify the current grid; the level, gridID, and timestep. 00117 @enddesc 00118 @calls SDSwriteAttrib 00119 @calledby AMRwriteData 00120 @seeroutine AMRreadData AMRreadAttribs 00121 00122 @par filename 00123 @pdesc Name of the HDF file to open or create 00124 @ptype char* 00125 @endpar 00126 00127 @par level 00128 @pdesc The level in the amr heirarchy, starting from 0. 00129 @ptype int32 00130 @endpar 00131 00132 @par gridID 00133 @pdesc At a particular level, there can be multiple grids. 00134 This is an integer (starting from 0) that differentiates 00135 grids at the same level at a particular timestep. There is no 00136 other implied meaning for this number (ie. it has no meaning 00137 between timesteps). 00138 @ptype int32 00139 @endpar 00140 00141 @par step 00142 @pdesc This is the current integer step for a particular 00143 level. It need not be associated with time so that the 00144 AMR file can store more than one component as successive 00145 steps in the same graph if they share the same tree structure. 00146 @ptype int32 00147 @endpar 00148 00149 @par 00150 @retval 00151 @ptype int 00152 @pvalues 0 on success, -1 on failure 00153 @endpar 00154 00155 @history 00156 @hdate Wed Feb 28 20:38:57 1996 @hauthor John Shalf 00157 @hdesc Initial Version 00158 @endhistory 00159 00160 @@*/ 00161 int AMRgetLocation(char * filename,int32 *level,int32 *gridID,int32 *step) 00162 { 00163 SDSreadAttrib(filename,"AMRlevel",1,(VOIDP)level); 00164 SDSreadAttrib(filename,"AMRgridID",1,(VOIDP)gridID); 00165 SDSreadAttrib(filename,"AMRtimestep",1,(VOIDP)step); 00166 return 0; 00167 } 00168 00169 /*@@ 00170 @routine AMRwriteAttribs 00171 @date Wed Feb 26 20:05:00 1996 00172 @author John Shalf 00173 @desc Used internally by AMRwriteData to write the attibutes 00174 of the AMR grid into the HDF file. This uses SDSwriteAttrib 00175 to attach NetCDF attributes to the HDF dataset. 00176 @enddesc 00177 @calls SDSwriteAttrib 00178 @calledby AMRwriteData 00179 @seeroutine AMRreadData AMRreadAttribs 00180 00181 @par filename 00182 @pdesc Name of the HDF file to open or create 00183 @ptype char* 00184 @endpar 00185 00186 @par level 00187 @pdesc The level in the amr heirarchy, starting from 0. 00188 @ptype int32 00189 @endpar 00190 00191 @par gridID 00192 @pdesc At a particular level, there can be multiple grids. 00193 This is an integer (starting from 0) that differentiates 00194 grids at the same level at a particular timestep. There is no 00195 other implied meaning for this number (ie. it has no meaning 00196 between timesteps). 00197 @ptype int32 00198 @endpar 00199 00200 @par step 00201 @pdesc This is the current integer step for a particular 00202 level. It need not be associated with time so that the 00203 AMR file can store more than one component as successive 00204 steps in the same graph if they share the same tree structure. 00205 @ptype int32 00206 @endpar 00207 00208 @par realtime 00209 @pdesc Since this may not be derivable from any combination of 00210 the time resolution and level/gridID/step, then we'd best 00211 store this explicitly. Since it is a floating point number, 00212 it can't be relied upon for searching or seeking through 00213 the heirarchy, but it does provide useful information 00214 once the grid is found. You can use AMRseekTime to select 00215 grids based on a particular floating point time value. 00216 @ptype float64 00217 @endpar 00218 00219 @par rank 00220 @pdesc The number of dimensions of the data (this particular grid). 00221 @ptype int32 00222 @endpar 00223 00224 @par dims 00225 @pdesc The dimensions of the data (for this particular grid). 00226 @ptype int32* 00227 @endpar 00228 00229 @par origin 00230 @pdesc An array locating the origin of the current 00231 grid with respect to the origin of the toplevel grid 00232 (where the number of elements in the array = rank of the data at top level). 00233 The resolution of the coordinates is with respect to the current level 00234 is with respect to the toplevel. ie. A 1D grid that is 00235 offset by 2 top-level grid points with respect to 00236 the toplevel origin, and has a refinement factor of 5 00237 has its origin[0]=10. 00238 @ptype int32* 00239 @endpar 00240 00241 @par resolution 00242 @pdesc This is the integer refinement factor by which the 00243 current level grid has been refined with respect to the 00244 toplevel grid (ie. a refinement factor of 3 means 00245 3 grid points at this level fit in the space of one grid point 00246 at the toplevel. It is an (rank+1) element array. 00247 The first 'rank' elements are the refinement factors for each 00248 of the spatial dimensions. The last element is the refinement 00249 factor for time with respect to the toplevel. 00250 @ptype int32* 00251 @endpar 00252 00253 @par 00254 @retval 00255 @ptype int 00256 @pvalues 0 on success, -1 on failure 00257 @endpar 00258 00259 @history 00260 @hdate Wed Feb 28 20:38:57 1996 @hauthor John Shalf 00261 @hdesc Initial Version 00262 @endhistory 00263 00264 00265 @@*/ 00266 /* Internal Only */ 00267 int AMRwriteAttribs(char *filename,int32 proc, 00268 int32 level,int32 gridID,int32 step,float64 realTime, 00269 int32 rank,int32 *origin,int32 *resolution) 00270 { 00271 SDSwriteAttrib(filename,"AMRProc",DFNT_INT32,1,&proc); 00272 SDSwriteAttrib(filename,"AMRlevel",DFNT_INT32,1,&level); 00273 SDSwriteAttrib(filename,"AMRgridID",DFNT_INT32,1,&gridID); 00274 SDSwriteAttrib(filename,"AMRtimestep",DFNT_INT32,1,&step); 00275 SDSwriteAttrib(filename,"AMRrank",DFNT_INT32,1,&rank); 00276 SDSwriteAttrib(filename,"AMRorigin",DFNT_INT32,rank,origin); 00277 SDSwriteAttrib(filename,"AMRresolution",DFNT_INT32,rank+1,resolution); 00278 SDSwriteAttrib(filename,"AMRrealtime",DFNT_FLOAT64,1,&realTime); 00279 return 0; 00280 } 00281 00282 /*@@ 00283 @routine AMRwriteData 00284 @date Wed Feb 26 20:05:00 1996 00285 @author John Shalf 00286 @desc Works just like DFSDadddata(), except it includes 00287 all of the AMR attributes as well. 00288 @enddesc 00289 @calls AMRwriteAttribs SDSwriteData 00290 @seeroutine AMRreadData AMRreadAttribs 00291 00292 @par filename 00293 @pdesc Name of the HDF file to open or create 00294 @ptype char* 00295 @endpar 00296 00297 @par dataname 00298 @pdesc Name of the dataset. Can use this to identify the 00299 name of the component this grid refers to. 00300 @ptype char* 00301 @endpar 00302 00303 @par level 00304 @pdesc The level in the amr heirarchy, starting from 0. 00305 @ptype int32 00306 @endpar 00307 00308 @par gridID 00309 @pdesc At a particular level, there can be multiple grids. 00310 This is an integer (starting from 0) that differentiates 00311 grids at the same level at a particular timestep. There is no 00312 other implied meaning for this number (ie. it has no meaning 00313 between timesteps). 00314 @ptype int32 00315 @endpar 00316 00317 @par step 00318 @pdesc This is the current integer step for a particular 00319 level. It need not be associated with time so that the 00320 AMR file can store more than one component as successive 00321 steps in the same graph if they share the same tree structure. 00322 @ptype int32 00323 @endpar 00324 00325 @par realtime 00326 @pdesc Since this may not be derivable from any combination of 00327 the time resolution and level/gridID/step, then we'd best 00328 store this explicitly. Since it is a floating point number, 00329 it can't be relied upon for searching or seeking through 00330 the heirarchy, but it does provide useful information 00331 once the grid is found. You can use AMRseekTime to select 00332 grids based on a particular floating point time value. 00333 @ptype float64 00334 @endpar 00335 00336 @par rank 00337 @pdesc The number of dimensions of the data (this particular grid). 00338 @ptype int32 00339 @endpar 00340 00341 @par dims 00342 @pdesc The dimensions of the data (for this particular grid). 00343 @ptype int32* 00344 @endpar 00345 00346 @par origin 00347 @pdesc An array locating the origin of the current 00348 grid with respect to the origin of the toplevel grid 00349 (where the number of elements in the array = rank of the data at top level). 00350 The resolution of the coordinates is with respect to the current level 00351 is with respect to the toplevel. ie. A 1D grid that is 00352 offset by 2 top-level grid points with respect to 00353 the toplevel origin, and has a refinement factor of 5 00354 has its origin[0]=10. 00355 @ptype int32* 00356 @endpar 00357 00358 @par resolution 00359 @pdesc This is the integer refinement factor by which the 00360 current level grid has been refined with respect to the 00361 toplevel grid (ie. a refinement factor of 3 means 00362 3 grid points at this level fit in the space of one grid point 00363 at the toplevel. It is an (rank+1) element array. 00364 The first 'rank' elements are the refinement factors for each 00365 of the spatial dimensions. The last element is the refinement 00366 factor for time with respect to the toplevel. 00367 @ptype int32* 00368 @endpar 00369 00370 @par data 00371 @pdesc The data for the grid to be stored in the HDF file. 00372 @ptype VOIDP 00373 @endpar 00374 00375 @par 00376 @retval 00377 @ptype int 00378 @pvalues 0 on success, -1 on failure 00379 @endpar 00380 00381 @history 00382 @hdate Wed Feb 28 20:38:57 1996 @hauthor John Shalf 00383 @hdesc Initial Version 00384 @endhistory 00385 @@*/ 00386 int AMRwriteData (char *filename,char *dataname,int32 proc,int32 level,int32 gridID, 00387 int32 step,float64 realTime, 00388 int32 rank,int32 *dims,int32 *origin,int32 *resolution,void *data) 00389 { 00390 if(SDSwriteData(filename,dataname,rank,dims,data)<0) 00391 { 00392 if(AmrDebug) fprintf(stderr,"AMRaddData: DFSDaddData() failed for %s\n",filename); 00393 return -1; 00394 } 00395 AMRwriteAttribs(filename,proc,level,gridID,step,realTime,rank,origin,resolution); 00396 return 0; 00397 } 00398 00399 /*@@ 00400 @routine AMRreadAttribs 00401 @date Wed Feb 26 20:05:00 1996 00402 @author John Shalf 00403 @desc Works just like DFSDadddata(), except it includes 00404 all of the AMR attributes as well. 00405 @enddesc 00406 @calls SDSgetDims SDSreadAttrib 00407 @seeroutine AMRwriteData 00408 00409 @par filename 00410 @pdesc Name of the HDF file to open or create 00411 @ptype char* 00412 @endpar 00413 00414 @par dataname 00415 @pdesc Array in which to store the name of the dataset 00416 @ptype char* 00417 @pvalues Preallocated character array or NULL 00418 @endpar 00419 00420 @par level 00421 @pdesc The level in the amr heirarchy, starting from 0. 00422 @ptype int32* 00423 @endpar 00424 00425 @par gridID 00426 @pdesc At a particular level, there can be multiple grids. 00427 This is an integer (starting from 0) that differentiates 00428 grids at the same level at a particular timestep. There is no 00429 other implied meaning for this number (ie. it has no meaning 00430 between timesteps). 00431 @ptype int32* 00432 @endpar 00433 00434 @par step 00435 @pdesc This is the current integer step for a particular 00436 level. It need not be associated with time so that the 00437 AMR file can store more than one component as successive 00438 steps in the same graph if they share the same tree structure. 00439 @ptype int32* 00440 @endpar 00441 00442 @par realtime 00443 @pdesc Since this may not be derivable from any combination of 00444 the time resolution and level/gridID/step, then we'd best 00445 store this explicitly. Since it is a floating point number, 00446 it can't be relied upon for searching or seeking through 00447 the heirarchy, but it does provide useful information 00448 once the grid is found. You can use AMRseekTime to select 00449 grids based on a particular floating point time value. 00450 @ptype float64* 00451 @endpar 00452 00453 @par rank 00454 @pdesc The number of dimensions of the data (this particular grid). 00455 @ptype int32* 00456 @endpar 00457 00458 @par dims 00459 @pdesc The dimensions of the data (for this particular grid). 00460 @ptype int32* 00461 @endpar 00462 00463 @par origin 00464 @pdesc An array locating the origin of the current 00465 grid with respect to the origin of the toplevel grid 00466 (where the number of elements in the array = rank of the data at top level). 00467 The resolution of the coordinates is with respect to the current level 00468 is with respect to the toplevel. ie. A 1D grid that is 00469 offset by 2 top-level grid points with respect to 00470 the toplevel origin, and has a refinement factor of 5 00471 has its origin[0]=10. 00472 @ptype int32* 00473 @endpar 00474 00475 @par resolution 00476 @pdesc This is the integer refinement factor by which the 00477 current level grid has been refined with respect to the 00478 toplevel grid (ie. a refinement factor of 3 means 00479 3 grid points at this level fit in the space of one grid point 00480 at the toplevel. It is an (rank+1) element array. 00481 The first 'rank' elements are the refinement factors for each 00482 of the spatial dimensions. The last element is the refinement 00483 factor for time with respect to the toplevel. 00484 @ptype int32* 00485 @endpar 00486 00487 @par 00488 @retval 00489 @ptype int 00490 @pvalues 0 on success, -1 on failure 00491 @endpar 00492 00493 @history 00494 @hdate Wed Feb 28 20:38:57 1996 @hauthor John Shalf 00495 @hdesc Initial Version 00496 @endhistory 00497 00498 @@*/ 00499 int AMRreadAttribs(char *filename,char *dataname,int32 *proc, 00500 int32 *level,int32 *gridID,int32 *step,float64 *realTime, 00501 int32 *rank,int32 *dims,int32 *origin,int32 *resolution) 00502 { 00503 int readErr; 00504 readErr=(int) SDSgetDims(filename,dataname,rank,dims); 00505 if (readErr >=0) { 00506 SDSreadAttrib(filename,"AMRProc",1,proc); 00507 SDSreadAttrib(filename,"AMRlevel",1,level); 00508 SDSreadAttrib(filename,"AMRgridID",1,gridID); 00509 SDSreadAttrib(filename,"AMRtimestep",1,step); 00510 SDSreadAttrib(filename,"AMRrank",1,rank); 00511 SDSreadAttrib(filename,"AMRorigin",*rank,origin); 00512 SDSreadAttrib(filename,"AMRresolution",*rank+1,resolution); 00513 SDSreadAttrib(filename,"AMRrealtime",1,realTime); 00514 } 00515 return readErr; 00516 } 00517 00518 int AMRgetNumAttribs(char *filename) 00519 00520 { 00521 return SDSgetNumAttribs(filename); 00522 } 00523 00524 /*@@ 00525 @routine AMRreadData 00526 @date Wed Feb 28 15:37:43 1996 00527 @desc 00528 Reads data from an HDF file. 00529 This must be preceded by an AMRreadAttribs() which 00530 returns the dimensions of the data so that the user 00531 can allocate the space to read in the data as well as 00532 all other relevant AMR parameters. 00533 @enddesc 00534 @seeroutine SDSgetDims AMRreadAttribs 00535 @calls SDSreadData 00536 00537 @par filename 00538 @pdesc Name of the HDF file 00539 @ptype char* 00540 @endpar 00541 00542 @par rank 00543 @pdesc Number of dimension in the dataset 00544 @ptype int32 00545 @endpar 00546 00547 @par dims 00548 @pdesc Dimensions of the dataset 00549 @ptype int32* 00550 @endpar 00551 00552 @par data 00553 @pdesc Pointer to the actual dataset (preallocated by the user) 00554 @ptype VOIDP 00555 @endpar 00556 00557 @par 00558 @retval 00559 @ptype int 00560 @pvalues 0 on success, -1 on failure 00561 @endpar 00562 00563 @history 00564 @hdate Wed Feb 28 20:38:57 1996 @hauthor John Shalf 00565 @hdesc Initial Version 00566 @endhistory 00567 @@*/ 00568 int AMRreadData (char *filename,int32 rank,int32 *dims,void *data) 00569 { 00570 return SDSreadData(filename,rank,dims,data); 00571 } 00572 00573 00574 00575 /*@@ ------------------------------------------------------ 00576 @routine AMRseekTime 00577 @date Wed Feb 26 20:05:00 1996 00578 @author John Shalf 00579 @desc Seeks to the nearest grid with matching 00580 level, gridID, and timestep. The value 00581 AMR_ANY can be used as a wildcard that matches 00582 any value. 00583 @enddesc 00584 @calls SDSreadAttrib SDSseek 00585 @seeroutine AMRseek 00586 00587 @par filename 00588 @pdesc Name of the HDF file to open or create 00589 @ptype char* 00590 @endpar 00591 00592 @par realtime 00593 @pdesc The floating point global "real time" value for the 00594 AMR evolution. 00595 @ptype float64 00596 @endpar 00597 00598 @par matchtype 00599 @pdesc Selects the criterion used for matching a particular 00600 timevalue. For example, <b>AMRseekTime("file.hdf",6.125,"<=")</b> 00601 matches the next grid (stored linearly in the file) that has 00602 a "realtime" attribute which is less than or equal to 6.125. 00603 Likewise, <b>AMRseekTime("file.hdf",6.125,">=")</b> 00604 matches the next grid greater than or equal to 6.125. 00605 The search will wrap around to the beginning 00606 of the HDF file and will continue as far as the grid that 00607 the search started on. However, it will not select the 00608 current grid as a successful match under any circumstance. 00609 @ptype int32 00610 @pvalues integer or AMR_ANY for wildcard 00611 @endpar 00612 00613 @par 00614 @retval 00615 @ptype int 00616 @pvalues 0 on success, -1 on failure 00617 @endpar 00618 00619 @history 00620 @hdate Wed Feb 28 20:38:57 1996 @hauthor John Shalf 00621 @hdesc Initial Version 00622 @endhistory 00623 @@*/ 00624 int AMRseekTime(char *filename,float64 realtime,char *matchtype) 00625 { 00626 /* seek based on the RealTime. 00627 Return -1 if you end up seeking back to the start (even on success) */ 00628 float64 rt; 00629 int32 i; 00630 char annotation[DEFAULT_ANNOTATION_SZ]; 00631 int32 nsds=SDSgetNumDatasets(filename)+1; /* limit the search to one cycle */ 00632 int32 start=SDSgetIndex(filename); 00633 00634 for(i=start;i<=nsds;i++){ 00635 SDSseek(filename,i); 00636 if(SDSisCoord(filename)) 00637 continue; 00638 if(SDSreadAttrib(filename,"AMRrealtime",1,&rt)<0) 00639 { 00640 if(AmrDebug) fprintf(stderr, 00641 "AMRseek: () AMRparseLocation failed for annotation %s\n",annotation); 00642 return -1; 00643 } 00644 if(!matchtype){ /* use default */ 00645 if(realtime>=rt) /* default matchtype */ 00646 return 0; /* a match (sort-of) */ 00647 } 00648 if(matchtype[0]=='='){ /* exact match */ 00649 if(rt==realtime) 00650 return 0; 00651 } 00652 else if(matchtype[0]=='<'){ 00653 if(matchtype[1]=='='){ 00654 if(rt<=realtime) 00655 return 0; 00656 } 00657 else { /* just < */ 00658 if(rt<realtime) 00659 return 0; 00660 } 00661 } 00662 else if(matchtype[0]=='>'){ 00663 if(matchtype[1]=='='){ 00664 if(rt>=realtime) 00665 return 0; 00666 } 00667 else { /* just > */ 00668 if(rt>realtime) 00669 return 0; 00670 } 00671 } 00672 else { 00673 fprintf(stderr,"AMRseekRealTime: Don't understand matchtype of %s\n", 00674 matchtype); 00675 break; 00676 } 00677 } 00678 for(i=0;i<=(start-1);i++) /* if start is only place with this time, then fail */ 00679 { 00680 SDSseek(filename,i); 00681 if(SDSisCoord(filename)) 00682 continue; 00683 if(SDSreadAttrib(filename,"AMRrealtime",1,&rt)<0) 00684 { 00685 if(AmrDebug) fprintf(stderr, 00686 "AMRseek: () AMRparseLocation failed for annotation %s\n",annotation); 00687 return -1; 00688 }if(SDSreadAttrib(filename,"AMRrealtime",1,&rt)<0) 00689 { 00690 if(AmrDebug) fprintf(stderr, 00691 "AMRseek: () AMRparseLocation failed for annotation %s\n",annotation); 00692 return -1; 00693 } 00694 if(!matchtype){ /* use default */ 00695 if(realtime>=rt) /* default matchtype */ 00696 return 0; /* a match (sort-of) */ 00697 } 00698 if(matchtype[0]=='='){ /* exact match */ 00699 if(rt==realtime) 00700 return 0; 00701 } 00702 else if(matchtype[0]=='<'){ 00703 if(matchtype[1]=='='){ 00704 if(rt<=realtime) 00705 return 0; 00706 } 00707 else { /* just < */ 00708 if(rt<realtime) 00709 return 0; 00710 } 00711 } 00712 else if(matchtype[0]=='>'){ 00713 if(matchtype[1]=='='){ 00714 if(rt>=realtime) 00715 return 0; 00716 } 00717 else { /* just > */ 00718 if(rt>realtime) 00719 return 0; 00720 } 00721 } 00722 else { 00723 fprintf(stderr,"AMRseekRealTime: Don't understand matchtype of %s\n", 00724 matchtype); 00725 break; 00726 } 00727 } 00728 SDSseek(filename,start); /* seek back to the original */ 00729 return -1; /* no match found */ 00730 } 00731 00732 00733 /*@@ 00734 @routine AMRseek 00735 @date Wed Feb 26 20:05:00 1996 00736 @author John Shalf 00737 @desc Seeks to the nearest grid with matching 00738 level, gridID, and timestep. The value 00739 AMR_ANY can be used as a wildcard that matches 00740 any value. The search will wrap around to the beginning 00741 of the HDF file and will continue as far as the grid that 00742 the search started on. However, it will not select the 00743 current grid as a successful match under any circumstance. 00744 @enddesc 00745 @calls AMRgetLocation SDSseek 00746 @seeroutine AMRseekTime 00747 00748 @par filename 00749 @pdesc Name of the HDF file to open or create 00750 @ptype char* 00751 @endpar 00752 00753 @par level 00754 @pdesc The level in the amr heirarchy, starting from 0. 00755 @ptype int32 00756 @pvalues integer or AMR_ANY for wildcard 00757 @endpar 00758 00759 @par gridID 00760 @pdesc At a particular level, there can be multiple grids. 00761 This is an integer (starting from 0) that differentiates 00762 grids at the same level at a particular timestep. There is no 00763 other implied meaning for this number (ie. it has no meaning 00764 between timesteps). 00765 @ptype int32 00766 @pvalues integer or AMR_ANY for wildcard 00767 @endpar 00768 00769 @par step 00770 @pdesc This is the current integer step for a particular 00771 level. It need not be associated with time so that the 00772 AMR file can store more than one component as successive 00773 steps in the same graph if they share the same tree structure. 00774 @ptype int32 00775 @pvalues integer or AMR_ANY for wildcard 00776 @endpar 00777 00778 @par 00779 @retval 00780 @ptype int 00781 @pvalues 0 on success, -1 on failure 00782 @endpar 00783 00784 @history 00785 @hdate Wed Feb 28 20:38:57 1996 @hauthor John Shalf 00786 @hdesc Initial Version 00787 @endhistory 00788 @@*/ 00789 int AMRseek(char *filename,int32 level,int32 gridID,int32 step) 00790 { 00791 00792 int i; 00793 int32 tlevel,tgridID,tstep; 00794 char annotation[DEFAULT_ANNOTATION_SZ]; 00795 int nsds=SDSgetNumDatasets(filename)+1; /* limit the search to one cycle */ 00796 int start=SDSgetIndex(filename); 00797 00798 for(i=start;i<=nsds;i++){ 00799 SDSseek(filename,i); 00800 if(SDSisCoord(filename)) 00801 continue; 00802 SDSgetDataName(filename,annotation); 00803 if(AMRgetLocation(annotation,&tlevel,&tgridID,&tstep)) 00804 { 00805 if(AmrDebug) fprintf(stderr, 00806 "AMRseek: () AMRparseLocation failed for annotation %s\n",annotation); 00807 return -1; 00808 } 00809 if((level==AMR_ANYVAL || tlevel==level) && 00810 (gridID==AMR_ANYVAL || tgridID==gridID) && 00811 (step==AMR_ANYVAL || tstep==step)) 00812 return 0; /* a match */ 00813 } 00814 for(i=0;i<=(start-1);i++) /* if start is only place with this time, then fail */ 00815 { 00816 SDSseek(filename,i); 00817 if(SDSisCoord(filename)) 00818 continue; 00819 SDSgetDataName(filename,annotation); 00820 if(AMRgetLocation(annotation,&tlevel,&tgridID,&tstep)) 00821 { 00822 if(AmrDebug) fprintf(stderr, 00823 "AMRseek: () AMRparseLocation failed for annotation %s\n",annotation); 00824 return -1; 00825 } 00826 if((level==AMR_ANYVAL || tlevel==level) && 00827 (gridID==AMR_ANYVAL || tgridID==gridID) && 00828 (step==AMR_ANYVAL || tstep==step)) 00829 return 0; /* a match */ 00830 } 00831 SDSseek(filename,start); /* seek back to the original */ 00832 return -1; /* no match found */ 00833 } 00834 00835 int AMRgetRegion(char *filename,int32 level,int32 step,int32 rank, 00836 int32 *lb,int32 *ub,int32 *dims,void *data) 00837 { 00838 return 0; 00839 } 00840 00841 int RegionOverlap(int *rank, 00842 int32 *sourceDims,int32 *sourceOrigin,int32 *sourceResolution, 00843 int32 *destDims,int32 *destOrigin,int32 *destResolution) 00844 { 00845 /* must compute normalized dimensions (normalize to a single resolution) 00846 And then check for overlap on ALL dimensions */ 00847 int i; 00848 for(i=0;i<*rank;i++) 00849 { 00850 float normSrc,normDst,nStSrc,nStDst,nEndSrc,nEndDst; 00851 float maxres=(float)((sourceResolution[i]>destResolution[i])? 00852 (sourceResolution[i]):(destResolution[i])); 00853 normSrc = (float)(sourceResolution[i]) / maxres; 00854 normDst = (float)(destResolution[i]) / maxres; 00855 nStSrc = normSrc * (float)(sourceOrigin[i]); 00856 nStDst = normDst * (float)(destOrigin[i]); 00857 nEndSrc = nStSrc + (float)(sourceDims[i]) * normSrc; 00858 nEndDst = nStDst + (float)(destDims[i]) * normDst; 00859 if(nStSrc>nEndDst || nStDst>nEndSrc) /* if any dim doesn't overlap */ 00860 return 0; /* then nothing overlaps */ 00861 } 00862 return 1; 00863 } 00864 00865 void AMRsetInterpolator (AMRinterpolator interp) 00866 { 00867 AMRdefaultInterp=interp; 00868 } 00869 00870 void PatchReplace(int32 *rank, 00871 int32 *sourceDims,int32 *sourceOrigin,int32 *sourceResolution, 00872 void *sourcedata, 00873 int32 *destdims,int32 *destOrigin,int32 *destResolution, 00874 void *destdata) 00875 { 00876 float *sNorm=(float *)malloc(sizeof(float)**rank); 00877 int i; 00878 if(!sNorm) {perror("PatchReplace: malloc failed"); return;} 00879 /* compute normalization factor for given resolution */ 00880 for(i=0;i<*rank;i++) 00881 sNorm[i]=(float)(destResolution[i])/(float)(sourceResolution[i]); 00882 for(i=0;i<*rank;i++) 00883 {} 00884 free(sNorm); 00885 }
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04