attachedwallop

wallop  时间:2021-02-28  阅读:()
PGIFortranReferenceThePortlandGroupTMSTMicroelectronicsTwoCenterpointeDrive,Suite320LakeOswego,OR97035www.
pgroup.
comiiWhileeveryprecautionhasbeentakeninthepreparationofthisdocument,ThePortlandGroup,awholly-ownedsubsidiaryofSTMicroelectronics,makesnowarrantyfortheuseofitsproductsandassumesnoresponsibilityforanyerrorsthatmayappear,orfordamagesresultingfromtheuseoftheinformationcontainedherein.
STMicroelectronicsretainstherighttomakechangestothisinformationatanytime,withoutnotice.
ThesoftwaredescribedinthisdocumentisdistributedunderlicensefromSTMicroelectronicsandmaybeusedorcopiedonlyinaccordancewiththetermsofthelicenseagreement.
Nopartofthisdocumentmaybereproducedortransmittedinanyformorbyanymeans,foranypurposeotherthanthepurchaser'spersonalusewithouttheexpresswrittenpermissionofSTMicroelectronics.
Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsareclaimedastrademarks.
Wherethosedesignationsappearinthismanual,STMicroelectronicswasawareofatrademarkclaim.
Thedesignationshavebeenprintedincapsorinitialcaps.
ThanksisgiventotheParallelToolsConsortiumand,inparticular,totheHighPerformanceDebuggingForumfortheirefforts.
PGF90,PGF95,PGC++,ClusterDevelopmentKit,CDKandThePortlandGrouparetrademarksandPGI,PGHPF,PGF77,PGCC,PGPROF,andPGDBGareregisteredtrademarksofSTMicroelectronics,Inc.
Otherbrandsandnamesarethepropertyoftheirrespectiveowners.
TheuseofSTLport,aC++Library,islicensedseparatelyandlicense,distributionandcopyrightnoticecanbefoundinonlinedocumentationforagivenreleaseofthePGIcompilersandtools.
PGIFortranReferenceCopyright2005-2007,STMicroelectronics,Inc.
Allrightsreserved.
PrintedintheUnitedStatesofAmericaFirstPrinting:Release6.
0,March,2005SecondPrinting:Release6.
1,December,2005ThirdPrinting:Release6.
1-3,February,2006FourthPrinting:Release7.
0-1,December,2006FifthPrinting:Release7.
0-2,February,2007Technicalsupport:http://www.
pgroup.
com/support/Sales:sales@pgroup.
comWeb:http://www.
pgroup.
comiiiContentsPrefacexiiiAudienceDescriptionxiiiCompatibilityandConformancetoStandardsxivOrganizationxvHardwareandSoftwareConstraintsxviConventionsxviRelatedPublicationsxvii1LanguageOverview1ElementsofaFortranProgramUnit1Statements1FreeandFixedSource2StatementOrdering2TheFortranCharacterSet3FreeFormFormatting5FixedFormatting6ColumnFormatting6FixedFormatLabelField6FixedFormatContinuationField7FixedFormatStatementField7FixedFormatDebugStatements7TabFormatting7FixedInputFileFormat–Summary8IncludingFortranSourceFiles8TheComponentsofFortranStatements9SymbolicNames9Expressions10ExpressionPrecedenceRules10ArithmeticExpressions12RelationalExpressions14LogicalExpressions14CharacterExpressions15CharacterConcatenation15SymbolicNameScope16AssignmentStatements16ArithmeticAssignment17ivLogicalAssignmentStatement17CharacterAssignment18ListingControls19OpenMPDirectives19HPFDirectives202FortranDataTypes21IntrinsicDataTypes21KindParameter21NumberofBytesSpecification22Constants25IntegerConstants25Binary,OctalandHexadecimalConstants26RealConstants26DoublePrecisionConstants27ComplexConstants28DoubleComplexConstants28LogicalConstants28CharacterConstants29PARAMETERConstants30DerivedTypes30Arrays30AnArrayDeclarationElement31DeferredShapeArrays32Subscripts32CharacterSubstring32FortranPointersandTargets33FortranBinary,OctalandHexadecimalConstants33OctalandHexadecimalConstants-AlternateForm34HollerithConstants35Structures36Records37UNIONandMAPDeclarations38DataInitialization40PointerVariables41Restrictions423FortranStatements43OriginofStatement43Statements44v4FortranArrays139ArrayTypes139ExplicitShapeArrays140AssumedShapeArrays140DeferredShapeArrays140AssumedSizeArrays140ArraySpecification141ExplicitShapeArrays141AssumedShapeArrays141DeferredShapeArrays141AssumedSizeArrays142ArraySubscriptsandAccess142ArraySectionsandSubscriptTriplets142ArraySectionsandVectorSubscripts143ArrayConstructors144CMFortranExtensions144TheARRAYAttribute144ArrayConstructorsExtensions1445InputandOutputFormatting145FileAccessMethods145StandardPreconnectedUnits146OpeningandClosingFiles146DirectAccessFiles147ClosingaFile147DataTransferStatements149UnformattedDataTransfer150FormattedDataTransfer150ImpliedDOListInputOutputList151FormatSpecifications151AFormatControl–CharacterData153BFormatControl–BinaryData154DFormatControl–RealDoublePrecisionDatawithExponent154EFormatControl–RealSinglePrecisionDatawithExponent155ENFormatControl155ESFormatControl155FFormatControl-RealSinglePrecisionData156GFormatControl156IFormatControl–IntegerData156viLFormatControl–LogicalData157QuoteFormatControl157BNFormatControl–BlankControl158HFormatControl–HollerithControl158OFormatControlOctalValues158PFormatSpecifier–ScaleControl159QFormatControl-Quantity159SFormatControl–SignControl159T,TLandXFormatControls–SpacesandTabControls160ZFormatControlHexadecimalValues161SlashFormatControl/–EndofRecord161The:FormatSpecifier–FormatTermination162$FormatControl162VariableFormatExpressions,162Non-advancingInputandOutput162List-directedformatting163List-directedinput163List-directedoutput165CommasinExternalField167NamelistGroups167NamelistInput167NamelistOutput1686FortranIntrinsics171FORTRAN77andFortran90/95IntrinsicsbyCategory171FORTRAN77andFortran90/95IntrinsicsDescriptions201SupportedHPFIntrinsics258CMFortranIntrinsics26173FFunctionsandVAXSubroutines2653FRoutines265VAXSystemSubroutines290Built-InFunctions291VAX/VMSSystemSubroutines2918OpenMPDirectivesforFortran295ParallelizationDirectives295PARALLEL.
.
.
ENDPARALLEL296CRITICAL.
.
.
ENDCRITICAL300MASTER.
.
.
ENDMASTER301viiSINGLE.
.
.
ENDSINGLE302DO.
.
.
ENDDO302BARRIER305DOACROSS305PARALLELDO306SECTIONS.
.
.
ENDSECTIONS307PARALLELSECTIONS308ORDERED309ATOMIC309FLUSH310THREADPRIVATE310Run-timeLibraryRoutines310EnvironmentVariables3139HPFDirectives315AddingHPFDirectivestoPrograms315HPFDirectiveSummary316AppendixA.
HPF_LOCAL327viiiixTablesTable1-1:FortranCharacters.
4Table1-2:CLanguageCharacterEscapeSequences.
5Table1-3:FixedFormatRecordPositionsandFields6Table1-4:FortranOperatorPrecedence11Table1-5:ArithmeticOperators13Table1-6:ArithmeticOperatorPrecedence13Table2-1:FortranIntrinsicDataTypes22Table2-2:DataTypesKindParameters22Table2-3:DataTypeExtensions.
23Table2-4:DataTypeRanks24Table2-5:ExampleofRealConstants27Table2-6:DoublePrecisionConstants.
28Table3-1:OPTIONSStatement.
109Table5-1:OPENSpecifiers148Table5-2:FormatCharacterControlsforaPrinter153Table5-3:ListDirectedInputValues164Table5-4:DefaultListDirectedOutputFormatting166Table6-1:NumericFunctions172Table6-2:MathematicalFunctions179Table6-3:RealManipulationFunctions182Table6-4:BitManipulationFunctions182Table6-5:Fortran90/95BitManipulationSubroutine186Table6-6:ElementalCharacterandLogicalFunctions187Table6-7:Fortran90/95Vector/MatrixFunctions189Table6-8:Fortran90/95ArrayReductionFunctions189Table6-9:Fortran90/95StringConstructionFunctions193Table6-10:Fortran90/95ArrayConstruction/ManipulationFunctions193Table6-11:Fortran90/95GeneralInquiryFunctions197Table6-12:Fortran90/95NumericInquiryFunctions.
197Table6-13:Fortran90/95ArrayInquiryFunctions199Table6-14:Fortran90/95StringInquiryFunction.
199Table6-15:Fortran90/95Subroutines199Table6-16:Fortran90/95TransferFunction201Table6-17:MiscellaneousFunctions201Table6-18:HPFIntrinsicsandLibraryProcedures.
259Table8-1:InitializationofREDUCTIONVariables299xTable9-1:HPFDirectiveSummary316TableA-1:HPF_LOCAL_LIBRARYProcedures.
328xiFiguresFigure1-1:OrderofStatements.
3xiiAudienceDescriptionxiiiPrefaceThishelpcollectiondescribesThePortlandGroup'simplementationoftheFORTRAN77,Fortran90/95languages.
Collectively,ThePortlandGroupcompilersthatimplementtheselanguagesarereferredtoasthePGIFortrancompilers.
ThishelpcollectionispartofasetofotherdocumentsdescribingtheFortranlanguageandthecompilationtoolsavailablefromThePortlandGroup.
ThishelpcollectionpresentstheFortranlanguagestatements,intrinsics,andextensiondirectives.
ThePortlandGroup'sFortrancompilationsystemincludesacompilationdriver,multipleFortrancompilers,associatedruntimesupportandmathematicallibraries,andassociatedsoftwaredevelopmenttoolsfordebuggingandprofilingtheperformanceofFortranprograms.
Dependingonthetargetsystem,ThePortlandGroup'sFortransoftwaredevelopmenttoolsmayalsoincludeanassembleroralinker.
Youcanusethesetoolstocreate,debug,optimizeandprofileyourFortranprograms.
"RelatedPublications"listsothermanualsinthePGIdocumentationset.
ThismanualdescribesThePortlandGroup'simplementationoftheFORTRAN77,Fortran90/95andHighPerformanceFortran(HPF)languages.
Collectively,ThePortlandGroupcompilersthatimplementtheselanguagesarereferredtoasthePGIFortrancompilers.
ThismanualispartofasetofotherdocumentsdescribingtheFortranlanguageandthecompilationtoolsavailablefromThePortlandGroup.
ThismanualpresentstheFortranlanguagestatements,intrinsics,andextensiondirectives.
ThePortlandGroup'sFortrancompilationsystemincludesacompilationdriver,multipleFortrancompilers,associatedruntimesupportandmathematicallibraries,andassociatedsoftwaredevelopmenttoolsfordebuggingandprofilingtheperformanceofFortranprograms.
Dependingonthetargetsystem,ThePortlandGroup'sFortransoftwaredevelopmenttoolsmayalsoincludeanassembleroralinker.
Youcanusethesetoolstocreate,debug,optimizeandprofileyourFortranprograms.
"RelatedPublications"listsothermanualsinthePGIdocumentationset.
AudienceDescriptionThishelpcollectionmanualisintendedforpeoplewhoareportingorwritingFortranprogramsusingthePGIFortrancompilers.
TouseFortranyoushouldbeawareoftheroleofFortranandofsource-levelprogramsinthesoftwaredevelopmentprocessandyoushouldhavesomeknowledgeofaparticularsystemorworkstationcluster.
TousethePGIFortrancompilers,youneedtobefamiliarwiththeFortranlanguage,eitherFORTRAN77,orFortran90/95orHPF,andthebasiccommandsavailableonyourhostsystem.
xivCompatibilityandConformancetoStandardsThePGIFortrancompilers,PGF77,orPGF95,runonavarietyof32-bitand64-bitx86processor-basedhostsystems.
ThePGF77compileracceptsanenhancedversionofFORTRAN77thatconformstotheANSIstandardforFORTRAN77andincludesvariousextensionsfromVAX/VMSFortran,IBM/VSFortran,andMIL-STD-1753.
ThePGF95compileracceptsasimilarlyenhancedversionoftheANSIstandardforFortran90/95.
ThePGIFortrancompilers,PGF77,PGF95andPGHPF,runonavarietyof32-bitand64-bitx86processor-basedhostsystems.
ThePGF77compileracceptsanenhancedversionofFORTRAN77thatconformstotheANSIstandardforFORTRAN77andincludesvariousextensionsfromVAX/VMSFortran,IBM/VSFortran,andMIL-STD-1753.
ThePGF95compileracceptsasimilarlyenhancedversionoftheANSIstandardforFortran90/95.
ThePGHPFcompileracceptstheHPFlanguageandislargely,thoughnotstrictly,asupersetofFortran90/95.
ThePGHPFcompilerconformstotheHighPerformanceFortranLanguageSpecificationVersion1.
1,publishedbytheCenterforResearchonParallelComputation,atRiceUniversity(withafewlimitationsandmodifications,consultthePGHPFReleaseNotesfordetails).
ForfurtherinformationontheFortranlanguage,youcanalsorefertothefollowing:AmericanNationalStandardProgrammingLanguageFORTRAN,ANSIX3.
-1978(1978).
ISO/IEC1539:1991,Informationtechnology–ProgrammingLanguages–Fortran,Geneva,1991(Fortran90).
ISO/IEC1539:1997,Informationtechnology–ProgrammingLanguages–Fortran,Geneva,1997(Fortran95).
Fortran95HandbookCompleteISO/ANSIReference,Adamsetal,TheMITPress,Cambridge,Mass,1997.
HighPerformanceFortranLanguageSpecification,Revision1.
0,RiceUniversity,Houston,Texas(1993),http://www.
crpc.
rice.
edu/HPFF.
HighPerformanceFortranLanguageSpecification,Revision2.
0,RiceUniversity,Houston,Texas(1997),http://www.
crpc.
rice.
edu/HPFF.
OpenMPFortranApplicationProgramInterface,Version1.
1,November1999,http://www.
openmp.
org.
ProgramminginVAXFortran,Version4.
0,DigitalEquipmentCorporation(September,1984).
OrganizationxvIBMVSFortran,IBMCorporation,Rev.
GC26-4119.
MilitaryStandard,Fortran,DODSupplementtoAmericanNationalStandardProgrammingLanguageFortran,ANSIx.
3-1978,MIL-STD-1753(November9,1978).
OrganizationThismanualisdividedintothefollowingchaptersandappendices:Chapter1,"LanguageOverview",providesanintroductiontotheFortranlanguage.
Chapter2,"FortranDataTypes",describesthedatatypessupportedbyPGIFortrancompilersandprovidesexamplesusingvariousdatatypes.
Memoryallocationandalignmentissuesarealsodiscussed.
Chapter3,"FortranStatements",describeseachFortranandHPFstatementthatthePGIFortrancompilersaccept.
ManyHPFstatementsareintheformofcompilerdirectiveswhichcanbeignoredbynon-HPFcompilers.
Chapter4,"FortranArrays",describesspecialcharacteristicsofarraysinFortran90/95.
Chapter5,"InputandOutputFormatting",describestheinput,output,andformatstatementsthatallowprogramstotransferdatatoorfromfiles.
Chapter6,"FortranIntrinsics",liststheFortranintrinsicsandsubroutinessupportedbythePGIFortrancomilers.
Chapter7,"3FFunctionsandVAXSubroutines",describesthefunctionsandsubroutinesintheFortranrun-timelibraryanddiscussestheVAX/VMSsystemsubroutinesandthebuilt-infunctionssupportedbythePGIFortrancompilers.
Chapter8,"OpenMPDirectivesforFortran",liststhelanguageextensionsthatthePGIFortrancompilerssupport.
Chapter9,"HPFDirectives",describestheHPFdirectiveswhichsupportdatadistributionandalignment,andinfluencedataparallelismbyprovidingadditionalinformationtothePGHPFcompiler.
AppendixA.
,"HPF_LOCAL",liststheHPF_LOCAL_LIBRARYproceduressupportedbythePGHPFcompiler.
xviHardwareandSoftwareConstraintsThePGIcompilersoperateonavarietyofhostsystemsandproduceobjectcodeforavarietyoftargetsystems.
Detailsconcerningenvironment-specificvaluesanddefaultsandhost-specificfeaturesorlimitationsarepresentedinthePGIUser'sGuide,themanpagesforeachcompilerinagiveninstallation,andinthereleasenotesandinstallationinstructionsincludedwithallPGIcompilersandtoolssoftwareproducts.
ConventionsThisPGIFortranReferencemanualusesthefollowingconventions:italicisusedforcommands,filenames,directories,arguments,optionsandforemphasis.
ConstantWidthisusedinexamplesandforlanguagestatementsinthetext.
[item]squarebracketsindicateoptionalitems.
Inthiscaseitem1isoptional.
{item2|item3}bracesindicatethataselectionisrequired.
Inthiscase,youmustselecteitheritem2oritem3.
filename.
.
.
ellipsisindicatearepetition.
Zeroormoreoftheprecedingitemmayoccur.
Inthisexample,multiplefilenamesareallowed.
FORTRANFortranlanguagestatementsareshownusingupper-casecharactersandareducedpointsize.
non-printingcharacters,suchasTAB,areshownenclosedingreaterthanandlessthancharactersandareducedpointsize.
§thissymbolindicatesanareainthetextthatdescribesaFortran90/95Languageenhancement.
EnhancementsarefeaturesthatarenotdescribedintheANSIFortran90/95standards.
@ThissymbolindicatesanareainthetextthatdescribesaFORTRAN77enhancement.
EnhancementsmaybeVAX/VMSFortranenhancements,IBM/VMenhancements,ormilitarystandardMIL-STD-1753enhancements.
RelatedPublicationsxviiRelatedPublicationsThefollowingdocumentscontainadditionalinformationrelatedtoHPFandothercompilersandtoolsavailablefromThePortlandGroup,Inc.
ThePGIUser'sGuidedescribesthegeneralfeaturesandusageguidelinesforallPGIcompilers,anddescribesindetailvariousavailablecompileroptionsinauser'sguideformat.
ThePGHPFUser'sGuidedescribesthePGHPFcompileranddescribessomedetailsconcerningthePGIimplementationofHPFinauser'sguideformat.
Fortran95Handbook,fromMcGraw-Hill,describestheFortran95languageandthestatements,datatypes,input/outputformatspecifiers,andadditionalreferencematerialthatdefinesANSI/ISOFortran95.
SystemVApplicationBinaryInterfaceProcessorSupplementbyAT&TUNIXSystemLaboratories,Inc,(availablefromPrenticeHall,Inc.
)TheHighPerformanceFortranHandbook,fromMITPress,describestheHPFlanguageindetail.
HighPerformanceFortranLanguageSpecification,RiceUniversity,HoustonTexas(1993),isthespecificationfortheHPFlanguageandisavailableonlineathttp://www.
crpc.
rice.
edu/HPFF.
AmericanNationalStandardProgrammingLanguageFortran,ANSIx.
3-1978(1978).
ProgramminginVAXFORTRAN,Version4.
0,DigitalEquipmentCorporation(September,1984).
IBMVSFORTRAN,IBMCorporation,Rev.
GC26-4119.
MilitaryStandard,FORTRAN,DODSupplementtoAmericanNationalStandardProgrammingLanguageFORTRAN,ANSIX3.
-1978,MIL-STD-1753(November9,1978).
xviiiElementsofaFortranProgramUnit11LanguageOverviewThischapterdescribesthebasicelementsoftheFortranlanguage,theformatofFortranstatements,andthetypesofexpressionsandassignmentsacceptedbythePGIFortrancompilers.
ThePGF77compileracceptsasinputFORTRAN77andproducesasoutputassemblylanguagecode,binaryobjectcodeorbinaryexecutablesinconjunctionwiththeassembler,linkerandlibrariesonthetargetsystem.
TheinputlanguagemustbeextendedFORTRAN77asspecifiedinthisreferencemanual.
ThePGF95compilerfunctionssimilarlyforFortran90/95.
ThePGF95andPGHPFcompilersfunctionsimilarlyforFortran90/95andHPFrespectively.
ThischapterisnotanintroductiontotheoverallcapabilitiesofFortran.
Rather,itisanoverviewofthesyntaxrequirementsofprogramsusedwiththePGIFortrancompilers.
TheFortran95HandbookprovidesdetailsonthecapabilitiesofFortran90/95language.
TheFortran95HandbookandTheHighPerformanceFortranHandbookprovidedetailsonthecapabilitiesofFortran90/95andHPFlanguages.
ElementsofaFortranProgramUnitAFortranprogramiscomposedofSUBROUTINE,FUNCTION,MODULE,BLOCKDATA,orPROGRAMprogramunits.
Fortransourcecodeconsistsofasequenceofprogramunitswhicharetobecompiled.
Everyprogramunitconsistsofstatementsandoptionallycommentsbeginningwithaprogramunitstatement,eitheraSUBROUTINE,FUNCTION,orPROGRAMstatement,andfinishingwithanENDstatement(BLOCKDATAandMODULEprogramunitsarealsoallowed).
Intheabsenceofoneofthesestatements,thePGIFortrancompilersinsertaPROGRAMstatement.
StatementsStatementsareeitherexecutablestatementsornonexecutablespecificationstatements.
Eachstatementconsistsofasinglelineorsourcerecord,possiblyfollowedbyoneormorecontinuationlines.
Multiplestatementsmayappearonasinglelineiftheyareseparatedbyasemicolon(;).
Commentsmayappearonanylinefollowingacommentcharacter(!
).
LanguageOverview2FreeandFixedSourceFortranpermitstwotypesofsourceformatting,fixedsourceformandfreesourceform.
FixedsourceformusesthetraditionalFortranapproachwherespecificcolumnpositionsarereservedforlabels,continuationcharacters,andstatementsandblankcharactersareignored.
ThePGF77compilersupportsonlyfixedsourceform.
ThePGF77compileralsosupportsalessrestrictivevarietyoffixedsourceformcalledtabsourceform.
FreesourceformintroducedwithFortran90placesfewrestrictionsonsourceformatting;thecontextofanelement,aswellasthepositionofblanks,ortabs,separatelogicaltokens.
Usingthecompileroption–MfreeformyoucanselectfreesourceformasanoptiontoPGF95orPGHPF.
StatementOrderingFortranstatementsandconstructsmustconformtoorderingrequirementsimposedbythelanguagedefinition.
Thefigure"OrderofStatements"illustratestheserequirements.
Verticallinesseparatestatementsandconstructsthatcanbeinterspersed.
Horizontallinesseparatestatementsthatmustnotbeinterspersed.
TheserulesarelessstrictthanthoseintheANSIstandard.
Thedifferencesareasfollows:DATAstatementscanbefreelyinterspersedwithPARAMETERstatementsandotherspecificationstatements.
NAMELISTstatementsaresupportedandhavethesameorderrequirementsasFORMATandENTRYstatements.
TheIMPLICITNONEstatementcanprecedeotherIMPLICITstatements.
TheFortranCharacterSet3Figure1-1:OrderofStatementsTheFortranCharacterSetTable1-1,"FortranCharacters",showsthesetofFortrancharacters.
CharactervariablesandconstantscanuseanyASCIIcharacter.
Thevalueofthecommand-lineoption–Mupcasedeterminesifthecompilerdistinguishesbetweencase(upperandlower)inidentifiers.
Bydefault,withoutthe–Mupcaseoptionselected,thecompilerdoesnotdistinguishbetweenupperandlowercasecharactersinidentifiersENDStatementCommentsandINCLUDEStatementsOPTIONSStatementPROGRAM,FUNCTION,SUBROUTINE,orBLOCKDATAStatementsStatementFunctionDefinitionOtherSpecificationNAMELIST,FORMAT,AndENTRYStatementsUSEStatementsIMPLICITNONEStatementIMPLICITStatementsPARAMETEREXECUTABLEStatementsDATAStatementsCONTAINSStatementInternalSubprogramsorModuleLanguageOverview4(upperandlowercasearealwayssignificantincharacterconstants).
Table1-1:FortranCharactersTable1-2,"CLanguageCharacterEscapeSequences",showsClanguagecharacterescapesequencesthatthePGIFortrancompilersrecognizeincharacterstringconstants.
Thesevaluesdependonthecommand-lineoption–Mbackslash.
CharacterDescriptionCharacterDescription,CommaA-Z,a-zAlphabetic:ColonSpacecharacter;Semicolon=Equals_Underscorecharacter+PlusGreaterthan*AsteriskQuestionmark/Slash%Percent(Leftparenthesis"Quotationmark)Rightparenthesis$Currencysymbol[Leftbracket.
Decimalpoint]Rightbracket!
ExclamationmarkCarriagereturn0-9NumericTabulationcharac-terFreeFormFormatting5Table1-2:CLanguageCharacterEscapeSequencesFreeFormFormattingUsingfreeformformatting,columnsarenotsignificantfortheelementsofaFortranline,andablankorseriesofblanksortabsandthecontextofatokenspecifythetokentype.
132charactersarevalidperline,andthecompileroption–Mextenddoesnotapply.
Commentsareindicatedbyablankline,orbyfollowingaFortranlinewiththe!
character.
Allcharactersafterthe!
arestrippedoutoftheFortrantext.
CharacterDescription\vverticaltab\aalert(bell)\nnewline\ttab\bbackspace\fformfeed\rcarriagereturn\0null\'apostrophe(doesnotterminateastring)\"doublequotes(doesnotterminateastring)\\\\xx,wherexisanyothercharacter\dddcharacterwiththegivenoctalrepresenta-tion.
LanguageOverview6Usingfreeformformatting,the&characterattheendofalinemeansthefollowinglinerepresentsacontinuationline.
Ifacontinuationlinestartswiththe&character,thenthecharactersfollowingthe&arethestartofthecontinuationline.
Withoutaleading&atthestartofthecontinuationline,allcharactersonthelinearepartofthecontinuationline,includinganyinitialblanksortabs.
AsingleFortranlinemaycontainmultiplestatements.
The;(semicolon)separatesmultiplestatementsonasingleline.
Freeformatlabelsarevalidatthestartofaline,aslongasthelabelisseparatedfromtheremainingstatementsonthelinebyatleastoneblankora.
Labelsconsistofanumericfielddrawnfromdigits0to9.
Thelabelcannotbemorethan5characters.
FixedFormattingThissectiondescribesthetwotypesoffixedformattingthatPGIFortrancompilerssupport,columnformattingandtabformatting.
ColumnFormattingUsingcolumnformattingaFortranrecordconsistsofasequenceofupto73ASCIIcharacters,thelastbeing.
Thereisafixedlayoutasshowninthetablebelow.
Table1-3:FixedFormatRecordPositionsandFieldsCharactersbeyondposition72onalineareignoredunlessthe–Mextendoptionisspecified.
Inaddition,anycharactersfollowinga!
characterarecommentsandaredisregardedduringcompilation.
FixedFormatLabelFieldThelabelfieldholdsuptofivecharacters.
ThecharactersCor*inthefirstcharacterpositionofalabelfieldindicateacommentline.
PositionField1-5Labelfield6Continuationfield7-72StatementfieldFixedFormatting7InadditiontothecharactersCor*,eitherofthecharactersDor!
inthefirstpositionofalabelfieldalsoindicateacommentline.
Whenanumericfielddrawnfromdigits0to9isplacedinthelabelfield,thefieldisalabel.
Alinewithnolabel,andwithfivespacecharactersorainthelabelfield,isanunlabeledstatement.
Eachlabelmustbeuniqueinitsprogramunit.
Continuationlinesmustnotbelabeled.
Labelscanonlybejumpedtowhentheyareonexecutablestatements.
FixedFormatContinuationFieldThesixthcharacterposition,orthepositionafterthetab,isthecontinuationfield.
Thisfieldisignoredincommentlines.
Itisinvalidifthelabelfieldisnotfivespaces.
Avalueof0,orindicatesthefirstlineofastatement.
Anyothervalueindicatesasubsequent,continuationlinetotheprecedingstatement.
FixedFormatStatementFieldThestatementfieldconsistsofvalididentifiersandsymbols,possiblyseparatedbyorandterminatedby.
Withinthestatementfieldtabsandspacesareignoredasarecomments,charactersfollowinga!
,oranycharactersfoundbeyondthe72ndcharacter(unlesstheoption–Mextendisenabled).
FixedFormatDebugStatementsTheletterDincolumn1usingfixedformattingdesignatesthestatementonthespecifiedlineisadebuggingstatement.
Thecompilerwilltreatthedebuggingstatementasacomment,thatisignoringit,unlessthecommandlineoption–Mdlinesissetduringcompilation.
Inthatcase,thecompileractsasifthelinestartingwithDwereaFortranstatementandcompilesthelineaccordingtothestandardrules.
TabFormattingThePGIFortrancompilerssupportanalternateformoffixedsourcefromcalledtabsourceform.
Atabformattedsourcefileismadeupofalabelfield,anoptionalcontinuationindicatorandastatementfield.
Thelabelfieldisterminatedbyatabcharacter.
Thelabelcannotbemorethan5characters.
Acontinuationlineisindicatedbyatabcharacterfollowedimmediatelybyadigit.
Thestatementfieldstartsafteracontinuationindicator,whenoneispresent.
The73rdandsubsequentcharactersareignored.
LanguageOverview8FixedInputFileFormat–SummaryTab-Formatlinesaresupported.
Atabincolumns1-6endsthestatementlabelfieldandbeginsanoptionalcontinuationindicatorfield.
Ifanon-zerodigitfollowsthetabcharacter,thecontinuationfieldexistsandindicatesacontinuationfield.
Ifanythingotherthananon-zerodigitfollowsthetabcharacter,thestatementbodybeginswiththatcharacterandextendstotheendofthesourcestatement.
NotethatthisdoesnotoverrideFortran'sfreesourceformhandlingsincenovalidFortranstatementcanbeginwithanon-zerodigit.
ThetabcharacterisignoredifitoccursinalineexceptinHollerithorcharacterconstants.
Inputlinesmaybeofvaryinglengths.
Iftherearefewerthan72characters,thelineispaddedwithblanks;charactersafterthe72ndareignoredunlessthe–Mextendoptionisusedonthecommandline.
Ifthe–Mextendoptionisusedonthecommandlinethentheinputlinecanextendto132characters.
Thelineispaddedwithblanksifitisfewerthan132characters;charactersafterthe132ndareignored.
Notethatuseofthisoptionextendsthestatementfieldtoposition132.
Blanklinesareallowedattheendofaprogramunit.
Thenumberofcontinuationlinesallowedisextendedto1000lines.
IncludingFortranSourceFilesThesequenceofconsecutivecompilationofsourcestatementsmaybeinterruptedsothatanextrasourcefilecanbeincluded.
ThisiscarriedoutusingtheINCLUDEstatementwhichtakestheform:INCLUDE"filename"wherefilenameisthenameofthefiletobeincluded.
Pairsofeithersingleordoublequotesareacceptableenclosingfilename.
TheINCLUDEfileiscompiledtoreplacetheINCLUDEstatement,andoncompletionofthatsourcethefileisclosedandcompilationcontinueswiththestatementfollowingtheINCLUDE.
INCLUDEfilesareespeciallyrecommendedwhenthesameCOMMONblocksandthesameCOMMONblockdatamappingsareusedinseveralprogramunits.
ForexamplethefollowingstatementincludesthefileMYFILE.
DEF.
INCLUDE"MYFILE.
DEF"TheComponentsofFortranStatements9Recursiveincludesarenotallowed.
Thatis,ifafileincludesafile,thatfilemaynotalsoincludethesamefile.
Nestedincludesareallowed,uptoaPGIFortrandefinedlimitof20.
TheComponentsofFortranStatementsFortranprogramunitsaremadeupofstatementswhichconsistofexpressionsandelements.
Anexpressioncanbebrokendowntosimplerexpressionsandeventuallytoitselementscombinedwithoperators.
Hencethebasicbuildingblockofastatementisanelement.
Anelementtakesoneofthefollowingforms:Aconstantrepresentsafixedvalue.
Avariablerepresentsavaluewhichmaychangeduringprogramexecution.
Anarrayisagroupofvaluesthatcanbereferredtoasawhole,asasection,orseparately.
Theseparatevaluesareknownastheelementsofthearray.
Thearrayhasasymbolicname.
Afunctionreferenceorsubroutinereferenceisthenameofafunctionorsubroutinefollowedbyanargumentlist.
Thereferencecausesthecodespecifiedatfunction/subroutinedefinitiontobeexecutedandifafunction,theresultissubstitutedforthefunctionreference.
SymbolicNamesSymbolicnamesidentifydifferententitiesinFortransourcecode.
Asymbolicnameisastringoflettersanddigits,whichmuststartwithaletterandbeterminatedbyacharacternotinthesymbolicnamesset(forexampleaoracharacter).
Underscore(_)charactersmayappearwithinsymbolicnames.
Onlythefirstthirty-onecharactersidentifythesymbolicname.
Belowareseveralexamplesofsymbolicnames:NUMCRA9numericabcdefghijklmnopqrstuvwxyzThelastexampleisidentifiedbyitsfirst31charactersandisequivalentto:numericabcdefghijklmnopqrstuvwxThefollowingexamplesareinvalidsymbolicnames.
8QLanguageOverview10Thisisinvalidbecauseitbeginswithanumber.
FIVE.
4Thisisinvalidbecauseitcontainsaperiodwhichisaninvalidcharacterforasymbolicname.
ExpressionsEachdataitem,suchasavariableoraconstant,representsaparticularvalueatanypointduringprogramexecution.
Theseelementsmaybecombinedtogethertoformexpressions,usingbinaryorunaryoperators,sothattheexpressionitselfyieldsavalue.
AFortranexpressionmaybeanyofthefollowing:AscalarexpressionAnarrayexpressionAconstantexpressionAspecificationexpressionAninitializationexpressionMixedarrayandscalarexpressionsExpressionPrecedenceRulesArithmetic,relationalandlogicalexpressionsmaybeidentifiedtothecompilerbytheuseofparentheses,asdescribedin"ArithmeticExpressions"onpage12.
Whennoguidanceisgiventothecompileritwillimposeasetofprecedencerulestoidentifyeachexpressionuniquely.
Table1-4,"FortranOperatorPrecedence",showstheoperatorprecedencerulesforexpressions.
Expressions11Table1-4:FortranOperatorPrecedenceAnexpressionisformedas:exprbinary-operatorexprorunary-operatorexprwhereanexprisformedasOperatorEvaluatedUnarydefinedHighest**N/A*or/N/AUnary+or-N/ABinary+or–N/ARelationaloperators:GT.
,.
GE.
,.
LE.
N/ARelationaloperators==,/=Sameprece-denceRelationaloperatorsSameprece-denceRelationaloperators.
EQ.
,.
NE.
,.
LT.
Sameprece-dence.
NOT.
N/A.
AND.
N/A.
OR.
N/A.
NEQV.
and.
EQV.
N/ABinarydefinedLowestLanguageOverview12expressionorelementForexample,A+B-C+DThesearesimpleexpressionswhosecomponentsareelements.
Expressionsfallintooneoffourclasses:arithmetic,relational,logicalorcharacter.
Operatorsofequalrankareevaluatedlefttoright.
Thus:A*B+B**C.
EQ.
X+Y/Z.
AND.
.
NOT.
K-3.
0.
GT.
Tisequivalentto:((((A*B)+(B**C)).
EQ.
(X+(Y/Z))).
AND.
(.
NOT.
((K-3.
0).
GT.
T)))ArithmeticExpressionsArithmeticexpressionsareformedfromarithmeticelementsandarithmeticoperators.
Anarithmeticelementmaybe:anarithmeticexpressionavariableaconstantanarrayelementafunctionreferenceafieldofastructureThearithmeticoperatorsspecifyacomputationtobeperformedontheelements.
Theresultisanumericresult.
Table1-5,"ArithmeticOperators",showsthearithmeticoperators.
Notethatavalueshouldbeassociatedwithavariableorarrayelementbeforeitisusedinanexpression.
Arithmeticexpressionsareevaluatedinanorderdeterminedbyaprecedenceassociatedwitheachoperator.
TheprecedenceofeacharithmeticoperatorisshowninTable1-5,"ArithmeticOperators".
Expressions13Thisfollowingexampleisresolvedintothearithmeticexpressions(A)+(B*C)ratherthan(A+B)*(C).
A+B*CNormalrankedprecedencemaybeovercomeusingparentheseswhichforcetheitem(s)enclosedtobeevaluatedfirst.
(A+B)*CThecompilerresolvesthisintotheexpressions(A+B)*(C).
Table1-5:ArithmeticOperatorsTable1-6:ArithmeticOperatorPrecedenceThetypeofanarithmeticexpressionis:INTEGERifitcontainsonlyintegerelements.
REALifitcontainsonlyrealandintegerelements.
OperatorFunction**Exponentiation*Multiplication/Division+Additionorunaryplus-SubtractionorunaryminusOperatorPrecedence**First*and/Second+and-ThirdLanguageOverview14DOUBLEPRECISIONifitcontainsonlydoubleprecision,realandintegerelements.
COMPLEXifanyelementiscomplex.
Anyelementwhichneedsconversiontocomplexwillbeconvertedbytakingtherealpartfromtheoriginalvalueandsettingtheimaginaryparttozero.
DOUBLECOMPLEXifanyelementisdoublecomplex.
RelationalExpressionsArelationalexpressioniscomposedoftwoarithmeticexpressionsseparatedbyarelationaloperator.
Thevalueoftheexpressionistrueorfalse(.
TRUE.
or.
FALSE.
)dependingonthevalueoftheexpressionsandthenatureoftheoperator.
Thetablebelowshowstherelationaloperators.
Inrelationalexpressionsthearithmeticelementsareevaluatedtoobtaintheirvalues.
Therelationshipisthenevaluatedtoobtainthetrueorfalseresult.
Thustherelationalexpression:TIME+MEAN.
LT.
LASTmeansifthesumofTIMEandMEANislessthanthevalueofLAST,thentheresultistrue,otherwiseitisfalse.
LogicalExpressionsAlogicalexpressioniscomposedoftworelationalorlogicalexpressionsseparatedbyalogicaloperator.
Eachlogicalexpressionyieldsthevaluetrueorfalse(.
TRUE.
or.
FALSE.
)Thefollowingtableshowsthelogicaloperators.
OperatorRelationship.
LT.
Lessthan.
LE.
Lessthanorequalto.
EQ.
Equalto.
NE.
Notequalto.
GT.
Greaterthan.
GE.
GreaterthanorequaltoExpressions15Inthefollowingexample,TESTwillbe.
TRUE.
ifAisgreaterthanBorIisnotequaltoJ+17.
TEST=A.
GT.
B.
OR.
I.
NE.
J+17CharacterExpressionsAnexpressionoftypeCHARACTERcanconsistofoneormoreprintablecharacters.
Itslengthisthenumberofcharactersinthestring.
Eachcharacterisnumberedconsecutivelyfromlefttorightbeginningwith1.
Forexample:'ab_&''A@HJi2''var[1,12]'CharacterConcatenationAcharacterexpressioncanbeformedbyconcatenatingtwo(ormore)validcharacterexpressionsusingtheconcatenationoperator//.
Thefollowingtableshowsseveralexamplesofconcatenation.
OperatorRelationship.
AND.
Trueifbothexpressionsaretrue.
.
OR.
Trueifeitherexpressionorbothistrue.
.
NOT.
Thisisaunaryoperator;itistrueiftheexpressionisfalse,otherwiseitisfalse.
.
NEQV.
Falseifbothexpressionshavethesamelogicalvalue.
XOR.
Sameas.
NEQV.
.
EQV.
TrueifbothexpressionshavethesamelogicalvalueExpressionValue'ABC'//'YZ'"ABCYZ"LanguageOverview16SymbolicNameScopeFortran90/95scopingisexpandedfromthetraditionalFORTRAN77capabilitieswhichprovideascopingmechanismusingsubroutines,mainprograms,andCOMMONs.
Fortran90/95addstheMODULEstatement.
ModulesprovideanexpandedalternativetotheuseofbothCOMMONsandINCLUDEstatements.
Modulesallowdataandfunctionstobepackagedanddefinedasaunit,incorporatingdatahidingandusingascopethatisdeterminedwiththeUSEstatement.
Fortran90/95andHPFscopingisexpandedfromthetraditionalFORTRAN77capabilitieswhichprovideascopingmechanismusingsubroutines,mainprograms,andCOMMONs.
Fortran90/95andHPFaddtheMODULEstatement.
ModulesprovideanexpandedalternativetotheuseofbothCOMMONsandINCLUDEstatements.
Modulesallowdataandfunctionstobepackagedanddefinedasaunit,incorporatingdatahidingandusingascopethatisdeterminedwiththeUSEstatement.
NamesofCOMMONblocks,SUBROUTINEsandFUNCTIONsareglobaltothosemodulesthatreferencethem.
Theymustrefertouniqueobjects,notonlyduringcompilation,butalsointhelinkstage.
Thescopeofnamesotherthantheseislocaltothemoduleinwhichtheyoccur,andanyreferencetothenameinadifferentmodulewillimplyanewlocaldeclaration.
Thisincludesthearithmeticfunctionstatement.
AssignmentStatementsAFortranassignmentstatementcanbeanyofthefollowing:AnintrinsicassignmentstatementAstatementlabelassignmentAnarrayassignmentAmaskedarrayassignment'JOHN'//'SMITH'"JOHNSMITH"'J'//'JAMES'//'JOY'"JJAMESJOY"ExpressionValueAssignmentStatements17ApointerassignmentAdefinedassignmentArithmeticAssignmentThearithmeticassignmentstatementhasthefollowingform:object=arithmetic-expressionwhereobjectisoneofthefollowing:VariableFunctionname(withinafunctionbody)SubroutineargumentArrayelementFieldofastructureThetypeofobjectdeterminesthetypeoftheassignment(INTEGER,REAL,DOUBLEPRECISIONorCOMPLEX)andthearithmetic-expressioniscoercedintothecorrecttypeifnecessary.
Inthecaseof:complex=realexpressiontheimplicationisthattherealpartofthecomplexnumberbecomestheresultoftheexpressionandtheimaginarypartbecomeszero.
Thesameappliesiftheexpressionisdoubleprecision,exceptthattheexpressionwillbecoercedtoreal.
Thefollowingareexamplesofarithmeticassignmentstatements.
A=(P+Q)*(T/V)B=R**T**2LogicalAssignmentStatementThelogicalassignmentstatementhasthefollowingform:object=logical-expressionLanguageOverview18whereobjectisoneofthefollowing:VariableFunctionname(onlywithinthebodyofthefunction)SubroutineargumentArrayelementAfieldofastructureThetypeofobjectmustbelogical.
Inthefollowingexample,FLAGtakesthelogicalvalue.
TRUE.
ifP+QisgreaterthanR;otherwiseFLAGhasthelogicalvalue.
FALSE.
FLAG=(P+Q).
GT.
RCharacterAssignmentTheformofacharacterassignmentis:object=characterexpressionwhereobjectisoneofthefollowing:VariableFunctionname(onlywithinthebodyofthefunction)SubroutineargumentArrayelementCharactersubstringAfieldofastructureAbove,objectmustbeoftypecharacter.
ListingControls19Noneofthecharacterpositionsbeingdefinedinobjectcanbereferencedinthecharacterexpressionandonlysuchcharactersasarenecessaryfortheassignmenttoobjectneedtobedefinedinthecharacterexpression.
Thecharacterexpressionandobjectcanhavedifferentlengths.
Whenobjectislongerthanthecharacterexpressiontrailingblanksareaddedtotheobject;andifobjectisshorterthanthecharacterexpressiontheright-handcharactersofthecharacterexpressionaretruncatedasnecessary.
Inthefollowingexample,notethatallthevariablesandarraysareassumedtobeoftypecharacter.
FILE='BOOKS'PLOT(3:8)='PLANTS'TEXT(I,K+1)(2:B-1)=TITLE//XListingControlsThePGIFortrancompilersrecognizethreecompilerdirectivesthataffecttheprogramlistingprocess:%LISTTurnsonthelistingprocessbeginningatthefollowingsourcecodeline.
%NOLISTTurnsoffthelistingprocess(includingthe%NOLISTlineitself).
%EJECTCausesanewlistingpagetobestarted.
Thesedirectiveshaveaneffectonlywhenthe–Mlistoptionisused.
Allofthedirectivesmustbeginincolumnone.
OpenMPDirectivesOpenMPdirectivesinaFortranprogramprovideinformationthatallowsthePGF77andPGF95compilerstogenerateexecutableprogramsthatusemultiplethreadsandprocessorsonashared-memoryparallel(SMP)computersystem.
AnOpenMPdirectivemayhaveanyofthefollowingforms:!
$OMPdirectiveC$OMPdirective*$OMPdirectiveAcompletelistandspecificationsofOpenMPdirectivessupportedbythePGF77andPGF95compilers,alongwithdescriptionsoftherelatedOpenMPruntimelibraryroutines,canbefoundinChapter8,"OpenMPDirectivesforFortran".
LanguageOverview20HPFDirectivesHPFdirectivesinaFortranprogramprovideinformationthatallowsthePGHPFcompilertoexplicitlycreatedatadistributionsfromwhichparallelismcanbederived.
AnHPFdirectivemayhaveanyofthefollowingforms:CHPF$directive!
HPF$directive*HPF$directiveSinceHPFsupportstwosourceforms,fixedsourceformandfreesourceform,thereareavarietyofmethodstoenteradirective.
TheC,!
,or*mustbeincolumn1forfixedsourceformdirectives.
Infreesourceform,Fortranlimitsthecommentcharacterto!
.
Ifyouusethe!
HPF$formforthedirectiveorigin,yourcodewillbeuniversallyvalid.
Thebodyofthedirectivemayimmediatelyfollowthedirectiveorigin.
Alternatively,anynumberofblanksmayprecedetheHPFdirective.
Anynamesinthebodyofthedirective,includingthedirectivename,maynotcontainembeddedblanks.
Blanksmaysurroundanyspecialcharacters,suchasacommaoranequalssign.
Thedirectivename,includingthedirectiveorigin,maycontainupperorlowercaseletters(caseisnotsignificant).
AcompletelistandspecificationsofHPFdirectivessupportedbythePGHPFcompilercanbefoundinChapter9,"HPFDirectives".
IntrinsicDataTypes212FortranDataTypesEveryFortranelementandexpressionhasadatatype.
Thedatatypeofanelementmaybeimplicitinitsdefinitionorexplicitlyattachedtotheelementinadeclarationstatement.
ThischapterdescribestheFortrandatatypesandconstantsthataresupportedbythePGIFortrancompilers.
Fortranprovidestwokindsofdatatypes,intrinsicdatatypesandderiveddatatypes.
Typesprovidedbythelanguageareintrinsictypes.
Typesspecifiedbytheprogrammerandbuiltfromtheintrinsicdatatypesarecalledderivedtypes.
IntrinsicDataTypesFortranprovidessixdifferentintrinsicdatatypesasshowninTable2-1,"FortranIntrinsicDataTypes".
Table2-2,"DataTypesKindParameters"andTable2-3,"DataTypeExtensions"showvariationsanddifferent"kinds"oftheintrinsicdatatypessupportedbythePGIFortrancompilers.
KindParameterTheFortran95KINDparameterspecifiesaprecisionforintrinsicdatatypes.
TheKINDparameterfollowsadatatypespecifierandspecifiessizeortypeofthesupporteddatatype.
AKINDspecificationoverridesthelengthattributethatthestatementimpliesandassignsaspecificlengthtotheitem,regardlessofthecompiler'scommand-lineoptions.
AKINDisdefinedforadatatypebyaPARAMETERstatement,usingsizessupportedontheparticularsystem.
ThefollowingaresomeexamplesusingaKINDspecification:INTEGER(SHORT)::LREAL(HIGH)BREAL(KIND=HIGH)XVAR,YVARTheseexamplesrequirethattheprogrammeruseaPARAMETERstatementtodefinekinds:INTEGER,PARAMETER::SHORT=1INTEGERHIGHPARAMETER(HIGH=8)ThefollowingtableshowsseveralexamplesofKINDsthatasystemcouldsupport.
FortranDataTypes22Table2-1:FortranIntrinsicDataTypesTable2-2:DataTypesKindParametersNumberofBytesSpecificationThePGIFortrancompilerssupportalengthspecifierforsomedatatypes.
Thedatatypecanbefollowedbyadatatypelengthspecifieroftheform*s,wheresisoneofthesupportedlengthsforthedatatype.
Suchaspecificationoverridesthelengthattributethatthestatementimpliesandassignsaspecificlengthtothespecifieditem,regardlessofthecompileroptions.
Forexample,REAL*8isequivalenttoDOUBLEPRECISION.
Thefollowingtableshowsthelengthsofdatatypes,theirmeanings,andtheirsizes.
DataTypeValueINTEGERAnintegernumber.
REALArealnumber.
DOUBLEPRECISIONAdoubleprecisionfloatingpointnumber,realnumber,takinguptwonumericstorageunitsandwhosepreci-sionisgreaterthanREAL.
LOGICALAvaluewhichcanbeeitherTRUEorFALSE.
COMPLEXApairofrealnumbersusedincomplexarithmetic.
For-tranprovidestwoprecisionsforCOMPLEXnumbers.
CHARACTERAstringconsistingofoneormoreprintablecharacters.
TypeKindSizeINTEGERSHORT1byteINTEGERLONG4bytesREALHIGH8bytesIntrinsicDataTypes23Table2-3:DataTypeExtensionsTheBYTEtypeistreatedasasignedone-byteintegerandisequivalenttoLOGICAL*1.
Assignmentofavaluetoobigforthedatatypetowhichitisassignedisanundefinedoperation.
AspecifierisallowedafteraCHARACTERfunctionnameeveniftheCHARACTERtypewordhasaspecifier.
Forexample:CHARACTER*4FUNCTIONC*8(VAR1)TypeMeaningSizeLOGICAL*1SmallLOGICAL1byteLOGICAL*2ShortLOGICAL2bytesLOGICAL*4LOGICAL4bytesLOGICAL*8LOGICAL8bytesBYTESmallINTEGER1byteINTEGER*1SameasBYTE1byteINTEGER*2ShortINTEGER2bytesINTEGER*4INTEGER4bytesINTEGER*8INTEGER8bytesREAL*4REAL4bytesREAL*8DOUBLEPRECISION8bytesCOMPLEX*8COMPLEX8bytesCOMPLEX*16DOUBLECOMPLEX16bytesFortranDataTypes24ThefunctionsizespecificationC*8overridestheCHARACTER*4specification.
Logicaldataitemscanbeusedwithanyoperationwhereasimilarsizedintegerdataitemispermissibleandviceversa.
Thelogicaldataitemistreatedasanintegerortheintegerdataitemistreatedasalogicalofthesamesizeandnotypeconversionisperformed.
FloatingpointdataitemsoftypeREALorDOUBLEPRECISIONmaybeusedasarraysubscripts,incomputedGOTOs,inarrayboundsandinalternatereturns.
Thefloatingpointdataitemisconvertedtoaninteger.
Thedatatypeoftheresultofanarithmeticexpressioncorrespondstothetypeofitsdata.
Thetypeofanexpressionisdeterminedbytherankofitselements.
Thefollowingtableshowstheranksofthevariousdatatypes,fromlowesttohighest.
Table2-4:DataTypeRanksThedatatypeofavalueproducedbyanoperationontwoarithmeticelementsofdifferentdatatypesisthedatatypeofthehighest-rankedelementintheoperation.
TheexceptiontothisruleisthatanoperationinvolvingaCOMPLEX*8elementandaREAL*8elementproducesaCOMPLEX*16result.
Inthisoperation,theCOMPLEX*8elementisconvertedtoaCOMPLEX*16element,whichconsistsoftwoREAL*8elements,beforetheoperationisperformed.
DataTypeRankLOGICAL1(lowest)LOGICAL*82INTEGER*23INTEGER*44INTEGER*85REAL*46REAL*8(Doubleprecision)7COMPLEX*8(Complex)8COMPLEX*16(Doublecomplex)9(highest)Constants25Inmostcases,alogicalexpressionwillhaveaLOGICAL*4result.
IncaseswherethehardwaresupportsLOGICAL*8andiftheexpressionisLOGICAL*8,theresultmaybeLOGICAL*8.
ConstantsAconstantisanunchangingvaluethatcanbedeterminedatcompiletime.
Ittakesaformcorrespondingtooneofthedatatypes.
ThePGIFortrancompilerssupportdecimal(INTEGERandREAL),unsignedbinary,octal,hexadecimal,characterandHollerithconstants.
Theuseofcharacterconstantsinanumericcontext,forexample,intheright-handsideofanarithmeticassignmentstatement,issupported.
Theseconstantsassumeadatatypethatconformstothecontextinwhichtheyappear.
IntegerConstantsTheformofadecimalintegerconstantis:[s]d1d2.
.
.
dn[_kind-parameter]wheresisanoptionalsignanddiisadigitintherange0to9.
Theoptional_kind-parameterisaFortran90/95featuresupportedonlybyPGF95andPGHPF,andspecifiesasupportedkind.
Thevalueofanintegerconstantmustbewithintherangeforthespecifiedkind.
Thevalueofanintegerconstantmustbewithintherange-2147483648to2147483647inclusive(-231to(231-1)).
IntegerconstantsassumeadatatypeofINTEGER*4andhavea32-bitstoragerequirement.
The–i8compilationoptioncausesalldataoftypeINTEGERtobepromotedtoan8byteINTEGER.
The–i8optiondoesnotoverrideanexplicitdatatypeextensionsizespecifier(forexampleINTEGER*4).
Therange,datatypeandstoragerequirementchangeifthe–i8flagisspecified(thisflagisnotsupportedonalltargets).
Withthe–i8flag,therangeforintegerconstantsis-263to(263-1)),andinthiscasethevalueofanintegerconstantmustbewithintherange-9223372036854775808to9223372036854775807.
IftheconstantdoesnotfitinanINTEGER*4range,thedatatypeisINTEGER*8andthestoragerequirementis64bits.
Belowareseveralexamplesofintegerconstants.
FortranDataTypes26+2-36437-36_SHORT369_I2Binary,OctalandHexadecimalConstantsThePGIcompilersandFortran90/95supportvarioustypesofconstantsbesidesdecimalconstants.
Fortranallowsunsignedbinary,octal,orhexadecimalconstantsinDATAstatements.
PGIcompilerssupporttheseconstantsinDATAstatements,andadditionally,supportsomeoftheseconstantsoutsideofDATAstatements.
Formoreinformationonsupportoftheseconstants,referto"FortranBinary,OctalandHexadecimalConstants"onpage33.
RealConstantsRealconstantshavetwoforms,scaledandunscaled.
Anunscaledrealconstantconsistsofasignedorunsigneddecimalnumber(anumberwithadecimalpoint).
Ascaledrealconstanttakesthesameformasanunscaledconstant,butisfollowedbyanexponentscalingfactoroftheform:E+digits[_kind-parameter]Edigit[_kind-parameter]E-digits[_kind-parameter]wheredigitsisthescalingfactor,thepoweroften,tobeappliedtotheunscaledconstant.
Thefirsttwoformsaboveareequivalent,thatis,ascalingfactorwithoutasignisassumedtobepositive.
Thefollowingtableshowsseveralrealconstants.
Constants27Table2-5:ExampleofRealConstantsDoublePrecisionConstantsAdoubleprecisionconstanthasthesameformasascaledREALconstantexceptthattheEisreplacedbyDandthekindparameterisnotpermitted.
Forexample:D+digitsDdigitD-digitsThefollowingtableshowsseveraldoubleprecisionconstants.
ConstantValue1.
0unscaledsingleprecisionconstant1.
unscaledsingleprecisionconstant-.
003signedunscaledsingleprecisionconstant-.
003_LOWsignedunscaledconstantwithkindLOW-1.
0signedunscaledsingleprecisionconstant6.
1E2_LOWisequivalentto610.
0withkindLOW+2.
3E3_HIGHisequivalentto2300.
0withkindHIGH6.
1E2isequivalentto610.
0+2.
3E3isequivalentto2300.
0-3.
5E-1isequivalentto-0.
35FortranDataTypes28Table2-6:DoublePrecisionConstantsComplexConstantsAcomplexconstantisheldastworealorintegerconstantsseparatedbyacommaandsurroundedbyparentheses.
Thefirstrealnumberistherealpartandthesecondrealnumberistheimaginarypart.
Togetherthesevaluesrepresentacomplexnumber.
IntegervaluessuppliedasparametersforaCOMPLEXconstantareconvertedtoREALnumbers.
Belowareseveralexamples:(18,-4)(3.
5,-3.
5)(6.
1E2,+2.
3E3)DoubleComplexConstantsAcomplexconstantisheldastwodoubleconstantsseparatedbyacommaandsurroundedbyparentheses.
Thefirstdoubleistherealpartandtheseconddoubleistheimaginarypart.
Togetherthesevaluesrepresentacomplexnumber.
Belowisanexample:(6.
1D2,+2.
3D3)LogicalConstantsAlogicalconstantisoneof:.
TRUE.
[_kind-parameter].
FALSE.
[_kind-parameter]Thelogicalconstants.
TRUE.
and.
FALSE.
arebydefaultdefinedtobethefour-bytevalues-1and0respectively.
Alogicalexpressionisdefinedtobe.
TRUE.
ifitsleastsignificantbitis1and.
FALSE.
otherwise1.
ConstantValue6.
1D2isequivalentto610.
0+2.
3D3isequivalentto2300.
0-3.
5D-1isequivalentto-0.
35+4D4isequivalentto40000Constants29Belowareseveralexamples:.
TRUE.
.
FALSE.
.
TRUE.
_BITTheabbreviationsTandFcanbeusedinplaceof.
TRUE.
and.
FALSE.
indatainitializationstatementsandinNAMELISTinput.
CharacterConstantsCharacterstringconstantsmaybedelimitedusingeitheranapostrophe(')oradoublequote(").
Theapostropheordoublequoteactsasadelimiterandisnotpartofthecharacterconstant.
Usetwoapostrophestogethertoincludeanapostropheaspartoftheexpression.
Ifastringbeginswithonevarietyofquotemark,theothermaybeembeddedwithinitwithoutusingtherepeatedquoteorbackslashescape.
Withincharacterconstants,blanksaresignificant.
Forfurtherinformationontheuseofthebackslashcharacter,referto–MbackslashinthePGIUser'sGuide.
Acharacterconstantisoneof:[kind-parameter_]"[characters]"[kind-parameter_]'[characters]'Belowareseveralexamplesofcharacterconstants.
'abc''abc''ab''c'"TestWord"GREEK_""Azerolengthcharacterconstantiswrittenas''or"".
Ifacharacterconstantisusedinanumericcontext,forexampleastheexpressionontherightsideofanarithmeticassignmentstatement,itistreatedasaHollerithconstant.
Therulesfortypingandsizingcharacterconstantsusedinanumericcontextaredescribedin"HollerithConstants"onpage35.
1.
Theoption–MunixlogicaldefinesalogicalexpressiontobeTRUEifitsvalueisnon-zero,andFALSEotherwise;also,theinternalvalueof.
TRUE.
issettoone.
Thisoptionisnotavailableonalltargetsystems.
FortranDataTypes30PARAMETERConstantsThePARAMETERstatementpermitsnamedconstantstobedefined.
RefertothedescriptionofthePARAMETERstatementfoundinChapter3,"FortranStatements",formoredetailsondefiningconstants.
DerivedTypesAderivedtypeisatypemadeupofcomponentswhosetypeiseitherintrinsicoranotherderivedtype.
TheTYPEandENDTYPEkeywordsdefineaderivedtype.
Forexample,thefollowingderivedtypedeclarationdefinesthetypePERSONandthearrayCUSTOMERoftypePERSON:!
DeclareastructuretodefineapersonderivedtypeTYPEPERSONINTEGERIDLOGICALLIVINGCHARACTER(LEN=20)FIRST,LAST,MIDDLEINTEGERAGEENDTYPEPERSONTYPE(PERSON)CUSTOMER(10)Aderivedtypestatementdefinitioniscalledaderived-typestatement(thestatementsbetweenTYPEPERSONandENDTYPEPERSONinthepreviousexample.
ThedefinitionofavariableofthenewtypeiscalledaTYPEstatement(CUSTOMERinthepreviousexample);notetheuseofparenthesesintheTYPEstatement.
The%characteraccessesthecomponentsofaderivedtype.
Forexample:CUSTOMER(1)%ID=11308ArraysArraysinFortranarenotdatatypes,butaredataobjectsofintrinsicorderivedtypewithspecialcharacteristics.
Adimensionstatementprovidesadatatypewithoneormoredimensions.
ThereareseveraldifferencesbetweenFortran90/95andtraditionalFORTRAN77arrays.
Note:Fortran90/95supportsallFORTRAN77arraysemantics.
Arrays31Anarrayisagroupofconsecutive,contiguousstoragelocationsassociatedwithasymbolicnamewhichisthearrayname.
Eachindividualelementofstorage,calledthearrayelement,isreferencedbythearraynamemodifiedbyalistofsubscripts.
Arraysaredeclaredwithtypedeclarationstatements,DIMENSIONstatementsandCOMMONstatements;theyarenotdefinedbyimplicitreference.
Thesedeclarationswillintroduceanarraynameandestablishthenumberofdimensionsandtheboundsandsizeofeachdimension.
Ifasymbol,modifiedbyalistofsubscriptsisnotdefinedasanarray,thenitwillbeassumedtobeaFUNCTIONreferencewithanargumentlist.
Fortran90/95arraysare"objects"andoperationsandexpressionsinvolvingarraysmayapplytoeveryelementofthearrayinanunspecifiedorder.
Forexample,inthefollowingcode,whereAandBarearraysofthesameshape(conformablearrays),thefollowingexpressionaddssixtoeveryelementofBandassignstheresultstothecorrespondingelementsofA:A=B+6Fortranarraysmaybepassedwithunspecifiedshapestosubroutinesandfunctions,andsectionsofarraysmaybeusedandpassedaswell.
Arraysofderivedtypearealsovalid.
Inaddition,allocatablearraysmaybecreatedwithdeferredshapes(numberofdimensionsisspecifiedatdeclaration,buttheactualboundsandsizeofeachdimensionaredeterminedwhenthearrayisallocatedwhiletheprogramisrunning).
AnArrayDeclarationElementAnarraydeclarationhasthefollowingform:name([lb:]ub[,[lb:]ub].
.
.
)wherenameisthesymbolicnameofthearray,lbisthespecificationofthelowerboundofthedimensionandubisthespecificationoftheupperbound.
Theupperbound,ubmustbegreaterthanthelowerboundlb.
Thevalueslbandubmaybenegative.
Theboundlbistakentobe1ifitisnotspecified.
Thedifference(ub-lb+1)specifiesthenumberofelementsinthatdimension.
Thenumberoflb,ubpairsspecifiestherankofthearray.
AssumingthearrayisofadatatypethatrequiresNbytesperelement,thetotalamountofstorageofthearrayis:N*(ub-lb+1)*(ub-lb+1)*.
.
.
ThedimensionspecifiersofanarraysubroutineargumentmaythemselvesbesubroutineargumentsormembersofCOMMON.
FortranDataTypes32DeferredShapeArraysDeferred-shapearraysarethosearrayswhoseshapecanbechangedbyanexecutablestatement.
Deferred-shapearraysaredeclaredwitharank,butwithnoboundsinformation.
TheyassumetheirshapewheneitheranALLOCATEstatementoraREDIMENSIONstatementisencountered.
Forexample,thefollowingstatementdeclaresadeferredshapeREALarrayAofranktwo:REALA(:,:)SubscriptsAsubscriptisusedtospecifyanarrayelementforaccess.
Anarraynamequalifiedbyasubscriptlisthasthefollowingform:name(sub[,sub].
.
.
)wheretheremustbeonesubentryforeachdimensioninarrayname.
Eachsubmustbeanintegerexpressionyieldingavaluewhichiswithintherangeofthelowerandupperbounds.
Arraysarestoredasalinearsequenceofvaluesinmemoryandareheldsuchthatthefirstelementisinthefirststorelocationandthelastelementisinthelaststorelocation.
Inamulti-dimensionalarraythefirstsubscriptvariesmorerapidlythanthesecond,thesecondmorerapidlythanthethird,andsoon(columnmajororder).
CharacterSubstringAcharactersubstringisacontiguousportionofacharactervariableandisoftypecharacter.
Acharactersubstringcanbereferenced,assignedvaluesandnamed.
Itcantakeeitherofthefollowingforms:character_variable_name(x1:x2)character_array_name(subscripts)(x1:x2)wherex1andx2areintegersandx1denotestheleft-handcharacterpositionandx2theright-handone.
Theseareknownassubstringexpressions.
Insubstringexpressionsx1mustbebothgreaterthanorequalto1andlessthanx2andx2mustbelessthanorequaltothelengthofthecharactervariableorarrayelement.
Forexample:J(2:4)FortranPointersandTargets33thecharactersinpositions2to4ofcharactervariableJ.
K(3,5)(1:4)thecharactersinpositions1to4ofarrayelementK(3,5).
Asubstringexpressioncanbeanyvalidintegerexpressionandmaycontainarrayelementsorfunctionreferences.
FortranPointersandTargetsFortranpointersaresimilartoallocatablearrays.
Pointersaredeclaredwithatypeandarank;theydonotactuallyrepresentavalue,however,butrepresentavalue'saddress.
Fortran90/95hasaspecificassignmentoperator,=>,foruseinpointerassignments.
FortranBinary,OctalandHexadecimalConstantsThePGIFortrancompilerssupporttworepresentationsforbinary,octal,andhexadecimalnumbers:thestandardFortran90/95representationandthePGIextensionrepresentation.
Refertothenextsectionfordetailsonthealternaterepresentation.
Fortransupportsbinary,octalandhexadecimalconstantsinDATAstatements.
Theformofabinaryconstantis:B'b1b2.
.
.
bn'B"b1b2.
.
.
bn"wherebiiseither0or1.
Theformofanoctalconstantis:O'c1c2.
.
.
cn'O"c1c2.
.
.
cn"whereciisintherange0through7.
Theformofahexadecimalconstantis:Z'a1a2.
.
.
an'Z"a1a2.
.
.
an"orFortranDataTypes34'a1a2.
.
.
an'X"a1a2.
.
.
an"Xwhereaisintherange0through9oraletterintherangeAthroughForathroughf(casemixingisallowed).
OctalandHexadecimalConstants-AlternateForm§ThePGF95compilersupportsadditionalextensions.
ThePGF95andPGHPFcompilerssupportadditionalextensions.
Thisisanalternateformforoctalconstants,outsideofDATAstatements.
Theformforanoctalconstantis:'c1c2.
.
.
cn'OTheformofahexadecimalconstantis:'a1a2.
.
.
an'Xwhereciisadigitintherange0to7andaiisadigitintherange0to9oraletterintherangeAtoForatof(casemixingisallowed).
Upto64bits(22octaldigitsor16hexadecimaldigits)canbespecified.
Octalandhexadecimalconstantsarestoredaseither32-bitor64-bitquantities.
Theyarepaddedontheleftwithzeroesifneededandassumedatatypesbasedonhowtheyareused.
Thefollowingaretherulesforconvertingthesedatatypes:Aconstantisalwayseither32or64bitsinsizeandistypeless.
Sign-extensionandtype-conversionareneverperformed.
Allbinaryoperationsareperformedon32-bitor64-bitquantities.
Thisimpliesthattherulestofollowareonlyconcernedwithmixing32-bitand64-bitdata.
Whenaconstantisusedwithanarithmeticbinaryoperator(includingtheassignmentoperator)andtheotheroperandistyped,theconstantassumesthetypeandsizeoftheotheroperand.
Whenaconstantisusedinarelationalexpressionsuchas.
EQ.
,itssizeischosenfromtheoperandhavingthelargestsize.
Thisimpliesthat64-bitcomparisonsarepossible.
WhenaconstantisusedasanargumenttothegenericAND,OR,EQV,NEQV,SHIFT,orCOMPLfunction,a32-bitoperationisperformedifnoargumentismorethan32bitsinsize;otherwise,a64-bitoperationisperformed.
Thesizeoftheresultcorrespondstothechosenoperation.
Whenaconstantisusedasanactualargumentinanyothercontext,nodatatypeisassumed;however,alengthoffourbytesisalwaysused.
Ifnecessary,truncationontheleftoccurs.
HollerithConstants35Whenaspecific32-bitor64-bitdatatypeisrequired,thattypeisassumedfortheconstant.
Arraysubscriptingisanexample.
Whenaconstantisusedinacontextotherthanthosementionedabove,anINTEGER*4datatypeisassumed.
Logicalexpressionsandbinaryarithmeticoperationswithotheruntypedconstantsareexamples.
Whentherequireddatatypeforaconstantimpliesthatthelengthneededismorethanthenumberofdigitsspecified,theleftmostdigitshaveavalueofzero.
Whentherequireddatatypeforaconstantimpliesthatthelengthneededislessthanthenumberofdigitsspecified,theconstantistruncatedontheleft.
Truncationofnonzerodigitsisallowed.
Intheexamplebelow,theconstantI(oftypeINTEGER*4)andtheconstantJ(oftypeINTEGER*2)willhavehexvalues1234and4567,respectively.
ThevariableD(oftypeREAL*8)willhavethehexvaluex4000012345678954afteritssecondassignment:I='1234'X!
LeftmostPadwithzeroJ='1234567'X!
TruncateLeftmost3hexdigitsD='40000123456789ab'XD=NEQV(D,'ff'X)!
64-bitExclusiveOrHollerithConstantsTheformofaHollerithconstantis:nHc1c2.
.
.
cnwherenspecifiesthepositivenumberofcharactersintheconstantandcannotexceed2000characters.
AHollerithconstantisstoredasabytestringwithfourcharactersper32-bitword.
HollerithconstantsareuntypedarraysofINTEGER*4.
Thelastwordofthearrayispaddedontherightwithblanksifnecessary.
Hollerithconstantscannotassumeacharacterdatatypeandcannotbeusedwhereacharactervalueisexpected.
ThedatatypeofaHollerithconstantusedinanumericexpressionisdeterminedbythefollowingrules:Sign-extensionisneverperformed.
ThebytesizeoftheHollerithconstantisdeterminedbyitscontextandisnotstrictlylimitedto32or64bitslikehexadecimalandoctalconstants.
Whentheconstantisusedwithabinaryoperator(includingtheassignmentoperator),thedatatypeoftheconstantassumesthedatatypeoftheotheroperand.
FortranDataTypes36Whenaspecificdatatypeisrequired,thattypeisassumedfortheconstant.
Whenanintegerorlogicalisrequired,INTEGER*4andLOGICAL*4areassumed.
Whenafloatisrequired,REAL*4isassumed(arraysubscriptingisanexampleoftheuseofarequireddatatype).
Whenaconstantisusedasanargumenttocertaingenericfunctions(AND,OR,EQV,NEQV,SHIFT,andCOMPL),a32-bitoperationisperformedifnoargumentislargerthan32bits;otherwise,a64-bitoperationisperformed.
Thesizeoftheresultcorrespondstothechosenoperation.
Whenaconstantisusedasanactualargument,nodatatypeisassumedandtheargumentispassedasanINTEGER*4array.
Characterconstantsarepassedbydescriptoronly.
Whenaconstantisusedinanyothercontext,a32-bitINTEGER*4arraytypeisassumed.
WhenthelengthoftheHollerithconstantislessthanthelengthimpliedbythedatatype,spacesareappendedtotheconstantontheright.
Whenthelengthoftheconstantisgreaterthanthelengthimpliedbythedatatype,theconstantistruncatedontheright.
StructuresAstructure,aDECextensiontoFORTRAN77,isauser-definedaggregatedatatypehavingthefollowingform:STRUCTURE[/structure_name/][field_namelist]field_declaration[field_declaration].
.
.
[field_declaration]ENDSTRUCTUREWhere:structure_nameisuniqueandisusedbothtoidentifythestructureandtoallowitsuseinsubsequentRECORDstatements.
field_namelistisalistoffieldshavingthestructureoftheassociatedstructuredeclaration.
Afield_namelistisallowedonlyinnestedstructuredeclarations.
field_declarationcanconsistofanycombinationofsubstructuredeclarations,typeddatadeclarations,uniondeclarationsorunnamedfielddeclarations.
Structures37Fieldswithinstructuresconformtomachine-dependentalignmentrequirements.
AlignmentoffieldsalsoprovidesaC-like"struct"buildingcapabilityandallowsconvenientinter-languagecommunications.
Fieldnameswithinthesamedeclarationnestinglevelmustbeunique,butaninnerstructuredeclarationcanincludefieldnamesusedinanouterstructuredeclarationwithoutconflict.
Also,becauserecordsuseperiodstoseparatefields,itisnotlegaltouserelationaloperators(forexample,.
EQ.
,.
XOR.
),logicalconstants(.
TRUE.
or.
FALSE.
),orlogicalexpressions(.
AND.
,.
NOT.
,.
OR.
)asfieldnamesinstructuredeclarations.
Fieldsinastructurearealignedasrequiredbyhardware;thereforeastructure'sstoragerequirementsaremachine-dependent.
Becauseexplicitpaddingofrecordsisnotnecessary,thecompilerrecognizesthe%FILLintrinsic,butperformsnoactioninresponsetoit.
Datainitializationcanoccurfortheindividualfields.
RecordsArecord,aDECextensiontoFORTRAN77,isauser-definedaggregatedataitemhavingthefollowingform:RECORD/structure_name/record_namelist[,/structure_name/record_namelist].
.
.
[,/structure_name/record_namelist]where:structure_nameisthenameofapreviouslydeclaredstructure.
record_namelistisalistofoneormorevariableorarraynamesseparatedbycommas.
YoucreatememorystorageforarecordbyspecifyingastructurenameintheRECORDstatement.
Youdefinethefieldvaluesinarecordeitherbydefiningtheminthestructuredeclarationorbyassigningthemwithexecutablecode.
Youcanaccessindividualfieldsinarecordbycombiningtheparentrecordname,aperiod(.
),andthefieldname(forexample,recordname.
fieldname).
Forrecords,ascalarreferencemeansareferencetoanamethatresolvestoasingletypeddataitem(forexample,INTEGER),whileanaggregatereferencemeansareferencethatresolvestoastructureddataitem.
FortranDataTypes38ScalarfieldreferencesmayappearwherevernormalvariableorarrayelementsmayappearwiththeexceptionofCOMMON,SAVE,NAMELIST,DATAandEQUIVALENCEstatements.
Aggregatereferencesmayonlyappearinaggregateassignmentstatements,unformattedI/Ostatements,andasparameterstosubprograms.
ThefollowingisanexampleofRECORDandSTRUCTUREusage.
STRUCTURE/person/!
DeclareastructuredefiningapersonINTEGERidLOGICALlivingCHARACTER*5first,last,middleINTEGERageENDSTRUCTURE!
Definepopulationtobeanarraywhereeachelementis!
oftypeperson.
Alsodefineavariable,me,oftype!
person.
RECORD/person/population(2),me.
.
.
me.
age=34!
Assignvaluesforthevariablemetome.
living=.
TRUE.
!
someofthefields.
me.
first='Steve'me.
id=542124822.
.
.
population(1).
last='Jones'!
Assignthe"last"fieldof!
element1ofarraypopulation.
population(2)=me!
Assignallvaluesofrecord!
"me"totherecord!
population(2)UNIONandMAPDeclarationsAUNIONdeclaration,aDECextensiontoFORTRAN77,isamulti-statementdeclarationdefiningadataareathatcanbesharedintermittentlyduringprogramexecutionbyoneormorefieldsorgroupsoffields.
Itdeclaresgroupsoffieldsthatshareacommonlocationwithinastructure.
EachgroupoffieldswithinauniondeclarationisdeclaredbyaMAPdeclaration,withoneormorefieldsperMAPdeclaration.
Structures39Uniondeclarationsareusedwhenonewantstousethesameareaofmemorytoalternatelycontaintwoormoregroupsoffields.
Wheneveroneofthefieldsdeclaredbyauniondeclarationisreferencedinaprogram,thatfieldandanyotherfieldsinitsmapdeclarationbecomedefined.
Then,whenafieldinoneoftheothermapdeclarationsintheuniondeclarationisreferenced,thefieldsinthatmapdeclarationbecomedefined,supersedingthefieldsthatwerepreviouslydefined.
AuniondeclarationisinitiatedbyaUNIONstatementandterminatedbyanENDUNIONstatement.
Enclosedwithinthesestatementsareoneormoremapdeclarations,initiatedandterminatedbyMAPandENDMAPstatements,respectively.
Eachuniquefieldorgroupoffieldsisdefinedbyaseparatemapdeclaration.
TheformatofaUNIONstatementisdescribedinthefollowingexample:UNIONmap_declaration[map_declaration].
.
.
[map_declaration]ENDUNIONTheformatofthemap_declarationisasfollows:MAPfield_declaration[field_declaration].
.
.
[field_declaration]ENDMAPwherefield_declarationisastructuredeclarationorRECORDstatementcontainedwithinauniondeclaration,auniondeclarationcontainedwithinauniondeclaration,orthedeclarationofatypeddatafieldwithinaunion.
Datacanbeinitializedinfielddeclarationstatementsinuniondeclarations.
Note,however,itisillegaltoinitializemultiplemapdeclarationsinasingleunion.
Fieldalignmentwithinmultiplemapdeclarationsisperformedaspreviouslydefinedinstructuredeclarations.
Thesizeofthesharedareaforauniondeclarationisthesizeofthelargestmapdefinedforthatunion.
Thesizeofamapisthesumofthesizesofthefield(s)declaredwithinitplusthespacereservedforalignmentpurposes.
FortranDataTypes40ManipulatingdatausinguniondeclarationsissimilartowhathappensusingEQUIVALENCEstatements.
However,uniondeclarationsareprobablymoresimilartouniondeclarationsforthelanguageC.
ThemaindifferenceisthattheClanguagerequiresonetoassociateanamewitheach"map"(union).
Fortranfieldnamesmustbeuniquewithinthesamedeclarationnestinglevelofmaps.
ThefollowingisanexampleofRECORD,STRUCTURE,MAPandUNIONusage.
Thesizeofeachelementoftherecarrarraywouldbethesizeoftypetag(4bytes)plusthesizeofthelargestMAP,theemployeemap(24bytes).
STRUCTURE/account/INTEGERtypetag!
Tagtodeterminedefinedmap.
UNIONMAP!
StructureforanemployeeCHARACTER*12ssn!
SocialSecurityNumberREAL*4salaryCHARACTER*8empdate!
EmploymentdateENDMAPMAP!
StructureforacustomerINTEGER*4acct_custREAL*4credit_amtCHARACTER*8due_dateENDMAPMAP!
StructureforasupplierINTEGER*4acct_suppREAL*4debit_amtBYTEnum_itemsBYTEitems(12)!
ItemssuppliedENDMAPENDUNIONENDSTRUCTURERECORD/account/recarr(1000)DataInitializationDatainitializationisallowedwithindatatypedeclarationstatements.
ThisisanextensiontotheFortranlanguage.
Dataisinitializedbyplacingvaluesboundedbyslashesimmediatelyfollowingthesymbolicname(variableorarray)tobeinitialized.
Initializationoffieldswithinstructuredeclarationsisallowed,butinitializationofunnamedfieldsandrecordsisnot.
Hollerith,octalandhexadecimalconstantscanbeusedtoinitializedatainbothdatatypedeclarationsandinDATAstatements.
Truncationandpaddingoccurforconstantsthatdifferinsizefromthedeclareddataitem(asspecifiedinthediscussionofconstants).
PointerVariables41PointerVariablesThePOINTERstatement,aCRAYextensiontoFORTRAN77whichisdistinctfromtheFortran90/95POINTERspecificationstatementorattribute,declaresascalarvariabletobeapointervariable(ofdatatypeINTEGER),andanothervariabletobeitspointer-basedvariable.
ThesyntaxofthePOINTERstatementis:POINTER(p1,v1)[,(p2,v2).
.
.
]v1andv2arepointer-basedvariables.
Apointer-basedvariablecanbeofanytype,includingSTRUCTURE.
Apointer-basedvariablecanbedimensionedinaseparatetype,inaDIMENSIONstatement,orinthePOINTERstatement.
Thedimensionexpressionmaybeadjustable,wheretherulesforadjustabledummyarraysregardinganyvariableswhichappearinthedimensiondeclaratorsapply.
p1andp2arethepointervariablescorrespondingtov1andv2.
Apointervariablemaynotbeanarray.
Thepointerisanintegervariablecontainingtheaddressofapointer-basedvariable.
Thestoragelocatedbythepointervariableisdefinedbythepointer-basedvariable(forexample,array,datatype,etc.
).
Areferencetoapointer-basedvariableappearsinFortranstatementslikeanormalvariablereference(forexample,alocalvariable,aCOMMONblockvariable,oradummyvariable).
Whenthebasedvariableisreferenced,theaddresstowhichitrefersisalwaystakenfromitsassociatedpointer(thatis,itspointervariableisdereferenced).
Thepointer-basedvariabledoesnothaveanaddressuntilitscorrespondingpointerisdefined.
Thepointerisdefinedinoneofthefollowingways:ByassigningthevalueoftheLOCfunction.
Byassigningavaluedefinedintermsofanotherpointervariable.
Bydynamicallyallocatingamemoryareaforthebasedvariable.
Ifapointer-basedvariableisdynamicallyallocated,itmayalsobefreed.
Thefollowingcodeillustratestheuseofpointers:FortranDataTypes42REALXC(10)COMMONIC,XCPOINTER(P,I)POINTER(Q,X(5))P=LOC(IC)I=0!
ICgets0P=LOC(XC)Q=P+20!
sameasLOC(XC(6))X(1)=0!
XC(6)gets0ALLOCATE(X)!
QlocatesanallocatedmemoryareaRestrictionsThefollowingrestrictionsapplytothePOINTERstatement:Nostorageisallocatedwhenapointer-basedvariableisdeclared.
Ifapointer-basedvariableisreferenced,itspointervariableisassumedtobedefined.
Apointer-basedvariablemaynotappearintheargumentlistofaSUBROUTINEorFUNCTIONandmaynotappearinCOMMON,EQUIVALENCE,DATA,NAMELIST,orSAVEstatements.
Apointer-basedvariablecanbeadjustedonlyinaSUBROUTINEorFUNCTIONsubprogram.
Ifapointer-basedvariableisanadjustablearray,itisassumedthatthevariablesinthedimensiondeclaratorsaredefinedwithanintegervalueatthetimetheSUBROUTINEorFUNCTIONiscalled.
Foravariablewhichappearsinapointer-basedvariable'sadjustabledeclarator,modifyingitsvalueduringtheexecutionoftheSUBROUTINEorFUNCTIONdoesnotmodifytheboundsofthedimensionsofthepointer-basedarray.
Apointer-basedvariableisassumednottooverlapwithanotherpointer-basedvariable.
OriginofStatement433FortranStatementsThischapterdescribeseachoftheFortranstatementssupportedbythePGIFortrancompilers.
Eachdescriptionincludesabriefsummaryofthestatement,asyntaxdescription,acompletedescriptionandanexample.
Thestatementsarelistedinalphabeticalorder.
Thefirstsectionliststermsthatareusedthroughoutthechapter.
DefinitionofTermscharacterscalarmemoryreferenceisacharactervariable,acharacterarrayelement,oracharactermemberofastructure.
integerscalarmemoryreferenceisanintegervariable,anintegerarrayelement,oranintegermemberofastructure.
logicalscalarmemoryreferenceisalogicalvariable,alogicalarrayelement,oralogicalmemberofastructure.
obsolescentThestatementisunchangedfromtheFORTRAN77definitionbuthasabetterreplacementinFortran95.
OriginofStatementAtthetopofeachreferencepageisanindicationoftheoriginofthestatement.
HeadingExplanation77FORTRAN77statementsthatareessentiallyunchangedfromtheoriginalFORTRAN77standardandaresupportedbythePGF77compiler.
90/95ThisstatementiseithernewforFortran90/95orsignificantlychangedinFortran95fromitsoriginalFORTRAN77definitionandissupportedbythePGF95andPGHPFcompilers.
HPFThestatementhasitsoriginintheHPFstandard.
§ThestatementisanextensiontotheFortranlanguage.
CMFIndicatesaCMFortranfeature(CMFortranisaversionofFortranthatwasproducedbyThinkingMachinesCorporationforparallelcomputers).
FortranStatements44StatementsACCEPT§77TheACCEPTstatementhasthesamesyntaxasthePRINTstatementandcausesformattedinputtobereadonstandardinput.
ACCEPTisidenticaltotheREADstatementwithaunitspecifierofasterisk(*).
SyntaxACCEPTf[,iolist]ACCEPTnamelistfformat-specifier,a*indicateslistdirectedinput.
iolistisalistofvariablestobeinput.
namelististhenameofanamelistspecifiedwiththeNAMELISTstatement.
ExamplesACCEPT*,IA,ZAACCEPT99,I,J,KACCEPTSUM99FORMAT(I2,I4,I3)Non-characterFormat-specifier§Ifaformat-specifierisavariablewhichisneitherCHARACTERnorasimpleINTEGERvariable,thecompileracceptsitandtreatsitasifthecontentswerecharacter.
Forexample,belowsumistreatedasaformatdescriptor:realsumsum=4h()acceptsumandisroughlyequivalenttocharacter*4chch='()'acceptchSeeAlsoREAD,PRINTStatements45ALLOCATABLE90TheALLOCATABLEspecificationstatement(attribute)specifiesthatanarraywithfixedrankbutdeferredshapeisavailableforafutureALLOCATEstatement.
AnALLOCATEstatementallocatesspacefortheallocatablearray.
SyntaxALLOCATABLE[::]array-name[(deferred-array-spec)][,array-name[(deferred-array-spec)]].
.
.
array-nameisthenameoftheallocatablearray.
deferred-array-specisa:character.
ExampleREALSCORE(:),NAMES(:,:)REAL,ALLOCATABLE,DIMENSION(TESTALLOCATABLESCORE,NAMESINTEGER,ALLOCATABLE::REC1(SeeAlsoALLOCATE,DEALLOCATEALLOCATE90TheALLOCATEstatementisanextensiontoFORTRAN77butispartoftheFortran90/95standard.
Itallocatesstorageforeachpointer-basedvariableandallocatablearraywhichappearsinthestatement.
ALLOCATEalsodeclaresstoragefordeferred-shapearrays.
SyntaxALLOCATE(allocation-list[,STAT=var])allocation-listis:allocate-object[allocate-shape-spec-list]allocate-objectis:variable-namestructure-componentallocate-shape-spec-listis:FortranStatements46[allocate-lower-bound:]allocate-upper-boundvarisanintegervariable,integerarrayelementoranintegermemberofaSTRUCTURE(thatis,anintegerscalarmemoryreference).
ThisvariableisassignedavaluedependingonthesuccessoftheALLOCATEstatement.
nameisapointer-basedvariableornameofanallocatableCOMMONenclosedinslashes.
DescriptionForapointer-basedvariable,itsassociatedpointervariableisdefinedwiththeaddressoftheallocatedmemoryarea.
IfthespecifierSTAT=ispresent,successfulexecutionoftheALLOCATEstatementcausesthestatusvariabletobedefinedwithavalueofzero.
IfanerroroccursduringexecutionofthestatementandthespecifierSTAT=ispresent,thestatusvariableisdefinedtohavetheintegervalueone.
IfanerroroccursandthespecifierSTAT=isnotpresent,programexecutionisterminated.
Adynamic,orallocatableCOMMONblockisacommonblockwhosestorageisnotallocateduntilanexplicitALLOCATEstatementisexecuted.
Note:AllocatableCOMMONblocksareanextensiontoFORTRAN77supportedonlybyPGF77compiler,andnotbythePGF95orPGHPFcompilers.
ForanALLOCATABLEarray,thearrayisallocatedwiththeexecutableALLOCATEstatement.
ExamplesCOMMONP,N,MPOINTER(P,A(N,M))COMMON,ALLOCATABLE/ALL/X(10),YALLOCATE(/ALL/,A,STAT=IS)PRINT*,ISX(5)=A(2,1)DEALLOCATE(A)DEALLOCATE(A,STAT=IS)PRINT*,'shouldbe1',ISDEALLOCATE(/ALL/)Foradeferredshapearray,theallocatemustincludetheboundsofthearray.
REAL,ALLOCATABLE::A(:),B(:)ALLOCATE(A(10),B(SIZE(A)))REALA(:,:)N=3M=1Statements47ALLOCATE(A(1:11,M:N))INTEGERFLAG,NREAL,ALLOCATABLE::B(:,:)ALLOCATE(B(N,N),STAT=FLAG)ARRAYCMFTheARRAYattributedefinesthenumberofdimensionsinanarraythatmaybedefinedandthenumberofelementsandboundsineachdimension.
SyntaxARRAY[::]array-name(array-spec)[,array-name(array-spec)].
.
.
array-nameisthesymbolicnameofanarray.
array-specisavalidarrayspecification,eitherexplicit-shape,assumed-shape,deferred-shape,orassumedsize(refertoChapter4,"FortranArrays",fordetailsonarrayspecifications).
DescriptionARRAYcanbeusedinasubroutineasasynonymforDIMENSIONtoestablishanargumentasanarray,andinthiscasethedeclaratorcanuseexpressionsformedfromintegervariablesandconstantstoestablishthedimensions(adjustablearrays).
NotehoweverthattheseintegervariablesmustbeeitherargumentsordeclaredinCOMMON;theycannotbelocal.
NotethatinthiscasethefunctionofARRAYismerelytosupplyamappingoftheargumenttothesubroutinecode,andnottoallocatestorage.
ThetypingofthearrayinanARRAYstatementisdefinedbytheinitialletterofthearraynameinthesamewayasvariablenames,unlessoverriddenbyanIMPLICITortypedeclarationstatement.
ArraysmayappearintypedeclarationandCOMMONstatementsbutthearraynamecanappearinonlyonearraydeclaration.
ExampleREAL,ARRAY(3:10)::ARRAY_ONEINTEGER,ARRAY(3,-2:2)::ARRAY_TWOFortranStatements48ThisspecifiesARRAY_ONEasavectorhavingeightelementswiththelowerboundof3andtheupperboundof10.
ARRAY_TWOasamatrixoftwodimensionshavingfifteenelements.
Thefirstdimensionhasthreeelementsandthesecondhasfivewithboundsfrom-2to2.
ASSIGN77(Obsolescent)Theassignstatementassignsastatementlabeltoavariable.
Internalprocedurescanbeusedinplaceoftheassignstatement.
Othercaseswheretheassignstatementisusedcanbereplacedbyusingcharacterstrings(fordifferentformatstatementsthatwereformallyassignedlabelsbyusinganintegervariableasaformatspecifier).
SyntaxASSIGNaTObaisthestatementlabel.
bisanintegervariable.
DescriptionExecutinganASSIGNstatementassignsastatementlabeltoanintegervariable.
Thisistheonlywaythatavariablemaybedefinedwithastatementlabelvalue.
Thestatementlabelmustbe:AstatementlabelinthesameprogramunitastheASSIGNstatement.
ThelabelofanexecutablestatementoraFORMATstatement.
Avariablemustbedefinedwithastatementlabelwhenitisreferenced:InanassignedGOTOstatement.
Asaformatidentifierinaninput/outputstatementandwhilesodefinedmustnotbereferencedinanyotherway.
Anintegervariabledefinedwithastatementlabelcanberedefinedwithadifferentstatementlabel,thesamestatementlabelorwithanintegervalue.
Statements49ExampleASSIGN40TOKGOTOK40L=P+I+56BACKSPACE77WhenaBACKSPACEstatementisexecutedthefileconnectedtothespecifiedunitispositionedbeforetheprecedingrecord.
SyntaxBACKSPACEunitBACKSPACE([UNIT=]unit[,ERR=errs][,IOSTAT=ios])UNIT=unitunitistheunitspecifier.
ERR=ssisanexecutablestatementlabelforthestatementusedforprocessinganerrorcondition.
IOSTAT=iosiosisanintegervariableorarrayelement.
iosbecomesdefinedwith0ifnoerroroccurs,andapositiveintegerwhenthereisanerror.
DescriptionIfthereisnoprecedingrecord,thepositionofthefileisnotchanged.
ABACKSPACEstatementcannotbeexecutedonafilethatdoesnotexist.
DonotissueaBACKSPACEstatementforafilethatisopenfordirectorappendaccess.
ExamplesBACKSPACE4BACKSPACE(UNIT=3)BACKSPACE(7,IOSTAT=IOCHEK,ERR=50)BLOCKDATA77TheBLOCKDATAstatementintroducesanumberofstatementsthatinitializedatavaluesinCOMMONblocks.
NoexecutablestatementsareallowedinaBLOCKDATAsegment.
FortranStatements50SyntaxBLOCKDATA[name][specification]END[BLOCKDATA[name]]nameisasymbolidentifyingthenameoftheblockdataandmustbeuniqueamongallglobalnames(COMMONblocknames,programname,modulenames).
Ifmissing,theblockdataisgivenadefaultname.
ExampleBLOCKDATACOMMON/SIDE/BASE,ANGLE,HEIGHT,WIDTHINTEGERSIZEPARAMETER(SIZE=100)INTEGERBASE(0:SIZE)REALWIDTH(0:SIZE),ANGLE(0:SIZE)DATA(BASE(I),I=0,SIZE)/SIZE*-1,-1/,+(WIDTH(I),I=0,SIZE)/SIZE*0.
0,0.
0/ENDBYTE§77TheBYTEstatementestablishesthedatatypeofavariablebyexplicitlyattachingthenameofavariabletoa1-byteinteger.
Thisoverridestheimplicationofdatatypingbytheinitialletterofasymbolicname.
SyntaxBYTEname[/clist/],.
.
.
nameisthesymbolicnameofavariable,array,oranarraydeclarator(seetheDIMENSIONstatementforanexplanationofarraydeclarators).
clistisalistofconstantsthatinitializethedata,asinaDATAstatement.
DescriptionBytestatementsmaybeusedtodimensionarraysexplicitlyinthesamewayastheDIMENSIONstatement.
BYTEdeclarationstatementsmustnotbelabeled.
Statements51ExampleBYTETB3,SEC,STORE(5,5)CALL77TheCALLstatementtransferscontroltoasubroutine.
SyntaxCALLsubroutine[([actual-arg-list].
.
.
])]subroutineisthenameofthesubroutine.
argumentistheactualargumentbeingpassedtothesubroutine.
ThefirstargumentcorrespondstothefirstdummyargumentintheSUBROUTINEstatementandsoon.
actual-arg-listhastheform:[keyword=]subroutine-argument.
keywordisadummyargumentnameinthesubroutineinterface.
subroutine-argumentisanactualargument.
DescriptionActualargumentscanbeexpressionsincluding:constants,scalarvariables,functionreferencesandarrays.
Actualargumentscanalsobealternatereturnspecifiers.
Alternatereturnspecifiersarelabelsprefixedbyasterisks(*)orampersands(&).
TheampersandisanextensiontoFORTRAN77.
Recursivecallsareallowedusingthe–Mrecursivecommand-lineoption.
ExamplesCALLCRASH!
noargumentsCALLBANG(1.
0)!
oneargumentCALLWALLOP(V,INT)!
twoargumentsCALLALTRET(I,*10,*20)SUBROUTINEONEDIMENSIONARR(10,10)REALWORKFortranStatements52INTEGERROW,COLPI=3.
142857CALLEXPENS(ARR,ROW,COL,WORK,SIN(PI/2)+3.
4)RETURNENDCASE90TheCASEstatementbeginsacase-statement-blockportionofaSELECTCASEconstruct.
Syntax[case-name:]SELECTCASE(case-expr)[CASE(selector)[name]block].
.
.
[CASEDEFAULT[case-name]block]ENDSELECT[case-name]ExampleSELECTCASE(FLAG)CASE(1,2,3)TYPE=1CASE(4:6)TYPE=2CASEDEFAULTTYPE=0ENDSELECTTypeExecutableSeeAlsoSELECTCASECHARACTER90TheCHARACTERstatementestablishesthedatatypeofavariablebyexplicitlyattachingthenameofavariabletoacharacterdatatype.
Thisoverridestheimplicationofdatatypingbytheinitialletterofasymbolicname.
Statements53SyntaxThesyntaxforCHARACTERhastwoforms,thestandardFortranformandthePGIextendedform.
Thissectiondescribesbothsyntaxforms.
CHARACTER[character-selector][,attribute-list::]entity-listcharacter-selectorthecharacterselectorspecifiesthelengthofthecharacterstring.
Thishasoneofseveralforms:([LEN=]type-param-value)*character-length[,]Character-selectoralsopermitsaKINDspecification.
RefertotheFortran95Handbookformoresyntaxdetails.
attribute-lististhelistofattributesforthecharactervariable.
entity-lististhelistofdefinedentities.
SyntaxExtension§CHARACTER[*len][,]name[dimension][*len][/clist/],.
.
.
lenisaconstantor*.
A*isonlyvalidifthecorrespondingnameisadummyargument.
nameisthesymbolicnameofavariable,array,oranarraydeclarator(seetheDIMENSIONstatementforanexplanationofarraydeclarators).
clistisalistofconstantsthatinitializethedata,asinaDATAstatement.
DescriptionCharactertypedeclarationstatementsmaybeusedtodimensionarraysexplicitlyinthesamewayastheDIMENSIONstatement.
Typedeclarationstatementsmustnotbelabeled.
Note:Thedatatypeofasymbolmaybeexplicitlydeclaredonlyonce.
Itisestablishedbytypedeclarationstatement,IMPLICITstatementorbypredefinedtypingrules.
Explicitdeclarationofatypeoverridesanyimplicitdeclaration.
AnIMPLICITstatementoverridespredefinedtypingrules.
FortranStatements54ExamplesCHARACTERA*4,B*6,CCHARACTER(LEN=10)::NAMEAis4andBis6characterslongandCis1characterlong.
NAMEis10characterslong.
CLOSE77TheCLOSEstatementterminatestheconnectionofthespecifiedfiletoaunit.
SyntaxCLOSE([UNIT=]u[,ERR=errs][,DISP[OSE]=sta][,IOSTAT=ios][,STATUS=sta])uistheexternalunitspecifierwhereuisaninteger.
errsisanerrorspecifierintheformofastatementlabelofanexecutablestatementinthesameprogramunit.
Ifanerrorconditionoccurs,executioncontinueswiththestatementspecifiedbyerrs.
iosisanintegerscalar;ifthisisincludediosbecomesdefinedwith0(zero)ifnoerrorconditionexistsorapositiveintegerwhenthereisanerrorcondition.
Avalueof-1indicatesanend-of-fileconditionwithnoerror.
Avalueof-2indicatesanend-of-recordconditionwithnoerrorwhenusingnon-advancingI/O.
staisacharacterexpression,wherecaseisinsignificant,specifyingthefilestatusandthesamekeywordsareusedforthedisposestatus.
Statuscanbe'KEEP'or'DELETE'(thequotesarerequired).
KEEPcannotbespecifiedforafilewhosedisposestatusisSCRATCH.
WhenKEEPisspecified(forafilethatexists)thefilecontinuestoexistaftertheCLOSEstatement;converselyDELETEdeletesthefileaftertheCLOSEstatement.
ThedefaultvalueisKEEPunlessthefilestatusisSCRATCH.
DescriptionAunitmaybethesubjectofaCLOSEstatementfromwithinanyprogramunit.
IftheunitspecifieddoesnotexistorhasnofileconnectedtoittheuseoftheCLOSEstatementhasnoeffect.
ProvidedthefileisstillinexistenceitmaybereconnectedtothesameoradifferentunitaftertheexecutionofaCLOSEstatement.
NotethatanimplicitCLOSEisexecutedwhenaprogramstops.
Statements55ExampleInthefollowingexample,thefileonUNIT6isclosedanddeleted.
CLOSE(UNIT=6,STATUS='DELETE')COMMON77TheCOMMONstatementdefinesglobalblocksofstoragethatareeithersequentialornonsequential.
TherearetwoformsoftheCOMMONstatement,astaticformandadynamicform.
EachcommonblockisidentifiedbythesymbolicnamedefinedintheCOMMONblock.
SyntaxCOMMON/[name]/nlist[,/name/nlist].
.
.
nameisthenameofeachcommonblockandisdeclaredbetweenthe/.
.
.
/delimitersforanamedcommonandwithnonameforablankcommon.
nlistisalistofvariablenameswherearraysmaybedefinedinDIMENSIONstatementsorformallydeclaredbytheirinclusionintheCOMMONblock.
CommonBlockRulesandBehaviorsAcommonblockisaglobalentity.
Anycommonblockname(orblankcommon)canappearmorethanonceinoneormoreCOMMONstatementsinaprogramunit.
Thefollowingisalistofrulesassociatedwithcommonblocks:BlankCommonThenameoftheCOMMONblockneednotbesupplied;withoutaname,thecommonisaBLANKCOMMON.
Inthiscasethecompilerusesadefaultname.
SameNamesTherecanbeseveralCOMMONblockstatementsofthesamenameinaprogramsegment;theseareeffectivelytreatedasonestatement,withvariablesconcatenatedfromoneCOMMONstatementofthesamenametothenext.
Thisisanalternativetotheuseofcontinuationlineswhendeclaringacommonblockwithmanysymbols.
CommonblockswiththesamenamethataredeclaredindifferentprogramunitssharethesamestorageareawhencombinedintooneexecutableprogramandtheyaredefinedusingtheSEQUENCEattribute.
FortranStatements56HPFInHPF,acommonblockisnon-sequentialbydefault,unlessthereisanexplicitSEQUENCEdirectivethatspecifiesthearrayassequential.
NotethismayrequirethatolderFORTRAN77programsassumingsequenceassociationinCOMMONstatementshaveSEQUENCEstatementsforCOMMONvariables.
ExampleDIMENSIONR(10)COMMON/HOST/A,R,Q(3),UThisdeclaresacommonblockcalledHOSTNoteThedifferenttypesofdeclarationusedforR(declaredinaDIMENSIONstatement)andQ(declaredintheCOMMONstatement).
ThedeclarationofHOSTinaSUBROUTINEinthesameexecutableprogram,withadifferentshapeforitselementswouldrequirethatthearraybedeclaredusingtheSEQUENCEattribute.
SUBROUTINEDEMO!
HPF$SEQUENCEHOSTCOMMON/HOST/STORE(15).
.
.
RETURNENDCommonBlocksandSubroutinesIfthemainprogramhasthecommonblockdeclarationasinthepreviousexample,theCOMMONstatementinthesubroutinecausesSTORE(1)tocorrespondtoA,STORE(2)tocorrespondtoR(1),STORE(3)tocorrespondtoR(2),andsoonthroughtoSTORE(15)correspondingtothevariableU.
CommonBlockRecordsandCharactersYoucannamerecordswithinaCOMMONblock.
Becausethestoragerequirementsofrecordsaremachine-dependent,thesizeofaCOMMONblockcontainingrecordsmayvarybetweenmachines.
NotethatthismayalsoaffectsubsequentequivalenceassociationstovariableswithinCOMMONblocksthatcontainrecords.
Statements57Bothcharacterandnon-characterdatamayresideinoneCOMMONblock.
DataisalignedwithintheCOMMONblockinordertoconformtomachine-dependentalignmentrequirements.
BlankCOMMONisalwayssaved.
BlankCOMMONmaybedatainitialized.
SeeAlsoTheSEQUENCEdirective.
SyntaxExtension–dynamicCOMMON§Adynamic,orallocatable,COMMONblockisacommonblockwhosestorageisnotallocateduntilanexplicitALLOCATEstatementisexecuted.
PGF77supportsdynamicCOMMONblocks,whilePGF95doesnot.
andPGHPFdonot.
IftheALLOCATABLEattributeispresent,allnamedCOMMONblocksappearingintheCOMMONstatementaremarkedasallocatable.
LikeanormalCOMMONstatement,thenameofanallocatableCOMMONblockmayappearinmorethanoneCOMMONstatement.
NotethattheALLOCATABLEattributeneednotappearineveryCOMMONstatement.
ThefollowingrestrictionsapplytothedynamicCOMMONstatement:BeforemembersofanallocatableCOMMONblockcanbereferenced,thecommonblockmusthavebeenexplicitlyallocatedusingtheALLOCATEstatement.
Thedatainanallocatablecommonblockcannotbeinitialized.
ThememoryusedforanallocatablecommonblockmaybefreedusingtheDEALLOCATEstatement.
IfaSUBPROGRAMdeclaresaCOMMONblocktobeallocatable,allothersubprogramscontainingCOMMONstatementsofthesameCOMMONblockmustalsodeclaretheCOMMONtobeallocatable.
Example(dynamicCOMMON)COMMON,ALLOCATABLE/ALL1/A,B,/ALL2/AA,BBCOMMON/STAT/D,/ALL1/CThisdeclaresthefollowingvariables:ALL1isanallocatableCOMMONblockwhosemembersareA,B,andC.
FortranStatements58ALL2isanallocatableCOMMONblockwhosemembersareAA,andBB.
STATisastatically-allocatedCOMMONblockwhoseonlymemberisD.
AreferencetoamemberofanallocatableCOMMONblockappearsinaFortranstatementjustlikeamemberofanormal(static)COMMONblock.
Nospecialsyntaxisrequiredtoaccessmembersofallocatablecommonblocks.
Forexample,usingtheabovedeclarations,thefollowingisavalidpgf77statement:AA=B*DCOMPLEX90TheCOMPLEXstatementestablishesthedatatypeofavariablebyexplicitlyattachingthenameofavariabletoacomplexdatatype.
Thisoverridestheimplicationofdatatypingbytheinitialletterofasymbolicname.
SyntaxThesyntaxforCOMPLEXhastwoforms,thestandardFortranformandthePGIextendedform.
Thissectiondescribesbothsyntaxforms.
COMPLEX[([KIND=]kind-value)][,attribute-list::]entity-listCOMPLEXpermitsaKINDspecification.
RefertotheFortran95Handbookformoresyntaxdetails.
attribute-lististhelistofattributesforthecharactervariable.
entity-lististhelistofdefinedentities.
SyntaxExtension§COMPLEXname[*n][dimensions][/clist/][,name][/clist/].
.
.
nameisthesymbolicnameofavariable,array,oranarraydeclarator(seetheDIMENSIONstatementbelowforanexplanationofarraydeclarators).
clistisalistofconstantsthatinitializethedata,asinaDATAstatement.
Statements59DescriptionCOMPLEXstatementsmaybeusedtodimensionarraysexplicitlyinthesamewayastheDIMENSIONstatement.
COMPLEXstatementsmustnotbelabeled.
NoteThedatatypeofasymbolmaybeexplicitlydeclaredonlyonce.
Itisestablishedbytypedeclarationstatement,IMPLICITstatementorbypredefinedtypingrules.
Explicitdeclarationofatypeoverridesanyimplicitdeclaration.
AnIMPLICITstatementoverridespredefinedtypingrules.
ExampleCOMPLEXCURRENTCOMPLEXDIMENSION(8)::CONV1,FLUX1ThedefaultsizeofaCOMPLEXvariableis8bytes.
Withthe-r8option,thedefaultsizeofaCOMPLEXvariableis16bytes.
CONTAINS90TheCONTAINSstatementprecedesasubprogram,afunctionorsubroutine,thatisdefinedinsideamainprogram,externalsubprogram,ormodulesubprogram(internalsubprogram).
TheCONTAINSstatementisaflagindicatingthepresenceofasubroutineorfunctiondefinition.
Aninternalsubprogramdefinesascopefortheinternalsubprogram'slabelsandnames.
Scopingisdefinedbyuseandhostscopingruleswithinscopingunits.
Scopingunitshavethefollowingprecedencefornames:Aderived-typedefinition.
Aprocedureinterfacebody.
Aprogramunitorasubprogram,excludingcontainedsubprograms.
SyntaxSUBROUTINEXINTEGERH,I.
.
.
CONTAINSSUBROUTINEYFortranStatements60INTEGERII=I+H.
.
ENDSUBROUTINEYENDSUBROUTINEXTypeNon-executableSeeAlsoMODULECONTINUE77TheCONTINUEstatementpassescontroltothenextstatement.
ItissuppliedmainlytoovercometheproblemthattransferofcontrolstatementsarenotallowedtoterminateaDOloop.
SyntaxCONTINUEExampleDO100I=1,10SUM=SUM+ARRAY(I)IF(SUM.
GE.
1000.
0)GOTO200100CONTINUE200.
.
.
CYCLE90TheCYCLEstatementinterruptsaDOconstructexecutionandcontinueswiththenextiterationoftheloop.
SyntaxCYCLE[do-construct-name]Statements61ExampleDOIF(A(I).
EQ.
0)CYCLEB=100/A(I)IF(B.
EQ.
5)EXITENDDOSeeAlsoEXIT,DODATA77TheDATAstatementassignsinitialvaluestovariablesbeforeexecution.
SyntaxDATAvlist/dlist/[[,]vlist/dlist/].
.
.
vlistisalistofvariablenames,arrayelementnamesorarraynamesseparatedbycommas.
dlistisalistofconstantsorPARAMETERconstants,separatedbycommas,correspondingtoelementsinthevlist.
Anarraynameinthevlistdemandsthatdlistconstantsbesuppliedtofilleveryelementofthearray.
Repetitionofaconstantisprovidedbyusingtheform:n*constant-valuenapositiveinteger,istherepetitioncount.
ExampleREALA,B,C(3),D(2)DATAA,B,C(1),D/1.
0,2.
0,3.
0,2*4.
0/Thisperformsthefollowinginitialization:A=1.
0B=2.
0C(1)=3.
0D(1)=4.
0D(2)=4.
0FortranStatements62DEALLOCATE77TheDEALLOCATEstatementcausesthememoryallocatedforeachpointer-basedvariableorallocatablearraythatappearsinthestatementtobedeallocated(freed).
Deallocatealsodeallocatesstoragefordeferred-shapearrays.
SyntaxDEALLOCATE(allocate-object-list[,STAT=var])Where:allocate-object-listisavariablenameorastructurecomponent.
alisapointer-basedvariableorthenameofanallocatableCOMMONblockenclosedinslashes.
varisthestatusindicator,anintegervariable,integerarrayelementoranintegermemberofastructure.
DescriptionAnattempttodeallocateapointer-basedvariableoranallocatableCOMMONblockwhichwasnotcreatedbyanALLOCATEstatementresultsinanerrorcondition.
IfthespecifierSTAT=ispresent,successfulexecutionofthestatementcausesvartobedefinedwiththevalueofzero.
IfanerroroccursduringtheexecutionofthestatementandthespecifierSTAT=ispresent,thestatusvariableisdefinedtohavetheintegervalueone.
IfanerroroccursandthespecifierSTAT=isnotpresent,programexecutionisterminated.
ExamplesREAL,ALLOCATABLE::X(:,:)ALLOCATE(X(10,2))X=0DEALLOCATE(X)COMMONP,N,MPOINTER(P,A(N,M))COMMON,ALLOCATABLE/ALL/X(10),YALLOCATE(/ALL/,A,STAT=IS)PRINT*,ISX(5)=A(2,1)Statements63DEALLOCATE(A)DEALLOCATE(A,STAT=IS)PRINT*,'shouldbe1',ISDEALLOCATE(/ALL/)DECODE§77TheDECODEstatementtransfersdatabetweenvariablesorarraysininternalstorageandtranslatesthatdatafromcharacterformtointernalform,accordingtoformatspecifiers.
SimilarresultscanbeaccomplishedusinginternalfileswithformattedsequentialREADstatements.
SyntaxDECODE(c,f,b[,IOSTAT=ios][,ERR=errs])[list]cisanintegerexpressionspecifyingthenumberofbytesinvolvedintranslation.
fistheformat-specifier.
bisascalarorarrayreferenceforthebufferareacontainingformatteddata(characters).
iosisanintegerscalarmemoryreferencewhichistheinput/outputstatusspecifier:ifthisisspecifiediosbecomesdefinedwithzeroifnoerrorconditionexistsorapositiveintegerwhenthereisanerrorcondition.
errsanerrorspecifierwhichtakestheformofastatementlabelofanexecutablestatementinthesameprogramunit.
Ifanerrorconditionoccursexecutioncontinueswiththestatementspecifiedbyerrs.
listisalistofinputitems.
Non-characterFormat-specifier§Ifaformat-specifierisavariablewhichisneitherCHARACTERnorasimpleINTEGERvariable,thecompileracceptsitandtreatsitasifthecontentswerecharacter.
Forexample,belowsumistreatedasaformatdescriptor:realsumsum=4h()acceptsumandisroughlyequivalenttoFortranStatements64character*4chch='()'acceptchSeeAlsoREAD,PRINTDIMENSION90TheDIMENSIONstatementdefinesthenumberofdimensionsinanarrayandthenumberofelementsineachdimension.
SyntaxDIMENSION[::]array-name(array-spec)[,array-name(array-spec)].
.
.
DIMENSIONarray-name([lb:]ub[,[lb:]ub].
.
.
)[,name([lb:]ub[,[lb:]ub].
.
.
)]array-nameisthesymbolicnameofanarray.
array-specisavalidarrayspecification,eitherexplicit-shape,assumed-shape,deferred-shape,orassumedsize(referfordetailsonarrayspecifications).
lb:ubisadimensiondeclaratorspecifyingtheboundsforadimension(thelowerboundlbandtheupperboundub).
lbandubmustbeintegerswithubgreaterthanlb.
Thelowerboundlbisoptional;ifitisnotspecified,itistakentobe1.
DescriptionDIMENSIONcanbeusedinasubroutinetoestablishanargumentasanarray,andinthiscasethedeclaratorcanuseexpressionsformedfromintegervariablesandconstantstoestablishthedimensions(adjustablearrays).
NotehoweverthattheseintegervariablesmustbeeitherargumentsordeclaredinCOMMON;theycannotbelocal.
InthiscasethefunctionofDIMENSIONismerelytosupplyamappingoftheargumenttothesubroutinecode,andnottoallocatestorage.
Statements65ThetypingofthearrayinaDIMENSIONstatementisdefinedbytheinitialletterofthearraynameinthesamewayasvariablenames.
ThelettersI,J,K,L,MandNimplythatthearrayisofINTEGERtypeandanarraywithanamestartingwithanyofthelettersAtoHandOtoZwillbeoftypeREAL,unlessoverriddenbyanIMPLICITortypedeclarationstatement.
ArraysmayappearintypedeclarationandCOMMONstatementsbutthearraynamecanappearinonlyonearraydeclaration.
DIMENSIONstatementsmustnotbelabeled.
ExamplesDIMENSIONARRAY1(3:10),ARRAY2(3,-2:2)ThisspecifiesARRAY1asavectorhavingeightelementswiththelowerboundof3andtheupperboundof10.
ARRAY2asamatrixoftwodimensionshavingfifteenelements.
Thefirstdimensionhasthreeelementsandthesecondhasfivewithboundsfrom-2to2.
CHARACTERB(0:20)*4ThisexamplesetsupanarrayBwith21characterelementseachhavingalengthoffourcharacters.
NotethatthecharacterarrayhasbeendimensionedinatypedeclarationstatementandthereforecannotsubsequentlyappearinaDIMENSIONstatement.
DO(Iterative)90TheDOstatementintroducesaniterativeloopandspecifiestheloopcontrolindexandparameters.
TherearetwoformsofDOstatement,blockandnon-block(FORTRAN77style).
Therearetwoformsofblockdostatements,DOiterativeandDOWHILE.
RefertothedescriptionofDOWHILEformoredetailsonthisformofDOstatement.
SyntaxDO(block)[do-construct-name:]DO[label][loop-control][execution-part-construct][label]ENDDOloop-controlisanincrementindexexpressionoftheform:[index=e1e2[,e3]]labellabelsthelastexecutablestatementintheloop(thismustnotbeatransferofcontrol).
FortranStatements66indexisthenameofavariablecalledtheDOvariable.
e1isanexpressionwhichyieldsaninitialvaluefori.
e2isanexpressionwhichyieldsafinalvaluefori.
e3isanoptionalexpressionyieldingavaluespecifyingtheincrementvaluefori.
Thedefaultfore3is1.
DO(non-block)DOlabel[,]index=e1,e2[,e3]labellabelsthelastexecutablestatementintheloop(thismustnotbeatransferofcontrol).
indexisthenameofavariablecalledtheDOvariable.
e1isanexpressionwhichyieldsaninitialvaluefori.
e2isanexpressionwhichyieldsafinalvaluefori.
e3isanoptionalexpressionyieldingavaluespecifyingtheincrementvaluefori.
Thedefaultfore3is1.
DescriptionTheDOloopconsistsofalltheexecutablestatementsafterthespecifyingDOstatementuptoandincludingthelabeledstatement,calledtheterminalstatement.
Thelabelisoptional.
Ifomitted,theterminalstatementoftheloopisanENDDOstatement.
BeforeexecutionofaDOloop,aniterationcountisinitializedfortheloop.
ThisvalueisthenumberoftimestheDOloopisexecuted,andis:INT((e2-e1+e3)/e3)Ifthevalueobtainedisnegativeorzerotheloopisnotexecuted.
TheDOloopisexecutedfirstwithitakingthevaluee1,thenthevalue(e1+e3),thenthevalue(e1+e3+e3),etc.
ItispossibletojumpoutofaDOloopandjumpbackin,aslongasthedoindexvariablehasnotbeenadjusted.
InanestedDOloop,itislegaltotransfercontrolfromaninnerlooptoanouterloop.
Itisillegal,however,totransferintoanestedloopfromoutsidetheloop.
Statements67SyntaxExtension§NestedDOloopsmaysharethesamelabeledterminalstatementifrequired.
TheymaynotshareanENDDOstatement.
ExamplesDO100J=-10,10DO100I=-5,5100SUM=SUM+ARRAY(I,J)DOA(I)=A(I)+1IF(A(I).
EQ.
4)EXITENDDODOI=1,NA(I)=A(I)+1ENDDODOWHILE77TheDOWHILEstatementintroducesalogicaldoloopandspecifiestheloopcontrolexpression.
TheDOWHILEstatementexecutesforaslongasthelogicalexpressioncontinuestobetruewhentestedatthebeginningofeachiteration.
Ifexpressionisfalse,controltransferstothestatementfollowingtheloop.
SyntaxDO[label[,]]WHILEexpressionTheendoftheloopisspecifiedinthesamewayasforaniterativeloop,eitherwithalabeledstatementoranENDDO.
labellabelsthelastexecutablestatementintheloop(thismustnotbeatransferofcontrol).
expressionisalogicalexpressionandlabel.
DescriptionThelogicalexpressionisevaluated.
Ifitis.
FALSE.
,theloopisnotentered.
Ifitis.
TRUE.
,theloopisexecutedonce.
Thenlogicalexpressionisevaluatedagain,andthecycleisrepeateduntiltheexpressionevaluates.
FALSE.
FortranStatements68ExampleDOWHILE(K==0)SUM=SUM+XENDDODOUBLECOMPLEX§77TheDOUBLECOMPLEXstatementestablishesthedatatypeofavariablebyexplicitlyattachingthenameofavariabletoadoublecomplexdatatype.
Thisoverridestheimplicationofdatatypingbytheinitialletterofasymbolicname.
SyntaxThesyntaxforDOUBLECOMPLEXhastwoforms,astandardFortran90/95entitybasedform,andthePGIextendedform.
Thissectiondescribesbothsyntaxforms.
DOUBLECOMPLEX[,attribute-list::]entity-listattribute-lististhelistofattributesforthedoublecomplexvariable.
entity-lististhelistofdefinedentities.
SyntaxExtension§DOUBLECOMPLEXname[/clist/][,name][/clist/].
.
.
nameisthesymbolicnameofavariable,array,oranarraydeclarator(seetheDIMENSIONstatementforanexplanationofarraydeclarators).
clistisalistofconstantsthatinitializethedata,asinaDATAstatement.
DescriptionTypedeclarationstatementsmaybeusedtodimensionarraysexplicitlyinthesamewayastheDIMENSIONstatement.
Typedeclarationstatementsmustnotbelabeled.
Note:Thedatatypeofasymbolmaybeexplicitlydeclaredonlyonce.
Itisestablishedbytypedeclarationstatement,IMPLICITstatementorbypredefinedtypingrules.
Explicitdeclarationofatypeoverridesanyimplicitdeclaration.
AnIMPLICITstatementoverridespredefinedtypingrules.
ThedefaultsizeofaDOUBLECOMPLEXvariableis16bytes.
Withthe-r8option,thedefaultsizeofaDOUBLECOMPLEXvariableisalso16bytes.
Statements69ExamplesDOUBLECOMPLEXCURRENT,NEXTDOUBLEPRECISION90TheDOUBLEPRECISIONstatementestablishesthedatatypeofavariablebyexplicitlyattachingthenameofavariabletoadoubleprecisiondatatype.
Thisoverridestheimplicationofdatatypingbytheinitialletterofasymbolicname.
SyntaxThesyntaxforDOUBLEPRECISIONhastwoforms,astandardFortran90/95entitybasedform,andthePGIextendedform.
Thissectiondescribesbothsyntaxforms.
DOUBLEPRECISION[,attribute-list::]entity-listattribute-lististhelistofattributesforthedoubleprecisionvariable.
entity-lististhelistofdefinedentities.
SyntaxExtension§DOUBLEPRECISIONname[/clist/][,name][/clist/].
.
.
nameisthesymbolicnameofavariable,array,oranarraydeclarator(seetheDIMENSIONstatementforanexplanationofarraydeclarators).
clistisalistofconstantsthatinitializethedata,asinaDATAstatement.
DescriptionTypedeclarationstatementsmaybeusedtodimensionarraysexplicitlyinthesamewayastheDIMENSIONstatement.
Typedeclarationstatementsmustnotbelabeled.
Note:Thedatatypeofasymbolmaybeexplicitlydeclaredonlyonce.
Itisestablishedbytypedeclarationstatement,IMPLICITstatementorbypredefinedtypingrules.
Explicitdeclarationofatypeoverridesanyimplicitdeclaration.
AnIMPLICITstatementoverridespredefinedtypingrules.
ThedefaultsizeofaDOUBLEPRECISIONvariableis8bytes.
ExampleDOUBLEPRECISIONPLONGFortranStatements70ELSE77TheELSEstatementbeginsanELSEblockofanIFblockandenclosesaseriesofstatementsthatareconditionallyexecuted.
SyntaxIFlogicalexpressionTHENstatementsELSEIFlogicalexpressionTHENstatementsELSEstatementsENDIFTheELSEsectionisoptionalandmayoccuronlyonce.
OtherIFblocksmaybenestedwithinthestatementssectionofanELSEblock.
ExampleIF(I.
LT.
15)THENM=4ELSEM=5ENDIFELSEIF77TheELSEIFstatementbeginsanELSEIFblockofanIFblockseriesandenclosesstatementsthatareconditionallyexecuted.
SyntaxIFlogicalexpressionTHENstatementsELSEIFlogicalexpressionTHENstatementsELSEstatementsENDIFTheELSEIFsectionisoptionalandmayberepeatedanynumberoftimes.
OtherIFblocksmaybenestedwithinthestatementssectionofanELSEIFblock.
Statements71ExampleIF(I.
GT.
70)THENM=1ELSEIF(I.
LT.
5)THENM=2ELSEIF(I.
LT.
16)THENM=3ENDIFELSEWHERE90TheWHEREstatementandtheWHEREELSEWHEREconstructpermitmaskedassignmentstotheelementsofanarray(ortoascalar,zerodimensionalarray).
SyntaxWHEREStatementWHERE(logical-array-expr)array-variable=array-exprWHEREConstructWHERE(logical-array-expr)array-assignments[ELSEWHEREarray-assignments]ENDWHEREExamplesINTEGERSCORE(30)CHARACTERGRADE(30)WHERE(SCORE>60)GRADE='P'WHERE(SCORE>60)GRADE='P'ELSEWHEREGRADE='F'ENDWHEREENCODE§77TheENCODEstatementtransfersdatabetweenvariablesorarraysininternalstorageandtranslatesthatdatafrominternaltocharacterform,accordingtoformatspecifiers.
SimilarresultscanbeaccomplishedusinginternalfileswithformattedsequentialWRITEstatements.
FortranStatements72SyntaxENCODE(c,f,b[,IOSTAT=ios][,ERR=errs])[list]cisanintegerexpressionspecifyingthenumberofbytesinvolvedintranslation.
fistheformat-specifier.
bisascalarorarrayreferenceforthebufferareareceivingformatteddata(characters).
iosisanintegerscalarmemoryreferencewhichistheinput/outputstatusspecifier:ifthisisincluded,iosbecomesdefinedwithzeroifnoerrorconditionexistsorapositiveintegerwhenthereisanerrorcondition.
errsanerrorspecifierwhichtakestheformofastatementlabelofanexecutablestatementinthesameprogram.
Ifanerrorconditionoccursexecutioncontinueswiththestatementspecifiedbyerrs.
listalistofoutputitems.
Non-characterFormat-specifier§Ifaformat-specifierisavariablewhichisneitherCHARACTERnorasimpleINTEGERvariable,thecompileracceptsitandtreatsitasifthecontentswerecharacter.
Forexample,belowsumistreatedasaformatdescriptor:realsumsum=4h()acceptsumandisroughlyequivalenttocharacter*4chch='()'acceptchSeeAlsoREAD,PRINTEND77TheENDstatementterminatesasegmentofaFortranprogram.
ThereareseveralvarietiesoftheENDstatement.
Eachisdescribedbelow.
Statements73ENDSyntaxENDDescriptionTheENDstatementterminatesamodule.
TheENDstatementhasthesameeffectasaRETURNstatementinaSUBROUTINEorFUNCTION,ortheeffectofaSTOPstatementinaPROGRAMprogramunit.
ENDmaybethelaststatementinacompilationoritmaybefollowedbyanewprogramunitormodule.
ENDDOSyntaxTheENDDOstatementterminatesaDOorDOWHILEloop.
ENDDODescriptionTheENDDOstatementterminatesanindexedDOorDOWHILEstatementwhichdoesnotcontainaterminal-statementlabel.
TheENDDOstatementmayalsobeusedasalabeledterminalstatementiftheDOorDOWHILEstatementcontainsaterminal-statementlabel.
ENDFILESyntaxENDFILEuENDFILE([UNIT=]u,[,IOSTAT=ios][,ERR=errs])uistheexternalunitspecifierwhereuisaninteger.
IOSTAT=iosanintegerscalarmemoryreferencewhichistheinput/outputspecifier:ifthisisincludedinlist,iosbecomesdefinedwithzeroifnoerrorconditionexistsorapositiveintegerwhenthereisanerrorcondition.
ERR=errsanerrorspecifierwhichtakestheformofastatementlabelofanexecutablestatementinthesameprogram.
Ifanerrorconditionoccursexecutioncontinueswiththestatementspecifiedbyerrs.
FortranStatements74DescriptionWhenanENDFILEstatementisexecutedanendfilerecordiswrittentothefileasthenextrecord.
Thefileisthenpositionedaftertheendfilerecord.
Notethatonlyrecordswrittenpriortotheendfilerecordcanbereadlater.
ABACKSPACEorREWINDstatementmustbeusedtorepositionthefileafteranENDFILEstatementpriortotheexecutionofanydatatransferstatement.
AfileiscreatedifthereisanENDFILEstatementforafileconnectedbutnotinexistence.
Forexample:ENDFILE(20)ENDFILE(UNIT=34,IOSTAT=IOERR,ERR=140)ENDIFSyntaxTheENDIFstatementterminatesanIFELSEorELSEIFblock.
SyntaxENDIFDescriptionTheENDIFstatementterminatesanIFblock.
TheremustbeamatchingblockIFstatement(atthesameIFlevel)earlierinthesamesubprogram.
SyntaxExtension–ENDMAP§ENDMAPSyntaxTheENDMAPstatementterminatesaMAPdeclaration.
SyntaxENDMAPDescriptionSeetheMAPstatementfordetails.
ENDSELECTSyntaxTheENDSELECTstatementterminatesaSELECTdeclaration.
Statements75SyntaxENDSELECTExampleSELECTCASE(FLAG)CASE(1,2,3)TYPE=1CASE(4:6)TYPE=2CASEDEFAULTTYPE=0ENDSELECTSyntaxExtension–ENDSTRUCTURE§ENDSTRUCTURESyntaxTheENDSTRUCTUREstatementterminatesaSTRUCTUREdeclaration.
SyntaxENDSTRUCTUREDescriptionSeetheSTRUCTUREstatementfordetails.
SyntaxExtension–ENDUNION§ENDUNIONTheENDUNIONstatementterminatesaUNIONdeclaration.
SyntaxENDUNIONDescriptionSeetheUNIONstatementfordetails.
ENTRY77TheENTRYstatementallowsasubroutineorfunctiontohavemorethanoneentrypoint.
FortranStatements76SyntaxENTRYname[(variable,variable.
.
.
)]nameisthesymbolicname,orentryname,bywhichthesubroutineorfunctionmaybereferenced.
variableisadummyargument.
Adummyargumentmaybeavariablename,arrayname,dummyprocedureor,iftheENTRYisinasubroutine,analternatereturnargumentindicatedbyanasterisk.
Iftherearenodummyargumentsnamemayoptionallybefollowedby().
TheremaybemorethanoneENTRYstatementwithinasubroutineorfunction,buttheymustnotappearwithinablockIForDOloop.
DescriptionThenameofanENTRYmustnotbeusedasadummyargumentinaFUNCTION,SUBROUTINEorENTRYstatement,normayitappearinanEXTERNALstatement.
WithinafunctionavariablenamewhichisthesameastheentrynamemaynotappearinanystatementthatprecedestheENTRYstatement,exceptinatypestatement.
Ifnameisoftypecharacterthenamesofeachentryinthefunctionandthefunctionnamemustbeoftypecharacter.
Ifthefunctionnameoranyentrynamehasalengthof(*)allsuchnamesmusthavealengthof(*);otherwisetheymustallhavealengthspecificationofthesameintegervalue.
AnamewhichisusedasadummyargumentmustnotappearinanexecutablestatementprecedingtheENTRYstatementunlessitalsoappearsinaFUNCTION,SUBROUTINEorENTRYstatementthatprecedestheexecutablestatement.
Neithermustitappearintheexpressionofastatementfunctionunlessthenameisalsoadummyargumentofthestatementfunction,orappearsinaFUNCTIONorSUBROUTINEstatement,orinanENTRYstatementthatprecedesthestatementfunctionstatement.
Ifadummyargumentappearsinanexecutablestatement,executionofthatstatementisonlypermittedduringtheexecutionofareferencetothefunctionorsubroutineifthedummyargumentappearsinthedummyargumentlistoftheprocedurenamereferenced.
Whenasubroutineorfunctioniscalledusingtheentryname,executionbeginswiththestatementimmediatelyfollowingtheENTRYstatement.
Ifafunctionentryhasnodummyargumentsthefunctionmustbereferencedbyname()butasubroutineentrywithoutdummyargumentsmaybecalledwithorwithouttheparenthesesaftertheentryname.
Statements77Anentrymaybereferencedfromanyprogramunitexcepttheoneinwhichitisdefined.
Theorder,type,numberandnamesofdummyargumentsinanENTRYstatementcanbedifferentfromthoseusedintheFUNCTION,SUBROUTINEorotherENTRYstatementsinthesameprogramunitbuteachreferencemustuseanactualargumentlistwhichagreesinorder,numberandtypewiththedummyargumentlistofthecorrespondingFUNCTION,SUBROUTINEorENTRYstatement.
Whenasubroutinenameoranalternatereturnspecifierisusedasanactualargumentthereisnoneedtomatchthetype.
EntrynameswithinaFUNCTIONsubprogramneednotbeofthesamedatatypeasthefunctionname,buttheyallmustbeconsistentwithinoneofthefollowinggroupsofdatatypes:BYTE,INTEGER*2,INTEGER*4,LOGICAL*1,LOGICAL*2,LOGICAL*4,REAL*4,REAL*8,COMPLEX*8COMPLEX*16CHARACTERIfthefunctionisofcharacterdatatype,allentrynamesmustalsohavethesamelengthspecificationasthatofthefunction.
ExampleFUNCTIONSUM(TALL,SHORT,TINY).
SUM=TALL-(SHORT+TINY)RETURNENTRYSUM1(X,LONG,TALL,WIDE,NARROW).
.
SUM1=(X*LONG)+(TALL*WIDE)+NARROWRETURNENTRYSUM2(SHORT,SMALL,TALL,WIDE).
.
SUM2=(TALL-SMALL)+(WIDE-SHORT)RETURNENDWhenthecallingprogramcallsthefunctionSUMitcandosoinoneofthreewaysdependingonwhichENTRYpointisdesired.
Forexampleifthecallis:FortranStatements78Z=SUM2(LITTLE,SMALL,BIG,HUGE)theENTRYpointisSUM2.
Ifthecallis:Z=SUM(T,X,Y)theENTRYpointisSUMandsoon.
EQUIVALENCE77TheEQUIVALENCEstatementallowstwoormorenamedregionsofdatamemorytosharethesamestartaddress.
ArraysthataresubjecttotheEQUIVALENCEstatementinHPFaretreatedassequentialandanyattemptatnon-replicateddatadistributionormappingisignoredforsucharrays.
SyntaxEQUIVALENCE(list)[,(list).
.
.
]listisasetofidentifiers(variables,arraysorarrayelements)whicharetobeassociatedwiththesameaddressindatamemory.
Theitemsinalistareseparatedbycommas,andtheremustbeatleasttwoitemsineachlist.
Whenanarrayelementischosen,thesubscriptsmustbeintegerconstantsorintegerPARAMETERconstants.
DescriptionThestatementcanbeusedtomakeasingleregionofdatamemoryhavedifferenttypes,sothatforinstancetheimaginarypartofacomplexnumbercanbetreatedasarealvalue.
Itcanalsobeusedtomakearraysoverlap,sothatthesameregionofstorecanbedimensionedinseveraldifferentways.
RecordsandrecordfieldscannotbespecifiedinEQUIVALENCEstatements.
SyntaxExtension§AnarrayelementmaybeidentifiedwithasinglesubscriptinanEQUIVALENCEstatementeventhoughthearrayisdefinedtobeamultidimensionalarray.
Also,EQUIVALENCEofcharacterandnon-characterdataisallowedaslongasmisalignmentofnon-characterdatadoesnotoccur.
ExampleCOMPLEXNUMREALQWER(2)EQUIVALENCE(NUM,QWER(1))Statements79Intheaboveexample,QWER(1)istherealpartofNUMandQWER(2)istheimaginarypart.
EQUIVALENCEstatementsareillegalifthereisanyattempttomakeamappingofdatamemoryinconsistentwithitslinearlayout.
EXIT90TheEXITstatementinterruptsaDOconstructexecutionandcontinueswiththenextstatementaftertheloop.
SyntaxEXIT[do-construct-name]ExampleDOIF(A(I).
EQ.
0)CYCLEB=100/A(I)IF(B.
EQ.
5)EXITENDDOSeeAlsoCYCLE,DOEXTERNAL77TheEXTERNALstatementidentifiesasymbolicnameasanexternalordummyprocedure.
Thisprocedurecanthenbeusedasanactualargument.
SyntaxEXTERNALproc[,proc].
.
procisthenameofanexternalprocedure,dummyprocedureorblockdataprogramunit.
WhenanexternalordummyprocedurenameisusedasanactualargumentinaprogramunititmustappearinanEXTERNALstatementinthatprogramunit.
DescriptionIfanintrinsicfunctionappearsinanEXTERNALstatementanintrinsicfunctionofthesamenamecannotthenbereferencedintheprogramunit.
AsymbolicnamecanappearonlyonceinalltheEXTERNALstatementsofaprogramunit.
FortranStatements80EXTRINSICHPFTheEXTRINSICstatementidentifiesasymbolicnameasanexternalordummyprocedurethatiswritteninsomelanguageotherthanHPF.
SyntaxEXTRINSIC(extrinsic-kind-keyword)procedurenameextrinsic-kind-keywordisthenameofanextrinsicinterfacesupported.
ThecurrentlysupportedvalueisF77_LOCAL.
procedurenameiseitherasubroutine-statementorafunction-statementdefininganameforanexternalandextrinsicprocedure.
DescriptionTheEXTRINSICprocedurecanthenbeusedasanactualargumentonceitisdefined.
ThecalltoanEXTRINSICprocedureshouldbesemanticallyequivalenttotheexecutionofanHPFprocedureinthatonreturnfromtheprocedure,allprocessorsarestillavailable,andalldataandtemplateswillhavethesamedistributionandalignmentaswhentheprocedurewascalled.
SeeAlsoForacompletedescriptionofthePGHPFextrinsicfacility,alongwithexamples,refertothePGHPFUser'sGuide.
FORALLF95TheFORALLstatementandtheFORALLconstructprovideaparallelmechanismtoassignvaluestotheelementsofanarray.
SyntaxFORALL(forall-triplet-spec-list[,scalar-mask-expr])forall-assignmentorFORALL(forall-triplet-spec-list[,scalar-mask-expr])forall-body[forall-body].
.
.
ENDFORALLStatements81whereforall-bodyisoneof:forall-assignmentwhere-statementwhere-constructforall-statementforall-constructDescriptionTheFORALLstatementiscomputedinfourstages:First,computethevalidsetofindexvalues.
Second,computetheactivesetofindexvalues,takingintoconsiderationthescalar-mask-expr.
Ifnoscalar-mask-exprispresent,thevalidsetisthesameastheactivesetofindexvalues.
Third,foreachindexvalue,theright-handsideofthebodyoftheFORALLiscomputed.
Finally,theright-handsideisassignedtotheleft-handside,foreachindexvalue.
ExamplesFORALL(I=1:3)A(I)=B(I)FORALL(I=1:L,A(I)==0.
0)A(I)=R(I)FORALL(I=1:3)A(I)=D(I)B(I)=C(I)*2ENDFORALLFORALL(I=1:5)WHERE(A(I,:)/=0.
0)A(I,:)=A(I-1,:)+A(I+1,:)ELSEWHEREB(I,:)=A(6-I,:)ENDWHEREENDFORALLFORMAT77TheFORMATstatementspecifiesformatrequirementsforinputoroutput.
SyntaxlabelFORMAT(list-items)list-itemscanbeanyofthefollowing,separatedbycommas:Repeatableeditorcommandswhichmayormaynotbeprecededbyanintegerconstantwhichdefinesthenumberofrepeats.
FortranStatements82Nonrepeatableeditorcommands.
Aformatspecificationlistoptionallyprecededbyanintegerconstantwhichdefinesthenumberofrepeats.
Eachactionofformatcontroldependsonthenexteditcodeandthenextitemintheinput/outputlistwhereoneisused.
Ifaninput/outputlistcontainsatleastoneitemtheremustbeatleastonerepeatableeditcodeintheformatspecification.
Anemptyformatspecification()canonlybeusedifnolistitemsarespecified;insuchacaseoneinputrecordisskippedoranoutputrecordcontainingnocharactersiswritten.
Unlesstheeditcodeortheformatlistisprecededbyarepeatspecification,aformatspecificationisinterpretedfromlefttoright.
Wherearepeatspecificationisusedtheappropriateitemisrepeatedtherequirednumberoftimes.
DescriptionRefertoformoredetailsonusingtheFORMATstatement.
ExamplesWRITE(6,90)NPAGE90FORMAT('1PAGENUMBER',I2,16X,'SALESREPORT,Cont.
')produces:PAGENUMBER10SALESREPORT,Cont.
ThefollowingexampleshowsuseofthetabulationspecifierT:PRINT2525FORMAT(T41,'COLUMN2',T21,'COLUMN1')produces:COLUMN1COLUMN2DIMENSIONA(6)DO10I=1,610A(I)=25.
TYPE100,A100FORMAT('',F8.
2,2PF8.
2,F8.
2)!
''C!
givessinglespacingproduces:Statements8325.
002500.
002500.
002500.
002500.
002500.
00Notethattheeffectofthescalefactorcontinuesuntilanotherscalefactorisused.
Non-characterFormat-specifier§Ifaformat-specifierisavariablewhichisneitherCHARACTERnorasimpleINTEGERvariable,thecompileracceptsitandtreatsitasifthecontentswerecharacter.
Forexample,belowsumistreatedasaformatdescriptor:realsumsum=4h()acceptsumandisroughlyequivalenttocharacter*4chch='()'acceptchSeeAlsoREAD,PRINTFUNCTION77TheFUNCTIONstatementintroducesaprogramunit;thestatementsthatfollowallapplytothefunctionitselfandarelaidoutinthesameorderasthoseinaPROGRAMprogramunit.
Syntax[function-prefix]FUNCTIONname[*n]([argument[,argument].
.
.
]).
.
.
END[FUNCTION[function-name]]function-prefixisoneof:[type-spec]RECURSIVE[RECURSIVE]type-specFortranStatements84wheretype-specisavalidtypespecification.
Typewillexplicitlyapplyatypetothefunction.
Ifthefunctionisnotexplicitlytypedthenthefunctiontypeistakenfromtheinitialletterandisdictatedbytheusualdefault.
nameisthenameofthefunctionandmustbeuniqueamongalltheprogramunitnamesintheprogram.
namemustnotclashwithanylocal,COMMONorPARAMETERnames.
*nistheoptionallengthofthedatatype.
argumentisasymbolicname,startingwithaletterandcontainingonlylettersanddigits.
AnargumentcanbeoftypeREAL,INTEGER,DOUBLEPRECISION,CHARACTER,LOGICAL,COMPLEX,orBYTE,etc.
DescriptionThestatementsandnamesapplyonlytothefunction,exceptforsubroutineorfunctionreferencesandthenamesofCOMMONblocks.
ThefunctionmustbeterminatedbyanENDstatement.
Afunctionproducesaresult;thisallowsafunctionreferencetoappearinanexpression,wheretheresultisassumedtoreplacetheactualreference.
Thesymbolicnameofthefunctionmustappearasavariableinthefunction,unlesstheRESULTkeywordisused.
Thevalueofthisvariable,onexitfromthefunction,istheresultofthefunction.
Thefunctionresultisundefinedifthevariablehasnotbeendefined.
ThetypeofaFUNCTIONreferstothetypeofitsresult.
Recursionisallowedifthe–Mrecursiveoptionisusedonthecommand-lineandtheRECURSIVEprefixisincludedinthefunctiondefinition.
ExamplesFUNCTIONFRED(A,B,C)REALX.
ENDFUNCTIONEMPTY()!
NoteparenthesesENDPROGRAMFUNCALL.
SIDE=TOTAL(A,B,C).
Statements85ENDFUNCTIONTOTAL(X,Y,Z).
ENDFUNCTIONAORB(A,B)IF(A-B)1,2,31AORB=ARETURN2AORB=BRETURN3AORB=A+BRETURNENDSeeAlsoPURE,RECURSIVE,RESULTGOTO(Assigned)(Obsolescent)TheassignedGOTOstatementtransferscontrolsothatthestatementidentifiedbythestatementlabelisexecutednext.
InternalprocedurescanbeusedinplaceoftheassignstatementusedwithanassignedGOTO.
SyntaxGOTOinteger-variable-name[[,](list)]integer-variable-namemustbedefinedwiththevalueofastatementlabelofanexecutablestatementwithinthesameprogramunit.
ThistypeofdefinitioncanonlybedonebytheASSIGNstatement.
listconsistsofoneormorestatementlabelsattachedtoexecutablestatementsinthesameprogramunit.
Ifalistofstatementlabelsispresent,thestatementlabelassignedtotheintegervariablemustbeinthatlist.
FortranStatements86ExamplesASSIGN50TOKGOTOK(50,90)90G=D**5.
.
50F=R/TGOTO(Computed)77ThecomputedGOTOstatementallowstransferofcontroltooneofalistoflabelsaccordingtothevalueofanexpression.
SyntaxGOTO(list)[,]expressionlistisalistoflabelsseparatedbycommas.
expressionselectsthelabelfromthelisttowhichtotransfercontrol.
Thusavalueof1impliesthefirstlabelinthelist,avalueof2impliesthesecondlabelandsoon.
AnexpressionvalueoutsidetherangewillresultintransferofcontroltothestatementfollowingthecomputedGOTOstatement.
ExampleREAD*,A,BGOTO(50,60,70)AWRITE(*,10)A,B10FORMAT('',I3,F10.
4,5X,'Amustbe1,2+or3')STOP50X=A**B!
ComehereifAhasthevalue1GOTO10060X=(A*56)*(B/3)!
ComehereifAis2GOTO10070X=A*B!
ComehereifAhasthevalue3100WRITE(*,20)A,B,X20FORMAT('',I3,F10.
4,5X,F10.
4)Statements87GOTO(Unconditional)77TheGOTOstatementunconditionallytransferscontroltothestatementwiththelabellabel.
ThestatementlabellabelmustbedeclaredwithinthecodeoftheprogramunitcontainingtheGOTOstatementandmustbeuniquewithinthatprogramunit.
SyntaxGOTOlabellabelisastatementlabelExampleTOTAL=0.
030READ*,XIF(X.
GE.
0)THENTOTAL=TOTAL+XGOTO30ENDIFIF(Arithmetic)77(Obsolescent)ThearithmeticIFstatementtransferscontroltooneofthreelabeledstatements.
Thestatementchosendependsuponthevalueofanarithmeticexpression.
SyntaxIF(arithmetic-expression)label-1,label-2,label-3Controltransferstolabel-1,label-2orlabel-3iftheresultoftheevaluationofthearithmetic-expressionislessthanzero,equaltozeroorgreaterthanzerorespectively.
ExampleIFX10,20,30IfXislessthanzerothencontrolistransferredtolabel10.
IfXequalszerothencontrolistransferredtolabel20.
IfXisgreaterthanzerothencontrolistransferredtolabel30.
IF(Block)77TheblockIFstatementconsistsofaseriesofstatementsthatareconditionallyexecuted.
FortranStatements88SyntaxIFlogicalexpressionTHENstatementsELSEIFlogicalexpressionTHENstatementsELSEstatementsENDIFTheELSEIFsectionisoptionalandmayberepeatedanynumberoftimes.
OtherIFblocksmaybenestedwithinthestatementssectionofanELSEIFblock.
TheELSEsectionisoptionalandmayoccuronlyonce.
OtherIFblocksmaybenestedwithinthestatementssectionofanELSEblock.
ExampleIF(I.
GT.
70)THENM=1ELSEIF(I.
LT.
5)THENM=2ELSEIF(I.
LT.
16)THENM=3ENDIFIF(I.
LT.
15)THENM=4ELSEM=5ENDIFIF(Logical)77ThelogicalIFstatementexecutesordoesnotexecuteastatementbasedonthevalueofalogicalexpression.
SyntaxIF(logical-expression)statementlogical-expressionisevaluatedandifitistruethestatementisexecuted.
Ifitisfalse,thestatementisnotexecutedandcontrolispassedtothenextexecutablestatement.
Statements89statementcanbeanassignmentstatement,aCALLstatementoraGOTOstatement.
ExamplesIF(N.
LE.
2)GOTO27IF(HIGH.
GT.
1000.
0.
OR.
HIGH.
LT.
0.
0)HIGH=1000.
0IMPLICIT77TheIMPLICITstatementredefinestheimplieddatatypeofsymbolicnamesfromtheirinitialletter.
WithouttheuseoftheIMPLICITstatementallnamesthatbeginwiththelettersI,J,K,L,MorNareassumedtobeoftypeintegerandallnamesbeginningwithanyotherlettersareassumedtobereal.
SyntaxIMPLICITspec(a[,a].
.
.
)[,spec(a[,a].
.
.
)]IMPLICITNONEspecisadatatypespecifier.
aisanalphabeticspecificationexpressedeitherasaora1-a2,specifyinganalphabeticallyorderedrangeofletters.
DescriptionIMPLICITstatementsmustnotbelabeled.
Symbolnamesmaybeginwithadollarsign($)orunderscore(_)character,bothofwhichareoftypeREALbydefault.
InanIMPLICITstatement,thesecharactersmaybeusedinthesamemannerasothercharacters,buttheycannotbeusedinarangespecification.
TheIMPLICITNONEstatementspecifiesthatallsymbolicnamesmustbeexplicitlydeclared,otherwiseanerrorisreported.
IfIMPLICTNONEisused,nootherIMPLICITcanbepresent.
ExamplesIMPLICITREAL(L,N)IMPLICITINTEGER(S,W-Z)IMPLICITINTEGER(A-D,$,_)FortranStatements90INCLUDE§77TheINCLUDEstatementdirectsthecompilertostartreadingfromanotherfile.
NoteTheINCLUDEstatementisusedforFORTRAN77.
ThereisnosupportforVAX/VMStextlibrariesorthemodule_namepathnamequalifierthatexistsintheVAX/VMSversionoftheINCLUDEstatement.
SyntaxINCLUDE'filename[/[NO]LIST]'INCLUDE"filename[/[NO]LIST]"TheINCLUDEstatementmaybenestedtoadepthof20andcanappearanywherewithinaprogramunitaslongasFortran'sstatement-orderingrestrictionsarenotviolated.
§Thequalifiers/LISTand/NOLISTcanbeusedtocontrolwhethertheincludefileisexpandedinthelistingfile(ifgenerated).
Eithersingleordoublequotesmaybeused.
Ifthefinalcomponentofthefilepathnameis/LISTor/NOLIST,thecompilerwillassumeitisaqualifier,unlessanadditionalqualifierissupplied.
Thefilenameandthe/LISTor/NOLISTqualifiermaybeseparatedbyblanks.
Theincludefileissearchedforinthefollowingdirectories:Each–Idirectoryspecifiedonthecommand-line.
ThedirectorycontainingthefilethatcontainstheINCLUDEstatement(thecurrentworkingdirectory.
)Thestandardincludearea.
ExampleINCLUDE'/mypath/list/list'Thislineincludesafilenamed/mypath/listandexpandsitinthelistingfile,ifalistingfileisused.
Statements91INQUIRE77AnINQUIREstatementhastwoformsandisusedtoinquireaboutthecurrentpropertiesofaparticularfileorthecurrentconnectionsofaparticularunit.
INQUIREmaybeexecutedbefore,duringorafterafileisconnectedtoaunit.
SyntaxINQUIRE(FILE=filename,list)INQUIRE([UNIT=]unit,list)Inadditionlistmaycontainoneofeachofthefollowingspecifiersinanyorder,followingtheunitnumberiftheoptionalUNITspecifierkeywordisnotsupplied.
ACCESS=accaccreturnsacharacterexpressionspecifyingtheaccessmethodforthefileaseitherDIRECTorSEQUENTIAL.
ThedefaultisSEQUENTIAL.
ACTION=accaccisacharacterexpressionspecifyingtheaccesstypesfortheconnection.
EitherREAD,WRITE,orREADWRITE.
BLANK=blnkblnkisacharacterexpressionwhichreturnsthevalueNULLorZEROorUNDEFINED.
NULLcausesallblankcharactersinnumericformattedinputfieldstobeignoredwiththeexceptionofanall-blankfieldwhichhasavalueofzero.
ZEROcausesallblanksotherthanleadingblankstobetreatedaszeros.
Thisspecifiermustonlybeusedwhenafileisconnectedforformattedinput/output.
DELIM=del_chardel_charisacharacterexpressionwhichreturnsthevalueAPOSTROPHE,QUOTE,NONEorUNDEFINED.
Thesevaluesspecifythecharacterdelimiterforlist-directedornamelistformatteddatatransferstatements.
DIRECT=dir_chardir_charisacharacterreferencewhichreturnsthevalueYESifDIRECTisoneoftheallowedaccessmethodsforthefile,NOifnotandUNKNOWNifitisnotknownifDIRECTisincluded.
ERR=errserrsisanerrorspecifierwhichreturnsthevalueofastatementlabelofanexecutablestatementwithinthesameprogram.
Ifanerrorconditionoccursexecutioncontinueswiththestatementspecifiedbyerrs.
FortranStatements92EXIST=valuevalueisalogicalvariableorlogicalarrayelementwhichbecomes.
TRUE.
ifthereisafile/unitwiththenameor.
FALSE.
otherwise.
FILE=finfinisacharacterexpressionwhosevalueisthefilenameexpression,thenameofthefileconnectedtothespecifiedunit.
FORM=fmfmisacharacterexpressionspecifyingwhetherthefileisbeingconnectedforFORMATTEDorUNFORMATTEDinput/output.
ThedefaultisUNFORMATTED.
FORMATTED=fmtfmtisacharactermemoryreferencewhichtakesthevalueYESifFORMATTEDisoneoftheallowedaccessmethodsforthefile,NOifnotandUNKNOWNifitisnotknownifFORMATTEDisincluded.
IOSTAT=iosiosinput/outputstatusspecifierwhereiosisanintegerreference:ifthisisincludedinlist,iosisdefinedas0ifnoerrorconditionoccurredandapositiveintegerwhenthereisanerrorcondition.
NAME=fnfnisacharacterscalarmemoryreferencewhichisassignedthenameofthefilewhenthefilehasaname,otherwiseitisundefinedNAMED=nmdnmdisalogicalscalarmemoryreferencewhichbecomes.
TRUE.
ifthefilehasaname,otherwiseitbecomes.
FALSE.
NEXTREC=nrnrisanintegerscalarmemoryreferencewhichisassignedthevaluen+1,wherenisthenumberoftherecordreadorwritten.
Ittakesthevalue1ifnorecordshavebeenreadorwritten.
Ifthefileisnotconnectedoritspositionisindeterminatenrisundefined.
NUMBER=numnumisanintegerscalarmemoryreferenceorintegerarrayelementassignedthevalueoftheexternalunitnumberofthecurrentlyconnectedunit.
Itbecomesundefinedifnounitisconnected.
OPENED=ododisalogicalscalarmemoryreferencewhichbecomes.
TRUE.
ifthefile/unitspecifiedisconnected(open)and.
FALSE.
ifthefileisnotconnected(.
FALSE.
).
PAD=pad_charpad_charisacharacterexpressionspecifyingwhethertouseblankpadding.
Valuesforpad_charareYESorNO:yesspecifiesblankpaddingisused,norequiresthatinputrecordscontainallrequesteddata.
Statements93POSITION=pos_charpos_charisacharacterexpressionspecifyingthefileposition.
ValuesareASIS,REWINDorAPPEND.
Foraconnectedfile,onOPENASISleavesthepositioninthecurrentposition,REWINDrewindsthefileandAPPENDplacesthecurrentpositionattheendofthefile,immediatelybeforetheend-of-filerecord.
READ=rlrlisacharacterreferencewhichtakesthevalueYESifUNFORMATTEDisoneoftheallowedaccessmethodsforfile,NOifnot,orUNKNOWNifitisnotknownifUNFORMATTEDisincluded.
READWRITE=rlrlisacharacterscalarmemoryreferencewhichtakesthevalueYESifUNFORMATTEDisoneoftheallowedaccessmethodsforthefile,NOifnotandUNKNOWNifitisnotknownifUNFORMATTEDisincluded.
RECL=rcllrclisanintegerexpressiondefiningtherecordlengthinafileconnectedfordirectaccess.
Whensequentialinput/outputisspecifiedthisisthemaximumrecordlength.
Thisspecifiermustonlybegivenwhenafileisconnectedfordirectaccess.
SEQUENTIAL=seqseqacharacterscalarmemoryreferencewhichtakesthevalueYESifUNFORMATTEDisoneoftheallowedaccessmethodsforthefile,NOifnotandUNKNOWNifitisnotknownifUNFORMATTEDisincluded.
UNFORMATTED=unfunfacharacterscalarmemoryreferencewhichtakesthevalueYESifUNFORMATTEDisoneoftheallowedaccessmethodsforthefile,NOifnotandUNKNOWNifitisnotknownifUNFORMATTEDisincluded.
WRITE=rlrlacharacterscalarmemoryreferencewhichtakesthevalueYES,NO,orUNKNOWN.
ThesevaluesindicatethatWRITEisallowed,notallowed,orindeterminateforthespecifiedfile,respectively.
DescriptionWhenanINQUIREbyfilestatementisexecutedthefollowingspecifierswillonlybeassignedvaluesifthefilenameisacceptable:nmd,fn,seq,dir,fmtandunf.
numisdefined,andacc,fm,rcl,nrandblnkmaybecomedefinedonlyifodisdefinedas.
TRUE.
.
WhenanINQUIREbyunitstatementisexecutedthespecifiersnum,nmd,fn,acc,seq,dir,fm,fmt,unf,rcl,nrandblnkareassignedvaluesprovidedthattheunitexistsandafileisconnectedtothatunit.
ShouldanerrorconditionoccurduringtheexecutionofanINQUIREstatementallthespecifiersexceptiosbecomeundefined.
FortranStatements94INTEGER77TheINTEGERstatementestablishesthedatatypeofavariablebyexplicitlyattachingthenameofavariabletoanintegerdatatype.
Thisoverridestheimplicationofdatatypingbytheinitialletterofasymbolicname.
SyntaxThesyntaxforINTEGERhastwoforms,astandardFORTRAN77or90/95attributedform,andthePGIextendedform.
Thissectiondescribesbothsyntaxforms.
INTEGER[([KIND=kind-value)][,attribute-list::]entity-listINTEGERpermitsaKINDspecification.
RefertotheFortran95Handbookformoresyntaxdetails.
attribute-lististhelistofattributesforthecharactervariable.
entity-lististhelistofdefinedentities.
SyntaxExtension§INTEGER[*n][,]name[*n][dimensions][/clist/].
.
.
nisanoptionalsizespecification.
nameisthesymbolicnameofavariable,array,oranarraydeclarator(seetheDIMENSIONstatementforanexplanationofarraydeclarators).
clistisalistofconstantsthatinitializethedata,asinaDATAstatement.
DescriptionIntegertypedeclarationstatementsmaybeusedtodimensionarraysexplicitlyinthesamewayastheDIMENSIONstatement.
INTEGERstatementsmustnotbelabeled.
ThedefaultsizeofanINTEGERvariableis4bytes.
Withthe-Mnoi4option,thedefaultsizeofanINTEGERvariableis2bytes.
NoteThedatatypeofasymbolmaybeexplicitlydeclaredonlyonce.
Itisestablishedbytypedeclarationstatement,IMPLICITstatementorbypredefinedtypingrules.
Explicitdeclarationofatypeoverridesanyimplicitdeclaration.
AnIMPLICITstatementoverridespredefinedtypingrules.
Statements95ExampleINTEGERTIME,SECOND,STORE(5,5)INTENT90TheINTENTspecificationstatement(attribute)specifiesintendeduseofadummyargument.
Thisstatement(attribute)maynotbeusedinamainprogram'sspecificationstatement.
SyntaxINTENT(intent-spec)dummy-arg-listintent-specisoneof:INOUTINOUTdummy-arg-lististhelistofdummyargumentswiththespecifiedintent.
DescriptionWithintentspecifiedasIN,thesubprogramargumentmustnotberedefinedbythesubprogram.
WithintentspecifiedasOUT,thesubprogramshouldusetheargumenttopassinformationtothecallingprogram.
WithintentspecifiedasINOUT,thesubprogrammayusethevaluepassedthroughtheargument,butshouldalsoredefinetheargumenttopassinformationtothecallingprogram.
SeeAlsoOPTIONALExampleSUBROUTINEIN_OUT(R1,I1)REAL,INTENT(IN)::R1INTEGER,INTENT(OUT)::I1I1=R1ENDSUBROUTINEIN_OUTFortranStatements96INTERFACE90TheINTERFACEstatementblockmakesanimplicitprocedureanexplicitprocedurewherethedummyparametersandproceduretypeareknowntothecallingmodule.
Thisstatementisalsousedtooverloadaprocedurename.
SyntaxINTERFACE[generic-spec][interface-body].
.
.
[MODULEPROCEDUREprocedure-name-list].
.
.
ENDINTERFACEwheregeneric-specisoneofthefollowing:generic-nameOPERATOR(definedoperator)ASSIGNMENT(=)andtheinterfacebodyspecifiestheinterfaceforafunctionorasubroutine:function-statement[specification-part]ENDFUNCTION[functionname]subroutine-statement[specification-part]ENDFUNCTION[subroutinename]SeeAlsoENDINTERFACEExampleINTERFACESUBROUTINEIN_OUT(R1,I1)REAL,INTENT(IN)::R1INTEGER,INTENT(OUT)::I1ENDSUBROUTINEIN_OUTENDINTEFACEINTRINSIC77AnINTRINSICstatementidentifiesasymbolicnameasanintrinsicfunctionandallowsittobeusedasanactualargument.
Statements97SyntaxINTRINSICfunc[,func]funcisthenameofanintrinsicfunctionsuchasSIN,COS,etc.
DescriptionDonotuseanyofthefollowingfunctionsinINTRINSICstatements:typeconversions:INT,IFIX,IDINT,FLOAT,SNGL,REAL,DBLE,CMPLX,ICHAR,CHARlexicalrelationships:LGE,LGT,LLE,LLTvalues:MAX,MAX0,AMAX1,DMAX1,AMAX0,MAX1,MIN,MIN0,AMIN1,DMIN1,AMIN0,MIN1WhenaspecificnameofanintrinsicfunctionisusedasanactualargumentinaprogramunititmustappearinanINTRINSICstatementinthatprogramunit.
IfthenameusedinanINTRINSICstatementisalsothenameofagenericintrinsicfunction,itretainsitsgenericproperties.
AsymbolicnamecanappearonlyonceinalltheINTRINSICstatementsofaprogramunitandcannotbeusedinbothanEXTERNALandINTRINSICstatementinaprogramunit.
ThefollowingexampleillustratestheuseofINTRINSICandEXTERNAL:EXTERNALMYOWNINTRINSICSIN,COS.
.
CALLTRIG(ANGLE,SIN,SINE).
CALLTRIG(ANGLE,MYOWN,COTANGENT).
CALLTRIG(ANGLE,COS,SINE)SUBROUTINETRIG(X,F,Y)Y=F(X)RETURNENDFortranStatements98FUNCTIONMYOWNMYOWN=COS(X)/SIN(X)RETURNENDInthisexample,whenTRIGiscalledwithasecondargumentofSINorCOSthefunctionreferenceF(X)referencestheintrinsicfunctionsSINandCOS;howeverwhenTRIGiscalledwithMYOWNasthesecondargumentF(X)referencestheuserfunctionMYOWN.
LOGICAL77TheLOGICALstatementestablishesthedatatypeofavariablebyexplicitlyattachingthenameofavariabletoanintegerdatatype.
Thisoverridestheimplicationofdatatypingbytheinitialletterofasymbolicname.
SyntaxThesyntaxforLOGICALhastwoforms,astandardFORTRAN77and90/95attributedform,andthePGIextendedform.
Thissectiondescribesbothsyntaxforms.
LOGICAL[([KIND=kind-value)][,attribute-list::]entity-listLOGICALpermitsaKINDspecification.
RefertotheFortran95Handbookformoresyntaxdetails.
attribute-lististhelistofattributesforthecharactervariable.
entity-lististhelistofdefinedentities.
SyntaxExtension§LOGICAL[*n][,]name[*n][dimensions][/clist/][,name][*n][dimensions][/clist/].
.
.
nisanoptionalsizespecification.
nameisthesymbolicnameofavariable,array,oranarraydeclarator(seetheDIMENSIONstatementforanexplanationofarraydeclarators).
clistisalistofconstantsthatinitializethedata,asinaDATAstatement.
Statements99DescriptionLogicaltypedeclarationstatementsmaybeusedtodimensionarraysexplicitlyinthesamewayastheDIMENSIONstatement.
Typedeclarationstatementsmustnotbelabeled.
Note:Thedatatypeofasymbolmaybeexplicitlydeclaredonlyonce.
Itisestablishedbytypedeclarationstatement,IMPLICITstatementorbypredefinedtypingrules.
Explicitdeclarationofatypeoverridesanyimplicitdeclaration.
AnIMPLICITstatementoverridespredefinedtypingrules.
ThedefaultsizeofaLOGICALvariableis4bytes.
Withthe-Mnoi4option,thedefaultsizeofaLOGICALvariableis2bytes.
ExampleLOGICALTIME,SECOND,STORE(5,5)MAP§77AuniondeclarationisinitiatedbyaUNIONstatementandterminatedbyanENDUNIONstatement.
Enclosedwithinthesestatementsareoneormoremapdeclarations,initiatedandterminatedbyMAPandENDMAPstatements,respectively.
Eachuniquefieldorgroupoffieldsisdefinedbyaseparatemapdeclaration.
Fieldalignmentwithinmultiplemapdeclarationsisperformedaspreviouslydefinedinstructuredeclarations.
SyntaxMAPfield_declaration[field_declaration].
.
.
[field_declaration]ENDMAPfield_declarationisastructuredeclarationorRECORDstatementcontainedwithinauniondeclaration,auniondeclarationcontainedwithinauniondeclaration,orthedeclarationofatypeddatafieldwithinaunion.
DescriptionDatacanbeinitializedinfielddeclarationstatementsinuniondeclarations.
However,itisillegaltoinitializemultiplemapdeclarationsinasingleunion.
FortranStatements100Thesizeofthesharedareaforauniondeclarationisthesizeofthelargestmapdefinedforthatunion.
Thesizeofamapisthesumofthesizesofthefield(s)declaredwithinitplusthespacereservedforalignmentpurposes.
ManipulatingdatausinguniondeclarationsissimilartousingEQUIVALENCEstatements.
However,uniondeclarationsareprobablymoresimilartouniondeclarationsforthelanguageC.
ThemaindifferenceisthatthelanguageCrequiresonetoassociateanamewitheachmap(union).
Fortranfieldnamesmustbeuniquewithinthesamedeclarationnestinglevelofmaps.
ExampleThefollowingisanexampleofRECORD,STRUCTUREandUNIONusage.
Thesizeofeachelementoftherecarrarraywouldbethesizeoftypetag(4bytes)plusthesizeofthelargestMAP(theemployeemapat24bytes).
STRUCTURE/account/INTEGERtypetag!
TagtodeterminedefinedmapUNIONMAP!
StructureforanemployeeCHARACTER*12ssn!
SocialSecurityNumberREAL*4salaryCHARACTER*8empdate!
EmploymentdateENDMAPMAP!
StructureforacustomerINTEGER*4acct_custREAL*4credit_amtCHARACTER*8due_dateENDMAPMAP!
StructureforasupplierINTEGER*4acct_suppREAL*4debit_amtBYTEnum_itemsBYTEitems(12)!
ItemssuppliedENDMAPENDUNIONENDSTRUCTURERECORD/account/recarr(1000)Statements101MODULE90(PGF95andPGHPFonly)TheMODULEstatementspecifiestheentrypointforaFortran90/95moduleprogramunit.
Amoduledefinesahostenvironmentofscopeofthemodule,andmaycontainsubprogramsthatareinthesamescopingunit.
SyntaxMODULE[name][specification-part][CONTAINS[module-subprogram-part]]END[MODULE[module-name]]nameisoptional;ifsupplieditbecomesthenameoftheprogrammoduleandmustnotclashwithanyothernamesusedintheprogram.
Ifitisnotsupplied,adefaultnameisused.
specification-partcontainsspecificationstatements.
SeetheFortran95Handbookforacompletedescriptionofthevalidstatements.
module-subprogram-partcontainsfunctionandsubroutinedefinitionsforthemodule,precededbyasingleCONTAINSkeyword.
ModulescanbeindependentlycompiledandusedwithinprogramsusingtheUSEstatement.
UseofFortran90/95modulescausesthecompilertocreateafilename.
modfileinthecurrentdirectory(a.
modfile).
Thisfilecontainsalltheinformationthecompilerneedsconcerninginterfacespecificationsandthedatatypesfortheroutinesdefinedinthemodule.
Whenaprogram,routine,oranothermoduleencounterstheUSEstatement,the.
modfileisreadand"included"intheprogram,usingthescoperulesdefinedinFortran90/95forUSEassociation.
Ifyouareusingseparatemodules,thiscreatesanotherstepintheprogramdevelopmentprocess.
Whenamoduleiscompiled,botha.
modandanobjectfilearecreated.
The.
modfileisusedwhenaUSEstatementisencountered,andtheobjectfileisusedwhentheprogramislinked.
Forexample,ifmodule1.
fcontainsamodulewithseveralprocedures,andtest1.
fcontainsaUSEstatementthatusesmodule1,thecompilationwouldinvolvethesteps.
%pgf95-cmodule1.
f%pgf95-otest1test1.
fmodule1.
oThesearchfora.
modfileincludesthefollowingdirectories:Each–Idirectoryspecifiedonthecommand-line.
FortranStatements102ThedirectorycontainingthefilethatcontainstheUSEstatement(thecurrentworkingdirectory.
)Thestandardincludearea.
Usingthe–Icommand-lineoptiondirectoriescanbeaddedtothesearchpathfor.
modfiles.
ExampleMODULEMYOWNREALMEAN,TOTALINTEGER,ALLOCATABLE,DIMENSION(:)::ACONTAINSRECURSIVEINTEGERFUNCTIONX(Y).
.
.
ENDFUNCTIONXENDMODULEMYOWNNAMELIST90TheNAMELISTstatementallowsforthedefinitionofnamelistgroupsfornamelist-directedI/O.
SyntaxNAMELIST/group-name/namelist[[,]/group-name/namelist].
.
.
group-nameisthenameofthenamelistgroup.
namelististhelistofvariablesinthenamelistgroup.
ExampleInthefollowingexampleanamedgroupPERSconsistsofaname,anaccount,andavalue.
CHARACTER*12NAMEINTEGER*$ACCOUNTREAL*4VALUENAMELIST/PERS/NAME,ACCOUNT,VALUENULLIFY90TheNULLIFYstatementdisassociatesapointerfromitstarget.
Statements103SyntaxNULLIFY(pointer-object-list)ExampleNULLIFY(PTR1)SeeAlsoALLOCATE,DEALLOCATEOPEN77TheOPENstatementconnectsanexistingfiletoaunit,createsandconnectsafiletoaunit,createsafilethatispreconnectedorchangescertainspecifiersofaconnectionbetweenafileandaunit.
SyntaxOPEN(list)listmustcontainexactlyoneunitspecifieroftheform:[UNIT=]uwheretheUNIT=isoptionalandtheexternalunitspecifieruisaninteger.
Inadditionlistmaycontainoneofeachofthefollowingspecifiersinanyorder,followingtheunitnumberiftheoptionalUNITspecifierkeywordisnotsupplied.
ACCESS=accaccisacharacterexpressionspecifyingtheaccessmethodforfileconnectionasSEQUENTIAL,DIRECTorSTREAM;thedefaultisSEQUENTIAL.
ACTION=accaccisacharacterexpressionspecifyingthepermittedaccesstypesforconnection.
OneofREAD,WRITE,UNKNOWNorREADWRITEisallowed.
ThedefaultisUNKNOWN.
ASYNCHRONOUS=asyncasyncisacharacterexpressionspecifyingwhethertoallowasynchronousdatatransferonthisfileconnection.
Oneof'YES'or'NO'isallowed.
BLANK=blnkblnkisacharacterexpressionwhichtakesthevalue'NULL'or'ZERO'.
'NULL'causesallblankcharactersinnumericformattedinputfieldstobeignoredwiththeexceptionofanall-blankfieldwhichhasavalueofFortranStatements104zero.
'ZERO'causesallblanksotherthanleadingblankstobetreatedaszeros.
Thedefaultis'NULL.
'Thisspecifiermustonlybeusedwhenafileisconnectedforformattedinput/output.
DELIM=del_chardel_charisacharacterexpressionwhichtakesthevalue'APOSTROPHE','QUOTE'or'NONE'.
Thesevaluesspecifythecharacterdelimiterforlist-directedornamelistformatteddatatransferstatements.
ERR=errserrsisanerrorspecifier;ittakestheformofastatementlabelofanexecutablestatementwithintheprogram.
Ifanerrorconditionoccursexecutioncontinueswiththestatementspecifiedbyerrs.
FILE=finfinisacharacterexpressionwhosevalueisthefilenameexpression,thenameofafiletobeconnectedtothespecifiedunit.
FORM=fmfmisacharacterexpressionspecifyingwhetherthefileisbeingconnectedfor'FORMATTED'or'UNFORMATTED'input/output.
IOSTAT=iosiosisanintegerscalar;ifthisisincludediosbecomesdefinedwith0(zero)ifnoerrorconditionexistsorapositiveintegerwhenthereisanerrorcondition.
Avalueof-1indicatesanend-of-fileconditionwithnoerror.
Avalueof-2indicatesanend-of-recordconditionwithnoerrorwhenusingnon-advancingI/O.
PAD=pad_charpad_charisacharacterexpressionspecifyingwhethertouseblankpadding.
AcceptablevaluesareYESorNO;yesspecifiesthatblankpaddingisusedandnorequiresthatinputrecordscontainallrequesteddata.
POSITION=pos_charpos_charisacharacterexpressionspecifyingthefileposition.
ValuesareASIS,REWINDorAPPEND.
Foraconnectedfile,onOPENASISleavesthepositioninthecurrentposition,REWINDrewindsthefileandAPPENDplacesthecurrentpositionattheendofthefile,immediatelybeforetheend-of-filerecord.
RECL=rlrlisanintegerexpressiondefiningtherecordlengthinafileconnectedfordirectaccess.
Whensequentialinput/outputisspecifiedthisisthemaximumrecordlength.
Statements105STATUS=stastaisacharacterexpressionwhosevaluecanbe:NEW,OLD,SCRATCH,UNKNOWNorREPLACE.
WhenOLDorNEWisspecifiedafilespecifiermustbegiven.
SCRATCHmustnotbeusedwithanamedfile.
ThedefaultstatusisUNKNOWNwhichspecifiesthatthefile'sexistenceisunknown,whichlimitstheerrorcheckingwhenopeningthefile.
WithstatusOLD,thefilemustexistoranerrorisreported.
WithstatusNEW,thefileiscreated;ifthefileexists,anerrorisreported.
StatusSCRATCHspecifiesthatthefileisremovedwhenclosed.
DescriptionTherecordlength,RECL=,mustbespecifiedifafileisconnectedfordirectaccessandoptionallyoneofeachoftheotherspecifiersmaybeused.
RECLisignorediftheaccessmethodissequential.
TheunitspecifiedmustexistandonceconnectedbyanOPENstatementcanbereferencedinanyprogramunitoftheexecutableprogram.
IfafileisconnectedtoaunititcannotbeconnectedtoadifferentunitbytheOPENstatement.
Ifaunitisconnectedtoanexistingfile,executionofanOPENstatementforthatfileisallowed.
WhereFILE=isnotspecifiedthefiletobeconnectedisthesameasthefilecurrentlyconnected.
Ifthefilespecifiedforconnectiontotheunitdoesnotexistbutisthesameasapreconnectedfile,thepropertiesspecifiedbytheOPENstatementbecomepartoftheconnection.
However,ifthefilespecifiedisnotthesameasthepreconnectedfilethishasthesameeffectastheexecutionofaCLOSEstatementwithoutaSTATUS=specifierimmediatelybeforetheexecutionoftheOPENstatement.
WhenthefiletobeconnectedisthesameasthefilealreadyconnectedonlytheBLANK=specifiermaybedifferentfromtheonecurrentlydefined.
Thesequentialanddirectaccessmethodsaccessfilesthatcontainfixed-lengthrecords.
Thestreamaccessmethod,aFortran2003languageextension,allowsaccesstofilesthatdonotcontainfixed-lengthrecords.
StreamI/Oisenabledbyspecifyingaccess='STREAM'.
StreamI/Omaybeformattedorunformatted.
Asynchronousi/o,theabilitytoreturncontrolbeforethestatementhascompleted,issupportedincertainsituations.
IfASYNCHRONOUS='yes'isspecifiedontheOPENstatementandaREADorWRITEstatementforaparticularfileconnection,aprocessormayperformanasynchronousdatatransferasynchronously,butisnotrequiredtodoso.
Inpractice,theunderlyingoperatingsystemcontrolsmuchofwhatcanbeperformed.
AfilemustbeseekabletosupportaysynchronousI/O;i.
e.
youcannotperformasynchronousI/Oonanon-seekablefilesuchasafifo.
AsynchronousI/Oisonlysupportedforthestreamaccessmethod.
FortranStatements106ExamplesInthefollowingexampleanewfile,BOOK,iscreatedandconnectedtounit12fordirectformattedinput/outputwitharecordlengthof98characters.
NumericvalueswillhaveblanksignoredandE1willbeassignedsomepositivevalueifanerrorconditionexistswhentheOPENstatementisexecuted;executionwillthencontinuewiththestatementlabeled20.
Ifnoerrorconditionpertains,E1isassignedthevaluezero(0)andexecutioncontinueswiththenextstatement.
OPEN(12,IOSTAT=E1,ERR=20,FILE='BOOK',+BLANK='NULL',ACCESS='DIRECT',RECL=98,+FORM='FORMATTED',STATUS='NEW')ThenextexampleshowshowtouseasynchronousI/O.
programtestcharacter*13bb="hello,world\n"open(unit=10,file='u.
dat',access='stream',form='unformatted',&asynchronous='yes')write(unit=10,asynchronous='yes')b!
Dosomethingusefulwait(10)close(10)endEnvironmentVariablesForanOPENstatementwhichdoesnotcontaintheFILE=specifier,anenvironmentvariablemaybeusedtospecifythefiletobeconnectedtotheunit.
IftheenvironmentvariableFORdddexists,wheredddisa3digitstringwhosevalueistheunit,theenvironmentvariable'svalueisthenameofthefiletobeopened.
PGIFortranExtensions§PGIhasextendedtheOPENstatementasfollows:CONVERT=orderorderisacharacterexpressionspecifyingthebyteorderofthefile.
Oneof'BIG_ENDIAN','LITTLE_ENDIAN',or'NATIVE'isallowed.
TheCONVERTspecifierallowsbyte-swappingI/Otobeperformedonspecificlogicalunits.
Thevalue'BIG_ENDIAN'isusedtoconvertbig-endianformatdatafilesproducedbymostRISCworkstationsandhigh-endserverstothelittle-endianformatusedonIntelArchitecturesystemson-the-flyduringStatements107filereads/writes.
Thisvalueassumesthattherecordlayoutsofunformattedsequentialaccessanddirectaccessfilesarethesameonthesystems.
Forthevalues'LITTLE_ENDIAN'and'NATIVE',byte-swappingisnotperformedduringfilereads/writessincethelittle-endianformatisusedbythex86architecture.
VAX/VMSFortranExtensions§VAX/VMSintroducesanumberofextensionstotheOPENstatement.
ManyoftheserelateonlytotheVMSfilesystemandarenotsupported(e.
g.
,KEYEDaccessforindexedfiles).
ThefollowingkeywordsfortheOPENstatementhavebeenaddedoraugmentedasshownbelow.
RefertoProgramminginVAXFORTRANforadditionaldetailsonthesekeywords.
ACCESSThevalueof'APPEND'willberecognizedandimpliessequentialaccessandpositioningafterthelastrecordofthefile.
Openingafilewithappendaccessmeansthateachappendedrecordiswrittenattheendofthefile.
ASSOCIATEVARIABLEThiskeywordspecifiesanINTEGER*4integerscalarmemoryreferencewhichisupdatedtothenextsequentialrecordnumberaftereachdirectaccessI/Ooperation.
Appliesonlytodirectaccessmode.
DISPOSEandDISPThesekeywordsspecifythedispositionforthefileafteritisclosed.
'KEEP'or'SAVE'isthedefaultonanythingotherthanSTATUS='SCRATCH'files.
'DELETE'indicatesthatthefileistoberemovedafteritisclosed.
ThePRINTandSUBMITvaluesarenotsupported.
NAMEThiskeywordisasynonymforFILE.
READONLYThiskeywordspecifiesthatanexistingfilecanbereadbutprohibitswritingtothatfile.
Thedefaultisread/write.
RECL=lenTherecordlengthgivenisinterpretedasthenumberofwordsinarecordiftheruntimeenvironmentparameterFTNOPTissetto"vaxio".
ThissimplifiestheportingofVAX/VMSprograms.
Thedefaultisthatlenisgiveninnumberofbytesinarecord.
TYPEThiskeywordisasynonymforSTATUS.
FortranStatements108OPTIONAL90TheOPTIONALspecificationstatement(attribute)specifiesdummyargumentsthatmaybeomittedorthatareoptional.
SyntaxOPTIONAL[::]dummy-arg-listExamplesOPTIONAL::VAR4,VAR5OPTIONALVAR6,VAR7INTEGER,OPTIONAL::VAR8,VAR9SeeAlsoINTENTOPTIONS§77TheOPTIONSstatementconfirmsoroverridescertaincompilercommand-lineoptions.
SyntaxOPTIONS/option[/option.
.
.
]ThefollowingtableshowswhatoptionsareavailablefortheOPTIONSstatement:Statements109Table3-1:OPTIONSStatementThefollowingrestrictionsapplytotheOPTIONSstatement:TheOPTIONSstatementmustbethefirststatementinaprogramunit;itmustprecedethePROGRAM,SUBROUTINE,FUNCTION,andBLOCKDATAstatements.
TheoptionslistedintheOPTIONSstatementoverridevaluesfromthedrivercommand-linefortheprogramunit(subprogram)immediatelyfollowingtheOPTIONSstatement.
Anyabbreviatedversionofanoptionthatislongenoughtoidentifytheoptionuniquelyisalegalabbreviationfortheoption.
OptionActionTakenCHECK=ALLEnablearrayboundscheckingCHECK=[NO]OVERFLOWNone(recognizedbutignored)CHECK=[NO]BOUNDS(Disable)EnablearrayboundscheckingCHECK=[NO]UNDERFLOWNoneCHECK=NONEDisablearrayboundscheckingNOCHECKDisablearrayboundschecking[NO]EXTEND_SOURCE(Disable)Enablethe–Mextendoption[NO]G_FLOATINGNone[NO]F77(Disable)Enablethe–Mstandardoption[NO]I4(Disable)Enablethe–Mi4option[NO]RECURSIVE(Disable)Enablethe–Mrecursiveoption[NO]REENTRANT(Enable)Disableoptimizationsthatmayresultincodethatisnotreentrant.
[NO]STANDARD(Disable)Enablethe–MstandardoptionFortranStatements110Caseisnotsignificant,unlessthe–Mupcaseispresentonthecommandline.
Ifitis,eachoptionmustbeinlowercase.
PARAMETER77ThePARAMETERstatementgivesasymbolicnametoaconstant.
SyntaxPARAMETER(name=expression[,name=expression.
.
.
])expressionisanarithmeticexpressionformedfromconstantorPARAMETERelementsusingthearithmeticoperatorsTheusualprecedenceordercanbechangedbyusingparentheses.
expressionmayincludeapreviouslydefinedPARAMETER.
ExamplesPARAMETER(PI=3.
142)PARAMETER(INDEX=1024)PARAMETER(INDEX3=INDEX*3)ThefollowingVAX/VMSextensionstothePARAMETERstatementarefullysupported:Itslistisnotboundedwithparentheses.
Theformoftheconstant(ratherthantheimplicitorexplicittypingofthesymbolicname)determinesthedatatypeofthevariable.
TheformofthealternativePARAMETERstatementis:PARAMETERp=c[,p=c].
.
.
wherepisasymbolicnameandcisaconstant,symbolicconstant,oracompiletimeconstantexpression.
PAUSE(Obsolescent)ThePAUSEstatementstopstheprogram'sexecution.
ThePAUSEstatementisobsolescentbecauseaWRITEstatementmaysendamessagetoanydevice,andaREADstatementmaybeusedtowaitforamessagefromthesamedevice.
Statements111SyntaxPAUSE[character-expression|digits]ThePAUSEstatementstopstheprogram'sexecution.
TheprogrammayberestartedlaterandexecutionwillthencontinuewiththestatementfollowingthePAUSEstatement.
POINTER90ThePOINTERspecificationstatementorattributedeclaresascalarvariabletobeapointervariable(oftypeINTEGER),andanothervariabletobeitstargetpointer-basedvariable.
Thetargetmaybeascalaroranarrayofanytype.
SyntaxPOINTER[::]object-name[(deferred-shape-spec-list)][,object-name[(deferred-shape-spec-list)]]ExampleREAL,DIMENSION(:,:),POINTER::XPOINTER(Cray)§77ThePOINTERstatementisanextensiontoFORTRAN77.
Itdeclaresascalarvariabletobeapointervariable(oftypeINTEGER),andanothervariabletobeitspointer-basedvariable.
SyntaxPOINTER(p1,v1)[,(p2,v2).
.
.
]v1andv2arepointer-basedvariables.
Apointer-basedvariablecanbeofanytype,includingSTRUCTURE.
Apointer-basedvariablecanbedimensionedinaseparatetype,inaDIMENSIONstatement,orinthePOINTERstatement.
Thedimensionexpressionmaybeadjustable,wheretherulesforadjustabledummyarraysregardinganyvariableswhichappearinthedimensiondeclaratorsapply.
p1andp2arethepointervariablescorrespondingtov1andv2.
Apointervariablemaynotbeanarray.
Thepointerisanintegervariablecontainingtheaddressofapointer-basedvariable.
Thestoragelocatedbythepointervariableisdefinedbythepointer-basedvariable(forexample,array,datatype,etc.
).
Areferencetoapointer-basedvariableappearsinFortranStatements112Fortranstatementslikeanormalvariablereference(forexample,alocalvariable,aCOMMONblockvariable,oradummyvariable).
Whenthebasedvariableisreferenced,theaddresstowhichitrefersisalwaystakenfromitsassociatedpointer(thatis,itspointervariableisdereferenced).
Thepointer-basedvariabledoesnothaveanaddressuntilitscorrespondingpointerisdefined.
Thepointerisdefinedinoneofthefollowingways:ByassigningthevalueoftheLOCfunction.
Byassigningavaluedefinedintermsofanotherpointervariable.
Bydynamicallyallocatingamemoryareaforthebasedvariable.
Ifapointer-basedvariableisdynamicallyallocated,itmayalsobefreed.
ExampleREALXC(10)COMMONIC,XCPOINTER(P,I)POINTER(Q,X(5))P=LOC(IC)I=0!
ICgets0P=LOC(XC)Q=P+20!
sameasLOC(XC(6))X(1)=0!
XC(6)gets0ALLOCATE(X)!
Qlocatesadynamically!
allocatedmemoryareaRestrictionsThefollowingrestrictionsapplytothePOINTERstatement:Nostorageisallocatedwhenapointer-basedvariableisdeclared.
Ifapointer-basedvariableisreferenced,itspointervariableisassumedtobedefined.
Apointer-basedvariablemaynotappearintheargumentlistofaSUBROUTINEorFUNCTIONandmaynotappearinCOMMON,EQUIVALENCE,DATA,NAMELIST,orSAVEstatements.
Statements113Apointer-basedvariablecanbeadjustedonlyinaSUBROUTINEorFUNCTIONsubprogram.
Ifapointer-basedvariableisanadjustablearray,itisassumedthatthevariablesinthedimensiondeclarator(s)aredefinedwithanintegervalueatthetimetheSUBROUTINEorFUNCTIONiscalled.
Foravariablewhichappearsinapointer-basedvariable'sadjustabledeclarator,modifyingitsvalueduringtheexecutionoftheSUBROUTINEorFUNCTIONdoesnotmodifytheboundsofthedimensionsofthepointer-basedarray.
Apointer-basedvariableisassumednottooverlapwithanotherpointer-basedvariable.
PRINT77ThePRINTstatementisadatatransferoutputstatement.
SyntaxPRINTformat-specifier[,iolist]orPRINTnamelist-groupformatspecifieralabelofaformatstatementoravariablecontainingaformatstring.
iolistisaninput/outputlistthatmusteitherbeoneoftheitemsinaninputlistoranyotherexpression.
Acharacterexpressioninvolvingconcatenationofanoperandofvariablelengthcannotbeincludedinanoutputlist,however,unlesstheoperandisthesymbolicnameofaconstant.
namelist-groupthenameofthenamelistgroup.
DescriptionWhenaPRINTstatementisexecutedthefollowingoperationsarecarriedout:dataistransferredtothestandardoutputdevicefromtheitemsspecifiedintheoutputlistandformatspecification.
1Thedataaretransferredbetweenthespecifieddestinationsintheorderspecifiedbytheinput/outputlist.
Everyitemwhosevalueistobetransferredmustbedefined.
1.
Ifanasterisk(*)isusedinsteadofaformatidentifier,thelist-directedformattingrulesapply.
FortranStatements114Non-characterFormat-specifier§Ifaformat-specifierisavariablewhichisneitherCHARACTERnorasimpleINTEGERvariable,thecompileracceptsitandtreatsitasifthecontentswerecharacter.
Forexample,belowsumistreatedasaformatdescriptor:realsumsum=4h()printsumandisroughlyequivalenttocharacter*4chch='()'printchSeeAlsoREAD,PRINTPRIVATE90ThePRIVATEstatementspecifiesentitiesdefinedinamodulearenotaccessibleoutsideofthemodule.
Thisstatementisonlyvalidinamodule.
ThedefaultspecificationforamoduleisPUBLIC.
SyntaxPRIVATE[::[access-id-list]]DescriptionExampleMODULEFORMULAPRIVATEPUBLIC::VARA.
.
.
ENDMODULETypeNon-executableStatements115SeeAlsoPUBLIC,MODULEPROGRAM77ThePROGRAMstatementspecifiestheentrypointforthelinkedFortranprogram.
SyntaxPROGRAM[name].
.
.
END[PROGRAM[program-name]]nameisoptional;ifsupplieditbecomesthenameoftheprogrammoduleandmustnotclashwithanyothernamesusedintheprogram.
Ifitisnotsupplied,adefaultnameisused.
DescriptionTheprogramstatementspecifiestheentrypointforthelinkedFortranprogram.
AnENDstatementterminatestheprogram.
TheENDPROGRAMstatementterminatesamainprogramunitthatbeginswiththeoptionalPROGRAMstatement.
TheprogramnamefoundintheENDPROGRAMmustmatchthatinthePROGRAMstatement.
ExamplePROGRAMMYOWNREALMEAN,TOTAL.
CALLTRIG(A,B,C,MEAN).
ENDPUBLIC90ThePUBLICstatementspecifiesentitiesdefinedinamoduleareaccessibleoutsideofthemodule.
Thisstatementisonlyvalidinamodule.
ThedefaultspecificationforamoduleisPUBLIC.
FortranStatements116SyntaxPUBLIC[::[access-id-list]]ExampleMODULEFORMULAPRIVATEPUBLIC::VARA.
.
.
ENDMODULETypeNon-executableSeeAlsoPRIVATE,MODULEPURE95ThePUREattributeindicatesthatafunctionorsubroutinehasnosideeffects.
UseofPUREcanenableadditionalopportunitiesforoptimization,andforthePGHPFcompilerindicatesthatasubroutineorfunctioncanbeusedinaFORALLstatementorconstructorwithinanINDEPENDENTDOloop.
SyntaxPURE[type-specification]FUNCTIONortype-specificationPUREFUNCTIONorPURESUBROUTINETypeNon-executableStatements117SeeAlsoFUNCTION,SUBROUTINEREAD90TheREADstatementisthedatatransferinputstatement.
SyntaxREAD([unit=]u,format-specifier[,control-information)[iolist]READformat-specifier[,iolist]READ([unit=]u,[NML=]namelist-group[,control-information])wheretheUNIT=isoptionalandtheexternalunitspecifieruisaninteger.
Inadditioncontrol-informationisanoptionalcontrolspecificationwhichcanbeanyofthefollowing:maycontainoneofeachofthefollowingspecifiersinanyorder,followingtheunitnumberiftheoptionalUNITspecifierkeywordisnotsupplied.
ASYNCHRONOUS=asyncasyncisacharacterexpressionspecifyingwhethertoallowthedatatransfertobedoneasynchronously.
Thevaluespecifiedmaybe'YES'or'NO'.
FMT=formatformatisalabelofaformatstatementoravariablecontainingaformatstring.
NML=namelistnamelistisanamelistgroupADVANCE=specspecisacharacterexpressionspecifyingtheaccessmethodforfileconnectionaseitherYESorNO.
END=ssisanexecutablestatementlabelforthestatementusedforprocessinganendoffilecondition.
EOR=ssisanexecutablestatementlabelforthestatementusedforprocessinganendofrecordcondition.
ERR=ssisanexecutablestatementlabelforthestatementusedforprocessinganerrorcondition.
IOSTAT=iosiosisanintegervariableorarrayelement.
iosbecomesdefinedwith0ifnoerroroccurs,andapositiveintegerwhenthereisanerror.
FortranStatements118REC=rnrnisarecordnumbertoreadandmustbeapositiveinteger.
Thisisonlyusedfordirectaccessfiles.
SIZE=nnisthenumberofcharactersread.
iolist(inputlist)musteitherbeoneoftheitemsinaninputlistoranyotherexpression.
DescriptionWhenaREADstatementisexecuted,thefollowingoperationsarecarriedout:dataistransferredfromthestandardinputdevicetotheitemsspecifiedintheinputandformatspecification.
1Thedataaretransferredbetweenthespecifieddestinationsintheorderspecifiedbytheinput/outputlist.
Everyitemwhosevalueistobetransferredmustbedefined.
ExampleREAD(2,110)I,J,K110FORMAT(I2,I4,I3)Non-characterFormat-specifier§Ifaformat-specifierisavariablewhichisneitherCHARACTERnorasimpleINTEGERvariable,thecompileracceptsitandtreatsitasifthecontentswerecharacter.
Forexample,belowsumistreatedasaformatdescriptor:realsumsum=4h()acceptsumandisroughlyequivalenttocharacter*4chch='()'acceptch1.
Ifanasterisk(*)isusedinsteadofaformatidentifier,thelist-directedformattingrulesapply.
Statements119SeeAlsoOPEN,PRINT,WRITEREAL90TheREALstatementestablishesthedatatypeofavariablebyexplicitlyattachingthenameofavariabletoadatatype.
Thisoverridestheimplicationofdatatypingbytheinitialletterofasymbolicname.
SyntaxThesyntaxforREALhastwoforms,astandardFortran90/95attributedform,andthePGIextendedform.
Thissectiondescribesbothsyntaxforms.
REAL[([KIND=kind-value)][,attribute-list::]entity-listREALpermitsaKINDspecification.
RefertotheFortran95Handbookformoresyntaxdetails.
attribute-lististhelistofattributesforthecharactervariable.
entity-lististhelistofdefinedentities.
SyntaxExtension§REAL[*n]name[*n][dimensions][/clist/][,name][*n][dimensions][/clist/].
.
.
nisanoptionalsizespecification.
nameisthesymbolicnameofavariable,array,oranarraydeclarator(seetheDIMENSIONstatementbelowforanexplanationofarraydeclarators).
clistisalistofconstantsthatinitializethedata,asinaDATAstatement.
DescriptionTheREALtypedeclarationstatementsmaybeusedtodimensionarraysexplicitlyinthesamewayastheDIMENSIONstatement.
Typedeclarationstatementsmustnotbelabeled.
FortranStatements120NoteThedatatypeofasymbolmaybeexplicitlydeclaredonlyonce.
Itisestablishedbytypedeclarationstatement,IMPLICITstatementorbypredefinedtypingrules.
Explicitdeclarationofatypeoverridesanyimplicitdeclaration.
AnIMPLICITstatementoverridespredefinedtypingrules.
ThedefaultsizeofaREALvariableis4bytes.
Withthe-Mr8option,thedefaultsizeofanREALvariableis8bytes.
ExampleREALKNOTSRECORD§77TheRECORDstatementdefinesauser-definedaggregatedataitem.
SyntaxRECORD/structure_name/record_namelist[,/structure_name/record_namelist].
.
.
[,/structure_name/record_namelist]ENDRECORDstructure_nameisthenameofapreviouslydeclaredstructure.
record_namelistisalistofoneormorevariableorarraynamesseparatedbycommas.
DescriptionYoucreatememorystorageforarecordbyspecifyingastructurenameintheRECORDstatement.
Youdefinethefieldvaluesinarecordeitherbydefiningtheminthestructuredeclarationorbyassigningthemwithexecutablecode.
Youcanaccessindividualfieldsinarecordbycombiningtheparentrecordname,aperiod(.
),andthefieldname(forexample,recordname.
fieldname).
Forrecords,ascalarreferencemeansareferencetoanamethatresolvestoasingletypeddataitem(forexample,INTEGER),whileanaggregatereferencemeansareferencethatresolvestoastructureddataitem.
Statements121ScalarfieldreferencesmayappearwherevernormalvariableorarrayelementsmayappearwiththeexceptionoftheCOMMON,SAVE,NAMELIST,DATAandEQUIVALENCEstatements.
Aggregatereferencesmayonlyappearinaggregateassignmentstatements,unformattedI/Ostatements,andasparameterstosubprograms.
RecordsareallowedinCOMMONandDIMENSIONstatements.
ExampleSTRUCTURE/PERSON/!
DeclareastructuredefiningapersonINTEGERIDLOGICALLIVINGCHARACTER*5FIRST,LAST,MIDDLEINTEGERAGEENDSTRUCTURE!
Definepopulationtobeanarraywhereeachelementisof!
typeperson.
Alsodefineavariable,me,oftypeperson.
RECORD/PERSON/POPULATION(2),ME.
.
.
ME.
AGE=34!
AssignvaluesforthevariablemetoME.
LIVING=.
TRUE.
!
someofthefields.
ME.
FIRST='Steve'ME.
ID=542124822.
.
.
POPULATION(1).
LAST='Jones'!
Assignthe"LAST"fieldof!
element1ofarraypopulation.
POPULATION(2)=ME!
Assignallthevaluesofrecord!
"ME"totherecordpopulation(2)RECURSIVE90TheRECURSIVEstatementindicateswhetherafunctionorsubroutinemaycallitselfrecursively.
SyntaxRECURSIVE[type-specification]FUNCTIONortype-specificationRECURSIVEFUNCTIONFortranStatements122orRECURSIVESUBROUTINETypeNon-executableSeeAlsoFUNCTION,SUBROUTINEREDIMENSION§77TheREDIMENSIONstatement,aCRAYextensiontoFORTRAN77,dynamicallydefinestheboundsofadeferred-shapearray.
AfteraREDIMENSIONstatement,theboundsofthearraybecomethosesuppliedinthestatement,untilanothersuchstatementisencountered.
SyntaxREDIMENSIONname([lb:]ub[,[lb:]ub].
.
.
)[,name([lb:]ub[,[lb:]ub]Where:nameisthesymbolicnameofanarray.
[lb:]ubisadimensiondeclaratorspecifyingtheboundsforadimension(thelowerboundlbandtheupperboundub).
lbandubmustbeintegerswithubgreaterthanlb.
Thelowerboundlbisoptional;ifitisnotspecified,itisassumedtobe1.
Thenumberofdimensiondeclarationsmustbethesameasthenumberofdimensionsinthearray.
ExampleREALA(:,:)POINTER(P,A)P=malloc(12*10*4)REDIMENSIONA(12,10)A(3,4)=33.
RETURN77TheRETURNstatementcausesareturntothestatementfollowingaCALLwhenusedinasubroutine,andreturnstotherelevantarithmeticexpressionwhenusedinafunction.
Statements123SyntaxRETURNAlternateRETURN(Obsolescent)ThealternateRETURNstatementisobsolescentforHPFandFortran90/95.
UsetheCASEstatementwherepossibleinneworupdatedcode.
ThealternateRETURNstatementtakesthefollowingform:RETURNexpressionexpressionexpressionisconvertedtointegerifnecessary(expressionmaybeoftypeintegerorreal).
Ifthevalueofexpressionisgreaterthanorequalto1andlessthanorequaltothenumberofasterisksintheSUBROUTINEorsubroutineENTRYstatementthenthevalueofexpressionidentifiesthenthasteriskintheactualargumentlistandcontrolisreturnedtothatstatement.
ExampleSUBROUTINEFIX(A,B,*,*,C)40IF(T)50,60,7050RETURN60RETURN170RETURN2ENDPROGRAMFIXITCALLFIX(X,Y,*100,*200,S)WRITE(*,5)X,S!
Comehereif(T)0REWIND77TheREWINDstatementpositionsthefileatitsbeginning.
Thestatementhasnoeffectifthefileisalreadypositionedatthestartorifthefileisconnectedbutdoesnotexist.
SyntaxREWINDunitREWIND(unit,list)FortranStatements124unitisanintegervaluewhichistheexternalunit.
listcontainstheoptionalspecifiersasfollows:UNIT=unitunitistheunitspecifier.
ERR=errserrsisanexecutablestatementlabelforthestatementusedforprocessinganerrorcondition.
Ifanerrorconditionoccursexecutioncontinueswiththestatementspecifiedbys.
IOSTAT=iosiosisanintegervariableorarrayelement.
iosbecomesdefinedwith0ifnoerroroccurs,andapositiveintegerwhenthereisanerror.
ExamplesREWIND5REWIND(2,ERR=30)REWIND(3,IOSTAT=IOERR)SAVE77TheSAVEstatementretainsthedefinitionstatusofanentityafteraRETURNorENDstatementinasubroutineorfunctionhasbeenexecuted.
SyntaxSAVE[v[,v].
.
.
]vnameofarray,variable,orcommonblock(enclosedinslashes)DescriptionUsingacommon-blockname,precededandfollowedbyaslash,ensuresthatallentitieswithinthatCOMMONblockaresaved.
SAVEmaybeusedwithoutalist,inwhichcasealltheallowableentitieswithintheprogramunitaresaved(thishasthesameeffectasusingthe–Msavecommand-lineoption).
Dummyarguments,namesofproceduresandnamesofentitieswithinacommonblockmaynotbespecifiedinaSAVEstatement.
UseoftheSAVEstatementwithlocalvariablesensuresthevaluesofthelocalvariablesareretainedforthenextinvocationoftheSUBROUTINEorFUNCTION.
WithinamainprogramtheSAVEstatementisoptionalandhasnoeffect.
WhenaRETURNorENDisexecutedwithinasubroutineorfunction,allentitiesbecomeundefinedwiththeexceptionof:EntitiesspecifiedbyaSAVEstatementStatements125EntitiesinblankcommonornamedcommonEntitiesinitiallydefinedwhichhavenotbeenchangedinanywayExamplePROGRAMSAFE.
CALLKEEP.
SUBROUTINEKEEPCOMMON/LIST/TOP,MIDDLEINTEGERLOCAL1.
SAVE/LIST/,LOCAL1SELECTCASE90TheSELECTCASEstatementbeginsaCASEconstruct.
Syntax[case-name:]SELECTCASE(case-expr)[CASEselector[name]block].
.
.
[CASEDEFAULT[case-name]blockENDSELECT[case-name]ExampleSELECTCASE(FLAG)CASE(1,2,3)TYPE=1CASE(4:6)TYPE=2CASEDEFAULTTYPE=0ENDSELECTSEQUENCE90TheSEQUENCEstatementisaderivedtypequalifierthatspecifiestheorderingofthestorageassociatedwiththederivedtype.
ThisstatementspecifiesstorageforusewithCOMMONandEQUIVALENCEstatements(thepreferredmethodforderivedtypedatasharingisusingMODULES).
FortranStatements126NoteThereisalsoanHPFSEQUENCEdirectivethatspecifieswhetheranarray,commonblock,orequivalenceissequentialornon-sequential.
RefertothePGHPFUser'sGuideformoreinformation.
SyntaxTYPE[SEQUENCE]type-specification.
.
.
ENDTYPEExampleTYPERECORDSEQUENCECHARACTERNAME(25)INTEGERCUST_NUMREALCOSTENDTYPESTOP77TheSTOPstatementstopstheprogram'sexecutionandprecludesanyfurtherexecutionoftheprogram.
SyntaxSTOP[character-expression|digits]STRUCTURE§77TheSTRUCTUREstatement,aDECextensiontoFORTRAN77,definesanaggregatedatatype.
SyntaxSTRUCTURE[/structure_name/][field_namelist]field_declaration[field_declaration].
.
.
[field_declaration]ENDSTRUCTUREStatements127structure_nameisuniqueandisusedbothtoidentifythestructureandtoallowitsuseinsubsequentRECORDstatements.
field_namelistisalistoffieldshavingthestructureoftheassociatedstructuredeclaration.
Afield_namelistisallowedonlyinnestedstructuredeclarations.
field_declarationcanconsistofanycombinationofsubstructuredeclarations,typeddatadeclarations,uniondeclarationsorunnamedfielddeclarations.
DescriptionFieldswithinstructuresconformtomachine-dependentalignmentrequirements.
AlignmentoffieldsalsoprovidesaC-like"struct"buildingcapabilityandallowsconvenientinter-languagecommunications.
NotethataligningofstructurefieldsisnotsupportedbyVAX/VMSFortran.
Fieldnameswithinthesamedeclarationnestinglevelmustbeunique,butaninnerstructuredeclarationcanincludefieldnamesusedinanouterstructuredeclarationwithoutconflict.
Also,becauserecordsuseperiodstoseparatefields,itisnotlegaltouserelationaloperators(forexample,.
EQ.
,.
XOR.
),logicalconstants(.
TRUE.
or.
FALSE.
),orlogicalexpressions(.
AND.
,.
NOT.
,.
OR.
)asfieldnamesinstructuredeclarations.
Fieldsinastructurearealignedasrequiredbyhardwareandastructure'sstoragerequirementsarethereforemachine-dependent.
NotethatVAX/VMSFortrandoesnopadding.
Becauseexplicitpaddingofrecordsisnotnecessary,thecompilerrecognizesthe%FILLintrinsic,butperformsnoactioninresponsetoit.
Datainitializationcanoccurfortheindividualfields.
TheUNIONandMAPstatementsaresupported.
Thefollowingisanexampleofrecordandstructureusage.
STRUCTURE/account/INTEGERtypetag!
TagtodeterminedefinedmapUNIONMAP!
StructureforanemployeeCHARACTER*12ssn!
SocialSecurityNumberREAL*4salaryCHARACTER*8empdate!
EmploymentdateENDMAPMAP!
StructureforacustomerFortranStatements128INTEGER*4acct_custREAL*4credit_amtCHARACTER*8due_dateENDMAPMAP!
StructureforasupplierINTEGER*4acct_suppREAL*4debit_amtBYTEnum_itemsBYTEitems(12)!
ItemssuppliedENDMAPENDUNIONENDSTRUCTURERECORD/account/recarr(1000)SUBROUTINE77TheSUBROUTINEstatementintroducesasubprogramunit.
ThestatementsthatfollowshouldbelaidoutinthesameorderasaPROGRAMmodule.
Syntax[RECURSIVE]SUBROUTINEname&[(argument[,argument.
.
.
])]&[specification-part][execution-part][internal-subspart]END[SUBROUTINE[name]]nameisthenameofthesubroutinebeingdeclaredandmustbeuniqueamongallthesubroutineandfunctionnamesintheprogram.
nameshouldnotclashwithanylocal,COMMON,PARAMETERorENTRYnames.
argumentisasymbolicname,startingwithaletterandcontainingonlylettersanddigits.
ThetypeofargumentcanbeREAL,INTEGER,DOUBLEPRECISION,CHARACTER,COMPLEX,orBYTE,etc.
specification-partisthespecificationofdatatypesforthesubroutine.
execution-partcontainsthesubprogram'sexecutablestatements.
internal-subs-partcontainssubprogramsdefinedwithinthesubroutine.
Statements129DescriptionASUBROUTINEmustbeterminatedbyanENDstatement.
ThestatementsandnamesinthesubprogramonlyapplytothesubroutineexceptforsubroutineorfunctionreferencesandthenamesofCOMMONblocks.
Dummyargumentsmaybespecifiedas*whichindicatesthattheSUBROUTINEcontainsalternatereturns.
Recursionisallowedifthe–Mrecursiveoptionisusedonthecommand-lineandtheRECURSIVEprefixisincludedinthefunctiondefinition.
ExampleSUBROUTINEDAXTIM(A,X,Y,N,M,ITER,FP,TOH)INTEGER*4N,M,ITERREAL*8A,X(N,M),Y(N,M),FP,TOH.
.
.
ENDSUBROUTINEDAXTIMSeeAlsoPURE,RECURSIVETARGET90TheTARGETspecificationstatement(attribute)specifiesthatadatatypemaybetheobjectofapointervariable(e.
g.
,pointedtobyapointervariable).
Likewise,typesthatdonothavetheTARGETattributecannotbethetargetofapointervariable.
SyntaxTARGET[::]object-name[(array-spec)][,object-name[(array-spec)]].
.
.
SeeAlsoALLOCATABLE,POINTERTHEN77TheTHENstatementispartofablockIFstatementandsurroundsaseriesofstatementsthatareconditionallyexecuted.
FortranStatements130SyntaxIFlogicalexpressionTHENstatementsELSEIFlogicalexpressionTHENstatementsELSEstatementsENDIFTheELSEIFsectionisoptionalandmayberepeatedanynumberoftimes.
OtherIFblocksmaybenestedwithinthestatementssectionofanIFblock.
ExampleIF(I.
GT.
70)THENM=1ELSEIF(I.
LT.
5)THENM=2ELSEIF(I.
LT.
16)THENM=3ENDIFIF(I.
LT.
15)THENM=4ELSEM=5ENDIFTYPE77TheTYPEstatementbeginsaderivedtypedataspecificationordeclaresvariablesofaspecifieduser-definedtype.
SyntaxTypeDeclarationTYPE(type-name)[,attribute-list::]entity-listSyntaxDerivedTypeDefinitionTYPE[[access-spec]::]type-name[private-sequence-statement].
.
.
component-definition-statement[component-definition-statement].
.
.
ENDTYPE[type-name]Statements131FORTRAN77TypeStatementTYPETheTYPEstatementhasthesamesyntaxandeffectasthePRINTstatement.
RefertothePRINTstatementforafulldescription.
UNION§77AUNIONdeclaration,aDECextensiontoFORTRAN77,isamulti-statementdeclarationdefiningadataareathatcanbesharedintermittentlyduringprogramexecutionbyoneormorefieldsorgroupsoffields.
Itdeclaresgroupsoffieldsthatshareacommonlocationwithinastructure.
Eachgroupoffieldswithinauniondeclarationisdeclaredbyamapdeclaration,withoneormorefieldspermapdeclaration.
Uniondeclarationsareusedwhenonewantstousethesameareaofmemorytoalternatelycontaintwoormoregroupsoffields.
Wheneveroneofthefieldsdeclaredbyauniondeclarationisreferencedinaprogram,thatfieldandanyotherfieldsinitsmapdeclarationbecomedefined.
Then,whenafieldinoneoftheothermapdeclarationsintheuniondeclarationisreferenced,thefieldsinthatmapdeclarationbecomedefined,supersedingthefieldsthatwerepreviouslydefined.
AuniondeclarationisinitiatedbyaUNIONstatementandterminatedbyanENDUNIONstatement.
Enclosedwithinthesestatementsareoneormoremapdeclarations,initiatedandterminatedbyMAPandENDMAPstatements,respectively.
Eachuniquefieldorgroupoffieldsisdefinedbyaseparatemapdeclaration.
TheformatofaUNIONstatementisasfollows:SyntaxUNIONmap_declaration[map_declaration].
.
.
[map_declaration]ENDUNIONTheformatofthemap_declarationisasfollows:MAPfield_declaration[field_declaration].
.
.
[field_declaration]ENDMAPFortranStatements132field_declarationwherefielddeclarationisastructuredeclarationorRECORDstatementcontainedwithinauniondeclaration,auniondeclarationcontainedwithinauniondeclaration,orthedeclarationofatypeddatafieldwithinaunion.
DescriptionDatacanbeinitializedinfielddeclarationstatementsinuniondeclarations.
Note,however,itisillegaltoinitializemultiplemapdeclarationsinasingleunion.
Thesizeofthesharedareaforauniondeclarationisthesizeofthelargestmapdefinedforthatunion.
Thesizeofamapisthesumofthesizesofthefield(s)declaredwithinitplusthespacereservedforalignmentpurposes.
ManipulatingdatausinguniondeclarationsissimilartousingEQUIVALENCEstatements.
However,uniondeclarationsareprobablymoresimilartouniondeclarationsforthelanguageC.
ThemaindifferenceisthatthelanguageCrequiresonetoassociateanamewitheachmap(union).
Fortranfieldnamesmustbeuniquewithinthesamedeclarationnestinglevelofmaps.
ThefollowingisanexampleofRECORD,STRUCTUREandUNIONusage.
Thesizeofeachelementoftherecarrarraywouldbethesizeoftypetag(4bytes)plusthesizeofthelargestMAP(theemployeemapat24bytes).
STRUCTURE/account/INTEGERtypetag!
Tagtodeterminedefinedmap.
UNIONMAP!
StructureforanemployeeCHARACTER*12ssn!
SocialSecurityNumberREAL*4salaryCHARACTER*8empdate!
EmploymentdateENDMAPMAP!
StructureforacustomerINTEGER*4acct_custREAL*4credit_amtCHARACTER*8due_dateENDMAPMAP!
StructureforasupplierINTEGER*4acct_suppREAL*4debit_amtBYTEnum_itemsBYTEitems(12)!
ItemssuppliedStatements133ENDMAPENDUNIONENDSTRUCTURERECORD/account/recarr(1000)USE90TheUSEstatementgivesaprogramunitaccesstothepublicentitiesortothenamedentitiesinthespecifiedmodule.
SyntaxUSEmodule-name[,rename-list]USEmodule-name,ONLY:[only-list]DescriptionAmodule-namefilehasanassociatedcompiled.
modfilethatisincludedwhenthemoduleisused.
The.
modfileissearchedforinthefollowingdirectories:Each–Idirectoryspecifiedonthecommand-line.
ThedirectorycontainingthefilethatcontainstheUSEstatement(thecurrentworkingdirectory.
)Thestandardincludearea.
ExamplesUSEMOD1USEMOD2,TEMP=>VARUSEMOD3,ONLY:RESULTS,SCORES=>VAR2TypeNon-executableSeeAlsoMODULEVOLATILE§77TheVOLATILEstatementinhibitsalloptimizationsonthevariables,arraysandcommonblocksthatitidentifies.
FortranStatements134SyntaxVOLATILEnitem[,nitem.
.
.
]nitemisthenameofavariable,anarray,oracommonblockenclosedinslashes.
DescriptionIfnitemnamesacommonblock,allmembersoftheblockarevolatile.
Thevolatileattributeofavariableisinheritedbyanydirectorindirectequivalences,asshownintheexample.
ExampleCOMMON/COM/C1,C2VOLATILE/COM/,DIR!
/COM/andDIRarevolatileEQUIVALENCE(DIR,X)!
XisvolatileEQUIVALENCE(X,Y)!
YisvolatileWHERE90TheWHEREstatementandtheWHEREENDWHEREconstructpermitmaskedassignmentstotheelementsofanarray(ortoascalar,zerodimensionalarray).
SyntaxWHEREStatementWHERE(logical-array-expr)array-variable=array-exprWHEREConstructWHERE(logical-array-expr)array-assignments[ELSEWHEREarray-assignments]ENDWHEREDescriptionThisconstructallowsforconditionalassignmenttoanarraybasedontheresultofalogicalarrayexpression.
Thelogicalarrayexpressionandthearrayassignmentsmustinvolvearraysofthesameshape.
Statements135ExamplesINTEGERSCORE(30)CHARACTERGRADE(30)WHERE(SCORE>60)GRADE='P'WHERE(SCORE>60)GRADE='P'ELSEWHEREGRADE='F'ENDWHEREWRITE90TheWRITEstatementisadatatransferoutputstatement.
SyntaxWRITE([unit=]u,[,control-information)[iolist]WRITE([unit=]u,[NML=]namelist-group[,control-information])wheretheUNIT=isoptionalandtheexternalunitspecifieruisaninteger.
Thismayalsobea*indicatinglist-directedoutput.
Inadditiontotheunitspecification,control-informationareoptionalcontrolspecifications,andmaybeanyofthoselistedinthefollowing(therearesomelimitsontheallowedspecificationsdependingonthetypeofoutput,forexample,non-advancing,directandsequential):ADVANCE=specspecisacharacterexpressionspecifyingtheaccessmethodforthewrite.
YESindicatesadvancingformattedsequentialdatatransfer.
NOindicatesnon-advancingformattedsequentialdatatransfer.
ASYNCHRONOUS=asyncasyncisacharacterexpressionspecifyingwhethertoallowthedatatransfertobedoneasynchronously.
Thevaluespecifiedmaybe'YES'or'NO'.
ERR=ssisanexecutablestatementlabelforthestatementusedforprocessinganerrorcondition.
[FMT=]formatformatisalabelofaformatstatementoravariablecontainingaformatstring.
IOSTAT=iosiosisanintegervariableorarrayelement.
iosbecomesdefinedwith0ifnoerroroccurs,andapositiveintegerwhenthereisanerror.
FortranStatements136[NML=]namelistnamelistisanamelistgroupREC=rnrnisarecordnumbertoreadandmustbeapositiveinteger.
Thisisonlyusedfordirectaccessfiles.
iolistiolistmusteitherbeoneoftheitemsinaninputlistoranyotherexpression.
Howeveracharacterexpressioninvolvingconcatenationofanoperandofvariablelengthcannotbeincludedinanoutputlistunlesstheoperandisthesymbolicnameofaconstant.
DescriptionWhenaWRITEstatementisexecutedthefollowingoperationsarecarriedout:dataistransferredtothestandardoutputdevicefromtheitemsspecifiedintheoutputlistandformatspecification.
1Thedataaretransferredbetweenthespecifieddestinationsintheorderspecifiedbytheinput/outputlist.
Everyitemwhosevalueistobetransferredmustbedefined.
ExampleWRITE(6,90)NPAGE90FORMAT('1PAGENUMBER',I2,16X,'SALESREPORT,Cont.
')Non-characterFormat-specifier§Ifaformat-specifierisavariablewhichisneitherCHARACTERnorasimpleINTEGERvariable,thecompileracceptsitandtreatsitasifthecontentswerecharacter.
Forexample,belowsumistreatedasaformatdescriptor:realsumsum=4h()acceptsumandisroughlyequivalenttocharacter*4chch='()'acceptch1.
Ifanasterisk(*)isusedinsteadofaformatidentifier,thelist-directedformattingrulesapply.
Statements137SeeAlsoREAD,PRINTFortranStatements138ArrayTypes1394FortranArraysFortranarraysareanyobjectwiththedimensionattribute.
InFortran90/95,arraysmaybeverydifferentfromarraysinolderversionsofFortran.
Arrayscanhavevaluesassignedasawholewithoutspecifyingoperationsonindividualarrayelements,andarraysectionscanbeaccessed.
Also,allocatablearraysthatarecreateddynamicallyareavailableaspartoftheFortran90/95standard.
ThischapterdescribessomeofthefeaturesofFortran90/95arrays.
Fortranarraysareanyobjectwiththedimensionattribute.
InFortran90/95,andinHPF,arraysmaybeverydifferentfromarraysinolderversionsofFortran.
Arrayscanhavevaluesassignedasawholewithoutspecifyingoperationsonindividualarrayelements,andarraysectionscanbeaccessed.
Also,allocatablearraysthatarecreateddynamicallyareavailableaspartoftheFortran90/95andHPFstandards.
ArraysinHPFplayacentralroleindatadistributionanddataalignment(refertothischapterandTheHighPerformanceFortranHandbookfordetailsonworkingwitharraysinHPF).
ThischapterdescribessomeofthefeaturesofFortran90/95andHPFarrays.
Thefollowingexampleillustratesvalidarrayoperations.
REAL(10,10)A,B,CA=12!
Assign12toallelementsofAB=3!
Assign3toallelementsofBC=A+B!
AddeachelementofAtoeachofBArrayTypesFortransupportsfourtypesofarrays:explicit-shapearrays,assumed-shapearrays,deferred-shapearraysandassumed-sizearrays.
Bothexplicit-shapearraysanddeferredshapearraysarevalidinamainprogram.
Assumedshapearraysandassumedsizearraysareonlyvalidforarraysusedasdummyarguments.
Deferredshapearrays,wherethestorageforthearrayisallocatedduringexecution,mustbedeclaredwitheithertheALLOCATABLEorPOINTERattributes.
Everyarrayhaspropertiesoftyperank,shapeandsize.
Theextentofanarray'sdimensionisthenumberofelementsinthedimension.
Thearrayrankisthenumberofdimensionsinthearray,uptoamaximumofseven.
Theshapeisthevectorrepresentingtheextentsforalldimensions.
Thesizeistheproductoftheextents.
Forsometypesofarrays,allofthesepropertiesaredeterminedwhenthearrayisdeclared.
Forothertypesofarrays,someofthesepropertiesaredeterminedwhenthearrayisallocatedorwhenaprocedureusingthearrayisentered.
Forarraysthataredummyarguments,thereareseveralspecialcases.
FortranArrays140Allocatablearraysarearraysthataredeclaredbutforwhichnostorageisallocateduntilanallocatestatementisexecutedwhentheprogramisrunning.
AllocatablearraysprovideFortran90/95andHPFprogramswithdynamicstorage.
Allocatablearraysaredeclaredwitharankspecifiedwiththe":"characterratherthanwithexplicitextents,andtheyaregiventheALLOCATABLEattribute.
ExplicitShapeArraysExplicitshapearraysarethosearraysfamiliartoFORTRAN77programmers.
Eachdimensionisdeclaredwithanexplicitvalue.
Therearetwospecialcasesofexplicitarrays.
Inaprocedure,anexplicitarraywhoseboundsarepassedinfromthecallingprogramiscalledanautomatic-array.
Thesecondspecialcase,alsofoundinaprocedure,isthatofanadjustable-arraywhichisadummyarraywheretheboundsarepassedfromthecallingprogram.
AssumedShapeArraysAnassumedshapearrayisadummyarraywhoseboundsaredeterminedfromtheactualarray.
Intrinsicscalledfromthecalledprogramcandeterminesizesoftheextentsinthecalledprogram'sdummyarray.
DeferredShapeArraysAdeferredshapearrayisanarraythatisdeclared,butnotwithanexplicitshape.
Upondeclaration,thearray'stype,itskind,anditsrank(numberofdimensions)aredetermined.
Deferredshapearraysareoftwovarieties,allocatablearraysandarraypointers.
AssumedSizeArraysAnassumedsizearrayisadummyarraywhosesizeisdeterminedfromthecorrespondingarrayinthecallingprogram.
Thearray'srankandextentsmaynotbedeclaredthesameastheoriginalarray,butitstotalsize(numberofelements)isthesameastheactualarray.
ThisformofarrayshouldnotneedtobeusedinnewFortranprograms.
ArraySpecification141ArraySpecificationArraysmaybespecifiedineitheroftwotypesofdatatypespecificationstatements,attribute-orientedspecificationsorentity-orientedspecifications.
Arraysmayalsooptionallyhavedataassignedtothemwhentheyaredeclared.
Thissectioncoversthebasicformofentity-baseddeclarationsforthevarioustypesofarrays.
Notethatallthedetailsofarraypassingforproceduresarenotcoveredhere;refertoTheFortran95Handbookforcompletedetailsontheuseofarraysasdummyarguments.
ExplicitShapeArraysExplicitshapearraysaredefinedwithaspecifiedrank,eachdimensionmusthaveanupperboundspecified,andalowerboundmaybespecified.
Eachboundisexplicitlydefinedwithaspecificationoftheform:[lower-bound:]upper-boundAnarrayhasamaximumofsevendimensions.
Thefollowingarevalidexplicitarraydeclarations:INTEGERNUM1(1,2,3)!
ThreedimensionsINTEGERNUM2(-12:6,100:1000)!
Twodimensionswith!
lowerandupperboundsINTEGERNUM3(0,12,12,12)!
Arrayofsize0INTEGERNUM3(M:N,P:Q,L,99)!
Arraywith4dimensionsAssumedShapeArraysAnassumedshapearrayisalwaysadummyargument.
Anassumedshapearrayhasaspecificationoftheform:[lower-bound]:Thenumberofcolons(:)determinesthearray'srank.
AnassumedshapearraycannotbeanALLOCATABLEorPOINTERarray.
DeferredShapeArraysAndeferredshapearrayisanarraypointeroranallocatablearray.
Anassumedshapearrayhasaspecificationdeterminesthearray'srankandhasthefollowingformforeachdimension::Forexample:FortranArrays142INTEGER,POINTER::NUM1(INTEGER,ALLOCATABLE::NUM2(:)AssumedSizeArraysAnassumedsizearrayisadummyargumentwithanassumedsize.
Thearray'srankandboundsarespecifiedwithadeclarationthathasthefollowingform:[explicit-shape-spec-list,][lower-bound:]*Forexample:SUBROUTINEYSUM1(M,B,C)INTEGERMREAL,DIMENSION(M,4,5,*)::B,CArraySubscriptsandAccessThereareavarietyofwaystoaccessanarrayinwholeorinpart.
Arrayscanbeaccessed,used,andassignedtoaswholearrays,aselements,orassections.
Arrayelementsarethebasicaccessmethod,forexample:INTEGER,DIMENSION(3,11)::NUMBNUMB(3,1)=5Thisassignsthevalue5toelement3,1ofNUMBThearrayNUMBmayalsobeaccessedasanentirearray:NUMB=5Thisassignsthevalue5toallelementsofNUMB.
ArraySectionsandSubscriptTripletsAnotherpossibilityforaccessingarrayelementsisthearraysection.
Anarraysectionisanarrayaccessedbyasubscriptthatrepresentsasubsetoftheentirearray'selementsandisnotanarrayelement.
Anarraysectionresultingfromapplyingasubscriptlistmayhaveadifferentrankthantheoriginalarray.
Anarraysection'ssubscriptlistconsistsofsubscripts,subscripttriplets,and/orvectorsubscripts.
Forexampleusingasubscripttripletandasubscript:ArraySubscriptsandAccess143NUMB(:,3)=6assignsthevalue6toallelementsofNUMBwiththeseconddimensionofvalue3(NUMB(1,3),NUMB(2,3),NUMB(3,3)).
Thisarraysectionusesthearraysubscripttripletandasubscripttoaccessthreeelementsoftheoriginalarray.
Thisarraysectioncouldalsobeassignedtoarankonearraywiththreeelements,forexample:INTEGER(3,11)NUMBINTEGER(3)NUMCNUMB(:,3)=6NUMC=NUMB(:,3)NotethatNUMCisrank1andNUMBisrank2.
ThisarraysectionassignmentillustrateshowNUMC,anthearraysectionofNUMB,hasashapethatduetotheuseofthesubscript3,isofadifferentrankthantheoriginalarray.
Thegeneralformforanarray'sdimensionwithavectorsubscripttripletis:[subscript]:[subscript][:stride]Thefirstsubscriptisthelowerboundforthearraysection,thesecondistheupperboundandthethirdisthestride.
Thestrideisbydefaultone.
Ifallvaluesexceptthe:areomitted,thenallthevaluesforthespecifieddimensionsareincludedinthearraysection.
Forexample,usingNUMBabove:NUMB(1:3:2,3)=7assignsthevalue7totheelementsNUMB(1,3)andNUMB(3,3).
ArraySectionsandVectorSubscriptsVector-valuedsubscriptsspecifyanarraysectionbysupplyingasetofvaluesdefinedinaonedimensionalarray(vector)foradimensionorseveraldimensionsofanarraysection.
Forexample:INTEGERJ(2),I(2)INTEGERNUMB(3,6)I=(/1,2/)J=(/2,3/)NUMB(J,I)=7ThisarraysectionusesthevectorsIandJtoassignthevalue7totheelementsNUMB(2,1),NUMB(2,2),NUMB(3,1),NUMB(3,2).
FortranArrays144ArrayConstructorsAnarrayconstructorcanbeusedtoassignvaluestoanarray.
Arrayconstructorsformone-dimensionalvectorstosupplyvaluestoaone-dimensionalarray,oronedimensionalvectorsandtheRESHAPEfunctiontosupplyvaluestoarrayswithmorethanonedimension.
ArrayconstructorscanuseaformofimpliedDOsimilartothatinaDATAstatement.
Forexample:INTEGERDIMENSION(4)::K=(/1,2,7,11/)INTEGERDIMENSION(20)::J=(/(I,I=1,40,2)/)CMFortranExtensionsTheARRAYAttribute§ThePGHPFcompilerprovidesseveralextensionsforhandlingarrays.
ThecompilerhandlestheCMFortranattributeARRAY.
TheARRAYattributeissimilartotheDIMENSIONattribute.
RefertoformoredetailsontheARRAYstatement.
ArrayConstructorsExtensions§ThePGHPFcompilersupportsanextendedformofthearrayconstructorspecification.
Inadditiontothe(/.
.
/)specificationforarrayconstructors,PGHPFsupportsthenotationwhere[and]beginandend,respectively,anarrayconstructor.
Inaddition,anarrayconstructoritemmaybea'subscripttriplet'intheformofanarraysectionwherethevaluesareassignedtothearray:lower-bound:upper-bound[:]Forthevaluesi:j:kthearraywouldbeassignedvaluesi,i+k,i+2k,.
.
.
,j.
Ifkisnotpresent,strideisassumedtobe1.
Forexample:INTEGER,DIMENSION(20)::K=[1:40:2]FileAccessMethods1455InputandOutputFormattingInput,output,andformatstatementsprovidethemeansfortransferringdatatoorfromfiles.
Dataistransferredasrecordstoorfromfiles.
Arecordisasequenceofdatawhichmaybevaluesorcharactersandafileisasequenceofsuchrecords.
Afilemaybeinternal,thatis,heldinmemory,orexternalsuchasthoseheldondisk.
Toaccessanexternalfileaformalconnectionmustbemadebetweenaunit,forexampleadiskfile,andtherequiredfile.
Anexternalunitmustbeidentifiedeitherbyapositiveintegerexpression,thevalueofwhichindicatesaunit,orbyanasterisk(*)whichidentifiesastandardinputoroutputdevice.
Thischapterdescribesthetypesofinputandoutputavailableandprovidesexamplesofinput,outputandformatstatements.
Therearefourtypesofinput/outputusedtotransferdatatoorfromfiles:unformatted,formatted,listdirected,andnamelist.
unformatteddataistransferredbetweentheitem(s)intheinput/outputlist(iolist)andthecurrentrecordinthefile.
Exactlyonerecordmaybereadorwritten.
formatteddataiseditedtoconformtoaformatspecification,andtheediteddataistransferredbetweentheitemoritemsintheiolist,andthefile.
Oneormorerecordsmaybereadorwritten.
Non-advancingformatteddatatransfersareavarietyofformattedI/Owhereaportionofadatarecordistransferredwitheachinput/outputstatement.
listdirectedinput/outputisanabbreviatedformofformattedinput/outputthatdoesnotuseaformatspecification.
Dependingonthetypeofthedataitemordataitemsintheiolist,dataistransferredtoorfromthefile,usingadefault,andnotnecessarilyaccurateformatspecification.
namelistinput/outputisaspecialtypeofformatteddatatransfer;dataistransferredbetweenanamedgroup(namelistgroup)ofdataitemsandoneormorerecordsinafile.
FileAccessMethodsYoucanaccessfilesusingoneoftwomethods,sequentialaccess,ordirectaccess(randomaccess).
TheaccessmethodisdeterminedbythespecifierssuppliedwhenthefileisopenedusingtheOPENstatement.
Sequentialaccessfilesareaccessedoneaftertheother,andarewritteninthesamemanner.
Directaccessfilesareaccessedbyspecifyingarecordnumberforinput,andbywritingtothecurrentlyspecifiedrecordonoutput.
InputandOutputFormatting146Filesmaycontainoneoftwotypesofrecords,fixedlengthrecordsorvariablelengthrecords.
Tospecifythesizeofthefixedlengthrecordsinafile,usetheRECLspecifierwiththeOPENstatement.
RECLsetstherecordlengthinbytes.
1RECLcanonlybeusedwhenaccessisdirect.
Arecordinavariablelengthformattedfileisterminatedwith\n.
Arecordinavariablelengthunformattedfileisprecededandfollowedbyawordindicatingthelengthoftherecord.
StandardPreconnectedUnitsCertaininputandoutputunitsarepredefined,dependingonthevalueofcompileroptions.
ThePGIFortrancompilers–Mdefaultunitoptiontellsthecompilertotreat"*"asasynonymforstandardinputforreadingandstandardoutputforwriting.
Whentheoptionis–Mnodefaultunit,thecompilertreats"*"asasynonymforunit5oninputandunit6onoutput.
OpeningandClosingFilesTheOPENstatementestablishesaconnectiontoafile.
OPENallowsyoutodoanyofthefollowingConnectanexistingfiletoaunit.
Createandconnectafiletoaunit.
Createafilethatispreconnected.
Establishtheaccessmethodandrecordformatforaconnection.
OPENhastheform:OPEN(list)wherelistcontainsaunitspecifieroftheform:[UNIT=]uwhereu,aninteger,istheexternalunitspecifier.
1.
TheunitsdependonthevalueoftheFORTRANOPTenvironmentvariable.
Ifthevalueisvaxio,thentherecordlengthisinunitsof32-bitwords.
IfFORTRANOPTisnotdefined,oritsvalueissomethingotherthanvaxio,thentherecordlengthisalwaysinunitsofbytes.
OpeningandClosingFiles147InadditionlistmaycontainoneofeachofthespecifiersshowninTable5-1,"OPENSpecifiers".
DirectAccessFilesIfafileisconnectedfordirectaccessusingOPENwithACCESS='DIRECT',therecordlengthmustbespecifiedusingRECL=,andoptionallyoneofeachoftheotherspecifiersmaybeused.
Anyfileopenedfordirectaccessmustbeviafixedlengthrecords.
Inthefollowingexampleanewfile,book.
dat,iscreatedandconnectedtounit12fordirectformattedinput/outputwitharecordlengthof98characters.
NumericvalueswillhaveblanksignoredandthevariableE1willbeassignedsomepositivevalueifanerrorconditionexistswhentheOPENstatementisexecuted;executionwillthencontinuewiththestatementlabeled20.
Ifnoerrorconditionpertains,E1isassignedthevalue0andexecutioncontinueswiththestatementfollowingtheOPENstatement.
OPEN(12,IOSTAT=E1,ERR=20,FILE='book.
dat',BLANK='NULL',+ACCESS='DIRECT',RECL=98,FORM='FORMATTED',STATUS='NEW')ClosingaFileCloseaunitbyspecifyingtheCLOSEstatementfromwithinanyprogramunit.
Iftheunitspecifieddoesnotexistorhasnofileconnectedtoit,theCLOSEstatementhasnoeffect.
Providedthefileisstillinexistence,itmaybereconnectedtothesameoradifferentunitaftertheexecutionofaCLOSEstatement.
AnimplicitCLOSEisexecutedwhenaprogramstops.
TheCLOSEstatementterminatestheconnectionofthespecifiedfiletoaunit.
CLOSE([UNIT=]u[,IOSTAT=ios][,ERR=errs][,STATUS=sta][,DISPOSE=sta][,DISP=sta])CLOSEtakesthestatusvaluesIOSTAT,ERR,andSTATUS,similartothosedescribedinTable5-1,"OPENSpecifiers".
Inaddition,CLOSEallowstheDISPOSEorDISPspecifierwhichcantakeastatusvaluestawhichisacharacterstring,wherecaseisinsignificant,specifyingthefilestatus(thesamekeywordsareusedfortheDISPandDISPOSEstatus).
StatuscanbeKEEPorDELETE.
KEEPcannotbespecifiedforafilewhosedisposestatusisSCRATCH.
WhenKEEPisspecified(forafilethatexists)thefilecontinuestoexistaftertheCLOSEstatement,converselyDELETEdeletesthefileaftertheCLOSEstatement.
ThedefaultvalueisKEEPunlessthefilestatusisSCRATCH.
InputandOutputFormatting148Table5-1:OPENSpecifiersSpecifierDescriptionACCESS=accWhereaccisacharacterstringspecifyingtheaccessmethodforfilecon-nectionasDIRECT(randomaccess)orSEQUENTIAL.
ThedefaultisSEQUENTIAL.
ACTION=actWhereactisacharacterstringspecifyingtheallowedactionsforthefileandisoneofREAD,WRITE,orREADWRITE.
BLANK=blnkWhereblnkisacharacterstringwhichtakesthevalueNULLorZERO:NULLcausesallblankcharactersinnumericformattedinputfieldstobeignoredwiththeexceptionofanall-blankfieldwhichhasavalueofzero.
ZEROcausesallblanksotherthanleadingblankstobetreatedaszeros.
ThedefaultisNULL.
Thisspecifiermustonlybeusedwhenafileisconnectedforformattedinput/output.
DELIM=delSpecifythedelimiterforcharacterconstantswrittenbyalist-directedornamelist-formattedstatement.
TheoptionsareAPOSTROPHE,QUOTE,andNONE.
ERR=errsAnerrorspecifierwhichtakestheformofastatementlabelofanexecut-ablestatementinthesameprogram.
Ifanerrorconditionoccurs,exe-cutioncontinueswiththestatementspecifiedbyerrs.
2FILE=finWherefinisacharacterstringdefiningthefilenametobeconnectedtothespecifiedunit.
FORM=fmWherefmisacharacterstringspecifyingwhetherthefileisbeingcon-nectedforFORMATTEDorUNFORMATTEDoutputrespectively.
ThedefaultisFORMATTED.
IOSTAT=iosInput/outputstatusspecifierwhereiosisanintegerscalarmemoryref-erence.
Ifthisisincludedinlist,iosbecomesdefinedwith0ifnoerrorexistsorapositiveintegerwhenthereisanerrorcondition.
1PAD=paddingSpecifieswhetherornottouseblankpaddingforinputitems.
Thepad-dingvaluesareYESandNO.
ThevalueNOrequiresthattheinputrecordandtheinputlistformatspecificationmatch.
DataTransferStatements149AunitmaybethesubjectofaCLOSEstatementfromwithinanymodule.
Iftheunitspecifieddoesnotexistorhasnofileconnectedtoit,theuseoftheCLOSEstatementhasnoeffect.
ProvidedthefileisstillinexistenceitmaybereconnectedtothesameoradifferentunitaftertheexecutionofaCLOSEstatement.
NotethatanimplicitCLOSEisexecutedwhenaprogramstops.
InthefollowingexamplethefileonUNIT6isclosedanddeleted.
CLOSE(UNIT=6,STATUS='DELETE')DataTransferStatementsOnceaunitisconnected,eitherusingapreconnection,orbyexecutinganOPENstatement,datatransferstatementsmaybeused.
Theavailabledatatransferstatementsinclude:READ,WRITE,andPRINT.
ThegeneralformforthesedatatransferstatementsisshowninChapter3,"FortranStatements";refertothatsectionfordetailsontheREAD,WRITEandPRINTstatementsandtheirvalidI/Ocontrolspecifiers.
POSITION=posSpecifiesthepositionofanopenedfile.
ASISindicatesthefilepositionremainsunchanged.
REWINDindicatesthefileistoberewound,andAPPENDindicatesthefileistopositionedjustbeforeanend-of-filerecord,oratitsterminalpoint.
RECL=rlWhererlisanintegerwhichdefinestherecordlengthinafileconnectedfordirectaccessandisthenumberofcharacterswhenformattedinput/outputisspecified.
Thisspecifiermustonlybegivenwhenafileiscon-nectedfordirectaccess.
STATUS=staThefilestatuswherestaisacharacterexpression:itcanbeNEW,OLD,SCRATCH,REPLACEorUNKNOWN.
WhenOLDorNEWisspecifiedafilespecifiermustbegiven.
SCRATCHmustnotbeusedwithanamedfile.
ThedefaultisUNKNOWN.
1.
IfIOSTATandERRarenotpresent,theprogramterminatesifanerroroccurs.
SpecifierDescriptionInputandOutputFormatting150UnformattedDataTransferUnformatteddatatransferallowsdatatobetransferredbetweenthecurrentrecordandtheitemsspecifiedinaninput/outputlist.
UseOPENtoopenafileforunformattedoutput:OPEN(2,FILE='new.
dat',FORM='UNFORMATTED')Theunitspecifiedmustbeanexternalunit.
Afterdataistransferred,thefileispositionedafterthelastrecordreadorwritten,ifthereisnoerrorconditionorend-of-fileconditionset.
Unformatteddatatransfercannotbecarriedoutifthefileisconnectedforformattedinput/output.
Thefollowingexampleshowsanunformattedinputstatement:READ(2,ERR=50)A,BOnoutputtoafileconnectedfordirectaccess,theoutputlistmustnotspecifymorevaluesthancanfitintoarecord.
Ifthevaluesspecifieddonotfilltherecordtherestoftherecordisundefined.
Oninput,thefilemustbepositionedsothattherecordreadiseither:Anunformattedrecordoranendfilerecord.
Thenumberofvaluesrequiredbytheinputlistintheinputstatementmustbelessthanorequaltothenumberofvaluesintherecordbeingread.
Thetypeofeachvalueintherecordmustagreewiththatofthecorrespondingentityintheinputlist.
Howeveronecomplexvaluemaycorrespondtotworeallistentitiesorviceversa.
IftheinputlistitemisoftypeCHARACTER,itslengthmustbethesameasthatofthecharactervalueIntheeventofanerrorcondition,thepositionofthefileisindeterminate.
FormattedDataTransferDuringformatteddatatransfer,dataiseditedtoconformtoaformatspecification,andtheediteddataistransferredbetweentheitemsspecifiedintheinputoroutputstatement'siolistandthefile;thecurrentrecordisreadorwrittenand,possibly,soareadditionalrecords.
Oninput,thefilemustbepositionedsothattherecordreadiseitheraformattedrecordoranendfilerecord.
Formatteddatatransferisprohibitedifthefileisconnectedforunformattedinput/output.
FormattedDataTransfer151Forvariablelengthrecordformattedinput,eachnewlinecharacterisinterpretedasarecordseparator.
Onoutput,theI/Osystemwritesanewlineattheendofeachrecord.
Ifaprogramwritesanewlineitself,thesinglerecordcontainingthenewlinewillappearastworecordswhenreadorbackspacedover.
Themaximumallowedlengthofarecordinavariablelengthrecordformattedfileis2000characters.
ImpliedDOListInputOutputListAnimpliedDOlisttakestheform(iolist,do-var=var1,var2,var3)wheretheitemsiniolistareeitheritemspermissibleinaninput/outputlistoranotherimpliedDOlist.
Thevaluedo-varisanINTEGER,REALorDOUBLEPRECISIONvariableandvar1,var2andvar3arearithmeticexpressionsoftypeINTEGER,REALorDOUBLEPRECISION.
Generally,do-var,var1,var2andvar3areoftypeINTEGER.
Shouldiolistoccurinaninputstatement,thedo-varcannotbeusedasaniteminiolist.
Ifvar3andtheprecedingcommaareomitted,theincrementtakesthevalue1.
ThelistitemsarespecifiedonceforeachiterationoftheDOloopwiththeDO-variablebeingsubstitutedasappropriate.
REALC(6),D(6)DATAOXO,(C(I),I=7,9),TEMP,(D(J),J=1,2)/4*0.
0,3*10.
0/IntheaboveexampleOXO,C(7),C(8)andC(9)aresetto0.
0withTEMP,D(1)andD(2)beingsetto10.
0.
Inthenextexample:READ*,A,B,(R(I),I=1,4),ShasthesameeffectasREAD*,A,B,R(1),R(2),R(3),R(4),SFormatSpecificationsFormatrequirementsmaybegiveneitherinanexplicitFORMATstatementoralternatively,asfieldswithinaninput/outputstatement(asvaluesincharactervariables,arraysorothercharacterexpressionswithintheinput/outputstatement).
Whenaformatidentifierinaformattedinput/outputstatementisacharacterarraynameorothercharacterexpression,theleftmostcharactersmustbedefinedwithcharacterdatathatconstituteaformatspecificationwhenthestatementisexecuted.
Acharacterformatspecificationisenclosedinparentheses.
Blanksmayprecedetheleftparenthesis.
Characterdatamayfollowtheright-handInputandOutputFormatting152parenthesisandhasnoeffectontheformatspecification.
Whenacharacterarraynameisusedasaformatidentifier,thelengthoftheformatspecificationcanexceedthelengthofthefirstelementofthearray;acharacterarrayformatspecificationisconsideredtobeanorderedconcatenationofallthearrayelements.
Whenacharacterarrayelementisusedasaformatidentifierthelengthmustnotexceedthatoftheelementused.
TheFORMATstatementhastheform:FORMAT(list-of-format-requirements)Thelistofformatrequirementscanbeanyofthefollowing,separatedbycommas:Repeatableeditorcommandswhichmayormaynotbeprecededbyanintegerconstantwhichdefinesthenumberofrepeats.
Non-repeatableeditorcommands.
Aformatspecificationlistenclosedinparentheses,optionallyprecededbyanintegerconstantwhichdefinesthenumberofrepeats.
EachactionofformatcontroldependsonaFORMATspecifiededitcodeandthenextitemintheinput/outputlistused.
Ifaninput/outputlistcontainsatleastoneitem,theremustbeatleastonerepeatableeditcodeintheformatspecification.
AnemptyformatspecificationFORMAT()canonlybeusedifnolistitemsarespecified.
Insuchacase,oneinputrecordisskippedoranoutputrecordcontainingnocharactersiswritten.
Unlesstheeditcodeortheformatlistisprecededbyarepeatspecification,aformatspecificationisinterpretedfromlefttoright.
Whenarepeatspecificationisused,theappropriateitemisrepeatedtherequirednumberoftimes.
Eachrepeatableeditcodehasacorrespondingitemintheiolist;howeverwhenalistitemisoftypecomplextwoeditcodesofF,E,DorGarerequired.
TheeditcodesP,X,T,TL,TR,S,SP,SS,H,BN,BZ,/,:andapostropheactdirectlyontherecordandhavenocorrespondingitemintheinput/outputlist.
ThefileispositionedafterthelastcharacterreadorwrittenwhentheeditcodesI,F,E,D,G,L,A,Horapostropheareprocessed.
Ifthespecifiedunitisaprinterthenthefirstcharacteroftherecordisusedtocontroltheverticalspacingasshowninthefollowingtable:FormattedDataTransfer153Table5-2:FormatCharacterControlsforaPrinterAFormatControl–CharacterDataTheAspecifiertransferscharacters.
TheAcanoptionallybefollowedbyafieldwidthw.
Whenwisnotspecified,thewidthisdeterminedbythesizeofthedataitem.
Onoutput,iflisthelengthofthecharacteritemandwisthefieldwidth,thenthefollowingrulesapply:Ifw>l,w–lblanksbeforethecharacter.
Ifwl,rightmostlcharactersfromtheinputfiled.
Ifw|significand|1.
ThisformatisthesameastheEformatdescriptor,exceptforrestrictionsonthesizeoftheexponentandthesignificand.
ESFormatControlTheESspecifiertransfersrealvaluesinscientificnotation.
TheESformatspecifierhastwobasicforms:ESw.
dESw.
dEewherewisthefieldwidth,dthenumberofdigitsinthefractionalpartandethenumberofdigitstobeprintedintheexponentpart.
Foroutput,thescalefactorcontrolsthedecimalnormalizationasintheDspecifier.
InputandOutputFormatting156Onoutput,thenumberispresentedinscientificnotation,wheretheabsolutevalueofthesignificandis10>|significand|1.
FFormatControl-RealSinglePrecisionDataTheFspecifiertransfersrealvalues.
TheformoftheFspecifieris:Fw.
dwherewisthefieldwidthanddisthenumberofdigitsinthefractionalpart.
Oninput,ifthefielddoesnotcontainadecimaldigitoranexponent,right-handddigits,withleadingzeros,areinterpretedasbeingthefractionalpart.
Onoutput,aleadingzeroisonlyproducedtotheleftofthedecimalpointifthevalueislessthanone.
GFormatControlTheGformatspecifierprovidesgeneralizededitingofrealdata.
TheGformathastwobasicforms:Gw.
dGw.
dEeThespecifiertransfersrealvalues;itactsliketheFformatcontroloninputanddependingonthevalue'smagnitude,likeEorFonoutput.
Themagnitudeofthedatadeterminestheoutputformat.
Fordetailsontheactualformatused,basedonthemagnitude,refertotheANSIFORTRANStandard(Section13.
5.
9.
2.
3GEditing).
IFormatControl–IntegerDataTheIformatspecifiertransfersintegervalues.
TheIformatspecifierhastwobasicforms:IwIw.
mwherewisthefieldwidthandmistheminimumfiledwidthonoutput,includingleadingzeros.
Ifpresent,mmustnotexceedwidthw.
Oninput,theexternalfieldtobeinputmustcontain(unsigned)decimalcharactersonly.
Anallblankfieldistreatedasavalueofzero.
Ifthevalueoftheexternalfieldexceedstherangeofthecorrespondinglistelement,anerroroccurs.
FormattedDataTransfer157Onoutput,theIformatdescriptortransfersthedecimalvaluesofthecorrespondingI/Olistelement,right-justified,toanexternalfieldthatiswcharacterslong.
Ifthevaluetobetransmitteddoesnotfillthefield,leadingspacesareinserted;ifthevalueistoolargeforthefield,theentirefieldisfilledwithasterisks.
Ifmispresent,theexternalfieldconsistsofatleastmdigits,andiszero-filledontheleftifnecessary.
Notethatifmiszero,andtheinternalrepresentationiszero,theexternalfieldisblank-filled.
LFormatControl–LogicalDataTheLformatcontroltransferslogicaldataoffieldwidthw:LwOninput,thelistitemwillbecomedefinedwithalogicalvalue;thefieldconsistsofoptionalblanks,followedbyanoptionaldecimalpointfollowedbyTorF.
Thevalues.
TRUE.
or.
FALSE.
mayalsoappearintheinputfieldTheoutputfieldconsistsofw-1blanksfollowedbyTorFasappropriate.
QuoteFormatControlQuoteeditingprintsacharacterconstant.
Theformatspecifierwritesthecharactersenclosedbetweenthequotesandcannotbeusedoninput.
Thefieldwidthisthatofthecharacterscontainedwithinquotes(youcanalsouseapostrophestoenclosethecharacterconstant).
Towriteanapostrophe(orquote),usetwoconsecutiveapostrophes(orquotes).
Forexample:WRITE(*,101)101FORMAT('Printanapostrophe''andend.
')Produces:Printanapostrophe'andend.
Similarly,youcanusequotes,forexample:WRITE(*,102)102FORMAT("Printalinewitha""andend.
")Produces:Printalinewitha"andend.
InputandOutputFormatting158BNFormatControl–BlankControlTheBNandBZformatscontrolblankspacing.
BNcausesallembeddedblanksexceptleadingblanksinnumericinputtobeignored,whichhastheeffectofright-justifyingtheremainderofthefield.
Notethatafieldofallblankshasthevaluezero.
OnlyinputstatementsandI,F,E,DandGeditingareaffected.
BZcausesallblanksexceptleadingblanksinnumericinputtobereplacedbyzeros.
OnlyinputstatementsandI,F,E,DandGeditingareaffected.
HFormatControl–HollerithControlTheHformatcontrolwritesthencharactersfollowingtheHintheformatspecificationandcannotbeusedoninput.
Thebasicformofthisformatspecificationis:nHc1cn.
.
.
wherenisthenumberofcharacterstoprintandc1throughcnarethecharacterstoprint.
OFormatControlOctalValuesTheOandZfielddescriptorstransferoctalorhexadecimalvaluesandcanbeusedwithanintegerdatatype.
Theyhavetheform:Ow[.
m]andZw[.
m]wherewspecifiesthefieldwidthandmindicatesminimumfieldwidthonoutput.
Oninput,theexternalfieldtobeinputmustcontain(unsigned)octalorhexadecimalcharactersonly.
Anallblankfieldistreatedasavalueofzero.
Ifthevalueoftheexternalfieldexceedstherangeofthecorrespondinglistelement,anerroroccurs.
Onoutput,theOandZfielddescriptorstransfertheoctalandhexadecimalvalues,respectively,ofthecorrespondingI/Olistelement,right-justified,toanexternalfieldthatiswcharacterslong.
Ifthevaluetobetransmitteddoesnotfillthefield,leadingspacesareinserted;ifthevalueistoolargeforthefield,theentirefieldisfilledwithasterisks.
Ifmispresent,theexternalfieldconsistsofatleastmdigits,andiszero-filledontheleftifnecessary.
Notethatifmiszero,andtheinternalrepresentationiszero,theexternalfieldisblank-filled.
FormattedDataTransfer159PFormatSpecifier–ScaleControlThePformatspecifierkPisthescalefactorformatwhichisappliedasfollows.
WithF,E,DandGeditingoninputandFeditingonoutput,theexternalnumberequalstheinternalnumbermultipliedby10**k.
Ifthereisanexponentinthefieldoninput,editingwithF,E,DandGthescalefactorhasnoeffect.
OnoutputwithEandDediting,thebasicrealconstantpartofthenumberismultipliedby10**kandtheexponentreducedbyk;withGeditingtheeffectofthescalefactorissuspendedunlessthesizeofthedatumtobeeditedisoutsidetherangepermittedforFediting.
IfEeditingisrequired,thescalefactorhasthesameeffectaswithEoutputediting.
Thefollowingisanexampleusingascalefactor.
DIMENSIONA(6)DO10I=1,610A(I)=25.
TYPE100,A100FORMAT('',F8.
2,2PF8.
2,F8.
2)produces:25.
002500.
002500.
002500.
002500.
002500.
00Notethattheeffectofthescalefactorcontinuesuntilanotherscalefactorisused.
QFormatControl-QuantityTheQeditdescriptorcalculatesthenumberofcharactersremainingintheinputrecordandstoresthatvalueinthenextI/Olistitem.
Onoutput,theQdescriptorskipsthenextI/Oitem.
SFormatControl–SignControlTheSformatspecifierrestoresthedefaultprocessingforwritingaplus;thedefaultisSSprocessing.
InputandOutputFormatting160SPforcestheprocessortowriteaplusinanypositionwhereanoptionalplusisfoundinnumericoutputfields,thisonlyaffectsoutputstatements.
SSstopstheprocessorfromwritingaplusinanypositionwhereanoptionalplusisfoundinnumericoutputfields,thisonlyaffectsoutputstatements.
T,TLandXFormatControls–SpacesandTabControlsTheTspecifiercontrolswhichportionofarecordinaniolistvalueisreadfromorwrittentoafile.
Thegeneralform,whichspecifiesthatthenthvalueistobewrittentoorfromarecord,isasfollows:TnTheTLformspecifiestherelativepositiontotheleftofthedatatobereadorwritten:TLnandspecifiesthatthenthcharactertotheleftofthecurrentpositionistobewrittentoorfromtherecord.
Ifthecurrentpositionislessthanorequalton,thetransmissionwillbeginatpositiononeoftherecord.
TheTRformspecifiestherelativepositiontotherightofthedatatobereadorwritten:TRnandspecifiesthatthenthcharactertotherightofthecurrentpositionistobewrittentoorfromtherecord.
TheXcontrolspecifiesanumberofcharacterstoskipforwardandthatthenextcharactertobewrittentoorfromisncharactersforwardfromthecurrentposition:nXThefollowingexampleusestheXformatspecifier:NPAGE=19WRITE(6,90)NPAGE90FORMAT('1PAGENUMBER,I2,16X,'SALESREPORT,Cont.
')produces:PAGENUMBER19SALESREPORT,Cont.
ThefollowingexampleshowsuseoftheTformatspecifier:FormattedDataTransfer161PRINT2525FORMAT(T41,'COLUMN2',T21,'COLUMN1')produces:COLUMN1COLUMN2ZFormatControlHexadecimalValuesTheOandZfielddescriptorstransferoctalorhexadecimalvaluesandcanbeusedwithanyintegerdatatype.
Theyhavetheform:Ow[.
m]andZw[.
m]wherewspecifiesthefieldwidthandmindicatesminimumfieldwidthonoutput.
Oninput,theexternalfieldtobeinputmustcontain(unsigned)octalorhexadecimalcharactersonly.
Anall-blankfieldistreatedasavalueofzero.
Ifthevalueoftheexternalfieldexceedstherangeofthecorrespondinglistelement,anerroroccurs.
Onoutput,theOandZfielddescriptorstransfertheoctalandhexadecimalvalues,respectively,ofthecorrespondingI/Olistelement,right-justified,toanexternalfieldthatiswcharacterslong.
Ifthevaluetobetransmitteddoesnotfillthefield,leadingspacesareinserted;ifthevalueistoolargeforthefield,theentirefieldisfilledwithasterisks.
Ifmispresent,theexternalfieldconsistsofatleastmdigits,andiszero-filledontheleftifnecessary.
Notethatifmiszero,andtheinternalrepresentationiszero,theexternalfieldisblank-filled.
SlashFormatControl/–EndofRecordTheslash(/)controlindicatestheendofdatatransferonthecurrentrecord.
Oninputfromafileconnectedforsequentialaccess,therestofthecurrentrecordisskippedandthefilepositionedatthestartofthenextrecord.
Onoutputanewrecordiscreatedwhichbecomesthelastandcurrentrecord.
Foraninternalfileconnectedfordirectaccess,therecordisfilledwithblankcharacters.
Foradirectaccessfile,therecordnumberisincreasedbyoneandthefileispositionedatthestartoftherecord.
Multipleslashesarepermitted,thusmultiplerecordsareskipped.
InputandOutputFormatting162The:FormatSpecifier–FormatTerminationThe(:)controlterminatesformatcontroliftherearenomoreitemsintheinput/outputlist.
Ithasnoeffectifthereareanyitemsleftinthelist.
$FormatControlThe$fielddescriptorallowstheprogrammertocontrolcarriagecontrolconventionsonoutput.
Itisignoredoninput.
Forexample,onterminaloutput,itcanbeusedforprompting.
Theformofthe$fielddescriptoris:$VariableFormatExpressions,Variableformatexpressionsaresupported.
Theyprovideameansforsubstitutingrun-timeexpressionsforthefieldwidth,otherparametersforthefieldandeditdescriptorsinaFORMATstatement(exceptfortheHfielddescriptorandrepeatcounts).
Variableformatexpressionsareenclosedin""andareevaluatedeachtimetheyareencounteredinthescanofaformat.
IfthevalueofavariableusedintheexpressionchangesduringtheexecutionoftheI/Ostatement,thenewvalueisusedthenexttimetheformatitemcontainingtheexpressionisprocessed.
Non-advancingInputandOutputNon-advancinginput/outputischaracter-orientedandappliestosequentialaccessformattedexternalfiles.
Thefilepositionisafterthelastcharacterreadorwrittenandnotautomaticallyadvancedtothenextrecord.
Fornon-advancinginput/output,usetheADVANCE='NO'specifier.
Twootherspecifiersapplytonon-advancingIO:EORapplieswhenendofrecordisdetectedandSIZEreturnsthenumberofcharactersread.
List-directedformatting163List-directedformattingList-directedformattingisanabbreviatedformofinput/outputthatdoesnotrequiretheuseofaformatspecification.
Thetypeofthedataisusedtodeterminehowavalueisread/written.
Onoutput,itwillnotalwaysbeaccurateenoughforcertainrangesofvalues.
Thecharactersinalist-directedrecordconstituteasequenceofvalueswhichcannotcontainembeddedblanksexceptthosepermittedwithinacharacterstring.
Touselist-directedinput/outputformatting,specifya*forthelistofformatrequirements.
Forexample,thefollowingexampleuseslist-directedoutput:READ(1,*)VAL1,VAL2List-directedinputTheformofthevaluebeinginputmustbeacceptableforthetypeofitemintheiolist.
Blanksmustnotbeusedaszerosnorbeembeddedinconstantsexceptinacharacterconstantorwithinatypecomplexformcontainedinparentheses.
InputandOutputFormatting164Table5-3:ListDirectedInputValuesAnullvaluehasnoeffectonthedefinitionstatusofthecorrespondingiolistitem.
Anullvaluecannotrepresentjustonepartofacomplexconstantbutmayrepresenttheentirecomplexconstant.
Aslashencounteredasavalueseparatorstopstheexecutionofthatinputstatementaftertheassignmentofthepreviousvalue.
Iftherearefurtheritemsinthelist,theyaretreatedasiftheyarenullvalues.
Commasmaybeusedtoseparatetheinputvalues.
Ifthereareconsecutivecommas,orifthefirstnon-blankcharacterofarecordisacomma,theinputvalueisanullvalue.
Inputvaluesmayalsoberepeated.
Inthefollowingexampleoflist-directedformatting,assumethatA=-1.
5K=125andallothervariablesareundefined.
Whenthestatementbelowreadsinthelistfromtheinputfile:READ*I,J,X,Y,Z,A,C,Kwherethefilecontainsthefollowingrecord:10,-14,25.
2,-76,313,,29/InputListTypeFormIntegerAnumericinputfield.
RealAnumericinputfieldsuitableforFeditingwithnofrac-tionalpartunlessadecimalpointisused.
DoubleprecisionSameasforreal.
ComplexAnorderedpairofnumberscontainedwithinparenthesesasshown(realpart,imaginarypart).
LogicalAlogicalfieldwithoutanyslashesorcommas.
CharacterAnon-emptycharacterstringwithinapostrophes.
Achar-acterconstantcanbecontinuedonasmanyrecordsasrequired.
Blanks,slashesandcommascanbeused.
List-directedformatting165Thevariablesareassignedthefollowingvaluesbythelist-directedinput/outputmechanism:I=10J=-14X=25.
2Y=-76.
0Z=313.
0A=-1.
5C=29K=125.
NotethatthevalueforAdoesnotchangebecausetheinputrecordisnull(consecutivecommas).
NoinputisreadforK,soitassumesnullandKretainsitspreviousvalue(the/terminatestheinput).
List-directedoutputListdirectedinput/outputisanabbreviatedformofformattedinput/outputthatdoesnotrequiretheuseofaformatspecification.
Dependingonthetypeofthedataitemordataitemsintheiolist,dataistransferredtoorfromthefile,usingadefault,andnotnecessarilyaccurateformatspecification.
Thedatatypeofeachitemappearingintheiolistisformattedaccordingtotherulesinthefollowingtable:InputandOutputFormatting166Table5-4:DefaultListDirectedOutputFormattingThelengthofarecordislessthan80characters;iftheoutputofanitemwouldcausethelengthtoexceed80characters,anewrecordiscreated.
Issuestonotewhenusinglist-directedoutput:Newrecordsmaybeginasnecessary.
LogicaloutputconstantsareTfortrueandFforfalse.
DataTypeDefaultFormattingBYTEI5INTEGER*2I7INTEGER*4I12INTEGER*8I24LOGICAL*1I5(L21)1.
Thisformatisappliedwhentheoption–Munixlogicalisselectedwhencompiling.
LOGICAL*2L2LOGICAL*4L2LOGICAL*8L2REAL*4G15.
7e2REAL*8G25.
16e3COMPLEX*8(G15.
7e2,G15.
7e2)COMPLEX*16(G25.
16e3,G25.
16e3)CHAR*nAnNamelistGroups167Complexconstantsarecontainedwithinparentheseswiththerealandimaginarypartsseparatedbyacomma.
Characterconstantsarenotdelimitedbyapostrophesandhaveeachinternalapostrophe(ifanyarepresent)representedexternallybyoneapostrophe.
Eachoutputrecordbeginswithablankcharactertoprovidecarriagecontrolwhentherecordisprinted.
Atypelessvalueoutputwithlist-directedI/Oisoutputinhexadecimalformbydefault.
Thereisnootheroctalorhexadecimalcapabilitywithlist-directedI/O.
CommasinExternalFieldUseofthecommainanexternalfieldeliminatestheneedto"countspaces"tohavedatamatchformateditdescriptors.
Theuseofacommatoterminateaninputfieldandthusavoidpaddingthefieldisfullysupported.
NamelistGroupsTheNAMELISTstatementallowsforthedefinitionofnamelistgroups.
Anamelistgroupallowsforaspecialtypeofformattedinput/output,wheredataistransferredbetweenanamedgroupofdataitemsdefinedinaNAMELISTstatementandoneormorerecordsinafile.
Thegeneralformofanameliststatementis:NAMELIST/group-name/namelist[[,]/group-name/namelist].
.
.
where:group-nameisthenameofthenamelistgroup.
namelististhelistofvariablesinthenamelistgroup.
NamelistInputNamelistinputisaccomplishedusingaREADstatementbyspecifyinganamelistgroupastheinputitem.
Thefollowingstatementshowstheformat:READ([unit=]u,[NML=]namelist-group[,control-information])Oneormorerecordsareprocessedwhichdefinetheinputforitemsinthenamelistgroup.
InputandOutputFormatting168Therecordsarelogicallyviewedasfollows:$group-nameitem=value[,item=value]END]Thefollowingrulesdescribetheseinputrecords:1.
Thestartorenddelimiter($)maybeanampersand(&).
2.
Thestartdelimitermustbeginincolumn2ofarecord.
3.
Thegroup-namebeginsimmediatelyafterthestartdelimiter.
4.
Thespacesortabsmaynotappearwithinthegroup-name,withinanyitem,orwithinanyconstants.
5.
Thevaluemaybeconstantsasareallowedforlistdirectedinput,ortheymaybealistofconstantsseparatedbycommas(,).
Alistofitemsisusedtoassignconsecutivevaluestoconsecutiveelementsofanarray.
6.
Spacesortabsmayprecedetheitem,the=andtheconstants.
7.
Arrayitemsmaybesubscripted.
8.
Characteritemsmaybesubstringed.
NamelistOutputNamelistoutputisaccomplishedusingaREADstatementbyspecifyinganamelistgroupastheoutputitem.
Thefollowingstatementshowstheformat:WRITE([unit=]u,[NML=]namelist-group[,control-information])Therecordsoutputarelogicallyviewedasfollows:$group-nameitem=value$[END]Thefollowingrulesdescribetheseoutputrecords:1.
Onerecordisoutputpervalue.
2.
Multiplevaluesareseparatedbyacomma(,).
NamelistGroups1693.
Valuesareformattedaccordingtotherulesofthelist-directedwrite.
Exception:characteritemsaredelimitedbyanapostrophe(').
4.
Anapostrophe(')oraquote(")inthevalueisrepresentedbytwoconsecutiveapostrophesorquotes.
InputandOutputFormatting170FORTRAN77andFortran90/95IntrinsicsbyCategory1716FortranIntrinsicsThischapterliststheFORTRAN77andFortran90/95intrinsicsandsubroutines,intrinsicsdefinedintheHPFLanguageSpecification,andCMFortranintrinsics.
Color-codingisusedtohighlightthedifferentFortranversions.
Thecolorsusedareasfollows:FORTRAN77isshowninblackFortran90/95isshowninblueHPFisshowninredCMFortranisshowningreenFORTRAN77andFortran90/95IntrinsicsbyCategoryThetablesinthissectioncontaintheFORTRAN77andFortran90/95intrinsicssupportedbythePGF77andPGF95compilers.
Intrinsicsarecategorizedbyfunctionalityandalphabetizedbygenericnamewithineachtable.
AllFORTRAN77intrinsicsaresupportedandaredetailedintheANSIFORTRANStandard.
Tosimplifythetablesinthissection,twogroupsofintrinsictypeshavebeengiventhefollowingabbreviatedgroupnames:NUMERICINTEGER,REAL,COMPLEXNONCHARLOGICAL,INTEGER,REAL,COMPLEXFortranIntrinsics172Table6-1:NumericFunctionsGenericNamePurposeNumberofArgsSpecificNameArgumentTypeResultTypeABSAbsoluteValue1NUMERICNUMERIC1IIABSINTEGER*2INTEGER*21JIABSINTEGER*4INTEGER*41KIABSINTEGER*8INTEGER*81ABSREAL*4REAL*41DABSREAL*8REAL*81CABCOMPLEX*8COMPLEX*81CDABSCOMPLEX*16COMPLEX*16AIMAGImaginaryPartofCom-plexNumber1AIMAGCOMPLEX*8REAL*41DIMAGCOMPLEX*16REAL*8AINTTruncation1AINTREAL*4REAL*41DINTREAL*8REAL*8ANINTNearestWholeNumber1ANINTREAL*4REAL*41DNINTREAL*8REAL*8CEILINGNextWholeNumber1REALINTEGER2REAL,INTEGERINTEGERCMPLXConverttoCOMPLEX*81NUMERICCOMPLEX*82INTEGER,INTEGERCOMPLEX*82REAL,REALCOMPLEX*8FORTRAN77andFortran90/95IntrinsicsbyCategory173CONJGComplexCon-jugate1CONJGCOMPLEX*8COMPLEX*81DCONJGCOMPLEX*16COMPLEX*16DBLEConverttoREAL*81NUMERICREAL*81DFLOTIINTEGER*2REAL*81DFLOATINTEGER*4REAL*81DFLOTJINTEGER*4REAL*81DFLOTKINTEGER*8REAL*81DREALCOMPLEX*16REAL*8DCMPLXConverttoCOMPLEX*161NUMERICCOMPLEX*162INTEGER,INTEGERCOMPLEX*162REAL,REALCOMPLEX*16DIMPositiveDif-ference2IIDIMINTEGER*2,INTE-GER*2INTEGER*22JIDIMINTEGER*4,INTE-GER*4INTEGER*42KIDIMINTEGER*8,INTE-GER*8INTEGER*82DIMREAL*4,REAL*4REAL*42DDIMREAL*8,REAL*8REAL*8FLOORPreviousinte-ger1REALINTEGER2REAL,INTEGERINTEGERGenericNamePurposeNumberofArgsSpecificNameArgumentTypeResultTypeFortranIntrinsics174IINTTruncation1NUMERICINTEGER*21IINTREAL*4INTEGER*21IIFIXREAL*4INTEGER*21IIDINTREAL*8INTEGER*2ININTNearestInte-ger[a+.
5*sign(a)]1ININTREAL*4INTEGER*21IIDNNTREAL*8INTEGER*2INTTruncation1NUMERICINTEGER*41JIFIXREAL*4INTEGER*41IDINTREAL*8INTEGER*4INT8Truncation1REAL*4INTEGER*81KIFIXREAL*4INTEGER*8IZEXTZero-ExtendFunction(Conversion)1LOGICAL*1INTEGER*21LOGICAL*2INTEGER*21INTEGER*2INTEGER*2JINTTruncation1NUMERICINTEGER*41JINTREAL*4INTEGER*41JIDINTREAL*8INTEGER*4JNINTNearestInte-ger[a+.
5*sign(a)]1REALINTEGER*41JIDNNTREAL*8INTEGER*4KNINTNearestInte-ger[a+.
5*sign(a)]1REALINTEGER*81KIDNNTREAL*8INTEGER*8GenericNamePurposeNumberofArgsSpecificNameArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory175MAXMaximumn>1IMAX0INTEGER*2INTEGER*2n>1IMAX1REAL*4INTEGER*2n>1AIMAX0INTEGER*2REAL*4n>1JMAX0INTEGER*4INTEGER*4n>1INTEGER*8INTEGER*8n>1JMAX1REAL*4INTEGER*4n>1KMAX1REAL*4INTEGER*8n>1AJMAX0INTEGER*4REAL*4n>1AKMAX0INTEGER*8REAL*4n>1MAX0INTEGER*4INTEGER*4n>1AMAX1REAL*4REAL*4n>1DMAX1REAL*8REAL*8GenericNamePurposeNumberofArgsSpecificNameArgumentTypeResultTypeFortranIntrinsics176MINMinimumn>1IMIN0INTEGER*2INTEGER*2n>1IMIN1REAL*4INTEGER*2n>1AIMIN0INTEGER*2REAL*4n>1JMIN0INTEGER*4INTEGER*4n>1INTEGER*8INTEGER*8n>1JMIN1REAL*4INTEGER*4n>1KMIN1REAL*4INTEGER*8n>1AJMIN0INTEGER*4REAL*4n>1MIN0INTEGER*4INTEGER*4n>1AMIN1REAL*4REAL*4n>1AKNIN0INTEGER*8REAL*4n>1DMIN1REAL*8REAL*8MODRemainder2IMODINTEGER*2,INTE-GER*2INTEGER*22JMODINTEGER*4,INTE-GER*4INTEGER*42KMODINTEGER*8,INTE-GER*8INTEGER*82AMODREAL*4,REAL*4REAL*42DMODREAL*8,REAL*4REAL*8GenericNamePurposeNumberofArgsSpecificNameArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory177MODULOFortran90/95Modulo2INTEGER*2,INTE-GER*2INTEGER*22INTEGER*4,INTE-GER*4INTEGER*42INTEGER*8,INTE-GER*8INTEGER*82REAL*4,REAL*4REAL*42REAL*8,REAL*4REAL*8NINTNearestInte-ger[a+.
5*sign(a)]1REALINTEGER*41IDNINTREAL*8INTEGER*4REALConverttoREAL*41NUMERICREAL*41FLOATIINTEGER*2REAL*41FLOATINTEGER*2REAL*41REALINTEGER*4REAL*41FLOATJINTEGER*4REAL*41FLOATKINTEGER*8REAL*41SNGLREAL*8REAL*4SIGNTransferofSign2IISIGNINTEGER*2INTEGER*22JISIGNINTEGER*4INTEGER*42KISIGNINTEGER*8INTEGER*82SIGNREAL*4REAL*42DSIGNREAL*8REAL*8GenericNamePurposeNumberofArgsSpecificNameArgumentTypeResultTypeFortranIntrinsics178ZEXTZero-ExtendFunction(Conversion)1JZEXTLOGICAL*1INTEGER*41LOGICAL*2INTEGER*41LOGICAL*4INTEGER*41INTEGER*2INTEGER*41INTEGER*4INTEGER*4GenericNamePurposeNumberofArgsSpecificNameArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory179Table6-2:MathematicalFunctionsGenericNamePurposeNumberofArgsSpecificNameArgumentTypeResultTypeACOSArcCosine1ACOSREAL*4REAL*41DACOSREAL*8REAL*8ACOSDArcCosine(degree)1ACOSDREAL*4REAL*41DACOSDREAL*8REAL*8ASINArcSine1ASINREAL*4REAL*41DASINREAL*8REAL*8ASINDArcSine(degree)1ASINDREAL*4REAL*41DASINDREAL*8REAL*8ATANArcTangent1ATANREAL*4REAL*41DATANREAL*8REAL*8ATAN2ArcTangent2ATAN2REAL*4,REAL*4REAL*42DATAN2REAL*8,REAL*8REAL*8ATAN2DArcTangent(degree)2ATAN2DREAL*4,REAL*4REAL*42DATAN2DREAL*8,REAL*8REAL*8ATANDArcTangent(degree)1ATANDREAL*4REAL*41DATANDREAL*8REAL*8COSCosine1COSREAL*4REAL*41DCOSREAL*8REAL*81CCOSCOMPLEX*8COMPLEX*81CDCOSCOMPLEX*16COMPLEX*16FortranIntrinsics180COSDCosine(degree)1COSDREAL*4REAL*41DCOSDREAL*8REAL*8COSHHyperbolicCosine1COSHREAL*4REAL*41DCOSHREAL*8REAL*8DPRODProduct2REAL*4,REAL*4REAL*8EXPExponential1EXPREAL*4REAL*41DEXPREAL*8REAL*81CEXPCOMPLEX*8COMPLEX*81CDEXPCOMPLEX*16COMPLEX*16LOGNaturalLoga-rithm1ALOGREAL*4REAL*41DLOGREAL*8REAL*81CLOGCOMPLEX*8COMPLEX*81CDLOGCOMPLEX*16COMPLEX*16LOG10CommonLoga-rithm1ALOG10REAL*4REAL*41DLOG10REAL*8REAL*8SINSine1SINREAL*4REAL*41DSINREAL*8REAL*81CSINCOMPLEX*8COMPLEX*81CDSINCOMPLEX*16COMPLEX*16SINDSine(degree)1SINDREAL*4REAL*41DSINDREAL*8REAL*8GenericNamePurposeNumberofArgsSpecificNameArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory181SINHHyperbolicSine1SINHREAL*4REAL*41DSINHREAL*8REAL*8SQRTSquareRoot1SQRTREAL*4REAL*41DSQRTREAL*8REAL*81CSQRTCOMPLEX*8COMPLEX*81REAL*8COMPLEX*16COMPLEX*16TANTangent1TANREAL*4REAL*41DTANREAL*8REAL*8TANDTangent(degree)1TANDREAL*4REAL*41DTANDREAL*8REAL*8TANHHyperbelicTan-gent1TANHREAL*4REAL*41DTANHREAL*8REAL*8GenericNamePurposeNumberofArgsSpecificNameArgumentTypeResultTypeFortranIntrinsics182Table6-3:RealManipulationFunctionsTable6-4:BitManipulationFunctionsGenericNamePurposeNumberofArgsArgumentTypeResultTypeEXPONENTExponentpart1REALINTEGERFRACTIONFractionalpart1REALINTEGERNEARESTNearestdifferentmachine-represent-ablenumber2REAL,REALREALRRSPACINGReciprocalofrela-tivespacing1REALREALSCALEValueofexponentpartchangedbyaspecifiedvalue2REAL,INTEGERREALSET_EXPONENTValueofexponentpartsettoaspeci-fiedvalue2REAL,INTEGERREALSPACINGSpacingnearargu-ment1REALREALGenericNamePurposeNum.
ArgsSpecificNameArgumentTypeResultTypeANDLogicalAND2any1,any***'any,any'onpage186***typelessBIT_SIZEPrecision(inbits)1INTEGERINTEGERFORTRAN77andFortran90/95IntrinsicsbyCategory183BTESTBitTest2INTEGER,INTEGERLOGICAL2BITESTINTEGER*2,INTEGER*2LOGICAL*22BJTESTINTEGER*4,INTEGER*4LOGICAL*42KBTESTINTEGER*8,INTEGER*8LOGICAL*8COMPLLogicalComple-ment1any***'any,any***'any,any'onpage186***'onpage186***typelessEQVLogicalExclusiveNor2any***'any,any***'any,any'onpage186***'onpage186***,any***'any,any***'any,any'onpage186***'onpage186***typelessIANDLogicalAND2INTEGER,INTEGERINTE-GER*2,INTEGER2IIANDINTEGER*2INTEGER*22JIANDINTEGER*4,INTEGER*4INTEGER*42KIANDINTEGER*8,INTEGER*8INTEGER*8IBCLRBitClear2INTEGER,INTEGERINTEGER2IIBCLRINTEGER*2,INTEGER*2INTEGER*22JIBCLRINTEGER*4,INTEGER*4INTEGER*42KIBCLRINTEGER*8,INTEGER*8INTEGER*8GenericNamePurposeNum.
ArgsSpecificNameArgumentTypeResultTypeFortranIntrinsics184IBITSBitExtrac-tion3INTEGER,INTEGER,INTE-GERINTEGER3IIBITSINTEGER*2,INTEGER*2,INTEGER*2INTEGER*23JIBITSINTEGER*4,INTEGER*4,INTEGER*4INTEGER*43KIBITSINTEGER*8,INTEGER*8,INTEGER*8INTEGER*8IBSETBitSet2INTEGER,INTEGERINTEGER2IIBSETINTEGER*2,INTEGER*2INTEGER*22JIBSETINTEGER*4,INTEGER*4INTEGER*42KIBSETINTEGER*8,INTEGER*8INTEGER*8IEORLogicalXOR2INTEGER,INTEGERINTEGER2IIEORINTEGER*2,INTEGER*2INTEGER*2IORLogicalOR2INTEGER,INTEGERINTEGER2IIORINTEGER*2,INTEGER*2INTEGER*22JIORINTEGER*4,INTEGER*4INTEGER*42KIORINTEGER*8,INTEGER*8INTEGER*8ISHFTLogicalShift2INTEGER,INTEGERINTEGER2IISHFTINTEGER*2,INTEGER*2INTEGER*22JISHFTINTEGER*4,INTEGER*4INTEGER*42KISHFTINTEGER*8,INTEGER*8INTEGER*8GenericNamePurposeNum.
ArgsSpecificNameArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory185ISHFTCCircularShift3INTEGER,INTEGERINTEGER3IISHFTCINTEGER*2,INTEGER*2,INTEGER*2INTEGER*23JISHFTCINTEGER*4,INTEGER*4,INTEGER*4INTEGER*43KISHFTCINTEGER*8,INTEGER*8,INTEGER*8INTEGER*8LSHIFTLogicalLeftShift2INTEGER,INTEGERINTEGERNEQVLogicalExclusiveOR2any***'any,any***'any,any'onpage186***'onpage186***,any***'any,any***'any,any'onpage186***'onpage186***typelessNOTLogicalComple-ment1INTEGERINTEGER1INOTINTEGER*2INTEGER*21JNOTINTEGER*4INTEGER*41KNOTINTEGER*8INTEGER*8ORLogicalOR2any***'any,any***'any,any'onpage186***'onpage186***,any***'any,any***'any,any'onpage186***'onpage186***typelessRSHIFTLogicalRightShift2INTEGER,INTEGERINTEGERGenericNamePurposeNum.
ArgsSpecificNameArgumentTypeResultTypeFortranIntrinsics186Table6-5:Fortran90/95BitManipulationSubroutineThefunctionsinthefollowingtablearespecifictoFortran90/95unlessotherwisespecified.
SHIFTLogicalShift2any2,INTEGERtypelessXORLogicalExclusiveOR2INTEGER,INTEGERINTEGERJIEORINTEGER*4,INTEGER*4INTEGER*41.
ArgumentstotheintrinsicsAND,COMPL,EQV,OR,andNEQVmaybeofanytypeexceptforCHARACTERandCOMPLEX.
2.
ThefirstargumenttotheSHIFTintrinsicmaybeofanytypeexceptforCHARACTERandCOMPLEX.
GenericNamePurposeArgumentsMVBITSCopiesbitsequenceINTEGER(IN),INTEGER(IN),INTEGER(IN),INTE-GER(INOUT),INTEGER(IN)GenericNamePurposeNum.
ArgsSpecificNameArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory187Table6-6:ElementalCharacterandLogicalFunctionsGenericNamePurposeNum.
ArgsArgumentTypeResultTypeACHARReturncharac-terinspecifiedASCIIcollatingposition.
1INTEGERCHARACTERADJUSTLLeftadjuststring1CHARACTERCHARACTERADJUSTRRightadjuststring1CHARACTERCHARACTERCHAR(f77)Returncharac-terwithspeci-fiedASCIIvalue.
1LOGICAL*1CHARACTER1INTEGERCHARACTERIACHARReturnpositionofcharacterinASCIIcollatingsequence.
1CHARACTERINTEGERICHARReturnpositionofcharacterinthecharacterset'scollatingsequence.
1CHARACTERINTEGERINDEXReturnstartingpositionofsub-stringwithinfirststring.
2CHARACTER,CHARACTERINTEGER3CHARACTER,CHARACTER,LOGICALINTEGERLEN_TRIMReturnlengthofstringminustrailingblanks.
1CHARACTERINTEGERFortranIntrinsics188LGELexicalcompar-ison2CHARACTER,CHARACTERLOGICALLGTLexicalcompar-ison2CHARACTER,CHARACTERLOGICALLLELexicalcompar-ison2CHARACTER,CHARACTERLOGICALLLTLexicalcompar-ison2CHARACTER,CHARACTERLOGICALLOGICALLogicalconver-sion1LOGICALLOGICAL2LOGICAL,INTEGERLOGICALSCANScanstringforcharactersinset2CHARACTER,CHARACTERINTEGER3CHARACTER,CHARACTER,LOGICALINTEGERVERIFYDetermineifstringcontainsallcharactersinset2CHARACTER,CHARACTERINTEGER3CHARACTER,CHARACTER,LOGICALINTEGERGenericNamePurposeNum.
ArgsArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory189Table6-7:Fortran90/95Vector/MatrixFunctionsTable6-8:Fortran90/95ArrayReductionFunctionsGenericNamePurposeNumberofArgsArgumentTypeResultTypeDOT_PRODUCTPerformdotproductontwovectors2NONCHAR*K,NONCHAR*KNONCHAR*KMATMULPerformmatrixmultiplyontwomatrices2NONCHAR*K,NONCHAR*KNONCHAR*KGenericNamePurposeNumberofArgsArgumentTypeResultTypeALLDetermineifallarrayvaluesaretrue1LOGICALLOGICAL2LOGICAL,INTEGERLOGICALANYDetermineifanyarrayvalueistrue1LOGICALLOGICAL2LOGICAL,INTEGERLOGICALCOUNTCounttrueval-uesinarray1LOGICALINTEGER2LOGICAL,INTEGERINTEGERFortranIntrinsics190MAXLOCDetermineposi-tionofarrayele-mentwithmaximumvalue1INTEGERINTEGER2INTEGER,LOGICALINTEGER2INTEGER,INTEGERINTEGER3INTEGER,INTEGER,LOGICALINTEGER1REALINTEGER2REAL,LOGICALINTEGER2REAL,INTEGERINTEGER3REAL,INTEGER,LOGICALINTEGERMAXVALDeterminemax-imumvalueofarrayelements1INTEGERINTEGER2INTEGER,LOGICALINTEGER2INTEGER,INTEGERINTEGER3INTEGER,INTEGER,LOGICALINTEGER1REALREAL2REAL,LOGICALREAL2REAL,INTEGERREAL3REAL,INTEGER,LOGICALREALGenericNamePurposeNumberofArgsArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory191MINLOCDetermineposi-tionofarrayele-mentwithminimumvalue1INTEGERINTEGER2INTEGER,LOGICALINTEGER2INTEGER,INTEGERINTEGER3INTEGER,INTEGER,LOGICALINTEGER1REALINTEGER2REAL,LOGICALINTEGER2REAL,INTEGERINTEGER3REAL,INTEGER,LOGICALINTEGERMINVALDeterminemini-mumvalueofarrayelements1INTEGERINTEGER2INTEGER,LOGICALINTEGER2INTEGER,INTEGERINTEGER3INTEGER,INTEGER,LOGICALINTEGER1REALREAL2REAL,LOGICALREAL2REAL,INTEGERREAL3REAL,INTEGER,LOGICALREALPRODUCTCalculatetheproductoftheelementsofanarray1NUMERICNUMERIC2NUMERIC,LOGICALNUMERIC2NUMERIC,INTEGERNUMERIC3NUMERIC,INTEGER,LOGICALNUMERICGenericNamePurposeNumberofArgsArgumentTypeResultTypeFortranIntrinsics192SUMCalculatethesumoftheele-mentsofanarray1NUMERICNUMERIC2NUMERIC,LOGICALNUMERIC2NUMERIC,INTEGERNUMERIC3NUMERIC,INTEGER,LOGICALNUMERICGenericNamePurposeNumberofArgsArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory193Table6-9:Fortran90/95StringConstructionFunctionsTable6-10:Fortran90/95ArrayConstruction/ManipulationFunctionsGenericNamePurposeNumberofArgsArgumentTypeResultTypeREPEATConcatenatecopiesofastring2CHARACTER,INTEGERCHARACTERTRIMRemovetrailingblanksfromastring1CHARACTERCHARACTERGenericNamePurposeNumberofArgsArgumentTypeResultTypeCSHIFTPerformcir-cularshiftonarray2ARRAY,INTEGERARRAY***'any,any,LOGICAL'onpage196***3ARRAY,INTEGER,INTEGERARRAY***'any,any,LOGICAL'onpage196***FortranIntrinsics194EOSHIFTPerformend-offshiftonarray2ARRAY,INTEGERARRAY***'any,any,LOGICAL'onpage196***3ARRAY,INTEGER,any***'any,any,LOGICAL'onpage196***ARRAY***'any,any,LOGICAL'onpage196***3ARRAY,INTEGER,INTEGERARRAY***'any,any,LOGICAL'onpage196***4ARRAY,INTEGER,any***'any,any,LOGICAL'onpage196***,INTEGERARRAY***'any,any,LOGICAL'onpage196***MERGEMergetwoargumentsbasedonlogi-calmask3any,any1,LOGICALany***'any,any,LOGICAL'onpage196***GenericNamePurposeNumberofArgsArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory195PACKPackarrayintorank-onearray2ARRAY,LOGICALARRAY***'any,any,LOGICAL'onpage196***3ARRAY,LOGICAL,VECTOR***'any,any,LOGICAL'onpage196***ARRAY***'any,any,LOGICAL'onpage196***RESHAPEChangetheshapeofanarray2ARRAY,INTEGERARRAY***'any,any,LOGICAL'onpage196***3ARRAY,INTEGER,ARRAY***'any,any,LOGICAL'onpage196***ARRAY***'any,any,LOGICAL'onpage196***3ARRAY,INTEGER,INTEGERARRAY***'any,any,LOGICAL'onpage196***4ARRAY,INTEGER,ARRAY***'any,any,LOGICAL'onpage196***,INTEGERARRAY***'any,any,LOGICAL'onpage196***GenericNamePurposeNumberofArgsArgumentTypeResultTypeFortranIntrinsics196SPREADReplicatesanarraybyadd-ingadimen-sion3any,INTEGER,INTEGERARRAY***'any,any,LOGICAL'onpage196***TRANS-POSETransposeanarrayofranktwo1ARRAYARRAY***'any,any,LOGICAL'onpage196***UNPACKUnpackarank-onearrayintoanarrayofmul-tipledimen-sions3VECTOR,LOGICAL,ARRAY***'any,any,LOGICAL'onpage196***ARRAY***'any,any,LOGICAL'onpage196***1.
Mustbeofthesametypeasthefirstargument.
GenericNamePurposeNumberofArgsArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory197Table6-11:Fortran90/95GeneralInquiryFunctionsTable6-12:Fortran90/95NumericInquiryFunctionsGenericNamePurposeNumberofArgsArgumentTypeResultTypeASSOCIATEDDetermineassociationstatus12POINTERPOINTER,TAR-GETLOGICAL-LOGICALKINDDetermineargument'skind1anyintrinsictypeINTEGERPRESENTDeterminepresenceofoptionalargument1anyLOGICALGenericNamePurposeNumberofArgsArgumentTypeResultTypeDIGITSDeterminenum-berofsignificantdigits1INTEGERINTEGER1REALINTEGEREPSILONSmallestrepresent-ablenumber1REALREALHUGELargestrepresent-ablenumber1INTEGERINTEGER1REALREALMAXEXPONENTValueofmaxi-mumexponent1REALINTEGERMINEXPONENTValueofminimumexponent1REALINTEGERPRECISIONDecimalprecision1REALINTEGER1COMPLEXINTEGERFortranIntrinsics198RADIXBaseofmodel1INTEGERINTEGER1REALINTEGERRANGEDecimalexponentrange1INTEGERINTEGER1REALINTEGER1COMPLEXINTEGERSELECTED_INT_KINDKindtypetitleme-terinrange1INTEGERINTEGERSELECTED_REAL_KINDKindtypetitleme-terinrange1INTEGERINTEGER2INTEGER,INTEGERINTEGERTINYSmallestrepresent-ablepositivenum-ber1REALREALGenericNamePurposeNumberofArgsArgumentTypeResultTypeFORTRAN77andFortran90/95IntrinsicsbyCategory199Table6-13:Fortran90/95ArrayInquiryFunctionsTable6-14:Fortran90/95StringInquiryFunctionTable6-15:Fortran90/95SubroutinesGenericNamePurposeNumberofArgsArgumentTypeResultTypeALLOCATEDDetermineifarrayisallo-cated1ARRAYLOGICALLBOUNDDeterminelowerbounds1ARRAYINTEGER2ARRAY,INTEGERINTEGERSHAPEDetermineshape1anyINTEGERSIZEDeterminenumberofele-ments1ARRAYINTEGER2ARRAY,INTEGERINTEGERUBOUNDDetermineupperbounds1ARRAYINTEGER2ARRAY,INTEGERINTEGERGenericNamePurposeNumberofArgsArgumentTypeResultTypeLENLengthofstring1CHARACTERINTEGERGenericNamePurposeNumberofArgsArgumentTypeCPU_TIMEReturnsprocessortime1REAL(OUT)FortranIntrinsics200DATE_AND_TIMEReturnsdateandtime4(optional)DATE(CHARACTER,OUT)TIME(CHARACTER,OUT)ZONE(CHARACTER,OUT)VALUES(INTEGER,OUT)RANDOM_NUMBERGeneratepseudo-randomnumbers1REAL(OUT)RANDOM_SEEDSetorquerypseudo-randomnumbergenerator01SIZE(INTEGER,OUT)1PUT(INTEGERARRAY,IN)1GET(INTEGERARRAY,OUT)SYSTEM_CLOCKQueryrealtimeclock3(optional)COUNT(INTEGER,OUT)COUNT_RATE(INTEGER,OUT)COUNT_MAX(INTEGER,OUT)GenericNamePurposeNumberofArgsArgumentTypeFORTRAN77andFortran90/95IntrinsicsDescriptions201Table6-16:Fortran90/95TransferFunctionTable6-17:MiscellaneousFunctionsFORTRAN77andFortran90/95IntrinsicsDescriptionsThissectioncontainsdescriptionsofeachFORTRAN77andFortran90/95intrinsicsupportedbythePGF77andPGF95compilers.
Intrinsicsandsubroutinesarelistedalphabetically.
ThissectioncontainsdescriptionsofeachFORTRAN77andFortran90/95intrinsicsupportedbythePGF77,PGF95andPGHPFcompilers.
Intrinsicsandsubroutinesarelistedalphabetically.
ABS77Determinetheabsolutevalueofthesuppliedargument.
SynopsisABS(A)GenericNamePurposeNumberofArgsArgumentTypeResultTypeTRANSFERChangetypebutmain-tainbitrepresentation23any,anyany11.
Mustbeofthesametypeasthesecondargument.
3any,any,INTEGERGenericNamePurposeLangNumberofArgsArgumentTypeResultTypeLOCReturnaddressofargu-mentF771NUMERICINTEGERNULLAssigndisassociatedsta-tusF950POINTER1POINTERPOINTERFortranIntrinsics202ArgumentTheargumentAmustbeoftypeinteger,real,orcomplex.
ReturnValueThereturntypeforintegerisinteger,forrealisreal,andforcomplexisreal.
ACHAR90ReturnthecharacterintheASCIIcollatingpositionspecifiedbytheargument.
SynopsisACHAR(I)ArgumentTheargumentImustbeoftypeinteger.
ReturnValueAsinglecharacter.
ACOS77Returnthearccosineofthespecifiedvalue.
SynopsisACOS(X)ArgumentsTheargumentXmustbearealvalue.
ReturnValueTherealvaluerepresentingthearccosineinradians.
ACOSD77Returnthearccosine(indegrees)ofthespecifiedvalue.
SynopsisACOSD(X)FORTRAN77andFortran90/95IntrinsicsDescriptions203ArgumentsTheargumentXmustbearealvalue.
ReturnValueTherealvaluerepresentingthearccosineindegrees.
ADJUSTL90Adjuststringtotheleft,removingallleadingblanksandinsertingtrailingblanks.
SynopsisADJUSTL(STR)ArgumentsTheargumentSTRisthestringtobeadjusted.
ReturnValueStringofsamelengthandkindastheargumentwithleadingblanksremovedandthesamenumberoftrailingblanksadded.
ADJUSTR90Adjuststringtotheright,removingalltrailingblanksandinsertingleadingblanks.
SynopsisADJUSTR(STR)ArgumentsTheargumentSTRisthestringtobeadjusted.
ReturnValueStringofsamelengthandkindastheargumentwithtrailingblanksremovedandthesamenumberofleadingblanksadded.
AIMAG77Determinethevalueoftheimaginarypartofacomplexnumber.
FortranIntrinsics204SynopsisAIMAG(Z)ArgumentsTheargumentZmustbecomplex.
ReturnValueArealvaluerepresentingtheimaginarypartofthesuppliedargument.
AINT77Truncatethesuppliedvaluetoawholenumber.
SynopsisAINT(A[,KIND])ArgumentsTheargumentAisoftypereal.
TheoptionalKINDargumentisanintegerkind.
ReturnValueArealvaluethatisequaltothelargestintegerthatisnotgreaterthanthesuppliedargument.
IftheKINDargumentispresent,theresultisofthatkind.
ALL90Determineifallthevaluesinthesuppliedargumentarelogicaltrue.
SynopsisALL(MASK[,DIM])ArgumentsTheargumentMASKisanarrayoftypeLOGICAL.
TheoptionalargumentDIMspecifiesthedimensionofthearrayMASKtocheck.
ReturnValueIfnoDIMargumentispresent,thereturnvalueisalogicalscalarthatistrueonlyifallvaluesofMASKaretrue.
FORTRAN77andFortran90/95IntrinsicsDescriptions205IftheDIMargumentispresentandifMASKhasrankone,thenthereturnvalueisthesameasALL(MASK).
IftheDIMargumentispresentandMASKhasrankgreaterthanone,thenthereturnvalueisanarraythathasrankn-1,wherenistherankofMASK.
ThereturnvalueisdefinedrecursivelyasthevalueofALLforeachextentofthedimensionDIM(refertotheFortran95Handbookforamoredetailedexplanation).
ALLOCATED90Determineifthesuppliedallocatablearrayiscurrentlyallocated.
SynopsisALLOCATED(ARRAY)ArgumentTheargumentARRAYisanallocatablearray.
ReturnValueReturnsalogicalscalarindicatingwhetherthearrayisallocated.
AND§77PerformsalogicalANDoncorrespondingbitsofthearguments.
SynopsisAND(M,N)ArgumentsTheargumentsMandNmaybeofanytypeexceptforcharacterandcomplex.
ReturnValueThereturnvalueistypeless.
ANINT77Returnthenearestwholenumbertothesuppliedargument.
FortranIntrinsics206SynopsisANINT(A[,KIND])ArgumentsTheargumentAisarealnumber.
TheoptionalargumentKINDisakindparameter.
ReturnValueTheresultisareal.
ThevalueisAINT(A+0.
5)ifAis>0andAINT(A-0.
5)ifAisY,otherwisezero.
DOT_PRODUCT90Performadotproductontwovectors(arrays).
FORTRAN77andFortran90/95IntrinsicsDescriptions217SynopsisDOT_PRODUCT(VECTOR_A,VECTOR_B)ArgumentsVECTOR_Amustbeanarrayofrankoneoftypenumeric(integer,real,complex)orlogical.
VECTOR_BmustbenumericifVECTOR_Aisnumeric,orlogicalifVECTOR_Aislogical.
ItmusthavethesamerankandsizeasARRAY_A.
ReturnValueThedotproduct.
ForVECTOR_Aofintegerorreal,thevalueisSUM(VECTOR_A*VECTOR_B).
Forcomplex,thevalueisSUM(CONJG(VECTOR_A)*VECTOR_B).
Forlogical,thevalueisANY(VECTOR_A.
AND.
VECTOR_B).
DPROD90Doubleprecisionrealproduct.
SynopsisDPROD(X,Y)ArgumentsBothargumentsXandYmustbeoftypedefaultreal.
ReturnValueThereturnvalueisadoubleprecisionrealthatistheproductofXandY.
EOSHIFT90Performanend-offshiftonthespecifiedarray.
SynopsisEOSHIFT(ARRAY,SHIFT[,BOUNDARY][,DIM])ArgumentsTheargumentARRAYisthearraytoshift.
Itmaybeanarrayofanytype.
TheargumentSHIFTisanintegeroranarrayofintegerswithrankn-1wherenistherankofARRAY.
TheoptionalargumentBOUNDARYisofthesametypeasthearray,itmaybescalarorofrankn-1wherenistherankofFortranIntrinsics218ARRAY.
TheoptionalargumentBOUNDARYisthevaluetofillintheshiftedoutpositions.
Bydefaultithasthefollowingvaluesforinteger0,forreal0.
0,forcomplex(0.
0,0.
0),forlogicalfalse,forcharacterthedefaultisblankcharacters.
TheoptionalargumentDIMrepresentsthedimensionofARRAYtoshift.
ReturnValueTheshiftedarraywiththesamesizeandshapeastheargumentARRAY.
EPSILON90Returnthesmallestnumberrepresentableinthekindofthesuppliedargument.
SynopsisEPSILON(X)ArgumentTheargumentXmustbeoftypereal.
ReturnValueAverysmallnumberinthespecifiedrealkind.
EQV§77PerformsalogicalexclusiveNORonthearguments.
SynopsisCOMPL(M,N)ArgumentsTheargumentsMandNmaybeofanytypeexceptforcharacterandcomplex.
ReturnValueThereturnvalueistypeless.
EXP77Exponentialfunction.
FORTRAN77andFortran90/95IntrinsicsDescriptions219SynopsisEXP(X)ArgumentTheargumentXmustbeoftyperealorcomplex.
ReturnValueThevaluereturnedisofthesametypeastheargument.
Ithasthevalueex.
EXPONENT90Returntheexponentpartofarealnumber.
SynopsisEXPONENT(X)ArgumentTheargumentXisarealnumber.
ReturnValueThereturnvalueisanintegerwhichhasthevalueoftheexponentpartofthevalueofX.
Iftheexponentiszero,thefunctionreturnszero.
Iftheexponentistoolargetobedefinedasaninteger,theresultisundefined.
FLOOR90Returnthegreatestintegerlessthanorequaltothesuppliedrealargument.
SynopsisFLOOR(A[,KIND])ArgumentTheargumentAisarealvalue.
TheoptionalargumentKINDisakindparameterandwasaddedtoFLOORinFortran95.
ReturnValueThereturnvalueisaninteger.
IfKINDispresent,theresultisoftypeKIND.
FortranIntrinsics220FRACTION90Returnthefractionalpartofarealnumber.
SynopsisFRACTION(X)ArgumentTheargumentXisarealnumber.
ReturnValueThereturnvalueisanintegerwhichhasthevalueofthefractionalpartofthevalueofX.
Ifthefractionvalueiszero,thefunctionreturnszero.
HUGE90Returnthelargestnumberrepresentableinthekindofthesuppliedargument.
SynopsisHUGE(X)ArgumentTheargumentXmustbeoftypeintegerorreal.
ReturnValueAvalueofthesametypeastheargumentwiththemaximumvaluepossible.
IACHAR90ReturnsthepositionofthecharacterintheASCIIcollatingsequence.
SynopsisIACHAR(C)ArgumentTheargumentCmustbeoftypecharacter.
FORTRAN77andFortran90/95IntrinsicsDescriptions221ReturnValueAnintegerrepresentingthecharacterposition.
IAND77Performabit-by-bitlogicalANDonthearguments.
SynopsisIAND(I,J)ArgumentsTheargumentsIandJmustbeoftypeintegerofthesamekind.
ReturnValueThereturnvalueisanintegervaluerepresentingabit-by-bitlogicalANDofthebitsinthetwointegerarguments.
IBCLR77Clearsonebittozero.
SynopsisIBCLR(I,POS)ArgumentsIisaninteger.
POSisanonnegativeintegerlessthanBIT_SIZE(I).
ReturnValueThereturnvalueisofthesametypeasIwithavaluethatisthesameasIexceptthebitinpositionPOSissetto0.
IBITS77Extractsasequenceofbits.
SynopsisIBITS(I,POS,LEN)FortranIntrinsics222ArgumentsIisaninteger.
POSisanonnegativeintegerandPOS+LENmustbelessthanorequaltoBIT_SIZE(I).
LENisoftypeintegerandisnonnegative.
ReturnValueThereturnvalueisofthesametypeasIwithavaluethatisthesequenceofLENbitsinIbeginningatpositionPOS,right-adjustedandwithallotherbitssettozero.
IBSET77Setonebittoone.
SynopsisIBSET(I,POS)ArgumentsIisaninteger.
POSisanonnegativeintegerlessthanBIT_SIZE(I).
ReturnValueThereturnvalueisofthesametypeasIwithavaluethatisthesameasIexceptthebitinpositionPOSissetto1.
ICHAR90Returnsthepositionofacharacterinthecharacterset'scollatingsequence.
SynopsisICHAR(C)ArgumentTheargumentCmustbeoftypecharacterandlengthone.
ReturnValueAnintegerrepresentingthecharacterposition.
IEOR77Performabit-by-bitlogicalexclusiveORonthearguments.
FORTRAN77andFortran90/95IntrinsicsDescriptions223SynopsisIEOR(I,J)ArgumentTheargumentsIandJmustbeoftypeintegerofthesamekind.
ReturnValueThereturnvalueisanintegervaluerepresentingabit-by-bitlogicalexclusiveORofthebitsinthetwointegerarguments.
IINT§77Convertsavaluetoashortintegertype.
SynopsisIINT(A)ArgumentsTheargumentAisoftypeinteger,real,orcomplex.
ReturnValueThereturnvalueistheshortintegervalueofthesuppliedargument.
Forarealnumber,iftheabsolutevalueoftherealislessthan1,thereturnvalueis0.
Iftheabsolutevalueisgreaterthan1,theresultisthelargestshortintegerthatdoesnotexceedtherealvalue.
Ifargumentisacomplexnumber,thereturnvalueistheresultofapplyingtherealconversiontotherealpartofthecomplexnumber.
INDEX90Returnsthestartingpositionofasubstringwithinastring.
SynopsisINDEX(STRING,SUBSTRING[,BACK])ArgumentsTheargumentSTRINGmustbeoftypecharacterstring.
TheargumentSUBSTRINGmustbeoftypecharacterstringwiththesamekindasSTRING.
TheoptionalargumentBACKmustbeoftypelogical.
FortranIntrinsics224ReturnValueThefunctionreturnsaninteger.
IfBACKisabsentorfalse,theresultisthestartingpointofthefirstmatchingSUBSTRINGwithinSTRING.
Zeroisreturnedifnomatchisfound.
1isreturnediftheSUBSTRINGhaszerolength.
IfBACKispresentwiththevaluetrue,theresultisthelastmatchingsubstringinstring,orzeroifnomatchisfound.
ININT§77Returnsthenearestshortintegertotherealargument.
SynopsisININT(A)ArgumentsTheargumentAmustbeareal.
ReturnValueTheresultisashortintegerwithvalue(A+.
5*SIGN(A)).
INT77Convertsavaluetointegertype.
SynopsisINT(A[,KIND])ArgumentsTheargumentAisoftypeinteger,real,orcomplex.
TheoptionalargumentKINDmustbeascalarintegerthatisavalidkindforthespecifiedtype.
TheKINDargumentisnotallowedbypgf77.
ReturnValueThereturnvalueistheintegervalueofthesuppliedargument.
Forarealnumber,iftheabsolutevalueoftherealislessthan1,thereturnvalueis0.
Iftheabsolutevalueisgreaterthan1,theresultisthelargestintegerthatdoesnotexceedtherealvalue.
Iftheargumentisacomplexnumber,thereturnvalueistheresultofapplyingtherealconversiontotherealpartofthecomplexnumber.
FORTRAN77andFortran90/95IntrinsicsDescriptions225INT8§77Convertsarealvaluetoalongintegertype.
SynopsisINT8(A)ArgumentsTheargumentAisoftypereal.
ReturnValueThereturnvalueisthelongintegervalueofthesuppliedargument.
IOR77Performabit-by-bitlogicalORonthearguments.
SynopsisIOR(I,J)ArgumentTheargumentsIandJmustbeoftypeintegerofthesamekind.
ReturnValueThereturnvalueisanintegervaluerepresentingabit-by-bitlogicalORofthebitsinthetwointegerarguments.
ISHFT77Performalogicalshift.
SynopsisISHFT(I,SHIFT)ArgumentsIandSHIFTareintegervalues.
TheabsolutevalueofSHIFTmustbelessthanorequaltoBIT_SIZE(I).
FortranIntrinsics226ReturnValueThereturnvalueisofthesametypeandkindastheargumentI.
ItisthevalueoftheargumentIlogicallyshiftedbySHIFTbits.
IfSHIFTispositive,theshiftistotheleft.
IfSHIFTisnegative,theshiftistotheright.
Zeroesareshiftedinattheendsandthebitsshiftedoutarelost.
ISHFTC77Performacircularshiftoftherightmostbits.
SynopsisISHIFTC(I,SHIFT[,SIZE])ArgumentsIandSHIFTareintegervalues.
TheabsolutevalueofSHIFTmustbelessthanorequaltotheoptionalargumentSIZE.
Ifpresent,SIZEmustnotexceedthevalueBIT_SIZE(I);ifSIZEisnotpresent,thefunctionactsasifitwerepresentwiththevalueBIT_SIZE(I).
ReturnValueTheresultisthevalueofthesub-groupofSIZEbitsshiftedbySHIFTpositionswithinthesub-group,allotherbitsremainthesameandremaininthesameposition.
IftheSIZEargumentisnotpresent,thecircularshiftisoverthecompletegroupofbitsandallofthebitsareshiftedbySHIFTpositions.
IfSHIFTispositive,theshiftistotheleft.
IfSHIFTisnegative,theshiftistotheright.
IZEXT§77Zero-extendtheargument.
SynopsisIZEXT(A)ArgumentsTheargumentAisoftypelogicalorinteger.
ReturnValueThereturnvalueisazero-extendedshortintegeroftheargument.
FORTRAN77andFortran90/95IntrinsicsDescriptions227JINT§77Convertsavaluetoanintegertype.
SynopsisJINT(A)ArgumentsTheargumentAisoftypeinteger,real,orcomplex.
ReturnValueThereturnvalueistheintegervalueofthesuppliedargument.
Forarealnumber,iftheabsolutevalueoftherealislessthan1,thereturnvalueis0.
Iftheabsolutevalueisgreaterthan1,theresultisthelargestintegerthatdoesnotexceedtherealvalue.
Ifargumentisacomplexnumber,thereturnvalueistheresultofapplyingtherealconversiontotherealpartofthecomplexnumber.
JNINT§77Returnsthenearestintegertotherealargument.
SynopsisJNINT(A)ArgumentsTheargumentAmustbeareal.
ReturnValueTheresultisanintegerwithvalue(A+.
5*SIGN(A)).
KIND90Returnsthekindofthesuppliedargument.
SynopsisKIND(X)ArgumentTheargumentXisofanyintrinsictype.
FortranIntrinsics228ReturnValueTheresultisanintegerrepresentingthekindtypeparameterofX.
KNINT§77Returnsthenearestintegertotherealargument.
SynopsisKNINT(A)ArgumentsTheargumentAmustbeareal.
ReturnValueTheresultisalongintegerwithvalue(A+.
5*SIGN(A)).
LBOUND90Returnsthelowerboundsofanarray,orthelowerboundforthespecifieddimension.
SynopsisLBOUND(ARRAY[,DIM])ArgumentsTheargumentARRAYisanarrayofanytype.
TheoptionalargumentDIMisascalarthathasthevalueofavaliddimensionofthearray(validdimensionsarebetweenthevalues1andnwherenistherankofthearray).
ReturnValueThereturnvalueisaninteger,oranarrayofrankoneandsizen,wherenistherankoftheargumentARRAY.
ForthefunctionwithaDIMargument,thereturnvalueisthevalueofthelowerboundinthespecifieddimension.
ForthefunctionwithnoDIMsupplied,thereturnvalueisanarraywithallthelowerboundsofARRAY.
LEN90Returnsthelengthofthesuppliedstring.
FORTRAN77andFortran90/95IntrinsicsDescriptions229SynopsisLEN(STRING)ArgumentTheargumentSTRINGisacharacterstringoranarray.
ReturnValueThereturnvalueisanintegerthatrepresentsthelengthofthescalarstringsupplied,orthelengthofanelementofSTRINGifSTRINGisanarray.
LEN_TRIM90Returnsthelengthofthesuppliedstringminusthenumberoftrailingblanks.
SynopsisLEN_TRIM(STRING)ArgumentsTheargumentSTRINGisacharacterstring.
ReturnValueThereturnvalueisanintegerthatrepresentsthelengthofthescalarstringminusthenumberoftrailingblanks,ifany.
LGE90TestthesuppliedstringstoseeifthefirststringSTRING_AislexicallygreaterthanorequaltothesecondstringSTRING_B.
Astringislexicallygreaterthananotherstringifthefirststringfollowsthesecondstringalphabetically.
SynopsisLGE(STRING_A,STRING_B)ArgumentTheargumentsSTRING_AandSTRING_Bareoftypedefaultcharacter.
FortranIntrinsics230ReturnValueThefunctionreturnsalogicalvalue.
Ifthestringsarenotofthesamelength,theshorterstringispaddedwithblanksontheright.
LGT90TestthesuppliedstringstoseeifthefirststringSTRING_AislexicallygreaterthanthesecondstringSTRING_B.
Astringislexicallygreaterthananotherstringifthefirststringfollowsthesecondstringalphabetically.
SynopsisLGT(STRING_A,STRING_B)ArgumentTheargumentsSTRING_AandSTRING_Bareoftypedefaultcharacter.
ReturnValueThefunctionreturnsalogicalvalue.
Ifthestringsarenotofthesamelength,theshorterstringispaddedwithblanksontheright.
LLE90TestthesuppliedstringstoseeifthefirststringSTRING_AislexicallylessthanorequaltothesecondstringSTRING_B.
Astringislexicallylessthananotherstringifthefirststringprecedesthesecondstringalphabetically.
SynopsisLLE(STRING_A,STRING_B)ArgumentTheargumentsSTRING_AandSTRING_Bareoftypedefaultcharacter.
ReturnValueThefunctionreturnsalogicalvalue.
Ifthestringsarenotofthesamelength,theshorterstringispaddedwithblanksontheright.
FORTRAN77andFortran90/95IntrinsicsDescriptions231LLT90TestthesuppliedstringstoseeifthefirststringSTRING_Aislexicallylessthanthesecondstring,STRING_B.
Astringislexicallylessthananotherstringifthefirststringprecedesthesecondstringalphabetically.
SynopsisLLT(STRING_A,STRING_B)ArgumentTheargumentsSTRING_AandSTRING_Bareoftypedefaultcharacter.
ReturnValueThefunctionreturnsalogicalvalue.
Ifthestringsarenotofthesamelength,theshorterstringispaddedwithblanksontheright.
LOC77Returnthe32-bitaddressofadataitem.
SynopsisLOC(X)ArgumentTheargumentXisoftypeinteger,realorcomplex.
ReturnValueThereturnvalueisanintegerrepresentingtheaddressoftheargument.
LOG77Functionreturnsthenaturallogarithm.
SynopsisLOG(X)FortranIntrinsics232ArgumentTheargumentXisoftyperealorcomplex.
IfXisreal,itmustbegreaterthan0.
IfXiscomplex,itmustnotbeequaltozero.
ReturnValueThereturnvalueisthenaturallog(basee)ofX.
LOG1077Functionreturnsthecommonlogarithm.
SynopsisLOG10(X)ArgumentTheargumentXisoftyperealandmustbegreaterthan0.
ReturnValueThereturnvalueisthecommonlog(base10)ofX.
LOGICAL90Convertalogicalvaluetothespecifiedlogicalkind.
SynopsisLOGICAL(L[,KIND])ArgumentsTheargumentListhelogicalvaluetoconvert.
TheoptionalargumentKINDmustbeascalarintegerthatisavalidkindforthespecifiedtype.
ReturnValueReturnsalogicalvalueequaltothelogicalvalueL.
IfKINDisspecified,thekindtypeparameterofthereturnvalueisthatofKIND,otherwiseitisdefaultlogical.
LSHIFT§77Performalogicalshifttotheleft.
FORTRAN77andFortran90/95IntrinsicsDescriptions233SynopsisLSHIFT(I,SHIFT)ArgumentsIandSHIFTareintegervalues.
ReturnValueThereturnvalueisofthesametypeandkindastheargumentI.
ItisthevalueoftheargumentIlogicallyshiftedleftbySHIFTbits.
MATMUL90Performamatrixmultiplyofnumericorlogicalmatrices.
SynopsisMATMUL(MATRIX_A,MATRIX_B)ArgumentsTheargumentMATRIX_Amustbenumeric(integer,real,orcomplex)orlogical,andhavearankofoneortwo.
TheargumentMATRIX_Bmustbenumeric(integer,real,orcomplex)orlogical,andhavearankofoneortwo.
IfMATRIX_Ahasrankone,thenMATRIX_Bmusthaverank2.
IfMATRIX_Bhasrankone,thenMATRIX_Amusthaverank2.
ThesizeofthefirstdimensionofMATRIX_BmustequalthesizeofthelastdimensionofMATRIX_A.
ReturnValueAmatrixrepresentingthevalueofthematrixmultipliedarguments.
Therearethreepossibleresultshapes:MATRIX_A(n,m)andMATRIX_B(m,k)givesaresult(n,k)matrix.
MATRIX_A(m)andMATRIX_B(m,k)givesaresult(k),MATRIX_A(n,m)andMATRIX_B(m)givesaresult(n).
MAX77Returnthemaximumvalueofthesuppliedarguments.
SynopsisMAX(A1,A2[,A3,.
.
.
])FortranIntrinsics234ArgumentsAnyargumentsafterthefirsttwoareoptional.
Theargumentsmustallhavethesamekindandtheymustbeintegerorreal.
ReturnValueThereturnvalueisthesameasthetypeandkindofthearguments.
Ithasthevalueofthelargestargument.
MAXEXPONENT90Returnsthevalueofthemaximumexponentforthetypeandthekindsupplied.
SynopsisMAXEXPONENT(X)ArgumentTheargumentXmustbeascalaroranarrayoftypereal.
ReturnValueThereturnvalueisaninteger.
Itcontainsthevalueofthelargestexponentinthespecifiedkind.
MAXLOC90Determinethefirstpositioninthespecifiedarraythathasthemaximumvalueofthevaluesinthearray.
Thetestelementsmaybelimitedbyadimensionargumentorbyalogicalmaskargument.
SynopsisMAXLOC(ARRAY[,DIM][,MASK])ArgumentsTheargumentARRAYmustbeanarrayoftypeintegerorreal.
TheoptionalargumentDIM,addedinFortran95,isoftypeinteger.
TheoptionalargumentMASKmustbeoftypelogicalandmusthavethesameshapeasARRAY.
Ifonlytwoargumentsaresupplied,thetypeofthesecondargumentisusedtodetermineifitrepresentsDIMorMASK.
FORTRAN77andFortran90/95IntrinsicsDescriptions235ReturnValueThereturnvalueisanintegerarrayofrank1withsizeequaltothenumberofdimensionsinARRAY.
Thereturnvaluesrepresentthepositionsofthefirstelementineachdimensionthatisthemaximumvalueofthatdimension.
IftheMASKparameterispresent,thereturnvalueisthepositionofthefirstvaluethathasthemaximumvalueofvaluesinARRAY,andthatalsohasatruevalueinthecorrespondingMASKarray.
WhentheDIMargumentissupplied,thereturnvalueisanarraythathasavalueofMAXLOCappliedrecursivelyalongtheDIMdimensionsofthearray.
MAXVAL90Returnthemaximumvalueoftheelementsoftheargumentarray.
Thetestelementsmaybelimitedbyadimensionargumentorbyalogicalmaskargument.
SynopsisMAXVAL(ARRAY[,DIM][,MASK])ArgumentsTheargumentARRAYmustbeanarrayoftypeintegerorreal.
TheoptionalargumentDIMisascalarthathasthevalueofavaliddimensionofthearray(validdimensionsarebetweenthevalues1andnwherenistherankofthearray).
TheoptionalargumentMASKmustbeoftypelogicalandmusthavethesameshapeasARRAY.
Fortran95hasextendedMAXVALsuchthatifonlytwoargumentsaresupplied,thetypeofthesecondargumentisusedtodetermineifitrepresentsDIMorMASK.
ReturnValueThereturnvalueisascalarifnoDIMargumentispresent,orhasarankofn-1andhasashapespecifiedbyallofthedimensionsexcepttheDIMargumentdimension.
Thereturnvalueisthevalueofthelargestelementofthearrayifnooptionalparametersaresupplied.
IfonlytheMASKparameterissuppliedwiththearray,thenthereturnvalueisthevaluethatisthemaximumofthetrueelementsofMASK.
WhentheDIMargumentissupplied,thereturnvalueisanarraythathasavalueofMAXVALappliedrecursivelyalongtheDIMdimensionsofthearray.
FortranIntrinsics236MERGE90Thisfunctionmergestwoargumentsbasedonthevalueofalogicalmask.
SynopsisMERGE(TSOURCE,FSOURCE,MASK)ArgumentsTSOURCEisthesourcethatismergedifthemaskistrue.
FSOURCEisthesourcethatismergedifthemaskisfalse.
TSOURCEandFSOURCEmustbeofthesametypeandmusthavethesametypeparameters(iftheyarearraystheymustbeconformable).
MASKmustbeoftypelogical.
ReturnValueTheresulthasthesametypeandtypeparametersasthesourcearrays.
MIN77Returntheminimumvalueofthesuppliedarguments.
SynopsisMIN(A1,A2[,A3,.
.
.
])ArgumentsAnyargumentsafterthefirsttwoareoptional.
Theargumentsmustallhavethesamekindandtheymustbeintegerorreal.
ReturnValueThereturnvalueisthesameasthetypeandkindofthearguments.
Ithasthevalueofthesmallestargument.
MINEXPONENT90Returnsthevalueoftheminimumexponentforthetypeandthekindsupplied.
SynopsisMINEXPONENT(X)FORTRAN77andFortran90/95IntrinsicsDescriptions237ArgumentTheargumentXhastyperealandmaybeascalaroranarray.
ReturnValueThereturnvalueisaninteger.
Itcontainsthevalueofthesmallestexponentinthespecifiedkind.
MINLOC90Returnthepositionoftheelementwiththeminimumvalueoftheelementsoftheargumentarray.
Thetestelementsmaybelimitedbyadimensionargumentorbyalogicalmaskargument.
SynopsisMINLOC(ARRAY[,DIM][,MASK])ArgumentsTheargumentARRAYmustbeanarrayoftypeintegerorreal.
TheoptionalargumentDIM,addedinFortran95,isoftypeinteger.
TheoptionalargumentMASKmustbeoftypelogicalandmusthavethesameshapeasARRAY.
Ifonlytwoargumentsaresupplied,thetypeofthesecondargumentisusedtodetermineifitrepresentsDIMorMASK.
ReturnValueThereturnvalueisanintegerarrayofrank1andhasasizeequaltothenumberofdimensionsinARRAY.
Thereturnvalueisthepositionofthefirstelementthatistheminimumvalueofthearray.
IftheMASKparameterispresent,thereturnvalueisthepositionofthefirstvaluethathastheminimumvalueofvaluesinARRAY,andthatalsohasatruevalueinthecorrespondingMASKarray.
WhentheDIMargumentissupplied,thereturnvalueisanarraythathasavalueofMINLOCappliedrecursivelyalongtheDIMdimensionsofthearray.
MINVAL90Returntheminimumvalueoftheelementsoftheargumentarray.
Thetestelementsmaybelimitedbyadimensionargumentorbyalogicalmaskargument.
SynopsisMINVAL(ARRAY[,DIM][,MASK])FortranIntrinsics238ArgumentsTheargumentARRAYmustbeanarrayoftypeintegerorreal.
TheoptionalargumentDIMisascalarthathasthevalueofavaliddimensionofthearray(validdimensionsarebetweenthevalues1andnwherenistherankofthearray).
TheoptionalargumentMASKmustbeoftypelogicalandmusthavethesameshapeasARRAY.
Fortran95hasextendedMINVALsuchthatifonlytwoargumentsaresupplied,thetypeofthesecondargumentisusedtodetermineifitrepresentsDIMorMASK.
ReturnValueThereturnvalueisascalarifnoDIMargumentispresent,orhasarankofn-1andhasashapespecifiedbyallofthedimensionsexcepttheDIMargumentdimension.
Thereturnvalueisthevalueofthelargestelementofthearrayifnooptionalparametersaresupplied.
IfonlytheMASKparameterissuppliedwiththearray,thenthereturnvalueisthevaluethatistheminimumofthetrueelementsofMASK.
WhentheDIMargumentissupplied,thereturnvalueisanarraythathasavalueofMINVALappliedrecursivelyalongtheDIMdimensionsofthearray.
MOD77Findtheremainder.
SynopsisMOD(A,P)ArgumentsTheargumentAmustbeanintegerorareal.
TheargumentPmustbeofthesametypeandkindasA.
ReturnValueThereturnvalueisthesametypeastheargumentAandhasthevalue(A-INT(A/P)*P).
MODULO90Returnthemodulovalueofthearguments.
SynopsisMODULO(A,P)FORTRAN77andFortran90/95IntrinsicsDescriptions239ArgumentsTheargumentAmustbeanintegerorareal.
TheargumentPmustbeofthesametypeandkindasA.
ReturnValueThereturnvalueisthesametypeastheargumentA.
IfAandPareoftypereal,theresultis(A–FLOOR(A/P)*P).
IfAandPareoftypeinteger,theresultis(A–FLOOR(A÷P)*P)where÷representsordinarymathematicaldivision.
MVBITS90Copiesabitsequencefromasourcedataobjecttoadestinationdataobject.
SynopsisMVBITS(FROM,FROMPOS,LEN,TO,TOPOS)ArgumentsAllargumentshavetypeinteger.
TheargumentsFROMPOS,LEN,andTOPOSmustbenonnegative.
TheTOargumentmustbeavariableoftypeintegerandhavethesamekindtypeparameterastheFROMargument.
ReturnValueMVBITSisasubroutineandhasnoreturnvalue;instead,theTOargumentismodified.
LENbitsstartingatFROMPOSinFROMarecopiedtoTOatTOPOS.
AllotherbitsofTOremainunchanged.
NEAREST90Returnsthenearestdifferentmachinerepresentablenumberinagivendirection.
SynopsisNEAREST(X,S)ArgumentsTheargumentXisarealnumber.
TheargumentSisarealnumberandnotequaltozero.
ReturnValueThereturnvalueisofthesametypeasX.
ItcontainsthevaluethatistheclosestpossibledifferentmachinerepresentablenumberfromXinthedirectiongivenbythesignofS.
FortranIntrinsics240NEQV§77PerformsalogicalexclusiveORonthearguments.
SynopsisCOMPL(M,N)ArgumentsTheargumentsMandNmaybeofanytypeexceptforcharacterandcomplex.
ReturnValueThereturnvalueistypeless.
NINT77Returnsthenearestintegertotherealargument.
SynopsisNINT(A[,KIND])ArgumentsTheargumentAmustbeareal.
TheoptionalargumentKINDspecifiesthekindoftheresultinteger.
ReturnValueTheresultisaninteger.
IfA>0,NINT(A)hasthevalueisINT(A+0.
5).
IfAislessthanorequalto0,NINT(A)hasthevalueINT(A-0.
5).
NOT77Performabit-by-bitlogicalcomplementontheargument.
SynopsisNOT(I)ArgumentTheargumentImustbeoftypeinteger.
FORTRAN77andFortran90/95IntrinsicsDescriptions241ReturnValueThereturnvalueisanintegervaluerepresentingabit-by-bitlogicalcomplementofthebitsintheargument.
NULL95Fortran95addedthistransformationalfunction.
NULLgivesthedisassociatedstatustopointerentities.
Foramoredetailedexplanation,refertoFortran95Explained.
SynopsisNULL([PTR])ArgumentsTheoptionalargumentPTRisapointerofanytypeandmayhaveanyassociationstatusincludingundefined.
ReturnValueThereturnvalueisadisassociatedpointer.
OR§77PerformsalogicalORoneachbitofthearguments.
SynopsisOR(M,N)ArgumentsTheargumentsMandNmaybeofanytypeexceptforcharacterandcomplex.
ReturnValueThereturnvalueistypeless.
PACK90Packanarrayofanynumberofdimensionsintoanarrayofrankone.
SynopsisPACK(ARRAY,MASK[,VECTOR])FortranIntrinsics242ArgumentsTheARRAYargumentisthearraytobepackedandmaybeofanytype.
TheMASKargumentisoftypelogicalandmustbeconformablewithARRAY.
TheoptionalargumentVECTORisofthesametypeasARRAYandhasrankone.
ReturnValueThereturnvalueisthepackedarraylimitedbythelogicalvaluesinthearrayMASK.
IfVECTORispresentitsvaluesarepartoftheresultarrayonlyforthoseelementsthathaveanelementordergreaterthanthenumberoftrueelementsinMASK.
Forfurtherdetails,refertotheFortran95Handbook.
PRECISION90Returnthedecimalprecisionoftherealorcomplexargument.
SynopsisPRECISION(X)ArgumentTheargumentXmustbearealorcomplexnumber.
ReturnValueThereturnvalueisanintegerrepresentingthedecimalprecisionoftheargument.
PRESENT90Determineifanoptionalargumentispresent.
SynopsisPRESENT(A)ArgumentTheargumentAmustbeanoptionalargumentintheprocedureinwhichtheintrinsiciscalled.
ReturnValueAlogicalscalar.
TrueifAispresentandfalseotherwise.
FORTRAN77andFortran90/95IntrinsicsDescriptions243PRODUCT90Returnstheproductoftheelementsofthesuppliedarray.
SynopsisPRODUCT(ARRAY[,DIM][,MASK])ArgumentsTheARRAYargumentisanarrayofinteger,realorcomplextype.
TheoptionalDIMargumentisavaliddimension(validdimensionsarebetweenthevalues1andnwherenistherankofthearray).
TheoptionalMASKargumentisoftypelogicalandconformablewiththesuppliedarray.
Fortran95hasextendedPRODUCTsuchthatifonlytwoargumentsaresupplied,thetypeofthesecondargumentisusedtodetermineifitrepresentsDIMorMASK.
ReturnValueThereturnvalueistheproductoftheelementsofARRAY.
IftheoptionalDIMargumentispresent,theproductisforthespecifieddimension.
IftheoptionalMASKargumentispresent,theresultissubjecttothelogicalmasksupplied.
RADIX90Returnthebaseofthemodelrepresentingnumbersofthetypeandkindoftheargument.
SynopsisRADIX(X)ArgumentTheargumentXisoftypeintegerorreal.
ReturnValueThereturnvalueisanintegerwiththevalueoftheradix(base)ofthenumbersystemmodeloftheargument.
RANDOM_NUMBER90Returnsonepseudorandomnumberoranarrayofpseudo-randomnumbersfromtheuniformdistributionovertherange0x!
$OMPENDPARALLELClauses:PRIVATE(list)SHARED(list)DEFAULT(PRIVATE|SHARED|NONE)FIRSTPRIVATE(list)REDUCTION([{operator|intrinsic}:]list)COPYIN(list)IF(scalar_logical_expression)Thisdirectivepairdeclaresaregionofparallelexecution.
ItdirectsthecompilertocreateanexecutableinwhichthestatementsbetweenPARALLELandENDPARALLELareexecutedbymultiplelightweightthreads.
ThecodethatliesbetweenPARALLELandENDPARALLELiscalledaparallelregion.
PARALLEL.
.
.
ENDPARALLEL297TheOpenMPparallelizationdirectivessupportafork/joinexecutionmodelinwhichasinglethreadexecutesallstatementsuntilaparallelregionisencountered.
Attheentrancetotheparallelregion,asystem-dependentnumberofsymmetricparallelthreadsbeginexecutingallstatementsintheparallelregionredundantly.
Thesethreadsshareworkbymeansofwork-sharingconstructssuchasparallelDOloopsinthefollowingexample.
ThenumberofthreadsintheteamiscontrolledbytheOMP_NUM_THREADSenvironmentvariable.
IfOMP_NUM_THREADSisnotdefined,theprogramwillexecuteparallelregionsusingonlyoneprocessor.
Branchingintooroutofaparallelregionisnotsupported.
Allothershared-memoryparallelizationdirectivesmustoccurwithinthescopeofaparallelregion.
NestedPARALLEL.
.
.
ENDPARALLELdirectivepairsarenotsupportedandareignored.
TheENDPARALLELdirectivedenotestheendoftheparallelregion,andisanimplicitbarrier.
Whenallthreadshavecompletedexecutionoftheparallelregion,asinglethreadresumesexecutionofthestatementsthatfollow.
Notethat,bydefault,thereisnoworkdistributioninaparallelregion.
Eachactivethreadexecutestheentireregionredundantlyuntilitencountersadirectivethatspecifiesworkdistribution.
Forworkdistribution,seetheDO,PARALLELDO,orDOACROSSdirectives.
PROGRAMWHICH_PROCESSOR_AM_IINTEGERA(0:1)INTEGERomp_get_thread_numA(0)=-1A(1)=-1!
$OMPPARALLELA(omp_get_thread_num())=omp_get_thread_num()!
$OMPENDPARALLELPRINT*,"A(0)=",A(0),"A(1)=",A(1)ENDThevariablesspecifiedinaPRIVATElistareprivatetoeachthreadinateam.
Ineffect,thecompilercreatesaseparatecopyofeachofthesevariablesforeachthreadintheteam.
Whenanassignmenttoaprivatevariableoccurs,eachthreadassignstoitslocalcopyofthevariable.
Whenoperationsinvolvingaprivatevariableoccur,eachthreadperformstheoperationsusingitslocalcopyofthevariable.
Importantpointsaboutprivatevariablesare:Variablesdeclaredprivateinaparallelregionareundefineduponentrytotheparallelregion.
Ifthefirstuseofaprivatevariablewithintheparallelregionisinaright-handsideexpression,theresultsoftheexpressionwillbeundefined(i.
e.
,thisisprobablyacodingerror).
OpenMPDirectivesforFortran298Likewise,variablesdeclaredprivateinaparallelregionareundefinedwhenserialexecutionresumesattheendoftheparallelregion.
ThevariablesspecifiedinaSHAREDlistaresharedbetweenallthreadsinateam,meaningthatallthreadsaccessthesamestorageareaforSHAREDdata.
TheDEFAULTclauseletsyouspecifythedefaultattributeforvariablesinthelexicalextentoftheparallelregion.
IndividualclausesspecifyingPRIVATE,SHARED,etc.
statusoverridethedeclaredDEFAULT.
SpecifyingDEFAULT(NONE)declaresthatthereisnoimplicitdefault,andinthiscase,eachvariableintheparallelregionmustbeexplicitlylistedwithanattributeofPRIVATE,SHARED,FIRSTPRIVATE,LASTPRIVATE,orREDUCTION.
VariablesthatappearinthelistofaFIRSTPRIVATEclausearesubjecttothesamesemanticsasPRIVATEvariables,butinaddition,areinitializedfromtheoriginalobjectexistingpriortoenteringtheparallelregion.
VariablesthatappearinthelistofaREDUCTIONclausemustbeSHARED.
AprivatecopyofeachvariableinlistiscreatedforeachthreadasifthePRIVATEclausehadbeenspecified.
Eachprivatecopyisinitializedaccordingtotheoperatorasspecifiedinthefollowingtable:PARALLEL.
.
.
ENDPARALLEL299Table8-1:InitializationofREDUCTIONVariablesAttheendoftheparallelregion,areductionisperformedontheinstancesofvariablesappearinginlistusingoperatororintrinsicasspecifiedintheREDUCTIONclause.
TheinitialvalueofeachREDUCTIONvariableisincludedinthereductionoperation.
Ifthe{operator|intrinsic}:portionoftheREDUCTIONclauseisomitted,thedefaultreductionoperatoris"+"(addition).
TheCOPYINclauseappliesonlytoTHREADPRIVATEcommonblocks.
InthepresenceoftheCOPYINclause,datafromthemasterthread'scopyofthecommonblockiscopiedtothethreadprivatecopiesuponentrytotheparallelregion.
InthepresenceofanIFclause,theparallelregionwillbeexecutedinparallelonlyifthecorrespondingscalar_logical_expressionevaluatesto.
TRUE.
.
Otherwise,thecodewithintheregionwillbeexecutedbyasingleprocessorregardlessofthevalueoftheenvironmentvariableOMP_NUM_THREADS.
Operator/IntrinsicInitialization+0*1-0.
AND.
.
TRUE.
.
OR.
.
FALSE.
.
EQV.
.
TRUE.
.
NEQV.
.
FALSE.
MAXsmallestrepresentablenumberMINlargestrepresentablenumberIANDallbitsonIOR0IEOR0OpenMPDirectivesforFortran300CRITICAL.
.
.
ENDCRITICALTheOpenMPENDCRITICALdirectiveusesthefollowingsyntax.
!
$OMPCRITICAL[(name)]!
$OMPENDCRITICAL[(name)]Withinaparallelregion,youmayhavecodethatwillnotexecuteproperlywhenmultiplethreadsactuponthesamesub-regionofcode.
Thisisoftenduetoasharedvariablethatiswrittenandthenreadagain.
TheCRITICAL.
.
.
ENDCRITICALdirectivepairdefinesasubsectionofcodewithinaparallelregion,referredtoasacriticalsection,whichwillbeexecutedonethreadatatime.
Theoptionalnameargumentidentifiesthecriticalsection.
Thefirstthreadtoarriveatacriticalsectionwillbethefirsttoexecutethecodewithinthesection.
Thesecondthreadtoarrivewillnotbeginexecutionofstatementsinthecriticalsectionuntilthefirstthreadhasexitedthecriticalsection.
Likewise,eachoftheremainingthreadswillwaititsturntoexecutethestatementsinthecriticalsection.
Criticalsectionscannotbenested,andanysuchspecificationsareignored.
Branchingintooroutofacriticalsectionisillegal.
IfanameargumentappearsonaCRITICALdirective,thesamenamemustappearontheENDCRITICALdirective.
PROGRAMCRITICAL_USEREALA(100,100),MX,LMXINTEGERI,JMX=-1.
0LMX=-1.
0CALLRANDOM_SEED()CALLRANDOM_NUMBER(A)!
$OMPPARALLELPRIVATE(I),FIRSTPRIVATE(LMX)!
$OMPDODOJ=1,100DOI=1,100LMX=MAX(A(I,J),LMX)ENDDOENDDO!
$OMPCRITICALMX=MAX(MX,LMX)MASTER.
.
.
ENDMASTER301!
$OMPENDCRITICAL!
$OMPENDPARALLELPRINT*,"MAXVALUEOFAIS",MXENDNotethatthisprogramcouldalsobeimplementedwithoutthecriticalregionbydeclaringMXasareductionvariableandperformingtheMAXcalculationintheloopusingMXdirectlyratherthanusingLMX.
See"DO.
.
.
ENDDO"onpage302,and"PARALLEL.
.
.
ENDPARALLEL"onpage296,formoreinformationonhowtousetheREDUCTIONclauseonaparallelDOloop.
MASTER.
.
.
ENDMASTERTheOpenMPMASTER.
.
.
ENDMASTERdirectiveusesthefollowingsyntax.
!
$OMPMASTER!
$OMPENDMASTERInaparallelregionofcode,theremaybeasub-regionofcodethatshouldexecuteonlyonthemasterthread.
Insteadofendingtheparallelregionbeforethesub-regionandthenstartingitupagainafterthesub-region,theMASTER.
.
.
ENDMASTERdirectivepairletsyouconvenientlydesignatecodethatexecutesonthemasterthreadandisskippedbytheotherthreads.
ThereisnoimpliedbarrieronentrytoorexitfromaMASTER.
.
.
ENDMASTERsectionofcode.
Nestedmastersectionsareignored.
Branchingintooroutofamastersectionisnotsupported.
PROGRAMMASTER_USEINTEGERA(0:1)INTEGERomp_get_thread_numA=-1!
$OMPPARALLELA(omp_get_thread_num())=omp_get_thread_num()!
$OMPMASTERPRINT*,"YOUSHOULDONLYSEETHISONCE"!
$OMPENDMASTER!
$OMPENDPARALLELPRINT*,"A(0)=",A(0),"A(1)=",A(1)ENDOpenMPDirectivesforFortran302SINGLE.
.
.
ENDSINGLETheOpenMPSINGLE.
.
.
ENDSINGLEdirectiveusesthefollowingsyntax:!
$OMPSINGLE[Clauses]!
$OMPENDSINGLE[NOWAIT]Clauses:PRIVATE(list)FIRSTPRIVATE(list)Inaparallelregionofcode,theremaybeasub-regionofcodethatwillonlyexecutecorrectlyonasinglethread.
Insteadofendingtheparallelregionbeforethesub-regionandthenstartingitupagainafterthesub-region,theSINGLE.
.
.
ENDSINGLEdirectivepairletsyouconvenientlydesignatecodethatexecutesonasinglethreadandisskippedbytheotherthreads.
ThereisanimpliedbarrieronexitfromaSINGLE.
.
.
ENDSINGLEsectionofcodeunlesstheoptionalNOWAITclauseisspecified.
Nestedsingleprocesssectionsareignored.
Branchingintooroutofasingleprocesssectionisnotsupported.
PROGRAMSINGLE_USEINTEGERA(0:1)INTEGERomp_get_thread_num()!
$OMPPARALLELA(omp_get_thread_num())=omp_get_thread_num()!
$OMPSINGLEPRINT*,"YOUSHOULDONLYSEETHISONCE"!
$OMPENDSINGLE!
$OMPENDPARALLELPRINT*,"A(0)=",A(0),"A(1)=",A(1)ENDThePRIVATEandFIRSTPRIVATEclausesareasdescribedinthePARALLEL.
.
.
ENDPARALLELsection.
DO.
.
.
ENDDOTheOpenMPDO.
.
.
ENDDOdirectiveusesthefollowingsyntax.
DO.
.
.
ENDDO303Syntax:!
$OMPDO[Clauses]!
$OMPENDDO[NOWAIT]Clauses:PRIVATE(list)FIRSTPRIVATE(list)LASTPRIVATE(list)REDUCTION({operator|intrinsic}:list)SCHEDULE(type[,chunk])ORDEREDTherealpurposeofsupportingparallelexecutionisthedistributionofworkacrosstheavailablethreads.
Youcanexplicitlymanageworkdistributionwithconstructssuchas:IF(omp_get_thread_num().
EQ.
0)THEN.
.
.
ELSEIF(omp_get_thread_num().
EQ.
1)THEN.
.
.
ENDIFHowever,theseconstructsarenotintheformofdirectives.
TheDO.
.
.
ENDDOdirectivepairprovidesaconvenientmechanismforthedistributionofloopiterationsacrosstheavailablethreadsinaparallelregion.
Itemstonoteaboutclausesare:VariablesdeclaredinaPRIVATElistaretreatedasprivatetoeachprocessorparticipatinginparallelexecutionoftheloop,meaningthataseparatecopyofthevariableexistsoneachprocessor.
VariablesdeclaredinaFIRSTPRIVATElistarePRIVATE,andinadditionareinitializedfromtheoriginalobjectexistingbeforetheconstruct.
VariablesdeclaredinaLASTPRIVATElistarePRIVATE,andinadditionthethreadthatexecutesthesequentiallylastiterationupdatestheversionoftheobjectthatexistedbeforetheconstruct.
TheREDUCTIONclauseisasdescribedinthePARALLEL.
.
.
ENDPARALLELsection.
TheSCHEDULEclauseisexplainedinthefollowingsection.
OpenMPDirectivesforFortran304IfORDEREDcodeblocksarecontainedinthedynamicextentoftheDOdirective,theORDEREDclausemustbepresent.
FormoreinformationonORDEREDcodeblocks,seetheORDEREDsection.
TheDO.
.
.
ENDDOdirectivepairdirectsthecompilertodistributetheiterativeDOloopimmediatelyfollowingthe!
$OMPDOdirectiveacrossthethreadsavailabletotheprogram.
TheDOloopisexecutedinparallelbytheteamthatwasstartedbyanenclosingparallelregion.
Ifthe!
$OMPENDDOdirectiveisnotspecified,the!
$OMPDOisassumedtoendwiththeenclosedDOloop.
DO.
.
.
ENDDOdirectivepairsmaynotbenested.
Branchingintooroutofa!
$OMPDOloopisnotsupported.
Bydefault,thereisanimplicitbarrieraftertheendoftheparallelloop;thefirstthreadtocompleteitsportionoftheworkwillwaituntiltheotherthreadshavefinishedtheirportionofwork.
IfNOWAITisspecified,thethreadswillnotsynchronizeattheendoftheparallelloop.
Otheritemstonoteabout!
$OMPDOloops:TheDOloopindexvariableisalwaysprivate.
!
$OMPDOloopsmustbeexecutedbyallthreadsparticipatingintheparallelregionornoneatall.
TheENDDOdirectiveisoptional,butifitispresentitmustappearimmediatelyaftertheendoftheenclosedDOloop.
PROGRAMDO_USEREALA(1000),B(1000)DOI=1,1000B(I)=FLOAT(I)ENDDO!
$OMPPARALLEL!
$OMPDODOI=1,1000A(I)=SQRT(B(I));ENDDO.
.
.
!
$OMPENDPARALLEL.
.
.
ENDTheSCHEDULEclausespecifieshowiterationsoftheDOlooparedividedupbetweenprocessors.
GivenaSCHEDULE(type[,chunk])clause,typecanbeSTATIC,DYNAMIC,GUIDED,orRUNTIME.
Thesearedefinedasfollows:BARRIER305WhenSCHEDULE(STATIC,chunk)isspecified,iterationsareallocatedincontiguousblocksofsizechunk.
Theblocksofiterationsarestaticallyassignedtothreadsinaround-robinfashioninorderofthethreadIDnumbers.
Thechunkmustbeascalarintegerexpression.
Ifchunkisnotspecified,adefaultchunksizeischosenequalto:(number_of_iterations+omp_num_threads()-1)/omp_num_threads()WhenSCHEDULE(DYNAMIC,chunk)isspecified,iterationsareallocatedincontiguousblocksofsizechunk.
Aseachthreadfinishesapieceoftheiterationspace,itdynamicallyobtainsthenextsetofiterations.
Thechunkmustbeascalarintegerexpression.
Ifnochunkisspecified,adefaultchunksizeischosenequalto1.
WhenSCHEDULE(GUIDED,chunk)isspecified,thechunksizeisreducedinanexponentiallydecreasingmannerwitheachdispatchedpieceoftheiterationspace.
Chunkspecifiestheminimumnumberofiterationstodispatcheachtime,exceptwhentherearelessthanchunkiterationsremainingtobeprocessed,atwhichpointallremainingiterationsareassigned.
Ifnochunkisspecified,adefaultchunksizeischosenequalto1.
WhenSCHEDULE(RUNTIME)isspecified,thedecisionregardingiterationschedulingisdeferreduntilruntime.
ThescheduletypeandchunksizecanbechosenatruntimebysettingtheOMP_SCHEDULEenvironmentvariable.
Ifthisenvironmentvariableisnotset,theresultingscheduleisequivalenttoSCHEDULE(STATIC).
BARRIERTheOpenMPBARRIERdirectiveusesthefollowingsyntax.
!
$OMPBARRIERTheremaybeoccasionsinaparallelregionwhenitisnecessarythatallthreadscompleteworktothatpointbeforeanythreadisallowedtocontinue.
TheBARRIERdirectivesynchronizesallthreadsatsuchapointinaprogram.
Multiplebarrierpointsareallowedwithinaparallelregion.
TheBARRIERdirectivemusteitherbeexecutedbyallthreadsexecutingtheparallelregionorbynoneofthem.
DOACROSSTheC$DOACROSSdirectiveisnotpartoftheOpenMPstandard,butissupportedforcompatibilitywithprogramsparallelizedusinglegacySGI-styledirectives.
OpenMPDirectivesforFortran306Syntax:C$DOACROSS[Clauses]Clauses:[{PRIVATE|LOCAL}(list)][{SHARED|SHARE}(list)][MP_SCHEDTYPE={SIMPLE|INTERLEAVE}][CHUNK=][IF(logical_expression)]TheC$DOACROSSdirectivehastheeffectofacombinedparallelregionandparallelDOloopappliedtotheloopimmediatelyfollowingthedirective.
ItisverysimilartotheOpenMPPARALLELDOdirective,butprovidesforbackwardcompatibilitywithcodesparallelizedforSGIsystemspriortotheOpenMPstandardizationeffort.
TheC$DOACROSSdirectivemustnotappearwithinaparallelregion.
Itisashorthandnotationthattellsthecompilertoparallelizethelooptowhichitapplies,eventhoughthatloopisnotcontainedwithinaparallelregion.
Whilethissyntaxismoreconvenient,itshouldbenotedthatifmultiplesuccessiveDOloopsaretobeparallelizeditismoreefficienttodefineasingleenclosingparallelregionandparallelizeeachloopusingtheOpenMPDOdirective.
AvariabledeclaredPRIVATEorLOCALtoaC$DOACROSSloopistreatedthesameasaprivatevariableinaparallelregionorDO(seeabove).
AvariabledeclaredSHAREDorSHAREtoaC$DOACROSSloopissharedamongthethreads,meaningthatonly1copyofthevariableexiststobeusedand/ormodifiedbyallofthethreads.
ThisisequivalenttothedefaultstatusofavariablethatisnotlistedasPRIVATEinaparallelregionorDO(thissamedefaultstatusisusedinC$DOACROSSloopsaswell).
PARALLELDOTheOpenMPPARALLELDOdirectiveusesthefollowingsyntax.
Syntax:!
$OMPPARALLELDO[CLAUSES][!
$OMPENDPARALLELDO]SECTIONS.
.
.
ENDSECTIONS307Clauses:PRIVATE(list)SHARED(list)DEFAULT(PRIVATE|SHARED|NONE)FIRSTPRIVATE(list)LASTPRIVATE(list)REDUCTION({operator|intrinsic}:list)COPYIN(list)IF(scalar_logical_expression)SCHEDULE(type[,chunk])ORDEREDThesemanticsofthePARALLELDOdirectiveareidenticaltothoseofaparallelregioncontainingonlyasingleparallelDOloopanddirective.
NotethattheENDPARALLELDOdirectiveisoptional.
TheavailableclausesareasdefinedintheDO.
.
.
ENDDOandPARALLEL.
.
.
ENDPARALLELsections.
SECTIONS.
.
.
ENDSECTIONSTheOpenMPSECTIONS.
.
.
ENDSECTIONSdirectivepairusesthefollowingsyntax:Syntax:!
$OMPSECTIONS[Clauses][!
$OMPSECTION][!
$OMPSECTION].
.
.
!
$OMPENDSECTIONS[NOWAIT]Clauses:PRIVATE(list)FIRSTPRIVATE(list)LASTPRIVATE(list)REDUCTION({operator|intrinsic}:list)TheSECTIONS.
.
.
ENDSECTIONSdirectivepairdefinesanon-iterativework-sharingconstructwithinaparallelregion.
Eachsectionisexecutedbyasingleprocessor.
Iftherearemoreprocessorsthansections,someprocessorswillhavenoworkandwilljumptotheimpliedbarrierattheendoftheconstruct.
Iftherearemoresectionsthanprocessors,oneormoreprocessorswillexecutemorethanonesection.
OpenMPDirectivesforFortran308ASECTIONdirectivemayonlyappearwithinthelexicalextentoftheenclosingSECTIONS.
.
.
ENDSECTIONSdirectives.
Inaddition,thecodewithintheSECTIONS.
.
.
ENDSECTIONSdirectivesmustbeastructuredblock,andthecodeineachSECTIONmustbeastructuredblock.
TheavailableclausesareasdefinedintheDO.
.
.
ENDDOandPARALLEL.
.
.
ENDPARALLELsections.
PARALLELSECTIONSTheOpenMPPARALLELSECTIONS.
.
.
ENDSECTIONSdirectivepairusesthefollowingsyntax:Syntax:!
$OMPPARALLELSECTIONS[CLAUSES][!
$OMPSECTION][!
$OMPSECTION].
.
.
!
$OMPENDSECTIONS[NOWAIT]Clauses:PRIVATE(list)SHARED(list)DEFAULT(PRIVATE|SHARED|NONE)FIRSTPRIVATE(list)LASTPRIVATE(list)REDUCTION({operator|intrinsic}:list)COPYIN(list)IF(scalar_logical_expression)ThePARALLELSECTIONS.
.
.
ENDSECTIONSdirectivesdefineanon-iterativework-sharingconstructwithouttheneedtodefineanenclosingparallelregion.
Eachsectionisexecutedbyasingleprocessor.
Iftherearemoreprocessorsthansections,someprocessorswillhavenoworkandwilljumptotheimpliedbarrierattheendoftheconstruct.
Iftherearemoresectionsthanprocessors,oneormoreprocessorswillexecutemorethanonesection.
ASECTIONdirectivemayonlyappearwithinthelexicalextentoftheenclosingPARALLELSECTIONS.
.
.
ENDSECTIONSdirectives.
Inaddition,thecodewithinthePARALLELSECTIONS.
.
.
ENDSECTIONSdirectivesmustbeastructuredblock,andthecodeineachSECTIONmustbeastructuredblock.
ORDERED309TheavailableclausesareasdefinedinDO.
.
.
ENDDOandPARALELL.
.
.
ENDPARALLELsections.
ORDEREDTheOpenMPORDEREDdirectiveissupportedusingthefollowingsyntax:!
$OMPORDERED!
$OMPENDORDEREDTheORDEREDdirectivecanappearonlyinthedynamicextentofaDOorPARALLELDOdirectivethatincludestheORDEREDclause.
ThecodeblockbetweentheORDERED.
.
.
ENDORDEREDdirectivesisexecutedbyonlyonethreadatatime,andintheorderoftheloopiterations.
Thissequentializestheorderedcodeblockwhileallowingparallelexecutionofstatementsoutsidethecodeblock.
ThefollowingadditionalrestrictionsapplytotheORDEREDdirective:TheORDEREDcodeblockmustbeastructuredblock.
Itisillegaltobranchintooroutoftheblock.
AgiveniterationofaloopwithaDOdirectivecannotexecutethesameORDEREDdirectivemorethanonce,andcannotexecutemorethanoneORDEREDdirective.
ATOMICTheOpenMPATOMICdirectiveusesfollowingsyntax:!
$OMPATOMICTheATOMICdirectiveissemanticallyequivalenttoenclosingthefollowingsinglestatementinaCRITICAL.
.
.
ENDCRITICALdirectivepair.
Thestatementmusthaveoneofthefollowingforms:x=xoperatorexprx=exproperatorxx=intrinsic(x,expr)x=intrinsic(expr,x)wherexisascalarvariableofintrinsictype,exprisascalarexpressionthatdoesnotreferencex,intrinsicisoneofMAX,MIN,IAND,IOR,orIEOR,andoperatorisoneofAND.
,.
OR.
,.
EQV.
,or.
NEQV.
.
OpenMPDirectivesforFortran310FLUSHTheOpenMPFLUSHdirectiveusesthefollowingsyntax:!
$OMPFLUSH[(list)]TheFLUSHdirectiveensuresthatallprocessor-visibledataitems,oronlythosespecifiedinlistwhenit'spresent,arewrittenbacktomemoryatthepointatwhichthedirectiveappears.
THREADPRIVATETheOpenMPTHREADPRIVATEdirectiveusesthefollowingsyntax:!
$OMPTHREADPRIVATE([/common_block1/[,/common_block2/]…])wherecommon_blocknisthenameofacommonblocktobemadeprivatetoeachthreadbutglobalwithinthethread.
Thisdirectivemustappearinthedeclarationssectionofaprogramunitafterthedeclarationofanycommonblockslisted.
Onentrytoaparallelregion,datainaTHREADPRIVATEcommonblockisundefinedunlessCOPYINisspecifiedonthePARALLELdirective.
WhenacommonblockthatisinitializedusingDATAstatementsappearsinaTHREADPRIVATEdirective,eachthread'scopyisinitializedoncepriortoitsfirstuse.
ThefollowingrestrictionsapplytotheTHREADPRIVATEdirective:TheTHREADPRIVATEdirectivemustappearaftereverydeclarationofathreadprivatecommonblock.
Onlynamedcommonblockscanbemadethreadprivate.
ItisillegalforaTHREADPRIVATEcommonblockoritsconstituentvariablestoappearinanyclauseotherthanaCOPYINclause.
Run-timeLibraryRoutinesUser-callablefunctionsareavailabletotheFortranprogrammertoqueryandaltertheparallelexecutionenvironment.
integeromp_get_num_threads()Run-timeLibraryRoutines311returnsthenumberofthreadsintheteamexecutingtheparallelregionfromwhichitiscalled.
Whencalledfromaserialregion,thisfunctionreturns1.
Anestedparallelregionisthesameasasingleparallelregion.
Bydefault,thevaluereturnedbythisfunctionisequaltothevalueoftheenvironmentvariableOMP_NUM_THREADSortothevaluesetbythelastpreviouscalltotheomp_set_num_threads()subroutinedefinedinthefollowingsection.
subroutineomp_set_num_threads(scalar_integer_exp)setsthenumberofthreadstouseforthenextparallelregion.
Thissubroutinecanonlybecalledfromaserialregionofcode.
Ifitiscalledfromwithinaparallelregion,orwithinasubroutineorfunctionthatiscalledfromwithinaparallelregion,theresultsareundefined.
ThissubroutinehasprecedenceovertheOMP_NUM_THREADSenvironmentvariable.
integeromp_get_thread_num()returnsthethreadnumberwithintheteam.
Thethreadnumberliesbetween0andomp_get_num_threads()-1.
Whencalledfromaserialregion,thisfunctionreturns0.
Anestedparallelregionisthesameasasingleparallelregion.
integerfunctionomp_get_max_threads()returnsthemaximumvaluethatcanbereturnedbycallstoomp_get_num_threads().
Ifomp_set_num_threads()isusedtochangethenumberofprocessors,subsequentcallstoomp_get_max_threads()willreturnthenewvalue.
Thisfunctionreturnsthemaximumvaluewhetherexecutingfromaparallelorserialregionofcode.
integerfunctionomp_get_num_procs()returnsthenumberofprocessorsthatareavailabletotheprogram.
logicalfunctionomp_in_parallel()returns.
TRUE.
ifcalledfromwithinaparallelregionand.
FALSE.
ifcalledoutsideofaparallelregion.
Whencalledfromwithinaparallelregionthatisserialized,forexampleinthepresenceofanIFclauseevaluating.
FALSE.
,thefunctionwillreturn.
FALSE.
.
subroutineomp_set_dynamic(scalar_logical_exp)isdesignedtoallowautomaticdynamicadjustmentofthenumberofthreadsusedforexecutionofparallelregions.
Thisfunctionisrecognized,butcurrentlyhasnoeffect.
logicalfunctionomp_get_dynamic()OpenMPDirectivesforFortran312isdesignedtoallowtheusertoquerywhetherautomaticdynamicadjustmentofthenumberofthreadsusedforexecutionofparallelregionsisenabled.
Thisfunctionisrecognized,butcurrentlyalwaysreturns.
FALSE.
.
subroutineomp_set_nested(scalar_logical_exp)isdesignedtoallowenabling/disablingofnestedparallelregions.
Thisfunctionisrecognized,butcurrentlyhasnoeffect.
logicalfunctionomp_get_nested()isdesignedtoallowtheusertoquerywhetherdynamicadjustmentofthenumberofthreadsavailableforexecutionofparallelregionsisenabled.
Thisfunctionisrecognized,butcurrentlyalwaysreturns.
FALSE.
.
subroutineomp_init_lock(integer_var)initializesalockassociatedwiththevariableinteger_varforuseinsubsequentcallstolockroutines.
Thisinitialstateofinteger_varisunlocked.
Itisillegaltomakeacalltothisroutineifinteger_varisalreadyassociatedwithalock.
subroutineomp_destroy_lock(integer_var)disassociatesalockassociatedwiththevariableinteger_var.
subroutineomp_set_lock(integer_var)causesthecallingthreadtowaituntilthespecifiedlockisavailable.
Thethreadgainsownershipofthelockwhenitisavailable.
Itisillegaltomakeacalltothisroutineifinteger_varhasnotbeenassociatedwithalock.
subroutineomp_unset_lock(integer_var)causesthecallingthreadtoreleaseownershipofthelockassociatedwithinteger_var.
Itisillegaltomakeacalltothisroutineifinteger_varhasnotbeenassociatedwithalock.
logicalfunctionomp_test_lock(integer_var)causesthecallingthreadtotrytogainownershipofthelockassociatedwithinteger_var.
Thefunctionreturns.
TRUE.
ifthethreadgainsownershipofthelock,and.
FALSE.
otherwise.
Itisillegaltomakeacalltothisroutineifinteger_varhasnotbeenassociatedwithalock.
EnvironmentVariables313EnvironmentVariablesOMP_NUM_THREADSspecifiesthenumberofthreadstouseduringexecutionofparallelregions.
Thedefaultvalueforthisvariableis1.
Forhistoricalreasons,theenvironmentvariableNCPUSissupportedwiththesamefunctionality.
IntheeventthatbothOMP_NUM_THREADSandNCPUSaredefined,thevalueofOMP_NUM_THREADStakesprecedence.
NOTEOMP_NUM_THREADSthreadswillbeusedtoexecutetheprogramregardlessofthenumberofphysicalprocessorsavailableinthesystem.
Asaresult,youcanrunprogramsusingmorethreadsthanphysicalprocessorsandtheywillexecutecorrectly.
However,performanceofprogramsexecutedinthismannercanbeunpredictable,andoftentimeswillbeinefficient.
OMP_SCHEDULEspecifiesthetypeofiterationschedulingtouseforDOandPARALLELDOloopswhichincludetheSCHEDULE(RUNTIME)clause.
Thedefaultvalueforthisvariableis"STATIC".
Iftheoptionalchunksizeisnotset,achunksizeof1isassumedexceptinthecaseofaSTATICschedule.
ForaSTATICschedule,thedefaultisasdefinedintheDO.
.
.
ENDDOandPARALLEL.
.
.
ENDPARALLELsections.
ExamplesoftheuseofOMP_SCHEDULEareasfollows:$setenvOMP_SCHEDULE"STATIC,5"$setenvOMP_SCHEDULE"GUIDED,8"$setenvOMP_SCHEDULE"DYNAMIC"OMP_DYNAMICcurrentlyhasnoeffect.
OMP_NESTEDcurrentlyhasnoeffect.
MPSTKZincreasesthesizeofthestacksusedbythreadsexecutinginparallelregions.
Itisforusewithprogramsthatutilizelargeamountsofthread-localstorageintheformofprivatevariablesorlocalvariablesinfunctionsorsubroutinescalledwithinparallelregions.
ThevalueshouldbeanintegernconcatenatedwithMormtospecifystacksizesofnmegabytes.
Forexample:$setenvMPSTKZ8MOpenMPDirectivesforFortran314AddingHPFDirectivestoPrograms3159HPFDirectivesHPFdirectivesareFortran90/95commentswhichconveyinformationtothePGHPFcompiler.
DirectivesaretheheartofanHPFprogram,indicatingdataparallelismbyspecifyinghowdataisassignedandallocatedamongprocessorsonaparallelsystem,andtheinterrelationshipsbetweenvariousdataelements.
AddingHPFDirectivestoProgramsDirectivesinanHPFprogrammayhaveanyofthefollowingforms:CHPF$directive!
HPF$directive*HPF$directiveSinceHPFsupportstwosourceforms,fixedsourceform,andfreesourceform,thereareavarietyofmethodstoenteradirective.
Section3.
4oftheFortran95HandbookoutlinesmethodsforenteringcodethatisvalidforbothfreeandfixedformFortran.
TheC,!
,or*mustbeincolumn1forfixedsourceformdirectives.
Infreesourceform,Fortranlimitsthecommentcharacterto!
.
Ifyouusethe!
HPF$formforthedirectiveorigin,andfollowtherulesoutlinedintheFortran95Handbook,yourcodewillbeuniversallyvalid.
Thebodyofthedirectivemayimmediatelyfollowthedirectiveorigin.
Alternatively,usingfreesourceform,anynumberofblanksmayprecedetheHPFdirective.
Anynamesinthebodyofthedirective,includingthedirectivename,maynotcontainembeddedblanks.
Blanksmaysurroundanyspecialcharacters,suchasacommaoranequalssign.
Thedirectivename,includingthedirectiveorigin,maycontainupperorlowercaseletters(caseisnotsignificant).
HPFDirectives316HPFDirectiveSummaryTable9-1:HPFDirectiveSummaryDIRECTIVEFUNCTIONALIGNSpecifiesthatadataobjectismappedinthesamefashionasanassoci-ateddataobject.
Thisisaspecificationstatement.
Bydefault,objectsarealignedtothemselves.
DIMENSIONSpecifiesthedimensionsofatemplateorprocessor"array".
Thisisaspecificationstatement.
DISTRIBUTESpecifiesthemappingofdataobjectstoprocessors.
Thisisaspecifica-tionstatement.
Bydefault,objectsarenotdistributed.
DYNAMICSpecifiesthatanobjectmaybedynamicallyrealignedorredistributed.
INDEPENDENTPrecedingaDOlooporFORALL,thisdirectivespecifiesthattheDOloop'siterationsdonotinteractinanywayandthattheFORALLindexcomputationsdonotinterferewitheachother,andthustheFORALLmaybeexecutedinparallel.
Thisisanexecutablestatement.
Bydefault,FORALLandDOloopsarenotassumedtobeindependent.
INHERITSpecifiesthatasubprogram'sdummyargumentusethetemplateasso-ciatedwiththeactualargumentforitsalignment.
Thisisaspecificationstatement.
NOSEQUENCESpecifiesvariablesthatarenotsequential.
NotethatusingPGHPF,bydefaultvariablesisnotsequential.
Variableswillbesequentialifthecompileroption-Msequenceissupplied.
PROCESSORSSpecifiesthenumberandrankofaprocessorarrangement.
Thisisaspecificationstatement.
REALIGNThisissimilartoALIGN,butisexecutable.
Anarraycanberealignedatanytime,ifitisdeclaredusingtheDYNAMICattribute.
REDISTRIB-UTEThisissimilartoDISTRIBUTE,butisexecutable.
Anarraycanberedis-tributedatanytime,ifitisdeclaredusingtheDYNAMICattribute.
HPFDirectiveSummary317ALIGN-REALIGNTheALIGNdirectivespecifieshowdataobjectsaremappedinrelationtootherdataobjects.
ThedataobjectsthataremostoftenalignedinHPFprogramsarearrays.
Alignmentsuggeststothecompilerthatentireobjectsorelementsofarraysbestoredonthesameprocessor.
Operationsonobjectsthatarealignedshouldbemoreefficientthanoperationsonobjectsthatarenotaligned,assumingthatobjectsthatarenotalignedmayresideondifferentprocessors.
REALIGNissimilartoALIGN,butisexecutable.
Anarraycanberealignedatanytime,ifitisdeclaredusingtheDYNAMICattribute.
Syntax!
HPF$ALIGNaligneealign-directive-stuffor!
HPF$ALIGNalign-attribute-stuff::alignee-listwhere:aligneeisanobject-name.
align-directive-stuffis(align-source-list)align-with-clausealign-attribute-stuffis[(align-source-list)]align-with-clauseEachalign-sourcehastheform::*align-dummyEachalign-with-clausehastheform:WITHalign-target[(align-subscript-list)]SEQUENCESpecifiesthatavariableorcommonblockissequentialandrequireslin-ear,standardFORTRAN77,treatment.
Thisisaspecificationstatement.
TEMPLATEDefinesanentitythatmaybeusedasanabstractalign-targetforadis-tributionoraredistribution.
Thisisaspecificationstatement.
DIRECTIVEFUNCTIONHPFDirectives318Analign-subscripthastheform:int-expalign-subscript-usesubscript-triplet*TypeSpecificationDefaultThedefaultPGHPFalignmentspecifiesthatadataobjectisreplicatedacrossallprocessormemories.
Forexample,foranarrayRAY1withasingledimensionandatemplateTwithmatchingsizeandshape,thefollowingalignmentspecifiesreplicationwhenTisdistributedinanymanneracrossprocessors.
!
HPF$ALIGNRAY1(*)WITHT(*)!
HPF$DISTRIBUTET(BLOCK)SeeAlsoFordetailsontheALIGNsyntaxspecifications,refereithertosection4.
5ofTheHighPerformanceFortranHandbook,orsection3.
4oftheHPFLanguageSpecification.
ExamplePROGRAMTESTINTEGERA(1000)!
HPF$PROCESSORSPROC(10)!
HPF$TEMPLATET(1000)!
HPF$ALIGNA(:)WITHT(:)!
HPF$DISTRIBUTE(BLOCK)ONTOPROC::TDIMENSIONTheDIMENSIONattributespecifiesthedimensionsandextentsforeachdimensionofaTEMPLATEorPROCESSORSdirective.
Syntax!
HPF$DIMENSION(explicit-shape-spec-list)HPFDirectiveSummary319TypeSpecificationDefaultThedefaultforaTEMPLATEorPROCESSORSarrangementisascalar.
SeeAlsoTheTEMPLATEandPROCESSORSdirectives.
ExampleREALA(100,100)!
HPF$PROCESSORS,DIMENSION(10,10)::PROC!
HPF$TEMPLATE,DIMENSION(10,10)::T!
HPF$ALIGNWITHT::A!
HPF$DISTRIBUTE(BLOCK,BLOCK)ONTOPROC::TDYNAMICTheDYNAMICattributespecifiesthatanobjectmaybedynamicallyrealignedorredistributed.
Syntax!
HPF$DYNAMICalignee-or-distributeee-listTypeSpecificationDefaultBydefaultanobjectisnotdynamic.
SeeAlsoTheREALIGNandREDISTRIBUTEdirectives.
HPFDirectives320ExampleREALA(100,100)!
HPF$DYNAMICA!
HPF$PROCESSORS,DIMENSION(10,10)::PROC!
HPF$TEMPLATE,DIMENSION(10,10)::T!
HPF$ALIGNWITHT::A!
HPF$DISTRIBUTE(BLOCK,BLOCK)ONTOPROC::TDISTRIBUTE-REDISTRIBUTETheDISTRIBUTEdirectivespecifiesamappingofdataobjectstoabstractprocessorsinaprocessorarrangement.
Distributionpartitionsanobject,intheusualcaseanarray(actuallyatemplate),amongasetofprocessors.
REDISTRIBUTEissimilartoDISTRIBUTE,butisexecutable.
Anarraycanberedistributedatanytime,ifitisdeclaredusingtheDYNAMICattributeSyntax!
HPF$DISTRIBUTEdistributeedist-directive-stuffor!
HPF$DISTRIBUTEdist-attribute-stuff::distributee-listwheredist-directive-stuffisoneof:(dist-format-list)(dist-format-list)ONTOprocessors-nameTheformofdist-attribute-stuffisoneof:(dist-format-list)(dist-format-list)ONTOprocessors-nameONTOdist-targetThedist-formatmaybeoneof:BLOCK[(int-expr)]CYCLIC[(int-expr)]TypeSpecificationHPFDirectiveSummary321DefaultBydefault,eachobjectisreplicatedanddistributedtoeveryprocessor.
SeeAlsoFordetailsontheDISTRIBUTEsyntaxspecifications,refereithertoSection4.
4ofTheHighPerformanceFortranHandbook,orSection3.
3oftheHPFLanguageSpecification.
ExampleREALA(100,100)!
HPF$PROCESSORSPROC(10,10)!
HPF$TEMPLATET(10,10)!
HPF$ALIGNWITHT::A!
HPF$DISTRIBUTE(BLOCK,BLOCK)ONTOPROC::TINDEPENDENTTheINDEPENDENTdirectivespecifiesthattheiterationsofaDOloop,orthecomputationsfortheactiveindexvaluesofaFORALL,donotinterferewitheachotherinanyway.
RefertothePGHPFReleasenotesfordetailsonextensionstotheINDEPENDENTdirective.
Syntax!
HPF$INDEPENDENT[,NEW(variable-list)]TypeExecutableDefaultBydefault,DOandFORALLstatementsarenotindependent.
SeeAlsoFordetailsontheINDEPENDENTsyntaxspecifications,refereithertoSection6.
4ofTheHighPerformanceFortranHandbook,orSection4.
4oftheHPFLanguageSpecification.
AlsorefertothePGHPFReleasenotesfordetailsonextensionstotheINDEPENDENTdirective.
HPFDirectives322Example!
HPF$INDEPENDENTDOI=2,N-1X(I)=Y(I-1)+Y(I)+Y(I+1)ENDDOINHERITTheINHERITdirectivespecifiesthatthetemplateforadummyargumentshouldbethesameasthetemplateforthecorrespondingactualargument.
Syntax!
HPF$INHERITdummy-argument-name-listDefaultIftheINHERITattributeisnotused,andALIGNandDISTRIBUTEarenotusedforadummyargument,thenthedummy'stemplatehasthesameshapeasthedummyargumentanditisultimatelyalignedwithitself.
TypeSpecificationSeeAlsoFordetailsontheINHERITsyntaxspecifications,refereithertoSection5.
4ofTheHighPerformanceFortranHandbook,orSection3.
9oftheHPFLanguageSpecification.
ExampleREALVAR1(100)!
HPF$DISTRIBUTEVAR1(BLOCK)10))CALLSUB1(VAR1(10:20:2))SUBROUTINESUB1(PARAM1)REALPARAM1(5)!
HPF$INHERITPARAM1PROCESSORSThePROCESSORSdirectivespecifiesoneormoreprocessorarrangements,byname,rank,andsize.
HPFDirectiveSummary323Syntax!
HPF$PROCESSORSprocessors-decl-listDefaultThedefaultforPROCESSORSisthenumberofprocessorsonwhichtheprogramisrunning,asspecifiedbytheruntimecommand-lineoptions.
TypeSpecificationSeeAlsoFordetailsonthePROCESSORsyntaxspecifications,refereithertoSection4.
8ofTheHighPerformanceFortranHandbook,orSection3.
7oftheHPFLanguageSpecificationForfindingmoreinformationonprocessorswhilerunningaprogram,refertotheNUMBER_OF_PROCESSORSandPROCESSORS_SHAPEintrinsics.
Examples!
HPF$PROCESSORSPROCN(128)!
HPF$PROCESSORSPROC2(3,3,3)!
HPF$PROCESSORS::PROC3(-8:12,100:200)NOSEQUENCEInenvironmentswherevariablesarebydefaultsequential,theNOSEQUENCEdirectivespecifiesthatnon-sequentialaccessshouldapplytoascopingunitortovariablesandcommonblockswithinthescopingunit.
Syntax!
HPF$NOSEQUENCEor!
HPF$NOSEQUENCE[::]association-name-listTypeSpecificationHPFDirectives324SeeAlsoFordetailsontheNOSEQUENCEsyntaxspecifications,refereithertoSection4.
10.
2ofTheHighPerformanceFortranHandbook,orSection7.
1.
3oftheHPFLanguageSpecificationTheSEQUENCEdirective.
ExampleINTEGERFLAG,I,A(1000)COMMON/FOO/A,I,FLAG!
HPF$NOSEQUENCEFOOSEQUENCETheSEQUENCEdirectiveallowsausertodeclareexplicitlythatvariablesorcommonblocksaretobetreatedbythecompilerassequential.
Syntax!
HPF$SEQUENCEor!
HPF$SEQUENCE[::]association-name-listTypeSpecificationSeeAlsoFordetailsontheSEQUENCEsyntaxspecifications,refereithertoSection4.
10.
2ofTheHighPerformanceFortranHandbook,orSection7.
1.
3oftheHPFLanguageSpecification.
TheNOSEQUENCEdirective.
ExampleINTEGERFLAG,I,A(1000)COMMON/FOO/A,I,FLAG!
HPF$SEQUENCEFOOHPFDirectiveSummary325TEMPLATETheTEMPLATEdirectivedeclaresoneormoretemplates,specifyingforeachaname,rank,andsizeforeachdimension.
Syntax!
HPF$TEMPLATEtemplate-decl-listDefaultBydefaultforeachobject,anewtemplateiscreatedandintheabsenceofanexplicitALIGNdirective,theobjectisultimatelyalignedtoitself.
TypeSpecificationSeeAlsoFordetailsontheTEMPLATEsyntaxspecifications,refereithertoSection4.
9ofTheHighPerformanceFortranHandbook,orSection3.
8oftheHPFLanguageSpecification.
Examples!
HPF$TEMPLATEVAR1(N)!
HPF$TEMPLATEVAR2(N,N)!
HPF$TEMPLATE,DISTRIBUTE(BLOCK,BLOCK)::BOARD(8,8)HPFDirectives326327AppendixA.
HPF_LOCALThisappendixliststheHPF_LOCAL_LIBRARYprocedures.
ForcompletedescriptionsoftheHPF_LOCAL_LIBRARYroutines,andthecurrentstandardsforHPF_LOCALextrinsics,refertoAnnexA,"CodingLocalRoutinesinHPFandFortran90",intheHighPerformanceFortranLanguageSpecification.
TableA-1,"HPF_LOCAL_LIBRARYProcedures",brieflyliststheprocedures.
RefertothemanpagessuppliedwiththePGHPFsoftwareforfurtherdetailsontheseprocedures.
RefertoChapter6,"FortranIntrinsics",fordetailsontheintrinsicsdefinedintheFortran90/95LanguageSpecificationandforHPFLIBRARYprocedures.
ForcompletedescriptionsoftheHPF_LOCAL_LIBRARYroutines,andthecurrentstandardsforHPF_LOCALextrinsics,refertoAnnexA,"CodingLocalRoutinesinHPFandFortran90",intheHighPerformanceFortranLanguageSpecification.
328TableA-1:HPF_LOCAL_LIBRARYProceduresIntrinsicDescriptionABSTRACT_TO_PHYSICALReturnsprocessoridentificationforthephysicalprocessorassociatedwithaspeci-fiedabstractprocessor.
GLOBAL_ALIGNMENTReturnsinformationabouttheglobalHPFarrayargument.
GLOBAL_DISTRIBUTIONReturnsinformationabouttheglobalHPFarrayargument.
GLOBAL_LBOUNDReturnslowerboundsoftheactualHPFglo-balarrayassociatedwithadummyarray.
GLOBAL_SHAPEReturnstheshapeoftheglobalHPFactualargument.
GLOBAL_SIZEReturnstheglobalextentofthespecifiedargument.
GLOBAL_TEMPLATEReturnstemplateinformationfortheglobalHPFarrayargument.
GLOBAL_TO_LOCALConvertsasetofglobalcoordinateswithinaglobalHPFactualargument.
GLOBAL_UBOUNDReturnsupperboundsoftheactualHPFglo-balarrayassociatedwithadummyarray.
LOCAL_BLKCNTReturnsthenumberofblocksofelementsineachdimensiononagivenprocessor.
LOCAL_LINDEXReturnsthelowestlocalindexofallblocksofanarraydummy.
LOCAL_TO_GLOBALConvertsasetoflocalcoordinateswithinalocaldummyarraytoanequivalentsetofglobalcoordinates.
329ABSTRACT_TO_PHYSICALSubroutinereturnsprocessoridentificationforthephysicalprocessorassociatedwithaspecifiedabstractprocessorrelativetoaglobalactualargumentarray.
SynopsisABSTRACT_TO_PHYSICAL(ARRAY,INDEX,PROC)ArgumentsARRAYmaybeofanytype;itmustbeadummyarraythatisassociatedwithaglobalHPFarrayactualargument.
ItisanINTENT(IN)argument.
INDEXmustbearank-1integerarraycontainingthecoordinatesofanabstractprocessorintheprocessorsarrangementontowhichtheglobalHPFarrayismapped.
ItisanINTENT(IN)argument.
ThesizeofINDEXmustequaltherankoftheprocessorsarrangement.
PROCmustbescalarandoftypeinteger.
ItisanINTENT(OUT)argument.
ItreceivestheidentifyingvalueforthephysicalprocessorassociatedwiththeabstractprocessorspecifiedbyINDEX.
GLOBAL_ALIGNMENTThishasthesameinterfaceandbehaviorastheHPFinquirysubroutineHPF_ALIGNMENT,butitreturnsinformationabouttheglobalHPFarrayactualargumentassociatedwiththelocaldummyargumentARRAY,ratherthanreturninginformationaboutthelocalarray.
SynopsisGLOBAL_ALIGNMENT(ARRAY,.
.
.
)LOCAL_UINDEXReturnsthehighestlocalindexofallblocksofanarraydummyargument.
MY_PROCESSORReturnstheidentifyingnumberofthecall-ingphysicalprocessor.
PHYSICAL_TO_ABSTRACTReturnscoordinatesforanabstractproces-sor,relativetoaglobalactualargumentarray.
IntrinsicDescription330GLOBAL_DISTRIBUTIONThishasthesameinterfaceandbehaviorastheHPFinquirysubroutineHPF_DISTRIBUTION,butitreturnsinformationabouttheglobalHPFarrayactualargumentassociatedwiththelocaldummyargumentARRAY,ratherthanreturninginformationaboutthelocalarray.
SynopsisGLOBAL_DISTRIBUTION(ARRAY,.
.
.
)GLOBAL_LBOUNDInquiryfunction,returnsallthelowerboundsoraspecifiedlowerboundoftheactualHPFglobalarray.
SynopsisGLOBAL_LBOUND(ARRAY,DIM)ArgumentsOptionalargument.
DIMARRAYmaybeofanytype.
Itmustnotbeascalar.
ItmustbeadummyarrayargumentofanHPF_LOCALprocedurewhichisargumentassociatedwithaglobalHPFarrayactualargument.
DIM(optional)mustbescalarandoftypeintegerwithavalueintherange1<=DIM<=n,wherenistherankofARRAY.
Thecorrespondingactualargumentmustnotbeanoptionaldummyargument.
ReturnTypeTheresultisoftypedefaultinteger.
ItisscalarifDIMispresent;otherwisetheresultisanarrayofrankoneandsizen,wherenistherankofARRAY.
ReturnValueIftheactualargumentassociatedwiththeactualargumentassociatedwithARRAYisanarraysectionoranarrayexpression,otherthanawholearrayoranarraystructurecomponent,GLOBAL_LBOUND(ARRAY,DIM)hasthevalue1;otherwiseithasavalueequaltothelowerboundforsubscriptDIMoftheactualargumentassociatedwiththeactualargumentassociatedwithARRAY.
GLOBAL_LBOUND(ARRAY)hasavaluewhoseithcomponentisequaltoGLOBAL_LBOUND(ARRAY,i),fori=1,2,.
.
.
nwherenistherankofARRAY.
331GLOBAL_SHAPEReturnstheshapeoftheglobalHPFactualargumentassociatedwithanarrayorscalardummyargumentofanHPF_LOCALprocedure.
SynopsisGLOBAL_SHAPE(SOURCE)ArgumentSOURCEmaybeofanytype.
Itmaybearrayvaluedorascalar.
ItmustbeadummyargumentofanHPF_LOCALprocedurewhichisargumentassociatedwithaglobalHPFactualargument.
ReturnTypeTheresultisadefaultintegerarrayofrankonewhosesizeisequaltotherankofSOURCE.
ReturnValueThevalueoftheresultistheshapeoftheglobalactualargumentassociatedwiththeactualargumentassociatedwithSOURCE.
GLOBAL_SIZEInquiryfunctionreturnstheextentalongaspecifieddimensionoftheglobalHPFactualarrayargumentassociatedwithadummyarrayargumentofanHPF_LOCALprocedure.
SynopsisGLOBAL_SIZE(ARRAY,DIM)ArgumentsARRAYmaybeofanytype.
Itmustnotbeascalar.
ItmustbeadummyargumentofanHPF_LOCALprocedurewhichisargumentassociatedwithaglobalHPFactualargument.
DIM(optional)mustbescalarandoftypeintegerwithavalueintherange1<=DIM<=n,wherenistherankofARRAY.
ReturnTypeDefaultintegerscalar.
332ReturnValueTheresulthasavalueequaltotheextentofdimensionDIMoftheactualargumentassociatedwiththeactualargumentassociatedwithARRAYor,ifDIMisabsent,thetotalnumberofelementsintheactualargumentassociatedwiththeactualargumentassociatedwithARRAY.
GLOBAL_TEMPLATEThishasthesameinterfaceandbehaviorastheHPFinquirysubroutineHPF_TEMPLATE,butitreturnsinformationabouttheglobalHPFarrayactualargumentassociatedwiththelocaldummyargumentARRAY,ratherthanreturninginformationaboutthelocalarray.
SynopsisGLOBAL_TEMPLATE(ARRAY,.
.
.
)ArgumentsRefertoHPF_TEMPLATE.
GLOBAL_TO_LOCALSubroutineconvertsasetofglobalcoordinateswithinaglobalHPFactualargumentarraytoanequivalentsetoflocalcoordinateswithintheassociatedlocaldummyarray.
SynopsisGLOBAL_TO_LOCAL(ARRAY,G_INDEX,L_INDEX,LOCAL,NCOPIES,PROCS)ArgumentsARRAYmaybeofanytype;itmustbeadummyarraythatisassociatedwithaglobalHPFarrayactualargument.
ItisanINTENT(IN)argument.
G_INDEXmustbearank-1integerarraywhosesizeisequaltotherankofARRAY.
ItisanINTENT(IN)argument.
ItcontainsthecoordinatesofanelementwithintheglobalHPFarrayactualargumentassociatedwiththelocaldummyarrayARRAY.
333L_INDEX(optional)mustbearank-1integerarraywhosesizeisequaltotherankofARRAY.
ItisanINTENT(OUT)argument.
ItreceivesthecoordinateswithinalocaldummyarrayoftheelementidentifiedwithintheglobalactualargumentarraybyG_INDEX.
(Thesecoordinatesareidenticalonanyprocessorthatholdsacopyoftheidentifiedglobalarrayelement.
)LOCAL(optional)mustbescalarandoftypeLOGICAL.
ItisanINTENT(OUT)argument.
Itissetto.
TRUE.
ifthelocalarraycontainsacopyoftheglobalarrayelementandto.
FALSE.
otherwise.
NCOPIES(optional)mustbescalarandoftypeinteger.
ItisanINTENT(OUT)argument.
Itissettothenumberofprocessorsthatholdacopyoftheidentifiedelementoftheglobalactualarray.
PROCS(optional)mustbearank-1integerarraywhosesizeisaleastthenumberofprocessorsthatholdcopiesoftheidentifiedelementoftheglobalactualarray.
TheidentifyingnumbersofthoseprocessorsareplacedinPROCS.
Theorderinwhichtheyappearisimplementationdependent.
GLOBAL_UBOUNDInquiryfunctionreturnsalltheupperboundsoraspecifiedupperboundoftheactualHPFglobalarrayargumentassociatedwithanHPF_LOCALdummyarrayargument.
SynopsisGLOBAL_UBOUND(ARRAY,DIM)ArgumentsOptionalargument.
DIMARRAYmaybeofanytype.
Itmustnotbeascalar.
ItmustbeadummyarrayargumentofanHPF_LOCALprocedurewhichisargumentassociatedwithaglobalHPFarrayactualargument.
DIM(optional)mustbescalarandoftypeintegerwithavalueintherange1<=DIM<=n,wherenistherankofARRAY.
Thecorrespondingactualargumentmustnotbeanoptionaldummyargument.
ReturnTypeTheresultisoftypedefaultinteger.
ItisscalarifDIMispresent;otherwisetheresultisanarrayofrankoneandsizen,wherenistherankofARRAY.
334ReturnValueIftheactualargumentassociatedwiththeactualargumentassociatedwithARRAYisanarraysectionoranarrayexpression,otherthanawholearrayoranarraystructurecomponent,GLOBAL_UBOUND(ARRAY,DIM)hasavalueequaltothenumberofelementsinthegivendimension;otherwiseithasavalueequaltotheupperboundforsubscriptDIMoftheactualargumentassociatedwiththeactualargumentassociatedwithARRAY,ifdimensionDIMdoesnothavesizezeroandhasthevaluezeroifdimensionDIMhassizezero.
GLOBAL_UBOUND(ARRAY)hasavaluewhoseithcomponentisequaltoGLOBAL_UBOUND(ARRAY,i),fori=1,2,.
.
.
nwherenistherankofARRAY.
LOCAL_BLKCNTPurefunctionreturnsthenumberofblocksofelementsineachdimension,orofaspecificdimensionofthearrayonagivenprocessor.
SynopsisLOCAL_BLKCNT(ARRAY,DIM,PROC)ArgumentsOptionalarguments.
DIM,PROC.
ARRAYmaybeofanytype;itmustbeadummyarraythatisassociatedwithaglobalHPFarrayactualargument.
DIM(optional)mustbescalarandoftypeintegerwithavalueintherange1<=DIM<=nwherenistherankofARRAY.
Thecorrespondingactualargumentmustnotbeanoptionaldummyargument.
PROC(optional)mustbescalarandoftypeinteger.
Itmustbeavalidprocessornumber.
ReturnTypeTheresultisoftypedefaultinteger.
ItisscalarifDIMispresent;otherwisetheresultisanarrayofrankoneandsizen,wherenistherankofARRAY.
ReturnValueThevalueofLOCAL_BLKCNT(ARRAY,DIM,PROC)isthenumberofblocksoftheultimatealigntargetofARRAYindimensionDIMthataremappedtoprocessorPROCandwhichhaveatleastoneelementofARRAYalignedtothem.
335LOCAL_BLKCNT(ARRAY,DIM)returnsthesamevalueasLOCAL_BLKCNT(ARRAY,DIM,PROC=MY_PROCESSOR()).
LOCAL_BLKCNT(ARRAY)hasavaluewhoseithcomponentisequaltoLOCAL_BLKCNT(ARRAY,i),fori=1,.
.
.
,n,wherenistherankofARRAY.
LOCAL_LINDEXPurefunctionreturnsthelowestlocalindexofallblocksofanarraydummyargumentinagivendimensiononaprocessor.
SynopsisLOCAL_LINDEX(ARRAY,DIM,PROC)ArgumentsOptionalargument.
PROC.
ARRAYmaybeofanytype;itmustbeadummyarraythatisassociatedwithaglobalHPFarrayactualargument.
DIMmustbescalarandoftypeintegerwithavalueintherange1<=DIM<=n,wherenistherankofARRAY.
PROC(optional)mustbescalarandoftypeinteger.
Itmustbeavalidprocessornumber.
ReturnTypeTheresultisarank-onearrayoftypedefaultintegerandsize1<=DIM<=n,wherenisthevaluereturnedbyLOCAL_BLKCNT(ARRAY,DIM[,PROC]).
ReturnValueThevalueofLOCAL_LINDEX(ARRAY,DIM,PROC)hasavaluewhoseithcomponentisthelocalindexofthefirstelementoftheithblockindimensionDIMofARRAYonprocessorPROC.
LOCAL_LINDEX(ARRAY,DIM)returnsthesamevalueasLOCAL_LINDEX(ARRAY,DIM,PROC=MY_PROCESSOR()).
LOCAL_TO_GLOBALSubroutineconvertsasetoflocalcoordinateswithinalocaldummyarraytoanequivalentsetofglobalcoordinateswithintheassociatedglobalHPFactualargumentarray.
336SynopsisLOCAL_TO_GLOBAL(ARRAY,L_INDEX,G_INDEX)ArgumentsARRAYmaybeofanytype;itmustbeadummyarraythatisassociatedwithaglobalHPFarrayactualargument.
ItisanINTENT(IN)argument.
L_INDEXmustbearank-1integerarraywhosesizeisequaltotherankofARRAY.
ItisanINTENT(IN)argument.
ItcontainsthecoordinatesofanelementwithinthelocaldummyarrayARRAY.
G_INDEXmustbearank-1integerarraywhosesizeisequaltotherankofARRAY.
ItisanINTENT(OUT)argument.
ItreceivesthecoordinateswithintheglobalHPFarrayactualargumentoftheelementidentifiedwithinthelocalarraybyL_INDEX.
LOCAL_UINDEXPurefunctionreturnsthehighestlocalindexofallblocksofanarraydummyargumentinagivendimensiononaprocessor.
SynopsisLOCAL_UINDEX(ARRAY,DIM,PROC)ArgumentsOptionalargument.
PROC.
ARRAYmaybeofanytype;itmustbeadummyarraythatisassociatedwithaglobalHPFarrayactualargument.
DIMmustbescalarandoftypeintegerwithavalueintherange1<=DIM<=n,wherenistherankofARRAY.
PROC(optional)mustbescalarandoftypeinteger.
Itmustbeavalidprocessornumber.
ReturnTypeTheresultisarank-onearrayoftypedefaultintegerandsizeb,wherebisthevaluereturnedbyLOCAL_BLKCNT(ARRAY,DIM[,PROC])337ReturnValueThevalueofLOCAL_UINDEX(ARRAY,DIM,PROC)hasavaluewhoseithcomponentisthelocalindexofthelastelementoftheithblockindimensionDIMofARRAYonprocessorPROC.
LOCAL_UINDEX(ARRAY,DIM)returnsthesamevalueasLOCAL_UINDEX(ARRAY,DIM,PROC=MY_PROCESSOR()).
MY_PROCESSORPurefunctionreturnstheidentifyingnumberofthecallingphysicalprocessor.
SynopsisMY_PROCESSOR()ReturnTypeTheresultisscalarandoftypedefaultinteger.
ReturnValueReturnstheidentifyingnumberofthephysicalprocessorfromwhichthecallismade.
ThisvalueisintherangewhereisthevaluereturnedbyNUMBER_OF_PROCESSORS().
PHYSICAL_TO_ABSTRACTSubroutinereturnscoordinatesforanabstractprocessor,relativetoaglobalactualargumentarray,correspondingtoaspecifiedphysicalprocessor.
Thisprocedurecanbeusedonlyonsystemswherethereisaone-to-onecorrespondencebetweenabstractprocessorsandphysicalprocessors.
Onsystemswherethiscorrespondenceisone-to-manyanequivalent,system-dependentprocedureshouldbeprovided.
SynopsisPHYSICAL_TO_ABSTRACT(ARRAY,PROC,INDEX)ArgumentsARRAYmaybeofanytype;itmustbeadummyarraythatisassociatedwithaglobalHPFarrayactualargument.
ItisanINTENT(IN)argument.
PROCmustbescalarandoftypedefaultinteger.
ItisanINTENT(IN)argument.
Itcontainsanidentifyingvalueforaphysicalprocessor.
338INDEXmustbearank-1integerarray.
ItisanINTENT(OUT)argument.
ThesizeofINDEXmustequaltherankoftheprocessorarrangementontowhichtheglobalHPFarrayismapped.
INDEXreceivesthecoordinateswithinthisprocessorsarrangementoftheabstractprocessorassociatedwiththephysicalprocessorspecifiedbyPROC.
339IndexAABSTRACT_TO_PHYSICAL329ACCEPT44ADVANCE162ALIGN317WITH317ALLOCATABLE45ALLOCATE45arithmeticexpressions12ARRAY47,144arraysARRAYattribute144assumedshape140assumedsize140CMFortranconstructors144constructorextensions144constructors144deferredshape140explicitshape140sections142,143specification141specificationassumedshape141specificationassumedsize142specificationdeferredshape141specificationexplicitshape141subscripttriplets142subscripts142vectorsubscripts143ASSIGN48assignmentstatements16assumedshapearrays140assumedsizearrays140attributeDIMENSION318PURE116BBACKSPACE49specifierERR49IOSTAT49UNIT49binaryconstants33BLOCK320BLOCKDATA49BYTE50CCALL51CASE52CHARACTER52characterconstants29charactersetClanguagecompatibility4CLOSE54DISPspecifier54DISPOSEspecifier54ERRspecifier54IOSTATspecifier54STATUSspecifier54UNITspecifier54closingafile147CMFortranarrays144CMFortranIntrinsics261CSHIFT262EOSHIFT262RESHAPE262columnformattingcontinuationfield6,7labelfield6statementfield6,7COMMON55COMPLEX58complexconstants28Conformancetostandardsxivconstants25PARAMETERstatement30CONTAINS59CONTINUE60ConventionsxviCSHIFTCMFortran262CYCLE60CYCLIC320DDATA61datatypesbinaryconstants33characterconstants29complexconstants28constants25doubleprecisionconstants27extensions22hexadecimalconstants33integerconstants25kindparameter21logicalconstants28octalconstants33realconstants26sizespecification22DEALLOCATE62STATspecifier62debugstatements7DECODE63340Indexdeferredshapearrays140derivedtypes30DIMENSION64directaccessfiles147DirectivesParallelization295DO65doubleprecisionconstants27DOUBLECOMPLEX68DOUBLEPRECISION69DOWHILE67DYNAMIC319EELSE70,87,88ELSEIF70,88ELSEWHERE71ELSEIF87ELSEWHERE134ENCODE71END72ENDDO65ENDIF88ENDBLOCKDATA49ENDCASE52ENDFORALL80ENDFUNCTION83ENDIF87ENDINTERFACE96ENDPROGRAM115ENDSUBROUTINE128ENDTYPE130ENDWHERE134ENTRY75EnvironmentVariablesMPSTKZ313OMP_DYNAMIC313OMP_NESTED313OMP_NUM_THREADS313OMP_SCHEDULE313EOSHIFTCMFortran262EQUIVALENCE78EXIT79expressions10EXTERNAL79EXTRINSIC80FF773FRoutines265ABORT266ACCESS266ALARM267BESSELFUNCTIONS267chdir268CHMOD269CTIME269DATE269DRANDM283DSECNDS285ELAPSEDTIME270ERRORFUNCTIONS270EXIT270FDATE271FGETC271FLUSH271FORK272FSTAT287GERROR273GETARG274GETC274GETCWD275GETENV275GETGID275GETLOG275GETPID276GETUID276GMTIME276HOSTNM277IARG274IDATE277IERRNO277IOINIT277IRAND283IRANDM283ISATTY278ITIME278KILL278LINK279LNBLNK279LOC279LSTAT287LTIME280MALLOC280MCLOCK280MVBITS281OUTSTR281PERROR281PUTC282PUTENV282QSORT282RAND283RANDOM283RANGE284RENAME284RINDEX285SECNDS285SETVBUF3F285SIGNAL286SLEEP287SRAND283STAT287STIME288SYMLNK288SYSTEM288TIME289TIMES289TTYNAM289UNLINK290WAIT290F77VAXBuilt-InFunctions291%LOC291%REF(a)291F77VAXSystemSubroutines290F77VAX/VMSSubroutines291DATE291EXIT291GETARG292IARGC292Index341IDATE292MVBITS292RAN293SECNDS293TIME294F90Functions228ABS201ACHAR202ACOS202ADJUSTL203ADJUSTR203AIMAG203AINT204ALL204ALLOCATED205ANINT205ANY206ASIN206,207ASSOCIATED207ATAN208,209ATAN2208BIT_SIZE209BTEST209CEILING210CHAR210CMPLX211,215CONJG211COSH212COUNT213CSHIFT214DATE_AND_TIME214DBLE215DIGITS216DIM216DOT_PRODUCT216DPROD217EOSHIFT217EPSILON218EXP218EXPONENT219FLOOR219,222FRACTION220HUGE220,255IACHAR220IAND221,223,225,229,230,231IBCLR221IBITS205,211,218,221,240,241,258INDEX223INT223,224,225,227IOR225ISHFT225,232,246,249ISHFTC226KIND227LBOUND228LEN_TRIM229LGE229LLT231LOG231LOG10232LOGICAL232MATMUL233MAX233MAXEXPONENT234MAXLOC234MAXVAL235,237MERGE236MIN236MINEXPONENT236MINVAL237MOD238MODULO238MVBITS239NEAREST239NINT224,227,228,240NOT240PACK241,257PRECISION242PRESENT242PRODUCT243RADIX243RANDOM_NUMBER243RANDOM_SEED244RANGE245REAL245REPEAT245RESHAPE246RRSPACING246SCALE247SCAN247SELECTED_INT_KIND248SELECTED_REAL_KIND248SET_EXPONENT249SHAPE249SIGN250SIN250SINH251SIZE251SPACING252SPREAD252SQRT252SUM253SYSTEM_CLOCK253TAN254TANH254TRANSFER255TRANSPOSE255TRIM256UBOUND256UNPACK257VERIFY226,257,258F95FunctionsCPU_TIME213NULL241fileaccessmethods145fixedsourceform2,6FORALL80FORMAT81Formatcontrolspecifier$specifier162Aspecifier153Bspecifier154BNspecifier158Dspecifier154Especifier155ENspecifier155endofrecord161ESspecifier155342IndexFspecifier156formattermination162Gspecifier156Hspecifier158Ispecifier156Lspecifier157Ospecifier158,161Pspecifier159Qspecifier159quotecontrol157Sspecifier159slash161SPspecifier159SSspecifier159Tspecifier160TLspecifier160Xspecifier160Zspecifier158,161formatspecifications151formatteddatatransfer150Fortran77171MathIntrinsics172FortranIntrinsics171FortranParallelizationDirectivesATOMIC309BARRIER305CRITICAL.
.
.
ENDCRITICAL300DO.
.
.
ENDDO302DOACROSS305FLUSH310MASTER.
.
.
ENDMASTER301PARALLELDO306PARALLELSECTIONS308SECTIONS.
.
.
ENDSECTIONS307SINGLE.
.
.
ENDSINGLE302THREADPRIVATE310Fortranprogramunitelementsof1freesourceform2,5comments5continuationline6statementlabels6FUNCTION83GGLOBAL_ALIGNMENT329GLOBAL_DISTRIBUTION330GLOBAL_LBOUND330GLOBAL_SHAPE331GLOBAL_SIZE331GLOBAL_TEMPLATE332GLOBAL_TO_LOCAL332GLOBAL_UBOUND333GOTOAssigned85Computed86Unconditional87Hhexadecimalconstants33,34hollerithconstants35HPFDirectives!
HPF$315*HPF$315addingtoHPF315ALIGN317CHPF$315DISTRIBUTE320DISTRIBUTEBLOCK320DISTRIBUTECYCLIC320DISTRIBUTEONTO320INDEPENDENT321INHERIT322NOSEQUENCE323PROCESSORS322REALIGN317REDISTRIBUTE320SEQUENCE324summarytable316TEMPLATE325HPF_LOCALFunctionsABSTRACT_TO_PHYSICAL329GLOBAL_ALIGNMENT329GLOBAL_DISTRIBUTION330GLOBAL_LBOUND330GLOBAL_SHAPE331GLOBAL_SIZE331GLOBAL_TEMPLATE332GLOBAL_TO_LOCAL332GLOBAL_UBOUND333LOCAL_BLKCNT334LOCAL_LINDEX335LOCAL_TO_GLOBAL335LOCAL_UNIDEX336MY_PROCESSOR337Overview327PHYSICAL_TO_ABSTRACT337IIFArithmetic87Block87Logical88IMPLICIT89impliedDOlist151INCLUDE8,90INDEPENDENT321INHERIT322inputandoutput145INQUIRE91ACCESSspecifier91ACTIONspecifier91BLANKspecifier91DELIMspecifier91DIRECTspecifier91ERRspecifier91EXISTspecifier92FILEspecifier92FORMspecifier92FORMATTEDspecifier92IOSTATspecifier92NAMEspecifier92NAMEDspecifier92NEXTRECspecifier92NUMBERspecifier92OPENEDspecifier92PADspecifier92POSITIONspecifier93READspecifier93READWRITEspecifier93Index343RECLspecifier93SEQUENTIALspecifier93STATUSspecifier93UNFORMATTEDspecifier93WRITEspecifier93INTEGER94integerconstants25INTENT95INTERFACE96INTRINSIC96intrinsicdatatypes21Llist-directedformatting163list-directedinput163list-directedoutput165LOCAL_BLKCNT334LOCAL_LINDEX335LOCAL_TO_GLOBAL335LOCAL_UNIDEX336LOGICAL98logicalconstants28MMAP@99multiplestatements6MY_PROCESSOR337NNAMELIST102namelistgroups167namelistinput167namelistoutput168non-advancingi/o162NULLIFY102Ooctalconstants33,34ONTO320OPEN103ACCESSspecifier103ACTIONspecifier103ASYNCHRONOUSspecifier103BLANKspecifier103DELIMspecifier104ERRspecifier104FILEspecifier104FORMspecifier104IOSTATspecifier104PADspecifier104POSITIONspecifier104RECLspecifier104STATUSspecifier105openingandclosingfiles146OpenMPDirectivessyntax295OpenMPEnvironmentVariablesMPSTKZ313OMP_DYNAMIC313OMP_NESTED313OMP_NUM_THREADS313OMP_SCHEDULE313OpenMPFortranDirectives295OpenMPFortranSupportRoutinesomp_destroy_lock()312omp_get_dynamic()312omp_get_max_threads()311omp_get_nested()312omp_get_num_procs()311omp_get_num_threads()310omp_get_thread_num()311omp_in_parallel()311omp_init_lock()312omp_set_dynamic()311omp_set_lock()312omp_set_nested()312omp_set_num_threads()311omp_test_lock()312omp_unset_lock()312option-Mdlines7-Mfreeform2OPTIONAL108OPTIONS108PParallelizationDirectives295PARAMETER110PAUSE110PHYSICAL_TO_ABSTRACT337POINTER111pointers33precedencerules10PRINT113PRIVATE114PROGRAM115PUBLIC115PURE116RREAD117ADVANCEspecifier117ASYNCHRONOUSspecifier117,135ENDspecifier117EORspecifier117ERRspecifier117FMTspecifier117IOSTATspecifier117NMLspecifier117RECspecifier118SIZEspecifier118REAL119realconstants26REALIGN317RECORD120RECURSIVE121REDIMENSION122REDISTRIBUTE320RelatedPublicationsxviiRESHAPECMFortran262RETURN122REWIND123specifierERR123IOSTAT123UNIT123344IndexSSELECT52SELECTCASE125Standardcompatibilityxivstandardpreconnectedunits146StatementACCEPT44ALLOCATABLE45ALLOCATE45ARRAY47,144ASSIGN48BACKSPACE49BLOCKDATA49BYTE50CALL51CASE52CHARACTER52CLOSE54COMMON55COMPLEX58CONTAINS59CONTINUE60CYCLE60DATA61DEALLOCATE62DECODE63DIMENSION64DO65DOUBLECOMPLEX68DOUBLEPRECISION69DOWHILE67ELSE70,87,88ELSEIF70,87,88ELSEWHERE71ELSEWHERE134ENCODE71END72ENDDO65ENDFUNCTION83ENDIF87,88ENDPROGRAM115ENDBLOCKDATA49ENDCASE52ENDFORALL80ENDINTERFACE96ENDSUBROUTINE128ENDTYPE130ENDWHERE134ENTRY75EQUIVALENCE78EXIT79EXTERNAL79EXTRINSIC80FORALL80FORMAT81FUNCTION83GOTO85,86,87IF87,88IMPLICIT89INCLUDE90INQUIRE91INTEGER94INTENT95INTERFACE96INTRINSIC96LOGICAL98MAP@99NAMELIST102NULLIFY102OPEN103OPTIONAL108OPTIONS108PARAMETER110PAUSE110POINTER111PRINT113PRIVATE114PROGRAM115PUBLIC115READ117REAL119RECORD120RECURSIVE121REDIMENSION122RETURN122REWIND123SELECT52SELECTCASE125SEQUENCE125STOP126STRUCTURE@126SUBROUTINE128TARGET129THEN87,88,129TYPE130UNION@131USE133VOLATILE133WHERE134WRITE135Statementordering2Statementsandcomments1STOP126STRUCTURE@126SUBROUTINE128symbolicnamescope16Ttabformatting7TARGET129targets33THEN87TYPE130Uunformatteddatatransfer150UNION@131USE133VVOLATILE133WWHERE134WITH317WRITEspecifierADVANCEspecifier135Index345ERRspecifier135FMTspecifier135IOSTATspecifier135NMLspecifier136RECspecifier136

819云互联(800元/月),香港BGP E5 2650 16G,日本 E5 2650 16G

819云互联 在本月发布了一个购买香港,日本独立服务器的活动,相对之前的首月活动性价比更高,最多只能享受1个月的活动 续费价格恢复原价 是有些颇高 这次819云互联与机房是合作伙伴 本次拿到机房 活动7天内购买独立服务器后期的长期续费价格 加大力度 确实来说这次的就可以买年付或者更长时间了…本次是5个机房可供选择,独立服务器最低默认是50M带宽,不限制流量,。官网:https://ww...

VinaHost,越南vps,国内延时100MS;不限流量100Mbps

vinahost怎么样?vinahost是一家越南的主机商家,至今已经成13年了,企业运营,老牌商家,销售VPS、虚拟主机、域名、邮箱、独立服务器等,机房全部在越南,有Viettle和VNPT两个机房,其中VNPT机房中三网直连国内的机房,他家的产品优势就是100Mbps不限流量。目前,VinaHost商家发布了新的优惠,购买虚拟主机、邮箱、云服务器、VPS超过三个月都有赠送相应的时长,最高送半年...

萤光云(13.25元)香港CN2 新购首月6.5折

萤光云怎么样?萤光云是一家国人云厂商,总部位于福建福州。其成立于2002年,主打高防云服务器产品,主要提供福州、北京、上海BGP和香港CN2节点。萤光云的高防云服务器自带50G防御,适合高防建站、游戏高防等业务。目前萤光云推出北京云服务器优惠活动,机房为北京BGP机房,购买北京云服务器可享受6.5折优惠+51元代金券(折扣和代金券可叠加使用)。活动期间还支持申请免费试用,需提交工单开通免费试用体验...

wallop为你推荐
视频截图软件什么视频截图软件最好用郭吉军二战中受害最大的国家?如何免费开通黄钻怎样才能免费开通黄钻简体翻译成繁体简体中文转换成繁体怎么转换?中国电信互联星空中国电信宽带于互联星空的区别iphone越狱后怎么恢复已经越狱的iphone怎么恢复到原来的系统腾讯文章腾讯罗剑楠是何许人也?雅虎天盾雅虎天盾、瑞星杀毒软件、瑞星防火墙、卡卡上网安全助手能同时使用吗?虚拟机软件下载那里可以下载虚拟系统,又该怎么安装呢??服务器连接异常服务器连接异常,即将退出,请重新进入游戏.怎么回事
免费域名空间申请 VPS之家 外贸主机 私服服务器 免费ftp空间 特价空间 标准机柜尺寸 镇江联通宽带 一元域名 合肥鹏博士 三拼域名 dux 怎么测试下载速度 河南移动网 国外免费asp空间 创建邮箱 dnspod 独立主机 主机返佣 阿里云邮箱登陆 更多