GRASS GIS 8 Programmer's Manual 8.3.2(2024)-exported
Loading...
Searching...
No Matches
dspf_header.c
Go to the documentation of this file.
1#include <string.h>
2#include <grass/gis.h>
3#include "viz.h"
4
5/*================= DOCUMENT RETURN VALUES! =================*/
6
8{
9 int isize, flsize;
10 cmndln_info *linep;
11 FILE *fp;
12 long Where_dataoff;
13
14 linep = &(headp->linefax);
15 fp = headp->dspfoutfp;
16
17 isize = sizeof(int);
18 flsize = sizeof(float);
19 /* print the header code on first line of file */
20 if (!fwrite(DSPF_ID, strlen(DSPF_ID), 1, fp))
21 return (-1);
22 /* the dimensions of the data */
23 if (1 != fwrite(&headp->xdim, isize, 1, fp))
24 return (-1);
25 if (1 != fwrite(&headp->ydim, isize, 1, fp))
26 return (-1);
27 if (1 != fwrite(&headp->zdim, isize, 1, fp))
28 return (-1);
29
30 /* print out code for min and max values */
31 if (1 != fwrite(&headp->min, flsize, 1, fp))
32 return (-1);
33 if (1 != fwrite(&headp->max, flsize, 1, fp))
34 return (-1);
35
36 /* the litmodel stored for each polygon */
37 if (1 != fwrite(&linep->litmodel, isize, 1, fp))
38 return (-1);
39
40 /* write the total number of thresholds to be searched for */
41 if (1 != fwrite(&linep->nthres, isize, 1, fp))
42 return (-1);
43 /* write the array of thresholds out */
44 if ((fwrite(linep->tvalue, flsize, linep->nthres, fp)) !=
45 (size_t)linep->nthres) {
46 fprintf(stderr, "ERROR: fwrite in dspf_header.c\n");
47 return (-1);
48 }
49
50 /* write the offset to the lookup table */
51 /* the first time this number is set to 0 */
52 /*this information will be overwritten after dspf is done */
53 /* G_ftell keeps track of where this information is to be placed */
54 headp->Lookoff = 0;
55 if (1 != fwrite(&headp->Lookoff, sizeof(long), 1, fp))
56 return (-1);
57
58 /* code to determine the length of the binary file header */
59 /* Dataoff = length of the header */
60 /*Dataoff = strlen (DSPF_ID) + 7*isize + 5*flsize + linep->nthres*flsize; */
61 Where_dataoff = G_ftell(fp);
62 headp->Dataoff = 0;
63 if (1 != fwrite(&headp->Dataoff, sizeof(long), 1, fp))
64 return (-1);
65
66 /* End of header, now go back and fill in what we can */
67 headp->Dataoff = G_ftell(fp);
68 G_fseek(fp, Where_dataoff, 0);
69 if (1 != fwrite(&headp->Dataoff, sizeof(long), 1, fp))
70 return (-1);
71
72 G_fseek(fp, headp->Dataoff, 0); /* and return to begin writing data */
73
74 /* will still have to come back once more to fill in Lookup offset */
75
76 return (0);
77}
78
79/**************************** dfread_header **********************************/
80
81/**************************** dfread_header **********************************/
82
83/**************************** dfread_header **********************************/
84
86{
87 int isize, flsize;
88 FILE *fp;
89 cmndln_info *linep;
90 char buf[80];
91 int len;
92
93 fp = headp->dspfinfp;
94
95 len = strlen(DSPF_ID);
96 G_fseek(fp, 0L, 0); /* rewind file */
97 /*read in header information and store in File_info struct */
98
99 if (!fread(buf, 1, len, fp))
100 return (-1);
101 buf[len] = 0;
102 if (strncmp(DSPF_ID, buf, len)) {
103 if (!strncmp("dspf003.01", buf, len))
104 return (dfread_header_old(headp, fp));
105
106 fprintf(stderr, "Error: header mismatch '%s' - '%s'\n", DSPF_ID, buf);
107 return (-1);
108 }
109 linep = &(headp->linefax);
110 isize = sizeof(int);
111 flsize = sizeof(float);
112
113 if (!fread(&headp->xdim, isize, 1, fp))
114 return (-1);
115 if (!fread(&headp->ydim, isize, 1, fp))
116 return (-1);
117 if (!fread(&headp->zdim, isize, 1, fp))
118 return (-1);
119 if (!fread(&headp->min, flsize, 1, fp))
120 return (-1);
121 if (!fread(&headp->max, flsize, 1, fp))
122 return (-1);
123 if (!fread(&linep->litmodel, isize, 1, fp))
124 return (-1);
125 if (!fread(&linep->nthres, isize, 1, fp))
126 return (-1);
127 if (!fread(linep->tvalue, flsize, linep->nthres, fp))
128 return (-1);
129 if (!fread(&headp->Lookoff, isize, 1, fp))
130 return (-1);
131 if (!fread(&headp->Dataoff, isize, 1, fp))
132 return (-1);
133
134 print_head_info(headp);
135
136 return (1);
137}
138
139int dfread_header_old(file_info *headp, FILE *fp)
140{
141 int isize, flsize;
142 cmndln_info *linep;
143 float tmp;
144
145 linep = &(headp->linefax);
146 isize = sizeof(int);
147 flsize = sizeof(float);
148
149 if (!fread(&headp->xdim, isize, 1, fp))
150 return (-1);
151 if (!fread(&headp->ydim, isize, 1, fp))
152 return (-1);
153 if (!fread(&headp->zdim, isize, 1, fp))
154 return (-1);
155 if (!fread(&tmp, flsize, 1, fp))
156 return (-1);
157 if (!fread(&tmp, flsize, 1, fp))
158 return (-1);
159 if (!fread(&tmp, flsize, 1, fp))
160 return (-1);
161 if (!fread(&headp->min, flsize, 1, fp))
162 return (-1);
163 if (!fread(&headp->max, flsize, 1, fp))
164 return (-1);
165 if (!fread(&linep->litmodel, isize, 1, fp))
166 return (-1);
167 if (!fread(&linep->nthres, isize, 1, fp))
168 return (-1);
169 if (!fread(linep->tvalue, flsize, linep->nthres, fp))
170 return (-1);
171 if (!fread(&headp->Lookoff, isize, 1, fp))
172 return (-1);
173 if (!fread(&headp->Dataoff, isize, 1, fp))
174 return (-1);
175
176 print_head_info(headp);
177
178 return (1);
179}
int dfwrite_header(file_info *headp)
Definition dspf_header.c:7
int dfread_header_old(file_info *headp, FILE *fp)
int dfread_header(file_info *headp)
Definition dspf_header.c:85
void G_fseek(FILE *fp, off_t offset, int whence)
Change the file position of the stream.
Definition gis/seek.c:50
off_t G_ftell(FILE *fp)
Get the current file position of the stream.
Definition gis/seek.c:29
int print_head_info(file_info *head)
Definition print_info.c:3
float tvalue[MAXTHRESH]
Definition viz.h:23
int nthres
Definition viz.h:22
int litmodel
Definition viz.h:24
int zdim
Definition viz.h:32
long Lookoff
Definition viz.h:41
int xdim
Definition viz.h:32
int ydim
Definition viz.h:32
FILE * dspfoutfp
Definition viz.h:31
cmndln_info linefax
Definition viz.h:42
long Dataoff
Definition viz.h:40
FILE * dspfinfp
Definition viz.h:31
float min
Definition viz.h:39
float max
Definition viz.h:39
#define DSPF_ID
Definition viz.h:6