summaryrefslogtreecommitdiffstats
path: root/tksao/fitsy++/outfile.C
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 18:59:29 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 18:59:29 (GMT)
commitd4d595fa7fb12903db9227d33d48b2b00120dbd1 (patch)
tree7d18365de0d6d1b29399b6a17c7eb01c2eb3ed49 /tksao/fitsy++/outfile.C
parent949f96e29bfe0bd8710d775ce220e597064e2589 (diff)
downloadblt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.zip
blt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.tar.gz
blt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.tar.bz2
Initial commit
Diffstat (limited to 'tksao/fitsy++/outfile.C')
-rw-r--r--tksao/fitsy++/outfile.C63
1 files changed, 63 insertions, 0 deletions
diff --git a/tksao/fitsy++/outfile.C b/tksao/fitsy++/outfile.C
new file mode 100644
index 0000000..e972599
--- /dev/null
+++ b/tksao/fitsy++/outfile.C
@@ -0,0 +1,63 @@
+// Copyright (C) 1999-2016
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <stdio.h>
+#include "outfile.h"
+
+OutFitsFile::OutFitsFile(const char* fn)
+{
+ if ((fd_ = fopen(fn, "wb")))
+ valid_ = 1;
+}
+
+OutFitsFile::~OutFitsFile()
+{
+ if (fd_)
+ fclose(fd_);
+}
+
+int OutFitsFile::write(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss =size;
+ size_t rr = 0;
+ int r = 0;
+
+ do {
+ r = fwrite(where+rr, 1, (ss>B1MB) ? B1MB : ss, fd_);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+}
+
+OutFitsFileGZ::OutFitsFileGZ(const char* fn)
+{
+ if ((fd_ = gzopen(fn, "wb")))
+ valid_ = 1;
+}
+
+OutFitsFileGZ::~OutFitsFileGZ()
+{
+ if (fd_)
+ gzclose(fd_);
+}
+
+int OutFitsFileGZ::write(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss =size;
+ size_t rr = 0;
+ int r = 0;
+
+ do {
+ r = gzwrite(fd_, where+rr, (ss>B1MB) ? B1MB : ss);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+}
+