Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
20 Views

optional parameter error

My dear friend:

my new version compiler is ifort version 19.0.2.187

system is linux(redhat)

my compiler is following:

ifort -c head_sublibf.f90 -std03 -fPIC -assume nounderscore -assume bscc -assume byterecl -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fpp

my code Complier and link is ok ,but run my code ,when it call the subroutinue is core .

If optional no default, i have it trc = 1 and channel = 0, my code runing is ok!

please help me ,thank!

 

following is part code :

!   my module:head_sublibf.f90      hdd_get is polymorphism  interface

   MODULE head_sublibf

    interface

    integer( c_int ) function hdd_seti_by_name(name,head_buffer,result,trc,channel )  bind( C )

    use, intrinsic::ISO_C_BINDING

    implicit none

    character (len = *) ::name

    integer(C_INT), dimension(*)::head_buffer

    integer (C_INT):: result

    integer (C_INT),OPTIONAL:: trc

    integer (C_INT),OPTIONAL:: channel

    end function hdd_seti_by_name

   end interface

    INTERFACE hdd_get

      MODULE PROCEDURE fhddgeti_byname

      MODULE PROCEDURE fhddgetl_byname

      MODULE PROCEDURE fhddgetf_byname

      MODULE PROCEDURE fhddgetd_byname

    END INTERFACE

      integer(C_INT) FUNCTION fhddgeti_byname( name,head_buffer,result,trc,channel )

      use,intrinsic::ISO_C_BINDING

      implicit none

        character (len = *) ::name

        integer(C_INT), dimension(*)::head_buffer

        integer (C_INT):: result

        integer (C_INT),OPTIONAL:: trc

        integer (C_INT),OPTIONAL:: channel

        integer (C_INT)::trc_default

        integer (C_INT)::channel_default

 

        write(*,*) "--------- fhddgeti :",name

        write(*,*) "trc:",trc

        write(*,*) "channel: ",channel

 

        if(present(trc) ) then

           trc_default =trc

        else

!           write(*,*) " default parameter --- trc"

           trc_default =1

        endif

 

        if(present(channel)) then

           channel_default =channel        

        else

!           write(*,*) " default parameter --- channel"

           channel_default =0

        endif

        

!        write(*,*) "--------- fhddgeti - name :",no   

!        write(*,*) "--------- fhddgeti - trc:",trc_default

!        write(*,*) "--------- fhddgeti - channel:",channel_default

 

        fhddgeti_byname = hdd_geti_by_name(name,head_buffer,result,trc_default,channel_default)

      END FUNCTION

   ............

 

    END MODULE

 

following is program.  it call module (head_sublibf.f90)

 

 1         dytest1 = hdd_get("max_samples",head,iresult,1,0)

 2         write(*,*) "AM---name parameter samples-------n :",dytest1, iresult

 3         dytest = hdd_get("max_samples",head,iresult)

 4         write(*,*) "AM---name parameter samples --- name:",dytest, iresult

 

code Line Numbers 1  optional parameter is 1,0 .i give it .the subroutine call is right. Line Numbers 2 give right resulte.

code Line Numbers 3  the optional parameter i use default value. (default is 1,0). the subroutine call is core.

i don't know why?

please tell me 。 where is wrong ? thanks!

 

0 Kudos
5 Replies
Highlighted
Black Belt
20 Views

Please present working program source that can be compiled and run. What you showed above is quite incomplete and the parts shown are fragmented.

0 Kudos
Highlighted
Beginner
20 Views

My job code, call a lot of other people's code, without that code can't run, I can only give such logic code。

I suspect that string in the module and interface, cause the failure of the program runs。

But I'm not sure, i do not know how to define is right.

 

0 Kudos
Highlighted
20 Views

Does: fhddgeti_byname = hdd_geti_by_name(name,head_buffer,result,trc_default,channel_default)

Open an I/O unit associated with the value of channel_default and/or trc_default?

If so, then if  hdd_geti_by_name also leaves the I/O unit open, then the second call using the same values for channel_default and/or trc_default will error on I/O unit in use.

Jim Dempsey

0 Kudos
Highlighted
Beginner
20 Views

hdd_geti_by_name is c subroutine.  channel_default and/or trc_default is optional parameter in hdd_geti_by_name.

0 Kudos
Highlighted
20 Views

While hdd_geti_by_name is a C routine, it may still obtain a resource based on channel_default and/or trc_default. Ergo the question remains unanswered: Does the first call to hdd_geti_by_name (with the same values for channel_default and/or trc_default) cause a conflict (i.e. in use) when called the second time with the same values?

Jim Dempsey

0 Kudos