Using NWTC Library outside of FAST

Hi

I’d like to create a simple test environment to help me create code and get it working before I add it to the rest of FAST, where there is lots going on that I don’t know about. I’d like to use the functions in the NWTC library though, so that when I do integrate my new stuff, things are relatively seamless.

I’ve found and fixed some little things, like USE NWTC_Library is not enough to get a good value of Pi, I also need to CALL NWTC_Init. (Actually, this is mentioned in the Programmer’s Handbook, so I should have read that in the first instance.)

Weirdly, when I CALL NWTC_Init, the subroutine WrScr() works fine:

and so do the PRINT*, ‘…’ commands that I’m using.
But when I put WrScr() into my main program, it all goes wrong and I get:

from this:

CALL WrScr ( 'STOP requested by DISCON.DLL: ' )

There isn’t much in Appendix K about this problem though, so I thought I’d ask here…

Thanks for your help.

Hi I’ve found that the Visual Fortran compiler likes to use 6 as access to the console ( software.intel.com/sites/product … C4CA5D.htm ), not 7 which is set in SysSubs line 45.

I’ve found that this is the line that crashes my application:

      WRITE (CU,Frm)  TRIM( ADJUSTL( Str(Beg:Beg+LStr-1) ) )

The debugger tells me that CU = 7, Frm = ‘(1X, 0X,A)’, Str = 'STOP requested by DISCON.DLL ', Beg = 1 and LStr = 28

Then I wrote

WRITE (6,'(1X, 0X,A)')  TRIM( ADJUSTL( 'STOP requested by DISCON.DLL '(1:1+28-1) ) )

in my main program, but it refused to build, saying

I’m trying to figure out the ‘(1X, 0X,A)’ at the moment.

Alec,

The “0X” is for the indent and it’s an invalid format. What version of the library are you using? The one I’m looking at (v1.04.01, 21-Feb-2012) has a check for zero-length indents and uses (1X,A) instead of (1X,0X,A) for the format:

MaxLen = 98 Indent = LEN_TRIM( Str ) - LEN_TRIM( ADJUSTL( Str ) ) Indent = MIN( Indent, MaxLen-2 ) ! at least 2 characters per line MaxLen = MaxLen - Indent IF ( Indent > 0 ) THEN Frm = '(1X, X,A)' WRITE (Frm(5:6),'(I2)') Indent ELSE Frm = '(1X,A)' END IF

Phew!

All figured out. So, here is a snippet of code from the subroutine WrScr

MaxLen = 98 Indent = LEN_TRIM( Str ) - LEN_TRIM( ADJUSTL( Str ) ) MaxLen = MaxLen - Indent Frm = '(1X, X,A)' WRITE (Frm(5:6),'(I2)') Indent

I’m not sure about why this is being done, but Indent ends up being equal to the number of leading spaces that there are in Str. It looks like we’re chopping the leading spaces off and putting them back on again.

If Str = ‘Anything without a leading space’, Indent = 0 and the program crashes, because you aren’t allowed to have ‘0X’ spaces in a format statement.

Nearly all the messages in FAST have a leading space. So this might be why it hasn’t been noticed.

Please could I suggest the following:

Indent = MAX(LEN_TRIM( Str ) - LEN_TRIM( ADJUSTL( Str ) ),1) MaxLen = MaxLen - Indent Frm = '(1X, X,A)' WRITE (Frm(5:6),'(I2)') Indent

So that Indent is always at least 1. With this, my code is very happy about sending me messages.

By the way, the CU = 7 doesn’t seem to be a problem when used by the WrScr Subroutine, but if I put

WRITE (7,'(1X,1X,A)')  TRIM( ADJUSTL( 'STOP requested by DISCON.DLL '(1:1+28-1) ) )

My program breaks at that statement, but a 6 is fine.

Please could you let me know if you’ll incorporate into the next version?

Thanks

Thanks Marshall

Looks like we sort of spoke over each other…

So, it looks like your library code has something in it to deal with a ‘0X’ situation.

I think I am using the version of the library that you suggest and here is what i have in my NWTC_IO.f90:

CHARACTER(29) :: NWTCName = 'NWTC Subroutine Library' ! The name of the NWTC subroutine library. CHARACTER(29) :: NWTCVer = ' (v1.04.01, 21-Feb-2012)' ! The version (including date) of the NWTC Subroutine Library.

So then I thought I must have mixed up my files with a previous version, so my SysVF.f90 might be wrong but my NWTC_IO is right. I downloaded the library from this link:
wind.nrel.gov/designcodes/miscel … .04.01.exe

and ran a compare on the files.

The only difference between my version 1.04.01 and the one from the above link I could find was:

Which is what I did to it.

So it looks like there might be an issue with the version in the link and the one on your computer.

Could you check it out please?

Thanks

Alec

Hi, Alec.

It looks like you are using SysVF.f90 and we are using SysIVF.f90. And apparently we didn’t copy the change from the IVF file into the VF file. In the next release of the library, we are getting rid of the SysVF and SysCVF files so we don’t have so many copies of things floating around, with the potential of errors like this happening. If you switch to the SysIVF.f90 file, the problem should go away.

Sorry for the confusion.

And to explain a few other things you’ve asked/noticed:

[]What that indent is all about: If the string to be written to the screen is longer than MaxLen (98) characters, it is split into several lines, and each line is indented the same amount of space.[/]
[]The console unit number: Ideally, we’d like to use unit 6, as that is typically the standard unit to write to the screen (most compilers preconnect 6 to standard output, but I don’t think that is officially in the Fortran standard). Earlier versions of the IVF compiler had a bug when we used unit 6, so we decided to use unit 7 along with the OpenCon() subroutine. That bug has been fixed, but we still have problems using unit 6 when we link with MSC.Adams using ADAMS2AD so we have left it as unit 7 for now.[/]
[]Library initialization: As you’ve noticed, you must call NWTC_Init() so that the constants–like pi–are set. The NWTC_Init() routine also calls OpenCon(). If your example of writing to unit 7 didn’t call OpenCon() or NWTC_Init() first, that could explain why it didn’t work.[/]

Perfect.

Thanks Bonnie

Alec