NOAA GVI GUIDE

Appendix N

Introduction Page, GVI Guide TOC, Acronyms
Previous Section, Next Section

APPENDIX N: Software to Read Third Generation Image Data

N.1 INTRODUCTION

This appendix contains FORTRAN and C programs that can be used as a guide for reading Third Generation image data. Each uncompressed image (B-, C- and D-level) is made up of 2500 columns by 904 rows of data with nominal 0.15 degree latitude/longitude resolution which yields a total size of 2,226,000 bytes/image. In addition, the B-level data contain a metadata header of 512 bytes, which is appended in front of the 2500 x 904 image (see Appendix K for further instructions on reading this header).

Each image is read by rows, starting with row 1 at 75N and ending with row 904 at 55S. Every row begins at 180W longitude and each successive map cell is 0.144 degrees east of the previous map cell. Therefore, the upper left corner of the image starts at 75N, 180W and ends at the lower right corner of the image at 55S, 180E. The physical range of the data is between 0 and 255, with all ocean values containing the value 0.

Since the binary imagery is character data, it cannot be browsed. However, the character data can easily be converted into integer values. The following software can be used as a guide for reading the image files. Each of these programs converts the character data into integer values. Reading the 8-bit imagery is somewhat platform specific. The coding is broken down by language and platform. This software is not intended to create an image.

N.2 USING FORTRAN

The following is a list of programs that should be used based on your platform.

A. Silicon Graphics (SGI), SUN Workstations, VAX and DEC ALPHA Workstations:

Note: one word of caution with the VAX and DEC ALPHA, please make sure that the data read from the media you are using blocks the data in 2500 byte blocks. Particularly, with the VAX and DEC ALPHA machines, there is a tendency to default to 512 byte blocks, which means you will NOT be able to read the data using these programs.

If the user has the data on a CD-ROM, follow the following example to mount the CD-ROM on a VAX or DEC ALPHA machine:

mount devicename / media=cd /und=fixed:none:2500)

FORTRAN Program:

        PROGRAM CONVRT
C
C    THIS PROGRAM IS DESIGNED TO READ 8-BIT IMAGE DATA AND
C    OUTPUT THE DATA AS ASCII TEXT WITH 2,260,000 RECORDS.  THIS
C    WORKS OUT TO 1 RECORD PER PIXEL.  UNIT 10 IS THE INPUT FILE
C    YOU ARE TRYING TO READ, AND IN THE EXAMPLE, UNIT 6  IS WHERE
C    THE OUTPUT IS GOING TO.
C
C*****************************************************
C **  COMMENTS ABOUT THE FORTRAN READING PROGRAM *****
C*****************************************************
C    THE NUMBER OF COLUMNS IS 2500 AND THE NUMBER OF ROWS IS 904.  
C    THE BLOCKING FACTOR IS 2500 BYTES.  YOU WILL NOTICE THAT THE
C    RECL (RECORD LENGTH) IS 625.  625 REPRESENTS THE NUMBER OF 4-
C    BYTE WORDS PER RECORD.  THE DATA WILL BE OUTPUT TO UNIT=6 ONE
C    PIXEL AT A TIME.  THEREFORE, THE OUTPUT FILE WILL CONTAIN 
C    2,260,000 LINES OR RECORDS IN IT.  THE DATA STARTS IN THE UPPER
C    LEFT HAND CORNER AT 75N, 180W AND ENDS IN THE BOTTOM RIGHT
C    HAND CORNER AT 55S, 180E.  EVERY ROW BEGINS AT 180W 
C    LONGITUDE, AND EACH SUCCESSIVE MAP CELL IS 0.144 DEGREES EAST
C    OF THE PREVIOUS CELL.  THE OUTPUT DATA RANGE WILL BE BETWEEN
C    0 AND 255.  THE OCEAN MAP CELLS ARE ALL ZEROES.
C
C    *****************************
C    DECLARE ALL VARIABLES
C    *****************************
C
        CHARACTER*1 IMAGE(2500)
        CHARACTER*8 HEX(2500)
        INTEGER DATA(2500)
C
C     *************************
C     OPEN FILES TO READ  
C     *************************             
C
       OPEN(UNIT=10,FILE='GVI.DATA',ACCESS='DIRECT',
     $RECL=625,FORM='UNFORMATTED',STATUS='UNKNOWN')
      
       DO 10 I=1,904
             READ(10,REC=I) IMAGE
          DO 15 J=1,2500
            WRITE(HEX(J),'(Z2)') IMAGE(J)
            READ(HEX(J),'(Z2)') DATA(J)
 15       CONTINUE

            DO 20 J=1,2500
              WRITE(6,'(I4)') DATA(J)
 20         CONTINUE
 10    CONTINUE
         STOP
         END
B. IBM Mainframes
        PROGRAM CONVRT
