[GRASS5] STDS(DEM)2ASC and Possible Bug
Kevin Atkinson
kevina at users.sourceforge.net
Wed Jan 17 00:27:21 EST 2001
On Tue, 16 Jan 2001, Eric G . Miller wrote:
> Sourcecode? A single executable is not generally useful.
OOPS: That was suppose to be the sourcecode, Sorry. :-|.
---
Kevin Atkinson
kevina at users sourceforge net
http://metalab.unc.edu/kevina/
-------------- next part --------------
/*
SDTS to GRASS ASCII GRID format
Kevin Atkinson
kevina at users sourceforge net
Version .001, Jan 16, 2001
Copyright: Public Domain or whatever the STDS2ARC was.
DERIVED FROM
U.S. Bureau of Land Management
Spatial Data Transfer Standard (SDTS)
SDTS to ARCINFO ASCII GRID format
program: stds2ARC.c
author: Sol Katz (skatz at blm.gov)
date: Mar 23, 1998
language: C
This program dumps SDTS DEM modules to a GRASS ascii grid
import data file
*/
#include <stdio.h>
#include <string.h>
#include "stc123.h"
#define null 0
FILE *fpin;
FILE *fpdem;
FILE *fpdat;
long int_level;
double xtemp, ytemp;
double sfax, sfay, xorg, yorg; /* Internal Spatial Reference transformation parameters */
double xhrs, yhrs; /* Internal Spatial Reference transformation parameters */
int p ;
double x[5];
double y[5];
long px[5];
long py[5];
long node_id[5];
long nxy, record_id;
long att_record_id;
long str_len;
long li;
long pid_l = 0, pid_r = 0;
long node_s= 0, node_e= 0;
long att_dat = 1;
long att_dem = 1;
long two = 2;
long nrow, ncol;
short natt;
int stat2;
int status;
int row, col, maxcol;
unsigned char temp[100]; /* temporary buffer used for hex dumps of binary */
long i;
int fillvalue;
int voidvalue;
int minvalue;
int maxvalue;
double height,width;
double upperlx,upperly;
char mapname[41];
char theme[21];
char date[11];
long scale;
char ice;
char leadid;
char ccs[4];
char tag[10];
char fdlen[10];
char *fdname;
char mod_name[10];
char base_name[100];
char file_name[100];
char out_file[100];
char dat_file[100];
char string[5000];
char descr[5000];
char frmts[500];
int order; /* byte order returned by g123order */
double lat;
double lon;
int zone = 0 ;
int level = 3;
int utm = 1 ;
int meters = 2 ;
double resolution = 0.61 ;
int file2map = 4;
int zero = 0;
int sides = 4;
/*int catas = 1;*/
int one = 1;
double rem;
double NE_LATITUDE ;
double NE_LONGITUDE;
double NW_LATITUDE ;
double NW_LONGITUDE;
double SW_LATITUDE ;
double SW_LONGITUDE;
double SE_LATITUDE ;
double SE_LONGITUDE;
double NEX;
double NEY;
double NWX;
double NWY;
double SWX;
double SWY;
double SEX;
double SEY;
char rsnm[5] ;
char oh1oh[4] ;
char cellid [3] ;
int klines = 0;
int knodes = 0;
int kareas = 0;
int kpoints = 0;
int main(int,char*[]);
void get_iref(void);
void get_xref(void);
void dem_rc(int);
void dem_head(int);
void dem_mbr(int);
void cell_range(int);
void cells_out(int);
void get_nw_corner(void);
int s123tol2(char *,long *,int);
double min (double x, double y) {return x < y ? x : y;}
double max (double x, double y) {return x > y ? x : y;}
int main(int argc,char *argv[])
{
/* Print error if arguments were not included on command line */
printf ("\n Spatial Data Transfer Standard (SDTS)");
printf ("\n SDTS to GRASS ASCII GRID Utility");
printf ("\n SDTS2ASC BETA ver .001");
printf ("\n By Kevin Atkinson, Jan 16, 2000");
printf ("\n Derived from STDS2ARC");
printf ("\n Sol Katz(skatz at blm.gov), Mar 1998.\n");
/* Open line input file */
if (argc < 4)
{
printf ("\nUsage: sdts2arc (base_input_name) (base_output_file) (cell id)\n ");
printf (" input file: ISO 8211 base file name\n");
printf (" output file: output file without extension\n");
printf (" layer id: digits in position 7 and 8 of filename \n\n");
}
if (argc < 2) /* Prompt for input SDTS file name */
{
printf ("\n\nEnter base SDTS file name:\n ");
scanf ("%s",base_name);
}
else
strcpy (base_name, argv[1]);
/* Determine byte order of current machine */
g123order (&order);
/*
get translation parameters for DEM dataset from the Internal
Spatial Reference module.)
*/
strcpy (file_name,base_name);
strcat (file_name,"IDEN.DDF");
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nCAN'T OPEN 'DEM' IDEN FILE %s",file_name);
exit(0);
}
stat2 = end123file (&fpin);
/* Prompt for output report file name */
if (argc < 3) /* prompt for output dem file name */
{
printf ("\nEnter base output file name (exclude any extension):\n ");
scanf ("%s",out_file);
}
else
strcpy (out_file, argv[2]);
strcat(out_file,".asc") ;
if (argc < 4) /* prompt for 2 digit layer number */
{
printf (
"\nEnter the 2 digits in position 7 and 8 of the base name, include leading 0:\n ");
scanf ("%s",cellid);
}
else
strcpy (cellid, argv[3]);
/* Open output .grd file */
fpdem = fopen (out_file,"w");
if (fpdem == null)
{
printf ("\nERROR OPENING .DEM FILE %s",out_file);
stat2 = end123file (&fpin);
exit (1);
}
dem_head(status);
cell_range(status);
get_iref();
get_xref();
dem_mbr(status);
dem_rc(status);
get_nw_corner();
printf ("nrow= %ld, ncol= %ld \n",nrow,ncol);
fprintf (fpdem,"rows: %ld\n",nrow);
fprintf (fpdem,"cols: %ld\n",ncol);
printf ("Range: max= %d, min= %d, void= %d, fill= %d\n",
maxvalue,minvalue,voidvalue,fillvalue);
fprintf(fpdem,"north: %f\n",max(NWY,NEY));
fprintf(fpdem,"south: %f\n",min(SWY,SEY));
fprintf(fpdem,"west: %f\n",min(SWX,NWX));
fprintf(fpdem,"east: %f\n",max(SEX,NEX));
fprintf(fpdem,"null: 32770\n");
printf("LAT/LONG of the 7.5 USGS Quad \n");
printf(" SW %f %f\n",SWX , SWY);
printf(" NW %f %f\n",NWX , NWY);
printf(" NE %f %f\n",NEX , NEY);
printf(" SE %f %f\n",SEX , SEY);
printf ("processing cells \n");
cells_out(status);
printf("\nEnd of Program\n");
/*Close files and end */
fclose (fpdem);
exit(0);
}
/***********************/
void dem_rc(int status)
{
strcpy (file_name,base_name);
strcat (file_name,"LDEF.DDF");
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nCAN'T OPEN 'dem' LDEF FILE %s",file_name);
exit(0);
}
/* Read data descriptive record (DDR) */
if (! rd123ddrec
(fpin, /* file pointer */
string, /* DDR record returned */
&status)) /* status returned */
{
printf ("\n*** ERROR READING DDR *** %d",status);
fprintf (fpdem,"\n*** ERROR READING DDR *** %d",status);
goto done;
}
status = -1;
/* Loop to process each subfield */
do
{
/* Read data record subfield */
if (! rd123sfld
(fpin, /* file pointer */
tag, /* field tag returned */
&leadid, /* leader identifier returned */
string, /* subfield contents returned */
&str_len, /* length of subfield */
&status)) /* status returned */
{
printf ("\nERROR READING DATA RECORD SUBFIELD");
fprintf (fpdem,"\nERROR READING DATA RECORD SUBFIELD");
goto done;
}
/* Retrieve description of current subfield */
if (! chk123sfld
(fpin, /* file pointer */
tag, /* tag output */
descr, /* subfield descriptions output */
frmts)) /* subfield format control */
{
printf ("\nERROR CHECKING DATA RECORD SUBFIELD");
fprintf (fpdem,"\nERROR CHECKING DATA RECORD SUBFIELD");
goto done;
}
/* Process based on field and subfield tags */
if ( !strcmp(tag,"LDEF") && !strcmp(descr,"NROW"))
{
nrow = atol (string);
}
else if ( !strcmp(tag,"LDEF") && !strcmp(descr,"NCOL"))
{
ncol = atol (string);
}
/* If end of record, write out record and reinitialize */
if (status == 3 || status == 4)
{
/* printf ("dem _rc nrow = %ld, ncol= %ld \n",nrow,ncol);*/
}
} while (status != 4); /* Break out of loop at end of file */
done:
stat2 = end123file (&fpin);
return;
}
/*********************************************/
void get_iref(void)
{
/* set some default values */
sfax = 1.0;
sfay = 1.0;
xorg = 0.0;
yorg = 0.0;
strcpy (file_name,base_name);
strcat (file_name,"IREF.DDF");
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nERROR OPENING FILE %s",file_name);
exit(0);
}
if (! rd123ddrec
(fpin, /* file pointer */
string, /* DDR record returned */
&status)) /* status returned */
{
printf ("\n*** ERROR READING DDR ***");
goto done;
}
status = -1;
/* Loop to process each subfield in Identification module */
do {
/* Read data record subfield */
if (! rd123sfld
(fpin, /* file pointer */
tag, /* field tag returned */
&leadid, /* leader identifier returned */
string, /* subfield contents returned */
&str_len, /* string length */
&status)) /* status returned */
{
printf ("\nERROR READING DATA RECORD SUBFIELD (IDEN MODULE)");
goto done;
}
/* Retrieve description of current subfield */
if (! chk123sfld
(fpin, /* file pointer */
tag, /* tag output */
descr, /* subfield descriptions output */
frmts)) /* subfield format control */
{
printf ("\nERROR CHECKING DATA RECORD SUBFIELD");
goto done;
}
/* check subfield name and extract contents for each subfield */
if (!strcmp (tag, "IREF") && !strcmp (descr, "SFAX"))
sfax = atof(string) ;
else if (!strcmp (tag, "IREF") && !strcmp (descr, "SFAY"))
sfay = atof(string) ;
else if (!strcmp (tag, "IREF") && !strcmp (descr, "XORG"))
xorg = atof(string) ;
else if (!strcmp (tag, "IREF") && !strcmp (descr, "YORG"))
yorg = atof(string) ;
else if (!strcmp (tag, "IREF") && !strcmp (descr, "XHRS"))
xhrs = atof(string) ;
else if (!strcmp (tag, "IREF") && !strcmp (descr, "YHRS"))
yhrs = atof(string) ;
} while (status != 4); /* Break out of loop at end of file */
width = xhrs;
height = yhrs;
done:
stat2 = end123file (&fpin);
/*
printf ("\nsfax: %f",sfax);
printf ("\nsfay: %f",sfay);
printf ("\nxorg: %f",xorg);
printf ("\nyorg: %f",yorg);
*/
printf ("\ncell width: %f",width);
printf ("\ncell height: %f",height);
return;
}
/*********************************************/
void get_xref(void)
{
/* set some default values */
strcpy(rsnm,"??1") ;
/*strcpy(hdat,"??2") ;*/
/*strcpy(rdoc,"??3") ;*/
strcpy (file_name,base_name);
strcat (file_name,"XREF.DDF");
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nERROR OPENING FILE %s",file_name);
exit(0);
}
if (! rd123ddrec
(fpin, /* file pointer */
string, /* DDR record returned */
&status)) /* status returned */
{
printf ("\n*** ERROR READING DDR ***");
goto done;
}
status = -1;
/* Loop to process each subfield in Identification module */
do {
/* Read data record subfield */
if (! rd123sfld
(fpin, /* file pointer */
tag, /* field tag returned */
&leadid, /* leader identifier returned */
string, /* subfield contents returned */
&str_len, /* string length */
&status)) /* status returned */
{
printf ("\nERROR READING DATA RECORD SUBFIELD (IDEN MODULE)");
goto done;
}
/* Retrieve description of current subfield */
if (! chk123sfld
(fpin, /* file pointer */
tag, /* tag output */
descr, /* subfield descriptions output */
frmts)) /* subfield format control */
{
printf ("\nERROR CHECKING DATA RECORD SUBFIELD");
goto done;
}
/* check subfield name and extract contents for each subfield */
if (!strcmp (tag, "XREF") && !strcmp (descr, "RSNM"))
strcpy(rsnm,string) ;
else if (!strcmp (tag, "XREF") && !strcmp (descr, "ZONE"))
zone = atoi(string) ;
/*
else if (!strcmp (tag, "XREF") && !strcmp (descr, "HDAT"))
strcpy(hdat,string) ;
else if (!strcmp (tag, "XREF") && !strcmp (descr, "RDOC"))
strcpy(rdoc,string) ;
*/
} while (status != 4); /* Break out of loop at end of file */
/*
printf ("hdat: %s\n",hdat);
printf ("rdoc: %s\n",rdoc);
*/
printf ("\nrsnm: %s\n",rsnm);
printf ( "zone: %d\n",zone);
done:
stat2 = end123file (&fpin);
return;
}
/***************************************/
void dem_head(int status)
{
/* Open Identification module */
strcpy (file_name,base_name);
strcat (file_name,"IDEN.DDF");
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nERROR OPENING FILE %s",file_name);
exit(0);
}
/*printf ("\n\nIdentification module: %s\n",file_name);*/
/* Read Identification module data descriptive record (DDR) */
if (! rd123ddrec
(fpin, /* file pointer */
string, /* DDR record returned */
&status)) /* status returned */
{
printf ("\n*** ERROR READING DDR ***");
goto done;
}
status = -1;
/* Loop to process each subfield in Identification module */
do {
/* Read data record subfield */
if (! rd123sfld
(fpin, /* file pointer */
tag, /* field tag returned */
&leadid, /* leader identifier returned */
string, /* subfield contents returned */
&str_len, /* string length */
&status)) /* status returned */
{
printf ("\nERROR READING DATA RECORD SUBFIELD (IDEN MODULE)");
goto done;
}
/* Retrieve description of current subfield */
if (! chk123sfld
(fpin, /* file pointer */
tag, /* tag output */
descr, /* subfield descriptions output */
frmts)) /* subfield format control */
{
printf ("\nERROR CHECKING DATA RECORD SUBFIELD");
goto done;
}
/* Display subfield name and contents for each subfield */
if (!strcmp (tag, "IDEN") && !strcmp (descr, "TITL"))
/* title */
printf ("\nTitle: %-41s\n",string);
else if (!strcmp (tag, "IDEN") && !strcmp (descr, "SCAL"))
{
/* scale */
scale = atol(string);
printf ("scale: %8s\n",string);
}
else if (!strcmp (tag, "IDEN") && !strcmp (descr, "DAID"))
printf ("Data ID: %s\n",string);
else if (!strcmp (tag, "IDEN") && !strcmp (descr, "MPDT"))
printf ("Map Date: %s\n",string);
else if (!strcmp (tag, "IDEN") && !strcmp (descr, "DCDT"))
printf ("Data set creation date: %s\n",string);
} while (status != 4); /* Break out of loop at end of file */
done:
/* Close input Identification module */
status = end123file (&fpin);
}
/*********************************************/
void dem_mbr(int status)
{
int seq=0;
double fl;
/* int label ;*/
strcpy (file_name,base_name);
strcat (file_name,"SPDM.DDF");
/* strcat (file_name,module);*/
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nCAN'T OPEN 'dem' SPDM FILE %s",file_name);
exit(0);
}
/* Read data descriptive record (DDR) */
if (! rd123ddrec
(fpin, /* file pointer */
string, /* DDR record returned */
&status)) /* status returned */
{
printf ("\n*** ERROR READING DDR *** %d",status);
fprintf (fpdem,"\n*** ERROR READING DDR *** %d",status);
goto done;
}
status = -1;
nxy = 1; /* number of coordinate pairs */
/* Loop to process each subfield */
do {
/* Read data record subfield */
if (! rd123sfld
(fpin, /* file pointer */
tag, /* field tag returned */
&leadid, /* leader identifier returned */
string, /* subfield contents returned */
&str_len, /* length of subfield */
&status)) /* status returned */
{
printf ("\nERROR READING DATA RECORD SUBFIELD");
fprintf (fpdem,"\nERROR READING DATA RECORD SUBFIELD");
goto done;
}
/* Retrieve description of current subfield */
if (! chk123sfld
(fpin, /* file pointer */
tag, /* tag output */
descr, /* subfield descriptions output */
frmts)) /* subfield format control */
{
printf ("\nERROR CHECKING DATA RECORD SUBFIELD");
fprintf (fpdem,"\nERROR CHECKING DATA RECORD SUBFIELD");
goto done;
}
/* Process based on field and subfield tags */
if ( !strcmp(tag,"DMSA"))
{
/* printf("tag = %s,descr = %s, string = %s\n",tag,descr,string); */
fl = atof (string);
/* Process if X spatial address */
if (!strcmp (descr, "!X"))
{
x[nxy] = fl;
}
/* Process if Y spatial address */
else if (!strcmp (descr, "!Y"))
{
y[nxy] = fl;
nxy++;
}
}
/* If end of record, write out record and reinitialize */
if (status == 3 || status == 4)
{
seq++;
for (i = i; i < nxy; i++)
{
/* Convert internal coordinates to external system */
/*
xtemp = ((double) x[0] * sfax) + xorg;
ytemp = ((double) y[0] * sfay) + yorg;
*/
if ( i==1 )
{
SWX = x[i];
SWY = y[i];
}
else if ( i==2 ) /*printf( "NW= ");*/
{
NWX = x[i];
NWY = y[i];
}
else if ( i==3 ) /*printf( "NE= ");*/
{
NEX = x[i];
NEY = y[i];
}
else if ( i==4 ) /* printf( "SE= ");*/
{
SEX = x[i];
SEY = y[i];
}
/* printf ("dem mbr %12.2f %12.2f,%12.2f %12.2f,
%12.2f %12.2f,%12.2f %12.2f \n",
SWX,SWY,NWX,NWY,NEX,NEY,SEX,SEY);
*/
/* fprintf (fpdem,"mbr %12.2f %12.2f \n, %12.2f %12.2f \n,
%12.2f %12.2f \n, %12.2f %12.2f \n",
SWX,SWY,NWX,NWY,NEX,NEY,SEX,SEY);
*/
}
nxy=0;
}
} while (status != 4); /* Break out of loop at end of file */
/*
printf ("sw dem mbr %12.2f %12.2f \n", SWX,SWY);
printf ("nw dem mbr %12.2f %12.2f \n", NWX,NWY);
printf ("se dem mbr %12.2f %12.2f \n", SEX,SEY);
printf ("ne dem mbr %12.2f %12.2f \n", NEX,NEY);
*/
done:
/* done2: */
stat2 = end123file (&fpin);
return;
}
/*********************************************/
void cell_range(int status)
{
int seq=0;
int recid;
strcpy (file_name,base_name);
strcat (file_name,"DDOM.DDF");
/*printf( "looking for cell range info in DDOM file\n");*/
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nERROR OPENING FILE %s",file_name);
exit(0);
}
if (! rd123ddrec
(fpin, /* file pointer */
string, /* DDR record returned */
&status)) /* status returned */
{
printf ("\n*** ERROR READING DDR ***");
goto done;
}
status = -1;
/* Loop to process each subfield in CATS module */
do {
/* Read data record subfield */
if (! rd123sfld
(fpin, /* file pointer */
tag, /* field tag returned */
&leadid, /* leader identifier returned */
string, /* subfield contents returned */
&str_len, /* string length */
&status)) /* status returned */
{
printf ("\nERROR READING DATA RECORD SUBFIELD (AHDR MODULE)");
goto done;
}
/* Retrieve description of current subfield */
if (! chk123sfld
(fpin, /* file pointer */
tag, /* tag output */
descr, /* subfield descriptions output */
frmts)) /* subfield format control */
{
printf ("\nERROR CHECKING DATA RECORD SUBFIELD");
goto done;
}
/* check subfield name and extract contents for each subfield */
if (!strcmp (tag, "DDOM") && !strcmp (descr, "RCID"))
{
/* printf("RECID as string %s \n", string);*/
recid = atoi(string);
/* printf ("rec id as number= %d \n",recid);*/
}
else if (recid == 1 && !strcmp ( descr,"DVAL"))
{
voidvalue = atoi (string) ;
/* printf ("void %d %s %d\n",recid,string, voidvalue);*/
}
else if (recid == 2 && !strcmp ( descr,"DVAL"))
{
fillvalue = atoi(string) ;
/* printf ("fill %d %s %d\n",recid,string, fillvalue);*/
}
else if (recid == 3 && !strcmp ( descr,"DVAL"))
{
minvalue = atoi (string) ;
/* printf ("min %d %s %d\n",recid,string, minvalue);*/
}
else if (recid == 4 && !strcmp ( descr,"DVAL"))
{
maxvalue = atoi (string) ;
/* printf ("max %d %s %d\n",recid,string, maxvalue);*/
}
} while (status != 4); /* Break out of loop at end of file */
done:
stat2 = end123file (&fpin);
return;
}
/***************************************************************************
**
** INVOCATION NAME: S123TOL2
**
** PURPOSE: TO CONVERT A 2 CHARACTER STRING TO A LONG INTEGER AND
** CHANGE ITS BYTE ORDERING WHEN SPECIFIED
**
** INVOCATION METHOD: S123TOL(STRING,NUM,REVERSE)
**
** ARGUMENT LIST:
** NAME TYPE USE DESCRIPTION
** STRING[] PTR I CHARACTER STRING
** NUM LONG O NUMBER TO BE CONVERTED
** REVERSE LOGICAL I REVERSE BYTE ORDER FLAG
** 1 - REVERSE
** 0 - DO NOT REVERSE
** S123TOL2() LOGICAL O SUCCESS FLAG
**
** EXTERNAL FUNCTION REFERENCES: NONE
**
** INTERNAL VARIABLES:
** NAME TYPE DESCRIPTION
** MSB unsigned char most significant digit
** LSB unsigned char lest significant digit
** I4 long int temp variable
**
** GLOBAL REFERENCES: NONE
**
** GLOBAL VARIABLES: NONE
**
** GLOBAL CONSTANTS: NONE
**
** CHANGE HISTORY:
** AUTHOR CHANGE_ID DATE CHANGE SUMMARY
** sol katz(blm) 3/20/98 created
**
**
******************************************************************************
** CODE SECTION
**
*****************************************************************************/
/*#include "stc123.h"*/
int s123tol2(string,num,reverse)
char *string;
long *num;
int reverse;
{
/* INTERNAL VARIABLES */
unsigned char MSB;
unsigned char LSB;
long i4;
int I256 = 256;
if (reverse) { /* IF BYTE ORDER TO BE REVERSED */
/* MOVE INPUT STRING TO WORK STRING IN REVERSE BYTE ORDER */
MSB = string[0];
LSB = string[1];
/* printf("\nreverse %2.2x %2.2x %d %d\n", MSB, LSB, MSB, LSB); */
}
else {
/* MOVE INPUT STRING TO WORK STRING WITH NO CHANGE IN BYTE ORDER */
MSB = string[1];
LSB = string[0];
/* printf("\nstandard %2.2x %2.2x \n", MSB, LSB);*/
}
/* MOVE WORK INTEGER TO OUTPUT LONG INTEGER */
i4 = (unsigned long) (MSB * I256) ;
i4 = i4 + LSB;
*num = i4;
/* RETURN SUCCESS */
return(1);
}
/********************************************/
void cells_out(int status)
{
strcpy (file_name,base_name);
strcat (file_name,"CE");
strcat (file_name,cellid);
strcat (file_name,".DDF");
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nCAN'T OPEN CELL VALUES FILE %s...",file_name);
return ;
}
/* Read data descriptive record (DDR) */
if (! rd123ddrec
(fpin, /* file pointer */
string, /* DDR record returned */
&status)) /* status returned */
{
printf ("\n*** ERROR READING DDR ***");
fprintf (fpdem,"\n*** ERROR READING DDR ***");
goto done;
}
status = -1;
/* Loop to process each subfield */
do {
/* Read data record subfield */
if (! rd123sfld
(fpin, /* file pointer */
tag, /* field tag returned */
&leadid, /* leader identifier returned */
string, /* subfield contents returned */
&str_len, /* string length */
&status)) /* status returned */
{
printf ("\nERROR READING DATA RECORD SUBFIELD");
goto done;
}
/* Retrieve description of current subfield */
if (! chk123sfld
(fpin, /* file pointer */
tag, /* tag output */
descr, /* subfield descriptions output */
frmts)) /* subfield format control */
{
printf ("\nERROR CHECKING DATA RECORD SUBFIELD");
fprintf (fpdem,"\nERROR CHECKING DATA RECORD SUBFIELD");
goto done;
}
/* only output if format is 2 byte binary format */
if (strstr (frmts, "B") != NULL)
{
/* memcpy (temp, string, str_len);*/
strncpy (temp, string, (int)str_len);
if (str_len == 2)
{
/* If little endian, switch byte order within long word
(SDTS requires "big endian" representation */
if (!order)
{
s123tol2 (string, &li, 1);
}
else
{
s123tol2 (string, &li, 0);
}
/* fprintf (fpdem,"%6d %6d %7ld\n",row, col++, li);*/
col++;
fprintf (fpdem,"%7ld",li);
}
}
/* Output record/end of file delimeters */
if (status == 3) /* subfield is at end of record */
{
/* newline to mark end of row */
fprintf (fpdem,"\n");
row ++;
if (maxcol < col)
{
maxcol = col;
/* printf ("max col = %d \n",maxcol);*/
}
col = 1;
/*
printf ("\n##### End of Row %d ######", row);
*/
}
else if (status == 4) /* subfield is at end of file */
{
printf ("\n END OF FILE \n");
/* printf ("rows = %d cols = %d \n", row, maxcol-1);*/
}
} while (status != 4); /* Break out of loop at end of file */
done:
/*done2:*/
/* Close input ISO 8211 file */
status = end123file (&fpin);
}
/*********************************************/
void get_nw_corner(void)
{
long sadr_x,sadr_y;
strcpy (file_name,base_name);
strcat (file_name,"RSDF.DDF");
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nERROR OPENING FILE %s",file_name);
exit(0);
}
if (! rd123ddrec
(fpin, /* file pointer */
string, /* DDR record returned */
&status)) /* status returned */
{
printf ("\n*** ERROR READING DDR ***");
goto done;
}
status = -1;
/*
Loop to process each subfield in Raster Definition module */
do
{
/* Read data record subfield */
if (! rd123sfld
(fpin, /* file pointer */
tag, /* field tag returned */
&leadid, /* leader identifier returned */
string,
/* subfield contents returned */
&str_len, /* string length */
&status)) /* status returned */
{
printf ("\nERROR READING DATA RECORD SUBFIELD (IDEN MODULE)");
goto done;
}
/* Retrieve description of current subfield */
if (! chk123sfld
(fpin, /* file pointer */
tag, /* tag output */
descr, /* subfield descriptions output */
frmts)) /* subfield format control */
{
printf ("\nERROR CHECKING DATA RECORD SUBFIELD");
goto done;
}
/* check subfield name and extract contents for each subfield */
if (!strcmp (tag, "SADR") && !strcmp (descr, "X"))
{
/* Binary data, convert character string returned by rd123sfld to a
long integer, changing bit order if necessary */
if (strstr (frmts,"B") != null)
{
if (!order)
s123tol (string, &sadr_x, 1);
else
s123tol (string, &sadr_x, 0);
}
}
else if (!strcmp (tag, "SADR") && !strcmp (descr, "Y"))
{
/* Binary data, convert character string returned by rd123sfld to a
long integer, changing bit order if necessary */
if (strstr (frmts,"B") != null)
{
if (!order)
s123tol (string, &sadr_y, 1);
else
s123tol (string, &sadr_y, 0);
}
}
} while (status != 4); /* Break out of loop at end of file */
done:
stat2 = end123file (&fpin);
upperlx = (sadr_x * sfax ) + xorg;
upperly = (sadr_y * sfay ) + yorg;
/*
printf ("\nsadr_x: %ld",sadr_x);
printf ("\nsadr_y: %ld",sadr_y);
printf ("\nupperlx: %f",upperlx);
printf ("\nupperly: %f",upperly);
*/
return;
}
/*********************************************/
More information about the grass-dev
mailing list