Skip to content

Commit 94e1638

Browse files
afni-rickrhjmjohnson
authored andcommitted
nifti_image_write_bricks_status
1 parent 55ece6a commit 94e1638

File tree

5 files changed

+60
-20
lines changed

5 files changed

+60
-20
lines changed

nifti2/nifti2_io.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8018,16 +8018,7 @@ znzFile nifti_write_ascii_image(nifti_image *nim, const nifti_brick_list * NBL,
80188018
*//*------------------------------------------------------------------------*/
80198019
void nifti_image_write( nifti_image *nim )
80208020
{
8021-
znzFile fp=NULL;
8022-
int rv;
8023-
8024-
rv = nifti_image_write_engine(nim, 1, "wb", &fp, NULL);
8025-
if( fp ){
8026-
if( g_opts.debug > 2 ) fprintf(stderr,"-d niw: done with znzFile\n");
8027-
free(fp);
8028-
}
8029-
if( g_opts.debug > 1 )
8030-
fprintf(stderr,"-d nifti_image_write: done, status %d\n", rv);
8021+
(void)nifti_image_write_status(nim);
80318022
}
80328023

80338024

@@ -8048,25 +8039,51 @@ int nifti_image_write_status( nifti_image *nim )
80488039
int rv;
80498040

80508041
rv = nifti_image_write_engine(nim, 1, "wb", &fp, NULL);
8042+
8043+
if( fp ){ /* this should not happen, as we requested file closure */
8044+
if( g_opts.debug > 2 ) fprintf(stderr,"-d niw: done with znzFile\n");
8045+
free(fp);
8046+
}
80518047
if( g_opts.debug > 1 )
80528048
fprintf(stderr,"-d nifti_image_write_status: done, status %d\n", rv);
8049+
80538050
return rv;
80548051
}
80558052

80568053

80578054
/*----------------------------------------------------------------------*/
8058-
/*! similar to nifti_image_write, but data is in NBL struct, not nim->data
8055+
/*! similar to nifti_image_write_status, but data is in NBL struct,
8056+
not nim->data
8057+
8058+
\return 0 on success, 1 on error
80598059
80608060
\sa nifti_image_write, nifti_image_free, nifti_set_filenames, nifti_free_NBL
80618061
*//*--------------------------------------------------------------------*/
8062-
void nifti_image_write_bricks( nifti_image *nim, const nifti_brick_list * NBL )
8062+
int nifti_image_write_bricks_status( nifti_image *nim,
8063+
const nifti_brick_list * NBL )
80638064
{
8064-
znzFile fp = nifti_image_write_hdr_img2(nim,1,"wb",NULL,NBL);
8065+
znzFile fp=NULL;
8066+
int rv;
8067+
8068+
rv = nifti_image_write_engine(nim, 1, "wb", &fp, NBL);
80658069
if( fp ){
80668070
if( g_opts.debug > 2 ) fprintf(stderr,"-d niwb: done with znzFile\n");
80678071
free(fp);
80688072
}
8069-
if( g_opts.debug > 1 ) fprintf(stderr,"-d niwb: done writing bricks\n");
8073+
if( g_opts.debug > 1 )
8074+
fprintf(stderr,"-d niwb: done writing bricks, status %d\n", rv);
8075+
return rv;
8076+
}
8077+
8078+
8079+
/*----------------------------------------------------------------------*/
8080+
/*! similar to nifti_image_write, but data is in NBL struct, not nim->data
8081+
8082+
\sa nifti_image_write, nifti_image_free, nifti_set_filenames, nifti_free_NBL
8083+
*//*--------------------------------------------------------------------*/
8084+
void nifti_image_write_bricks( nifti_image *nim, const nifti_brick_list * NBL )
8085+
{
8086+
(void)nifti_image_write_bricks_status(nim, NBL);
80708087
}
80718088

80728089

nifti2/nifti2_io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ int nifti_image_write_status( nifti_image *nim ) ; /* 7 Jun 2022 */
448448

449449
void nifti_image_write_bricks(nifti_image * nim,
450450
const nifti_brick_list * NBL);
451+
int nifti_image_write_bricks_status(nifti_image * nim,
452+
const nifti_brick_list * NBL);
451453
void nifti_image_infodump( const nifti_image * nim ) ;
452454

453455
void nifti_disp_lib_hist( int ver ) ; /* to display library history */

nifti2/nifti_tool.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7123,14 +7123,16 @@ int act_cbl( nt_opts * opts )
71237123

71247124
/* and finally, write out results */
71257125
if( err == 0 && nifti_nim_is_valid(nim, g_debug) )
7126-
nifti_image_write_bricks(nim, &NBL);
7126+
if( nifti_image_write_bricks_status(nim, &NBL) ) {
7127+
err++;
7128+
}
71277129

71287130
nifti_image_free(nim);
71297131
nifti_free_NBL(&NBL);
71307132
free(fname);
71317133
free(selstr);
71327134

7133-
return 0;
7135+
return err;
71347136
}
71357137

71367138

niftilib/nifti1_io.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5947,18 +5947,35 @@ int nifti_image_write_status( nifti_image *nim )
59475947
/*----------------------------------------------------------------------*/
59485948
/*! similar to nifti_image_write, but data is in NBL struct, not nim->data
59495949
5950-
\return 0 on success, -1 on error
5950+
\return 0 on success, 1 on error
59515951
59525952
\sa nifti_image_write, nifti_image_free, nifti_set_filenames, nifti_free_NBL
59535953
*//*--------------------------------------------------------------------*/
5954-
void nifti_image_write_bricks( nifti_image *nim, const nifti_brick_list * NBL )
5954+
int nifti_image_write_bricks_status( nifti_image *nim,
5955+
const nifti_brick_list * NBL )
59555956
{
5956-
znzFile fp = nifti_image_write_hdr_img2(nim,1,"wb",NULL,NBL);
5957+
znzFile fp=NULL;
5958+
int rv;
5959+
5960+
rv = nifti_image_write_engine(nim, 1, "wb", &fp, NBL);
59575961
if( fp ){
59585962
if( g_opts.debug > 2 ) fprintf(stderr,"-d niwb: done with znzFile\n");
59595963
free(fp);
59605964
}
5961-
if( g_opts.debug > 1 ) fprintf(stderr,"-d niwb: done writing bricks\n");
5965+
if( g_opts.debug > 1 )
5966+
fprintf(stderr,"-d niwb: done writing bricks, status %d\n", rv);
5967+
return rv;
5968+
}
5969+
5970+
5971+
/*----------------------------------------------------------------------*/
5972+
/*! similar to nifti_image_write, but data is in NBL struct, not nim->data
5973+
5974+
\sa nifti_image_write, nifti_image_free, nifti_set_filenames, nifti_free_NBL
5975+
*//*--------------------------------------------------------------------*/
5976+
void nifti_image_write_bricks( nifti_image *nim, const nifti_brick_list * NBL )
5977+
{
5978+
(void)nifti_image_write_bricks_status(nim, NBL);
59625979
}
59635980

59645981

niftilib/nifti1_io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ int nifti_image_write_status( nifti_image *nim );
303303

304304
void nifti_image_write_bricks(nifti_image * nim,
305305
const nifti_brick_list * NBL);
306+
int nifti_image_write_bricks_status(nifti_image * nim,
307+
const nifti_brick_list * NBL);
306308
void nifti_image_infodump( const nifti_image * nim ) ;
307309

308310
void nifti_disp_lib_hist( void ) ; /* to display library history */

0 commit comments

Comments
 (0)