Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

how to put a F90 string array into netCDF file?
Hello,

We want to put a character array like e.g.

character (30) :: err_string(35)

via the netCDF F90 function nf90_put_var(ncFileID, err_list_ID, err_string)

into a nc-file.

After several fruitless attempts (e.g. copying err_string into
a character(1), dimension=30x35 variable) we got completely stuck...
The online documentation http://www.unidata.ucar.edu/package.../f90-html-docs/
is not too specific on that topic...

Does anybody have a short example code how to do this.
Even a hint of how to write a simple string would be helpful.

Thanks in advance!

Michael Kiefer & Udo Grabowski

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Kiefer
03-27-04 05:17 AM


Re: how to put a F90 string array into netCDF file?
Michael Kiefer wrote:
> Hello,
>
> We want to put a character array like e.g.
>
> character (30) :: err_string(35)
>
> via the netCDF F90 function nf90_put_var(ncFileID, err_list_ID, err_string
)
>
> into a nc-file.
>
> After several fruitless attempts (e.g. copying err_string into
> a character(1), dimension=30x35 variable) we got completely stuck...
> The online documentation
> [url]http://www.unidata.ucar.edu/packages/netcdf/f90/Documentation/f90-html-docs/[/ur
l]
>
> is not too specific on that topic...
>
> Does anybody have a short example code how to do this.
> Even a hint of how to write a simple string would be helpful.
>
> Thanks in advance!

Hello,

Unfortunately it's not a trivial thing to do, but it's not too hard either.

The important thing is that netCDF really doesn't understand the concept of 
a "string" (as
far as I can tell). Think of it more as an array of single characters (or by
tes) -- so you
were on the rigth track.

The important step is to define the (maximum) length of the string (in your 
case, 30) as a
dimension:

NF90_Status = NF90_DEF_DIM( NC_FileID, &
'StrLen', &
LEN(err_string(1)), &
StrLen_DimID )

Same as for the "regular" dimension:

NF90_Status = NF90_DEF_DIM( NC_FileID, &
'n_Strings', &
SIZE(err_string), &
n_Strings_DimID )

Then you define your string array variable with the string length as the fir
st dimension:

NF90_Status = NF90_DEF_VAR( NC_fileID, &
'StringArray, &
NF90_CHAR, &
DimIDs = (/ StrLen_DimID, n_Strings_DimID /), &
VarID  = StringArray_VarID )

and after putting the file into data mode, you write the 2-d character array
:

NF90_Status = NF90_PUT_VAR( NC_FileID, &
StringArray_VarID, &
err_string )

Same for reading the string array,

NF90_Status = NF90_GET_VAR( NC_FileID, &
StringArray_VarID, &
err_string_to_read )


Typically when doing this I inquire the string length dimension and make sur
e it matches
what I'm read/writing, e.g.

NF90_Status = NF90_INQUIRE_DIMENSION( NC_FileID, &
StrLen_DimID, &
Len  = String_Length )

IF ( String_Length /= LEN( err_string(1) ) ) THEN
..issue error message...
END IF

I issue an error, but in most cases a warning would probably suffice. I have
 found,
though, that in writing character string to netCDF files, if what you're wri
ting is longer
than what you've defined, weird things can happen. (To be fair I've only not
iced it with
writing attributes which don't require this rigamarole but once bitten....)

All the above goes for higher dimensioned character string arrays. Just reme
mber to always
declare the string length as the first dimension in the "DimIDs" array in NF
90_DEF_VAR.

Hope this helps.

cheers,

paulv


Report this thread to moderator Post Follow-up to this message
Old Post
Paul Van Delst
03-27-04 05:17 AM


Re: how to put a F90 string array into netCDF file?
Hi Paul,

thanks for your sound advice! Now it works as expected.

The crucial point indeed is to declare the F90 variable
"as usual", e.g. character (30) :: err_string(35)
and then "make the netCDF believe" it is a two dimensional
array of single characters.

Cheers,

Michael & Udo, happy again ;-)

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Kiefer
03-27-04 05:17 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:06 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.