Ejemplo n.º 1
0
int main() {
  char filename[] = "test.he4";
  int fid = SWopen(filename, DFACC_CREATE);
  char swathname[] = "myswath";
  int swid = SWcreate(fid, swathname);

  char dimname[] = "mydim";
  const int32 dimlen = 10;
  int rc = SWdefdim(swid, dimname, dimlen);
  printf("SWdefdim: %d\n", rc);
  char fieldname[] = "test_field";
  rc = SWdefdatafield(swid, fieldname, dimname, DFNT_FLOAT, 0);
  printf("SWdefdatafield: %d\n", rc);

  int32 start = 0;
  int32 edge = dimlen;
  float data[dimlen];
  for (int i=0; i<dimlen; ++i) {
    data[i] = 1.0 + i;
  }
  rc = SWwritefield(swid, fieldname, &start, NULL, &edge, data);
  printf("SWwritefield: %d\n", rc);

  rc = SWdetach(swid);
  printf("SWdetach: %d\n", rc);
  rc = SWclose(fid);
  printf("SWclose: %d\n", rc);
}
Ejemplo n.º 2
0
intn 
write_field_1d(int32 swid, char* field_name, int geo, int size, char* dim_name)
{
    int dim = 0;

    intn status = 0;

    float val = 0.0;
    float* var = NULL;
    
    int32 start[1];
    int32 count[1];

    start[0] = 0;
    count[0] = size;

    var = (float*) malloc(size * sizeof(float));
    if(var == NULL){
        fprintf(stderr, "Out of Memory\n");
        return FAIL;
    }

    while(dim < size) {
        var[dim] = val;
        val = val + 1.0;
        dim++;
    }

    if(1 == geo)
        SWdefgeofield(swid, field_name, dim_name,
                                 DFNT_FLOAT32, HDFE_NOMERGE);
    if(0 == geo)
        SWdefdatafield(swid, field_name, dim_name, 
                                  DFNT_FLOAT32, HDFE_NOMERGE);
    status = SWwritefield(swid, field_name, start, NULL, count, var);
    if(status == -1){
        fprintf(stderr, "SWwritefield() failed.\n");
	return -1;        
    }

    if(var != NULL)
        free(var);

    return status;

}
Ejemplo n.º 3
0
intn write_field_2d(int32 swid, char* field_name, int geo, int xdim, int ydim, char* dim_name)
{
    int i = 0;
    intn status = 0;

    float32 *temp = (float32*)malloc(xdim*ydim*sizeof(float32));

    int32 edge[2];
    int32 start[2];

    /* Fill data. */
    for(i=0; i<xdim*ydim; i++)
	temp[i] = i+1;

    start[0] = 0; 
    start[1] = 0;
    edge[0] = xdim; /* latitude-ydim first */ 
    edge[1] = ydim;

    /* Create a field. */
    if(geo == 1)
        SWdefgeofield(swid, field_name, dim_name, DFNT_FLOAT32, 0); 
    else
        SWdefdatafield(swid, field_name, dim_name, DFNT_FLOAT32, 0); 

    /* status = SWwritefield(swid, field_name, start, NULL, edge, temp); */
    status = SWwritefield(swid, field_name, NULL, NULL, NULL, temp); 
    if(status == -1){
        fprintf(stderr, "SWwritefield() failed.\n");
	return -1;        
    }
    /* In HDFEOS2, you can't write attribute on the individual field. */

    if(temp != NULL)
	free(temp);

    return status;
}
Ejemplo n.º 4
0
intn write_field_3d(int32 swid, char *field_name, char *dim_name)
{
    int i = 0;
    int j = 0;
    int k = 0;
    intn status = 0;

    float32 temp[4][4][8];          /* longitude-xdim first. */

    int32 edge[3];
    int32 start[3];

    /* Fill data. */
    for (k=0; k<4; k++)
    	for (i=0; i<4; i++)
            for (j=0; j<8; j++)
            	temp[k][i][j] = (float32)(10 + i + j);

    start[0] = 0;
    start[1] = 0;
    start[2] = 0;
    edge[0] = 4; /* latitude-ydim first */
    edge[1] = 4;
    edge[2] = 8;

    SWdefdatafield(swid, field_name, dim_name, DFNT_FLOAT32, 0);

    /* status = SWwritefield(swid, field_name, start, NULL, edge, temp); */
    status = SWwritefield(swid, field_name, NULL, NULL, NULL, temp);
    if(status == -1){
        fprintf(stderr, "SWwritefield() failed.\n");
        return -1;
    }
    /* In HDFEOS2, you can't write attribute on the individual field. */

    return status;
}