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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 | int
saf_read_state(SAF_ParMode pmode, /* The parallel mode */
SAF_StateGrp *state_grp, /* The state group from which this state will be read. */
int state_index, /* An index that specifies which state within the state group will be read.
* This index is 0-based. */
SAF_Set *mesh, /* [OUT] Returned ID of the mesh associated with this state. */
SAF_Field *deflt_coords, /* [OUT] Returned ID of the default coordinate field of MESH; we may want to
* delete this argument since the client can call saf_find_default_coords()
* for MESH. */
void *coord_data, /* [OUT] Returned coordinate of STATE_INDEX within the state group. For
* instance, this is typically the time value of the state. */
SAF_Field **fields /* The IDs of the fields (the dependent variables) to be read from this state.
* The caller may supply a pointer to a value of NULL if this function is to
* allocate a buffer. If the caller supplies a pointer to a non-nil pointer,
* then it is the responsibility of the caller to ensure that the buffer is of
* sufficient size to contain the coordinates. This size (NUM_FIELDS) is the
* number of field templates (NUM_FTMPLS) obtained by a call to
* saf_describe_state_tmpl().*/
)
{
SAF_ENTER(saf_read_state, SAF_PRECONDITION_ERROR);
SAF_Field *coord;
SAF_Set suite;
int index[1];
SAF_Db db=SS_FILE_NULL;
SAF_Field *coords,*tmp_deflt_coords;
SAF_Field *tmp_fields;
SAF_Field *mesh_coord, *param_coord;
SAF_Field *stategrp_state;
SAF_FieldTmpl stategrp_tmpl;
size_t group_size;
hid_t group_type;
SAF_Field *stategrp_contents;
/* find the suite associated with this stategroup */
saf_describe_field(pmode, state_grp, &stategrp_tmpl, NULL, &suite,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
saf_get_count_and_type_for_field(pmode, state_grp, NULL, &group_size, &group_type );
if( group_size != 2 ) {
printf("size of stategrp field != 2\n");
}
/* get and set the database and db handles */
ss_pers_file((ss_pers_t*)&suite, &db);
{
/* the stategrp blob should contain two field handles:
the first is the indirect coord field containing the mesh_coords, and param_coord
the second is the state field containing the fields stored at this suite_index
*/
stategrp_contents = NULL;
index[0] = 0;
saf_read_field (pmode, state_grp, NULL, 1, SAF_TUPLES, index, (void **)(&stategrp_contents));
coord = &(stategrp_contents[0]);
stategrp_state = &(stategrp_contents[1]);
/* now read the coord field and get the mesh coord and the param coord (dump times) */
coords = NULL;
saf_read_field (pmode, coord, NULL, 1, SAF_TUPLES, index, (void **)(&coords));
mesh_coord = &(coords[1]);
param_coord = &(coords[0]);
if( deflt_coords != NULL ) {
tmp_deflt_coords = NULL;
saf_read_field( pmode, mesh_coord, NULL, 1, SAF_TUPLES, &state_index, (void **)&tmp_deflt_coords);
*deflt_coords = *tmp_deflt_coords;
}
/* get the mesh set that the mesh_default_coord lives on */
if( mesh != NULL ) {
saf_describe_field( pmode, deflt_coords, NULL, NULL, mesh,
NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL);
}
if( coord_data != NULL ) {
saf_read_field(pmode, param_coord, NULL, 1, SAF_TUPLES, &state_index, (void **)&coord_data);
}
if( fields != NULL ) {
if( *fields == NULL ) {
tmp_fields = NULL;
saf_read_field( pmode, stategrp_state, NULL, 1, SAF_TUPLES, &state_index, (void **)&tmp_fields);
*fields = tmp_fields;
}
else {
tmp_fields = *fields;
saf_read_field( pmode, stategrp_state, NULL, 1, SAF_TUPLES, &state_index, (void **)&tmp_fields);
}
}
}
free(coords);
free(stategrp_contents);
SAF_LEAVE(0);
}
|