1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <stdio.h>
#include <stdlib.h>
#include <IEEEIO.hh>
#include "AmrFileReader.hh"
int main(int argc,char *argv[]){
IEEEIO *file;
AmrFileReader *amrfile;
if (argc < 2) {
fprintf(stderr,"Usage: SampleAmrReader AMRfile\n");
exit(0);
}
printf("Open the file named %s\n\n",argv[1]);
file = new IEEEIO(argv[1],IObase::Read);
if (!file->isValid()) {
fprintf(stderr,"Couldn't open %s for reading\n",argv[1]);
exit(0);
}
printf("Now we put the file into an AMR parsing framework\n\n");
amrfile = new AmrFileReader(*file);
printf("Number of Levels = %u\n\n",amrfile->nLevels());
int min,max;
amrfile->getTimeRange(min,max);
printf("The time range of AMR data in this file\n (in terms of finest-level-of-resolution timesteps) = %u:%u\n\n",min,max);
printf("Lets tell the driver to load up all of the grids for the first timestep\n\n");
amrfile->showAllLevels();
amrfile->setTime(min);
printf("========================> ActiveGrids are (all levels)...\n");
amrfile->printActiveGrids();
// printf("========================> Grid Info is...\n");
// amrfile->printGridInfo();
printf("\nLet's hide level %d\n",amrfile->nLevels() - 2);
amrfile->hideLevel(amrfile->nLevels() - 2);
printf("Let's hide level %d\n",amrfile->nLevels() - 1);
amrfile->hideLevel(amrfile->nLevels() - 1);
printf("Tell the driver to load up the active grids for the first timestep\n");
amrfile->setTime(min);
printf("========================> ActiveGrids are (all but finest level)...\n");
amrfile->printActiveGrids();
printf("\nActually load the grid data into %u standard arrays\n",amrfile->getNumGrids());
AmrGrid *grids = new AmrGrid[amrfile->getNumGrids()];
amrfile->getGrids(grids); // that loaded all of the data
printf("We read %u grids\n\n",amrfile->getNumGrids());
printf("Let's grab the grids into a flexarray (a dynamically resizable array)\n");
FlexArray<AmrGrid> gridarray;
amrfile->getGrids(gridarray);
printf("We read %u grids\n",gridarray.getSize());
// You can access individual grids with gridarray[]
// Take a look at AmrGrid.hh to see whats in the datastruct
// or take a look at docs
// http://infinite-entropy.lbl.gov/FlexIO/AmrGrid.html
// To get rid of the data associated with these grids we can do a
// amrfile->setDataLoadingOff(); // this deletes the data arrays
// amrfile->setDataLoadingOn(); // reloads the data arrays from disk
return 1;
}
|