MISR Toolkit  1.5.1
MtkWriteBinFile3D.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkWriteBinFile3D =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2005, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrWriteData.h"
18 #include "MisrError.h"
19 #include "MisrUtil.h"
20 #include <string.h>
21 #include <stdio.h>
22 
30  const char *filename,
32 {
33  FILE *fp; /* File pointer */
34  char infofname[300]; /* Filename plus extension */
35  char rawfname[300]; /* Filename plus extension */
37  /* Datatype description mapping */
38  int endian = 1; /* Endian test */
39  char *endian_ptr = (char *)&endian;
40 
41  if (filename == NULL)
42  return MTK_NULLPTR;
43 
44  /* Write binary file */
45  strcpy(rawfname, filename);
46  strcat(rawfname, ".raw");
47  if ((fp = fopen(rawfname, "wb")) == NULL) {
48  MTK_ERR_MSG_JUMP("Error opening binfile");
49  }
50  fwrite(buf.dataptr, buf.datasize, buf.nblock * buf.nline * buf.nsample, fp);
51  fclose(fp);
52 
53 
54  /* Write info file */
55  strcpy(infofname, filename);
56  strcat(infofname, ".info");
57  if ((fp = fopen(infofname, "wb")) == NULL) {
58  MTK_ERR_MSG_JUMP("Error opening infofile");
59  }
60 
61  fprintf(fp, "filename = %s\n", rawfname);
62 
63  fprintf(fp, "image.header_bytes = 0\n");
64  fprintf(fp, "image.nblock = %d\n", buf.nblock);
65  fprintf(fp, "image.nline = %d\n", buf.nline);
66  fprintf(fp, "image.nsample = %d\n", buf.nsample);
67  fprintf(fp, "image.nblock * image.nline = %d\n", buf.nblock * buf.nline);
68  fprintf(fp, "image.datatype = %s\n", datatype[buf.datatype]);
69  fprintf(fp, "image.datasize = %d\n", buf.datasize);
70  if (endian_ptr[0] == 1)
71  fprintf(fp,"image.byteorder = little_endian\n");
72  else
73  fprintf(fp,"image.byteorder = big_endian\n");
74 
75  fclose(fp);
76 
77  return MTK_SUCCESS;
78 ERROR_HANDLE:
79  return MTK_FAILURE;
80 }
HDFFCLIBAPI _fcd _fcd intf intf * datatype
char * filename
Definition: cdjpeg.h:133
3-dimensional Data Buffer
Definition: MisrUtil.h:129
MTKt_DataType datatype
Definition: MisrUtil.h:134
MTKt_status MtkWriteBinFile3D(const char *filename, MTKt_DataBuffer3D buf)
Write binary file from 3D buffer in stacked block format.
#define MTKd_NDATATYPE
Definition: MisrUtil.h:30
#define MTK_ERR_MSG_JUMP(msg)
Definition: MisrError.h:169
#define MTKd_DataType
Definition: MisrUtil.h:31
MTKt_status
Definition: MisrError.h:11
HDFFCLIBAPI intf * buf

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:53