29 ifstream* fimg =
new ifstream(p->
file_name());
30 if ( fimg->fail() )
return -1;
32 short titlen, nbr, nbc,
sb = 0, pad;
36 cout <<
"DEBUG readPIC: Reading PIC file = " << p->
file_name() << endl;
39 fimg->read( (
char *)&pad,
sizeof(
short) );
if ( fimg->fail() )
return -2;
40 fimg->read( (
char *)&titlen,
sizeof(
short) );
if ( fimg->fail() )
return -2;
43 swapbytes((
unsigned char *)&titlen,
sizeof(
short));
45 fimg->read( (
char *)&pad,
sizeof(
short) );
if ( fimg->fail() )
return -2;
46 if ( !pad ) fimg->read( (
char *)&pad,
sizeof(
short) );
if ( fimg->fail() )
return -2;
47 if ( titlen > 59 ) titlen = 59;
49 fimg->read( title, 2*titlen );
50 if ( fimg->fail() )
return -2;
51 title[2*titlen+1] = 0;
53 fimg->read( (
char *)&pad,
sizeof(
short) );
if ( fimg->fail() )
return -2;
54 if ( !pad ) fimg->read( (
char *)&pad,
sizeof(
short) );
if ( fimg->fail() )
return -2;
55 fimg->read( (
char *)&nbr,
sizeof(
short) );
if ( fimg->fail() )
return -2;
56 fimg->read( (
char *)&pad,
sizeof(
short) );
if ( fimg->fail() )
return -2;
57 if ( !pad ) fimg->read( (
char *)&pad,
sizeof(
short) );
if ( fimg->fail() )
return -2;
58 fimg->read( (
char *)&nbc,
sizeof(
short) );
if ( fimg->fail() )
return -2;
61 swapbytes((
unsigned char *)&nbr,
sizeof(
short));
62 swapbytes((
unsigned char *)&nbc,
sizeof(
short));
66 cout <<
"DEBUG readPIC: sb=" <<
sb << endl;
67 cout <<
"DEBUG readPIC: title: " << title <<
" (length = " << 2*titlen <<
")" << endl;
68 cout <<
"DEBUG readPIC: size=" << nbc <<
"x" << nbr << endl;
69 cout <<
"DEBUG readPIC: offset=" << 2*titlen + 8*
sizeof(short) << endl;
78 if ( p->
file_name().find(
".bq") != string::npos || p->
file_name().find(
".BQ") != string::npos )
86 long linesize = p->
sizeX()*datatypesize;
87 long i, y, y2, pagesize;
95 for ( y=0; y<p->
sizeY(); y++ ) {
96 for ( i=1, y2=0; y2<p->
sizeX(); y2+=2042, i++ ) {
98 if ( pagesize > linesize - y2 ) pagesize = linesize - y2;
99 fimg->read( (
char *)&pad,
sizeof(short) );
100 if ( fimg->fail() )
return -3;
101 if ( !pad ) fimg->read( (
char *)&pad,
sizeof(short) );
102 if ( fimg->fail() )
return -3;
103 fimg->read( data+y*linesize+y2, pagesize );
104 if ( fimg->fail() )
return -3;
114 cout <<
"Warning: BQ files may be VMS G_float, not supported in Bsoft" << endl;
115 for ( y=0; y<datasize; y+=4 )
120 cout <<
"DEBUG readPIC: PIC file " << p->
file_name() <<
" read" << endl;
136 short titlen, nbr, nbc, pad = 3;
138 memset(title,
' ', 120);
141 strncpy(title, p->
label().c_str(), 120);
142 titlen = strlen(title)/2 + 1;
147 long linesize = p->
sizeX()*datatypesize;
150 if ( fimg.fail() )
return -1;
152 fimg.write( (
char *)&pad,
sizeof(
short) );
153 fimg.write( (
char *)&titlen,
sizeof(
short) );
154 fimg.write( (
char *)&pad,
sizeof(
short) );
155 fimg.write( title, 2*titlen );
156 fimg.write( (
char *)&pad,
sizeof(
short) );
157 fimg.write( (
char *)&nbr,
sizeof(
short) );
158 fimg.write( (
char *)&pad,
sizeof(
short) );
159 fimg.write( (
char *)&nbc,
sizeof(
short) );
163 long y, y2, pagesize;
167 for ( y=0; y<p->
sizeY(); y++ ) {
168 for ( y2=0; y2<p->
sizeX(); y2+=2042 ) {
169 if ( p->
sizeX() > 2042 ) pad = y2 + 1;
171 if ( pagesize > linesize - y2 ) pagesize = linesize - y2;
172 fimg.write( (
char *)&pad,
sizeof(short) );
173 fimg.write( data+y*linesize+y2, pagesize );