コード例 #1
0
ファイル: ddffielddefn.cpp プロジェクト: bbradbury/lib_gdal
void DDFFieldDefn::AddSubfield( const char *pszName,
                                const char *pszFormat )

{
    DDFSubfieldDefn *poSFDefn = new DDFSubfieldDefn;

    poSFDefn->SetName( pszName );
    poSFDefn->SetFormat( pszFormat );
    AddSubfield( poSFDefn );
}
コード例 #2
0
ファイル: ddffielddefn.cpp プロジェクト: bbradbury/lib_gdal
int DDFFieldDefn::BuildSubfields()

{
    char        **papszSubfieldNames;
    const char  *pszSublist = _arrayDescr;

/* -------------------------------------------------------------------- */
/*      It is valid to define a field with _arrayDesc                   */
/*      '*STPT!CTPT!ENPT*YCOO!XCOO' and formatControls '(2b24)'.        */
/*      This basically indicates that there are 3 (YCOO,XCOO)           */
/*      structures named STPT, CTPT and ENPT.  But we can't handle      */
/*      such a case gracefully here, so we just ignore the              */
/*      "structure names" and treat such a thing as a repeating         */
/*      YCOO/XCOO array.  This occurs with the AR2D field of some       */
/*      AML S-57 files for instance.                                    */
/*                                                                      */
/*      We accomplish this by ignoring everything before the last       */
/*      '*' in the subfield list.                                       */
/* -------------------------------------------------------------------- */
    if( strrchr(pszSublist, '*') != NULL )
        pszSublist = strrchr(pszSublist,'*');

/* -------------------------------------------------------------------- */
/*      Strip off the repeating marker, when it occurs, but mark our    */
/*      field as repeating.                                             */
/* -------------------------------------------------------------------- */
    if( pszSublist[0] == '*' )
    {
        bRepeatingSubfields = TRUE;
        pszSublist++;
    }

/* -------------------------------------------------------------------- */
/*      split list of fields .                                          */
/* -------------------------------------------------------------------- */
    papszSubfieldNames = CSLTokenizeStringComplex( pszSublist, "!",
                                                   FALSE, FALSE );

/* -------------------------------------------------------------------- */
/*      minimally initialize the subfields.  More will be done later.   */
/* -------------------------------------------------------------------- */
    int nSFCount = CSLCount( papszSubfieldNames );
    for( int iSF = 0; iSF < nSFCount; iSF++ )
    {
        DDFSubfieldDefn *poSFDefn = new DDFSubfieldDefn;

        poSFDefn->SetName( papszSubfieldNames[iSF] );
        AddSubfield( poSFDefn, TRUE );
    }

    CSLDestroy( papszSubfieldNames );

    return TRUE;
}
コード例 #3
0
ファイル: fea2esig.c プロジェクト: rsprouse/espsfree
static FieldList
fea_to_FieldList(struct header	    *hdr,
		 struct fea_data    *rec,
		 char		    **field_names,
		 int		    copy_sources)
{
    struct fea_header	*fea;
    FieldList		list;
    int			i, j;
    FieldSpec		*field, *subfield;
    char		*name;
    int			spstype;
    long		*dim;
    int			rank;
    int			type;
    char		**codes;
    char		**gnames;
    int			gnum;
    struct varsize	*var;
    int			nsrc;
    FieldList		source;
    char		*line;
    long		len;


    if (hdr == NULL)
	return NULL;

    if (hdr->common.type != FT_FEA)
	return NULL;

    fea = hdr->hd.fea;

    list = NULL;

    if (hdr->common.tag && FindStr(ESPS_TAG, field_names))
    {
	field = NewFieldSpec(ELONG, 0);
	field->name = savestring(ESPS_TAG);
	field->occurrence = REQUIRED;
	if (rec != NULL)
	    field->data = &rec->tag;
	AddField(&list, field);
    }

    if (debug_level)
	fprintf(stderr, "fea_to_FieldList: field count %d.\n",
		fea->field_count);

    for (i = 0; i < (int) fea->field_count; i++)
    {
	long	size;

	name = fea->names[i];

	if (FindStr(name, field_names))
	{
	    spstype = fea->types[i];
	    size = fea->sizes[i];
	    rank = fea->ranks[i];
	    dim = fea->dimens[i];

	    if (debug_level >= 2)
		fprintf(stderr,
			"fea_to_FieldList: field[%d]: \"%s\".\n",
			i, name);

	    type = EspsTypeToElib(spstype);
	    field = NewFieldSpec(type, rank);
	    if (rank == 1)
		field->dim[0] = size;
	    else
		for (j = 0; j < rank; j++)
		    field->dim[j] = dim[j];
	    field->name = savestring(name);
	    field->occurrence = REQUIRED;
	    if (spstype == CODED)
	    {
		codes = fea->enums[i];
		subfield = NewFieldSpec(ECHAR, 2);
		subfield->name = savestring("enumStrings");
		subfield->occurrence = GLOBAL;
		StrArrToRect(codes, &subfield->dim, &subfield->data);
		AddSubfield(field, subfield);
	    }
	    if (rec != NULL)
		field->data = get_fea_ptr(rec, name, hdr);
	    AddField(&list, field);
	}
    }

    gnames = genhd_list(&gnum, hdr);

    for (i = 0; i < gnum; i++)
    {
	int	size;

	name = gnames[i];
	spstype = genhd_type(name, &size, hdr);

	if (debug_level >= 2)
	    fprintf(stderr,
		    "fea_to_FieldList: global field[%d]: \"%s\".\n",
		    i, name);

	type = EspsTypeToElib(spstype);
	field = NewFieldSpec(type, 1);
	field->dim[0] = size;
	field->name = savestring(name);
	field->occurrence = GLOBAL;
	if (spstype == CODED)
	{
	    codes = genhd_codes(name, hdr);
	    subfield = NewFieldSpec(ECHAR, 2);
	    subfield->name = savestring("enumStrings");
	    subfield->occurrence = GLOBAL;
	    StrArrToRect(codes, &subfield->dim, &subfield->data);
	    AddSubfield(field, subfield);
	}
	field->data = get_genhd(name, hdr);
	AddField(&list, field);
    }

    if (fea->fea_type != NONE)
    {
	field = AddGlobalField(&list, "FeaSubtype",
			       0, NULL, ESHORT, NULL);
	*(short *) field->data = fea->fea_type;
	subfield = NewFieldSpec(ECHAR, 2);
	subfield->name = savestring("enumStrings");
	subfield->occurrence = GLOBAL;
	StrArrToRect(fea_file_type, &subfield->dim, &subfield->data);
	AddSubfield(field, subfield);
    }

    var = &hdr->variable;

    if (copy_sources)
    {
	nsrc = MAX(var->nnames, var->nheads);
	for (i = 0; i < nsrc; i++)
	{
	    source = (i >= var->nheads) ? NULL
		: fea_to_FieldList(var->srchead[i], NULL, NULL, TRUE);
	    name = (i >= var->nnames) ? NULL
		: var->source[i];
	    (void) AddSource(&list, i, name, source);
	}
    }

    if (var->comment != NULL)
    {
	line = savestring(var->comment);
	len = strlen(line);
	if (line[len-1] == '\n')
	    line[len-1] = '\0';
	(void) AddCommandLine(&list, line);
    }

    return list;
}