Пример #1
0
static int ppfFileIdLen(FILE *f, int version)
{
  if (version == 2) {
    fseeko64(f, -8, SEEK_END);
  } else {
    fseeko64(f, -6, SEEK_END);
  }

  if (fgetc(f) != '.' || fgetc(f) != 'D' || fgetc(f) != 'I' || fgetc(f) != 'Z')
    return 0;

  return (version == 2) ? readInt4(f) : readInt2(f);
}
Пример #2
0
//==========================================================
// GshhsPolygon  (compatible avec le format .rim de RANGS)
//==========================================================
GshhsPolygon::GshhsPolygon(ZUFILE *file_)
{
 	file  = file_;
    ok = true;
    id    = readInt4();
    n     = readInt4();
    flag  = readInt4();
    west  = readInt4() * 1e-6;
    east  = readInt4() * 1e-6;
    south = readInt4() * 1e-6;
    north = readInt4() * 1e-6;
    area  = readInt4();
    greenwich = readInt2();
    readInt2();   // source

	antarctic = (west==0 && east==360);
    if (ok)
    {
		double x, y=-90;
        
        for (int i=0; i<n; i++) {
            x = readInt4() * 1e-6;
            if (greenwich && x > 270)
                x -= 360;
            y = readInt4() * 1e-6;
            lsPoints.push_back(new GshhsPoint(x,y));
        }
        
    	// force l'Antarctic à être un "rectangle" qui passe par le pôle
        if (antarctic) {
        	lsPoints.insert (lsPoints.begin(), 2, (GshhsPoint*)0);
        	lsPoints [1] = new GshhsPoint(360, y);
        	lsPoints [0] = new GshhsPoint(360,-90);
            lsPoints.push_back(new GshhsPoint(0,-90));
        }
    
    }
}
Пример #3
0
//----------------------------------------------
// SECTION 3: BIT MAP SECTION (BMS)
//----------------------------------------------
bool GribV1Record::readGribSection3_BMS(ZUFILE* file) {
    fileOffset3 = zu_tell(file);
    if (! hasBMS) {
        sectionSize3 = 0;
        return ok;
    }
    sectionSize3 = readInt3(file);
    (void) readChar(file);
    int bitMapFollows = readInt2(file);

    if (bitMapFollows != 0) {
        return ok;
    }
    BMSbits = new zuchar[sectionSize3-6];
    if (!BMSbits) {
        //erreur("Record: out of memory");
        ok = false;
    }
    for (zuint i=0; i<sectionSize3-6; i++) {
        BMSbits[i] = readChar(file);
    }
    return ok;
}
Пример #4
0
static bool patchApplyIPS(const char *patchname, u8 **r, int *s)
{
  // from the IPS spec at http://zerosoft.zophar.net/ips.htm
  FILE *f = fopen(patchname, "rb");
  if(!f)
    return false;

  bool result = false;

  u8 *rom = *r;
  int size = *s;
  if(fgetc(f) == 'P' &&
     fgetc(f) == 'A' &&
     fgetc(f) == 'T' &&
     fgetc(f) == 'C' &&
     fgetc(f) == 'H') {
    int b;
    int offset;
    int len;

    result = true;

    for(;;) {
      // read offset
      offset = readInt3(f);
      // if offset == EOF, end of patch
      if(offset == 0x454f46 || offset == -1)
        break;
      // read length
      len = readInt2(f);
      if(!len) {
        // len == 0, RLE block
        len = readInt2(f);
        // byte to fill
        int c = fgetc(f);
        if(c == -1)
          break;
        b = (u8)c;
      } else
        b= -1;
      // check if we need to reallocate our ROM
      if((offset + len) >= size) {
        size *= 2;
        rom = (u8 *)realloc(rom, size);
        *r = rom;
        *s = size;
      }
      if(b == -1) {
        // normal block, just read the data
        if(fread(&rom[offset], 1, len, f) != (size_t)len)
          break;
      } else {
        // fill the region with the given byte
        while(len--) {
          rom[offset++] = b;
        }
      }
    }
  }
  // close the file
  fclose(f);

  return result;
}
Пример #5
0
//----------------------------------------------
// SECTION 2: THE GRID DESCRIPTION SECTION (GDS)
//----------------------------------------------
bool GribV1Record::readGribSection2_GDS(ZUFILE* file) {
    if (! hasGDS)
        return 0;
    fileOffset2 = zu_tell(file);
    sectionSize2 = readInt3(file);  // byte 1-2-3
    readChar(file);			// byte 4 => NV
    readChar(file); 			// byte 5 => PV
    gridType = readChar(file); 		// byte 6

    if (gridType != 0) {
        erreur("Record: unknown grid type GDS(6) : %d",gridType);
        ok = false;
    }

    Ni  = readInt2(file);				// byte 7-8
    Nj  = readInt2(file);				// byte 9-10
    La1 = readSignedInt3(file)/1000.0;	// byte 11-12-13
    Lo1 = readSignedInt3(file)/1000.0;	// byte 14-15-16
    resolFlags = readChar(file);		// byte 17
    La2 = readSignedInt3(file)/1000.0;	// byte 18-19-20
    Lo2 = readSignedInt3(file)/1000.0;	// byte 21-22-23

    if (Lo1>=0 && Lo1<=180 && Lo2<0) {
        Lo2 += 360.0;    // cross the 180 deg meridien,beetwen alaska and russia
    }

    Di  = readSignedInt2(file)/1000.0;	// byte 24-25
    Dj  = readSignedInt2(file)/1000.0;	// byte 26-27

    while ( Lo1> Lo2   &&  Di >0) {   // horizontal size > 360 °
        Lo1 -= 360.0;
    }

    double val=Lo2+Di;
    while(val>=360) val-=360;
    if(val==Lo1)
        isFull=true;

    hasDiDj =(resolFlags&0x80) !=0;

    scanFlags = readChar(file);			// byte 28
    isScanIpositive = (scanFlags&0x80) ==0;
    isScanJpositive = (scanFlags&0x40) !=0;
    isAdjacentI     = (scanFlags&0x20) ==0;

        if (Lo2 > Lo1) {
            lonMin = Lo1;
            lonMax = Lo2;
        }
        else {
            lonMin = Lo2;
            lonMax = Lo1;
        }
        if (La2 > La1) {
            latMin = La1;
            latMax = La2;
        }
        else {
            latMin = La2;
            latMax = La1;
        }
        if (Ni<=1 || Nj<=1) {
                erreur("Recordd: Ni=%u Nj=%u",Ni,Nj);
                ok = false;
        }
        else {
                Di = (Lo2-Lo1) / (Ni-1);
                Dj = (La2-La1) / (Nj-1);
        }

if (false) {
printf("====\n");
printf("Lo1=%f Lo2=%f    La1=%f La2=%f\n", Lo1,Lo2,La1,La2);
printf("Ni=%u Nj=%u\n", Ni,Nj);
printf("hasDiDj=%d Di,Dj=(%f %f)\n", hasDiDj, Di,Dj);
printf("hasBMS=%d\n", hasBMS);
printf("isScanIpositive=%d isScanJpositive=%d isAdjacentI=%d\n",
                        isScanIpositive,isScanJpositive,isAdjacentI );
}
    return ok;
}