X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 20 Nov 2007 05:36 PM by  anon
Writing to HDF-EOS files in ENVI4.3
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
20 Nov 2007 05:36 PM
    Hi, I have been trying to modify a geofield in a MODIS HDF-EOS file with the following code: (infile is a string with the location of the .hdf) nswath = eos_sw_inqswath(infile, swath_list) swath_name = strsplit(swath_list, ',', /extract) fid = eos_sw_open(infile, /rdwr) swath_id = eos_sw_attach(fid, swath_name[0]) geofield_count = eos_sw_inqgeofields(swath_id, geofield_list, geofield_ranks, geofield_types) geofield_names = strsplit(geofield_list, ',', /extract) name=geofield_names[0] print,name result = eos_sw_detach(swath_id) swath_id = eos_sw_attach(fid, swath_name[0]) status = EOS_SW_DEFDIM(swath_id, "GeoTrack", 2000) status = EOS_SW_DEFDIM(swath_id, "GeoXTrack", 2200) status = EOS_SW_WRITEGEOMETA(swath_id,name, "GeoTrack,GeoXtrack", 5) print,status result = eos_sw_detach(swath_id) swath_id = eos_sw_attach(fid, swath_name[0]) geofield_count = eos_sw_inqgeofields(swath_id, geofield_list, geofield_ranks, geofield_types) print,geofield_list result=eos_sw_close(fid) However, I am having a bit of a problem. Rather than overwriting the previous geofield the EOS_SW_WRITEGEOMETA command seems to be creating an entirely new one with the same name. I compared geofield_list pre- and post- calling this command and before I have this output: Latitude, Longitude After calling eos_sw_writegeometa I get this: Latitude, Longitude, Latitude Could someone point me in the direction of what I've done wrong here? I'm guessing I have overlooked something simple! I'm also not sure about the detach and attach commands, I've tried various combinations of positions and numbers of calls, but they don't seem to make much difference. I've left them in the above code, though. Thanks, Simon.

    Deleted User



    New Member


    Posts:
    New Member


    --
    20 Nov 2007 05:36 PM
    I have never worked with the EOS_SW_... routines in ENVI+IDL programming, but I can share this general knowledge of the rules of HDF version 4: The NCSA writing functions for this file format are not designed to facilitate modification of datasets. For example, the only types of modification that are allowed for "SD datasets" are a change of the values and the change of a narrow set of metadata fields: data range (to match your new data values) and several kind of string labels. If you would want to change datatype, however, or the type or size of your array, then your only options would be to append your new data to the old file (as you have done above) or to create a new HDF file from scratch (copying over from the old HDF file entities that you wanted to keep, replacing others with newly created datasets). If all you are doing is modifying data values, and not data type or data size, and the ENVI EOS_SW_... library does not appear to have data modification routines, but the data slab in the target file ***is*** SD data, then the following IDL routines might help you: sd_id = hdf_sd_start('/path/to/my_eos_data.hdf', /RDWR) ; NOTE: I am making some wild assuptions here about what your 'swath_name' holds sds_id = hdf_sd_select(sd_id, hdf_sd_nametoindex(swath_name[0])) ; The next line only works if 'myNewData' has the same size and type as the old data hdf_sd_adddata, sds_id, myNewData hdf_sd_setnfo, RANGE=[max(mydata, MIN=mydataMin), mydataMin] hdf_sd_endaccess, sds_id hdf_sd_end, sd_id So that is your one option. I see now that there is a thread going on in the IDL forum on this and that you ***do*** want to change data array size. That is not possible, and I am 99.9% sure that that is a restriction of the underlying HDF 4 library. HDF 5 makes specific provisions for allowing programmers to expand a dataset's size (though they are not allowed to delete or contract, even in HDF 5), and IDL has implemented that functionality. But that would not help you if MODIS HDF-EOS files are HDF4-formatted. James Jones ITT Technical Support
    You are not authorized to post a reply.