void tcpip_init(void) { net_mutex = thinkos_mutex_alloc(); assert(net_mutex > 0); tcpip_net_lock(); DCC_LOG1(LOG_TRACE, "net_mutex=%d", net_mutex); mbuf_init(); pktbuf_pool_init(); #if (ENABLE_NET_RAW) raw_init(); #endif #if (ENABLE_NET_UDP) udp_init(); #endif #if (ENABLE_NET_TCP) tcp_init(); #endif ifnet_init(); tcpip_net_unlock(); }
int main (int arguments, char *argument[]) { unsigned long int size; unsigned long int counter; fd_set sockets; struct timeval timeout; char *lines; unsigned long int temp; unsigned long int bytes = 0; raw_socket = raw_init (ETHNAME); while (1) { FD_ZERO (&sockets); FD_SET (raw_socket, &sockets); timeout.tv_sec = 1; timeout.tv_usec = 0; select (raw_socket + 1, &sockets, NULL, NULL, &timeout); if (FD_ISSET (raw_socket, &sockets)) { raw_parse (raw_socket, buffer); } } }
RAW_RGB bmp_to_raw (BMP_FILE p) { DWORD i, j, row_size, height; RAW_RGB r = raw_init(); BMP_INFO pi; BYTE l; if (!r) { fprintf (stderr, "bmp_to_raw: init failed\n"); return NULL; } if (!p || !p->header || !p->info || !p->data) { fprintf (stderr, "bmp_to_raw: no BMP present\n"); return NULL; } pi = p->info; r->x_min = r->y_min = 0; r->x_max = pi->width - 1; height = abs(pi->height); r->y_max = height - 1; if (!(r->data = (BYTE**)malloc(abs(pi->height) * sizeof(BYTE*)))) { fprintf (stderr, "bmp_to_raw: failed allocating raw data array\n"); return NULL; } row_size = ((pi->bits_per_pixel * pi->width + 31) / 32) * 4; if (pi->height > 0 && pi->compression == 0) { for (i = 0; i < height; i++) { if (!(r->data[i] = (BYTE*)malloc(3 * pi->width))) { fprintf (stderr, "bmp_to_raw: failed allocating %d bytes on %d step\n", 3 * pi->width, i); return NULL; } for (j = 0; j < 3 * pi->width; j += 3) for (l = 0; l < 3; l++) r->data[i][j + l] = p->data[(height - i - 1) * row_size + j + 2 - l]; } } else if (pi->height < 0 && pi->compression == 0) { for (i = 0; i < height; i++) { if (!(r->data[i] = (BYTE*)malloc(3 * pi->width))) { fprintf (stderr, "bmp_to_raw: failed allocating %d bytes on %d step\n", 3 * pi->width, i); return NULL; } for (j = 0; j < 3 * pi->width; j += 3) for (l = 0; l < 3; l++) r->data[i][j + l] = p->data[i * row_size + j + 2 - l]; } } else { fprintf (stderr, "bmp_to_raw: unsupported file type\n"); return NULL; } verbose printf ("bmp_to_raw: RAW_RGB created\n"); return r; }
/** * Perform Sanity check of user-configurable values, and initialize all modules. */ void lwip_init(void) { /* Sanity check user-configurable values */ lwip_sanity_check(); /* Modules initialization */ stats_init(); #if !NO_SYS sys_init(); #endif /* !NO_SYS */ mem_init(); memp_init(); pbuf_init(); netif_init(); #if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ #if !NO_SYS /* in the Xilinx lwIP 1.2.0 port, lwip_init() was added as a convenience utility function to initialize all the lwIP layers. lwIP 1.3.0 introduced lwip_init() in the base lwIP itself. However a user cannot use lwip_init() regardless of whether it is raw or socket modes. The following call to lwip_sock_init() is made to make sure that lwIP is properly initialized in both raw & socket modes with just a call to lwip_init(). */ lwip_sock_init(); #endif }
/** * Perform Sanity check of user-configurable values, and initialize all modules. */ void lwip_init(void) { /*++ Changed by Espressif ++*/ MEMP_NUM_TCP_PCB = 5; TCP_WND = (4 * TCP_MSS); TCP_MAXRTX = 3; TCP_SYNMAXRTX = 6; /*-- --*/ /* Modules initialization */ stats_init(); #if !NO_SYS sys_init(); #endif /* !NO_SYS */ /*++ Changed by Espressif ++*/ #if 0 mem_init(&_bss_end); #endif /*-- --*/ memp_init(); pbuf_init(); netif_init(); #if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ }
/** * Perform Sanity check of user-configurable values, and initialize all modules. */ void lwip_init(void) { esp_ms_timer_init(); // espressif /* Modules initialization */ stats_init(); #if !NO_SYS sys_init(); #endif /* !NO_SYS */ mem_init(); memp_init(); pbuf_init(); netif_init(); #if LWIP_IPV4 ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #endif /* LWIP_IPV4 */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ #if LWIP_IPV6 ip6_init(); nd6_init(); #if LWIP_IPV6_MLD mld6_init(); #endif /* LWIP_IPV6_MLD */ #endif /* LWIP_IPV6 */ #if PPP_SUPPORT ppp_init(); #endif #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ }
/** * Perform Sanity check of user-configurable values, and initialize all modules. */ void ICACHE_FLASH_ATTR lwip_init(void) { /* Modules initialization */ stats_init(); #if !NO_SYS sys_init(); #endif /* !NO_SYS */ mem_init(); memp_init(); pbuf_init(); netif_init(); #if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ #if LWIP_IPV6 ip6_init(); nd6_init(); #if LWIP_IPV6_MLD mld6_init(); #endif /* LWIP_IPV6_MLD */ #endif /* LWIP_IPV6 */ #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ }
/** * Perform Sanity check of user-configurable values, and initialize all modules. */ void lwip_init(void) { /* Sanity check user-configurable values */ lwip_sanity_check(); /* Modules initialization */ stats_init(); #if !NO_SYS sys_init(); #endif /* !NO_SYS */ mem_init(); memp_init(); pbuf_init(); netif_init(); #if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ }
/** * Perform Sanity check of user-configurable values, and initialize all modules. */ void lwip_init(void) { lwip_init_globals(); /* Sanity check user-configurable values */ lwip_sanity_check(); /* Modules initialization */ stats_init(); sys_init(); mem_init(); memp_init(); pbuf_init(); netif_init(); #if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP /* Initialize the network stack */ // [MS_CHANGE] - tcpip_init() is a no-op. This method actually initializes the tcpip stack. tcpip_init(NULL,NULL); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ }
int __init chr_dev_init(void) { if (devfs_register_chrdev(MEM_MAJOR,"mem",&memory_fops)) printk("unable to get major %d for memory devs\n", MEM_MAJOR); memory_devfs_register(); rand_initialize(); raw_init(); #ifdef CONFIG_I2C i2c_init_all(); #endif #if defined (CONFIG_FB) fbmem_init(); #endif #if defined (CONFIG_PROM_CONSOLE) prom_con_init(); #endif #if defined (CONFIG_MDA_CONSOLE) mda_console_init(); #endif tty_init(); #ifdef CONFIG_PRINTER lp_init(); #endif #ifdef CONFIG_M68K_PRINTER lp_m68k_init(); #endif misc_init(); #if CONFIG_QIC02_TAPE qic02_tape_init(); #endif #if CONFIG_ISDN isdn_init(); #endif #ifdef CONFIG_FTAPE ftape_init(); #endif #if defined(CONFIG_ADB) adbdev_init(); #endif #ifdef CONFIG_VIDEO_DEV videodev_init(); #endif return 0; }
/************************************************************************** * atct_init_from_leader: * calculates alpha1, alpha2, and alpha3, which are some sort of coordinate * rotation amounts, in degrees. This creates a latitude/longitude-style * coordinate system centered under the satellite at the start of imaging. * Rather than using a passed-in state vector, the initial state vector is * read from the leader file. */ void atct_init_from_leader(const char *leaderName, meta_projection *proj) { struct dataset_sum_rec *dssr = NULL; meta_parameters *meta = raw_init(); stateVector st_start; ceos_description *ceos = get_ceos_description_ext(leaderName, REPORT_LEVEL_NONE, FALSE); // Azimuth time per pixel need to be known for state vector propagation dssr = &ceos->dssr; ceos_init_sar_general(ceos, leaderName, meta, TRUE); ceos_read_stVecs(leaderName, ceos, meta); st_start = meta_get_stVec(meta, 0.0); fixed2gei(&st_start,0.0);/* Remove earth's spin JPL's AT/CT projection requires this */ atct_init(proj, st_start); meta_free(meta); }
/*********************************************************** * meta_create: * Constructs a new meta_parameters record from CEOS, ARDOP * inputs, etc-- whatever it can find.*/ meta_parameters *meta_create(const char *fName) { meta_parameters *meta = raw_init(); //int success=FALSE; char **junk=NULL; int junk2; if (require_ceos_metadata(fName,&junk,&junk2) != NO_CEOS_METADATA) { ceos_init(fName, meta, REPORT_LEVEL_STATUS); //success=TRUE; FREE(junk[0]); FREE(junk[1]); FREE(junk); } if (extExists(fName,".in")) { ardop_init(fName,meta); //success=TRUE; } //if (success) meta_new2old(meta); return meta; }
RAW *ben_enc(BEN * node) { RAW *raw = raw_init(); /* Calculate size of ben data */ raw->size = ben_enc_size(node); if (raw->size <= 0) { raw_free(raw); return NULL; } /* Encode ben object */ raw->code = (UCHAR *) myalloc(raw->size * sizeof(UCHAR)); raw->p = ben_enc_rec(node, raw->code); if (raw->p == NULL || (LONG) (raw->p - raw->code) != raw->size) { raw_free(raw); return NULL; } return raw; }
// for brs, combined the "open_meta" and "open_data" functions -- both // will be opening the same file. meta_parameters* open_brs(const char *data_name, ClientInterface *client) { ReadBrsClientInfo *info = MALLOC(sizeof(ReadBrsClientInfo)); info->fp = FOPEN(data_name, "rb"); client->read_client_info = info; client->read_fn = read_brs_client; client->thumb_fn = NULL; client->free_fn = free_brs_client_info; client->require_full_load = TRUE; client->data_type = GREYSCALE_BYTE; meta_parameters *meta = raw_init(); // 700x700 size is hard-coded... I think this is ok int fs = fileSize(data_name); meta->general->line_count = 600; meta->general->sample_count = fs/meta->general->line_count; meta->general->band_count = 1; strcpy(meta->general->bands, ""); return meta; }
/*************************************************************** * meta_read: * Reads a meta file and returns a meta structure filled with * both old backward compatability and new fields filled in. * Note that the appropriate extension is appended to the given * base name automagically if needed. */ meta_parameters *meta_read(const char *inName) { char *meta_name = appendExt(inName,".meta"); char *ddr_name = appendExt(inName,".ddr"); meta_parameters *meta = raw_init(); /* Allocate and initialize basic structs */ char **junk=NULL; int junk2, ii; /* Read file with appropriate reader for version. */ if ( !fileExists(meta_name) && fileExists(ddr_name)) { meta_read_only_ddr(meta, ddr_name); /* printf("WARNING: * Unable to locate '%s';\n" " * Using only '%s' for meta data;\n" " * Errors due to lack of meta data are very likely.\n", meta_name, ddr_name);*/ } else if ( fileExists(meta_name) ) { if ( !meta_is_new_style(meta_name) ) { meta_read_old(meta, meta_name); } else { parse_metadata(meta, meta_name); } } // Generate metadata if CEOS files could be detected else if (require_ceos_metadata(inName,&junk,&junk2) != NO_CEOS_METADATA) { ceos_init(inName, meta, REPORT_LEVEL_STATUS); } /* Remember the name and location of the meta struct */ //add_meta_ddr_struct(inName, meta, NULL); // Add latlon block if data has a data has lat/lon bands // Currently only SMAP data has that kind of arrangement int lat_band = get_band_num(meta->general->bands, meta->general->band_count, "LAT"); int lon_band = get_band_num(meta->general->bands, meta->general->band_count, "LON"); if (strcmp_case(meta->general->sensor, "SMAP") == 0 && lat_band > 0 && lon_band > 0) { char *data_name = appendExt(inName, ".img"); if (fileExists(data_name)) { meta->latlon = meta_latlon_init(meta->general->line_count, meta->general->sample_count); FILE *fp = FOPEN(data_name, "rb"); get_band_float_lines(fp, meta, lat_band, 0, meta->general->line_count, meta->latlon->lat); get_band_float_lines(fp, meta, lon_band, 0, meta->general->line_count, meta->latlon->lon); FCLOSE(fp); } FREE(data_name); } FREE(ddr_name); FREE(meta_name); free_ceos_names(NULL, junk); return meta; }
meta_parameters *iso2meta(iso_meta *iso) { int ii; meta_parameters *meta = raw_init(); char str[30]; // Convenience pointers iso_generalHeader *header = iso->generalHeader; iso_productComponents *comps = iso->productComponents; iso_productInfo *info = iso->productInfo; iso_productSpecific *spec = iso->productSpecific; iso_setup *setup = iso->setup; iso_processing *proc = iso->processing; iso_instrument *inst = iso->instrument; iso_platform *platform = iso->platform; iso_productQuality *quality = iso->productQuality; meta->meta_version = 3.5; // General block for (ii=0; ii<comps->numAnnotations; ii++) if (comps->annotation[ii].type == MAIN_TYPE) strncpy(meta->general->basename, comps->annotation[ii].file.name, 256); strcpy(meta->general->sensor, header->mission); strcpy(meta->general->sensor_name, info->sensor); strcpy(meta->general->mode, info->elevationBeamConfiguration); strcpy(meta->general->receiving_station, info->receivingStation); strcpy(meta->general->processor, header->generationSystem); if (info->imageDataType == DETECTED_DATA_TYPE && info->imageDataDepth == 8) meta->general->data_type = ASF_BYTE; else if (info->imageDataType == DETECTED_DATA_TYPE && info->imageDataDepth == 16) meta->general->data_type = INTEGER16; else if (info->imageDataType == DETECTED_DATA_TYPE && info->imageDataDepth == 32) // assumption here is that we are not dealing with INTERGER32 meta->general->data_type = REAL32; else if (info->imageDataType == DETECTED_DATA_TYPE && info->imageDataDepth == 64) meta->general->data_type = REAL64; else if (info->imageDataType == COMPLEX_DATA_TYPE && info->imageDataDepth == 8) meta->general->data_type = COMPLEX_BYTE; else if (info->imageDataType == COMPLEX_DATA_TYPE && info->imageDataDepth == 16) meta->general->data_type = COMPLEX_INTEGER16; else if (info->imageDataType == COMPLEX_DATA_TYPE && info->imageDataDepth == 32) // assumption here is that we are not dealing with COMPLEX_INTEGER32 meta->general->data_type = COMPLEX_REAL32; else if (info->imageDataType == COMPLEX_DATA_TYPE && info->imageDataDepth == 64) meta->general->data_type = COMPLEX_REAL64; if (info->imageDataType == RAW_DATA_TYPE) meta->general->image_data_type = RAW_IMAGE; else if (info->imageDataType == COMPLEX_DATA_TYPE) meta->general->image_data_type = COMPLEX_IMAGE; else if (info->imageDataType == DETECTED_DATA_TYPE) meta->general->image_data_type = AMPLITUDE_IMAGE; // more detailed mapping of imageDataType will probably need pixelValueID // context if (strcmp_case(info->pixelValueID, "RADAR BRIGHTNESS") == 0) meta->general->radiometry = r_AMP; // dealing with any form of calibration not implemented yet dateTime2str(info->sceneCenterCoord.azimuthTimeUTC, meta->general->acquisition_date); meta->general->orbit = info->absOrbit; if (info->orbitDirection == ASCENDING) meta->general->orbit_direction = 'A'; else if (info->orbitDirection == DESCENDING) meta->general->orbit_direction = 'D'; meta->general->frame = setup->frameID; meta->general->band_count = comps->numLayers; strcpy(meta->general->bands, polLayer2str(comps->imageData[0].polLayer)); for (ii=1; ii<comps->numLayers; ii++) { sprintf(str, ", %s", polLayer2str(comps->imageData[ii].polLayer)); strcat(meta->general->bands, str); } meta->general->line_count = info->numberOfRows; meta->general->sample_count = info->numberOfColumns; meta->general->start_line = info->startRow; meta->general->start_sample = info->startColumn; meta->general->x_pixel_size = info->groundRangeResolution; meta->general->y_pixel_size = info->azimuthResolution; meta->general->center_latitude = info->sceneCenterCoord.lat; meta->general->center_longitude = info->sceneCenterCoord.lon; spheroid_type_t spheroid = WGS84_SPHEROID; // FIXME: needs to know reference spheroid_axes_lengths(spheroid, &meta->general->re_major, &meta->general->re_minor); meta->general->bit_error_rate = quality->imageDataQuality[0].bitErrorRate; meta->general->missing_lines = quality->imageDataQuality[0].missingLines; meta->general->no_data = (float) quality->imageDataQuality[0].noData; // SAR block meta->sar = meta_sar_init(); if (info->projection == SLANTRANGE_PROJ) meta->sar->image_type = 'S'; else if (info->projection == GROUNDRANGE_PROJ) meta->sar->image_type = 'G'; else if (info->projection == MAP_PROJ) meta->sar->image_type = 'P'; if (setup->lookDirection == RIGHT_LOOK) meta->sar->look_direction = 'R'; else if (setup->lookDirection == LEFT_LOOK) meta->sar->look_direction = 'L'; meta->sar->azimuth_look_count = info->azimuthLooks; meta->sar->range_look_count = info->rangeLooks; if (spec->imageCoordinateType == RAW_COORD) meta->sar->deskewed = FALSE; else if (spec->imageCoordinateType == ZERODOPPLER) meta->sar->deskewed = TRUE; meta->general->line_scaling = info->rowScaling; meta->general->sample_scaling = info->columnScaling; meta->sar->range_time_per_pixel = info->columnSpacing; meta->sar->azimuth_time_per_pixel = info->rowSpacing; meta->sar->slant_shift = spec->slantRangeShift; //meta->sar->slant_range_first_pixel = info->rangeTimeFirstPixel * SPD_LIGHT; meta->sar->slant_range_first_pixel = spec->projectedSpacingSlantRange; meta->sar->wavelength = SPD_LIGHT / inst->centerFrequency; meta->sar->prf = spec->commonPRF; meta->sar->earth_radius = info->earthRadius; meta->sar->satellite_height = info->satelliteHeight; // meta->sar->satellite_binary_time; // meta->sar->satellite_clock_time; for (ii=0; ii<=proc->doppler[0].polynomialDegree; ii++) meta->sar->range_doppler_coefficients[ii] = proc->doppler[0].coefficient[ii]; meta->sar->azimuth_doppler_coefficients[0] = proc->doppler[0].coefficient[0]; // meta->sar->chirp_rate // meta->sar->pulse_duration meta->sar->range_sampling_rate = spec->commonRSF; if (info->polarizationMode == SINGLE_POL) strcpy(meta->sar->polarization, "SINGLE"); else if (info->polarizationMode == DUAL_POL) strcpy(meta->sar->polarization, "DUAL"); else if (info->polarizationMode == QUAD_POL) strcpy(meta->sar->polarization, "QUAD"); meta->sar->multilook = proc->multiLookedFlag; meta->sar->pitch = info->pitch; meta->sar->roll = info->roll; meta->sar->yaw = info->yaw; meta->sar->incid_a[0] = info->sceneCenterCoord.incidenceAngle; meta->sar->heading_angle = info->headingAngle; meta->sar->chirp_rate = proc->processingParameter[0].chirpRate; meta->sar->pulse_duration = proc->processingParameter[0].pulseDuration; // meta->projection // meta->transform // meta->airsar // meta->uavsar // meta->statistics int numVectors = platform->numStateVectors; meta->state_vectors = meta_state_vectors_init(numVectors); meta->state_vectors->vector_count = numVectors; ymd_date ymdStart, ymdSV; julian_date jd; hms_time hmsStart, hmsSV; ymdStart.year = info->startTimeUTC.year; ymdStart.month = info->startTimeUTC.month; ymdStart.day = info->startTimeUTC.day; hmsStart.hour = info->startTimeUTC.hour; hmsStart.min = info->startTimeUTC.min; hmsStart.sec = info->startTimeUTC.second; meta->state_vectors->year = info->startTimeUTC.year; date_ymd2jd(&ymdStart, &jd); meta->state_vectors->julDay = jd.jd; meta->state_vectors->second = date_hms2sec(&hmsStart); for (ii=0; ii<numVectors; ii++) { ymdSV.year = platform->stateVec[ii].timeUTC.year; ymdSV.month = platform->stateVec[ii].timeUTC.month; ymdSV.day = platform->stateVec[ii].timeUTC.day; hmsSV.hour = platform->stateVec[ii].timeUTC.hour; hmsSV.min = platform->stateVec[ii].timeUTC.min; hmsSV.sec = platform->stateVec[ii].timeUTC.second; meta->state_vectors->vecs[ii].time = time_difference(&ymdSV, &hmsSV, &ymdStart, &hmsStart); meta->state_vectors->vecs[ii].vec.pos.x = platform->stateVec[ii].posX; meta->state_vectors->vecs[ii].vec.pos.y = platform->stateVec[ii].posY; meta->state_vectors->vecs[ii].vec.pos.z = platform->stateVec[ii].posZ; meta->state_vectors->vecs[ii].vec.vel.x = platform->stateVec[ii].velX; meta->state_vectors->vecs[ii].vec.vel.y = platform->stateVec[ii].velY; meta->state_vectors->vecs[ii].vec.vel.z = platform->stateVec[ii].velZ; } if (meta->sar->azimuth_time_per_pixel > 0) meta->sar->time_shift = 0.0; else meta->sar->time_shift = meta->state_vectors->vecs[numVectors-1].time; if (meta->sar->yaw == 0 || !meta_is_valid_double(meta->sar->yaw)) { meta->sar->yaw = meta_yaw(meta, meta->general->line_count/2.0, meta->general->sample_count/2.0); } /* // few calculations need state vectors meta->sar->earth_radius = meta_get_earth_radius(meta, line_count/2, sample_count/2); // meta->sar->earth_radius_pp meta->sar->satellite_height = meta_get_sat_height(meta, meta->general->line_count/2, meta->general->sample_count/2); meta->sar->incid_a[0] = meta_incid(meta, line_count/2, sample_count/2)*R2D; */ // Location block meta_get_corner_coords(meta); /* meta->location = meta_location_init(); for (ii=0; ii<4; ii++) { if (info->sceneCornerCoord[ii].refRow == 0 && info->sceneCornerCoord[ii].refColumn == 0) { meta->location->lat_start_near_range = info->sceneCornerCoord[ii].lat; meta->location->lon_start_near_range = info->sceneCornerCoord[ii].lon; } else if (info->sceneCornerCoord[ii].refRow == 0 && info->sceneCornerCoord[ii].refColumn == sample_count) { meta->location->lat_start_far_range = info->sceneCornerCoord[ii].lat; meta->location->lon_start_far_range = info->sceneCornerCoord[ii].lon; } else if (info->sceneCornerCoord[ii].refRow == line_count && info->sceneCornerCoord[ii].refColumn == 0) { meta->location->lat_end_near_range = info->sceneCornerCoord[ii].lat; meta->location->lon_end_near_range = info->sceneCornerCoord[ii].lon; } else if (info->sceneCornerCoord[ii].refRow == line_count && info->sceneCornerCoord[ii].refColumn == sample_count) { meta->location->lat_end_far_range = info->sceneCornerCoord[ii].lat; meta->location->lon_end_far_range = info->sceneCornerCoord[ii].lon; } } */ return meta; }
void k_loop(struct k_capture *p_capture, k_handler calback) { struct k_header head; struct dev_time *dt; int len, start = 1; u_char buf[BUFSIZ]; char *old_interface; head.dt = NULL; old_interface = NULL; // while(!connect(p_capture->socket,(struct sockaddr_ll*) &p_capture->sll, sizeof(p_capture->sll))){ while (1) { dt = NULL; if (start) { if ((old_interface = (char *) malloc(sizeof(char) * strlen("-") + sizeof(char))) == NULL) { fprintf(stderr, "k_loop: Error malloc old_interface: %s",strerror(errno)); exit(1); } strcpy(old_interface, "-"); if ((dt = (struct dev_time *) malloc(sizeof(struct dev_time))) == NULL) { fprintf(stderr,"k_loop(): Error malloc struct dev_time: %s",strerror(errno)); exit(1); } gettimeofday(&dt->ts, NULL); if (p_capture->name) { if ((dt->name_do = (char *) malloc(strlen(p_capture->name) * sizeof(char))) == NULL) { fprintf(stderr, "k_loop(): Error malloc dt->name: %s", strerror(errno)); exit(1); } strcpy(dt->name_do, p_capture->name); } else { if ((dt->name_do = (char *) malloc(strlen("unknown") * sizeof(char) + sizeof(char))) == NULL) { fprintf(stderr, "k_loop(): Error malloc dt->name: %s", strerror(errno)); exit(1); } strcpy(dt->name_do, "unknown"); } if ((dt->name_z = (char *) malloc(strlen(old_interface) * sizeof(char))) == NULL) { fprintf(stderr, "k_loop(): Error malloc old_interface: %s", strerror(errno)); exit(1); } strcpy(dt->name_z, old_interface); start = 0; } // if interface is down, find new interface and create new socket if (p_capture->interface_auto) { /* * if((p_capture->file_status == NULL) || (!get_status(p_capture->file_status))){ * if(*p_capture->file_status){ * free(p_capture->file_status); * p_capture->file_status = NULL; } */ if (!get_status(p_capture)) { if (p_capture->name != NULL) { if (old_interface != NULL) { free(old_interface); old_interface = NULL; } if ((old_interface = (char *) malloc(strlen(p_capture->name) * sizeof(char))) == NULL) { fprintf(stderr,"k_loop(): Error malloc old_interface: %s", strerror(errno)); exit(1); } strcpy(old_interface, p_capture->name); } if (p_capture->name && p_capture->socket) close_promisc(p_capture->socket, p_capture->name); if (p_capture->name) { free(p_capture->name); p_capture->name = NULL; } //return interface to old state //if(ioctl(p_capture->socket,SIOCSIFFLAGS, &p_capture->old_status) == -1){ //fprintf(stderr, "Error, set old state in k_loop(): %s\n",strerror(errno)); //} if (p_capture->socket) { close(p_capture->socket); p_capture->socket = 0; } if (raw_init(p_capture, "auto")) { sleep(2); continue; } if ((dt = (struct dev_time *) malloc(sizeof(struct dev_time))) == NULL) { fprintf(stderr,"k_loop(): Error malloc struct dev_time: %s", strerror(errno)); exit(1); } gettimeofday(&dt->ts, NULL); if ((dt->name_do = (char *) malloc(strlen(p_capture->name) * sizeof(char))) == NULL) { fprintf(stderr, "k_loop(): Error malloc dt->name: %s", strerror(errno)); exit(1); } strcpy(dt->name_do, p_capture->name); if ((dt->name_z = (char *) malloc(strlen(old_interface) * sizeof(char))) == NULL) { fprintf(stderr, "k_loop(): Error malloc old_interface: %s", strerror(errno)); exit(1); } strcpy(dt->name_z, old_interface); } } // fprintf(stderr,"Rozhranie: %s\n",p_capture->file_status); len = recvfrom(p_capture->socket, buf, sizeof(buf), 0, NULL, NULL); if (len <= 0) { fprintf(stderr, "Warring recv packet. %s\n", strerror(errno)); continue; } gettimeofday(&head.ts, NULL); head.len = len; head.interface_auto = p_capture->interface_auto; if (p_capture->interface_auto && (head.dt == NULL)) head.dt = dt; // printf("Len: %d\n", len); //fprintf(stderr,"proto: %d\n",p_capture->sll.sll_protocol); calback(&head, (u_char *) & buf); if (head.dt != NULL) { if (head.dt->name_z != NULL) { free(head.dt->name_z); head.dt->name_z = NULL; } if (head.dt->name_do) { free(head.dt->name_do); head.dt->name_do = NULL; } free(head.dt); head.dt = NULL; } } }
static void remaining_lwip_initialization(char *card_name, uint64_t queueid) { nb = netbench_alloc("app", RECORDED_EVENTS_COUNT); //asq: connect to the NIC driver, before doing anything else idc_connect_to_driver(card_name, queueid); DEBUGPRINTPS("Connected to driver [%s]\n", card_name); stats_init(); sys_init(); DEBUGPRINTPS("remaining_lwip_init: allocating pbuf memory\n"); #ifdef CONFIG_QEMU_NETWORK printf("#### Networking with small amount of memory #####\n"); #endif // CONFIG_QEMU_NETWORK printf("#### [%u:%"PRIuDOMAINID":%s] [%s] [%d] MEM_SIZE[%d], " "PBUF_POOL_SIZE[%d], MEMP_MAX[%d], RECEIVE_BUFFERS[%d] qid[%"PRIu64"]####\n", disp_get_core_id(), disp_get_domain_id(), disp_name(), MEM_CONF_LOC, is_ctl, MEM_SIZE, PBUF_POOL_SIZE, MEMP_MAX, RECEIVE_BUFFERS, queueid); memp_init(); // 0'st buffer DEBUGPRINTPS("remaining_lwip_init: allocating memory for sending\n"); mem_init(); // 1'th buffer DEBUGPRINTPS("remaining_lwip_init: done with memroy allocation\n"); DEBUGPRINTPS("LWIP: lwip_starting\n"); netif_init(); #if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); DEBUGPRINTPS("r_lwip_init: done ip_init\n"); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); DEBUGPRINTPS("r_lwip_init: done udp_init\n"); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); DEBUGPRINTPS("r_lwip_init: done tcp_init\n"); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); DEBUGPRINTPS("r_lwip_init: done snmp_init\n"); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); DEBUGPRINTPS("r_lwip_init: done autoip_init\n"); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); DEBUGPRINTPS("r_lwip_init: done igmp_init\n"); #endif /* LWIP_IGMP */ DEBUGPRINTPS("r_lwip_init: done2 igmp_init\n"); #if LWIP_DNS DEBUGPRINTPS("r_lwip_init: starting DNS_init\n"); dns_init(); DEBUGPRINTPS("r_lwip_init: done DNS_init\n"); #endif /* LWIP_DNS */ DEBUGPRINTPS("LWIP: lwip_started\n"); }
meta_parameters* uavsar_insar2meta(uavsar_insar *params) { meta_parameters *meta; // Allocate memory for metadata structure meta = raw_init(); // General block sprintf(meta->general->basename, "%s", params->site); sprintf(meta->general->sensor, "UAVSAR"); strcpy(meta->general->sensor_name, "InSAR"); strcpy(meta->general->processor, "JPL version "); strcat(meta->general->processor, params->processor); if (params->type == INSAR_AMP || params->type == INSAR_AMP_GRD) { if (params->type == INSAR_AMP) strcpy(meta->general->mode, "AMP"); else if (params->type == INSAR_AMP_GRD) strcpy(meta->general->mode, "AMP_GRD"); meta->general->image_data_type = AMPLITUDE_IMAGE; } else if (params->type == INSAR_INT || params->type == INSAR_INT_GRD) { if (params->type == INSAR_INT) strcpy(meta->general->mode, "INT"); else if (params->type == INSAR_INT_GRD) strcpy(meta->general->mode, "INT_GRD"); meta->general->image_data_type = INTERFEROGRAM; } else if (params->type == INSAR_UNW || params->type == INSAR_UNW_GRD) { if (params->type == INSAR_UNW) strcpy(meta->general->mode, "UNW"); else if (params->type == INSAR_UNW_GRD) strcpy(meta->general->mode, "UNW_GRD"); meta->general->image_data_type = UNWRAPPED_PHASE; } else if (params->type == INSAR_COR || params->type == INSAR_COR_GRD) { if (params->type == INSAR_COR) strcpy(meta->general->mode, "COR"); else if (params->type == INSAR_COR_GRD) strcpy(meta->general->mode, "COR_GRD"); meta->general->image_data_type = COHERENCE_IMAGE; } else if (params->type == INSAR_HGT_GRD) { strcpy(meta->general->mode, "HGT_GRD"); meta->general->image_data_type = DEM; } else strcpy(meta->general->mode, "unknown"); meta->general->data_type = REAL32; strcpy(meta->general->acquisition_date, params->acquisition_date); meta->general->band_count = 1; meta->general->line_count = params->row_count; meta->general->sample_count = params->column_count; meta->general->start_line = 0; meta->general->start_sample = 0; meta->general->x_pixel_size = params->range_pixel_spacing; meta->general->y_pixel_size = fabs(params->azimuth_pixel_spacing); meta->general->re_major = params->semi_major; double a = params->semi_major; double ecc2 = params->eccentricity; meta->general->re_minor = sqrt((1-ecc2)*a*a); // no information on bit error rate, missing lines and no data // SAR block meta->sar = meta_sar_init(); strcpy(meta->sar->polarization, params->polarization); if (strcmp_case(params->projection, "SCX") == 0) meta->sar->image_type = 'S'; else if (strcmp_case(params->projection, "EQA") == 0) meta->sar->image_type = 'P'; if (strcmp_case(params->look_direction, "Left") == 0) meta->sar->look_direction = 'L'; else if (strcmp_case(params->look_direction, "Right") == 0) meta->sar->look_direction = 'R'; meta->sar->azimuth_look_count = params->azimuth_look_count; meta->sar->range_look_count = params->range_look_count; meta->sar->multilook = 1; meta->sar->deskewed = 1; meta->sar->original_line_count = params->row_count; meta->sar->original_sample_count = params->column_count; meta->sar->line_increment = 1; meta->sar->sample_increment = 1; // no information on azimuth and range time per pixel meta->sar->time_shift = 0.0; meta->sar->slant_shift = 0.0; meta->sar->slant_range_first_pixel = params->slant_range_first_pixel * 1000.0; meta->sar->wavelength = params->wavelength / 100.0; // no information on pulse repetition frequency // no information on earth radius and satellite height // no time information // no Doppler information meta->sar->yaw = params->yaw; meta->sar->pitch = params->pitch; meta->sar->roll = params->roll; meta->sar->azimuth_processing_bandwidth = params->bandwidth; // no chirp rate information meta->sar->pulse_duration = params->pulse_length / 1000.0; // no information on range sampling rate // FIXME: check polarizations for interferometric/polarimetric data // FIXME: multilook flag depends on data type // UAVSAR block meta->uavsar = meta_uavsar_init(); strcpy(meta->uavsar->id, params->id); meta->uavsar->scale_factor = 1.0; meta->uavsar->gps_altitude = params->altitude; meta->uavsar->lat_peg_point = params->lat_peg_point; meta->uavsar->lon_peg_point = params->lon_peg_point; meta->uavsar->head_peg_point = params->head_peg_point; meta->uavsar->along_track_offset = params->along_track_offset; meta->uavsar->cross_track_offset = params->cross_track_offset; // Projection block if (params->type >= INSAR_AMP_GRD && params->type <= INSAR_HGT_GRD) { meta->projection = meta_projection_init(); meta->projection->type = LAT_LONG_PSEUDO_PROJECTION; strcpy (meta->projection->units, "degrees"); if (params->along_track_offset >= 0.0) meta->projection->hem = 'N'; else meta->projection->hem = 'S'; meta->projection->re_major = meta->general->re_major; meta->projection->re_minor = meta->general->re_minor; meta->projection->height = 0.0; meta->projection->spheroid = WGS84_SPHEROID; meta->projection->datum = WGS84_DATUM; // FIXME: Check that the following is correct - needs some data // Coordinate reference: Point // UAVSAR lat/lon projected data is calculated from center // pixel. Thus we have to add in a half-pixel shift. meta->projection->startX = params->cross_track_offset - params->range_pixel_spacing / 2.0; meta->projection->startY = params->along_track_offset - params->azimuth_pixel_spacing / 2.0; meta->projection->perX = params->range_pixel_spacing; meta->projection->perY = params->azimuth_pixel_spacing; meta->general->center_latitude = params->along_track_offset + params->azimuth_pixel_spacing * params->row_count / 2.0; meta->general->center_longitude = params->cross_track_offset + params->range_pixel_spacing * params->column_count / 2.0; } // Location block meta->location = meta_location_init(); meta->location->lat_start_near_range = params->lat_upper_left; meta->location->lon_start_near_range = params->lon_upper_left; meta->location->lat_start_far_range = params->lat_upper_right; meta->location->lon_start_far_range = params->lon_upper_right; meta->location->lat_end_near_range = params->lat_lower_left; meta->location->lon_end_near_range = params->lon_lower_left; meta->location->lat_end_far_range = params->lat_lower_right; meta->location->lon_end_far_range = params->lon_lower_right; return meta; }
// for png, combined the "open_meta" and "open_data" functions -- both // will be opening the same file. meta_parameters* open_png(const char *data_name, ClientInterface *client) { ReadPngClientInfo *info = MALLOC(sizeof(ReadPngClientInfo)); png_structp png_ptr; png_infop info_ptr; png_uint_32 width, height; int bit_depth, color_type, interlace_type, compression_type, filter_type; // We set up all the png infrastructure here, but don't actually // do anything with it, that all happens in read_png_client. // Can't do it all in read_png_client, because we need to set // up metadata in here. info->fp = FOPEN(data_name, "rb"); unsigned char sig[8]; // Important: Leaves file pointer offset into file by 8 bytes for png lib fread(sig, 1, 8, info->fp); if (!png_check_sig(sig, 8)) { // Bad PNG magic number (signature) asfPrintWarning("Invalid PNG file (%s)\n", "file type header bytes invalid", data_name); return NULL; } png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { asfPrintWarning("Cannot allocate PNG read struct (out of memory?)\n"); return NULL; } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, NULL, NULL); asfPrintWarning("Cannot allocate PNG info struct (out of memory?)\n"); return NULL; } if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); asfPrintWarning("PNG library error occurred (invalid PNG file?)\n"); return NULL; } png_init_io(png_ptr, info->fp); // Because of the sig-reading offset ...must do this for PNG lib png_set_sig_bytes(png_ptr, 8); // Read info and IHDR png_read_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_type); //int nbands = (int)png_get_channels(png_ptr, info_ptr); // Preliminary error checking on returned values // (make sure results are valid) if (//bit_depth != 1 && //bit_depth != 2 && //bit_depth != 4 && //bit_depth != 16 && bit_depth != 8) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); asfPrintWarning("Invalid PNG file bit depth found (%d).\n" "Must be 8.\n", bit_depth); return NULL; } if (color_type != PNG_COLOR_TYPE_GRAY && //color_type != PNG_COLOR_TYPE_GRAY_ALPHA && //color_type != PNG_COLOR_TYPE_PALETTE && color_type != PNG_COLOR_TYPE_RGB && //color_type != PNG_COLOR_TYPE_RGB_ALPHA && //color_type != PNG_COLOR_MASK_PALETTE && //color_type != PNG_COLOR_MASK_ALPHA && color_type != PNG_COLOR_MASK_COLOR) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); asfPrintWarning("Invalid PNG file color type found.\n"); return NULL; } if (filter_type != PNG_FILTER_TYPE_BASE && filter_type != PNG_INTRAPIXEL_DIFFERENCING) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); asfPrintWarning("Invalid PNG file filter type found.\n"); return NULL; } if (compression_type != PNG_COMPRESSION_TYPE_BASE) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); asfPrintWarning("Invalid PNG file compression type found.\n"); return NULL; } if (interlace_type != PNG_INTERLACE_NONE && interlace_type != PNG_INTERLACE_ADAM7) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); asfPrintWarning("Invalid PNG file interlace type found.\n"); return NULL; } info->png_ptr = png_ptr; info->info_ptr = info_ptr; client->read_client_info = info; client->read_fn = read_png_client; client->thumb_fn = NULL; client->free_fn = free_png_client_info; client->require_full_load = TRUE; if (color_type == PNG_COLOR_TYPE_GRAY) { client->data_type = GREYSCALE_BYTE; info->rgb_flag = FALSE; } else if (color_type == PNG_COLOR_TYPE_RGB && color_type == PNG_COLOR_MASK_COLOR) { client->data_type = RGB_BYTE; info->rgb_flag = TRUE; } meta_parameters *meta = raw_init(); meta->general->line_count = height; meta->general->sample_count = width; meta->general->band_count = 1; strcpy(meta->general->bands, ""); meta->general->data_type = ASF_BYTE; return meta; }
int main(int argc, char **argv) { FILE *fpIn, *fpOut, *fpInList, *fpOutList, *fpXml; meta_parameters *meta; extern int currArg; /* from cla.h in asf.h... initialized to 1 */ logflag = 0; // Parse command line args while (currArg < (argc-2)) { char *key=argv[currArg++]; if (strmatch(key,"-log")) { sprintf(logFile, "%s", argv[currArg]); logflag = 1; } else { printf("\n ***Invalid option: %s\n\n", argv[currArg-1]); usage(argv[0]); } } if ((argc-currArg) < 2) { printf("Insufficient arguments.\n"); usage(argv[0]); } asfSplashScreen(argc, argv); char *listInFile = (char *) MALLOC(sizeof(char)*(strlen(argv[1])+1)); strcpy(listInFile, argv[1]); char *outFile = (char *) MALLOC(sizeof(char)*(strlen(argv[2])+1)); strcpy(outFile, argv[2]); // Setup file names char outDirName[512], outFileName[512]; split_dir_and_file(outFile, outDirName, outFileName); char *tmpDir = (char *) MALLOC(sizeof(char)*512); sprintf(tmpDir, "%smeasures-", outDirName); char *tsdir = time_stamp_dir(); strcat(tmpDir, tsdir); FREE(tsdir); create_clean_dir(tmpDir); char *isoStr = iso_date(); // Read header information char inFile[512], imgFile[768], metaFile[768]; char listOutFile[768], citation[50], start[30], end[30], first[30]; char header[120], baseName[512], dirName[512], ext[5]; float x_pix, y_pix, x_map_ll, y_map_ll, x_map_ur, y_map_ur, inc, cat; double lat, lon, height, x, y, z; int ii, kk, nFiles=0, num = 1, sample_count, line_count; image_data_type_t image_data_type; sprintf(listOutFile, "%s%crgps.xml", tmpDir, DIR_SEPARATOR); // Preparing map projection information project_parameters_t pps; projection_type_t proj_type; datum_type_t datum; spheroid_type_t spheroid; read_proj_file("polar_stereographic_north_ssmi.proj", &pps, &proj_type, &datum, &spheroid); pps.ps.false_easting = 0.0; pps.ps.false_northing = 0.0; meta_projection *proj = meta_projection_init(); proj->type = proj_type; proj->datum = HUGHES_DATUM; proj->spheroid = HUGHES_SPHEROID; proj->param = pps; strcpy(proj->units, "meters"); proj->hem = 'N'; spheroid_axes_lengths(spheroid, &proj->re_major, &proj->re_minor); FREE(proj); // Set up supplemental file names: water mask, lat/lon, x/y grids char maskFile[768], latFile[768], lonFile[768], xFile[768], yFile[768]; sprintf(maskFile, "%s%cwater_mask.img", tmpDir, DIR_SEPARATOR); sprintf(latFile, "%s%clatitude.img", tmpDir, DIR_SEPARATOR); sprintf(lonFile, "%s%clongitude.img", tmpDir, DIR_SEPARATOR); sprintf(xFile, "%s%cxgrid.img", tmpDir, DIR_SEPARATOR); sprintf(yFile, "%s%cygrid.img", tmpDir, DIR_SEPARATOR); // Generating output XML file fpInList = FOPEN(listInFile, "r"); fpOutList = FOPEN(listOutFile, "w"); fprintf(fpOutList, "<netcdf>\n"); fprintf(fpOutList, " <data>\n"); fprintf(fpOutList, " <latitude>%s</latitude>\n", latFile); fprintf(fpOutList, " <longitude>%s</longitude>\n", lonFile); fprintf(fpOutList, " <xgrid>%s</xgrid>\n", xFile); fprintf(fpOutList, " <ygrid>%s</ygrid>\n", yFile); fprintf(fpOutList, " <mask>%s</mask>\n", maskFile); julian_date jdStart, jdEnd, jdRef; hms_time hms; hms.hour = 0; hms.min = 0; hms.sec = 0.0; asfPrintStatus("Working through the file list:\n"); int myrFlag=FALSE, divFlag=FALSE, vrtFlag=FALSE, shrFlag=FALSE; int firstYear, firstDay, startYear, startDay, endYear, endDay; double westBoundLon, eastBoundLon, northBoundLat, southBoundLat; double minLat=90.0, maxLat=-90.0, minLon=180.0, maxLon=-180.0; while (fgets(inFile, 512, fpInList)) { chomp(inFile); char inDirName[512], inFileName[512]; split_dir_and_file(inFile, inDirName, inFileName); // Preparing map projection information project_parameters_t pps; projection_type_t proj_type; datum_type_t datum; spheroid_type_t spheroid; read_proj_file("polar_stereographic_north_ssmi.proj", &pps, &proj_type, &datum, &spheroid); pps.ps.false_easting = 0.0; pps.ps.false_northing = 0.0; meta_projection *proj = meta_projection_init(); proj->type = proj_type; proj->datum = HUGHES_DATUM; proj->spheroid = HUGHES_SPHEROID; proj->param = pps; strcpy(proj->units, "meters"); proj->hem = 'N'; spheroid_axes_lengths(spheroid, &proj->re_major, &proj->re_minor); // Sort out dates startYear = subInt(inFileName, 0, 4); startDay = subInt(inFileName, 4, 3); endYear = subInt(inFileName, 8, 4); endDay = subInt(inFileName, 12, 3); if (nFiles == 0) { firstYear = startYear; firstDay = startDay; } sprintf(citation, "%d%03d to %d%03d", startYear, startDay, endYear, endDay); rgps2iso_date(startYear, (double) startDay, start); rgps2iso_date(endYear, (double) endDay, end); rgps2iso_date(firstYear, (double) firstDay, first); // Read header information FILE *fpIn = FOPEN(inFile, "r"); fgets(header, 100, fpIn); sscanf(header, "%f %f %f %f %f %f", &x_pix, &y_pix, &x_map_ll, &y_map_ll, &x_map_ur, &y_map_ur); fgets(header, 100, fpIn); int params = sscanf(header, "%f %f %d %d", &inc, &cat, &sample_count, &line_count); if (params == 3) { sscanf(header, "%f %d %d", &cat, &sample_count, &line_count); inc = 0; } else if (params == 2) { sscanf(header, "%d %d", &sample_count, &line_count); inc = 0; cat = 1; } num = (int) cat; if (num > 1) asfPrintError("Multiband imagery (%s) not supported for netCDF " "generation!\n", inFile); /* printf("x_pix: %f, y_pix: %f\n", x_pix, y_pix); printf("x_map_ll: %f, y_map_ll: %f\n", x_map_ll, y_map_ll); printf("x_map_ur: %f, y_map_ur: %f\n", x_map_ur, y_map_ur); printf("sample_count: %d, line_count: %d\n\n", sample_count, line_count); */ // Check extension split_base_and_ext(inFileName, 1, '.', baseName, ext); asfPrintStatus("Processing %s ...\n", inFileName); sprintf(imgFile, "%s%c%s_%s.img", tmpDir, DIR_SEPARATOR, baseName, &ext[1]); sprintf(metaFile, "%s%c%s_%s.meta", tmpDir, DIR_SEPARATOR, baseName, &ext[1]); jdRef.year = firstYear; jdRef.jd = 1; jdStart.year = startYear; jdStart.jd = startDay; jdEnd.year = endYear; jdEnd.jd = endDay; double startSec = date2sec(&jdStart, &hms) - date2sec(&jdRef, &hms); double endSec = date2sec(&jdEnd, &hms) - date2sec(&jdRef, &hms); if (strcmp_case(ext, ".MYR") == 0) { fprintf(fpOutList, " <multiyear_ice_fraction start=\"%.0f\" end=\"%.0f" "\">%s</multiyear_ice_fraction>\n", startSec, endSec, imgFile); image_data_type = MULTIYEAR_ICE_FRACTION; myrFlag = TRUE; } else if (strcmp_case(ext, ".DIV") == 0) { fprintf(fpOutList, " <divergence start=\"%.0f\" end=\"%.0f\">%s" "</divergence>\n", startSec, endSec, imgFile); image_data_type = DIVERGENCE; divFlag = TRUE; } else if (strcmp_case(ext, ".VRT") == 0) { fprintf(fpOutList, " <vorticity start=\"%.0f\" end=\"%.0f\">%s" "</vorticity>\n", startSec, endSec, imgFile); image_data_type = VORTICITY; vrtFlag = TRUE; } else if (strcmp_case(ext, ".SHR") == 0) { fprintf(fpOutList, " <shear start=\"%.0f\" end=\"%.0f\">%s</shear>", startSec, endSec, imgFile); image_data_type = SHEAR; shrFlag = TRUE; } // Generate basic metadata meta = raw_init(); meta->general->line_count = line_count; meta->general->sample_count = sample_count; meta->general->band_count = 1; meta->general->data_type = REAL32; meta->general->image_data_type = image_data_type; strcpy(meta->general->basename, inFile); meta->general->x_pixel_size = x_pix*1000.0; meta->general->y_pixel_size = y_pix*1000.0; meta->general->start_line = 0; meta->general->start_sample = 0; meta->general->no_data = MAGIC_UNSET_DOUBLE; strcpy(meta->general->sensor, "RGPS MEaSUREs"); char *tmp = image_data_type2str(meta->general->image_data_type); sprintf(meta->general->bands, "%s", lc(tmp)); FREE(tmp); sprintf(meta->general->acquisition_date, "%s", baseName); // Sort out map projection proj->startX = x_map_ll*1000.0; proj->startY = y_map_ur*1000.0; proj->perX = x_pix*1000.0; proj->perY = -y_pix*1000.0; meta->projection = proj; meta_write(meta, metaFile); strcpy(meta->general->bands, "water mask"); sprintf(metaFile, "%s%cwater_mask.meta", tmpDir, DIR_SEPARATOR); meta_write(meta, metaFile); sprintf(metaFile, "%s%c%s_%s.meta", tmpDir, DIR_SEPARATOR, baseName, &ext[1]); float *floatBuf = (float *) MALLOC(sizeof(float)*sample_count); // Write gridded data to ASF internal format fpOut = FOPEN(imgFile, "wb"); for (ii=0; ii<line_count; ii++) { for (kk=0; kk<sample_count; kk++) { ASF_FREAD(&floatBuf[kk], sizeof(float), 1, fpIn); ieee_big32(floatBuf[kk]); if (floatBuf[kk] > 10000000000.0 || FLOAT_EQUIVALENT(floatBuf[kk], 10000000000.0)) floatBuf[kk] = MAGIC_UNSET_DOUBLE; } put_float_line(fpOut, meta, line_count-ii-1, floatBuf); } FCLOSE(fpOut); FREE(floatBuf); double lat1, lon1, lat2, lon2, lat3, lon3, lat4, lon4; proj_to_latlon(proj, x_map_ll*1000.0, y_map_ll*1000.0, 0.0, &lat1, &lon1, &height); proj_to_latlon(proj, x_map_ll*1000.0, y_map_ur*1000.0, 0.0, &lat2, &lon2, &height); proj_to_latlon(proj, x_map_ur*1000.0, y_map_ur*1000.0, 0.0, &lat3, &lon3, &height); proj_to_latlon(proj, x_map_ur*1000.0, y_map_ll*1000.0, 0.0, &lat4, &lon4, &height); westBoundLon = minValue(lon1*R2D, lon2*R2D, lon3*R2D, lon4*R2D); eastBoundLon = maxValue(lon1*R2D, lon2*R2D, lon3*R2D, lon4*R2D); northBoundLat = maxValue(lat1*R2D, lat2*R2D, lat3*R2D, lat4*R2D); southBoundLat = minValue(lat1*R2D, lat2*R2D, lat3*R2D, lat4*R2D); if (westBoundLon < minLon) minLon = westBoundLon; if (eastBoundLon > maxLon) maxLon = eastBoundLon; if (southBoundLat < minLat) minLat = southBoundLat; if (northBoundLat > maxLat) maxLat = northBoundLat; meta_free(meta); nFiles++; } FCLOSE(fpInList); fprintf(fpOutList, " </data>\n"); fprintf(fpOutList, " <metadata>\n"); fprintf(fpOutList, " <time>\n"); fprintf(fpOutList, " <axis type=\"string\" definition=\"name of axis\">T" "</axis>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">serial date</long_name>\n"); fprintf(fpOutList, " <references type=\"string\" definition=\"reference " "of the value\">start time of 3-day average</references>\n"); fprintf(fpOutList, " <standard_name type=\"string\" definition=\"name " "used to identify the physical quantity\">time</standard_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">seconds since %d-01-01T00:00:00Z</units>\n", firstYear); fprintf(fpOutList, " <bounds type=\"string\" definition=\"variable " "containing data range\">time_bounds</bounds>\n"); fprintf(fpOutList, " <FillValue type=\"double\" definition=\"default " "value\">0</FillValue>\n"); fprintf(fpOutList, " </time>\n"); fprintf(fpOutList, " <time_bounds>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">serial date</long_name>\n"); fprintf(fpOutList, " <references type=\"string\" definition=\"reference " "of the value\">start and end time of 3-day average</references>\n"); fprintf(fpOutList, " <standard_name type=\"string\" definition=\"name " "used to identify the physical quantity\">time</standard_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">seconds since %d-01-01T00:00:00Z</units>\n", firstYear); fprintf(fpOutList, " <FillValue type=\"double\" definition=\"default " "value\">0</FillValue>\n"); fprintf(fpOutList, " </time_bounds>\n"); fprintf(fpOutList, " <latitude>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">latitude</long_name>\n"); fprintf(fpOutList, " <standard_name type=\"string\" definition=\"name " "used to identify the physical quantity\">latitude</standard_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">degrees_north</units>\n"); fprintf(fpOutList, " <FillValue type=\"float\" definition=\"default " "value\">-999</FillValue>\n"); fprintf(fpOutList, " <valid_min type=\"float\" definition=\"minimum " "valid value\">-90.0</valid_min>\n"); fprintf(fpOutList, " <valid_max type=\"float\" definition=\"minimum " "valid value\">90.0</valid_max>\n"); fprintf(fpOutList, " </latitude>\n"); fprintf(fpOutList, " <longitude>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">longitude</long_name>\n"); fprintf(fpOutList, " <standard_name type=\"string\" definition=\"name " "used to identify the physical quantity\">longitude</standard_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">degrees_east</units>\n"); fprintf(fpOutList, " <FillValue type=\"float\" definition=\"default " "value\">-999</FillValue>\n"); fprintf(fpOutList, " <valid_min type=\"float\" definition=\"minimum " "valid value\">-180.0</valid_min>\n"); fprintf(fpOutList, " <valid_max type=\"float\" definition=\"minimum " "valid value\">180.0</valid_max>\n"); fprintf(fpOutList, " </longitude>\n"); fprintf(fpOutList, " <xgrid>\n"); fprintf(fpOutList, " <axis type=\"string\" definition=\"name of axis\">X" "</axis>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">projection_grid_x_center</long_name>\n"); fprintf(fpOutList, " <standard_name type=\"string\" definition=\"name " "used to identify the physical quantity\">projection_x_coordinate" "</standard_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">meters</units>\n"); fprintf(fpOutList, " <FillValue type=\"float\" definition=\"default " "value\">NaN</FillValue>\n"); fprintf(fpOutList, " </xgrid>\n"); fprintf(fpOutList, " <ygrid>\n"); fprintf(fpOutList, " <axis type=\"string\" definition=\"name of axis\">Y" "</axis>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">projection_grid_y_center</long_name>\n"); fprintf(fpOutList, " <standard_name type=\"string\" definition=\"name " "used to identify the physical quantity\">projection_y_coordinate" "</standard_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">meters</units>\n"); fprintf(fpOutList, " <FillValue type=\"float\" definition=\"default " "value\">NaN</FillValue>\n"); fprintf(fpOutList, " </ygrid>\n"); fprintf(fpOutList, " <Polar_Stereographic>\n"); fprintf(fpOutList, " <grid_mapping_name>polar_stereographic" "</grid_mapping_name>\n"); fprintf(fpOutList, " <straight_vertical_longitude_from_pole>%.1f" "</straight_vertical_longitude_from_pole>\n", pps.ps.slon); fprintf(fpOutList, " <longitude_of_central_meridian>90.0" "</longitude_of_central_meridian>\n"); fprintf(fpOutList, " <standard_parallel>%.1f</standard_parallel>\n", pps.ps.slat); fprintf(fpOutList, " <false_easting>%.1f</false_easting>\n", pps.ps.false_easting); fprintf(fpOutList, " <false_northing>%.1f</false_northing>\n", pps.ps.false_northing); fprintf(fpOutList, " <projection_x_coordinate>xgrid" "</projection_x_coordinate>\n"); fprintf(fpOutList, " <projection_y_coordinate>ygrid" "</projection_y_coordinate>\n"); fprintf(fpOutList, " <units>meters</units>\n"); fprintf(fpOutList, " </Polar_Stereographic>\n"); fprintf(fpOutList, " <mask>\n"); fprintf(fpOutList, " <coordinates type=\"string\" definition=\"" "coordinate reference\">ygrid xgrid</coordinates>\n"); fprintf(fpOutList, " <grid_mapping type=\"string\" definition=\"\">" "Polar_Stereographic</grid_mapping>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">projection_grid_y_center</long_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">1</units>\n"); fprintf(fpOutList, " <units_description type=\"string\" definition=\"" "descriptive information about dimensionless quantity\">unitless" "</units_description>\n"); fprintf(fpOutList, " <FillValue type=\"int\" definition=\"default " "value\">0</FillValue>\n"); fprintf(fpOutList, " </mask>\n"); if (myrFlag) { fprintf(fpOutList, " <multiyear_ice_fraction>\n"); fprintf(fpOutList, " <cell_methods type=\"string\" definition=\"" "characteristic of a field that is represented by cell values\">area: " "multiyear ice fraction value</cell_methods>\n"); fprintf(fpOutList, " <coordinates type=\"string\" definition=\"" "coordinate reference\">ygrid xgrid</coordinates>\n"); fprintf(fpOutList, " <grid_mapping type=\"string\" definition=\"\">" "Polar_Stereographic</grid_mapping>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">RGPS MEaSUREs multiyear ice fraction</long_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">1</units>\n"); fprintf(fpOutList, " <units_description type=\"string\" definition=\"" "descriptive information about dimensionless quantity\">unitless" "</units_description>\n"); fprintf(fpOutList, " <FillValue type=\"float\" definition=\"default " "value\">NaN</FillValue>\n"); fprintf(fpOutList, " </multiyear_ice_fraction>\n"); } if (divFlag) { fprintf(fpOutList, " <divergence>\n"); fprintf(fpOutList, " <cell_methods type=\"string\" definition=\"" "characteristic of a field that is represented by cell values\">area: " "divergence value</cell_methods>\n"); fprintf(fpOutList, " <coordinates type=\"string\" definition=\"" "coordinate reference\">ygrid xgrid</coordinates>\n"); fprintf(fpOutList, " <grid_mapping type=\"string\" definition=\"\">" "Polar_Stereographic</grid_mapping>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">RGPS MEaSUREs divergence</long_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">1</units>\n"); fprintf(fpOutList, " <units_description type=\"string\" definition=\"" "descriptive information about dimensionless quantity\">unitless" "</units_description>\n"); fprintf(fpOutList, " <FillValue type=\"float\" definition=\"default " "value\">NaN</FillValue>\n"); fprintf(fpOutList, " </divergence>\n"); } if (vrtFlag) { fprintf(fpOutList, " <vorticity>\n"); fprintf(fpOutList, " <cell_methods type=\"string\" definition=\"" "characteristic of a field that is represented by cell values\">area: " "vorticity value</cell_methods>\n"); fprintf(fpOutList, " <coordinates type=\"string\" definition=\"" "coordinate reference\">ygrid xgrid</coordinates>\n"); fprintf(fpOutList, " <grid_mapping type=\"string\" definition=\"\">" "Polar_Stereographic</grid_mapping>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">RGPS MEaSUREs vorticity</long_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">1</units>\n"); fprintf(fpOutList, " <units_description type=\"string\" definition=\"" "descriptive information about dimensionless quantity\">unitless" "</units_description>\n"); fprintf(fpOutList, " <FillValue type=\"float\" definition=\"default " "value\">NaN</FillValue>\n"); fprintf(fpOutList, " </vorticity>\n"); } if (shrFlag) { fprintf(fpOutList, " <shear>\n"); fprintf(fpOutList, " <cell_methods type=\"string\" definition=\"" "characteristic of a field that is represented by cell values\">area: " "shear value</cell_methods>\n"); fprintf(fpOutList, " <coordinates type=\"string\" definition=\"" "coordinate reference\">ygrid xgrid</coordinates>\n"); fprintf(fpOutList, " <grid_mapping type=\"string\" definition=\"\">" "Polar_Stereographic</grid_mapping>\n"); fprintf(fpOutList, " <long_name type=\"string\" definition=\"long " "descriptive name\">RGPS MEaSUREs shear</long_name>\n"); fprintf(fpOutList, " <units type=\"string\" definition=\"unit of " "dimensional quantity\">1</units>\n"); fprintf(fpOutList, " <units_description type=\"string\" definition=\"" "descriptive information about dimensionless quantity\">unitless" "</units_description>\n"); fprintf(fpOutList, " <FillValue type=\"float\" definition=\"default " "value\">NaN</FillValue>\n"); fprintf(fpOutList, " </shear>\n"); } fprintf(fpOutList, " </metadata>\n"); fprintf(fpOutList, " <parameter>\n"); if (myrFlag) fprintf(fpOutList, " <multiyear_ice_fraction type=\"float\"/>\n"); if (divFlag) fprintf(fpOutList, " <divergence type=\"float\"/>\n"); if (vrtFlag) fprintf(fpOutList, " <vorticity type=\"float\"/>\n"); if (shrFlag) fprintf(fpOutList, " <shear type=\"float\"/>\n"); fprintf(fpOutList, " </parameter>\n"); char startStr[15], endStr[15]; jdStart.year = firstYear; jdStart.jd = firstDay; jdEnd.year = endYear; jdEnd.jd = endDay; jd2date(&jdStart, startStr); jd2date(&jdEnd, endStr); if (firstYear != endYear || firstDay != endDay) sprintf(citation, "%s to %s", startStr, endStr); else sprintf(citation, "%s", startStr); fprintf(fpOutList, " <root>\n"); fprintf(fpOutList, " <Conventions>CF-1.6</Conventions>\n"); fprintf(fpOutList, " <institution>Alaska Satellite Facility</institution>\n"); fprintf(fpOutList, " <title>Kwok, Ron. 2008. MEaSUREs Small-Scale Kinematics" " of Arctic Ocean Sea Ice, Version 01, %s. Jet Propulsion Laboratory " "Pasadena, CA USA and Alaska Satellite Facility Fairbanks, AK USA. " "Digital media.</title>\n", citation); fprintf(fpOutList, " <source>Products derived from RADARSAT-1 SWB imagery at " "100 m resolution</source>\n"); fprintf(fpOutList, " <comment>Imagery the products are derived from: Copyright " "Canadian Space Agency (1996 to 2008)</comment>\n"); fprintf(fpOutList, " <reference>Documentation available at: www.asf.alaska.edu" "</reference>\n"); fprintf(fpOutList, " <history>%s: netCDF file created.</history>\n", isoStr); fprintf(fpOutList, " </root>\n"); fprintf(fpOutList, "</netcdf>\n"); FCLOSE(fpOutList); // Generate supplemental files: water mask, lat/lon, x/y grids asfPrintStatus("Generating supplemental files ...\n"); float *floatBuf = (float *) MALLOC(sizeof(float)*sample_count); float *maskBuf = (float *) MALLOC(sizeof(float)*sample_count); float *latBuf = (float *) MALLOC(sizeof(float)*sample_count); float *lonBuf = (float *) MALLOC(sizeof(float)*sample_count); float *xBuf = (float *) MALLOC(sizeof(float)*sample_count); float *yBuf = (float *) MALLOC(sizeof(float)*sample_count); meta = meta_read(metaFile); fpIn = FOPEN(inFile, "r"); fgets(header, 100, fpIn); sscanf(header, "%f %f %f %f %f %f", &x_pix, &y_pix, &x_map_ll, &y_map_ll, &x_map_ur, &y_map_ur); fgets(header, 100, fpIn); sscanf(header, "%d %d", &sample_count, &line_count); FILE *fpMask = FOPEN(maskFile, "wb"); FILE *fpLat = FOPEN(latFile, "wb"); FILE *fpLon = FOPEN(lonFile, "wb"); FILE *fpXgrid = FOPEN(xFile, "wb"); FILE *fpYgrid = FOPEN(yFile, "wb"); for (ii=0; ii<line_count; ii++) { for (kk=0; kk<sample_count; kk++) { ASF_FREAD(&floatBuf[kk], sizeof(float), 1, fpIn); ieee_big32(floatBuf[kk]); } for (kk=0; kk<sample_count; kk++) { meta_get_latLon(meta, line_count-ii-1, kk, 0.0, &lat, &lon); latlon_to_proj(meta->projection, 'R', lat*D2R, lon*D2R, 0.0, &x, &y, &z); latBuf[kk] = lat; lonBuf[kk] = lon; xBuf[kk] = x; yBuf[kk] = y; if (floatBuf[kk] < 10000000000.0) { maskBuf[kk] = 1.0; } else if (floatBuf[kk] > 10000000000.0) { maskBuf[kk] = 1.0; } else { maskBuf[kk] = 0.0; } } put_float_line(fpMask, meta, line_count-ii-1, maskBuf); put_float_line(fpLat, meta, line_count-ii-1, latBuf); put_float_line(fpLon, meta, line_count-ii-1, lonBuf); put_float_line(fpXgrid, meta, line_count-ii-1, xBuf); put_float_line(fpYgrid, meta, line_count-ii-1, yBuf); } FCLOSE(fpIn); FCLOSE(fpMask); FCLOSE(fpLat); FCLOSE(fpLon); FREE(floatBuf); FREE(maskBuf); FREE(latBuf); FREE(lonBuf); FREE(xBuf); FREE(yBuf); meta_write(meta, latFile); meta_write(meta, lonFile); meta_write(meta, xFile); meta_write(meta, yFile); // Write ISO meatadata for netCDF asfPrintStatus("Generating metadata for netCDF file ...\n"); char *ncXmlBase = get_basename(outFile); char *ncXmlFile = appendExt(outFile, ".xml"); fpXml = FOPEN(ncXmlFile, "w"); fprintf(fpXml, "<rgps>\n"); fprintf(fpXml, " <granule>%s</granule>\n", ncXmlBase); fprintf(fpXml, " <metadata_creation>%s</metadata_creation>\n", isoStr); fprintf(fpXml, " <metadata>\n"); fprintf(fpXml, " <product>\n"); fprintf(fpXml, " <file type=\"string\" definition=\"name of product " "file\">%s.nc</file>\n", ncXmlBase); if (divFlag && vrtFlag && shrFlag) fprintf(fpXml, " <type type=\"string\" definition=\"product type\">" "divergence, vorticity, shear</type>\n"); else if (myrFlag) fprintf(fpXml, " <type type=\"string\" definition=\"product type\">" "multiyear ice fraction</type>\n"); fprintf(fpXml, " <format type=\"string\" definition=\"name of the data " "format\">netCDF</format>\n"); fpInList = FOPEN(listInFile, "r"); while (fgets(inFile, 512, fpInList)) { chomp(inFile); split_dir_and_file(inFile, dirName, baseName); fprintf(fpXml, " <source type=\"string\" definition=\"name of the data" " source\">%s</source>\n", baseName); } FCLOSE(fpInList); fprintf(fpXml, " <cell_size_x type=\"double\" definition=\"cell size " "in x direction\" units=\"m\">%.2f</cell_size_x>\n", x_pix*1000.0); fprintf(fpXml, " <cell_size_y type=\"double\" definition=\"cell size " "in y direction\" units=\"m\">%.2f</cell_size_y>\n", y_pix*1000.0); fprintf(fpXml, " <map_x_lower_left type=\"double\" definition=\"x " "coordinate of lower left corner\" units=\"m\">%.6f</map_x_lower_left>\n", x_map_ll*1000.0); fprintf(fpXml, " <map_y_lower_left type=\"double\" definition=\"y " "coordinate of lower left corner\" units=\"m\">%.6f</map_y_lower_left>\n", y_map_ll*1000.0); fprintf(fpXml, " <map_x_upper_right type=\"double\" definition=\"x " "coordinate of upper right corner\" units=\"m\">%.6f</map_x_upper_right>" "\n", x_map_ur*1000.0); fprintf(fpXml, " <map_y_upper_right type=\"double\" definition=\"y " "coordinate of upper right corner\" units=\"m\">%.6f</map_y_upper_right>" "\n", y_map_ur*1000.0); fprintf(fpXml, " <cell_dimension_x type=\"int\" definition=\"cell " "dimension in x direction\">%d</cell_dimension_x>\n", sample_count); fprintf(fpXml, " <cell_dimension_y type=\"int\" definition=\"cell " "dimension in y direction\">%d</cell_dimension_y>\n", line_count); fprintf(fpXml, " <projection_string type=\"string\" definition=\"map " "projection information as well known text\">%s</projection_string>\n", meta2esri_proj(meta, NULL)); fprintf(fpXml, " </product>\n"); fprintf(fpXml, " </metadata>\n"); fprintf(fpXml, " <extent>\n"); fprintf(fpXml, " <product>\n"); fprintf(fpXml, " <westBoundLongitude>%.5f</westBoundLongitude>\n", minLon); fprintf(fpXml, " <eastBoundLongitude>%.5f</eastBoundLongitude>\n", maxLon); fprintf(fpXml, " <northBoundLatitude>%.5f</northBoundLatitude>\n", maxLat); fprintf(fpXml, " <southBoundLatitude>%.5f</southBoundLatitude>\n", minLat); fprintf(fpXml, " <start_datetime>%s</start_datetime>\n", first); fprintf(fpXml, " <end_datetime>%s</end_datetime>\n", end); fprintf(fpXml, " </product>\n"); fprintf(fpXml, " </extent>\n"); fprintf(fpXml, "</rgps>\n"); FCLOSE(fpXml); FREE(ncXmlBase); FREE(ncXmlFile); meta_free(meta); // Export to netCDF asfPrintStatus("Exporting to netCDF file ...\n"); export_netcdf_xml(listOutFile, outFile); // Clean up remove_dir(tmpDir); FREE(tmpDir); FREE(outFile); FREE(listInFile); FREE(isoStr); return 0; }
meta_parameters* gamma_msp2meta(gamma_msp *gamma) { meta_parameters *meta; char *mon[13]={"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec"}; // Initialize the meta structure meta = raw_init(); // Fill general block strcpy(meta->general->basename, gamma->title); strcpy(meta->general->sensor, MAGIC_UNSET_STRING); // Sensor not available in MSP metadata strcpy(meta->general->sensor_name, MAGIC_UNSET_STRING); // Sensor name not available in MSP metadata strcpy(meta->general->mode, MAGIC_UNSET_STRING); // Mode not available in MSP metadata strcpy(meta->general->processor, "GAMMA MSP"); if (strncmp(uc(gamma->image_format), "FCOMPLEX", 8) == 0) meta->general->data_type = COMPLEX_REAL32; else if (strncmp(uc(gamma->image_format), "SCOMPLEX", 8) == 0) meta->general->data_type = COMPLEX_INTEGER16; else if (strncmp(uc(gamma->image_format), "FLOAT", 8) == 0) meta->general->data_type = REAL32; else if (strncmp(uc(gamma->image_format), "SHORT", 8) == 0) meta->general->data_type = INTEGER16; else if (strncmp(uc(gamma->image_format), "BYTE", 8) == 0) meta->general->data_type = ASF_BYTE; if (strcmp(gamma->image_data_type, "UNKNOWN") == 0) { switch(meta->general->data_type) { case COMPLEX_REAL32: case COMPLEX_INTEGER16: meta->general->image_data_type = COMPLEX_IMAGE; break; default: meta->general->image_data_type = IMAGE; break; } } else { if (strncmp(uc(gamma->image_data_type), "RAW_IMAGE", 9) == 0) meta->general->image_data_type = RAW_IMAGE; if (strncmp(uc(gamma->image_data_type), "COMPLEX_IMAGE", 13) == 0) meta->general->image_data_type = COMPLEX_IMAGE; if (strncmp(uc(gamma->image_data_type), "AMPLITUDE_IMAGE", 15) == 0) meta->general->image_data_type = AMPLITUDE_IMAGE; if (strncmp(uc(gamma->image_data_type), "PHASE_IMAGE", 11) == 0) meta->general->image_data_type = PHASE_IMAGE; if (strncmp(uc(gamma->image_data_type), "COHERENCE_IMAGE", 15) == 0) meta->general->image_data_type = COHERENCE_IMAGE; if (strncmp(uc(gamma->image_data_type), "POLARIMETRIC_IMAGE", 18) == 0) meta->general->image_data_type = POLARIMETRIC_IMAGE; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_SEGMENTATION", 25) == 0) meta->general->image_data_type = POLARIMETRIC_SEGMENTATION; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_DECOMPOSITION", 26) == 0) meta->general->image_data_type = POLARIMETRIC_DECOMPOSITION; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_PARAMETER", 22) == 0) meta->general->image_data_type = POLARIMETRIC_PARAMETER; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_C2_MATRIX", 22) == 0) meta->general->image_data_type = POLARIMETRIC_C2_MATRIX; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_C3_MATRIX", 22) == 0) meta->general->image_data_type = POLARIMETRIC_C3_MATRIX; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_C4_MATRIX", 19) == 0) meta->general->image_data_type = POLARIMETRIC_C4_MATRIX; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_T3_MATRIX", 19) == 0) meta->general->image_data_type = POLARIMETRIC_T3_MATRIX; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_T4_MATRIX", 19) == 0) meta->general->image_data_type = POLARIMETRIC_T4_MATRIX; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_STOKES_MATRIX", 26) == 0) meta->general->image_data_type = POLARIMETRIC_STOKES_MATRIX; if (strncmp(uc(gamma->image_data_type), "LUT_IMAGE", 9) == 0) meta->general->image_data_type = LUT_IMAGE; if (strncmp(uc(gamma->image_data_type), "ELEVATION", 9) == 0) meta->general->image_data_type = ELEVATION; if (strncmp(uc(gamma->image_data_type), "DEM", 3) == 0) meta->general->image_data_type = DEM; if (strncmp(uc(gamma->image_data_type), "IMAGE", 5) == 0) meta->general->image_data_type = IMAGE; if (strncmp(uc(gamma->image_data_type), "MASK", 4) == 0) meta->general->image_data_type = MASK; } sprintf(meta->general->acquisition_date, "%2d-%s-%4d", gamma->acquisition.day, mon[gamma->acquisition.month], gamma->acquisition.year); meta->general->orbit = gamma->orbit; if (gamma->track_angle < -90.0) meta->general->orbit_direction = 'D'; else meta->general->orbit_direction = 'A'; meta->general->frame = MAGIC_UNSET_INT; meta->general->band_count = 1; strcpy(meta->general->bands, gamma->band); meta->general->line_count = gamma->azimuth_pixels; meta->general->sample_count = gamma->range_pixels; meta->general->start_line = 0; meta->general->start_sample = 0; meta->general->x_pixel_size = gamma->range_pixel_spacing; meta->general->y_pixel_size = gamma->azimuth_pixel_spacing; meta->general->center_latitude = gamma->scene_center_latitude; meta->general->center_longitude = gamma->scene_center_longitude; meta->general->re_major = gamma->earth_semi_major_axis; meta->general->re_minor = gamma->earth_semi_minor_axis; meta->general->bit_error_rate = MAGIC_UNSET_DOUBLE; meta->general->missing_lines = 0; meta->general->no_data = MAGIC_UNSET_DOUBLE; // Fill SAR block meta->sar = meta_sar_init(); meta->sar->image_type = MAGIC_UNSET_CHAR; meta->sar->look_direction = MAGIC_UNSET_CHAR; meta->sar->azimuth_look_count = gamma->azimuth_looks; meta->sar->range_look_count = gamma->range_looks; meta->sar->deskewed = gamma->azimuth_deskew; meta->sar->original_line_count = gamma->offset_to_first_echo_to_process + gamma->echoes_to_process; meta->sar->original_sample_count = gamma->range_offset + gamma->raw_range_samples; meta->sar->line_increment = 1; meta->sar->sample_increment = 1; meta->sar->range_time_per_pixel = fabs((2.0 * gamma->range_pixel_spacing) / SPD_LIGHT); meta->sar->azimuth_time_per_pixel = get_gamma_msp_azimuth_time_per_pixel(gamma); meta->sar->slant_range_first_pixel = gamma->near_range_slc; meta->sar->slant_shift = 0.0; if (meta->general->orbit_direction == 'D') meta->sar->time_shift = 0.0; else if (meta->general->orbit_direction == 'A') meta->sar->time_shift = fabs(meta->sar->original_line_count * meta->sar->azimuth_time_per_pixel); else meta->sar->time_shift = MAGIC_UNSET_DOUBLE; meta->sar->wavelength = MAGIC_UNSET_DOUBLE; meta->sar->prf = gamma->prf; meta->sar->earth_radius = get_gamma_msp_earth_radius_below_sensor(gamma); meta->sar->earth_radius_pp = meta->sar->earth_radius; // KLUDGE: This value is actually unknown in MSP metadata meta->sar->satellite_height = sqrt(gamma->sensor_position_vector.x*gamma->sensor_position_vector.x + gamma->sensor_position_vector.y*gamma->sensor_position_vector.y + gamma->sensor_position_vector.z*gamma->sensor_position_vector.z); strcpy(meta->sar->satellite_binary_time, MAGIC_UNSET_STRING); strcpy(meta->sar->satellite_clock_time, MAGIC_UNSET_STRING); int i; if (gamma->doppler_polynomial[3] > 0.0001) { // FIXME: If this error ever fires, then we should insert a function that does a // quadratic fit to the cubic function. Then we can derive close 'nuf quadratic // values from a set of points generated by the cubic and use those. asfPrintError("GAMMA doppler polynomial has a large cubic term\n" "(%f versus limit of 0.0001) and is not well modeled by a\nquadratic.", gamma->doppler_polynomial[3]); } for (i=0; i<3; i++) { meta->sar->range_doppler_coefficients[i] = gamma->doppler_polynomial[i]; meta->sar->azimuth_doppler_coefficients[i] = 0.0; // FIXME: We have gamma->radar_frequency and state vectors ...we should estimate the azimuth doppler stuff } meta->sar->azimuth_processing_bandwidth = MAGIC_UNSET_DOUBLE; meta->sar->chirp_rate = MAGIC_UNSET_DOUBLE; meta->sar->pulse_duration = MAGIC_UNSET_DOUBLE; meta->sar->range_sampling_rate = MAGIC_UNSET_DOUBLE; strcpy(meta->sar->polarization, MAGIC_UNSET_STRING); meta->sar->multilook = 0; // Fill state vector structure meta->state_vectors = meta_state_vectors_init(3); meta->state_vectors = gamma->stVec; // Fill location block meta->location = meta_location_init(); if (meta->general->orbit_direction == 'D') { // See comments in gamma.h for map coordinate identification meta->location->lat_start_near_range = gamma->map_coordinate_2.lat; meta->location->lon_start_near_range = gamma->map_coordinate_2.lon; meta->location->lat_start_far_range = gamma->map_coordinate_1.lat; meta->location->lon_start_far_range = gamma->map_coordinate_1.lon; meta->location->lat_end_near_range = gamma->map_coordinate_4.lat; meta->location->lon_end_near_range = gamma->map_coordinate_4.lon; meta->location->lat_end_far_range = gamma->map_coordinate_3.lat; meta->location->lon_end_far_range = gamma->map_coordinate_3.lon; } else { meta->location->lat_start_near_range = gamma->map_coordinate_3.lat; meta->location->lon_start_near_range = gamma->map_coordinate_3.lon; meta->location->lat_start_far_range = gamma->map_coordinate_4.lat; meta->location->lon_start_far_range = gamma->map_coordinate_4.lon; meta->location->lat_end_near_range = gamma->map_coordinate_1.lat; meta->location->lon_end_near_range = gamma->map_coordinate_1.lon; meta->location->lat_end_far_range = gamma->map_coordinate_2.lat; meta->location->lon_end_far_range = gamma->map_coordinate_2.lon; } return meta; }
meta_parameters* gamma_isp2meta(gamma_isp *gamma) { meta_parameters *meta; char *mon[13]={"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec"}; // Initialize the meta structure meta = raw_init(); // Fill general block strcpy(meta->general->basename, gamma->title); strcpy(meta->general->sensor, gamma->sensor); strcpy(meta->general->sensor_name, MAGIC_UNSET_STRING); // Sensor name not available in ISP metadata strcpy(meta->general->mode, MAGIC_UNSET_STRING); // Mode not available in ISP metadata strcpy(meta->general->processor, "GAMMA ISP"); if (strncmp_case(gamma->image_format, "FCOMPLEX", 8) == 0) meta->general->data_type = COMPLEX_REAL32; else if (strncmp_case(gamma->image_format, "SCOMPLEX", 8) == 0) meta->general->data_type = COMPLEX_INTEGER16; else if (strncmp_case(gamma->image_format, "FLOAT", 8) == 0) meta->general->data_type = REAL32; else if (strncmp_case(gamma->image_format, "SHORT", 8) == 0) meta->general->data_type = INTEGER16; else if (strncmp_case(gamma->image_format, "BYTE", 8) == 0) meta->general->data_type = ASF_BYTE; if (strcmp(gamma->image_data_type, "UNKNOWN") == 0) { switch(meta->general->data_type) { case COMPLEX_REAL32: case COMPLEX_INTEGER16: meta->general->image_data_type = COMPLEX_IMAGE; break; default: meta->general->image_data_type = IMAGE; break; } } else { if (strncmp_case(gamma->image_data_type, "RAW_IMAGE", 9) == 0) meta->general->image_data_type = RAW_IMAGE; if (strncmp_case(gamma->image_data_type, "COMPLEX_IMAGE", 13) == 0) meta->general->image_data_type = COMPLEX_IMAGE; if (strncmp_case(gamma->image_data_type, "AMPLITUDE_IMAGE", 15) == 0) meta->general->image_data_type = AMPLITUDE_IMAGE; if (strncmp_case(gamma->image_data_type, "PHASE_IMAGE", 11) == 0) meta->general->image_data_type = PHASE_IMAGE; if (strncmp_case(gamma->image_data_type, "COHERENCE_IMAGE", 15) == 0) meta->general->image_data_type = COHERENCE_IMAGE; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_IMAGE", 18) == 0) meta->general->image_data_type = POLARIMETRIC_IMAGE; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_SEGMENTATION", 25) == 0) meta->general->image_data_type = POLARIMETRIC_SEGMENTATION; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_DECOMPOSITION", 26) == 0) meta->general->image_data_type = POLARIMETRIC_DECOMPOSITION; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_PARAMETER", 22) == 0) meta->general->image_data_type = POLARIMETRIC_PARAMETER; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_C2_MATRIX", 22) == 0) meta->general->image_data_type = POLARIMETRIC_C2_MATRIX; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_C3_MATRIX", 22) == 0) meta->general->image_data_type = POLARIMETRIC_C3_MATRIX; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_C4_MATRIX", 22) == 0) meta->general->image_data_type = POLARIMETRIC_C4_MATRIX; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_T3_MATRIX", 22) == 0) meta->general->image_data_type = POLARIMETRIC_T3_MATRIX; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_T4_MATRIX", 22) == 0) meta->general->image_data_type = POLARIMETRIC_T4_MATRIX; if (strncmp_case(gamma->image_data_type, "POLARIMETRIC_STOKES_MATRIX", 26) == 0) meta->general->image_data_type = POLARIMETRIC_STOKES_MATRIX; if (strncmp_case(gamma->image_data_type, "LUT_IMAGE", 9) == 0) meta->general->image_data_type = LUT_IMAGE; if (strncmp_case(gamma->image_data_type, "ELEVATION", 9) == 0) meta->general->image_data_type = ELEVATION; if (strncmp_case(gamma->image_data_type, "DEM", 3) == 0) meta->general->image_data_type = DEM; if (strncmp_case(gamma->image_data_type, "IMAGE", 5) == 0) meta->general->image_data_type = IMAGE; if (strncmp_case(gamma->image_data_type, "MASK", 4) == 0) meta->general->image_data_type = MASK; if (strncmp_case(gamma->image_data_type, "IMAGE_LAYER_STACK", 17) == 0) meta->general->image_data_type = IMAGE_LAYER_STACK; if (strncmp_case(gamma->image_data_type, "INSAR_STACK", 11) == 0) meta->general->image_data_type = INSAR_STACK; } sprintf(meta->general->acquisition_date, "%2d-%s-%4d", gamma->acquisition.day, mon[gamma->acquisition.month], gamma->acquisition.year); meta->general->orbit = gamma->orbit; if (gamma->heading > 90.0 && gamma->heading < 270.0) meta->general->orbit_direction = 'D'; else meta->general->orbit_direction = 'A'; meta->general->frame = MAGIC_UNSET_INT; meta->general->band_count = 1; strcpy(meta->general->bands, MAGIC_UNSET_STRING); meta->general->line_count = gamma->azimuth_lines; meta->general->sample_count = gamma->range_samples; meta->general->start_line = 0; meta->general->start_sample = 0; meta->general->x_pixel_size = gamma->range_pixel_spacing; meta->general->y_pixel_size = gamma->azimuth_pixel_spacing; meta->general->center_latitude = gamma->center_latitude; meta->general->center_longitude = gamma->center_longitude; meta->general->re_major = gamma->earth_semi_major_axis; meta->general->re_minor = gamma->earth_semi_minor_axis; meta->general->bit_error_rate = MAGIC_UNSET_DOUBLE; meta->general->missing_lines = 0; meta->general->no_data = MAGIC_UNSET_DOUBLE; // Fill SAR block meta->sar = meta_sar_init(); if (strncmp(uc(gamma->image_geometry), "SLANT_RANGE", 11) == 0) meta->sar->image_type = 'S'; else if (strncmp(uc(gamma->image_geometry), "GROUND_RANGE", 11) == 0) meta->sar->image_type = 'G'; else meta->sar->image_type = MAGIC_UNSET_CHAR; if (gamma->azimuth_angle >= 0.0) meta->sar->look_direction = 'R'; else meta->sar->look_direction = 'L'; meta->sar->azimuth_look_count = gamma->azimuth_looks; meta->sar->range_look_count = gamma->range_looks; if (gamma->azimuth_looks > 1 || gamma->range_looks > 1) meta->sar->multilook = 1; else meta->sar->multilook = 0; meta->sar->deskewed = gamma->azimuth_deskew; meta->sar->original_line_count = meta->general->line_count; meta->sar->original_sample_count = meta->general->sample_count; meta->sar->line_increment = 1; meta->sar->sample_increment = 1; meta->sar->range_time_per_pixel = fabs((2.0 * gamma->range_pixel_spacing) / gamma->range_looks / SPD_LIGHT); meta->sar->azimuth_time_per_pixel = gamma->azimuth_line_time; meta->sar->slant_range_first_pixel = gamma->near_range_slc; meta->sar->slant_shift = 0.0; meta->sar->time_shift = 0.0; /* Under testing - does not seem to apply to the test data set. if (meta->general->orbit_direction == 'D') meta->sar->time_shift = 0.0; else if (meta->general->orbit_direction == 'A') meta->sar->time_shift = fabs(meta->sar->original_line_count * meta->sar->azimuth_time_per_pixel); else meta->sar->time_shift = MAGIC_UNSET_DOUBLE; */ meta->sar->wavelength = SPD_LIGHT / gamma->radar_frequency; meta->sar->prf = gamma->prf; meta->sar->earth_radius = gamma->earth_radius_below_sensor; meta->sar->earth_radius_pp = meta->sar->earth_radius; // KLUDGE: This value is actually unknown in ISP metadata meta->sar->satellite_height = gamma->sar_to_earth_center; strcpy(meta->sar->satellite_binary_time, MAGIC_UNSET_STRING); strcpy(meta->sar->satellite_clock_time, MAGIC_UNSET_STRING); int i; if (gamma->doppler_polynomial[3] > 0.0001) { // FIXME: If this error ever fires, then we should insert a function that does a // quadratic fit to the cubic function. Then we can derive close 'nuf quadratic // values from a set of points generated by the cubic and use those. asfPrintError("GAMMA doppler polynomial has a large cubic term\n" "(%f versus limit of 0.0001) and is not well modeled by a\nquadratic.", gamma->doppler_polynomial[3]); } for (i=0; i<3; i++) { meta->sar->range_doppler_coefficients[i] = gamma->doppler_polynomial[i]; meta->sar->azimuth_doppler_coefficients[i] = 0.0; } // Adjust for difference in units [Hz/m] -> [Hz/pixel] meta->sar->range_doppler_coefficients[1] /= gamma->range_pixel_spacing; meta->sar->range_doppler_coefficients[2] /= gamma->range_pixel_spacing * gamma->range_pixel_spacing; meta->sar->azimuth_doppler_coefficients[0] = gamma->doppler_polynomial[0]; meta->sar->azimuth_processing_bandwidth = gamma->azimuth_proc_bandwidth; meta->sar->chirp_rate = gamma->chirp_bandwidth; meta->sar->pulse_duration = MAGIC_UNSET_DOUBLE; meta->sar->range_sampling_rate = gamma->adc_sampling_rate; strcpy(meta->sar->polarization, MAGIC_UNSET_STRING); // Fill state vector structure meta->state_vectors = meta_state_vectors_init(3); meta->state_vectors = gamma->stVec; // Propagate the state vectors to start, center, end int vector_count = 3; double data_int = gamma->center_time - gamma->start_time; while (fabs(data_int) > 15.0) { data_int /= 2; vector_count = vector_count*2-1; } propagate_state(meta, vector_count, data_int); // Generate location block meta_get_corner_coords(meta); return meta; }
meta_parameters* radarsat2meta(radarsat2_meta *radarsat2) { ymd_date date, imgStartDate, imgStopDate; hms_time time, imgStartTime, imgStopTime; meta_parameters *meta; char *mon[13]= {"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec" }; double lat, lon, height, re, rp; // Allocate memory for metadata structure meta = raw_init(); // General block strcpy(meta->general->basename, radarsat2->filename); strcpy(meta->general->sensor, radarsat2->satellite); strcpy(meta->general->sensor_name, radarsat2->sensor); strcpy(meta->general->mode, radarsat2->beamModeMnemonic); sprintf(meta->general->processor, "%s %s", radarsat2->processingFacility, radarsat2->softwareVersion); meta->general->data_type = REAL32; if (strcmp_case(radarsat2->dataType, "COMPLEX") == 0) meta->general->image_data_type = COMPLEX_IMAGE; //else if (strcmp_case(radarsat2->dataType, "DETECTED") == 0) // meta->general->image_data_type = AMPLITUDE_IMAGE; meta->general->radiometry = r_AMP; date_terrasar2date(radarsat2->zeroDopplerAzimuthTime, &date, &time); sprintf(meta->general->acquisition_date, "%02d-%s-%4d %02d:%02d:%02.0f", date.day, mon[date.month], date.year, time.hour, time.min, time.sec); //meta->general->orbit = radarsat2->absOrbit; if (strcmp_case(radarsat2->passDirection, "ASCENDING") == 0) meta->general->orbit_direction = 'A'; else if (strcmp_case(radarsat2->passDirection, "DESCENDING") == 0) meta->general->orbit_direction = 'D'; if (strcmp_case(radarsat2->dataType, "COMPLEX") == 0) meta->general->band_count = radarsat2->band_count * 2; else meta->general->band_count = radarsat2->band_count; strcpy(meta->general->bands, radarsat2->bands); meta->general->line_count = radarsat2->numberOfLines; meta->general->sample_count = radarsat2->numberOfSamplesPerLine; meta->general->start_line = 0; meta->general->start_sample = 0; meta->general->x_pixel_size = radarsat2->sampledPixelSpacing; meta->general->y_pixel_size = radarsat2->sampledLineSpacing; //meta->general->center_latitude = radarsat2->sceneCenterCoordLat; //meta->general->center_longitude = radarsat2->sceneCenterCoordLon; meta->general->re_major = radarsat2->semiMajorAxis; meta->general->re_minor = radarsat2->semiMinorAxis; // SAR block meta->sar = meta_sar_init(); if (strcmp_case(radarsat2->productType, "SLC") == 0) meta->sar->image_type = 'S'; if (strcmp_case(radarsat2->antennaPointing, "LEFT") == 0) meta->sar->look_direction = 'L'; else if (strcmp_case(radarsat2->antennaPointing, "RIGHT") == 0) meta->sar->look_direction = 'R'; meta->sar->azimuth_look_count = radarsat2->numberOfAzimuthLooks; meta->sar->range_look_count = radarsat2->numberOfRangeLooks; meta->sar->deskewed = 1; meta->sar->original_line_count = meta->general->line_count; meta->sar->original_sample_count = meta->general->sample_count; meta->sar->line_increment = 1; meta->sar->sample_increment = 1; date_terrasar2date(radarsat2->zeroDopplerTimeFirstLine, &imgStartDate, &imgStartTime); date_terrasar2date(radarsat2->zeroDopplerTimeLastLine, &imgStopDate, &imgStopTime); meta->sar->azimuth_time_per_pixel = date_difference(&imgStopDate, &imgStopTime, &imgStartDate, &imgStartTime) / meta->general->line_count; meta->sar->range_time_per_pixel = meta->general->x_pixel_size * 2.0 / speedOfLight; meta->sar->slant_range_first_pixel = radarsat2->slantRangeNearEdge; meta->sar->slant_shift = 0.0; meta->sar->time_shift = 0.0; meta->sar->wavelength = SPD_LIGHT / radarsat2->radarCenterFrequency; meta->sar->prf = radarsat2->pulseRepetitionFrequency; meta->sar->satellite_height = radarsat2->satelliteHeight; meta->sar->azimuth_processing_bandwidth = radarsat2->totalProcessedAzimuthBandwidth; // FIXME: chirp_rate ??? meta->sar->pulse_duration = radarsat2->pulseLength; meta->sar->range_sampling_rate = radarsat2->adcSamplingRate; if (strcmp_case(radarsat2->polarizations, "HH,VV,HV,VH") == 0) { meta->general->image_data_type = POLARIMETRIC_IMAGE; strcpy(meta->sar->polarization, "quad-pol"); } else strcpy(meta->sar->polarization, radarsat2->polarizations); if (strcmp_case(radarsat2->dataType, "COMPLEX") == 0) meta->sar->multilook = FALSE; // FIXME: pitch, roll, yaw ??? // Doppler block meta->doppler = radarsat2->doppler; // State vectors meta->state_vectors = radarsat2->state_vectors; // Propagate the state vectors to start, center, end int vector_count = 3; double data_int = date_difference(&imgStopDate, &imgStopTime, &imgStartDate, &imgStartTime) / 2.0; while (fabs(data_int) > 10.0) { data_int /= 2; vector_count = vector_count*2-1; } propagate_state(meta, vector_count, data_int); // Location block meta->location = meta_location_init(); meta->location->lat_start_near_range = radarsat2->sceneCornerCoord1Lat; meta->location->lon_start_near_range = radarsat2->sceneCornerCoord1Lon; meta->location->lat_start_far_range = radarsat2->sceneCornerCoord2Lat; meta->location->lon_start_far_range = radarsat2->sceneCornerCoord2Lon; meta->location->lat_end_near_range = radarsat2->sceneCornerCoord3Lat; meta->location->lon_end_near_range = radarsat2->sceneCornerCoord3Lon; meta->location->lat_end_far_range = radarsat2->sceneCornerCoord4Lat; meta->location->lon_end_far_range = radarsat2->sceneCornerCoord4Lon; // Still need to determine center location, really only needed to get // the earth radius straight meta->general->center_longitude = (radarsat2->sceneCornerCoord1Lon + radarsat2->sceneCornerCoord2Lon + radarsat2->sceneCornerCoord3Lon + radarsat2->sceneCornerCoord4Lon) / 4.0; location_to_latlon(meta, meta->general->sample_count/2, meta->general->line_count/2, 0.0, &lat, &lon, &height); meta->general->center_latitude = lat; meta->general->center_longitude = lon; lat = meta->general->center_latitude * D2R; re = meta->general->re_major; rp = meta->general->re_minor; meta->sar->earth_radius = (re*rp) / sqrt(rp*rp*cos(lat)*cos(lat)+re*re*sin(lat)*sin(lat)); meta->sar->satellite_height += meta->sar->earth_radius; return meta; }
void lwip_init(u8_t* lwip_memory){ sys_sem_t sem; extern u8_t** ADI_TOOLS_ram_ptr; extern u32_t ADI_TOOLS_ram_len; extern u8_t** ADI_TOOLS_memp_ptr; extern u32_t ADI_TOOLS_memp_len; extern u8_t** ADI_TOOLS_pbuf_pool_ptr; extern u32_t ADI_TOOLS_pbuf_pool_len; // caller must ensure that the area of memory supplied as 'lwip_memory' // is at least as long as the sum of the 'len' values *ADI_TOOLS_ram_ptr = lwip_memory; *ADI_TOOLS_memp_ptr = lwip_memory + ADI_TOOLS_ram_len; stats_init(); sys_init(); mem_init(); memp_init(); pbuf_init(); netif_init(); sys_sem_new(&sem,0); tcpip_init(tcpip_init_done, &sem); sys_sem_wait(&sem); sys_sem_free(&sem); #if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP //tcp_init(); #endif /* LWIP_TCP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ }
PACK_STRUCT_END #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/epstruct.h" #endif #define PACKED_STRUCT_TEST_EXPECTED_SIZE 5 #endif /* Compile-time sanity checks for configuration errors. * These can be done independently of LWIP_DEBUG, without penalty. */ #ifndef BYTE_ORDER #error "BYTE_ORDER is not defined, you have to define it in your cc.h" #endif #if (!IP_SOF_BROADCAST && IP_SOF_BROADCAST_RECV) #error "If you want to use broadcast filter per pcb on recv operations, you have to define IP_SOF_BROADCAST=1 in your lwipopts.h" #endif #if (!LWIP_UDP && LWIP_UDPLITE) #error "If you want to use UDP Lite, you have to define LWIP_UDP=1 in your lwipopts.h" #endif #if (!LWIP_UDP && LWIP_DHCP) #error "If you want to use DHCP, you have to define LWIP_UDP=1 in your lwipopts.h" #endif #if (!LWIP_UDP && LWIP_MULTICAST_TX_OPTIONS) #error "If you want to use IGMP/LWIP_MULTICAST_TX_OPTIONS, you have to define LWIP_UDP=1 in your lwipopts.h" #endif #if (!LWIP_UDP && LWIP_DNS) #error "If you want to use DNS, you have to define LWIP_UDP=1 in your lwipopts.h" #endif #if !MEMP_MEM_MALLOC /* MEMP_NUM_* checks are disabled when not using the pool allocator */ #if (LWIP_ARP && ARP_QUEUEING && (MEMP_NUM_ARP_QUEUE<=0)) #error "If you want to use ARP Queueing, you have to define MEMP_NUM_ARP_QUEUE>=1 in your lwipopts.h" #endif #if (LWIP_RAW && (MEMP_NUM_RAW_PCB<=0)) #error "If you want to use RAW, you have to define MEMP_NUM_RAW_PCB>=1 in your lwipopts.h" #endif #if (LWIP_UDP && (MEMP_NUM_UDP_PCB<=0)) #error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h" #endif #if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0)) #error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h" #endif #if (LWIP_IGMP && (MEMP_NUM_IGMP_GROUP<=1)) #error "If you want to use IGMP, you have to define MEMP_NUM_IGMP_GROUP>1 in your lwipopts.h" #endif #if (LWIP_IGMP && !LWIP_MULTICAST_TX_OPTIONS) #error "If you want to use IGMP, you have to define LWIP_MULTICAST_TX_OPTIONS==1 in your lwipopts.h" #endif #if (LWIP_IGMP && !LWIP_IPV4) #error "IGMP needs LWIP_IPV4 enabled in your lwipopts.h" #endif #if (LWIP_MULTICAST_TX_OPTIONS && !LWIP_IPV4) #error "LWIP_MULTICAST_TX_OPTIONS needs LWIP_IPV4 enabled in your lwipopts.h" #endif #if ((LWIP_NETCONN || LWIP_SOCKET) && (MEMP_NUM_TCPIP_MSG_API<=0)) #error "If you want to use Sequential API, you have to define MEMP_NUM_TCPIP_MSG_API>=1 in your lwipopts.h" #endif /* There must be sufficient timeouts, taking into account requirements of the subsystems. */ #if LWIP_TIMERS && (MEMP_NUM_SYS_TIMEOUT < (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0))) #error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts" #endif #if (IP_REASSEMBLY && (MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS)) #error "MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS doesn't make sense since each struct ip_reassdata must hold 2 pbufs at least!" #endif #endif /* !MEMP_MEM_MALLOC */ #if LWIP_WND_SCALE #if (LWIP_TCP && (TCP_WND > 0xffffffff)) #error "If you want to use TCP, TCP_WND must fit in an u32_t, so, you have to reduce it in your lwipopts.h" #endif #if (LWIP_TCP && LWIP_WND_SCALE && (TCP_RCV_SCALE > 14)) #error "The maximum valid window scale value is 14!" #endif #if (LWIP_TCP && (TCP_WND > (0xFFFFU << TCP_RCV_SCALE))) #error "TCP_WND is bigger than the configured LWIP_WND_SCALE allows!" #endif #if (LWIP_TCP && ((TCP_WND >> TCP_RCV_SCALE) == 0)) #error "TCP_WND is too small for the configured LWIP_WND_SCALE (results in zero window)!" #endif #else /* LWIP_WND_SCALE */ #if (LWIP_TCP && (TCP_WND > 0xffff)) #error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h (or enable window scaling)" #endif #endif /* LWIP_WND_SCALE */ #if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff)) #error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h" #endif #if (LWIP_TCP && (TCP_SND_QUEUELEN < 2)) #error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work" #endif #if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12))) #error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h" #endif #if (LWIP_TCP && TCP_LISTEN_BACKLOG && ((TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff))) #error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t" #endif #if (LWIP_NETIF_API && (NO_SYS==1)) #error "If you want to use NETIF API, you have to define NO_SYS=0 in your lwipopts.h" #endif #if ((LWIP_SOCKET || LWIP_NETCONN) && (NO_SYS==1)) #error "If you want to use Sequential API, you have to define NO_SYS=0 in your lwipopts.h" #endif #if (LWIP_PPP_API && (NO_SYS==1)) #error "If you want to use PPP API, you have to define NO_SYS=0 in your lwipopts.h" #endif #if (LWIP_PPP_API && (PPP_SUPPORT==0)) #error "If you want to use PPP API, you have to enable PPP_SUPPORT in your lwipopts.h" #endif #if (((!LWIP_DHCP) || (!LWIP_AUTOIP)) && LWIP_DHCP_AUTOIP_COOP) #error "If you want to use DHCP/AUTOIP cooperation mode, you have to define LWIP_DHCP=1 and LWIP_AUTOIP=1 in your lwipopts.h" #endif #if (((!LWIP_DHCP) || (!LWIP_ARP)) && DHCP_DOES_ARP_CHECK) #error "If you want to use DHCP ARP checking, you have to define LWIP_DHCP=1 and LWIP_ARP=1 in your lwipopts.h" #endif #if (!LWIP_ARP && LWIP_AUTOIP) #error "If you want to use AUTOIP, you have to define LWIP_ARP=1 in your lwipopts.h" #endif #if (LWIP_TCP && ((LWIP_EVENT_API && LWIP_CALLBACK_API) || (!LWIP_EVENT_API && !LWIP_CALLBACK_API))) #error "One and exactly one of LWIP_EVENT_API and LWIP_CALLBACK_API has to be enabled in your lwipopts.h" #endif #if (MEM_LIBC_MALLOC && MEM_USE_POOLS) #error "MEM_LIBC_MALLOC and MEM_USE_POOLS may not both be simultaneously enabled in your lwipopts.h" #endif #if (MEM_USE_POOLS && !MEMP_USE_CUSTOM_POOLS) #error "MEM_USE_POOLS requires custom pools (MEMP_USE_CUSTOM_POOLS) to be enabled in your lwipopts.h" #endif #if (PBUF_POOL_BUFSIZE <= MEM_ALIGNMENT) #error "PBUF_POOL_BUFSIZE must be greater than MEM_ALIGNMENT or the offset may take the full first pbuf" #endif #if (DNS_LOCAL_HOSTLIST && !DNS_LOCAL_HOSTLIST_IS_DYNAMIC && !(defined(DNS_LOCAL_HOSTLIST_INIT))) #error "you have to define define DNS_LOCAL_HOSTLIST_INIT {{'host1', 0x123}, {'host2', 0x234}} to initialize DNS_LOCAL_HOSTLIST" #endif #if PPP_SUPPORT && !PPPOS_SUPPORT && !PPPOE_SUPPORT && !PPPOL2TP_SUPPORT #error "PPP_SUPPORT needs at least one of PPPOS_SUPPORT, PPPOE_SUPPORT or PPPOL2TP_SUPPORT turned on" #endif #if PPP_SUPPORT && !PPP_IPV4_SUPPORT && !PPP_IPV6_SUPPORT #error "PPP_SUPPORT needs PPP_IPV4_SUPPORT and/or PPP_IPV6_SUPPORT turned on" #endif #if PPP_SUPPORT && PPP_IPV4_SUPPORT && !LWIP_IPV4 #error "PPP_IPV4_SUPPORT needs LWIP_IPV4 turned on" #endif #if PPP_SUPPORT && PPP_IPV6_SUPPORT && !LWIP_IPV6 #error "PPP_IPV6_SUPPORT needs LWIP_IPV6 turned on" #endif #if !LWIP_ETHERNET && (LWIP_ARP || PPPOE_SUPPORT) #error "LWIP_ETHERNET needs to be turned on for LWIP_ARP or PPPOE_SUPPORT" #endif #if (LWIP_IGMP || LWIP_IPV6) && !defined(LWIP_RAND) #error "When using IGMP or IPv6, LWIP_RAND() needs to be defined to a random-function returning an u32_t random value (in arch/cc.h)" #endif #if LWIP_TCPIP_CORE_LOCKING_INPUT && !LWIP_TCPIP_CORE_LOCKING #error "When using LWIP_TCPIP_CORE_LOCKING_INPUT, LWIP_TCPIP_CORE_LOCKING must be enabled, too" #endif #if LWIP_TCP && LWIP_NETIF_TX_SINGLE_PBUF && !TCP_OVERSIZE #error "LWIP_NETIF_TX_SINGLE_PBUF needs TCP_OVERSIZE enabled to create single-pbuf TCP packets" #endif #if LWIP_NETCONN && LWIP_TCP #if NETCONN_COPY != TCP_WRITE_FLAG_COPY #error "NETCONN_COPY != TCP_WRITE_FLAG_COPY" #endif #if NETCONN_MORE != TCP_WRITE_FLAG_MORE #error "NETCONN_MORE != TCP_WRITE_FLAG_MORE" #endif #endif /* LWIP_NETCONN && LWIP_TCP */ #if LWIP_SOCKET /* Check that the SO_* socket options and SOF_* lwIP-internal flags match */ #if SO_REUSEADDR != SOF_REUSEADDR #error "WARNING: SO_REUSEADDR != SOF_REUSEADDR" #endif #if SO_KEEPALIVE != SOF_KEEPALIVE #error "WARNING: SO_KEEPALIVE != SOF_KEEPALIVE" #endif #if SO_BROADCAST != SOF_BROADCAST #error "WARNING: SO_BROADCAST != SOF_BROADCAST" #endif #endif /* LWIP_SOCKET */ /* Compile-time checks for deprecated options. */ #ifdef MEMP_NUM_TCPIP_MSG #error "MEMP_NUM_TCPIP_MSG option is deprecated. Remove it from your lwipopts.h." #endif #ifdef TCP_REXMIT_DEBUG #error "TCP_REXMIT_DEBUG option is deprecated. Remove it from your lwipopts.h." #endif #ifdef RAW_STATS #error "RAW_STATS option is deprecated. Remove it from your lwipopts.h." #endif #ifdef ETHARP_QUEUE_FIRST #error "ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h." #endif #ifdef ETHARP_ALWAYS_INSERT #error "ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h." #endif #if !NO_SYS && LWIP_TCPIP_CORE_LOCKING && LWIP_COMPAT_MUTEX && !defined(LWIP_COMPAT_MUTEX_ALLOWED) #error "LWIP_COMPAT_MUTEX cannot prevent priority inversion. It is recommended to implement priority-aware mutexes. (Define LWIP_COMPAT_MUTEX_ALLOWED to disable this error.)" #endif #ifndef LWIP_DISABLE_TCP_SANITY_CHECKS #define LWIP_DISABLE_TCP_SANITY_CHECKS 0 #endif #ifndef LWIP_DISABLE_MEMP_SANITY_CHECKS #define LWIP_DISABLE_MEMP_SANITY_CHECKS 0 #endif /* MEMP sanity checks */ #if MEMP_MEM_MALLOC #if !LWIP_DISABLE_MEMP_SANITY_CHECKS #if LWIP_NETCONN || LWIP_SOCKET #if !MEMP_NUM_NETCONN && LWIP_SOCKET #error "lwip_sanity_check: WARNING: MEMP_NUM_NETCONN cannot be 0 when using sockets!" #endif #else /* MEMP_MEM_MALLOC */ #if MEMP_NUM_NETCONN > (MEMP_NUM_TCP_PCB+MEMP_NUM_TCP_PCB_LISTEN+MEMP_NUM_UDP_PCB+MEMP_NUM_RAW_PCB) #error "lwip_sanity_check: WARNING: MEMP_NUM_NETCONN should be less than the sum of MEMP_NUM_{TCP,RAW,UDP}_PCB+MEMP_NUM_TCP_PCB_LISTEN. If you know what you are doing, define LWIP_DISABLE_MEMP_SANITY_CHECKS to 1 to disable this error." #endif #endif /* LWIP_NETCONN || LWIP_SOCKET */ #endif /* !LWIP_DISABLE_MEMP_SANITY_CHECKS */ #if MEM_USE_POOLS #error "MEMP_MEM_MALLOC and MEM_USE_POOLS cannot be enabled at the same time" #endif #ifdef LWIP_HOOK_MEMP_AVAILABLE #error "LWIP_HOOK_MEMP_AVAILABLE doesn't make sense with MEMP_MEM_MALLOC" #endif #endif /* MEMP_MEM_MALLOC */ /* TCP sanity checks */ #if !LWIP_DISABLE_TCP_SANITY_CHECKS #if LWIP_TCP #if !MEMP_MEM_MALLOC && (MEMP_NUM_TCP_SEG < TCP_SND_QUEUELEN) #error "lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_SND_BUF < (2 * TCP_MSS) #error "lwip_sanity_check: WARNING: TCP_SND_BUF must be at least as much as (2 * TCP_MSS) for things to work smoothly. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_SND_QUEUELEN < (2 * (TCP_SND_BUF / TCP_MSS)) #error "lwip_sanity_check: WARNING: TCP_SND_QUEUELEN must be at least as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_SNDLOWAT >= TCP_SND_BUF #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than TCP_SND_BUF. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_SNDLOWAT >= (0xFFFF - (4 * TCP_MSS)) #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must at least be 4*MSS below u16_t overflow!" #endif #if TCP_SNDQUEUELOWAT >= TCP_SND_QUEUELEN #error "lwip_sanity_check: WARNING: TCP_SNDQUEUELOWAT must be less than TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (PBUF_POOL_BUFSIZE <= (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)) #error "lwip_sanity_check: WARNING: PBUF_POOL_BUFSIZE does not provide enough space for protocol headers. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (TCP_WND > (PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)))) #error "lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - protocol headers). If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_WND < TCP_MSS #error "lwip_sanity_check: WARNING: TCP_WND is smaller than MSS. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #endif /* LWIP_TCP */ #endif /* !LWIP_DISABLE_TCP_SANITY_CHECKS */ /** * @ingroup lwip_nosys * Initialize all modules. * Use this in NO_SYS mode. Use tcpip_init() otherwise. */ void lwip_init(void) { #ifndef LWIP_SKIP_PACKING_CHECK LWIP_ASSERT("Struct packing not implemented correctly. Check your lwIP port.", sizeof(struct packed_struct_test) == PACKED_STRUCT_TEST_EXPECTED_SIZE); #endif /* Modules initialization */ stats_init(); #if !NO_SYS sys_init(); #endif /* !NO_SYS */ mem_init(); memp_init(); pbuf_init(); netif_init(); #if LWIP_IPV4 ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #endif /* LWIP_IPV4 */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ #if PPP_SUPPORT ppp_init(); #endif #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ }
meta_parameters* terrasar2meta(terrasar_meta *terrasar) { ymd_date date, imgStartDate, imgStopDate; hms_time time, imgStartTime, imgStopTime; meta_parameters *meta; char *mon[13]={"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec"}; double lat, re, rp; // Allocate memory for metadata structure meta = raw_init(); // General block strcpy(meta->general->basename, terrasar->filename); strcpy(meta->general->sensor, terrasar->mission); strcpy(meta->general->sensor_name, terrasar->sensor); strcpy(meta->general->mode, terrasar->elevationBeamConfiguration); strcpy(meta->general->processor, ""); // terrsar->imagingMode determines stripMap, scanSAR and spotLight modes // not using the information yet meta->general->data_type = REAL32; if (strcmp_case(terrasar->imageDataType, "COMPLEX") == 0) meta->general->image_data_type = COMPLEX_IMAGE; else if (strcmp_case(terrasar->imageDataType, "DETECTED") == 0) meta->general->image_data_type = AMPLITUDE_IMAGE; meta->general->radiometry = r_AMP; date_terrasar2date(terrasar->azimuthTimeUTC, &date, &time); sprintf(meta->general->acquisition_date, "%02d-%s-%4d %02d:%02d:%02.0f", date.day, mon[date.month], date.year, time.hour, time.min, time.sec); meta->general->orbit = terrasar->absOrbit; if (strcmp_case(terrasar->orbitDirection, "ASCENDING") == 0) meta->general->orbit_direction = 'A'; else if (strcmp_case(terrasar->orbitDirection, "DESCENDING") == 0) meta->general->orbit_direction = 'D'; meta->general->band_count = terrasar->numberOfLayers; meta->general->line_count = terrasar->numberOfRows; meta->general->sample_count = terrasar->numberOfColumns; meta->general->start_line = 0; meta->general->start_sample = 0; meta->general->x_pixel_size = terrasar->rangeResolution; meta->general->y_pixel_size = terrasar->azimuthResolution; meta->general->center_latitude = terrasar->sceneCenterCoordLat; meta->general->center_longitude = terrasar->sceneCenterCoordLon; meta->general->re_major = 6378137.000; // WGS84 meta->general->re_minor = 6356752.314; // WGS84 // SAR block meta->sar = meta_sar_init(); if (strcmp_case(terrasar->projection, "SLANTRANGE") == 0) meta->sar->image_type = 'S'; else if (strcmp_case(terrasar->projection, "GROUNDRANGE") == 0) meta->sar->image_type = 'G'; // FIXME: MAP case not covered yet if (strcmp_case(terrasar->lookDirection, "LEFT") == 0) meta->sar->look_direction = 'L'; else if (strcmp_case(terrasar->lookDirection, "RIGHT") == 0) meta->sar->look_direction = 'R'; meta->sar->azimuth_look_count = terrasar->azimuthLooks; meta->sar->range_look_count = terrasar->rangeLooks; if (strcmp_case(terrasar->imageCoordinateType, "ZERODOPPLER") == 0) meta->sar->deskewed = 1; meta->sar->original_line_count = meta->general->line_count; meta->sar->original_sample_count = meta->general->sample_count; meta->sar->line_increment = 1; meta->sar->sample_increment = 1; if (meta->sar->image_type == 'S') { meta->sar->range_time_per_pixel = terrasar->rowSpacing; meta->sar->azimuth_time_per_pixel = terrasar->columnSpacing; } else if (meta->sar->image_type == 'G') { meta->sar->range_time_per_pixel = (terrasar->rangeTimeLast - terrasar->rangeTimeFirst) / terrasar->numberOfColumns; meta->general->x_pixel_size = terrasar->columnSpacing; meta->general->y_pixel_size = terrasar->rowSpacing; } meta->sar->slant_range_first_pixel = terrasar->rangeTimeFirst * SPD_LIGHT / 2.0; meta->sar->slant_shift = 0.0; meta->sar->time_shift = 0.0; meta->sar->wavelength = SPD_LIGHT / terrasar->centerFrequency; meta->sar->prf = terrasar->prf; lat = meta->general->center_latitude * D2R; re = meta->general->re_major; rp = meta->general->re_minor; meta->sar->earth_radius = (re*rp) / sqrt(rp*rp*cos(lat)*cos(lat)+re*re*sin(lat)*sin(lat)); // FIXME: Doppler values need to be filled in meta->sar->azimuth_processing_bandwidth = terrasar->totalProcessedAzimuthBandwidth; // FIXME: chirp_rate ??? meta->sar->pulse_duration = terrasar->pulseLength; meta->sar->range_sampling_rate = terrasar->rsf; strcpy(meta->sar->polarization, terrasar->polarisationMode); if (strcmp_case(terrasar->imageDataType, "COMPLEX") == 0) meta->sar->multilook = FALSE; else if (strcmp_case(terrasar->imageDataType, "DETECTED") == 0) meta->sar->multilook = TRUE; // FIXME: pitch, roll, yaw ??? // Doppler block meta->doppler = terrasar->doppler; // State vectors meta->state_vectors = terrasar->state_vectors; // Propagate the state vectors to start, center, end date_terrasar2date(terrasar->sceneStart, &imgStartDate, &imgStartTime); date_terrasar2date(terrasar->sceneStop, &imgStopDate, &imgStopTime); int vector_count = 3; double data_int = date_difference(&imgStopDate, &imgStopTime, &imgStartDate, &imgStartTime) / 2.0; while (fabs(data_int) > 10.0) { data_int /= 2; vector_count = vector_count*2-1; } propagate_state(meta, vector_count, data_int); data_int = date_difference(&imgStopDate, &imgStopTime, &imgStartDate, &imgStartTime); if (meta->sar->image_type == 'G') meta->sar->azimuth_time_per_pixel = data_int / meta->general->line_count; if (meta->general->orbit_direction == 'A') { meta->sar->time_shift = data_int; meta->sar->azimuth_time_per_pixel *= -1.0; } data_int /= 2.0; stateVector stVec = meta_get_stVec(meta, data_int); meta->sar->satellite_height = sqrt(stVec.pos.x * stVec.pos.x + stVec.pos.y * stVec.pos.y + stVec.pos.z * stVec.pos.z); // Location block meta->location = meta_location_init(); meta->location->lat_start_near_range = terrasar->sceneCornerCoord1Lat; meta->location->lon_start_near_range = terrasar->sceneCornerCoord1Lon; meta->location->lat_start_far_range = terrasar->sceneCornerCoord2Lat; meta->location->lon_start_far_range = terrasar->sceneCornerCoord2Lon; meta->location->lat_end_near_range = terrasar->sceneCornerCoord3Lat; meta->location->lon_end_near_range = terrasar->sceneCornerCoord3Lon; meta->location->lat_end_far_range = terrasar->sceneCornerCoord4Lat; meta->location->lon_end_far_range = terrasar->sceneCornerCoord4Lon; return meta; }
meta_parameters *read_meta_gridfloat_ext(char *inBaseName, char *flt_file, int *column_count, int *row_count) { // all three of these must be present char *hdr_file = appendExt(inBaseName, ".hdr"); char *prj_file = appendExt(inBaseName, ".prj"); flt_file = appendExt(inBaseName, ".flt"); if (!fileExists(flt_file) || !fileExists(hdr_file) || !fileExists(prj_file)) { asfPrintError( "The BIL and/or associated metadata files were not found:\n" " FLT File: %s %s\n" " PRJ File: %s %s\n" " HDR File: %s %s\n", flt_file, fileExists(flt_file) ? "Found" : "NOT FOUND", prj_file, fileExists(prj_file) ? "Found" : "NOT FOUND", hdr_file, fileExists(hdr_file) ? "Found" : "NOT FOUND"); } asfPrintStatus("Parsing %s ...\n", hdr_file); // Info we'll get from the header file int nrows=-1; int ncols=-1; double cell_size = 0; double lat_ll = -999; double lon_ll = -999; double nodata = -9999; int msbfirst = FALSE; // Read header file char line[1024], value[1024]; FILE *fp = FOPEN(hdr_file, "r"); while (NULL!=fgets(line, 1024, fp)) { if (matches(line, "ncols")) { get_value(line, value); ncols = atoi(value); } else if (matches(line, "nrows")) { get_value(line, value); nrows = atoi(value); } else if (matches(line, "xllcorner")) { get_value(line, value); lon_ll = atof(value); } else if (matches(line, "yllcorner")) { get_value(line, value); lat_ll = atof(value); } else if (matches(line, "cellsize")) { get_value(line, value); cell_size = atof(value); } else if (matches(line, "NODATA_value")) { get_value(line, value); nodata = atof(value); } else if (matches(line, "byteorder")) { get_value(line, value); if (strcmp(value, "LSBFIRST") == 0) { msbfirst = FALSE; } else if (strcmp(value, "MSBFIRST") == 0) { msbfirst = TRUE; } else { asfPrintError("Unsupported byte order (should be 'LSBFIRST' or 'MSBFIRST'): %s\n", value); } } } fclose(fp); if (nrows < 0 || ncols < 0) { asfPrintError( "Header file did not contain Row/Column infomation.\n" "It is a valid .HDR file?\n"); } // PRJ File asfPrintStatus("Parsing %s ...\n", prj_file); datum_type_t datum=UNKNOWN_DATUM; spheroid_type_t spheroid=UNKNOWN_SPHEROID; fp = FOPEN(prj_file, "r"); while (NULL!=fgets(line, 1024, fp)) { if (matches(line, "Projection")) { get_value(line, value); if (strcmp(value, "GEOGRAPHIC") != 0) asfPrintError("Unsupported byte order (should be GEOGRAPHIC): %s\n", value); } else if (matches(line, "Units")) { get_value(line, value); if (strcmp(value, "DD") != 0) asfPrintError("Unsupported Units (should be DD): %s\n", value); } else if (matches(line, "Zunits")) { get_value(line, value); if (strcmp(value, "METERS") != 0) asfPrintError("Unsupported Zunits (should be METERS): %s\n", value); } else if (matches(line, "Datum")) { get_value(line, value); if (strcmp_case(value, "NAD27") == 0) datum = NAD27_DATUM; else if (strcmp_case(value, "NAD83") == 0) datum = NAD83_DATUM; else if (strcmp_case(value, "WGS83") == 0) datum = WGS84_DATUM; else asfPrintError( "Unsupported Datum (should be NAD27, NAD83, or WGS84): %s\n", value); } else if (matches(line, "Spheroid")) { get_value(line, value); if (strcmp_case(value, "CLARKE1866") == 0) spheroid = CLARKE1866_SPHEROID; else if (strcmp_case(value, "BESSEL") == 0) spheroid = BESSEL_SPHEROID; else if (strcmp_case(value, "CLARKE1880") == 0) spheroid = CLARKE1880_SPHEROID; else if (strcmp_case(value, "GEM6") == 0) spheroid = GEM6_SPHEROID; else if (strcmp_case(value, "GEM10C") == 0) spheroid = GEM10C_SPHEROID; else if (strcmp_case(value, "GRS1980") == 0) spheroid = GRS1980_SPHEROID; else if (strcmp_case(value, "WGS72") == 0) spheroid = WGS72_SPHEROID; else if (strcmp_case(value, "WGS84") == 0) spheroid = WGS84_SPHEROID; else if (strcmp_case(value, "INTERNATIONAL1924") == 0) spheroid = INTERNATIONAL1924_SPHEROID; else if (strcmp_case(value, "INTERNATIONAL1967") == 0) spheroid = INTERNATIONAL1967_SPHEROID; else asfPrintError("Unsupported Spheroid: %s\n", value); } } fclose(fp); meta_parameters *meta = raw_init(); meta->projection = meta_projection_init(); meta->location = meta_location_init(); // aliases meta_general *mg = meta->general; meta_projection *mp = meta->projection; meta_location *ml = meta->location; // populate general block info mg->data_type = REAL32; mg->image_data_type = DEM; //presumably!? mg->no_data = nodata; // these are supposed to be in meters // currently, cell_size_* is in arcsecs... so here is a kludgey // calculation, to round to the nearest 10m. usgs data is either // 30, 60, or 90 meter. // Note that the projection block will have the actual pixel size int cell_size_m = 10 * (int)(11131.95 * cell_size + .5); if (cell_size_m != 30 && cell_size_m != 60 && cell_size_m != 90) { asfPrintWarning("Unexpected pixel size of %dm (%.10f degree) detected.\n" "USGS Seamless data should be 30, 60, or 90 meter.\n", cell_size_m, cell_size); } mg->x_pixel_size = cell_size_m; mg->y_pixel_size = cell_size_m; mg->line_count = nrows; mg->sample_count = ncols; mg->band_count = 1; mg->start_line = 0; mg->start_sample = 0; char *basename = get_basename(inBaseName); strcpy(mg->basename, basename); free(basename); strcpy(mg->sensor, "USGS Seamless data (e.g., NED, STRM)"); strcpy(mg->mode, "N/A"); strcpy(mg->processor, "Unknown"); mg->center_latitude = lat_ll + cell_size * ncols / 2.0; mg->center_longitude = lon_ll + cell_size * nrows / 2.0; // populate projection block info mp->type = LAT_LONG_PSEUDO_PROJECTION; mp->startX = lon_ll; mp->startY = lat_ll + cell_size * nrows; mp->perX = cell_size; mp->perY = -cell_size; strcpy(mp->units, "degrees"); mp->hem = mg->center_latitude > 0 ? 'N' : 'S'; // the datum for NED is NAD83, for SRTM it is WGS84 mp->datum = datum; mp->spheroid = spheroid; spheroid_axes_lengths(spheroid, &mg->re_major, &mg->re_minor); mp->re_major = mg->re_major; mp->re_minor = mg->re_minor; // location block ml->lon_start_near_range = mp->startX; ml->lat_start_near_range = mp->startY; ml->lon_start_far_range = mp->startX + mp->perX * ncols; ml->lat_start_far_range = mp->startY; ml->lon_end_near_range = mp->startX; ml->lat_end_near_range = mp->startY + mp->perY * nrows; ml->lon_end_far_range = mp->startX + mp->perX * ncols; ml->lat_end_far_range = mp->startY + mp->perY * nrows; free(hdr_file); free(prj_file); *column_count = ncols; *row_count = nrows; return meta; }
meta_parameters* uavsar_polsar2meta(uavsar_polsar *params) { meta_parameters *meta; // Allocate memory for metadata structure meta = raw_init(); // General block sprintf(meta->general->basename, "%s", params->site); sprintf(meta->general->sensor, "UAVSAR"); strcpy(meta->general->sensor_name, "PolSAR"); strcpy(meta->general->processor, "JPL version "); strcat(meta->general->processor, params->processor); if (params->type == POLSAR_SLC) { strcpy(meta->general->mode, "SLC"); meta->general->image_data_type = POLARIMETRIC_S2_MATRIX; } else if (params->type == POLSAR_MLC) { strcpy(meta->general->mode, "MLC"); meta->general->image_data_type = POLARIMETRIC_C3_MATRIX; } else if (params->type == POLSAR_DAT) { strcpy(meta->general->mode, "DAT"); meta->general->image_data_type = POLARIMETRIC_STOKES_MATRIX; } else if (params->type == POLSAR_GRD) { strcpy(meta->general->mode, "GRD"); meta->general->image_data_type = POLARIMETRIC_C3_MATRIX; meta->general->no_data = 0; } else if (params->type == POLSAR_HGT) { strcpy(meta->general->mode, "HGT"); meta->general->image_data_type = DEM; } else strcpy(meta->general->mode, "unknown"); meta->general->radiometry = r_GAMMA; meta->general->data_type = REAL32; strcpy(meta->general->acquisition_date, params->acquisition_date); meta->general->band_count = 1; meta->general->line_count = params->row_count; meta->general->sample_count = params->column_count; meta->general->start_line = 0; meta->general->start_sample = 0; meta->general->x_pixel_size = params->range_pixel_spacing; meta->general->y_pixel_size = fabs(params->azimuth_pixel_spacing); meta->general->re_major = params->semi_major; double re = params->semi_major; double ecc2 = params->eccentricity; double rp = sqrt((1-ecc2)*re*re); meta->general->re_minor = rp; // no information on bit error rate, missing lines and no data // SAR block meta->sar = meta_sar_init(); strcpy(meta->sar->polarization, "QUAD-POL"); if (strcmp_case(params->projection, "SCX") == 0) meta->sar->image_type = 'S'; else if (strcmp_case(params->projection, "EQA") == 0) meta->sar->image_type = 'P'; if (strcmp_case(params->look_direction, "Left") == 0) meta->sar->look_direction = 'L'; else if (strcmp_case(params->look_direction, "Right") == 0) meta->sar->look_direction = 'R'; if (params->type == POLSAR_SLC) { meta->sar->azimuth_look_count = 1; meta->sar->range_look_count = 1; meta->sar->multilook = 0; } else { // FIXME: Update once range look count is introduced to metadata structure meta->sar->azimuth_look_count = params->azimuth_look_count; meta->sar->range_look_count = params->range_look_count; meta->sar->multilook = 1; } meta->sar->deskewed = 1; meta->sar->original_line_count = params->row_count; meta->sar->original_sample_count = params->column_count; meta->sar->line_increment = 1; meta->sar->sample_increment = 1; // no information on azimuth and range time per pixel meta->sar->time_shift = 0.0; meta->sar->slant_shift = 0.0; meta->sar->slant_range_first_pixel = params->slant_range_first_pixel * 1000.0; meta->sar->wavelength = params->wavelength / 100.0; // no information on pulse repetition frequency double tan_lat = params->lat_peg_point*D2R; meta->sar->earth_radius = rp*sqrt(1 + tan_lat*tan_lat) / sqrt(rp*rp/(re*re) + tan_lat*tan_lat); // no information on satellite height // no time information // no Doppler information meta->sar->yaw = params->yaw; meta->sar->pitch = params->pitch; meta->sar->roll = params->roll; meta->sar->azimuth_processing_bandwidth = params->bandwidth; // no chirp rate information meta->sar->pulse_duration = params->pulse_length / 1000.0; // no information on range sampling rate // FIXME: check polarizations for interferometric/polarimetric data // FIXME: multilook flag depends on data type // UAVSAR block meta->uavsar = meta_uavsar_init(); strcpy(meta->uavsar->id, params->id); meta->uavsar->scale_factor = 1.0; meta->uavsar->gps_altitude = params->altitude; meta->uavsar->lat_peg_point = params->lat_peg_point; meta->uavsar->lon_peg_point = params->lon_peg_point; meta->uavsar->head_peg_point = params->head_peg_point; meta->uavsar->along_track_offset = params->along_track_offset; meta->uavsar->cross_track_offset = params->cross_track_offset; // Location block meta->location = meta_location_init(); meta->location->lat_start_near_range = params->lat_upper_left; meta->location->lon_start_near_range = params->lon_upper_left; meta->location->lat_start_far_range = params->lat_upper_right; meta->location->lon_start_far_range = params->lon_upper_right; meta->location->lat_end_near_range = params->lat_lower_left; meta->location->lon_end_near_range = params->lon_lower_left; meta->location->lat_end_far_range = params->lat_lower_right; meta->location->lon_end_far_range = params->lon_lower_right; // Projection block if (params->type == POLSAR_GRD || params->type == POLSAR_HGT) { meta->projection = meta_projection_init(); meta->projection->type = LAT_LONG_PSEUDO_PROJECTION; strcpy (meta->projection->units, "degrees"); if (params->along_track_offset >= 0.0) meta->projection->hem = 'N'; else meta->projection->hem = 'S'; meta->projection->re_major = meta->general->re_major; meta->projection->re_minor = meta->general->re_minor; meta->projection->height = 0.0; meta->projection->spheroid = WGS84_SPHEROID; meta->projection->datum = WGS84_DATUM; // Coordinate reference: Point // UAVSAR lat/lon projected data is calculated from center // pixel. Thus we have to add in a half-pixel shift. meta->projection->startX = params->cross_track_offset - params->range_pixel_spacing / 2.0; meta->projection->startY = params->along_track_offset - params->azimuth_pixel_spacing / 2.0; meta->projection->perX = params->range_pixel_spacing; meta->projection->perY = params->azimuth_pixel_spacing; meta->general->center_latitude = params->along_track_offset + params->azimuth_pixel_spacing * params->row_count / 2.0; meta->general->center_longitude = params->cross_track_offset + params->range_pixel_spacing * params->column_count / 2.0; } else { meta_get_latLon(meta, meta->general->line_count/2, meta->general->sample_count/2, 0, &meta->general->center_latitude, &meta->general->center_longitude); } return meta; }
meta_parameters* airsar2meta(airsar_header *header, airsar_param_header *params, airsar_dem_header *dem) { meta_parameters *meta; hms_time hms; // Allocate memory for metadata structure meta = raw_init(); // General block sprintf(meta->general->basename, "%s", params->site_name); sprintf(meta->general->sensor, "AIRSAR"); strcpy(meta->general->sensor_name, "SAR"); if (strlen(header->processor)>0) { header->processor[4] = '\0'; strcpy(meta->general->processor, "JPL version "); strcat(meta->general->processor, header->processor); } else { strcpy(meta->general->processor, MAGIC_UNSET_STRING); } // FIXME: various data types - InSAR vs. polarimetric date_sec2hms(params->acquisition_seconds, &hms); sprintf(meta->general->acquisition_date, "%s %d:%d:%.3lf", params->acquisition_date, hms.hour, hms.min, hms.sec); meta->general->orbit = params->cct_id; // close enough // no frame number // FIXME: decide how to separate interferometric/polarimetric data meta->general->band_count = 1; meta->general->line_count = header->line_count; //header->line_count - header->first_data_offset / header->sample_count; meta->general->sample_count = header->sample_count; meta->general->start_line = 0; meta->general->start_sample = 0; meta->general->x_pixel_size = header->x_pixel_size; meta->general->y_pixel_size = header->y_pixel_size; meta->general->center_latitude = params->center_lat; meta->general->center_longitude = params->center_lon; meta->general->re_major = 6378137.0; // WGS84 meta->general->re_minor = 6356752.314; // WGS84 // no information on bit error rate, missing lines and no data // SAR block meta->sar = meta_sar_init(); // The CCT type 'CM' stands for 'Compressed Stokes Matrix' which implies // that you have fully polarimetric data if (strncmp_case(params->cct_type, "CM", 2) == 0) { meta->general->image_data_type = POLARIMETRIC_IMAGE; meta->general->radiometry = r_SIGMA; strcpy(meta->sar->polarization, "QUAD-POL"); meta->general->band_count = 8; } if (strncmp_case(header->range_projection, "GROUND", 6) == 0) meta->sar->image_type = 'G'; // no information on look direction if (params->deskewed == 1) meta->sar->deskewed = 1; else if (params->deskewed == 2) meta->sar->deskewed = 0; meta->sar->original_line_count = header->line_count; meta->sar->original_sample_count = header->sample_count; meta->sar->line_increment = 1; meta->sar->sample_increment = 1; // no information on azimuth and range time per pixel // no information on slant and time shift meta->sar->slant_range_first_pixel = params->near_slant_range; meta->sar->wavelength = params->wavelength; meta->sar->prf = params->prf; // no information on earth radius and satellite height // no time information // no Doppler information meta->sar->azimuth_processing_bandwidth = params->chirp_bandwidth; // no chirp rate information meta->sar->pulse_duration = params->pulse_length; meta->sar->range_sampling_rate = params->range_sampling_rate; // FIXME: check polarizations for interferometric/polarimetric data // FIXME: multilook flag depends on data type // AirSAR block meta->airsar = meta_airsar_init(); meta->airsar->scale_factor = 1.0; // Bruce Chapman said so. meta->airsar->gps_altitude = params->gps_altitude; if (dem) { meta->airsar->lat_peg_point = dem->lat_peg_point; meta->airsar->lon_peg_point = dem->lon_peg_point; meta->airsar->head_peg_point = dem->head_peg_point; meta->airsar->along_track_offset = dem->along_track_offset; meta->airsar->cross_track_offset = dem->cross_track_offset; } else { meta->airsar->lat_peg_point = params->lat_peg_point; meta->airsar->lon_peg_point = params->lon_peg_point; meta->airsar->head_peg_point = params->head_peg_point; meta->airsar->along_track_offset = params->along_track_offset; meta->airsar->cross_track_offset = params->cross_track_offset; } // The DEM header of Rick's prime test data did not have a valid peg point. // Without that the other numbers (along-track and cross-track offsets // as well as corner coordinates) don't make sense. // Will take the numbers out of the parameter header. Seems to work fine // with the prime test data set. Extract only elevation offset and increment // out of the DEM header if (dem) { meta->airsar->elevation_increment = dem->elevation_increment; meta->airsar->elevation_offset = dem->elevation_offset; } // Location block meta->location = meta_location_init(); if (dem) { meta->location->lat_start_near_range = dem->corner1_lat; meta->location->lon_start_near_range = dem->corner1_lon; meta->location->lat_start_far_range = dem->corner2_lat; meta->location->lon_start_far_range = dem->corner2_lon; meta->location->lat_end_near_range = dem->corner4_lat; meta->location->lon_end_near_range = dem->corner4_lon; meta->location->lat_end_far_range = dem->corner3_lat; meta->location->lon_end_far_range = dem->corner3_lon; } return meta; }