@@ -29,6 +29,11 @@ void ph_write_header(FILE* f, const char* name, size_t bytes,
29
29
fprintf (f , "\n" );
30
30
}
31
31
32
+ static void skip_leading_spaces (char * * s )
33
+ {
34
+ while (* * s == ' ' ) ++ (* s );
35
+ }
36
+
32
37
static void cut_trailing_spaces (char * s )
33
38
{
34
39
char * e = s + strlen (s );
@@ -47,6 +52,7 @@ static void parse_header(char* header, char** name, size_t* bytes,
47
52
header = strtok_r (header , ":" , & saveptr );
48
53
if (name ) {
49
54
* name = header ;
55
+ skip_leading_spaces (name );
50
56
cut_trailing_spaces (* name );
51
57
}
52
58
strtok_r (NULL , "<" , & saveptr );
@@ -59,7 +65,7 @@ static void parse_header(char* header, char** name, size_t* bytes,
59
65
}
60
66
}
61
67
62
- static void find_header (FILE * f , const char * name , char header [PH_LINE ])
68
+ static int find_header (FILE * f , const char * name , char header [PH_LINE ])
63
69
{
64
70
char * hname ;
65
71
size_t bytes ;
@@ -70,10 +76,12 @@ static void find_header(FILE* f, const char* name, char header[PH_LINE])
70
76
strcpy (tmp , header );
71
77
parse_header (tmp , & hname , & bytes , 0 , NULL );
72
78
if (!strcmp (name , hname ))
73
- return ;
79
+ return 1 ;
74
80
fseek (f , bytes , SEEK_CUR );
75
81
}
76
- header [0 ] = '\0' ;
82
+ if (!PCU_Comm_Self ())
83
+ fprintf (stderr ,"warning: phIO could not find \"%s\"\n" ,name );
84
+ return 0 ;
77
85
}
78
86
79
87
static void get_now_string (char s [PH_LINE ])
@@ -97,8 +105,7 @@ static void write_magic_number(FILE* f)
97
105
static int seek_after_header (FILE * f , const char * name )
98
106
{
99
107
char dummy [PH_LINE ];
100
- find_header (f , name , dummy );
101
- return dummy [0 ] != '\0' ;
108
+ return find_header (f , name , dummy );
102
109
}
103
110
104
111
static void my_fread (void * p , size_t size , size_t nmemb , FILE * f )
@@ -111,7 +118,7 @@ static int read_magic_number(FILE* f)
111
118
{
112
119
if (!seek_after_header (f , magic_name )) {
113
120
if (!PCU_Comm_Self ())
114
- fprintf (stderr ,"warning: no byteorder magic number. not swapping\n" );
121
+ fprintf (stderr ,"warning: not swapping bytes \n" );
115
122
rewind (f );
116
123
return 0 ;
117
124
}
@@ -163,17 +170,15 @@ void ph_read_field(const char* file, const char* field, double** data,
163
170
size_t bytes , n ;
164
171
char header [PH_LINE ];
165
172
int should_swap ;
173
+ int ok ;
166
174
FILE * f = fopen (file , "r" );
167
175
if (!f ) {
168
176
fprintf (stderr ,"could not open \"%s\"\n" , file );
169
177
abort ();
170
178
}
171
179
should_swap = read_magic_number (f );
172
- find_header (f , field , header );
173
- if (header [0 ] == '\0' ) {
174
- fprintf (stderr ,"could not find field \"%s\"\n" ,field );
175
- abort ();
176
- }
180
+ ok = find_header (f , field , header );
181
+ assert (ok );
177
182
parse_params (header , & bytes , nodes , vars , step );
178
183
assert (((bytes - 1 ) % sizeof (double )) == 0 );
179
184
n = (bytes - 1 ) / sizeof (double );
0 commit comments