Go Back   HDF-EOS Forums > Library > C

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-02-2011, 03:14 AM
wlz1220 wlz1220 is offline
Junior Member
 
Join Date: Feb 2011
Posts: 2
Question How to write a hdf-eos2 file with geographic information(like the MCD43B3 files)?

Hello everyone,

I am trying to write a file in HDF-EOS2 format with VC++6.0 by using hdf4.2 libs and hdfeos v2 libs. I have written one, but the geographic information of it cannot be identified by MRT and ENVI.
The following is my code to write HDF-EOS2 files.
long GlassAlbedo03HDF::WriteHDFEOS(const char* pathname, ImageSampler16i *albedoimg[2], ImageSampler16u *newQCimage,float64 ulc[2],float64 lrc[2],int32 dimsizes[2])

//the pathname is the name of the file to write.
//the second and third parament is the image data to write.
//the ulc and lrc is the coner point coordinate which read from a MODIS file.
//the element of dimsizes is both 1200*1200

{
int fileID = 0, gridID = 0 , status = 0;
//define grid parameters
char gridName[] = "GLASS03_AB1_Albedo";
int32 Line = dimsizes[0], Sample = dimsizes[1];
int32 rank = 2;
int32 start[2] = {0,0}; int32 edges[2] = {Line,Sample};int32 stride[2] = {1,1};
//define the Projection Parameters
int32 projcode = 16;
int32 zonecode = -1;
int32 spherecode = -1;
float64 projparam[16] = {6371007.1809999999,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
char outputname[512];
strcpy(outputname,pathname);
//define data field Parameters
char Band1[] = "Albedo_BSA_shortwave";
char Band2[] = "Albedo_WSA_shortwave";
char Band3[] = "QA";
char dimName[] = "YDim,XDim";
int compparm[] ={5};
int fillvalue = -1;
//Create HDF-EOS File
fileID = GDopen(outputname,DFACC_CREATE);
if (fileID == -1)
{
printf("Create HDFEOS Failed!\n");
return 4;
}
// GDclose(fileID);
//Create grid field
// fileID = GDopen(outputname,DFACC_RDWR);
if (fileID == -1)
{
printf("Attach HDFEOS Failed!\n");
return 4;
}
gridID = GDcreate(fileID,gridName,Line,Sample,ulc,lrc);
if(gridID == -1)
{
printf("Create Albedo Grid Failed\n");
return 4;
}
status = GDdefproj(gridID,projcode,zonecode,spherecode,proj param);
if(status != 0 )
printf("error in projection define!\n");
GDdetach(gridID);
//Create data field BSA
gridID = GDattach(fileID,gridName);
if(gridID == -1)
{
printf("Attach HDF Grid failed\n");
return 4;
}
status = GDdeforigin(gridID,HDFE_GD_UL);
// status = GDdefcomp(gridID,HDFE_COMP_RLE,NULL);
status = GDdeffield(gridID,Band1,dimName,DFNT_INT16,HDFE_NO MERGE);
if(status != 0)
{
printf("error in data field defining!\n");
return 4;
}
status = GDsetfillvalue(gridID,Band1,&fillvalue);
status = GDsettilecomp(gridID,Band1,rank,dimsizes,HDFE_COMP _DEFLATE,compparm);
// GDdetach(gridID);
// GDclose(fileID);
//Write data field BSA
// fileID = GDopen(outputname,DFACC_RDWR);
// gridID = GDattach(fileID,gridName);
status = GDwritefield(gridID,Band1,start,stride,edges,albed oimg[0]->pimg);
if(status != 0)
{
printf("%d %s\n",gridID,Band1);
printf("error in data field1 writing!\n");
return 4;
}
GDdetach(gridID);
//Create data field WSA
gridID = GDattach(fileID,gridName);
if(gridID == -1)
{
printf("Attach HDF Grid failed\n");
return 4;
}
// status = GDdefcomp(gridID,HDFE_COMP_RLE,NULL);
status = GDdeforigin(gridID,HDFE_GD_UL);
status = GDdeffield(gridID,Band2,dimName,DFNT_INT16,HDFE_NO MERGE);
if(status != 0)
{
printf("error in data field defining!\n");
return 4;
}
status = GDsetfillvalue(gridID,Band2,&fillvalue);
status = GDsettilecomp(gridID,Band2,rank,dimsizes,HDFE_COMP _DEFLATE,compparm);
// GDdetach(gridID);
//Write data field WSA
// gridID = GDattach(fileID,gridName);
status = GDwritefield(gridID,Band2,start,stride,edges,albed oimg[1]->pimg);
if(status != 0)
{
printf("error in data field2 writing!\n");
return 4;
}
GDdetach(gridID);
//Create data field QC
gridID = GDattach(fileID,gridName);
if(gridID == -1)
{
printf("Attach HDF Grid failed\n");
return 4;
}
status = GDdeforigin(gridID,HDFE_GD_UL);
// status = GDdefcomp(gridID,HDFE_COMP_RLE,NULL);
status = GDdeffield(gridID,Band3,dimName,DFNT_UINT16,HDFE_N OMERGE);
if(status != 0)
{
printf("error in data field defining!\n");
return 4;
}
int fillvalue2 = 39171;
status = GDsetfillvalue(gridID,Band3,&fillvalue2);
status = GDsettilecomp(gridID,Band3,rank,dimsizes,HDFE_COMP _DEFLATE,compparm);
// GDdetach(gridID);
//Write data field QC
// gridID = GDattach(fileID,gridName);
status = GDwritefield(gridID,Band3,start,stride,edges,newQC image->pimg);
if(status != 0)
{
printf("error in data field3 writing!\n");
return 4;
}
GDdetach(gridID);
GDclose(fileID);
return status;
}

How can I solve this problem?
Reply With Quote
  #2  
Old 03-09-2011, 11:40 AM
kyang kyang is offline
Member
 
Join Date: Nov 2009
Posts: 38
Default

Abe,

Is this something you can help with?
Hi wlz,

Have you checked if you can generate a fake file following the parameters at
ftp://ftp.hdfgroup.uiuc.edu/pub/outg...7272184810.hdf

You can use HDFView to check the projection parameters. It is inside a file attribute called StructMetadata.

If your fake file cannot be read by ENVI, could you check if it can be opened by IDL. As I said, we have IDL/NCL/MATLAB examples to visualize the file
http://hdfeos.org/zoo/index_openLPDAAC_Examples.php
Reply With Quote
  #3  
Old 03-09-2011, 12:27 PM
ataaheri ataaheri is offline
Member
 
Join Date: Jun 2003
Posts: 30
Default

If you have put correct ulc and lrc values (in meters) for this Sinusoidal grid, I do not see anyreason for not having an acceptable grid (please not that your have chosen center meridian as 0). Please send me your hdf-eos file so that I check to see what is missing that MRT has problem. Perhaps it will fail also with our HEG software.
My email address is : abe_taaheri@raytheon.com
if your file is too big you can put it in our anonymous ftp site edhs1.gsfc.nasa.gov under pub directory, so that I grab it from there.
Reply With Quote
Reply

Tags
coordinate, hdf-eos, modis, projection

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:05 AM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
About Us | Contact Info | Archive Info | Disclaimer
Sponsored by NASA Cooperative Agreement Grant Number NNX08AO77A / Maintained by The HDF Group