! ! A sample program that decides if we have the module of the ! wind or its componenets ! ! !REPLACE! indicates lines which you need to replce by your own ! ! ! Jan Polcher (polcher@lmd.jussieu.fr) ! ! Declarations which need to be added to your code ! INTEGER :: iret ! return code for netCDF calls INTEGER :: ncid ! ID of the opened file INTEGER :: number_var ! Number of variables found in the file INTEGER :: iv ! Index of loop INTEGER :: wind_ids(2) ! IDs of the wind variables CHARACTER(LEN=80) :: var_name ! Name of the variables as we read them ! ! ! This goes into your code where you read the input ! ! ! Open the netCDF file ! !REPLACE! iret = NF_OPEN("/home/polcher/ISLSCP/islscp_Euro_87.nc", NF_NOWRITE, ncid) ! ! Read the number of variables in the file ! iret = NF_INQ_NVARS(ncid, number_var) ! ! Set the ids of the wind variables to impossible values ! wind_ids(1) = -1 wind_ids(2) = -1 ! ! Loop through all variables ! DO iv = 1, number_var ! ! Get the name of the variable ! iret = NF_INQ_VARNAME(ncid, iv, var_name) ! ! Test if this variable is a wind component ! ! NOTE on index : ! If you are not compiling with F90 check what your compiler ! offers for function to find a sub-string in a string. ! IF ( index(var_name, 'Wind') .GT. 0 ) THEN ! ! If it is a wind component then 3 cases need to be considered ! IF ( index(var_name, 'Wind_N') .GT. 0 ) THEN ! It is the Nortward component wind_ids(1) = iv ELSE IF ( index(var_name, 'Wind_E') .GT. 0 ) THEN ! It is teh Eastward component wind_ids(2) = iv ELSE ! If it is neither one then it can only be the module wind_ids(1) = iv wind_ids(2) = 0 ENDIF ENDIF ! ENDDO ! ! Depending on the number of components for the wind found, we take different actions ! IF ( wind_ids(1) .LT. 0 .OR. wind_ids(2) .LT. 0 ) THEN ! ! We are missing one component, this can not be right ! ! WRITE(*,*) 'ERROR : ' WRITE(*,*) 'We did not find the right information to extract the wind from this file' STOP ! ELSE IF ( wind_ids(1) .GT. 0 .AND. wind_ids(2) .GT. 0 ) THEN ! ! We have two wind componenets ! !REPLACE! iret = NF_GET_VAR_REAL(ncid, wind_ids(1), wind_north_variable) !REPLACE! iret = NF_GET_VAR_REAL(ncid, wind_ids(2), wind_east_variable) ! ELSE ! ! We have only the wind module ! !REPLACE! iret = NF_GET_VAR_REAL(ncid, wind_ids(1), wind_north_variable) !REPLACE! wind_east_variable = 0.0 ! ENDIF ! ! ! ! Continue here with you code !