C
C    THIS PROGRAM IS DESIGNED TO READ 8-BIT IMAGE DATA AND
C    OUTPUT THE DATA AS ASCII TEXT.
C    *************************************************************
C    COMMENTS ABOUT THE FORTRAN READING PROGRAM
C***************************************************************
C
C    THE NUMBER OF COLUMNS IS 2500 AND THE NUMBER OF ROWS IS 904.  
C    THE BLOCKING FACTOR IS 2500 BYTES.  THE DATA WILL BE OUTPUT 
C    TO UNIT=6 ONE PIXEL AT A TIME.  THEREFORE, THE OUTPUT FILE 
C    WILL CONTAIN 2,260,000 LINES OR RECORDS IN IT.  THE DATA STARTS
C     IN THE UPPER LEFT HAND CORNER AT 75N, 180W AND ENDS IN THE 
C     BOTTOM RIGHT HAND CORNER AT 55S, 180E.  EVERY ROW BEGINS AT 
C     180W LONGITUDE, AND EACH SUCCESSIVE MAP CELL IS 0.144 DEGREES
C     EAST OF THE PREVIOUS CELL.  THE OUTPUT DATA RANGE WILL BE 
C     BETWEEN 0 AND 255.  THE OCEAN MAP CELLS ARE ALL ZEROES.
C
C    *****************************
C    DECLARE ALL VARIABLES
C    *****************************
C
        CHARACTER*1 IMAGE(2500)
        INTEGER*2  DATA(2500)
        EQUIVALENCE (IMAGE,DATA)
C
C     *************************
C     OPEN FILES TO READ  
C     *************************             
C
       OPEN(UNIT=10,FILE='GVI.DATA')
      
       DO 10 I=1,904
             READ(10,'(125(20A1))') IMAGE
          DO 20 J=1,2500
            WRITE(6,'(I4)') DATA(J)
 20       CONTINUE
 10     CONTINUE
          STOP
          END
C. CRAY

With the Cray, the following script (cray.sh) should be used with the compiled FORTRAN code.

        PROGRAM CONVRT
C
C    THIS PROGRAM IS DESIGNED TO READ 8-BIT IMAGE DATA AND
C    OUTPUT THE DATA AS ASCII TEXT.
C    *************************************************************
C    COMMENTS ABOUT THE FORTRAN READING PROGRAM
C    *************************************************************
C
C    THE NUMBER OF COLUMNS IS 2500 AND THE NUMBER OF ROWS IS 904.  
C    THE BLOCKING FACTOR IS 2500 BYTES.  YOU WILL NOTICE THAT THE
C    RECL (RECORD LENGTH) IS 625.  625 REPRESENTS THE NUMBER OF 4-
C    BYTE WORDS PER RECORD.  THE DATA WILL BE OUTPUT TO UNIT=6 ONE
C    PIXEL AT A TIME.  THEREFORE, THE OUTPUT FILE WILL CONTAIN 
C    2,260,000 LINES OR RECORDS IN IT.  THE DATA STARTS IN THE UPPER 
C    LEFT HAND CORNER AT 75N, 180W AND ENDS IN THE BOTTOM RIGHT 
C    HAND CORNER AT 55S, 180E.  EVERY ROW BEGINS AT 180W 
C    LONGITUDE, AND EACH SUCCESSIVE MAP CELL IS 0.144 DEGREES
C     EAST OF THE PREVIOUS CELL.  THE OUTPUT DATA RANGE WILL BE 
C     BETWEEN 0 AND 255.  THE OCEAN MAP CELLS ARE ALL ZEROES.
C
C    *****************************
C    DECLARE ALL VARIABLES
C    *****************************
C
        CHARACTER IMAGE
C
C
       DO J=1,904
        DO I=1,2500
1          READ(10) IMAGE
            WRITE(6,*) ICHAR(IMAGE)
         ENDDO
        ENDDO
         STOP
       END
The shell script to use with the FORTRAN code is the following:

#!/bin/sh
assign -R
assign -a gvi.data -sunblocked u:10
cf77 filename
./a.out
exit

where,

assign -R = reset all assign attributes;

assign -a filename -sunblocked n:10 = data file "filename" has structure unblocked and has been assigned to unit 10;

cf77 filename = Use the CRAY FORTRAN 77 compiler on input file "filename" containing program CONVRT code;

./a/out = the executable.

N.3 USING C LANGUAGE

The following program can be universally used on all platforms which have a C compiler.

#include
#include
#include

/*
     The purpose of this program is to read 1-byte Plate Carr‚e
      images (C-level or D-level) and output them as ASCII text one
      byte at a time.  One word of caution, if you are using a VAX
      DEC ALPHA machine, then you need to make sure that the data
      has been stored in 2500 byte blocks, NOT 512 byte blocks.
*/

static FILE *fp1, *fp2;

void main(int argc, char *argv[])
{
 char image[2260000];
 int xsize=2500, ysize=904, i=0;
 register int I;
 short data;

   if (argc !=3)
   {
      printf("usage   image_read inputfile outputfile\n");
      exit(EXIT_FAILURE);
    }

    if (!(fp1=fopen(argv[1],"rb")))
    {
     printf("cannot open file %s to read\n", argv[1]);
     exit(EXIT_FAILURE);
     }

     if (!(fp2=fopen(argv[2],"w")))
     {
       printf("Cannot open file %s to write\n",argv[2]);
       exit(EXIT_FAILURE);
      }

      fread(&image[0],1,xsize*ysize,fp1);

      for(I=0;i<2260000;i++)
      {
         data=(short) image[i];
         fprintf(fp2,"%d\n",data);
       }

/*    Write output to user-defined file   */

}
To compile the program, use the following command:

cc read_image.c -o read_image

Then to run the program, use the following:

read_image inputfile outputfile

where,

read_image = the executable;

inputfile = the input 8-bit binary image;

outputfile = the output ASCII image.

The output ASCII image will be a sequential file, with each pixel constituting a new record. Therefore, the entire image will have 2,260,000 bytes.


Previous Section Top of Page Next Section