MISR Toolkit  1.5.1
MtkWriteBinFile.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkWriteBinFile =
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  MTKt_MapInfo mapinfo )
33 {
34  FILE *fp; /* File pointer */
35  char infofname[300]; /* Filename plus extension */
36  char rawfname[300]; /* Filename plus extension */
38  /* Datatype description mapping */
39  int i; /* Loop index */
40  int endian = 1; /* Endian test */
41  char *endian_ptr = (char *)&endian;
42 
43  if (filename == NULL)
44  return MTK_NULLPTR;
45 
46  /* Write binary file */
47  strcpy(rawfname, filename);
48  strcat(rawfname, ".raw");
49  if ((fp = fopen(rawfname, "wb")) == NULL) {
50  MTK_ERR_MSG_JUMP("Error opening binfile");
51  }
52  fwrite(buf.dataptr, buf.datasize, buf.nline * buf.nsample, fp);
53  fclose(fp);
54 
55 
56  /* Write info file */
57  strcpy(infofname, filename);
58  strcat(infofname, ".info");
59  if ((fp = fopen(infofname, "wb")) == NULL) {
60  MTK_ERR_MSG_JUMP("Error opening infofile");
61  }
62 
63  fprintf(fp, "filename = %s\n", rawfname);
64 
65  fprintf(fp, "image.header_bytes = 0\n");
66  fprintf(fp, "image.nline = %d\n", buf.nline);
67  fprintf(fp, "image.nsample = %d\n", buf.nsample);
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  fprintf(fp, "mapinfo.path = %d\n", mapinfo.path);
76  fprintf(fp, "mapinfo.start_block = %d\n", mapinfo.start_block);
77  fprintf(fp, "mapinfo.end_block = %d\n", mapinfo.end_block);
78  fprintf(fp, "mapinfo.resolution = %d\n", mapinfo.resolution);
79  fprintf(fp, "mapinfo.resfactor = %d\n", mapinfo.resfactor);
80  fprintf(fp, "mapinfo.nline = %d\n", mapinfo.nline);
81  fprintf(fp, "mapinfo.nsample = %d\n", mapinfo.nsample);
82  fprintf(fp, "mapinfo.pixelcenter = %s\n",
83  mapinfo.pixelcenter == 1 ? "true" : "false");
84  fprintf(fp, "mapinfo.som.ulc.x = %f\n", mapinfo.som.ulc.x);
85  fprintf(fp, "mapinfo.som.ulc.y = %f\n", mapinfo.som.ulc.y);
86  fprintf(fp, "mapinfo.som.ctr.x = %f\n", mapinfo.som.ctr.x);
87  fprintf(fp, "mapinfo.som.ctr.y = %f\n", mapinfo.som.ctr.y);
88  fprintf(fp, "mapinfo.som.lrc.x = %f\n", mapinfo.som.lrc.x);
89  fprintf(fp, "mapinfo.som.lrc.y = %f\n", mapinfo.som.lrc.y);
90 
91  fprintf(fp, "mapinfo.geo.ulc.lat = %f\n", mapinfo.geo.ulc.lat);
92  fprintf(fp, "mapinfo.geo.ulc.lon = %f\n", mapinfo.geo.ulc.lon);
93  fprintf(fp, "mapinfo.geo.urc.lat = %f\n", mapinfo.geo.ulc.lat);
94  fprintf(fp, "mapinfo.geo.urc.lon = %f\n", mapinfo.geo.ulc.lon);
95  fprintf(fp, "mapinfo.geo.ctr.lat = %f\n", mapinfo.geo.ctr.lat);
96  fprintf(fp, "mapinfo.geo.ctr.lon = %f\n", mapinfo.geo.ctr.lon);
97  fprintf(fp, "mapinfo.geo.lrc.lat = %f\n", mapinfo.geo.lrc.lat);
98  fprintf(fp, "mapinfo.geo.lrc.lon = %f\n", mapinfo.geo.lrc.lon);
99  fprintf(fp, "mapinfo.geo.llc.lat = %f\n", mapinfo.geo.lrc.lat);
100  fprintf(fp, "mapinfo.geo.llc.lon = %f\n", mapinfo.geo.lrc.lon);
101 
102  fprintf(fp, "mapinfo.pp.path = %d\n", mapinfo.pp.path);
103  fprintf(fp, "mapinfo.pp.projcode = %lld\n", mapinfo.pp.projcode);
104  fprintf(fp, "mapinfo.pp.zonecode = %lld\n", mapinfo.pp.zonecode);
105  fprintf(fp, "mapinfo.pp.spherecode = %lld\n", mapinfo.pp.spherecode);
106  for (i = 0; i < 15 ; i++)
107  fprintf(fp, "mapinfo.pp.projparam[%d] = %f\n", i, mapinfo.pp.projparam[i]);
108  for (i = 0; i < 2 ; i++)
109  fprintf(fp, "mapinfo.pp.ulc[%d] = %f\n", i, mapinfo.pp.ulc[i]);
110  for (i = 0; i < 2 ; i++)
111  fprintf(fp, "mapinfo.pp.lrc[%d] = %f\n", i, mapinfo.pp.lrc[i]);
112  fprintf(fp, "mapinfo.pp.nblock = %d\n", mapinfo.pp.nblock);
113  fprintf(fp, "mapinfo.pp.nline = %d\n", mapinfo.pp.nline);
114  fprintf(fp, "mapinfo.pp.nsample = %d\n", mapinfo.pp.nsample);
115  for (i = 0; i < 179 ; i++)
116  fprintf(fp, "mapinfo.pp.reloffset[%d] = %f\n", i, mapinfo.pp.reloffset[i]);
117  fprintf(fp, "mapinfo.pp.resolution = %d\n", mapinfo.pp.resolution);
118 
119  fclose(fp);
120 
121  return MTK_SUCCESS;
122 ERROR_HANDLE:
123  return MTK_FAILURE;
124 }
HDFFCLIBAPI _fcd _fcd intf intf * datatype
char * filename
Definition: cdjpeg.h:133
double projparam[15]
Map Information.
Definition: MisrMapQuery.h:65
MTKt_GeoCoord lrc
Definition: MisrMapQuery.h:45
2-dimensional Data Buffer
Definition: MisrUtil.h:98
float reloffset[179]
MTKt_GeoCoord ulc
Definition: MisrMapQuery.h:42
MTKt_GeoCoord ctr
Definition: MisrMapQuery.h:44
MTKt_MisrProjParam pp
Definition: MisrMapQuery.h:76
void * dataptr
Definition: MisrUtil.h:106
MTKt_DataType datatype
Definition: MisrUtil.h:102
MTKt_GeoRegion geo
Definition: MisrMapQuery.h:75
#define MTKd_NDATATYPE
Definition: MisrUtil.h:30
#define MTK_ERR_MSG_JUMP(msg)
Definition: MisrError.h:169
MTKt_boolean pixelcenter
Definition: MisrMapQuery.h:73
#define MTKd_DataType
Definition: MisrUtil.h:31
MTKt_SomCoord lrc
Definition: MisrMapQuery.h:58
MTKt_SomCoord ctr
Definition: MisrMapQuery.h:57
MTKt_status
Definition: MisrError.h:11
MTKt_SomRegion som
Definition: MisrMapQuery.h:74
MTKt_status MtkWriteBinFile(const char *filename, MTKt_DataBuffer buf, MTKt_MapInfo mapinfo)
Write binary file.
HDFFCLIBAPI intf * buf
MTKt_SomCoord ulc
Definition: MisrMapQuery.h:56

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