Mercurial > hg > minc-tools
changeset 1285:26dcce6f5b86
Added support for bzip files. (Modified patch from Steve Robbins)
author | neelin <neelin> |
---|---|
date | Wed, 13 Sep 2000 14:02:00 +0000 |
parents | d785af9dcd55 |
children | 4342fd888f8f |
files | libsrc/netcdf_convenience.c |
diffstat | 1 files changed, 16 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/libsrc/netcdf_convenience.c +++ b/libsrc/netcdf_convenience.c @@ -35,7 +35,10 @@ @CREATED : July 27, 1992. (Peter Neelin, Montreal Neurological Institute) @MODIFIED : * $Log: netcdf_convenience.c,v $ - * Revision 6.3 2000-02-02 18:43:29 neelin + * Revision 6.4 2000-09-13 14:02:00 neelin + * Added support for bzip files. (Modified patch from Steve Robbins) + * + * Revision 6.3 2000/02/02 18:43:29 neelin * Fixed bug in miexpand_file that would call fclose with a NULL file handle. * For newer versions of glibc, this would cause a seg fault. * @@ -113,7 +116,7 @@ ---------------------------------------------------------------------------- */ #ifndef lint -static char rcsid[] = "$Header: /private-cvsroot/minc/libsrc/netcdf_convenience.c,v 6.3 2000-02-02 18:43:29 neelin Exp $ MINC (MNI)"; +static char rcsid[] = "$Header: /private-cvsroot/minc/libsrc/netcdf_convenience.c,v 6.4 2000-09-13 14:02:00 neelin Exp $ MINC (MNI)"; #endif #include <minc_private.h> @@ -155,7 +158,6 @@ char whole_command[1024]; int status; FILE *pipe, *output; - int output_opened; char buffer[1024]; int successful_ncopen; int ibuf; @@ -186,7 +188,7 @@ (void) sprintf(whole_command, "exec %s %s 2> /dev/null", command, infile); pipe = popen(whole_command, "r"); - output_opened = FALSE; + output = NULL; /* Loop until we have successfully opened the minc file (the header is all there) */ @@ -199,13 +201,12 @@ ((nread = fread(buffer, sizeof(char), sizeof(buffer), pipe)) > 0); ibuf++) { - if (!output_opened) { - output= fopen(outfile, "w"); + if (output == NULL) { + output = fopen(outfile, "w"); if (output == NULL) { (void) fclose(pipe); return 1; } - output_opened = TRUE; } if (fwrite(buffer, sizeof(char), nread, output) != nread) { (void) fclose(output); @@ -285,7 +286,8 @@ public char *miexpand_file(char *path, char *tempfile, int header_only, int *created_tempfile) { - typedef enum {GZIPPED, COMPRESSED, PACKED, ZIPPED, UNKNOWN} Compress_type; + typedef enum + {BZIPPED, GZIPPED, COMPRESSED, PACKED, ZIPPED, UNKNOWN} Compress_type; int status, oldncopts, first_ncerr, iext; char *newfile, *extension, *compfile; FILE *fp; @@ -294,6 +296,8 @@ char *extension; Compress_type type; } compression_code_list[] = { + {".bz", BZIPPED}, + {".bz2", BZIPPED}, {".gz", GZIPPED}, {".Z", COMPRESSED}, {".z", PACKED}, @@ -399,6 +403,10 @@ status = execute_decompress_command("gunzip -c", path, newfile, header_only); } + else if (compress_type == BZIPPED) { + status = execute_decompress_command("bunzip2 -c", path, newfile, + header_only); + } /* If that doesn't work, try something else */ if (status != 0) {