void unit_setid(unit * u, int id) { unit *nu = findunit(id); if (nu == NULL) { uunhash(u); u->no = id; uhash(u); } }
static int use_museumexitticket(unit * u, const struct item_type *itype, int amount, order * ord) { attrib *a; region *r; unit *warden = findunit(atoi36("mwar")); int unit_cookie; unused_arg(amount); /* Prüfen ob in Eingangshalle */ if (u->region->x != 9525 || u->region->y != 9525) { cmistake(u, ord, 266, MSG_MAGIC); return 0; } a = a_find(u->attribs, &at_museumexit); assert(a); r = findregion(a->data.sa[0], a->data.sa[1]); assert(r); a_remove(&u->attribs, a); /* Übergebene Gegenstände zurückgeben */ a = a_find(u->attribs, &at_museumgivebackcookie); if (a) { unit_cookie = a->data.i; a_remove(&u->attribs, a); for (a = a_find(warden->attribs, &at_museumgiveback); a && a->type == &at_museumgiveback; a = a->next) { if (((museumgiveback *)(a->data.v))->cookie == unit_cookie) break; } if (a && a->type == &at_museumgiveback) { museumgiveback *gb = (museumgiveback *)(a->data.v); item *it; for (it = gb->items; it; it = it->next) { i_change(&u->items, it->type, it->number); } ADDMSG(&u->faction->msgs, msg_message("museumgiveback", "region unit sender items", r, u, warden, gb->items)); a_remove(&warden->attribs, a); } } /* Benutzer zurück teleportieren */ move_unit(u, r, NULL); /* Exitticket abziehen */ i_change(&u->items, itype, -1); return 0; }
int resolve_unit(variant id, void *address) { unit *u = NULL; if (id.i != 0) { u = findunit(id.i); if (u == NULL) { *(unit **) address = NULL; return -1; } } *(unit **) address = u; return 0; }
static void wall_read(connection * b, storage * store) { static wall_data dummy; wall_data *fd = b->data.v ? (wall_data *) b->data.v : &dummy; variant mno; if (global.data_version < STORAGE_VERSION) { READ_INT(store, &mno.i); fd->mage = findunit(mno.i); if (!fd->mage && b->data.v) { ur_add(mno, &fd->mage, resolve_unit); } } else { read_reference(&fd->mage, store, read_unit_reference, resolve_unit); } READ_INT(store, &fd->force); if (global.data_version >= NOBORDERATTRIBS_VERSION) { READ_INT(store, &fd->countdown); } fd->active = true; }
/** ** GM: KILL UNIT <id> <string> ** requires: permission-key "gmkill" **/ static void gm_killunit(const void *tnext, struct unit *u, struct order *ord) { const struct plane *p = rplane(u->region); unit *target = findunit(getid()); const char *msg = getstrtoken(); region *r = target->region; if (r == NULL || p != rplane(r)) { mistake(u, ord, "region is in another plane."); } else { /* checking permissions */ attrib *permissions = a_find(u->faction->attribs, &at_permissions); if (!permissions || !has_permission(permissions, atoi36("gmkill"))) { mistake(u, ord, "permission denied."); } else { scale_number(target, 0); ADDMSG(&target->faction->msgs, msg_message("killedbygm", "region unit string", r, target, msg)); } } }
void audio_interface(Dev *_1, Desc *dd) { byte *b = (uint8_t*)&dd->data; byte *bb = b; int nb = dd->data.bLength; int ctl, ch, u, x; byte *p; int class, subclass; Audioalt *aa; char *hd; class = Class(dd->iface->csp); subclass = Subclass(dd->iface->csp); dprint(2, "%d.%d: ", class, subclass); switch (subclass){ case 1: // control switch (b[2]){ case 0x01: dprint(2, "Class-Specific AC Interface Header Descriptor\n"); dprint(2, "\tAudioDevClass release (bcd)%c%c%c%c, " "TotalLength %d, InCollection %d aInterfaceNr %d\n", '0'+((b[4]>>4)&0xf), '0'+(b[4]&0xf), '0'+((b[3]>>4)&0xf), '0'+(b[3]&0xf), b[5]|(b[6]<<8), b[7], b[8]); break; case 0x02: // input dprint(2, "Audio Input Terminal Descriptor\n"); dprint(2, "\tbTerminalId %d, wTerminalType " "0x%x (%s), bAssocTerminal %d bNrChannels %d, " "wChannelConfig %d, iChannelNames %d iTerminal %d\n", b[3], b[4]|(b[5]<<8), namefor(terminal_types, b[4]|(b[5]<<8)), b[6], b[7], b[8]|(b[9]<<8), b[10], b[11]); if((b[4]|b[5]<<8) == 0x101){ if(verbose) fprint(2, "Audio output unit %d\n", b[3]); /* USB streaming input: play interface */ units[Play][nunits[Play]++] = b[3]; }else{ if(verbose) fprint(2, "Dev can record from %s\n", namefor(terminal_types, b[4]|(b[5]<<8))); /* Non-USB input: record interface */ units[Record][nunits[Record]++] = b[3]; } break; case 0x03: // output if(usbdebug){ fprint(2, "Audio Output Terminal Descriptor\n"); fprint(2, "\tbTerminalId %d, wTerminalType 0x%x (%s), bAssocTerminal %d bSourceId %d, iTerminal %d\n", b[3], b[4]|(b[5]<<8), namefor(terminal_types, b[4]|(b[5]<<8)), b[6], b[7], b[8]); } if((b[4]|b[5]<<8) == 0x101){ if(verbose) fprint(2, "Audio input unit %d\n", b[3]); /* USB streaming output: record interface */ units[Record][nunits[Record]++] = b[3]; if(verbose) fprint(2, "Dev can play to %s\n", namefor(terminal_types, b[4]|(b[5]<<8))); /* Non-USB output: play interface */ units[Play][nunits[Play]++] = b[3]; } break; case 0x04: if(verbose) fprint(2, "Audio Mixer Unit %d\n", b[3]); if(usbdebug){ fprint(2, "\t%d bytes:", nb); for(ctl = 0; ctl < nb; ctl++) fprint(2, " 0x%2.2x", b[ctl]); fprint(2, "\n\tbUnitId %d, bNrInPins %d", b[3], b[4]); } if(b[4]){ dprint(2, ", baSourceIDs: [%d", b[5]); u = findunit(b[5]); for(ctl = 1; ctl < b[4]; ctl++){ if(u < 0) u = findunit(b[5+ctl]); else if((x = findunit(b[5+ctl])) >= 0 && u != x && verbose) fprint(2, "\tMixer %d for I & O \n", b[3]); dprint(2, ", %d", b[5+ctl]); } dprint(2, "]\n"); if(u >= 0){ units[u][nunits[u]++] = b[3]; if(mixerid[u] >= 0) fprint(2, "Second mixer (%d, %d) on %s\n", mixerid[u], b[3], u?"record":"playback"); mixerid[u] = b[3]; } if(usbdebug){ fprint(2, "Channels %d, config %d, ", b[ctl+5], b[ctl+5+1] | b[ctl+5+2] << 8); x = b[ctl+5] * b[4]; fprint(2, "programmable: %d bits, 0x", x); x = (x + 7) >> 3; while(x--) fprint(2, "%2.2x", b[ctl+x+5+4]); } } break; case 0x05: if(verbose) fprint(2, "Audio Selector Unit %d\n", b[3]); dprint(2, "\tbUnitId %d, bNrInPins %d", b[3], b[4]); if(b[4]){ u = findunit(b[5]); dprint(2, ", baSourceIDs: %s [%d", u?"record":"playback", b[5]); for(ctl = 1; ctl < b[4]; ctl++){ if(u < 0) u = findunit(b[5+ctl]); else if((x = findunit(b[5+ctl])) >= 0 && u != x && verbose) fprint(2, "\tSelector %d for I & O\n", b[3]); dprint(2, ", %d", b[5+ctl]); } dprint(2, "]\n"); if(u >= 0){ units[u][nunits[u]++] = b[3]; if(selectorid[u] >= 0) fprint(2, "Second selector (%d, %d) on %s\n", selectorid[u], b[3], u?"record":"playback"); selectorid[u] = b[3]; controls[u][Selector_control].readable = 1; controls[u][Selector_control].settable = 1; controls[u][Selector_control].chans = 0; } } break; case 0x06: // feature if(verbose) fprint(2, "Audio Feature Unit %d", b[3]); dprint(2, "\tbUnitId %d, bSourceId %d, bControlSize %d\n", b[3], b[4], b[5]); u = findunit(b[4]); if(u >= 0){ if(verbose) fprint(2, " for %s\n", u?"Record":"Playback"); units[u][nunits[u]++] = b[3]; if(featureid[u] >= 0) if(verbose) fprint(2, "Second feature unit (%d, %d)" " on %s\n", featureid[u], b[3], u?"record":"playback"); featureid[u] = b[3]; }else if(verbose) fprint(2, ", not known what for\n"); p = b + 6; for(ctl = 1; ctl < 0x0b; ctl++) if((1<<(ctl-1)) & (b[6] | ((b[5]>1)?(b[7]<<8):0))){ if(verbose) fprint(2, "\t%s control on master channel\n", controls[0][ctl].name); if(u >= 0){ controls[u][ctl].readable = 1; controls[u][ctl].settable = 1; controls[u][ctl].chans = 0; } } p += (b[5]>1)?2:1; for(ch = 0; ch < (nb - 8)/b[5]; ch++){ for(ctl = 1; ctl < 0x0b; ctl++) if((1<<(ctl-1)) & (p[0] | ((b[5]>1)?(p[1]<<8):0))){ if(verbose) fprint(2, "\t%s control on channel %d\n", controls[0][ctl].name, ch+1); if(u >= 0){ controls[u][ctl].readable = 1; controls[u][ctl].settable = 1; controls[u][ctl].chans |= 1 <<(ch+1); } } p += (b[5]>1)?2:1; } break; default: hd = hexstr(bb, nb); fprint(2, "audio control unknown: %s\n", hd); free(hd); } break; case 2: // stream switch (b[2]){ case 0x01: dprint(2, "Audio stream for TerminalID %d, delay %d, format_tag %#ux\n", b[3], b[4], b[5] | (b[6]<<8)); break; case 0x02: aa = (Audioalt *)dd->altc->aux; if(aa == nil){ aa = mallocz(sizeof(Audioalt), 1); dd->altc->aux = aa; } if(verbose){ if(b[4] <= 2) fprint(2, "Interface %d: %s, %d bits, ", dd->iface->id, (b[4] == 1)?"mono":"stereo", b[6]); else fprint(2, "Interface %d, %d channels, %d bits, ", dd->iface->id, b[4], b[6]); } if(b[7] == 0){ if(verbose) fprint(2, "frequency variable between %d and %d\n", b[8] | b[9]<<8 | b[10]<<16, b[11] | b[12]<<8 | b[13]<<16); aa->minfreq = b[8] | b[9]<<8 | b[10]<<16; aa->maxfreq = b[11] | b[12]<<8 | b[13]<<16; aa->caps |= has_contfreq; }else{ if(verbose) fprint(2, "discrete frequencies are:"); for(ch = 0; ch < b[7] && ch < 8; ch++){ aa->freqs[ch] = b[8+3*ch] | b[9+3*ch]<<8 | b[10+3*ch]<<16; if(verbose) fprint(2, " %d", b[8+3*ch] | b[9+3*ch]<<8 | b[10+3*ch]<<16); } if(ch < 8) aa->freqs[ch] = -1; if(verbose) fprint(2, "\n"); if(ch > 1) aa->caps |= has_discfreq; /* more than one frequency */ else aa->caps |= onefreq; /* only one frequency */ } aa->nchan = b[4]; aa->res = b[6]; aa->subframesize = b[5]; break; default: if(usbdebug){ hd = hexstr(bb, nb); fprint(2, "audio stream unknown: %s\n", hd); free(hd); } } break; case 3: // midi default: if(usbdebug){ hd = hexstr(bb, nb); fprint(2, "Unknown audio stream type: CS_INTERFACE: %s\n", hd); free(hd); } } }
TC_Error_Code TCDS_Ascii_Harmonic::LoadHarmonicData(IDX_entry *pIDX) { Station_Data *psd = NULL; // Look in the index first if(pIDX->pref_sta_data) return TC_NO_ERROR; //easy // Try the member array of "already-looked-at" master stations for(unsigned int i=0 ; i < m_msd_array.GetCount() ; i++) { psd = &m_msd_array.Item(i); // In the following comparison, it is allowed that the sub-station reference_name may be // a pre-subset of the master station name. // e.g IDX_refence_name: The Narrows midchannel New York // as found in HARMONIC.IDX // psd_station_name: The Narrows, Midchannel, New York Harbor, New York Current // as found in HARMONIC if( (!slackcmp(psd->station_name, pIDX->IDX_reference_name)) && (toupper(pIDX->IDX_type) == psd->station_type) ) { pIDX->pref_sta_data = psd; // save for later return TC_NO_ERROR; } } // OK, have to read and create from the raw file psd = NULL; // If reference station was recently sought, and not found, don't bother // if(!strcmp(pIDX->IDX_reference_name, plast_reference_not_found->mb_str())) if(m_last_reference_not_found.IsSameAs(wxString(pIDX->IDX_reference_name, wxConvUTF8))) return TC_MASTER_HARMONICS_NOT_FOUND; // Clear for this looking m_last_reference_not_found.Clear(); // Find and load appropriate constituents FILE *fp; char linrec[linelen]; fp = fopen (m_harmfile_name.mb_str(), "r"); while (read_next_line (fp, linrec, 1)) { nojunk (linrec); int curonly = 0; if (curonly) if (!strstr (linrec, "Current")) continue; // See the note above about station names // if(!strncmp(linrec, "Rivi", 4)) // int ggl = 4; if (slackcmp (linrec, pIDX->IDX_reference_name)) continue; // Got the right location, so load the data psd = new Station_Data; psd->amplitude = (double *)malloc(num_csts * sizeof(double)); psd->epoch = (double *)malloc(num_csts * sizeof(double)); psd->station_name = (char *)malloc(strlen(linrec) +1); char junk[80]; int a; strcpy (psd->station_name, linrec); // Establish Station Type wxString caplin(linrec, wxConvUTF8); caplin.MakeUpper(); if(caplin.Contains(_T("CURRENT"))) psd->station_type = 'C'; else psd->station_type = 'T'; /* Get meridian */ read_next_line (fp, linrec, 0); psd->meridian = hhmm2seconds (linrec); psd->zone_offset = 0; /* Get tzfile, if present */ if (sscanf (nojunk(linrec), "%s %s", junk, psd->tzfile) < 2) strcpy (psd->tzfile, "UTC0"); /* Get DATUM and units */ read_next_line (fp, linrec, 0); if (sscanf (nojunk(linrec), "%lf %s", &(psd->DATUM), psd->unit) < 2) strcpy (psd->unit, "unknown"); if ((a = findunit (psd->unit)) == -1) { // Nonsense.... // strcpy (psd->units_abbrv, psd->unit); // strcpy (psd->units_conv, known_units[a].name); } psd->have_BOGUS = (findunit(psd->unit) != -1) && (known_units[findunit(psd->unit)].type == BOGUS); int unit_c; if (psd->have_BOGUS) unit_c = findunit("knots"); else unit_c = findunit(psd->unit); if (unit_c != -1) { strcpy (psd->units_conv, known_units[unit_c].name); strcpy (psd->units_abbrv, known_units[unit_c].abbrv); } /* Get constituents */ double loca, loce; for (a=0; a<num_csts; a++) { read_next_line (fp, linrec, 0); sscanf (linrec, "%s %lf %lf", junk, &loca, &loce); // loc_epoch[a] *= M_PI / 180.0; psd->amplitude[a] = loca; psd->epoch[a] = loce * M_PI / 180.; } fclose (fp); break; } if(!psd) { m_last_reference_not_found = wxString(pIDX->IDX_reference_name, wxConvUTF8); return TC_MASTER_HARMONICS_NOT_FOUND; } else { m_msd_array.Add(psd); // add it to the member array pIDX->pref_sta_data = psd; return TC_NO_ERROR; } }
int main( int argc, char ** argv ) { /* -------------------------------------------------------------------- */ /* Check command line usage. */ /* -------------------------------------------------------------------- */ if( argc < 2 ) error(); strcpy(infile, argv[1]); if (argc > 2) { strcpy(outfile,argv[2]); if (strncasecmp2(outfile, "LIST",0) == 0) { ilist = TRUE; } if (strncasecmp2(outfile, "ALL",0) == 0) { iall = TRUE; } } if (ilist || iall || argc == 2 ) { setext(infile, "shp"); printf("DESCRIBE: %s\n",infile); strcpy(outfile,""); } /* -------------------------------------------------------------------- */ /* Look for other functions on the command line. (SELECT, UNIT) */ /* -------------------------------------------------------------------- */ for (i = 3; i < argc; i++) { if ((strncasecmp2(argv[i], "SEL",3) == 0) || (strncasecmp2(argv[i], "UNSEL",5) == 0)) { if (strncasecmp2(argv[i], "UNSEL",5) == 0) iunselect=TRUE; i++; if (i >= argc) error(); strcpy(selectitem,argv[i]); i++; if (i >= argc) error(); selcount=0; strcpy(temp,argv[i]); cpt=temp; tj = atoi(cpt); ti = 0; while (tj>0) { selectvalues[selcount] = tj; while( *cpt >= '0' && *cpt <= '9') cpt++; while( *cpt > '\0' && (*cpt < '0' || *cpt > '9') ) cpt++; tj=atoi(cpt); selcount++; } iselect=TRUE; } /*** End SEL & UNSEL ***/ else if ((strncasecmp2(argv[i], "CLIP",4) == 0) || (strncasecmp2(argv[i], "ERASE",5) == 0)) { if (strncasecmp2(argv[i], "ERASE",5) == 0) ierase=TRUE; i++; if (i >= argc) error(); strcpy(clipfile,argv[i]); sscanf(argv[i],"%lf",&cxmin); i++; if (i >= argc) error(); if (strncasecmp2(argv[i], "BOUND",5) == 0) { setext(clipfile, "shp"); hSHP = SHPOpen( clipfile, "rb" ); if( hSHP == NULL ) { printf( "ERROR: Unable to open the clip shape file:%s\n", clipfile ); exit( 1 ); } SHPGetInfo( hSHPappend, NULL, NULL, adfBoundsMin, adfBoundsMax ); cxmin = adfBoundsMin[0]; cymin = adfBoundsMin[1]; cxmax = adfBoundsMax[0]; cymax = adfBoundsMax[1]; printf("Theme Clip Boundary: (%lf,%lf) - (%lf,%lf)\n", cxmin, cymin, cxmax, cymax); ibound=TRUE; } else { /*** xmin,ymin,xmax,ymax ***/ sscanf(argv[i],"%lf",&cymin); i++; if (i >= argc) error(); sscanf(argv[i],"%lf",&cxmax); i++; if (i >= argc) error(); sscanf(argv[i],"%lf",&cymax); printf("Clip Box: (%lf,%lf) - (%lf,%lf)\n",cxmin, cymin, cxmax, cymax); } i++; if (i >= argc) error(); if (strncasecmp2(argv[i], "CUT",3) == 0) icut=TRUE; else if (strncasecmp2(argv[i], "TOUCH",5) == 0) itouch=TRUE; else if (strncasecmp2(argv[i], "INSIDE",6) == 0) iinside=TRUE; else error(); iclip=TRUE; } /*** End CLIP & ERASE ***/ else if (strncasecmp2(argv[i], "FACTOR",0) == 0) { i++; if (i >= argc) error(); infactor=findunit(argv[i]); if (infactor == 0) error(); iunit=TRUE; i++; if (i >= argc) error(); outfactor=findunit(argv[i]); if (outfactor == 0) { sscanf(argv[i],"%lf",&factor); if (factor == 0) error(); } if (factor == 0) { if (infactor ==0) { puts("ERROR: Input unit must be defined before output unit"); exit(1); } factor=infactor/outfactor; } printf("Output file coordinate values will be factored by %lg\n",factor); ifactor=(factor != 1); /* True if a valid factor */ } /*** End FACTOR ***/ else if (strncasecmp2(argv[i],"SHIFT",5) == 0) { i++; if (i >= argc) error(); sscanf(argv[i],"%lf",&xshift); i++; if (i >= argc) error(); sscanf(argv[i],"%lf",&yshift); iunit=TRUE; printf("X Shift: %lg Y Shift: %lg\n",xshift,yshift); } /*** End SHIFT ***/ else { printf("ERROR: Unknown function %s\n",argv[i]); error(); } } /* -------------------------------------------------------------------- */ /* If there is no data in this file let the user know. */ /* -------------------------------------------------------------------- */ openfiles(); /* Open the infile and the outfile for shape and dbf. */ if( DBFGetFieldCount(hDBF) == 0 ) { puts( "There are no fields in this table!" ); exit( 1 ); } /* -------------------------------------------------------------------- */ /* Print out the file bounds. */ /* -------------------------------------------------------------------- */ iRecord = DBFGetRecordCount( hDBF ); SHPGetInfo( hSHP, NULL, NULL, adfBoundsMin, adfBoundsMax ); printf( "Input Bounds: (%lg,%lg) - (%lg,%lg) Entities: %d DBF: %d\n", adfBoundsMin[0], adfBoundsMin[1], adfBoundsMax[0], adfBoundsMax[1], nEntities, iRecord ); if (strcmp(outfile,"") == 0) /* Describe the shapefile; No other functions */ { ti = DBFGetFieldCount( hDBF ); showitems(); exit(0); } if (iclip) check_theme_bnd(); jRecord = DBFGetRecordCount( hDBFappend ); SHPGetInfo( hSHPappend, NULL, NULL, adfBoundsMin, adfBoundsMax ); if (nEntitiesAppend == 0) puts("New Output File\n"); else printf( "Append Bounds: (%lg,%lg)-(%lg,%lg) Entities: %d DBF: %d\n", adfBoundsMin[0], adfBoundsMin[1], adfBoundsMax[0], adfBoundsMax[1], nEntitiesAppend, jRecord ); /* -------------------------------------------------------------------- */ /* Find matching fields in the append file or add new items. */ /* -------------------------------------------------------------------- */ mergefields(); /* -------------------------------------------------------------------- */ /* Find selection field if needed. */ /* -------------------------------------------------------------------- */ if (iselect) findselect(); /* -------------------------------------------------------------------- */ /* Read all the records */ /* -------------------------------------------------------------------- */ jRecord = DBFGetRecordCount( hDBFappend ); for( iRecord = 0; iRecord < nEntities; iRecord++) /** DBFGetRecordCount(hDBF) **/ { /* -------------------------------------------------------------------- */ /* SELECT for values if needed. (Can the record be skipped.) */ /* -------------------------------------------------------------------- */ if (iselect) if (selectrec() == 0) goto SKIP_RECORD; /** SKIP RECORD **/ /* -------------------------------------------------------------------- */ /* Read a Shape record */ /* -------------------------------------------------------------------- */ psCShape = SHPReadObject( hSHP, iRecord ); /* -------------------------------------------------------------------- */ /* Clip coordinates of shapes if needed. */ /* -------------------------------------------------------------------- */ if (iclip) if (clip_boundary() == 0) goto SKIP_RECORD; /** SKIP RECORD **/ /* -------------------------------------------------------------------- */ /* Read a DBF record and copy each field. */ /* -------------------------------------------------------------------- */ for( i = 0; i < DBFGetFieldCount(hDBF); i++ ) { /* -------------------------------------------------------------------- */ /* Store the record according to the type and formatting */ /* information implicit in the DBF field description. */ /* -------------------------------------------------------------------- */ if (pt[i] > -1) /* if the current field exists in output file */ { switch( DBFGetFieldInfo( hDBF, i, NULL, &iWidth, &iDecimals ) ) { case FTString: case FTLogical: DBFWriteStringAttribute(hDBFappend, jRecord, pt[i], (DBFReadStringAttribute( hDBF, iRecord, i )) ); break; case FTInteger: DBFWriteIntegerAttribute(hDBFappend, jRecord, pt[i], (DBFReadIntegerAttribute( hDBF, iRecord, i )) ); break; case FTDouble: DBFWriteDoubleAttribute(hDBFappend, jRecord, pt[i], (DBFReadDoubleAttribute( hDBF, iRecord, i )) ); break; case FTInvalid: break; } } } jRecord++; /* -------------------------------------------------------------------- */ /* Change FACTOR and SHIFT coordinates of shapes if needed. */ /* -------------------------------------------------------------------- */ if (iunit) { for( j = 0; j < psCShape->nVertices; j++ ) { psCShape->padfX[j] = psCShape->padfX[j] * factor + xshift; psCShape->padfY[j] = psCShape->padfY[j] * factor + yshift; } } /* -------------------------------------------------------------------- */ /* Write the Shape record after recomputing current extents. */ /* -------------------------------------------------------------------- */ SHPComputeExtents( psCShape ); SHPWriteObject( hSHPappend, -1, psCShape ); SKIP_RECORD: SHPDestroyObject( psCShape ); psCShape = NULL; j=0; } /* -------------------------------------------------------------------- */ /* Print out the # of Entities and the file bounds. */ /* -------------------------------------------------------------------- */ jRecord = DBFGetRecordCount( hDBFappend ); SHPGetInfo( hSHPappend, &nEntitiesAppend, &nShapeTypeAppend, adfBoundsMin, adfBoundsMax ); printf( "Output Bounds: (%lg,%lg) - (%lg,%lg) Entities: %d DBF: %d\n\n", adfBoundsMin[0], adfBoundsMin[1], adfBoundsMax[0], adfBoundsMax[1], nEntitiesAppend, jRecord ); /* -------------------------------------------------------------------- */ /* Close the both shapefiles. */ /* -------------------------------------------------------------------- */ SHPClose( hSHP ); SHPClose( hSHPappend ); DBFClose( hDBF ); DBFClose( hDBFappend ); if (nEntitiesAppend == 0) { puts("Remove the output files."); setext(outfile, "dbf"); remove(outfile); setext(outfile, "shp"); remove(outfile); setext(outfile, "shx"); remove(outfile); } return( 0 ); }
TC_Error_Code TCDS_Binary_Harmonic::LoadData(const wxString &data_file_path) { if(!open_tide_db (data_file_path.mb_str())) return TC_TCD_FILE_CORRUPT; //Build the tables of constituent data DB_HEADER_PUBLIC hdr = get_tide_db_header (); source_ident = wxString( hdr.version, wxConvUTF8 ); num_csts = hdr.constituents; if(0 == num_csts) return TC_GENERIC_ERROR; num_nodes = hdr.number_of_years; if(0 == num_nodes) return TC_GENERIC_ERROR; // Allocate a working buffer m_work_buffer = (double *) malloc (num_csts * sizeof (double)); // Constituent speeds m_cst_speeds = (double *) malloc (num_csts * sizeof (double)); for (int a=0; a<num_csts; a++) { m_cst_speeds[a] = get_speed (a); m_cst_speeds[a] *= M_PI / 648000; /* Convert to radians per second */ } // Equilibrium tables by year m_first_year = hdr.start_year; num_epochs = hdr.number_of_years; m_cst_epochs = (double **) malloc (num_csts * sizeof (double *)); for (int i=0; i<num_csts; i++) m_cst_epochs[i] = (double *) malloc (num_epochs * sizeof (double)); for (int i=0; i<num_csts; i++) { for (int year=0; year<num_epochs; year++) { m_cst_epochs[i][year] = get_equilibrium (i, year); m_cst_epochs[i][year] *= M_PI / 180.0; } } // Node factors m_cst_nodes = (double **) malloc (num_csts * sizeof (double *)); for (int a=0; a<num_csts; a++) m_cst_nodes[a] = (double *) malloc (num_nodes * sizeof (double)); for (int a=0; a<num_csts; a++) { for (int year=0; year<num_nodes; year++) m_cst_nodes[a][year] = get_node_factor (a, year); } // now load and create the index TIDE_RECORD *ptiderec = (TIDE_RECORD *)calloc(sizeof(TIDE_RECORD), 1); for(unsigned int i=0 ; i < hdr.number_of_records ; i++) { read_tide_record (i, ptiderec); num_IDX++; // Keep counting entries for harmonic file stuff IDX_entry *pIDX = new IDX_entry; pIDX->source_data_type = SOURCE_TYPE_BINARY_HARMONIC; pIDX->pDataSource = NULL; pIDX->Valid15 = 0; pIDX->pref_sta_data = NULL; // no reference data yet pIDX->IDX_Useable = 1; // but assume data is OK pIDX->IDX_tzname = NULL; pIDX->IDX_lon = ptiderec->header.longitude; pIDX->IDX_lat = ptiderec->header.latitude; const char *tz = get_tzfile (ptiderec->header.tzfile); change_time_zone ((char *)tz); if(tz_info) pIDX->IDX_time_zone = -tz_info->tzi.Bias; strncpy(pIDX->IDX_station_name, ptiderec->header.name, MAXNAMELEN); // if(strstr(ptiderec->header.name, "Beaufort") != NULL) // int yyp = 4; pIDX->IDX_flood_dir = ptiderec->max_direction; pIDX->IDX_ebb_dir = ptiderec->min_direction; if(REFERENCE_STATION == ptiderec->header.record_type) { // Establish Station Type wxString caplin(pIDX->IDX_station_name, wxConvUTF8); caplin.MakeUpper(); if(caplin.Contains(_T("CURRENT"))) pIDX->IDX_type = 'C'; else pIDX->IDX_type = 'T'; int t1 = ptiderec->zone_offset; double zone_offset = (double)(t1 / 100) + ((double)(t1 % 100))/60.; // pIDX->IDX_time_zone = t1a; pIDX->IDX_ht_time_off = pIDX->IDX_lt_time_off = 0; pIDX->IDX_ht_mpy = pIDX->IDX_lt_mpy = 1.0; pIDX->IDX_ht_off = pIDX->IDX_lt_off = 0.0; pIDX->IDX_ref_dbIndex = ptiderec->header.reference_station; // will be -1 // build a Station_Data class, and add to member array Station_Data *psd = new Station_Data; psd->amplitude = (double *)malloc(num_csts * sizeof(double)); psd->epoch = (double *)malloc(num_csts * sizeof(double)); psd->station_name = (char *)malloc(ONELINER_LENGTH); strncpy(psd->station_name, ptiderec->header.name, MAXNAMELEN); psd->station_type = pIDX->IDX_type; // Get meridian, which is seconds difference from UTC, not figuring DST, so that New York is always (-300 * 60) psd->meridian = -(tz_info->tzi.Bias * 60); psd->zone_offset = zone_offset; // Get units strncpy (psd->unit, get_level_units (ptiderec->level_units), 40 - 1); psd->unit[40 -1] = '\0'; psd->have_BOGUS = (findunit(psd->unit) != -1) && (known_units[findunit(psd->unit)].type == BOGUS); int unit_c; if (psd->have_BOGUS) unit_c = findunit("knots"); else unit_c = findunit(psd->unit); if(unit_c != -1) { strncpy (psd->units_conv, known_units[unit_c].name, sizeof(psd->units_conv)-1); strncpy (psd->units_abbrv, known_units[unit_c].abbrv, sizeof(psd->units_abbrv)-1); } else { strncpy (psd->units_conv, psd->unit, 40 - 1); psd->units_conv[40 - 1] = '\0'; strncpy (psd->units_abbrv, psd->unit, 20 - 1); psd->units_abbrv[20 - 1] = '\0'; } // Get constituents for (int a=0; a<num_csts; a++) { psd->amplitude[a] = ptiderec->amplitude[a]; psd->epoch[a] = ptiderec->epoch[a] * M_PI / 180.; } psd->DATUM = ptiderec->datum_offset; m_msd_array.Add(psd); // add it to the member array pIDX->pref_sta_data = psd; pIDX->IDX_ref_dbIndex = i; pIDX->have_offsets = 0; } else if(SUBORDINATE_STATION == ptiderec->header.record_type) { // Establish Station Type wxString caplin(pIDX->IDX_station_name, wxConvUTF8); caplin.MakeUpper(); if(caplin.Contains(_T("CURRENT"))) pIDX->IDX_type = 'c'; else pIDX->IDX_type = 't'; int t1 = ptiderec->max_time_add; double t1a = (double)(t1 / 100) + ((double)(t1 % 100))/60.; t1a *= 60; // Minutes pIDX->IDX_ht_time_off = t1a; pIDX->IDX_ht_mpy = ptiderec->max_level_multiply; if(0. == pIDX->IDX_ht_mpy) pIDX->IDX_ht_mpy = 1.0; pIDX->IDX_ht_off = ptiderec->max_level_add; t1 = ptiderec->min_time_add; t1a = (double)(t1 / 100) + ((double)(t1 % 100))/60.; t1a *= 60; // Minutes pIDX->IDX_lt_time_off = t1a; pIDX->IDX_lt_mpy = ptiderec->min_level_multiply; if(0. == pIDX->IDX_lt_mpy) pIDX->IDX_lt_mpy = 1.0; pIDX->IDX_lt_off = ptiderec->min_level_add; pIDX->IDX_ref_dbIndex = ptiderec->header.reference_station; // strncpy(pIDX->IDX_reference_name, ptiderec->header.name, MAXNAMELEN); if( pIDX->IDX_ht_time_off || pIDX->IDX_ht_off != 0.0 || pIDX->IDX_lt_off != 0.0 || pIDX->IDX_ht_mpy != 1.0 || pIDX->IDX_lt_mpy != 1.0) pIDX->have_offsets = 1; } m_IDX_array.Add(pIDX); } // Mark the index entries individually with invariant harmonic constants unsigned int max_index = GetMaxIndex(); for(unsigned int i=0 ; i < max_index ; i++) { IDX_entry *pIDX = GetIndexEntry( i ); if(pIDX) { pIDX->num_nodes = num_nodes; pIDX->num_csts = num_csts; pIDX->num_epochs = num_epochs; pIDX->m_cst_speeds = m_cst_speeds; pIDX->m_cst_nodes = m_cst_nodes; pIDX->m_cst_epochs = m_cst_epochs; pIDX->first_year = m_first_year; pIDX->m_work_buffer = m_work_buffer; } } free( ptiderec ); return TC_NO_ERROR; }